ServerMethodDispatcherImpl.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.server.handler;
022 
023 import java.util.Map;
024 import java.util.HashMap;
025 
026 import org.apache.qpid.server.state.AMQStateManager;
027 import org.apache.qpid.framing.*;
028 import org.apache.qpid.AMQException;
029 
030 public class ServerMethodDispatcherImpl implements MethodDispatcher
031 {
032     private final AMQStateManager _stateManager;
033 
034     private static interface DispatcherFactory
035         {
036             public MethodDispatcher createMethodDispatcher(AMQStateManager stateManager);
037         }
038 
039         private static final Map<ProtocolVersion, DispatcherFactory> _dispatcherFactories =
040                 new HashMap<ProtocolVersion, DispatcherFactory>();
041 
042 
043     static
044         {
045             _dispatcherFactories.put(ProtocolVersion.v8_0,
046                                      new DispatcherFactory()
047                                      {
048                                          public MethodDispatcher createMethodDispatcher(AMQStateManager stateManager)
049                                          {
050                                              return new ServerMethodDispatcherImpl_8_0(stateManager);
051                                          }
052                                      });
053 
054             _dispatcherFactories.put(ProtocolVersion.v0_9,
055                                      new DispatcherFactory()
056                                      {
057                                          public MethodDispatcher createMethodDispatcher(AMQStateManager stateManager)
058                                          {
059                                              return new ServerMethodDispatcherImpl_0_9(stateManager);
060                                          }
061                                      });
062 
063         }
064 
065 
066     private static final AccessRequestHandler _accessRequestHandler = AccessRequestHandler.getInstance();
067     private static final ChannelCloseHandler _channelCloseHandler = ChannelCloseHandler.getInstance();
068     private static final ChannelOpenHandler _channelOpenHandler = ChannelOpenHandler.getInstance();
069     private static final ChannelCloseOkHandler _channelCloseOkHandler = ChannelCloseOkHandler.getInstance();
070     private static final ConnectionCloseMethodHandler _connectionCloseMethodHandler = ConnectionCloseMethodHandler.getInstance();
071     private static final ConnectionCloseOkMethodHandler _connectionCloseOkMethodHandler = ConnectionCloseOkMethodHandler.getInstance();
072     private static final ConnectionOpenMethodHandler _connectionOpenMethodHandler = ConnectionOpenMethodHandler.getInstance();
073     private static final ConnectionTuneOkMethodHandler _connectionTuneOkMethodHandler = ConnectionTuneOkMethodHandler.getInstance();
074     private static final ConnectionSecureOkMethodHandler _connectionSecureOkMethodHandler = ConnectionSecureOkMethodHandler.getInstance();
075     private static final ConnectionStartOkMethodHandler _connectionStartOkMethodHandler = ConnectionStartOkMethodHandler.getInstance();
076     private static final ExchangeDeclareHandler _exchangeDeclareHandler = ExchangeDeclareHandler.getInstance();
077     private static final ExchangeDeleteHandler _exchangeDeleteHandler = ExchangeDeleteHandler.getInstance();
078     private static final ExchangeBoundHandler _exchangeBoundHandler = ExchangeBoundHandler.getInstance();
079     private static final BasicAckMethodHandler _basicAckMethodHandler = BasicAckMethodHandler.getInstance();
080     private static final BasicRecoverMethodHandler _basicRecoverMethodHandler = BasicRecoverMethodHandler.getInstance();
081     private static final BasicConsumeMethodHandler _basicConsumeMethodHandler = BasicConsumeMethodHandler.getInstance();
082     private static final BasicGetMethodHandler _basicGetMethodHandler = BasicGetMethodHandler.getInstance();
083     private static final BasicCancelMethodHandler _basicCancelMethodHandler = BasicCancelMethodHandler.getInstance();
084     private static final BasicPublishMethodHandler _basicPublishMethodHandler = BasicPublishMethodHandler.getInstance();
085     private static final BasicQosHandler _basicQosHandler = BasicQosHandler.getInstance();
086     private static final QueueBindHandler _queueBindHandler = QueueBindHandler.getInstance();
087     private static final QueueDeclareHandler _queueDeclareHandler = QueueDeclareHandler.getInstance();
088     private static final QueueDeleteHandler _queueDeleteHandler = QueueDeleteHandler.getInstance();
089     private static final QueuePurgeHandler _queuePurgeHandler = QueuePurgeHandler.getInstance();
090     private static final ChannelFlowHandler _channelFlowHandler = ChannelFlowHandler.getInstance();
091     private static final TxSelectHandler _txSelectHandler = TxSelectHandler.getInstance();
092     private static final TxCommitHandler _txCommitHandler = TxCommitHandler.getInstance();
093     private static final TxRollbackHandler _txRollbackHandler = TxRollbackHandler.getInstance();
094     private static final BasicRejectMethodHandler _basicRejectMethodHandler = BasicRejectMethodHandler.getInstance();
095 
096 
097 
098     public static MethodDispatcher createMethodDispatcher(AMQStateManager stateManager, ProtocolVersion protocolVersion)
099     {
100         return _dispatcherFactories.get(protocolVersion).createMethodDispatcher(stateManager);
101     }
102 
103 
104     public ServerMethodDispatcherImpl(AMQStateManager stateManager)
105     {
106         _stateManager = stateManager;
107     }
108 
109 
110     protected AMQStateManager getStateManager()
111     {
112         return _stateManager;
113     }
114     
115 
116 
117     public boolean dispatchAccessRequest(AccessRequestBody body, int channelIdthrows AMQException
118     {
119         _accessRequestHandler.methodReceived(_stateManager, body, channelId);
120         return true;
121     }
122 
123     public boolean dispatchBasicAck(BasicAckBody body, int channelIdthrows AMQException
124     {
125         _basicAckMethodHandler.methodReceived(_stateManager, body, channelId);
126         return true;
127     }
128 
129     public boolean dispatchBasicCancel(BasicCancelBody body, int channelIdthrows AMQException
130     {
131         _basicCancelMethodHandler.methodReceived(_stateManager, body, channelId);
132         return true;
133     }
134 
135     public boolean dispatchBasicConsume(BasicConsumeBody body, int channelIdthrows AMQException
136     {
137         _basicConsumeMethodHandler.methodReceived(_stateManager, body, channelId);
138         return true;
139     }
140 
141     public boolean dispatchBasicGet(BasicGetBody body, int channelIdthrows AMQException
142     {
143         _basicGetMethodHandler.methodReceived(_stateManager, body, channelId);
144         return true;
145     }
146 
147     public boolean dispatchBasicPublish(BasicPublishBody body, int channelIdthrows AMQException
148     {
149         _basicPublishMethodHandler.methodReceived(_stateManager, body, channelId);
150         return true;
151     }
152 
153     public boolean dispatchBasicQos(BasicQosBody body, int channelIdthrows AMQException
154     {
155         _basicQosHandler.methodReceived(_stateManager, body, channelId);
156         return true;
157     }
158 
159     public boolean dispatchBasicRecover(BasicRecoverBody body, int channelIdthrows AMQException
160     {
161         _basicRecoverMethodHandler.methodReceived(_stateManager, body, channelId);
162         return true;
163     }
164 
165     public boolean dispatchBasicReject(BasicRejectBody body, int channelIdthrows AMQException
166     {
167         _basicRejectMethodHandler.methodReceived(_stateManager, body, channelId);
168         return true;
169     }
170 
171     public boolean dispatchChannelOpen(ChannelOpenBody body, int channelIdthrows AMQException
172     {
173         _channelOpenHandler.methodReceived(_stateManager, body, channelId);
174         return true;
175     }
176 
177 
178     public boolean dispatchAccessRequestOk(AccessRequestOkBody body, int channelIdthrows AMQException
179     {
180         throw new UnexpectedMethodException(body);
181     }
182 
183     public boolean dispatchBasicCancelOk(BasicCancelOkBody body, int channelIdthrows AMQException
184     {
185         throw new UnexpectedMethodException(body);
186     }
187 
188     public boolean dispatchBasicConsumeOk(BasicConsumeOkBody body, int channelIdthrows AMQException
189     {
190         throw new UnexpectedMethodException(body);
191     }
192 
193     public boolean dispatchBasicDeliver(BasicDeliverBody body, int channelIdthrows AMQException
194     {
195         throw new UnexpectedMethodException(body);
196     }
197 
198     public boolean dispatchBasicGetEmpty(BasicGetEmptyBody body, int channelIdthrows AMQException
199     {
200         throw new UnexpectedMethodException(body);
201     }
202 
203     public boolean dispatchBasicGetOk(BasicGetOkBody body, int channelIdthrows AMQException
204     {
205         throw new UnexpectedMethodException(body);
206     }
207 
208     public boolean dispatchBasicQosOk(BasicQosOkBody body, int channelIdthrows AMQException
209     {
210         throw new UnexpectedMethodException(body);
211     }
212 
213     public boolean dispatchBasicReturn(BasicReturnBody body, int channelIdthrows AMQException
214     {
215         throw new UnexpectedMethodException(body);
216     }
217 
218     public boolean dispatchChannelClose(ChannelCloseBody body, int channelIdthrows AMQException
219     {
220         _channelCloseHandler.methodReceived(_stateManager, body, channelId);
221         return true;
222     }
223 
224 
225     public boolean dispatchChannelCloseOk(ChannelCloseOkBody body, int channelIdthrows AMQException
226     {
227         _channelCloseOkHandler.methodReceived(_stateManager, body, channelId);
228         return true;
229     }
230 
231 
232     public boolean dispatchChannelFlow(ChannelFlowBody body, int channelIdthrows AMQException
233     {
234         _channelFlowHandler.methodReceived(_stateManager, body, channelId);
235         return true;
236     }
237 
238     public boolean dispatchChannelFlowOk(ChannelFlowOkBody body, int channelIdthrows AMQException
239     {
240         throw new UnexpectedMethodException(body);
241     }
242 
243     public boolean dispatchChannelOpenOk(ChannelOpenOkBody body, int channelIdthrows AMQException
244     {
245         throw new UnexpectedMethodException(body);
246     }
247 
248 
249     public boolean dispatchConnectionOpen(ConnectionOpenBody body, int channelIdthrows AMQException
250     {
251         _connectionOpenMethodHandler.methodReceived(_stateManager, body, channelId);
252         return true;
253     }
254 
255 
256     public boolean dispatchConnectionClose(ConnectionCloseBody body, int channelIdthrows AMQException
257     {
258         _connectionCloseMethodHandler.methodReceived(_stateManager, body, channelId);
259         return true;
260     }
261 
262 
263     public boolean dispatchConnectionCloseOk(ConnectionCloseOkBody body, int channelIdthrows AMQException
264     {
265         _connectionCloseOkMethodHandler.methodReceived(_stateManager, body, channelId);
266         return true;
267     }
268 
269     public boolean dispatchConnectionOpenOk(ConnectionOpenOkBody body, int channelIdthrows AMQException
270     {
271         throw new UnexpectedMethodException(body);
272     }
273 
274     public boolean dispatchConnectionRedirect(ConnectionRedirectBody body, int channelIdthrows AMQException
275     {
276         throw new UnexpectedMethodException(body);
277     }
278 
279     public boolean dispatchConnectionSecure(ConnectionSecureBody body, int channelIdthrows AMQException
280     {
281         throw new UnexpectedMethodException(body);
282     }
283 
284     public boolean dispatchConnectionStart(ConnectionStartBody body, int channelIdthrows AMQException
285     {
286         throw new UnexpectedMethodException(body);
287     }
288 
289     public boolean dispatchConnectionTune(ConnectionTuneBody body, int channelIdthrows AMQException
290     {
291         throw new UnexpectedMethodException(body);
292     }
293 
294     public boolean dispatchDtxSelectOk(DtxSelectOkBody body, int channelIdthrows AMQException
295     {
296         throw new UnexpectedMethodException(body);
297     }
298 
299     public boolean dispatchDtxStartOk(DtxStartOkBody body, int channelIdthrows AMQException
300     {
301         throw new UnexpectedMethodException(body);
302     }
303 
304     public boolean dispatchExchangeBoundOk(ExchangeBoundOkBody body, int channelIdthrows AMQException
305     {
306         throw new UnexpectedMethodException(body);
307     }
308 
309     public boolean dispatchExchangeDeclareOk(ExchangeDeclareOkBody body, int channelIdthrows AMQException
310     {
311         throw new UnexpectedMethodException(body);
312     }
313 
314     public boolean dispatchExchangeDeleteOk(ExchangeDeleteOkBody body, int channelIdthrows AMQException
315     {
316         throw new UnexpectedMethodException(body);
317     }
318 
319     public boolean dispatchFileCancelOk(FileCancelOkBody body, int channelIdthrows AMQException
320     {
321         throw new UnexpectedMethodException(body);
322     }
323 
324     public boolean dispatchFileConsumeOk(FileConsumeOkBody body, int channelIdthrows AMQException
325     {
326         throw new UnexpectedMethodException(body);
327     }
328 
329     public boolean dispatchFileDeliver(FileDeliverBody body, int channelIdthrows AMQException
330     {
331         throw new UnexpectedMethodException(body);
332     }
333 
334     public boolean dispatchFileOpen(FileOpenBody body, int channelIdthrows AMQException
335     {
336         throw new UnexpectedMethodException(body);
337     }
338 
339     public boolean dispatchFileOpenOk(FileOpenOkBody body, int channelIdthrows AMQException
340     {
341         throw new UnexpectedMethodException(body);
342     }
343 
344     public boolean dispatchFileQosOk(FileQosOkBody body, int channelIdthrows AMQException
345     {
346         throw new UnexpectedMethodException(body);
347     }
348 
349     public boolean dispatchFileReturn(FileReturnBody body, int channelIdthrows AMQException
350     {
351         throw new UnexpectedMethodException(body);
352     }
353 
354     public boolean dispatchFileStage(FileStageBody body, int channelIdthrows AMQException
355     {
356         throw new UnexpectedMethodException(body);
357     }
358 
359     public boolean dispatchQueueBindOk(QueueBindOkBody body, int channelIdthrows AMQException
360     {
361         throw new UnexpectedMethodException(body);
362     }
363 
364     public boolean dispatchQueueDeclareOk(QueueDeclareOkBody body, int channelIdthrows AMQException
365     {
366         throw new UnexpectedMethodException(body);
367     }
368 
369     public boolean dispatchQueueDeleteOk(QueueDeleteOkBody body, int channelIdthrows AMQException
370     {
371         throw new UnexpectedMethodException(body);
372     }
373 
374     public boolean dispatchQueuePurgeOk(QueuePurgeOkBody body, int channelIdthrows AMQException
375     {
376         throw new UnexpectedMethodException(body);
377     }
378 
379     public boolean dispatchStreamCancelOk(StreamCancelOkBody body, int channelIdthrows AMQException
380     {
381         throw new UnexpectedMethodException(body);
382     }
383 
384     public boolean dispatchStreamConsumeOk(StreamConsumeOkBody body, int channelIdthrows AMQException
385     {
386         throw new UnexpectedMethodException(body);
387     }
388 
389     public boolean dispatchStreamDeliver(StreamDeliverBody body, int channelIdthrows AMQException
390     {
391         throw new UnexpectedMethodException(body);
392     }
393 
394     public boolean dispatchStreamQosOk(StreamQosOkBody body, int channelIdthrows AMQException
395     {
396         throw new UnexpectedMethodException(body);
397     }
398 
399     public boolean dispatchStreamReturn(StreamReturnBody body, int channelIdthrows AMQException
400     {
401         throw new UnexpectedMethodException(body);
402     }
403 
404     public boolean dispatchTxCommitOk(TxCommitOkBody body, int channelIdthrows AMQException
405     {
406         throw new UnexpectedMethodException(body);
407     }
408 
409     public boolean dispatchTxRollbackOk(TxRollbackOkBody body, int channelIdthrows AMQException
410     {
411         throw new UnexpectedMethodException(body);
412     }
413 
414     public boolean dispatchTxSelectOk(TxSelectOkBody body, int channelIdthrows AMQException
415     {
416         throw new UnexpectedMethodException(body);
417     }
418 
419 
420     public boolean dispatchConnectionSecureOk(ConnectionSecureOkBody body, int channelIdthrows AMQException
421     {
422         _connectionSecureOkMethodHandler.methodReceived(_stateManager, body, channelId);
423         return true;
424     }
425 
426     public boolean dispatchConnectionStartOk(ConnectionStartOkBody body, int channelIdthrows AMQException
427     {
428         _connectionStartOkMethodHandler.methodReceived(_stateManager, body, channelId);
429         return true;
430     }
431 
432     public boolean dispatchConnectionTuneOk(ConnectionTuneOkBody body, int channelIdthrows AMQException
433     {
434         _connectionTuneOkMethodHandler.methodReceived(_stateManager, body, channelId);
435         return true;
436     }
437 
438     public boolean dispatchDtxSelect(DtxSelectBody body, int channelIdthrows AMQException
439     {
440         return false;
441     }
442 
443     public boolean dispatchDtxStart(DtxStartBody body, int channelIdthrows AMQException
444     {
445         return false;
446     }
447 
448     public boolean dispatchExchangeBound(ExchangeBoundBody body, int channelIdthrows AMQException
449     {
450         _exchangeBoundHandler.methodReceived(_stateManager, body, channelId);
451         return true;
452     }
453 
454     public boolean dispatchExchangeDeclare(ExchangeDeclareBody body, int channelIdthrows AMQException
455     {
456         _exchangeDeclareHandler.methodReceived(_stateManager, body, channelId);
457         return true;
458     }
459 
460     public boolean dispatchExchangeDelete(ExchangeDeleteBody body, int channelIdthrows AMQException
461     {
462         _exchangeDeleteHandler.methodReceived(_stateManager, body, channelId);
463         return true;
464     }
465 
466     public boolean dispatchFileAck(FileAckBody body, int channelIdthrows AMQException
467     {
468         return false;
469     }
470 
471     public boolean dispatchFileCancel(FileCancelBody body, int channelIdthrows AMQException
472     {
473         return false;
474     }
475 
476     public boolean dispatchFileConsume(FileConsumeBody body, int channelIdthrows AMQException
477     {
478         return false;
479     }
480 
481     public boolean dispatchFilePublish(FilePublishBody body, int channelIdthrows AMQException
482     {
483         return false;
484     }
485 
486     public boolean dispatchFileQos(FileQosBody body, int channelIdthrows AMQException
487     {
488         return false;
489     }
490 
491     public boolean dispatchFileReject(FileRejectBody body, int channelIdthrows AMQException
492     {
493         return false;
494     }
495 
496     public boolean dispatchQueueBind(QueueBindBody body, int channelIdthrows AMQException
497     {
498         _queueBindHandler.methodReceived(_stateManager, body, channelId);
499         return true;
500     }
501 
502     public boolean dispatchQueueDeclare(QueueDeclareBody body, int channelIdthrows AMQException
503     {
504         _queueDeclareHandler.methodReceived(_stateManager, body, channelId);
505         return true;
506     }
507 
508     public boolean dispatchQueueDelete(QueueDeleteBody body, int channelIdthrows AMQException
509     {
510         _queueDeleteHandler.methodReceived(_stateManager, body, channelId);
511         return true;
512     }
513 
514     public boolean dispatchQueuePurge(QueuePurgeBody body, int channelIdthrows AMQException
515     {
516         _queuePurgeHandler.methodReceived(_stateManager, body, channelId);
517         return true;
518     }
519 
520     public boolean dispatchStreamCancel(StreamCancelBody body, int channelIdthrows AMQException
521     {
522         return false;
523     }
524 
525     public boolean dispatchStreamConsume(StreamConsumeBody body, int channelIdthrows AMQException
526     {
527         return false;
528     }
529 
530     public boolean dispatchStreamPublish(StreamPublishBody body, int channelIdthrows AMQException
531     {
532         return false;
533     }
534 
535     public boolean dispatchStreamQos(StreamQosBody body, int channelIdthrows AMQException
536     {
537         return false;
538     }
539 
540     public boolean dispatchTunnelRequest(TunnelRequestBody body, int channelIdthrows AMQException
541     {
542         return false;
543     }
544 
545     public boolean dispatchTxCommit(TxCommitBody body, int channelIdthrows AMQException
546     {
547         _txCommitHandler.methodReceived(_stateManager, body, channelId);
548         return true;
549     }
550 
551     public boolean dispatchTxRollback(TxRollbackBody body, int channelIdthrows AMQException
552     {
553         _txRollbackHandler.methodReceived(_stateManager, body, channelId);
554         return true;
555     }
556 
557     public boolean dispatchTxSelect(TxSelectBody body, int channelIdthrows AMQException
558     {
559         _txSelectHandler.methodReceived(_stateManager, body, channelId);
560         return true;
561     }
562 
563 
564 
565 
566 }