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 channelId) throws AMQException
107 {
108 return false;
109 }
110
111 public boolean dispatchBasicCancelOk(BasicCancelOkBody body, int channelId) throws AMQException
112 {
113 _basicCancelOkMethodHandler.methodReceived(_session, body, channelId);
114 return true;
115 }
116
117 public boolean dispatchBasicConsumeOk(BasicConsumeOkBody body, int channelId) throws AMQException
118 {
119 return false;
120 }
121
122 public boolean dispatchBasicDeliver(BasicDeliverBody body, int channelId) throws AMQException
123 {
124 _basicDeliverMethodHandler.methodReceived(_session, body, channelId);
125 return true;
126 }
127
128 public boolean dispatchBasicGetEmpty(BasicGetEmptyBody body, int channelId) throws AMQException
129 {
130 return false;
131 }
132
133 public boolean dispatchBasicGetOk(BasicGetOkBody body, int channelId) throws AMQException
134 {
135 return false;
136 }
137
138 public boolean dispatchBasicQosOk(BasicQosOkBody body, int channelId) throws AMQException
139 {
140 return false;
141 }
142
143 public boolean dispatchBasicReturn(BasicReturnBody body, int channelId) throws AMQException
144 {
145 _basicReturnMethodHandler.methodReceived(_session, body, channelId);
146 return true;
147 }
148
149 public boolean dispatchChannelClose(ChannelCloseBody body, int channelId) throws AMQException
150 {
151 _channelCloseMethodHandler.methodReceived(_session, body, channelId);
152 return true;
153 }
154
155 public boolean dispatchChannelCloseOk(ChannelCloseOkBody body, int channelId) throws AMQException
156 {
157 return false;
158 }
159
160 public boolean dispatchChannelFlow(ChannelFlowBody body, int channelId) throws AMQException
161 {
162 return false;
163 }
164
165 public boolean dispatchChannelFlowOk(ChannelFlowOkBody body, int channelId) throws AMQException
166 {
167 _channelFlowOkMethodHandler.methodReceived(_session, body, channelId);
168 return true;
169 }
170
171 public boolean dispatchChannelOpenOk(ChannelOpenOkBody body, int channelId) throws AMQException
172 {
173 return false;
174 }
175
176 public boolean dispatchConnectionClose(ConnectionCloseBody body, int channelId) throws AMQException
177 {
178 _connectionCloseMethodHandler.methodReceived(_session, body, channelId);
179 return true;
180 }
181
182 public boolean dispatchConnectionCloseOk(ConnectionCloseOkBody body, int channelId) throws AMQException
183 {
184 return false;
185 }
186
187 public boolean dispatchConnectionOpenOk(ConnectionOpenOkBody body, int channelId) throws AMQException
188 {
189 _connectionOpenOkMethodHandler.methodReceived(_session, body, channelId);
190 return true;
191 }
192
193 public boolean dispatchConnectionRedirect(ConnectionRedirectBody body, int channelId) throws AMQException
194 {
195 _connectionRedirectMethodHandler.methodReceived(_session, body, channelId);
196 return true;
197 }
198
199 public boolean dispatchConnectionSecure(ConnectionSecureBody body, int channelId) throws AMQException
200 {
201 _connectionSecureMethodHandler.methodReceived(_session, body, channelId);
202 return true;
203 }
204
205 public boolean dispatchConnectionStart(ConnectionStartBody body, int channelId) throws AMQException
206 {
207 _connectionStartMethodHandler.methodReceived(_session, body, channelId);
208 return true;
209 }
210
211 public boolean dispatchConnectionTune(ConnectionTuneBody body, int channelId) throws AMQException
212 {
213 _connectionTuneMethodHandler.methodReceived(_session, body, channelId);
214 return true;
215 }
216
217 public boolean dispatchQueueDeleteOk(QueueDeleteOkBody body, int channelId) throws AMQException
218 {
219 _queueDeleteOkMethodHandler.methodReceived(_session, body, channelId);
220 return true;
221 }
222
223 public boolean dispatchQueuePurgeOk(QueuePurgeOkBody body, int channelId) throws AMQException
224 {
225 return false;
226 }
227
228 public boolean dispatchStreamCancelOk(StreamCancelOkBody body, int channelId) throws AMQException
229 {
230 return false;
231 }
232
233 public boolean dispatchStreamConsumeOk(StreamConsumeOkBody body, int channelId) throws AMQException
234 {
235 return false;
236 }
237
238 public boolean dispatchAccessRequest(AccessRequestBody body, int channelId) throws AMQException
239 {
240 throw new AMQMethodNotImplementedException(body);
241 }
242
243 public boolean dispatchBasicAck(BasicAckBody body, int channelId) throws AMQException
244 {
245 throw new AMQMethodNotImplementedException(body);
246 }
247
248 public boolean dispatchBasicCancel(BasicCancelBody body, int channelId) throws AMQException
249 {
250 throw new AMQMethodNotImplementedException(body);
251 }
252
253 public boolean dispatchBasicConsume(BasicConsumeBody body, int channelId) throws AMQException
254 {
255 throw new AMQMethodNotImplementedException(body);
256 }
257
258 public boolean dispatchBasicGet(BasicGetBody body, int channelId) throws AMQException
259 {
260 throw new AMQMethodNotImplementedException(body);
261 }
262
263 public boolean dispatchBasicPublish(BasicPublishBody body, int channelId) throws AMQException
264 {
265 throw new AMQMethodNotImplementedException(body);
266 }
267
268 public boolean dispatchBasicQos(BasicQosBody body, int channelId) throws AMQException
269 {
270 throw new AMQMethodNotImplementedException(body);
271 }
272
273 public boolean dispatchBasicRecover(BasicRecoverBody body, int channelId) throws AMQException
274 {
275 throw new AMQMethodNotImplementedException(body);
276 }
277
278 public boolean dispatchBasicReject(BasicRejectBody body, int channelId) throws AMQException
279 {
280 throw new AMQMethodNotImplementedException(body);
281 }
282
283 public boolean dispatchChannelOpen(ChannelOpenBody body, int channelId) throws AMQException
284 {
285 throw new AMQMethodNotImplementedException(body);
286 }
287
288 public boolean dispatchConnectionOpen(ConnectionOpenBody body, int channelId) throws AMQException
289 {
290 throw new AMQMethodNotImplementedException(body);
291 }
292
293 public boolean dispatchConnectionSecureOk(ConnectionSecureOkBody body, int channelId) throws AMQException
294 {
295 throw new AMQMethodNotImplementedException(body);
296 }
297
298 public boolean dispatchConnectionStartOk(ConnectionStartOkBody body, int channelId) throws AMQException
299 {
300 throw new AMQMethodNotImplementedException(body);
301 }
302
303 public boolean dispatchConnectionTuneOk(ConnectionTuneOkBody body, int channelId) throws AMQException
304 {
305 throw new AMQMethodNotImplementedException(body);
306 }
307
308 public boolean dispatchDtxSelect(DtxSelectBody body, int channelId) throws AMQException
309 {
310 throw new AMQMethodNotImplementedException(body);
311 }
312
313 public boolean dispatchDtxStart(DtxStartBody body, int channelId) throws AMQException
314 {
315 throw new AMQMethodNotImplementedException(body);
316 }
317
318 public boolean dispatchExchangeBound(ExchangeBoundBody body, int channelId) throws AMQException
319 {
320 throw new AMQMethodNotImplementedException(body);
321 }
322
323 public boolean dispatchExchangeDeclare(ExchangeDeclareBody body, int channelId) throws AMQException
324 {
325 throw new AMQMethodNotImplementedException(body);
326 }
327
328 public boolean dispatchExchangeDelete(ExchangeDeleteBody body, int channelId) throws AMQException
329 {
330 throw new AMQMethodNotImplementedException(body);
331 }
332
333 public boolean dispatchFileAck(FileAckBody body, int channelId) throws AMQException
334 {
335 throw new AMQMethodNotImplementedException(body);
336 }
337
338 public boolean dispatchFileCancel(FileCancelBody body, int channelId) throws AMQException
339 {
340 throw new AMQMethodNotImplementedException(body);
341 }
342
343 public boolean dispatchFileConsume(FileConsumeBody body, int channelId) throws AMQException
344 {
345 throw new AMQMethodNotImplementedException(body);
346 }
347
348 public boolean dispatchFilePublish(FilePublishBody body, int channelId) throws AMQException
349 {
350 throw new AMQMethodNotImplementedException(body);
351 }
352
353 public boolean dispatchFileQos(FileQosBody body, int channelId) throws AMQException
354 {
355 throw new AMQMethodNotImplementedException(body);
356 }
357
358 public boolean dispatchFileReject(FileRejectBody body, int channelId) throws AMQException
359 {
360 throw new AMQMethodNotImplementedException(body);
361 }
362
363 public boolean dispatchQueueBind(QueueBindBody body, int channelId) throws AMQException
364 {
365 throw new AMQMethodNotImplementedException(body);
366 }
367
368 public boolean dispatchQueueDeclare(QueueDeclareBody body, int channelId) throws AMQException
369 {
370 throw new AMQMethodNotImplementedException(body);
371 }
372
373 public boolean dispatchQueueDelete(QueueDeleteBody body, int channelId) throws AMQException
374 {
375 throw new AMQMethodNotImplementedException(body);
376 }
377
378 public boolean dispatchQueuePurge(QueuePurgeBody body, int channelId) throws AMQException
379 {
380 throw new AMQMethodNotImplementedException(body);
381 }
382
383 public boolean dispatchStreamCancel(StreamCancelBody body, int channelId) throws AMQException
384 {
385 throw new AMQMethodNotImplementedException(body);
386 }
387
388 public boolean dispatchStreamConsume(StreamConsumeBody body, int channelId) throws AMQException
389 {
390 throw new AMQMethodNotImplementedException(body);
391 }
392
393 public boolean dispatchStreamPublish(StreamPublishBody body, int channelId) throws AMQException
394 {
395 throw new AMQMethodNotImplementedException(body);
396 }
397
398 public boolean dispatchStreamQos(StreamQosBody body, int channelId) throws AMQException
399 {
400 throw new AMQMethodNotImplementedException(body);
401 }
402
403 public boolean dispatchTunnelRequest(TunnelRequestBody body, int channelId) throws AMQException
404 {
405 throw new AMQMethodNotImplementedException(body);
406 }
407
408 public boolean dispatchTxCommit(TxCommitBody body, int channelId) throws AMQException
409 {
410 throw new AMQMethodNotImplementedException(body);
411 }
412
413 public boolean dispatchTxRollback(TxRollbackBody body, int channelId) throws AMQException
414 {
415 throw new AMQMethodNotImplementedException(body);
416 }
417
418 public boolean dispatchTxSelect(TxSelectBody body, int channelId) throws AMQException
419 {
420 throw new AMQMethodNotImplementedException(body);
421 }
422
423 public boolean dispatchDtxSelectOk(DtxSelectOkBody body, int channelId) throws AMQException
424 {
425 throw new AMQMethodNotImplementedException(body);
426 }
427
428 public boolean dispatchDtxStartOk(DtxStartOkBody body, int channelId) throws AMQException
429 {
430 throw new AMQMethodNotImplementedException(body);
431 }
432
433 public boolean dispatchExchangeBoundOk(ExchangeBoundOkBody body, int channelId) throws AMQException
434 {
435 _exchangeBoundOkMethodHandler.methodReceived(_session, body, channelId);
436 return true;
437 }
438
439 public boolean dispatchExchangeDeclareOk(ExchangeDeclareOkBody body, int channelId) throws AMQException
440 {
441 return false;
442 }
443
444 public boolean dispatchExchangeDeleteOk(ExchangeDeleteOkBody body, int channelId) throws AMQException
445 {
446 return false;
447 }
448
449 public boolean dispatchFileCancelOk(FileCancelOkBody body, int channelId) throws AMQException
450 {
451 throw new AMQMethodNotImplementedException(body);
452 }
453
454 public boolean dispatchFileConsumeOk(FileConsumeOkBody body, int channelId) throws AMQException
455 {
456 throw new AMQMethodNotImplementedException(body);
457 }
458
459 public boolean dispatchFileDeliver(FileDeliverBody body, int channelId) throws AMQException
460 {
461 throw new AMQMethodNotImplementedException(body);
462 }
463
464 public boolean dispatchFileOpen(FileOpenBody body, int channelId) throws AMQException
465 {
466 throw new AMQMethodNotImplementedException(body);
467 }
468
469 public boolean dispatchFileOpenOk(FileOpenOkBody body, int channelId) throws AMQException
470 {
471 throw new AMQMethodNotImplementedException(body);
472 }
473
474 public boolean dispatchFileQosOk(FileQosOkBody body, int channelId) throws AMQException
475 {
476 throw new AMQMethodNotImplementedException(body);
477 }
478
479 public boolean dispatchFileReturn(FileReturnBody body, int channelId) throws AMQException
480 {
481 throw new AMQMethodNotImplementedException(body);
482 }
483
484 public boolean dispatchFileStage(FileStageBody body, int channelId) throws AMQException
485 {
486 throw new AMQMethodNotImplementedException(body);
487 }
488
489 public boolean dispatchQueueBindOk(QueueBindOkBody body, int channelId) throws AMQException
490 {
491 return false;
492 }
493
494 public boolean dispatchQueueDeclareOk(QueueDeclareOkBody body, int channelId) throws AMQException
495 {
496 return false;
497 }
498
499 public boolean dispatchStreamDeliver(StreamDeliverBody body, int channelId) throws AMQException
500 {
501 throw new AMQMethodNotImplementedException(body);
502 }
503
504 public boolean dispatchStreamQosOk(StreamQosOkBody body, int channelId) throws AMQException
505 {
506 throw new AMQMethodNotImplementedException(body);
507 }
508
509 public boolean dispatchStreamReturn(StreamReturnBody body, int channelId) throws AMQException
510 {
511 throw new AMQMethodNotImplementedException(body);
512 }
513
514 public boolean dispatchTxCommitOk(TxCommitOkBody body, int channelId) throws AMQException
515 {
516 return false;
517 }
518
519 public boolean dispatchTxRollbackOk(TxRollbackOkBody body, int channelId) throws AMQException
520 {
521 return false;
522 }
523
524 public boolean dispatchTxSelectOk(TxSelectOkBody body, int channelId) throws AMQException
525 {
526 return false;
527 }
528
529 }
|