BasicRecoverSyncMethodHandler.java
01 package org.apache.qpid.server.handler;
02 /*
03  
04  * Licensed to the Apache Software Foundation (ASF) under one
05  * or more contributor license agreements.  See the NOTICE file
06  * distributed with this work for additional information
07  * regarding copyright ownership.  The ASF licenses this file
08  * to you under the Apache License, Version 2.0 (the
09  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  
21  */
22 
23 
24 import org.apache.log4j.Logger;
25 
26 import org.apache.qpid.framing.BasicRecoverBody;
27 import org.apache.qpid.framing.ProtocolVersion;
28 import org.apache.qpid.framing.AMQMethodBody;
29 import org.apache.qpid.framing.BasicRecoverSyncBody;
30 import org.apache.qpid.framing.amqp_0_9.MethodRegistry_0_9;
31 import org.apache.qpid.framing.amqp_8_0.MethodRegistry_8_0;
32 import org.apache.qpid.server.state.StateAwareMethodListener;
33 import org.apache.qpid.server.state.AMQStateManager;
34 import org.apache.qpid.server.protocol.AMQProtocolSession;
35 import org.apache.qpid.server.AMQChannel;
36 import org.apache.qpid.AMQException;
37 
38 public class BasicRecoverSyncMethodHandler implements StateAwareMethodListener<BasicRecoverSyncBody>
39 {
40     private static final Logger _logger = Logger.getLogger(BasicRecoverSyncMethodHandler.class);
41 
42     private static final BasicRecoverSyncMethodHandler _instance = new BasicRecoverSyncMethodHandler();
43 
44     public static BasicRecoverSyncMethodHandler getInstance()
45     {
46         return _instance;
47     }
48 
49     public void methodReceived(AMQStateManager stateManager, BasicRecoverSyncBody body, int channelIdthrows AMQException
50     {
51         AMQProtocolSession session = stateManager.getProtocolSession();
52 
53         _logger.debug("Recover received on protocol session " + session + " and channel " + channelId);
54         AMQChannel channel = session.getChannel(channelId);
55 
56 
57         if (channel == null)
58         {
59             throw body.getChannelNotFoundException(channelId);
60         }
61 
62         channel.resend(body.getRequeue());
63 
64         // Qpid 0-8 hacks a synchronous -ok onto recover.
65         // In Qpid 0-9 we create a separate sync-recover, sync-recover-ok pair to be "more" compliant
66         if(session.getProtocolVersion().equals(ProtocolVersion.v0_9))
67         {
68             MethodRegistry_0_9 methodRegistry = (MethodRegistry_0_9session.getMethodRegistry();
69             AMQMethodBody recoverOk = methodRegistry.createBasicRecoverSyncOkBody();
70             session.writeFrame(recoverOk.generateFrame(channelId));
71 
72         }
73 
74     }
75 }