ClientMethodDispatcherImpl.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  *
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  *
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.client.handler;
022 
023 import java.util.Map;
024 import java.util.HashMap;
025 
026 import org.apache.qpid.framing.*;
027 import org.apache.qpid.AMQException;
028 import org.apache.qpid.client.state.AMQStateManager;
029 import org.apache.qpid.client.state.AMQMethodNotImplementedException;
030 import org.apache.qpid.client.protocol.AMQProtocolSession;
031 import org.slf4j.Logger;
032 import org.slf4j.LoggerFactory;
033 
034 public class ClientMethodDispatcherImpl implements MethodDispatcher
035 {
036 
037     private static final BasicCancelOkMethodHandler _basicCancelOkMethodHandler = BasicCancelOkMethodHandler.getInstance();
038     private static final BasicDeliverMethodHandler _basicDeliverMethodHandler = BasicDeliverMethodHandler.getInstance();
039     private static final BasicReturnMethodHandler _basicReturnMethodHandler = BasicReturnMethodHandler.getInstance();
040     private static final ChannelCloseMethodHandler _channelCloseMethodHandler = ChannelCloseMethodHandler.getInstance();
041     private static final ChannelFlowOkMethodHandler _channelFlowOkMethodHandler = ChannelFlowOkMethodHandler.getInstance();
042     private static final ConnectionCloseMethodHandler _connectionCloseMethodHandler = ConnectionCloseMethodHandler.getInstance();
043     private static final ConnectionOpenOkMethodHandler _connectionOpenOkMethodHandler = ConnectionOpenOkMethodHandler.getInstance();
044     private static final ConnectionRedirectMethodHandler _connectionRedirectMethodHandler = ConnectionRedirectMethodHandler.getInstance();
045     private static final ConnectionSecureMethodHandler _connectionSecureMethodHandler = ConnectionSecureMethodHandler.getInstance();
046     private static final ConnectionStartMethodHandler _connectionStartMethodHandler = ConnectionStartMethodHandler.getInstance();
047     private static final ConnectionTuneMethodHandler _connectionTuneMethodHandler = ConnectionTuneMethodHandler.getInstance();
048     private static final ExchangeBoundOkMethodHandler _exchangeBoundOkMethodHandler = ExchangeBoundOkMethodHandler.getInstance();
049     private static final QueueDeleteOkMethodHandler _queueDeleteOkMethodHandler = QueueDeleteOkMethodHandler.getInstance();
050 
051     private static final Logger _logger = LoggerFactory.getLogger(ClientMethodDispatcherImpl.class);
052 
053     private static interface DispatcherFactory
054     {
055         public ClientMethodDispatcherImpl createMethodDispatcher(AMQProtocolSession session);
056     }
057 
058     private static final Map<ProtocolVersion, DispatcherFactory> _dispatcherFactories =
059             new HashMap<ProtocolVersion, DispatcherFactory>();
060 
061     static
062     {
063         _dispatcherFactories.put(ProtocolVersion.v8_0,
064                                  new DispatcherFactory()
065                                  {
066                                      public ClientMethodDispatcherImpl createMethodDispatcher(AMQProtocolSession session)
067                                      {
068                                          return new ClientMethodDispatcherImpl_8_0(session);
069                                      }
070                                  });
071 
072         _dispatcherFactories.put(ProtocolVersion.v0_9,
073                                  new DispatcherFactory()
074                                  {
075                                      public ClientMethodDispatcherImpl createMethodDispatcher(AMQProtocolSession session)
076                                      {
077                                          return new ClientMethodDispatcherImpl_0_9(session);
078                                      }
079                                  });
080 
081     }
082 
083     public static ClientMethodDispatcherImpl newMethodDispatcher(ProtocolVersion version, AMQProtocolSession session)
084     {
085         if (_logger.isInfoEnabled())
086         {
087             _logger.info("New Method Dispatcher:" + session);
088         }
089         
090         DispatcherFactory factory = _dispatcherFactories.get(version);
091         return factory.createMethodDispatcher(session);
092     }
093 
094     AMQProtocolSession _session;
095 
096     public ClientMethodDispatcherImpl(AMQProtocolSession session)
097     {
098         _session = session;
099     }
100 
101     public AMQStateManager getStateManager()
102     {
103         return _session.getStateManager();
104     }
105 
106     public boolean dispatchAccessRequestOk(AccessRequestOkBody body, int channelIdthrows AMQException
107     {
108         return false;
109     }
110 
111     public boolean dispatchBasicCancelOk(BasicCancelOkBody body, int channelIdthrows AMQException
112     {
113         _basicCancelOkMethodHandler.methodReceived(_session, body, channelId);
114         return true;
115     }
116 
117     public boolean dispatchBasicConsumeOk(BasicConsumeOkBody body, int channelIdthrows AMQException
118     {
119         return false;
120     }
121 
122     public boolean dispatchBasicDeliver(BasicDeliverBody body, int channelIdthrows AMQException
123     {
124         _basicDeliverMethodHandler.methodReceived(_session, body, channelId);
125         return true;
126     }
127 
128     public boolean dispatchBasicGetEmpty(BasicGetEmptyBody body, int channelIdthrows AMQException
129     {
130         return false;
131     }
132 
133     public boolean dispatchBasicGetOk(BasicGetOkBody body, int channelIdthrows AMQException
134     {
135         return false;
136     }
137 
138     public boolean dispatchBasicQosOk(BasicQosOkBody body, int channelIdthrows AMQException
139     {
140         return false;
141     }
142 
143     public boolean dispatchBasicReturn(BasicReturnBody body, int channelIdthrows AMQException
144     {
145         _basicReturnMethodHandler.methodReceived(_session, body, channelId);
146         return true;
147     }
148 
149     public boolean dispatchChannelClose(ChannelCloseBody body, int channelIdthrows AMQException
150     {
151         _channelCloseMethodHandler.methodReceived(_session, body, channelId);
152         return true;
153     }
154 
155     public boolean dispatchChannelCloseOk(ChannelCloseOkBody body, int channelIdthrows AMQException
156     {
157         return false;
158     }
159 
160     public boolean dispatchChannelFlow(ChannelFlowBody body, int channelIdthrows AMQException
161     {
162         return false;
163     }
164 
165     public boolean dispatchChannelFlowOk(ChannelFlowOkBody body, int channelIdthrows AMQException
166     {
167         _channelFlowOkMethodHandler.methodReceived(_session, body, channelId);
168         return true;
169     }
170 
171     public boolean dispatchChannelOpenOk(ChannelOpenOkBody body, int channelIdthrows AMQException
172     {
173         return false;
174     }
175 
176     public boolean dispatchConnectionClose(ConnectionCloseBody body, int channelIdthrows AMQException
177     {
178         _connectionCloseMethodHandler.methodReceived(_session, body, channelId);
179         return true;
180     }
181 
182     public boolean dispatchConnectionCloseOk(ConnectionCloseOkBody body, int channelIdthrows AMQException
183     {
184         return false;
185     }
186 
187     public boolean dispatchConnectionOpenOk(ConnectionOpenOkBody body, int channelIdthrows AMQException
188     {
189         _connectionOpenOkMethodHandler.methodReceived(_session, body, channelId);
190         return true;
191     }
192 
193     public boolean dispatchConnectionRedirect(ConnectionRedirectBody body, int channelIdthrows AMQException
194     {
195         _connectionRedirectMethodHandler.methodReceived(_session, body, channelId);
196         return true;
197     }
198 
199     public boolean dispatchConnectionSecure(ConnectionSecureBody body, int channelIdthrows AMQException
200     {
201         _connectionSecureMethodHandler.methodReceived(_session, body, channelId);
202         return true;
203     }
204 
205     public boolean dispatchConnectionStart(ConnectionStartBody body, int channelIdthrows AMQException
206     {
207         _connectionStartMethodHandler.methodReceived(_session, body, channelId);
208         return true;
209     }
210 
211     public boolean dispatchConnectionTune(ConnectionTuneBody body, int channelIdthrows AMQException
212     {
213         _connectionTuneMethodHandler.methodReceived(_session, body, channelId);
214         return true;
215     }
216 
217     public boolean dispatchQueueDeleteOk(QueueDeleteOkBody body, int channelIdthrows AMQException
218     {
219         _queueDeleteOkMethodHandler.methodReceived(_session, body, channelId);
220         return true;
221     }
222 
223     public boolean dispatchQueuePurgeOk(QueuePurgeOkBody body, int channelIdthrows AMQException
224     {
225         return false;
226     }
227 
228     public boolean dispatchStreamCancelOk(StreamCancelOkBody body, int channelIdthrows AMQException
229     {
230         return false;
231     }
232 
233     public boolean dispatchStreamConsumeOk(StreamConsumeOkBody body, int channelIdthrows AMQException
234     {
235         return false;
236     }
237 
238     public boolean dispatchAccessRequest(AccessRequestBody body, int channelIdthrows AMQException
239     {
240         throw new AMQMethodNotImplementedException(body);
241     }
242 
243     public boolean dispatchBasicAck(BasicAckBody body, int channelIdthrows AMQException
244     {
245         throw new AMQMethodNotImplementedException(body);
246     }
247 
248     public boolean dispatchBasicCancel(BasicCancelBody body, int channelIdthrows AMQException
249     {
250         throw new AMQMethodNotImplementedException(body);
251     }
252 
253     public boolean dispatchBasicConsume(BasicConsumeBody body, int channelIdthrows AMQException
254     {
255         throw new AMQMethodNotImplementedException(body);
256     }
257 
258     public boolean dispatchBasicGet(BasicGetBody body, int channelIdthrows AMQException
259     {
260         throw new AMQMethodNotImplementedException(body);
261     }
262 
263     public boolean dispatchBasicPublish(BasicPublishBody body, int channelIdthrows AMQException
264     {
265         throw new AMQMethodNotImplementedException(body);
266     }
267 
268     public boolean dispatchBasicQos(BasicQosBody body, int channelIdthrows AMQException
269     {
270         throw new AMQMethodNotImplementedException(body);
271     }
272 
273     public boolean dispatchBasicRecover(BasicRecoverBody body, int channelIdthrows AMQException
274     {
275         throw new AMQMethodNotImplementedException(body);
276     }
277 
278     public boolean dispatchBasicReject(BasicRejectBody body, int channelIdthrows AMQException
279     {
280         throw new AMQMethodNotImplementedException(body);
281     }
282 
283     public boolean dispatchChannelOpen(ChannelOpenBody body, int channelIdthrows AMQException
284     {
285         throw new AMQMethodNotImplementedException(body);
286     }
287 
288     public boolean dispatchConnectionOpen(ConnectionOpenBody body, int channelIdthrows AMQException
289     {
290         throw new AMQMethodNotImplementedException(body);
291     }
292 
293     public boolean dispatchConnectionSecureOk(ConnectionSecureOkBody body, int channelIdthrows AMQException
294     {
295         throw new AMQMethodNotImplementedException(body);
296     }
297 
298     public boolean dispatchConnectionStartOk(ConnectionStartOkBody body, int channelIdthrows AMQException
299     {
300         throw new AMQMethodNotImplementedException(body);
301     }
302 
303     public boolean dispatchConnectionTuneOk(ConnectionTuneOkBody body, int channelIdthrows AMQException
304     {
305         throw new AMQMethodNotImplementedException(body);
306     }
307 
308     public boolean dispatchDtxSelect(DtxSelectBody body, int channelIdthrows AMQException
309     {
310         throw new AMQMethodNotImplementedException(body);
311     }
312 
313     public boolean dispatchDtxStart(DtxStartBody body, int channelIdthrows AMQException
314     {
315         throw new AMQMethodNotImplementedException(body);
316     }
317 
318     public boolean dispatchExchangeBound(ExchangeBoundBody body, int channelIdthrows AMQException
319     {
320         throw new AMQMethodNotImplementedException(body);
321     }
322 
323     public boolean dispatchExchangeDeclare(ExchangeDeclareBody body, int channelIdthrows AMQException
324     {
325         throw new AMQMethodNotImplementedException(body);
326     }
327 
328     public boolean dispatchExchangeDelete(ExchangeDeleteBody body, int channelIdthrows AMQException
329     {
330         throw new AMQMethodNotImplementedException(body);
331     }
332 
333     public boolean dispatchFileAck(FileAckBody body, int channelIdthrows AMQException
334     {
335         throw new AMQMethodNotImplementedException(body);
336     }
337 
338     public boolean dispatchFileCancel(FileCancelBody body, int channelIdthrows AMQException
339     {
340         throw new AMQMethodNotImplementedException(body);
341     }
342 
343     public boolean dispatchFileConsume(FileConsumeBody body, int channelIdthrows AMQException
344     {
345         throw new AMQMethodNotImplementedException(body);
346     }
347 
348     public boolean dispatchFilePublish(FilePublishBody body, int channelIdthrows AMQException
349     {
350         throw new AMQMethodNotImplementedException(body);
351     }
352 
353     public boolean dispatchFileQos(FileQosBody body, int channelIdthrows AMQException
354     {
355         throw new AMQMethodNotImplementedException(body);
356     }
357 
358     public boolean dispatchFileReject(FileRejectBody body, int channelIdthrows AMQException
359     {
360         throw new AMQMethodNotImplementedException(body);
361     }
362 
363     public boolean dispatchQueueBind(QueueBindBody body, int channelIdthrows AMQException
364     {
365         throw new AMQMethodNotImplementedException(body);
366     }
367 
368     public boolean dispatchQueueDeclare(QueueDeclareBody body, int channelIdthrows AMQException
369     {
370         throw new AMQMethodNotImplementedException(body);
371     }
372 
373     public boolean dispatchQueueDelete(QueueDeleteBody body, int channelIdthrows AMQException
374     {
375         throw new AMQMethodNotImplementedException(body);
376     }
377 
378     public boolean dispatchQueuePurge(QueuePurgeBody body, int channelIdthrows AMQException
379     {
380         throw new AMQMethodNotImplementedException(body);
381     }
382 
383     public boolean dispatchStreamCancel(StreamCancelBody body, int channelIdthrows AMQException
384     {
385         throw new AMQMethodNotImplementedException(body);
386     }
387 
388     public boolean dispatchStreamConsume(StreamConsumeBody body, int channelIdthrows AMQException
389     {
390         throw new AMQMethodNotImplementedException(body);
391     }
392 
393     public boolean dispatchStreamPublish(StreamPublishBody body, int channelIdthrows AMQException
394     {
395         throw new AMQMethodNotImplementedException(body);
396     }
397 
398     public boolean dispatchStreamQos(StreamQosBody body, int channelIdthrows AMQException
399     {
400         throw new AMQMethodNotImplementedException(body);
401     }
402 
403     public boolean dispatchTunnelRequest(TunnelRequestBody body, int channelIdthrows AMQException
404     {
405         throw new AMQMethodNotImplementedException(body);
406     }
407 
408     public boolean dispatchTxCommit(TxCommitBody body, int channelIdthrows AMQException
409     {
410         throw new AMQMethodNotImplementedException(body);
411     }
412 
413     public boolean dispatchTxRollback(TxRollbackBody body, int channelIdthrows AMQException
414     {
415         throw new AMQMethodNotImplementedException(body);
416     }
417 
418     public boolean dispatchTxSelect(TxSelectBody body, int channelIdthrows AMQException
419     {
420         throw new AMQMethodNotImplementedException(body);
421     }
422 
423     public boolean dispatchDtxSelectOk(DtxSelectOkBody body, int channelIdthrows AMQException
424     {
425         throw new AMQMethodNotImplementedException(body);
426     }
427 
428     public boolean dispatchDtxStartOk(DtxStartOkBody body, int channelIdthrows AMQException
429     {
430         throw new AMQMethodNotImplementedException(body);
431     }
432 
433     public boolean dispatchExchangeBoundOk(ExchangeBoundOkBody body, int channelIdthrows AMQException
434     {
435         _exchangeBoundOkMethodHandler.methodReceived(_session, body, channelId);
436         return true;
437     }
438 
439     public boolean dispatchExchangeDeclareOk(ExchangeDeclareOkBody body, int channelIdthrows AMQException
440     {
441         return false;
442     }
443 
444     public boolean dispatchExchangeDeleteOk(ExchangeDeleteOkBody body, int channelIdthrows AMQException
445     {
446         return false;
447     }
448 
449     public boolean dispatchFileCancelOk(FileCancelOkBody body, int channelIdthrows AMQException
450     {
451         throw new AMQMethodNotImplementedException(body);
452     }
453 
454     public boolean dispatchFileConsumeOk(FileConsumeOkBody body, int channelIdthrows AMQException
455     {
456         throw new AMQMethodNotImplementedException(body);
457     }
458 
459     public boolean dispatchFileDeliver(FileDeliverBody body, int channelIdthrows AMQException
460     {
461         throw new AMQMethodNotImplementedException(body);
462     }
463 
464     public boolean dispatchFileOpen(FileOpenBody body, int channelIdthrows AMQException
465     {
466         throw new AMQMethodNotImplementedException(body);
467     }
468 
469     public boolean dispatchFileOpenOk(FileOpenOkBody body, int channelIdthrows AMQException
470     {
471         throw new AMQMethodNotImplementedException(body);
472     }
473 
474     public boolean dispatchFileQosOk(FileQosOkBody body, int channelIdthrows AMQException
475     {
476         throw new AMQMethodNotImplementedException(body);
477     }
478 
479     public boolean dispatchFileReturn(FileReturnBody body, int channelIdthrows AMQException
480     {
481         throw new AMQMethodNotImplementedException(body);
482     }
483 
484     public boolean dispatchFileStage(FileStageBody body, int channelIdthrows AMQException
485     {
486         throw new AMQMethodNotImplementedException(body);
487     }
488 
489     public boolean dispatchQueueBindOk(QueueBindOkBody body, int channelIdthrows AMQException
490     {
491         return false;
492     }
493 
494     public boolean dispatchQueueDeclareOk(QueueDeclareOkBody body, int channelIdthrows AMQException
495     {
496         return false;
497     }
498 
499     public boolean dispatchStreamDeliver(StreamDeliverBody body, int channelIdthrows AMQException
500     {
501         throw new AMQMethodNotImplementedException(body);
502     }
503 
504     public boolean dispatchStreamQosOk(StreamQosOkBody body, int channelIdthrows AMQException
505     {
506         throw new AMQMethodNotImplementedException(body);
507     }
508 
509     public boolean dispatchStreamReturn(StreamReturnBody body, int channelIdthrows AMQException
510     {
511         throw new AMQMethodNotImplementedException(body);
512     }
513 
514     public boolean dispatchTxCommitOk(TxCommitOkBody body, int channelIdthrows AMQException
515     {
516         return false;
517     }
518 
519     public boolean dispatchTxRollbackOk(TxRollbackOkBody body, int channelIdthrows AMQException
520     {
521         return false;
522     }
523 
524     public boolean dispatchTxSelectOk(TxSelectOkBody body, int channelIdthrows AMQException
525     {
526         return false;
527     }
528 
529 }