summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/broker/bin/qpid-server-bdb.bat2
-rw-r--r--java/broker/distribution/src/main/assembly/broker-bin-tests.xml2
-rw-r--r--java/broker/etc/config.xml13
-rw-r--r--java/broker/etc/log4j.xml18
-rw-r--r--java/broker/etc/virtualhosts.xml9
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java9
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/Main.java24
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/ack/UnacknowledgedMessageMapImpl.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/filter/PropertyExpression.java31
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/BasicAckMethodHandler.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/BasicCancelMethodHandler.java6
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/BasicConsumeMethodHandler.java18
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java10
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/BasicPublishMethodHandler.java8
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/BasicQosHandler.java4
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverMethodHandler.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/BasicRejectMethodHandler.java4
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ChannelCloseHandler.java4
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ChannelFlowHandler.java6
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ChannelOpenHandler.java16
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionCloseMethodHandler.java4
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionOpenMethodHandler.java8
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java52
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java20
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionTuneOkMethodHandler.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeBoundHandler.java65
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeclareHandler.java20
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeleteHandler.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/QueueBindHandler.java29
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java28
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeleteHandler.java16
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/QueuePurgeHandler.java8
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/TxRollbackHandler.java15
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/TxSelectHandler.java13
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverter.java57
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverterRegistry.java62
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/output/amqp0_8/ProtocolOutputConverterImpl.java288
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java266
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/AMQNoMethodHandlerException.java34
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/AMQPFastProtocolHandler.java15
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java3
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java26
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/UnknnownMessageTypeException.java33
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java42
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java13
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/ConcurrentSelectorDeliveryManager.java3
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/SubscriptionImpl.java16
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java30
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/state/StateAwareMethodListener.java1
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/store/ContentChunkAdapter.java57
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/store/MessagePublishInfoAdapter.java62
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnection.java58
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQSession.java359
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java33
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java159
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java6
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ChannelCloseMethodHandler.java24
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionCloseMethodHandler.java29
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionSecureMethodHandler.java28
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionTuneMethodHandler.java41
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/BasicCancelOkMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/BasicCancelOkMethodHandler.java)8
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/BasicDeliverMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/BasicDeliverMethodHandler.java)5
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/BasicReturnMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/BasicReturnMethodHandler.java)5
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ChannelCloseMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java)23
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ChannelCloseOkMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseOkMethodHandler.java)5
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ChannelFlowOkMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/ChannelFlowOkMethodHandler.java)7
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionCloseMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java)28
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionOpenOkMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/ConnectionOpenOkMethodHandler.java)5
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionRedirectMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/ConnectionRedirectMethodHandler.java)7
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionSecureMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/ConnectionSecureMethodHandler.java)24
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionStartMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java)76
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionTuneMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/ConnectionTuneMethodHandler.java)36
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ExchangeBoundOkMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/ExchangeBoundOkMethodHandler.java)9
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/QueueDeleteOkMethodHandler.java (renamed from java/client/src/main/java/org/apache/qpid/client/handler/QueueDeleteOkMethodHandler.java)7
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java12
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/JMSTextMessage.java6
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/MessageFactoryRegistry.java4
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java636
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandlerImpl.java537
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java48
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java7
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolOutputHandler.java58
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolOutputHandlerFactory.java50
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/amqp_8_0/ProtocolOutputHandler_8_0.java278
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java44
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/state/StateAwareMethodListener.java4
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java5
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/transport/ITransportConnection.java4
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/transport/SocketTransportConnection.java4
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java4
-rw-r--r--java/client/src/old_test/java/org/apache/qpid/codec/BasicDeliverTest.java14
-rw-r--r--java/client/src/old_test/java/org/apache/qpid/framing/FieldTableTest.java4
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java7
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java39
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/NoCloseOKStateManager.java20
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java4
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQConnectionWaitException.java32
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQUnexpectedBodyTypeException.java33
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQUnexpectedFrameTypeException.java31
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/BlockingHandler.java12
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/Broker.java12
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/BrokerGroup.java4
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/ClientAdapter.java4
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/ClientHandlerRegistry.java28
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/ClusteredProtocolHandler.java3
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/DefaultGroupManager.java2
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/GroupRequest.java10
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/GroupResponseHandler.java4
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/MethodHandler.java4
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/MethodHandlerRegistry.java10
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/MinaBrokerProxy.java40
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/ResponseHandler.java4
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/ServerHandlerRegistry.java8
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/SimpleBodySendable.java6
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ChainedClusterMethodHandler.java8
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ClusterMethodHandler.java6
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ClusterMethodHandlerFactory.java6
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ExtendedHandler.java7
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/NullListener.java7
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/PeerHandler.java8
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ReplicatingHandler.java6
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/WrappedListener.java9
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/WrappingMethodHandlerFactory.java6
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ChainedMethodRecorder.java4
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ConsumerCounts.java6
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/MethodRecorder.java4
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/RecordingMethodHandlerFactory.java9
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ReplayManager.java6
-rw-r--r--java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ReplayStore.java14
-rw-r--r--java/cluster/src/test/java/org/apache/qpid/server/cluster/BrokerTest.java18
-rw-r--r--java/cluster/src/test/java/org/apache/qpid/server/cluster/TestBroker.java8
-rw-r--r--java/cluster/src/test/java/org/apache/qpid/server/cluster/TestReplayManager.java10
-rw-r--r--java/common/src/main/java/org/apache/qpid/AMQChannelException.java4
-rw-r--r--java/common/src/main/java/org/apache/qpid/AMQConnectionException.java3
-rw-r--r--java/common/src/main/java/org/apache/qpid/codec/AMQDecoder.java16
-rw-r--r--java/common/src/main/java/org/apache/qpid/common/ClientProperties.java20
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQBody.java21
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQBodyImpl.java27
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java133
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyImpl.java102
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyInstanceFactory.java3
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQMethodFactory.java90
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java125
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java65
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/ContentBody.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java4
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java4
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/FieldTable.java68
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java6
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/HeartbeatBodyFactory.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/MainRegistry.java35
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/MethodConverter_8_0.java22
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java155
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/abstraction/MessagePublishInfoConverter.java3
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/abstraction/ProtocolVersionMethodConverter.java3
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/amqp_8_0/AMQMethodBody_8_0.java160
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/amqp_8_0/AMQMethodFactory_8_0.java117
-rw-r--r--java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java1
-rw-r--r--java/common/src/main/java/org/apache/qpid/protocol/AMQMethodEvent.java1
-rw-r--r--java/common/src/main/java/org/apache/qpid/protocol/AMQMethodListener.java4
-rw-r--r--java/common/src/main/java/org/apache/qpid/protocol/AMQVersionAwareProtocolSession.java4
-rw-r--r--java/common/src/main/java/org/apache/qpid/protocol/ProtocolVersionAware.java5
-rw-r--r--java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java20
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/queue/MockProtocolSession.java6
169 files changed, 3634 insertions, 2247 deletions
diff --git a/java/broker/bin/qpid-server-bdb.bat b/java/broker/bin/qpid-server-bdb.bat
index 5c8b74e163..833415cb05 100644
--- a/java/broker/bin/qpid-server-bdb.bat
+++ b/java/broker/bin/qpid-server-bdb.bat
@@ -1,3 +1,3 @@
-set BDBSTORE_HOME=c:\qpid\trunk\java\bdbstore
+set BDBSTORE_HOME=c:\qpid-bdb\bdbstore
set QPID_MODULE_JARS=%BDBSTORE_HOME%\target\qpid-bdbstore-1.0-incubating-M2-SNAPSHOT.jar;%BDBSTORE_HOME%\lib\bdb\je-3.1.0.jar
.\qpid-server.bat \ No newline at end of file
diff --git a/java/broker/distribution/src/main/assembly/broker-bin-tests.xml b/java/broker/distribution/src/main/assembly/broker-bin-tests.xml
index fa017d6232..a14360bd73 100644
--- a/java/broker/distribution/src/main/assembly/broker-bin-tests.xml
+++ b/java/broker/distribution/src/main/assembly/broker-bin-tests.xml
@@ -92,7 +92,7 @@
<source>../../common/bin/qpid-run</source>
<outputDirectory>qpid-${qpid.version}/bin</outputDirectory>
<destName>qpid-run</destName>
- <fileMode>493</fileMode>
+ <fileMode>473</fileMode>
</file>
<!-- Common Configuration -->
diff --git a/java/broker/etc/config.xml b/java/broker/etc/config.xml
index 0b4091efa5..a3a33e11c5 100644
--- a/java/broker/etc/config.xml
+++ b/java/broker/etc/config.xml
@@ -89,8 +89,8 @@
<name>localhost</name>
<localhost>
<store>
- <!-- <class>org.apache.qpid.server.store.berkeleydb.BDBMessageStore</class> -->
- <class>org.apache.qpid.server.store.MemoryMessageStore</class>
+ <class>org.apache.qpid.server.store.berkeleydb.BDBMessageStore</class>
+ <!--<class>org.apache.qpid.server.store.MemoryMessageStore</class>-->
<environment-path>localhost-store</environment-path>
</store>
</localhost>
@@ -101,7 +101,9 @@
<development>
<store>
<class>org.apache.qpid.server.store.MemoryMessageStore</class>
- </store>
+ <!--<class>org.apache.qpid.server.store.berkeleydb.BDBMessageStore</class>-->
+ <environment-path>development-store</environment-path>
+ </store>
</development>
</virtualhost>
@@ -110,7 +112,10 @@
<test>
<store>
<class>org.apache.qpid.server.store.MemoryMessageStore</class>
- </store>
+ <!--<class>org.apache.qpid.server.store.berkeleydb.BDBMessageStore</class>-->
+ <environment-path>test-store</environment-path>
+
+ </store>
</test>
</virtualhost>
diff --git a/java/broker/etc/log4j.xml b/java/broker/etc/log4j.xml
index 0cf2579137..81824fde93 100644
--- a/java/broker/etc/log4j.xml
+++ b/java/broker/etc/log4j.xml
@@ -36,20 +36,22 @@
<param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</layout>
</appender>
-
- <!--<category name="org.apache.qpid.server.store">
+ <!--
+ <category name="org.apache.qpid.server.store.StoreContext">
<priority value="debug"/>
</category>
-
- <category name="org.apache.qpid.server.queue">
+ -->
+ <!--<category name="org.apache.qpid.server.queue.AMQMessage">
<priority value="debug"/>
</category>
-
- <category name="org.apache.qpid.server.txn">
+ -->
+ <!--
+ <category name="org.apache.qpid.server.store.berkeleydb.BDBMessageStore">
<priority value="debug"/>
- </category>-->
+ </category>
+ -->
<root>
- <priority value="info"/>
+ <priority value="${AMQJ_LOGGING_LEVEL}"/>
<appender-ref ref="STDOUT"/>
<appender-ref ref="FileAppender"/>
</root>
diff --git a/java/broker/etc/virtualhosts.xml b/java/broker/etc/virtualhosts.xml
index 52ff23e090..f73399a74c 100644
--- a/java/broker/etc/virtualhosts.xml
+++ b/java/broker/etc/virtualhosts.xml
@@ -27,8 +27,13 @@
<exchanges>
<exchange>
<type>direct</type>
+
<name>test.direct</name>
- <durable>true</durable>
+ <test>
+ <direct>
+ <durable>true</durable>
+ </direct>
+ </test>
</exchange>
<exchange>
<type>topic</type>
@@ -40,7 +45,7 @@
<maximumQueueDepth>4235264</maximumQueueDepth> <!-- 4Mb -->
<maximumMessageSize>2117632</maximumMessageSize> <!-- 2Mb -->
<maximumMessageAge>600000</maximumMessageAge> <!-- 10 mins -->
-
+ <durable>true</durable>
<queue>
<name>queue</name>
</queue>
diff --git a/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java b/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
index 7ceb3a7eef..be2cee79ee 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
@@ -433,7 +433,10 @@ public class AMQChannel
}
- /** Called to resend all outstanding unacknowledged messages to this same channel. */
+ /** Called to resend all outstanding unacknowledged messages to this same channel.
+ * @param session the session
+ * @param requeue if true then requeue, else resend
+ * @throws org.apache.qpid.AMQException */
public void resend(final AMQProtocolSession session, final boolean requeue) throws AMQException
{
final List<UnacknowledgedMessage> msgToRequeue = new LinkedList<UnacknowledgedMessage>();
@@ -752,7 +755,9 @@ public class AMQChannel
for (RequiredDeliveryException bouncedMessage : _returnMessages)
{
AMQMessage message = bouncedMessage.getAMQMessage();
- message.writeReturn(session, _channelId, bouncedMessage.getReplyCode().getCode(), new AMQShortString(bouncedMessage.getMessage()));
+ session.getProtocolOutputConverter().writeReturn(message, _channelId,
+ bouncedMessage.getReplyCode().getCode(),
+ new AMQShortString(bouncedMessage.getMessage()));
}
_returnMessages.clear();
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/Main.java b/java/broker/src/main/java/org/apache/qpid/server/Main.java
index 42fe8c5274..a48bc5df7f 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/Main.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/Main.java
@@ -45,7 +45,7 @@ import org.apache.mina.common.SimpleByteBufferAllocator;
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
import org.apache.mina.transport.socket.nio.SocketSessionConfig;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.ProtocolVersionList;
+import org.apache.qpid.framing.ProtocolVersion;
import org.apache.qpid.pool.ReadWriteThreadModel;
import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.protocol.AMQPFastProtocolHandler;
@@ -59,7 +59,8 @@ import org.apache.qpid.url.URLSyntaxException;
* Main entry point for AMQPD.
*
*/
-public class Main implements ProtocolVersionList
+@SuppressWarnings({"AccessStaticViaInstance"})
+public class Main
{
private static final Logger _logger = Logger.getLogger(Main.class);
@@ -143,12 +144,21 @@ public class Main implements ProtocolVersionList
else if (commandLine.hasOption("v"))
{
String ver = "Qpid 0.9.0.0";
- String protocol = "AMQP version(s) [major.minor]: ";
- for (int i=0; i<pv.length; i++)
+ StringBuilder protocol = new StringBuilder("AMQP version(s) [major.minor]: ");
+
+ boolean first = true;
+ for (ProtocolVersion pv : ProtocolVersion.getSupportedProtocolVersions())
{
- if (i > 0)
- protocol += ", ";
- protocol += pv[i][PROTOCOL_MAJOR] + "." + pv[i][PROTOCOL_MINOR];
+ if(first)
+ {
+ first = false;
+ }
+ else
+ {
+ protocol.append(", ");
+ }
+ protocol.append(pv.getMajorVersion()).append('-').append(pv.getMinorVersion());
+
}
System.out.println(ver + " (" + protocol + ")");
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/ack/UnacknowledgedMessageMapImpl.java b/java/broker/src/main/java/org/apache/qpid/server/ack/UnacknowledgedMessageMapImpl.java
index fdf087fdea..99cc60011a 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/ack/UnacknowledgedMessageMapImpl.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/ack/UnacknowledgedMessageMapImpl.java
@@ -209,7 +209,7 @@ public class UnacknowledgedMessageMapImpl implements UnacknowledgedMessageMap
if(consumerTag != null)
{
- msg.writeDeliver(protocolSession, channelId, deliveryTag, consumerTag);
+ protocolSession.getProtocolOutputConverter().writeDeliver(msg, channelId, deliveryTag, consumerTag);
}
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/filter/PropertyExpression.java b/java/broker/src/main/java/org/apache/qpid/server/filter/PropertyExpression.java
index 348bfa5e68..bdabcbf5be 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/filter/PropertyExpression.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/filter/PropertyExpression.java
@@ -25,7 +25,8 @@ import java.util.HashMap;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.BasicContentHeaderProperties;
+import org.apache.qpid.framing.CommonContentHeaderProperties;
+import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.queue.AMQMessage;
/**
@@ -63,8 +64,9 @@ public class PropertyExpression implements Expression
{
try
{
- BasicContentHeaderProperties _properties = (BasicContentHeaderProperties) message.getContentHeaderBody().properties;
- return _properties.getReplyTo();
+ CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
+ AMQShortString replyTo = _properties.getReplyTo();
+ return replyTo == null ? null : replyTo.toString();
}
catch (AMQException e)
{
@@ -83,8 +85,9 @@ public class PropertyExpression implements Expression
{
try
{
- BasicContentHeaderProperties _properties = (BasicContentHeaderProperties) message.getContentHeaderBody().properties;
- return _properties.getType();
+ CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
+ AMQShortString type = _properties.getType();
+ return type == null ? null : type.toString();
}
catch (AMQException e)
{
@@ -126,7 +129,7 @@ public class PropertyExpression implements Expression
{
try
{
- BasicContentHeaderProperties _properties = (BasicContentHeaderProperties) message.getContentHeaderBody().properties;
+ CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
return (int) _properties.getPriority();
}
catch (AMQException e)
@@ -147,8 +150,9 @@ public class PropertyExpression implements Expression
try
{
- BasicContentHeaderProperties _properties = (BasicContentHeaderProperties) message.getContentHeaderBody().properties;
- return _properties.getMessageId();
+ CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
+ AMQShortString messageId = _properties.getMessageId();
+ return messageId == null ? null : messageId;
}
catch (AMQException e)
{
@@ -168,7 +172,7 @@ public class PropertyExpression implements Expression
try
{
- BasicContentHeaderProperties _properties = (BasicContentHeaderProperties) message.getContentHeaderBody().properties;
+ CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
return _properties.getTimestamp();
}
catch (AMQException e)
@@ -189,8 +193,9 @@ public class PropertyExpression implements Expression
try
{
- BasicContentHeaderProperties _properties = (BasicContentHeaderProperties) message.getContentHeaderBody().properties;
- return _properties.getCorrelationId();
+ CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
+ AMQShortString correlationId = _properties.getCorrelationId();
+ return correlationId == null ? null : correlationId.toString();
}
catch (AMQException e)
{
@@ -210,7 +215,7 @@ public class PropertyExpression implements Expression
try
{
- BasicContentHeaderProperties _properties = (BasicContentHeaderProperties) message.getContentHeaderBody().properties;
+ CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
return _properties.getExpiration();
}
catch (AMQException e)
@@ -254,7 +259,7 @@ public class PropertyExpression implements Expression
else
{
- BasicContentHeaderProperties _properties = (BasicContentHeaderProperties) message.getContentHeaderBody().properties;
+ CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
if(_logger.isDebugEnabled())
{
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicAckMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicAckMethodHandler.java
index f93b2b25e6..269b68ff6b 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicAckMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicAckMethodHandler.java
@@ -61,6 +61,6 @@ public class BasicAckMethodHandler implements StateAwareMethodListener<BasicAckB
}
// this method throws an AMQException if the delivery tag is not known
- channel.acknowledgeMessage(body.deliveryTag, body.multiple);
+ channel.acknowledgeMessage(body.getDeliveryTag(), body.getMultiple());
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicCancelMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicCancelMethodHandler.java
index 7d18043f5c..c73cc73d23 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicCancelMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicCancelMethodHandler.java
@@ -55,15 +55,15 @@ public class BasicCancelMethodHandler implements StateAwareMethodListener<BasicC
throw body.getChannelNotFoundException(evt.getChannelId());
}
- channel.unsubscribeConsumer(protocolSession, body.consumerTag);
- if (!body.nowait)
+ channel.unsubscribeConsumer(protocolSession, body.getConsumerTag());
+ if (!body.getNowait())
{
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
// Be aware of possible changes to parameter order as versions change.
final AMQFrame responseFrame = BasicCancelOkBody.createAMQFrame(evt.getChannelId(),
(byte) 8, (byte) 0, // AMQP version (major, minor)
- body.consumerTag); // consumerTag
+ body.getConsumerTag()); // consumerTag
protocolSession.writeFrame(responseFrame);
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicConsumeMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicConsumeMethodHandler.java
index da61f2ffd5..e96f8e8cba 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicConsumeMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicConsumeMethodHandler.java
@@ -68,14 +68,14 @@ public class BasicConsumeMethodHandler implements StateAwareMethodListener<Basic
else
{
- AMQQueue queue = body.queue == null ? channel.getDefaultQueue() : vHost.getQueueRegistry().getQueue(body.queue);
+ AMQQueue queue = body.getQueue() == null ? channel.getDefaultQueue() : vHost.getQueueRegistry().getQueue(body.getQueue());
if (queue == null)
{
- _log.info("No queue for '" + body.queue + "'");
- if (body.queue != null)
+ _log.info("No queue for '" + body.getQueue() + "'");
+ if (body.getQueue() != null)
{
- String msg = "No such queue, '" + body.queue + "'";
+ String msg = "No such queue, '" + body.getQueue() + "'";
throw body.getChannelException(AMQConstant.NOT_FOUND, msg);
}
else
@@ -88,9 +88,9 @@ public class BasicConsumeMethodHandler implements StateAwareMethodListener<Basic
{
try
{
- AMQShortString consumerTag = channel.subscribeToQueue(body.consumerTag, queue, session, !body.noAck,
- body.arguments, body.noLocal, body.exclusive);
- if (!body.nowait)
+ AMQShortString consumerTag = channel.subscribeToQueue(body.getConsumerTag(), queue, session, !body.getNoAck(),
+ body.getArguments(), body.getNoLocal(), body.getExclusive());
+ if (!body.getNowait())
{
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
@@ -110,9 +110,9 @@ public class BasicConsumeMethodHandler implements StateAwareMethodListener<Basic
}
catch (ConsumerTagNotUniqueException e)
{
- AMQShortString msg = new AMQShortString("Non-unique consumer tag, '" + body.consumerTag + "'");
+ AMQShortString msg = new AMQShortString("Non-unique consumer tag, '" + body.getConsumerTag() + "'");
throw body.getConnectionException(AMQConstant.NOT_ALLOWED,
- "Non-unique consumer tag, '" + body.consumerTag + "'");
+ "Non-unique consumer tag, '" + body.getConsumerTag() + "'");
}
catch (AMQQueue.ExistingExclusiveSubscription e)
{
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java
index b88c2ebf3a..7c65d94ceb 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java
@@ -43,15 +43,15 @@ public class BasicGetMethodHandler implements StateAwareMethodListener<BasicGetB
}
else
{
- AMQQueue queue = body.queue == null ? channel.getDefaultQueue() : vHost.getQueueRegistry().getQueue(body.queue);
+ AMQQueue queue = body.getQueue() == null ? channel.getDefaultQueue() : vHost.getQueueRegistry().getQueue(body.getQueue());
if (queue == null)
{
- _log.info("No queue for '" + body.queue + "'");
- if(body.queue!=null)
+ _log.info("No queue for '" + body.getQueue() + "'");
+ if(body.getQueue()!=null)
{
throw body.getConnectionException(AMQConstant.NOT_FOUND,
- "No such queue, '" + body.queue + "'");
+ "No such queue, '" + body.getQueue() + "'");
}
else
{
@@ -61,7 +61,7 @@ public class BasicGetMethodHandler implements StateAwareMethodListener<BasicGetB
}
else
{
- if(!queue.performGet(session, channel, !body.noAck))
+ if(!queue.performGet(session, channel, !body.getNoAck()))
{
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicPublishMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicPublishMethodHandler.java
index 67ade0a744..2c1f99f7c4 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicPublishMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicPublishMethodHandler.java
@@ -24,6 +24,7 @@ import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.BasicPublishBody;
+import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.AMQChannel;
@@ -61,14 +62,15 @@ public class BasicPublishMethodHandler implements StateAwareMethodListener<Basi
_log.debug("Publish received on channel " + evt.getChannelId());
}
+ AMQShortString exchangeName = body.getExchange();
// TODO: check the delivery tag field details - is it unique across the broker or per subscriber?
- if (body.exchange == null)
+ if (exchangeName == null)
{
- body.exchange = ExchangeDefaults.DEFAULT_EXCHANGE_NAME;
+ exchangeName = ExchangeDefaults.DEFAULT_EXCHANGE_NAME;
}
VirtualHost vHost = session.getVirtualHost();
- Exchange e = vHost.getExchangeRegistry().getExchange(body.exchange);
+ Exchange e = vHost.getExchangeRegistry().getExchange(exchangeName);
// if the exchange does not exist we raise a channel exception
if (e == null)
{
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicQosHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicQosHandler.java
index 3cd6a87f64..f9afbaa954 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicQosHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicQosHandler.java
@@ -47,8 +47,8 @@ public class BasicQosHandler implements StateAwareMethodListener<BasicQosBody>
throw evt.getMethod().getChannelNotFoundException(evt.getChannelId());
}
- channel.setPrefetchCount(evt.getMethod().prefetchCount);
- channel.setPrefetchSize(evt.getMethod().prefetchSize);
+ channel.setPrefetchCount(evt.getMethod().getPrefetchCount());
+ channel.setPrefetchSize(evt.getMethod().getPrefetchSize());
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverMethodHandler.java
index bc11e4652c..601187d2cd 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverMethodHandler.java
@@ -54,7 +54,7 @@ public class BasicRecoverMethodHandler implements StateAwareMethodListener<Basic
throw body.getChannelNotFoundException(evt.getChannelId());
}
- channel.resend(session, body.requeue);
+ channel.resend(session, body.getRequeue());
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRejectMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRejectMethodHandler.java
index ed13092ded..4a7e99a219 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRejectMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRejectMethodHandler.java
@@ -49,10 +49,10 @@ public class BasicRejectMethodHandler implements StateAwareMethodListener<BasicR
{
AMQProtocolSession session = stateManager.getProtocolSession();
- _logger.info("FIXME: Rejecting:" + evt.getMethod().deliveryTag + ": Requeue:" + evt.getMethod().requeue);
+ _logger.info("FIXME: Rejecting:" + evt.getMethod().getDeliveryTag() + ": Requeue:" + evt.getMethod().getRequeue());
int channelId = evt.getChannelId();
- UnacknowledgedMessage message = session.getChannel(channelId).getUnacknowledgedMessageMap().get(evt.getMethod().deliveryTag);
+ UnacknowledgedMessage message = session.getChannel(channelId).getUnacknowledgedMessageMap().get(evt.getMethod().getDeliveryTag());
_logger.info("Need to reject message:" + message);
// if (evt.getMethod().requeue)
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelCloseHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelCloseHandler.java
index 9a8fce7129..8bee8d3992 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelCloseHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelCloseHandler.java
@@ -51,8 +51,8 @@ public class ChannelCloseHandler implements StateAwareMethodListener<ChannelClos
{
AMQProtocolSession session = stateManager.getProtocolSession();
ChannelCloseBody body = evt.getMethod();
- _logger.info("Received channel close for id " + evt.getChannelId() + " citing class " + body.classId +
- " and method " + body.methodId);
+ _logger.info("Received channel close for id " + evt.getChannelId() + " citing class " + body.getClassId() +
+ " and method " + body.getMethodId());
int channelId = evt.getChannelId();
AMQChannel channel = session.getChannel(channelId);
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelFlowHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelFlowHandler.java
index bfa170cfc5..35e1dd68f5 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelFlowHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelFlowHandler.java
@@ -58,15 +58,15 @@ public class ChannelFlowHandler implements StateAwareMethodListener<ChannelFlowB
throw body.getChannelNotFoundException(evt.getChannelId());
}
- channel.setSuspended(!body.active);
- _logger.debug("Channel.Flow for channel " + evt.getChannelId() + ", active=" + body.active);
+ channel.setSuspended(!body.getActive());
+ _logger.debug("Channel.Flow for channel " + evt.getChannelId() + ", active=" + body.getActive());
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
// Be aware of possible changes to parameter order as versions change.
AMQFrame response = ChannelFlowOkBody.createAMQFrame(evt.getChannelId(),
(byte)8, (byte)0, // AMQP version (major, minor)
- body.active); // active
+ body.getActive()); // active
session.writeFrame(response);
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelOpenHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelOpenHandler.java
index 03fc7a3926..50125c02be 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelOpenHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ChannelOpenHandler.java
@@ -24,6 +24,7 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.ChannelOpenBody;
import org.apache.qpid.framing.ChannelOpenOkBody;
+import org.apache.qpid.framing.amqp_8_0.ChannelOpenOkBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.protocol.AMQProtocolSession;
@@ -52,10 +53,15 @@ public class ChannelOpenHandler implements StateAwareMethodListener<ChannelOpenB
final AMQChannel channel = new AMQChannel(session,evt.getChannelId(), virtualHost.getMessageStore(),
virtualHost.getExchangeRegistry());
session.addChannel(channel);
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- AMQFrame response = ChannelOpenOkBody.createAMQFrame(evt.getChannelId(), (byte)8, (byte)0);
- session.writeFrame(response);
+
+ ChannelOpenOkBody channelOpenOkBody = createChannelOpenOkBody();
+
+
+ session.writeFrame(new AMQFrame(evt.getChannelId(), channelOpenOkBody));
+ }
+
+ private ChannelOpenOkBody createChannelOpenOkBody()
+ {
+ return new ChannelOpenOkBodyImpl();
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionCloseMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionCloseMethodHandler.java
index 21da03d226..6981fbc72c 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionCloseMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionCloseMethodHandler.java
@@ -49,8 +49,8 @@ public class ConnectionCloseMethodHandler implements StateAwareMethodListener<C
{
AMQProtocolSession session = stateManager.getProtocolSession();
final ConnectionCloseBody body = evt.getMethod();
- _logger.info("ConnectionClose received with reply code/reply text " + body.replyCode + "/" +
- body.replyText + " for " + session);
+ _logger.info("ConnectionClose received with reply code/reply text " + body.getReplyCode() + "/" +
+ body.getReplyText() + " for " + session);
try
{
session.closeSession();
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionOpenMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionOpenMethodHandler.java
index a85af61327..80e4c29577 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionOpenMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionOpenMethodHandler.java
@@ -58,13 +58,13 @@ public class ConnectionOpenMethodHandler implements StateAwareMethodListener<Con
//ignore leading '/'
String virtualHostName;
- if((body.virtualHost != null) && body.virtualHost.charAt(0) == '/')
+ if((body.getVirtualHost() != null) && body.getVirtualHost().charAt(0) == '/')
{
- virtualHostName = new StringBuilder(body.virtualHost.subSequence(1,body.virtualHost.length())).toString();
+ virtualHostName = new StringBuilder(body.getVirtualHost().subSequence(1,body.getVirtualHost().length())).toString();
}
else
{
- virtualHostName = body.virtualHost == null ? null : String.valueOf(body.virtualHost);
+ virtualHostName = body.getVirtualHost() == null ? null : String.valueOf(body.getVirtualHost());
}
VirtualHost virtualHost = stateManager.getVirtualHostRegistry().getVirtualHost(virtualHostName);
@@ -90,7 +90,7 @@ public class ConnectionOpenMethodHandler implements StateAwareMethodListener<Con
// Be aware of possible changes to parameter order as versions change.
AMQFrame response = ConnectionOpenOkBody.createAMQFrame((short)0,
(byte)8, (byte)0, // AMQP version (major, minor)
- body.virtualHost);
+ body.getVirtualHost());
stateManager.changeState(AMQState.CONNECTION_OPEN);
session.writeFrame(response);
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java
index 4ad6dcde71..9f7a1c1e7c 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java
@@ -30,6 +30,10 @@ import org.apache.qpid.framing.ConnectionCloseBody;
import org.apache.qpid.framing.ConnectionSecureBody;
import org.apache.qpid.framing.ConnectionSecureOkBody;
import org.apache.qpid.framing.ConnectionTuneBody;
+import org.apache.qpid.framing.amqp_8_0.ConnectionCloseBodyImpl;
+import org.apache.qpid.framing.amqp_8_0.ConnectionSecureOkBodyImpl;
+import org.apache.qpid.framing.amqp_8_0.ConnectionTuneBodyImpl;
+import org.apache.qpid.framing.amqp_8_0.ConnectionSecureBodyImpl;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.protocol.AMQProtocolSession;
@@ -68,7 +72,7 @@ public class ConnectionSecureOkMethodHandler implements StateAwareMethodListener
throw new AMQException("No SASL context set up in session");
}
- AuthenticationResult authResult = authMgr.authenticate(ss, body.response);
+ AuthenticationResult authResult = authMgr.authenticate(ss, body.getResponse());
switch (authResult.status)
{
case ERROR:
@@ -76,44 +80,32 @@ public class ConnectionSecureOkMethodHandler implements StateAwareMethodListener
// throw new AMQException(AMQConstant.NOT_ALLOWED.getCode(), AMQConstant.NOT_ALLOWED.getName());
_logger.info("Authentication failed");
stateManager.changeState(AMQState.CONNECTION_CLOSING);
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- AMQFrame close = ConnectionCloseBody.createAMQFrame(0,
- (byte)8, (byte)0, // AMQP version (major, minor)
- ConnectionCloseBody.getClazz((byte)8, (byte)0), // classId
- ConnectionCloseBody.getMethod((byte)8, (byte)0), // methodId
- AMQConstant.NOT_ALLOWED.getCode(), // replyCode
- AMQConstant.NOT_ALLOWED.getName()); // replyText
- session.writeFrame(close);
+
+ ConnectionCloseBody closeBody =
+ new ConnectionCloseBodyImpl(AMQConstant.NOT_ALLOWED.getCode(), // replyCode
+ AMQConstant.NOT_ALLOWED.getName(), // replyText)
+ ConnectionSecureOkBodyImpl.CLASS_ID, // classId
+ ConnectionSecureOkBodyImpl.METHOD_ID); // methodId
+
+ session.writeFrame(new AMQFrame(0,closeBody));
disposeSaslServer(session);
break;
case SUCCESS:
_logger.info("Connected as: " + ss.getAuthorizationID());
stateManager.changeState(AMQState.CONNECTION_NOT_TUNED);
- // TODO: Check the value of channelMax here: This should be the max
- // value of a 2-byte unsigned integer (as channel is only 2 bytes on the wire),
- // not Integer.MAX_VALUE (which is signed 4 bytes).
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- AMQFrame tune = ConnectionTuneBody.createAMQFrame(0,
- (byte)8, (byte)0, // AMQP version (major, minor)
- Integer.MAX_VALUE, // channelMax
- ConnectionStartOkMethodHandler.getConfiguredFrameSize(), // frameMax
- HeartbeatConfig.getInstance().getDelay()); // heartbeat
- session.writeFrame(tune);
+
+ ConnectionTuneBody tuneBody =
+ new ConnectionTuneBodyImpl(ConnectionStartOkMethodHandler.getConfiguredMaxChannels(),
+ ConnectionStartOkMethodHandler.getConfiguredFrameSize(),
+ HeartbeatConfig.getInstance().getDelay());
+ session.writeFrame(new AMQFrame(0,tuneBody));
disposeSaslServer(session);
break;
case CONTINUE:
stateManager.changeState(AMQState.CONNECTION_NOT_AUTH);
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- AMQFrame challenge = ConnectionSecureBody.createAMQFrame(0,
- (byte)8, (byte)0, // AMQP version (major, minor)
- authResult.challenge); // challenge
- session.writeFrame(challenge);
+ ConnectionSecureBody secureBody =
+ new ConnectionSecureBodyImpl(authResult.challenge);
+ session.writeFrame(new AMQFrame(0,secureBody));
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java
index 65b79cf8e7..b14c8a5c81 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java
@@ -48,6 +48,7 @@ public class ConnectionStartOkMethodHandler implements StateAwareMethodListener<
private static ConnectionStartOkMethodHandler _instance = new ConnectionStartOkMethodHandler();
private static final int DEFAULT_FRAME_SIZE = 65536;
+ private static final int DEFAULT_CHANNEL_MAX = 65536;
public static StateAwareMethodListener<ConnectionStartOkBody> getInstance()
{
@@ -62,23 +63,23 @@ public class ConnectionStartOkMethodHandler implements StateAwareMethodListener<
{
AMQProtocolSession session = stateManager.getProtocolSession();
final ConnectionStartOkBody body = evt.getMethod();
- _logger.info("SASL Mechanism selected: " + body.mechanism);
- _logger.info("Locale selected: " + body.locale);
+ _logger.info("SASL Mechanism selected: " + body.getMechanism());
+ _logger.info("Locale selected: " + body.getLocale());
AuthenticationManager authMgr = ApplicationRegistry.getInstance().getAuthenticationManager();
SaslServer ss = null;
try
{
- ss = authMgr.createSaslServer(String.valueOf(body.mechanism), session.getLocalFQDN());
+ ss = authMgr.createSaslServer(String.valueOf(body.getMechanism()), session.getLocalFQDN());
session.setSaslServer(ss);
- AuthenticationResult authResult = authMgr.authenticate(ss, body.response);
+ AuthenticationResult authResult = authMgr.authenticate(ss, body.getResponse());
//save clientProperties
if (session.getClientProperties() == null)
{
- session.setClientProperties(body.clientProperties);
+ session.setClientProperties(body.getClientProperties());
}
switch (authResult.status)
@@ -141,6 +142,15 @@ public class ConnectionStartOkMethodHandler implements StateAwareMethodListener<
_logger.info("Framesize set to " + framesize);
return framesize;
}
+
+
+ static int getConfiguredMaxChannels()
+ {
+ final Configuration config = ApplicationRegistry.getInstance().getConfiguration();
+ final int maxChannels = config.getInt("advanced.maxchannels", DEFAULT_CHANNEL_MAX);
+ _logger.info("Max Channels set to " + maxChannels);
+ return maxChannels;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionTuneOkMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionTuneOkMethodHandler.java
index ab7695955c..8a6b518934 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionTuneOkMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionTuneOkMethodHandler.java
@@ -49,6 +49,6 @@ public class ConnectionTuneOkMethodHandler implements StateAwareMethodListener<C
_logger.debug(body);
}
stateManager.changeState(AMQState.CONNECTION_NOT_OPENED);
- session.initHeartbeats(body.heartbeat);
+ session.initHeartbeats(body.getHeartbeat());
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeBoundHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeBoundHandler.java
index 2b123bcb2d..131d047c28 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeBoundHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeBoundHandler.java
@@ -22,6 +22,7 @@ import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ExchangeBoundBody;
import org.apache.qpid.framing.ExchangeBoundOkBody;
+import org.apache.qpid.framing.amqp_8_0.ExchangeBoundOkBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.protocol.AMQProtocolSession;
@@ -74,9 +75,9 @@ public class ExchangeBoundHandler implements StateAwareMethodListener<ExchangeBo
ExchangeBoundBody body = evt.getMethod();
- AMQShortString exchangeName = body.exchange;
- AMQShortString queueName = body.queue;
- AMQShortString routingKey = body.routingKey;
+ AMQShortString exchangeName = body.getExchange();
+ AMQShortString queueName = body.getQueue();
+ AMQShortString routingKey = body.getRoutingKey();
if (exchangeName == null)
{
throw new AMQException("Exchange exchange must not be null");
@@ -86,8 +87,8 @@ public class ExchangeBoundHandler implements StateAwareMethodListener<ExchangeBo
if (exchange == null)
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
EXCHANGE_NOT_FOUND, // replyCode
new AMQShortString("Exchange " + exchangeName + " not found")); // replyText
}
@@ -98,16 +99,16 @@ public class ExchangeBoundHandler implements StateAwareMethodListener<ExchangeBo
if (exchange.hasBindings())
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
OK, // replyCode
null); // replyText
}
else
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
NO_BINDINGS, // replyCode
null); // replyText
}
@@ -119,8 +120,8 @@ public class ExchangeBoundHandler implements StateAwareMethodListener<ExchangeBo
if (queue == null)
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
QUEUE_NOT_FOUND, // replyCode
new AMQShortString("Queue " + queueName + " not found")); // replyText
}
@@ -129,16 +130,16 @@ public class ExchangeBoundHandler implements StateAwareMethodListener<ExchangeBo
if (exchange.isBound(queue))
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
OK, // replyCode
null); // replyText
}
else
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
QUEUE_NOT_BOUND, // replyCode
new AMQShortString("Queue " + queueName + " not bound to exchange " + exchangeName)); // replyText
}
@@ -151,52 +152,58 @@ public class ExchangeBoundHandler implements StateAwareMethodListener<ExchangeBo
if (queue == null)
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
QUEUE_NOT_FOUND, // replyCode
new AMQShortString("Queue " + queueName + " not found")); // replyText
}
else
{
- if (exchange.isBound(body.routingKey, queue))
+ if (exchange.isBound(body.getRoutingKey(), queue))
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
OK, // replyCode
null); // replyText
}
else
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
SPECIFIC_QUEUE_NOT_BOUND_WITH_RK, // replyCode
new AMQShortString("Queue " + queueName + " not bound with routing key " +
- body.routingKey + " to exchange " + exchangeName)); // replyText
+ body.getRoutingKey() + " to exchange " + exchangeName)); // replyText
}
}
}
else
{
- if (exchange.isBound(body.routingKey))
+ if (exchange.isBound(body.getRoutingKey()))
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
OK, // replyCode
null); // replyText
}
else
{
// AMQP version change: Be aware of possible changes to parameter order as versions change.
- response = ExchangeBoundOkBody.createAMQFrame(evt.getChannelId(),
- major, minor, // AMQP version (major, minor)
+ response = createExchangeBoundResponseFrame(evt.getChannelId(),
+ // AMQP version (major, minor)
NO_QUEUE_BOUND_WITH_RK, // replyCode
- new AMQShortString("No queue bound with routing key " + body.routingKey +
+ new AMQShortString("No queue bound with routing key " + body.getRoutingKey() +
" to exchange " + exchangeName)); // replyText
}
}
session.writeFrame(response);
}
+
+ private AMQFrame createExchangeBoundResponseFrame(int channelId, int replyCode, AMQShortString replyText)
+ {
+ ExchangeBoundOkBody okBody = new ExchangeBoundOkBodyImpl(replyCode,replyText);
+ return new AMQFrame(channelId,okBody);
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeclareHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeclareHandler.java
index be3ffcc698..00c279f133 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeclareHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeclareHandler.java
@@ -64,43 +64,43 @@ public class ExchangeDeclareHandler implements StateAwareMethodListener<Exchange
final ExchangeDeclareBody body = evt.getMethod();
if (_logger.isDebugEnabled())
{
- _logger.debug("Request to declare exchange of type " + body.type + " with name " + body.exchange);
+ _logger.debug("Request to declare exchange of type " + body.getType() + " with name " + body.getExchange());
}
synchronized(exchangeRegistry)
{
- Exchange exchange = exchangeRegistry.getExchange(body.exchange);
+ Exchange exchange = exchangeRegistry.getExchange(body.getExchange());
if (exchange == null)
{
- if(body.passive && ((body.type == null) || body.type.length() ==0))
+ if(body.getPassive() && ((body.getType() == null) || body.getType().length() ==0))
{
- throw body.getChannelException(AMQConstant.NOT_FOUND, "Unknown exchange: " + body.exchange);
+ throw body.getChannelException(AMQConstant.NOT_FOUND, "Unknown exchange: " + body.getExchange());
}
else
{
try
{
- exchange = exchangeFactory.createExchange(body.exchange, body.type, body.durable,
- body.passive, body.ticket);
+ exchange = exchangeFactory.createExchange(body.getExchange(), body.getType(), body.getDurable(),
+ body.getPassive(), body.getTicket());
exchangeRegistry.registerExchange(exchange);
}
catch(AMQUnknownExchangeType e)
{
- throw body.getConnectionException(AMQConstant.COMMAND_INVALID, "Unknown exchange: " + body.exchange,e);
+ throw body.getConnectionException(AMQConstant.COMMAND_INVALID, "Unknown exchange: " + body.getExchange(),e);
}
}
}
- else if (!exchange.getType().equals(body.type))
+ else if (!exchange.getType().equals(body.getType()))
{
- throw new AMQConnectionException(AMQConstant.NOT_ALLOWED, "Attempt to redeclare exchange: " + body.exchange + " of type " + exchange.getType() + " to " + body.type +".",body.getClazz(), body.getMethod(),body.getMajor(),body.getMinor());
+ throw new AMQConnectionException(AMQConstant.NOT_ALLOWED, "Attempt to redeclare exchange: " + body.getExchange() + " of type " + exchange.getType() + " to " + body.getType() +".",body.getClazz(), body.getMethod(),body.getMajor(),body.getMinor());
}
}
- if(!body.nowait)
+ if(!body.getNowait())
{
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeleteHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeleteHandler.java
index f9926c399c..ebae8279d9 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeleteHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeleteHandler.java
@@ -54,7 +54,7 @@ public class ExchangeDeleteHandler implements StateAwareMethodListener<ExchangeD
ExchangeDeleteBody body = evt.getMethod();
try
{
- exchangeRegistry.unregisterExchange(body.exchange, body.ifUnused);
+ exchangeRegistry.unregisterExchange(body.getExchange(), body.getIfUnused());
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
// Be aware of possible changes to parameter order as versions change.
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/QueueBindHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/QueueBindHandler.java
index 4dc67b1970..2451aa2fa7 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/QueueBindHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/QueueBindHandler.java
@@ -26,6 +26,7 @@ import org.apache.qpid.AMQInvalidRoutingKeyException;
import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.QueueBindBody;
import org.apache.qpid.framing.QueueBindOkBody;
+import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.exchange.Exchange;
@@ -61,8 +62,10 @@ public class QueueBindHandler implements StateAwareMethodListener<QueueBindBody>
QueueRegistry queueRegistry = virtualHost.getQueueRegistry();
final QueueBindBody body = evt.getMethod();
+
+ AMQShortString routingKey = body.getRoutingKey();
final AMQQueue queue;
- if (body.queue == null)
+ if (body.getQueue() == null)
{
AMQChannel channel = session.getChannel(evt.getChannelId());
@@ -77,33 +80,35 @@ public class QueueBindHandler implements StateAwareMethodListener<QueueBindBody>
{
throw body.getChannelException(AMQConstant.NOT_FOUND, "No default queue defined on channel and queue was null");
}
-
- if (body.routingKey == null)
+
+
+
+ if (routingKey == null)
{
- body.routingKey = queue.getName();
+ routingKey = queue.getName();
}
}
else
{
- queue = queueRegistry.getQueue(body.queue);
+ queue = queueRegistry.getQueue(body.getQueue());
}
if (queue == null)
{
- throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + body.queue + " does not exist.");
+ throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + body.getQueue() + " does not exist.");
}
- final Exchange exch = exchangeRegistry.getExchange(body.exchange);
+ final Exchange exch = exchangeRegistry.getExchange(body.getExchange());
if (exch == null)
{
- throw body.getChannelException(AMQConstant.NOT_FOUND, "Exchange " + body.exchange + " does not exist.");
+ throw body.getChannelException(AMQConstant.NOT_FOUND, "Exchange " + body.getExchange() + " does not exist.");
}
try
{
- queue.bind(body.routingKey, body.arguments, exch);
+ queue.bind(routingKey, body.getArguments(), exch);
}
catch (AMQInvalidRoutingKeyException rke)
{
- throw body.getChannelException(AMQConstant.INVALID_ROUTING_KEY, body.routingKey.toString());
+ throw body.getChannelException(AMQConstant.INVALID_ROUTING_KEY, routingKey.toString());
}
catch (AMQException e)
{
@@ -112,9 +117,9 @@ public class QueueBindHandler implements StateAwareMethodListener<QueueBindBody>
if (_log.isInfoEnabled())
{
- _log.info("Binding queue " + queue + " to exchange " + exch + " with routing key " + body.routingKey);
+ _log.info("Binding queue " + queue + " to exchange " + exch + " with routing key " + routingKey);
}
- if (!body.nowait)
+ if (!body.getNowait())
{
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java
index 8b2467f47d..5a49368c1c 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java
@@ -78,10 +78,12 @@ public class QueueDeclareHandler implements StateAwareMethodListener<QueueDeclar
QueueDeclareBody body = evt.getMethod();
+ AMQShortString queueName = body.getQueue();
+
// if we aren't given a queue name, we create one which we return to the client
- if (body.queue == null)
+ if (body.getQueue() == null)
{
- body.queue = createName();
+ queueName = createName();
}
AMQQueue queue;
@@ -90,11 +92,11 @@ public class QueueDeclareHandler implements StateAwareMethodListener<QueueDeclar
synchronized (queueRegistry)
{
- if (((queue = queueRegistry.getQueue(body.queue)) == null) )
+ if (((queue = queueRegistry.getQueue(queueName)) == null) )
{
- if(body.passive)
+ if(body.getPassive())
{
- String msg = "Queue: " + body.queue + " not found.";
+ String msg = "Queue: " + queueName + " not found.";
throw body.getChannelException(AMQConstant.NOT_FOUND,msg );
}
else
@@ -109,8 +111,8 @@ public class QueueDeclareHandler implements StateAwareMethodListener<QueueDeclar
{
Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
- queue.bind(body.queue, null, defaultExchange);
- _log.info("Queue " + body.queue + " bound to default exchange");
+ queue.bind(queueName, null, defaultExchange);
+ _log.info("Queue " + body.getQueue() + " bound to default exchange");
}
}
}
@@ -130,7 +132,7 @@ public class QueueDeclareHandler implements StateAwareMethodListener<QueueDeclar
channel.setDefaultQueue(queue);
}
- if (!body.nowait)
+ if (!body.getNowait())
{
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
@@ -139,8 +141,8 @@ public class QueueDeclareHandler implements StateAwareMethodListener<QueueDeclar
(byte)8, (byte)0, // AMQP version (major, minor)
queue.getConsumerCount(), // consumerCount
queue.getMessageCount(), // messageCount
- body.queue); // queue
- _log.info("Queue " + body.queue + " declared successfully");
+ queueName); // queue
+ _log.info("Queue " + queueName + " declared successfully");
session.writeFrame(response);
}
}
@@ -159,11 +161,11 @@ public class QueueDeclareHandler implements StateAwareMethodListener<QueueDeclar
throws AMQException
{
final QueueRegistry registry = virtualHost.getQueueRegistry();
- AMQShortString owner = body.exclusive ? session.getContextKey() : null;
- final AMQQueue queue = new AMQQueue(body.queue, body.durable, owner, body.autoDelete, virtualHost);
+ AMQShortString owner = body.getExclusive() ? session.getContextKey() : null;
+ final AMQQueue queue = new AMQQueue(body.getQueue(), body.getDurable(), owner, body.getAutoDelete(), virtualHost);
final AMQShortString queueName = queue.getName();
- if(body.exclusive && !body.durable)
+ if(body.getExclusive() && !body.getDurable())
{
final AMQProtocolSession.Task deleteQueueTask =
new AMQProtocolSession.Task()
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeleteHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeleteHandler.java
index 0c7de312a7..97675e8731 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeleteHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeleteHandler.java
@@ -65,7 +65,7 @@ public class QueueDeleteHandler implements StateAwareMethodListener<QueueDelete
QueueDeleteBody body = evt.getMethod();
AMQQueue queue;
- if(body.queue == null)
+ if(body.getQueue() == null)
{
AMQChannel channel = session.getChannel(evt.getChannelId());
@@ -79,31 +79,31 @@ public class QueueDeleteHandler implements StateAwareMethodListener<QueueDelete
}
else
{
- queue = queueRegistry.getQueue(body.queue);
+ queue = queueRegistry.getQueue(body.getQueue());
}
if(queue == null)
{
if(_failIfNotFound)
{
- throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + body.queue + " does not exist.");
+ throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + body.getQueue() + " does not exist.");
}
}
else
{
- if(body.ifEmpty && !queue.isEmpty())
+ if(body.getIfEmpty() && !queue.isEmpty())
{
- throw body.getChannelException(AMQConstant.IN_USE, "Queue: " + body.queue + " is not empty." );
+ throw body.getChannelException(AMQConstant.IN_USE, "Queue: " + body.getQueue() + " is not empty." );
}
- else if(body.ifUnused && !queue.isUnused())
+ else if(body.getIfUnused() && !queue.isUnused())
{
// TODO - Error code
- throw body.getChannelException(AMQConstant.IN_USE, "Queue: " + body.queue + " is still used." );
+ throw body.getChannelException(AMQConstant.IN_USE, "Queue: " + body.getQueue() + " is still used." );
}
else
{
- int purged = queue.delete(body.ifUnused, body.ifEmpty);
+ int purged = queue.delete(body.getIfUnused(), body.getIfEmpty());
store.removeQueue(queue.getName());
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/QueuePurgeHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/QueuePurgeHandler.java
index 0c00436470..e380bb3770 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/QueuePurgeHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/QueuePurgeHandler.java
@@ -44,7 +44,7 @@ public class QueuePurgeHandler implements StateAwareMethodListener<QueuePurgeBod
QueuePurgeBody body = evt.getMethod();
AMQQueue queue;
- if(body.queue == null)
+ if(body.getQueue() == null)
{
if (channel == null)
@@ -65,14 +65,14 @@ public class QueuePurgeHandler implements StateAwareMethodListener<QueuePurgeBod
}
else
{
- queue = queueRegistry.getQueue(body.queue);
+ queue = queueRegistry.getQueue(body.getQueue());
}
if(queue == null)
{
if(_failIfNotFound)
{
- throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + body.queue + " does not exist.");
+ throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + body.getQueue() + " does not exist.");
}
}
else
@@ -80,7 +80,7 @@ public class QueuePurgeHandler implements StateAwareMethodListener<QueuePurgeBod
long purged = queue.clearQueue(channel.getStoreContext());
- if(!body.nowait)
+ if(!body.getNowait())
{
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/TxRollbackHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/TxRollbackHandler.java
index a10f44f906..18b09c00a7 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/TxRollbackHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/TxRollbackHandler.java
@@ -23,6 +23,8 @@ package org.apache.qpid.server.handler;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.TxRollbackBody;
import org.apache.qpid.framing.TxRollbackOkBody;
+import org.apache.qpid.framing.AMQFrame;
+import org.apache.qpid.framing.amqp_8_0.TxRollbackBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.protocol.AMQProtocolSession;
@@ -56,10 +58,10 @@ public class TxRollbackHandler implements StateAwareMethodListener<TxRollbackBod
}
channel.rollback();
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- session.writeFrame(TxRollbackOkBody.createAMQFrame(evt.getChannelId(), (byte) 8, (byte) 0));
+
+ TxRollbackBody rollbackBody = createTxRollbackBody();
+ session.writeFrame(new AMQFrame(evt.getChannelId(), rollbackBody));
+
//Now resend all the unacknowledged messages back to the original subscribers.
//(Must be done after the TxnRollback-ok response).
// Why, are we not allowed to send messages back to client before the ok method?
@@ -70,4 +72,9 @@ public class TxRollbackHandler implements StateAwareMethodListener<TxRollbackBod
throw evt.getMethod().getChannelException(e.getErrorCode(), "Failed to rollback: " + e.getMessage());
}
}
+
+ private TxRollbackBody createTxRollbackBody()
+ {
+ return new TxRollbackBodyImpl();
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/TxSelectHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/TxSelectHandler.java
index a9e478e301..bd8f29526d 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/TxSelectHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/TxSelectHandler.java
@@ -23,6 +23,8 @@ package org.apache.qpid.server.handler;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.TxSelectBody;
import org.apache.qpid.framing.TxSelectOkBody;
+import org.apache.qpid.framing.AMQFrame;
+import org.apache.qpid.framing.amqp_8_0.TxSelectBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.state.AMQStateManager;
@@ -55,9 +57,12 @@ public class TxSelectHandler implements StateAwareMethodListener<TxSelectBody>
channel.setLocalTransactional();
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- session.writeFrame(TxSelectOkBody.createAMQFrame(evt.getChannelId(), (byte) 8, (byte) 0));
+ TxSelectBody txSelect = createTxSelectBody();
+ session.writeFrame(new AMQFrame(evt.getChannelId(), txSelect));
+ }
+
+ private TxSelectBody createTxSelectBody()
+ {
+ return new TxSelectBodyImpl();
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverter.java b/java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverter.java
new file mode 100644
index 0000000000..e01c5aabbf
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverter.java
@@ -0,0 +1,57 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * This file is auto-generated by Qpid Gentools v.0.1 - do not modify.
+ * Supported AMQP versions:
+ * 8-0
+ */
+package org.apache.qpid.server.output;
+
+import org.apache.qpid.server.queue.AMQMessage;
+import org.apache.qpid.server.protocol.AMQProtocolSession;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.AMQDataBlock;
+import org.apache.qpid.AMQException;
+
+public interface ProtocolOutputConverter
+{
+ void confirmConsumerAutoClose(int channelId, AMQShortString consumerTag);
+
+ interface Factory
+ {
+ ProtocolOutputConverter newInstance(AMQProtocolSession session);
+ }
+
+ void writeDeliver(AMQMessage message, int channelId, long deliveryTag, AMQShortString consumerTag)
+ throws AMQException;
+
+ void writeGetOk(AMQMessage message, int channelId, long deliveryTag, int queueSize) throws AMQException;
+
+ byte getProtocolMinorVersion();
+
+ byte getProtocolMajorVersion();
+
+ void writeReturn(AMQMessage message, int channelId, int replyCode, AMQShortString replyText)
+ throws AMQException;
+
+ void writeFrame(AMQDataBlock block);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverterRegistry.java b/java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverterRegistry.java
new file mode 100644
index 0000000000..8366c426dd
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverterRegistry.java
@@ -0,0 +1,62 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * This file is auto-generated by Qpid Gentools v.0.1 - do not modify.
+ * Supported AMQP versions:
+ * 8-0
+ */
+package org.apache.qpid.server.output;
+
+import org.apache.qpid.server.output.ProtocolOutputConverter.Factory;
+import org.apache.qpid.server.output.amqp0_8.ProtocolOutputConverterImpl;
+import org.apache.qpid.server.protocol.AMQProtocolSession;
+
+import java.util.Map;
+import java.util.HashMap;
+
+public class ProtocolOutputConverterRegistry
+{
+
+ private static final Map<Byte, Map<Byte, Factory>> _registry =
+ new HashMap<Byte, Map<Byte, Factory>>();
+
+
+ static
+ {
+ register((byte) 8, (byte) 0, ProtocolOutputConverterImpl.getInstanceFactory());
+ }
+
+ private static void register(byte major, byte minor, Factory converter)
+ {
+ if(!_registry.containsKey(major))
+ {
+ _registry.put(major, new HashMap<Byte, Factory>());
+ }
+ _registry.get(major).put(minor, converter);
+ }
+
+
+ public static ProtocolOutputConverter getConverter(AMQProtocolSession session)
+ {
+ return _registry.get(session.getProtocolMajorVersion()).get(session.getProtocolMinorVersion()).newInstance(session);
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/output/amqp0_8/ProtocolOutputConverterImpl.java b/java/broker/src/main/java/org/apache/qpid/server/output/amqp0_8/ProtocolOutputConverterImpl.java
new file mode 100644
index 0000000000..bd5bb632fe
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/output/amqp0_8/ProtocolOutputConverterImpl.java
@@ -0,0 +1,288 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * This file is auto-generated by Qpid Gentools v.0.1 - do not modify.
+ * Supported AMQP versions:
+ * 8-0
+ */
+package org.apache.qpid.server.output.amqp0_8;
+
+import org.apache.qpid.server.protocol.AMQProtocolSession;
+import org.apache.qpid.server.queue.AMQMessage;
+import org.apache.qpid.server.queue.AMQMessageHandle;
+import org.apache.qpid.server.store.StoreContext;
+import org.apache.qpid.server.output.ProtocolOutputConverter;
+import org.apache.qpid.framing.*;
+import org.apache.qpid.framing.abstraction.ContentChunk;
+import org.apache.qpid.framing.abstraction.MessagePublishInfo;
+import org.apache.qpid.AMQException;
+
+import org.apache.mina.common.ByteBuffer;
+
+import java.util.Iterator;
+
+public class ProtocolOutputConverterImpl implements ProtocolOutputConverter
+{
+
+ public static Factory getInstanceFactory()
+ {
+ return new Factory()
+ {
+
+ public ProtocolOutputConverter newInstance(AMQProtocolSession session)
+ {
+ return new ProtocolOutputConverterImpl(session);
+ }
+ };
+ }
+
+ private final AMQProtocolSession _protocolSession;
+
+ private ProtocolOutputConverterImpl(AMQProtocolSession session)
+ {
+ _protocolSession = session;
+ }
+
+
+ public AMQProtocolSession getProtocolSession()
+ {
+ return _protocolSession;
+ }
+
+ public void writeDeliver(AMQMessage message, int channelId, long deliveryTag, AMQShortString consumerTag)
+ throws AMQException
+ {
+ ByteBuffer deliver = createEncodedDeliverFrame(message, channelId, deliveryTag, consumerTag);
+ AMQDataBlock contentHeader = ContentHeaderBody.createAMQFrame(channelId,
+ message.getContentHeaderBody());
+
+ final AMQMessageHandle messageHandle = message.getMessageHandle();
+ final StoreContext storeContext = message.getStoreContext();
+ final long messageId = message.getMessageId();
+
+ final int bodyCount = messageHandle.getBodyCount(storeContext,messageId);
+
+ if(bodyCount == 0)
+ {
+ SmallCompositeAMQDataBlock compositeBlock = new SmallCompositeAMQDataBlock(deliver,
+ contentHeader);
+
+ writeFrame(compositeBlock);
+ }
+ else
+ {
+
+
+ //
+ // Optimise the case where we have a single content body. In that case we create a composite block
+ // so that we can writeDeliver out the deliver, header and body with a single network writeDeliver.
+ //
+ ContentChunk cb = messageHandle.getContentChunk(storeContext,messageId, 0);
+
+ AMQDataBlock firstContentBody = new AMQFrame(channelId, getProtocolSession().getRegistry().getProtocolVersionMethodConverter().convertToBody(cb));
+ AMQDataBlock[] headerAndFirstContent = new AMQDataBlock[]{contentHeader, firstContentBody};
+ CompositeAMQDataBlock compositeBlock = new CompositeAMQDataBlock(deliver, headerAndFirstContent);
+ writeFrame(compositeBlock);
+
+ //
+ // Now start writing out the other content bodies
+ //
+ for(int i = 1; i < bodyCount; i++)
+ {
+ cb = messageHandle.getContentChunk(storeContext,messageId, i);
+ writeFrame(new AMQFrame(channelId, getProtocolSession().getRegistry().getProtocolVersionMethodConverter().convertToBody(cb)));
+ }
+
+
+ }
+
+
+ }
+
+
+ public void writeGetOk(AMQMessage message, int channelId, long deliveryTag, int queueSize) throws AMQException
+ {
+
+ final AMQMessageHandle messageHandle = message.getMessageHandle();
+ final StoreContext storeContext = message.getStoreContext();
+ final long messageId = message.getMessageId();
+
+ ByteBuffer deliver = createEncodedGetOkFrame(message, channelId, deliveryTag, queueSize);
+
+
+ AMQDataBlock contentHeader = ContentHeaderBody.createAMQFrame(channelId,
+ message.getContentHeaderBody());
+
+ final int bodyCount = messageHandle.getBodyCount(storeContext,messageId);
+ if(bodyCount == 0)
+ {
+ SmallCompositeAMQDataBlock compositeBlock = new SmallCompositeAMQDataBlock(deliver,
+ contentHeader);
+ writeFrame(compositeBlock);
+ }
+ else
+ {
+
+
+ //
+ // Optimise the case where we have a single content body. In that case we create a composite block
+ // so that we can writeDeliver out the deliver, header and body with a single network writeDeliver.
+ //
+ ContentChunk cb = messageHandle.getContentChunk(storeContext,messageId, 0);
+
+ AMQDataBlock firstContentBody = new AMQFrame(channelId, getProtocolSession().getRegistry().getProtocolVersionMethodConverter().convertToBody(cb));
+ AMQDataBlock[] headerAndFirstContent = new AMQDataBlock[]{contentHeader, firstContentBody};
+ CompositeAMQDataBlock compositeBlock = new CompositeAMQDataBlock(deliver, headerAndFirstContent);
+ writeFrame(compositeBlock);
+
+ //
+ // Now start writing out the other content bodies
+ //
+ for(int i = 1; i < bodyCount; i++)
+ {
+ cb = messageHandle.getContentChunk(storeContext, messageId, i);
+ writeFrame(new AMQFrame(channelId, getProtocolSession().getRegistry().getProtocolVersionMethodConverter().convertToBody(cb)));
+ }
+
+
+ }
+
+
+ }
+
+
+ private ByteBuffer createEncodedDeliverFrame(AMQMessage message, int channelId, long deliveryTag, AMQShortString consumerTag)
+ throws AMQException
+ {
+ final MessagePublishInfo pb = message.getMessagePublishInfo();
+ final AMQMessageHandle messageHandle = message.getMessageHandle();
+
+ AMQFrame deliverFrame = BasicDeliverBody.createAMQFrame(channelId, getProtocolMajorVersion(),
+ getProtocolMinorVersion(),
+ consumerTag,
+ deliveryTag, pb.getExchange(), messageHandle.isRedelivered(),
+ pb.getRoutingKey());
+
+ ByteBuffer buf = ByteBuffer.allocate((int) deliverFrame.getSize()); // XXX: Could cast be a problem?
+ deliverFrame.writePayload(buf);
+ buf.flip();
+ return buf;
+ }
+
+ private ByteBuffer createEncodedGetOkFrame(AMQMessage message, int channelId, long deliveryTag, int queueSize)
+ throws AMQException
+ {
+ final MessagePublishInfo pb = message.getMessagePublishInfo();
+ final AMQMessageHandle messageHandle = message.getMessageHandle();
+
+ AMQFrame getOkFrame = BasicGetOkBody.createAMQFrame(channelId,
+ getProtocolMajorVersion(),
+ getProtocolMinorVersion(),
+ deliveryTag, pb.getExchange(),
+ queueSize,
+ messageHandle.isRedelivered(),
+ pb.getRoutingKey());
+ ByteBuffer buf = ByteBuffer.allocate((int) getOkFrame.getSize()); // XXX: Could cast be a problem?
+ getOkFrame.writePayload(buf);
+ buf.flip();
+ return buf;
+ }
+
+ public byte getProtocolMinorVersion()
+ {
+ return getProtocolSession().getProtocolMinorVersion();
+ }
+
+ public byte getProtocolMajorVersion()
+ {
+ return getProtocolSession().getProtocolMajorVersion();
+ }
+
+ private ByteBuffer createEncodedReturnFrame(AMQMessage message, int channelId, int replyCode, AMQShortString replyText) throws AMQException
+ {
+ AMQFrame returnFrame = BasicReturnBody.createAMQFrame(channelId,
+ getProtocolMajorVersion(),
+ getProtocolMinorVersion(),
+ message.getMessagePublishInfo().getExchange(),
+ replyCode, replyText,
+ message.getMessagePublishInfo().getRoutingKey());
+ ByteBuffer buf = ByteBuffer.allocate((int) returnFrame.getSize()); // XXX: Could cast be a problem?
+ returnFrame.writePayload(buf);
+ buf.flip();
+ return buf;
+ }
+
+ public void writeReturn(AMQMessage message, int channelId, int replyCode, AMQShortString replyText)
+ throws AMQException
+ {
+ ByteBuffer returnFrame = createEncodedReturnFrame(message, channelId, replyCode, replyText);
+
+ AMQDataBlock contentHeader = ContentHeaderBody.createAMQFrame(channelId,
+ message.getContentHeaderBody());
+
+ Iterator<AMQDataBlock> bodyFrameIterator = message.getBodyFrameIterator(getProtocolSession(), channelId);
+ //
+ // Optimise the case where we have a single content body. In that case we create a composite block
+ // so that we can writeDeliver out the deliver, header and body with a single network writeDeliver.
+ //
+ if (bodyFrameIterator.hasNext())
+ {
+ AMQDataBlock firstContentBody = bodyFrameIterator.next();
+ AMQDataBlock[] headerAndFirstContent = new AMQDataBlock[]{contentHeader, firstContentBody};
+ CompositeAMQDataBlock compositeBlock = new CompositeAMQDataBlock(returnFrame, headerAndFirstContent);
+ writeFrame(compositeBlock);
+ }
+ else
+ {
+ CompositeAMQDataBlock compositeBlock = new CompositeAMQDataBlock(returnFrame,
+ new AMQDataBlock[]{contentHeader});
+
+ writeFrame(compositeBlock);
+ }
+
+ //
+ // Now start writing out the other content bodies
+ // TODO: MINA needs to be fixed so the the pending writes buffer is not unbounded
+ //
+ while (bodyFrameIterator.hasNext())
+ {
+ writeFrame(bodyFrameIterator.next());
+ }
+ }
+
+
+ public void writeFrame(AMQDataBlock block)
+ {
+ getProtocolSession().writeFrame(block);
+ }
+
+
+ public void confirmConsumerAutoClose(int channelId, AMQShortString consumerTag)
+ {
+
+ writeFrame(BasicCancelOkBody.createAMQFrame(channelId,
+ getProtocolMajorVersion(),
+ getProtocolMinorVersion(),
+ consumerTag // consumerTag
+ ));
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java
index 2de32c2f0f..587cb3b2aa 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java
@@ -43,25 +43,15 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.codec.AMQCodecFactory;
import org.apache.qpid.codec.AMQDecoder;
import org.apache.qpid.common.ClientProperties;
-import org.apache.qpid.framing.AMQDataBlock;
-import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.ConnectionStartBody;
-import org.apache.qpid.framing.ContentBody;
-import org.apache.qpid.framing.ContentHeaderBody;
-import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.framing.HeartbeatBody;
-import org.apache.qpid.framing.MainRegistry;
-import org.apache.qpid.framing.ProtocolInitiation;
-import org.apache.qpid.framing.ProtocolVersionList;
-import org.apache.qpid.framing.VersionSpecificRegistry;
-import org.apache.qpid.framing.ChannelCloseOkBody;
+import org.apache.qpid.framing.*;
+import org.apache.qpid.framing.amqp_8_0.ConnectionStartBodyImpl;
import org.apache.qpid.pool.ReadWriteThreadModel;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.output.ProtocolOutputConverter;
+import org.apache.qpid.server.output.ProtocolOutputConverterRegistry;
import org.apache.qpid.server.management.Managable;
import org.apache.qpid.server.management.ManagedObject;
import org.apache.qpid.server.registry.ApplicationRegistry;
@@ -71,7 +61,6 @@ import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
public class AMQMinaProtocolSession implements AMQProtocolSession,
- ProtocolVersionList,
Managable
{
private static final Logger _logger = Logger.getLogger(AMQProtocolSession.class);
@@ -111,12 +100,13 @@ public class AMQMinaProtocolSession implements AMQProtocolSession,
private long _maxNoOfChannels = 1000;
/* AMQP Version for this session */
- private byte _major = pv[pv.length - 1][PROTOCOL_MAJOR];
- private byte _minor = pv[pv.length - 1][PROTOCOL_MINOR];
+ private ProtocolVersion _protocolVersion = ProtocolVersion.getLatestSupportedVersion();
+
private FieldTable _clientProperties;
private final List<Task> _taskList = new CopyOnWriteArrayList<Task>();
- private VersionSpecificRegistry _registry = MainRegistry.getVersionSpecificRegistry(pv[pv.length - 1][PROTOCOL_MAJOR], pv[pv.length - 1][PROTOCOL_MINOR]);
+ private VersionSpecificRegistry _registry = MainRegistry.getVersionSpecificRegistry(_protocolVersion);
private List<Integer> _closingChannelsList = new ArrayList<Integer>();
+ private ProtocolOutputConverter _protocolOutputConverter;
public ManagedObject getManagedObject()
@@ -195,86 +185,123 @@ public class AMQMinaProtocolSession implements AMQProtocolSession,
_lastReceived = message;
if (message instanceof ProtocolInitiation)
{
- ProtocolInitiation pi = (ProtocolInitiation) message;
- // this ensures the codec never checks for a PI message again
- ((AMQDecoder) _codecFactory.getDecoder()).setExpectProtocolInitiation(false);
- try
- {
- pi.checkVersion(this); // Fails if not correct
+ protocolInitiationReceived((ProtocolInitiation) message);
- // This sets the protocol version (and hence framing classes) for this session.
- setProtocolVersion(pi.protocolMajor, pi.protocolMinor);
+ }
+ else if (message instanceof AMQFrame)
+ {
+ AMQFrame frame = (AMQFrame) message;
+ frameReceived(frame);
- String mechanisms = ApplicationRegistry.getInstance().getAuthenticationManager().getMechanisms();
+ }
+ else
+ {
+ throw new UnknnownMessageTypeException(message);
+ }
+ }
- String locales = "en_US";
+ private void frameReceived(AMQFrame frame)
+ throws AMQException
+ {
+ int channelId = frame.getChannel();
+ AMQBody body = frame.getBodyFrame();
- // Interfacing with generated code - be aware of possible changes to parameter order as versions change.
- AMQFrame response = ConnectionStartBody.createAMQFrame((short) 0,
- _major, _minor, // AMQP version (major, minor)
- locales.getBytes(), // locales
- mechanisms.getBytes(), // mechanisms
- null, // serverProperties
- (short) _major, // versionMajor
- (short) _minor); // versionMinor
- _minaProtocolSession.write(response);
- }
- catch (AMQException e)
- {
- _logger.error("Received incorrect protocol initiation", e);
- /* Find last protocol version in protocol version list. Make sure last protocol version
- listed in the build file (build-module.xml) is the latest version which will be used
- here. */
- int i = pv.length - 1;
- _minaProtocolSession.write(new ProtocolInitiation(pv[i][PROTOCOL_MAJOR], pv[i][PROTOCOL_MINOR]));
- // TODO: Close connection (but how to wait until message is sent?)
- // ritchiem 2006-12-04 will this not do?
-// WriteFuture future = _minaProtocolSession.write(new ProtocolInitiation(pv[i][PROTOCOL_MAJOR], pv[i][PROTOCOL_MINOR]));
-// future.join();
-// close connection
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Frame Received: " + frame);
+ }
- }
+ if (body instanceof AMQMethodBodyImpl)
+ {
+ methodFrameReceived(channelId, (AMQMethodBodyImpl)body);
+ }
+ else if (body instanceof ContentHeaderBody)
+ {
+ contentHeaderReceived(channelId, (ContentHeaderBody)body);
+ }
+ else if (body instanceof ContentBody)
+ {
+ contentBodyReceived(channelId, (ContentBody)body);
+ }
+ else if (body instanceof HeartbeatBody)
+ {
+ // NO OP
}
else
{
- AMQFrame frame = (AMQFrame) message;
-
- if (frame.getBodyFrame() instanceof AMQMethodBody)
- {
- methodFrameReceived(frame);
- }
- else
- {
- contentFrameReceived(frame);
- }
+ _logger.warn("Unrecognised frame " + frame.getClass().getName());
}
}
- private void methodFrameReceived(AMQFrame frame)
+ private void protocolInitiationReceived(ProtocolInitiation pi)
{
- if (_logger.isDebugEnabled())
+ // this ensures the codec never checks for a PI message again
+ ((AMQDecoder) _codecFactory.getDecoder()).setExpectProtocolInitiation(false);
+ try
+ {
+ pi.checkVersion(); // Fails if not correct
+
+ // This sets the protocol version (and hence framing classes) for this session.
+ setProtocolVersion(pi._protocolMajor, pi._protocolMinor);
+
+ String mechanisms = ApplicationRegistry.getInstance().getAuthenticationManager().getMechanisms();
+
+ String locales = "en_US";
+
+ ConnectionStartBody connectionStartBody = createConnectionStartBody(pi,
+ locales.getBytes(),
+ mechanisms.getBytes(),
+ null);
+
+ // Interfacing with generated code - be aware of possible changes to parameter order as versions change.
+ AMQFrame response = new AMQFrame((short) 0,connectionStartBody); // versionMinor
+ _minaProtocolSession.write(response);
+ }
+ catch (AMQException e)
{
- _logger.debug("Method frame received: " + frame);
+ _logger.error("Received incorrect protocol initiation", e);
+
+ _minaProtocolSession.write(new ProtocolInitiation(ProtocolVersion.getLatestSupportedVersion()));
+
+ // TODO: Close connection (but how to wait until message is sent?)
+ // ritchiem 2006-12-04 will this not do?
+// WriteFuture future = _minaProtocolSession.write(new ProtocolInitiation(pv[i][PROTOCOLgetProtocolMajorVersion()], pv[i][PROTOCOLgetProtocolMinorVersion()]));
+// future.join();
+// close connection
+
}
+ }
- final AMQMethodEvent<AMQMethodBody> evt = new AMQMethodEvent<AMQMethodBody>(frame.getChannel(),
- (AMQMethodBody) frame.getBodyFrame());
+ private ConnectionStartBody createConnectionStartBody(ProtocolInitiation pi,
+ byte[] locales,
+ byte[] mechanisms,
+ FieldTable serverProperties)
+ {
+ return new ConnectionStartBodyImpl(pi._protocolMajor, pi._protocolMinor,serverProperties,mechanisms,locales);
+ }
+
+
+ private void methodFrameReceived(int channelId, AMQMethodBodyImpl methodBody)
+ {
+
+ final AMQMethodEvent<AMQMethodBodyImpl> evt = new AMQMethodEvent<AMQMethodBodyImpl>(channelId,
+ methodBody);
//Check that this channel is not closing
- if (channelAwaitingClosure(frame.getChannel()))
+ if (channelAwaitingClosure(channelId))
{
if ((evt.getMethod() instanceof ChannelCloseOkBody))
{
if (_logger.isInfoEnabled())
{
- _logger.info("Channel[" + frame.getChannel() + "] awaiting closure - processing close-ok");
+ _logger.info("Channel[" + channelId + "] awaiting closure - processing close-ok");
}
}
else
{
if (_logger.isInfoEnabled())
{
- _logger.info("Channel[" + frame.getChannel() + "] awaiting closure ignoring");
+ _logger.info("Channel[" + channelId + "] awaiting closure ignoring");
}
return;
}
@@ -298,19 +325,19 @@ public class AMQMinaProtocolSession implements AMQProtocolSession,
}
if (!wasAnyoneInterested)
{
- throw new AMQException("AMQMethodEvent " + evt + " was not processed by any listener on Broker.");
+ throw new AMQNoMethodHandlerException(evt);
}
}
catch (AMQChannelException e)
{
- if (getChannel(frame.getChannel()) != null)
+ if (getChannel(channelId) != null)
{
if (_logger.isInfoEnabled())
{
_logger.info("Closing channel due to: " + e.getMessage());
}
- writeFrame(e.getCloseFrame(frame.getChannel()));
- closeChannel(frame.getChannel());
+ writeFrame(e.getCloseFrame(channelId));
+ closeChannel(channelId);
}
else
{
@@ -328,7 +355,7 @@ public class AMQMinaProtocolSession implements AMQProtocolSession,
AMQConstant.CHANNEL_ERROR.getName().toString());
_stateManager.changeState(AMQState.CONNECTION_CLOSING);
- writeFrame(ce.getCloseFrame(frame.getChannel()));
+ writeFrame(ce.getCloseFrame(channelId));
}
}
catch (AMQConnectionException e)
@@ -339,7 +366,7 @@ public class AMQMinaProtocolSession implements AMQProtocolSession,
}
closeSession();
_stateManager.changeState(AMQState.CONNECTION_CLOSING);
- writeFrame(e.getCloseFrame(frame.getChannel()));
+ writeFrame(e.getCloseFrame(channelId));
}
}
catch (Exception e)
@@ -353,61 +380,21 @@ public class AMQMinaProtocolSession implements AMQProtocolSession,
}
}
- private void contentFrameReceived(AMQFrame frame) throws AMQException
- {
- if (frame.getBodyFrame() instanceof ContentHeaderBody)
- {
- contentHeaderReceived(frame);
- }
- else if (frame.getBodyFrame() instanceof ContentBody)
- {
- contentBodyReceived(frame);
- }
- else if (frame.getBodyFrame() instanceof HeartbeatBody)
- {
- _logger.debug("Received heartbeat from client");
- }
- else
- {
- _logger.warn("Unrecognised frame " + frame.getClass().getName());
- }
- }
- private void contentHeaderReceived(AMQFrame frame) throws AMQException
+ private void contentHeaderReceived(int channelId, ContentHeaderBody body) throws AMQException
{
- if (_logger.isDebugEnabled())
- {
- _logger.debug("Content header frame received: " + frame);
- }
- AMQChannel channel = getChannel(frame.getChannel());
+ AMQChannel channel = getAndAssertChannel(channelId);
+
+ channel.publishContentHeader(body);
- if (channel == null)
- {
- throw new AMQException(AMQConstant.NOT_FOUND, "Channel not found with id:" + frame.getChannel());
- }
- else
- {
- channel.publishContentHeader((ContentHeaderBody) frame.getBodyFrame());
- }
}
- private void contentBodyReceived(AMQFrame frame) throws AMQException
+ private void contentBodyReceived(int channelId, ContentBody body) throws AMQException
{
- if (_logger.isDebugEnabled())
- {
- _logger.debug("Content body frame received: " + frame);
- }
- AMQChannel channel = getChannel(frame.getChannel());
+ AMQChannel channel = getAndAssertChannel(channelId);
- if (channel == null)
- {
- throw new AMQException(AMQConstant.NOT_FOUND, "Channel not found with id:" + frame.getChannel());
- }
- else
- {
- channel.publishContentBody((ContentBody) frame.getBodyFrame(), this);
- }
+ channel.publishContentBody(body, this);
}
/**
@@ -437,6 +424,16 @@ public class AMQMinaProtocolSession implements AMQProtocolSession,
return new ArrayList<AMQChannel>(_channelMap.values());
}
+ public AMQChannel getAndAssertChannel(int channelId) throws AMQException
+ {
+ AMQChannel channel = getChannel(channelId);
+ if (channel == null)
+ {
+ throw new AMQException(AMQConstant.NOT_FOUND, "Channel not found with id:" + channelId);
+ }
+ return channel;
+ }
+
public AMQChannel getChannel(int channelId) throws AMQException
{
if (channelAwaitingClosure(channelId))
@@ -685,24 +682,26 @@ public class AMQMinaProtocolSession implements AMQProtocolSession,
private void setProtocolVersion(byte major, byte minor)
{
- _major = major;
- _minor = minor;
- _registry = MainRegistry.getVersionSpecificRegistry(major, minor);
+ _protocolVersion = new ProtocolVersion(major,minor);
+
+ _registry = MainRegistry.getVersionSpecificRegistry(_protocolVersion);
+
+ _protocolOutputConverter = ProtocolOutputConverterRegistry.getConverter(this);
}
public byte getProtocolMajorVersion()
{
- return _major;
+ return _protocolVersion.getMajorVersion();
}
public byte getProtocolMinorVersion()
{
- return _minor;
+ return _protocolVersion.getMinorVersion();
}
public boolean isProtocolVersion(byte major, byte minor)
{
- return _major == major && _minor == minor;
+ return getProtocolMajorVersion() == major && getProtocolMinorVersion() == minor;
}
public VersionSpecificRegistry getRegistry()
@@ -739,5 +738,14 @@ public class AMQMinaProtocolSession implements AMQProtocolSession,
_taskList.remove(task);
}
+ public ProtocolOutputConverter getProtocolOutputConverter()
+ {
+ return _protocolOutputConverter;
+ }
+
+ public ProtocolVersion getProtocolVersion()
+ {
+ return _protocolVersion;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQNoMethodHandlerException.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQNoMethodHandlerException.java
new file mode 100644
index 0000000000..82f6e96906
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQNoMethodHandlerException.java
@@ -0,0 +1,34 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.protocol;
+
+import org.apache.qpid.framing.AMQMethodBodyImpl;
+import org.apache.qpid.protocol.AMQMethodEvent;
+import org.apache.qpid.AMQException;
+
+public class AMQNoMethodHandlerException extends AMQException
+{
+
+ public AMQNoMethodHandlerException(AMQMethodEvent<AMQMethodBodyImpl> evt)
+ {
+ super("AMQMethodEvent " + evt + " was not processed by any listener on Broker.");
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQPFastProtocolHandler.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQPFastProtocolHandler.java
index 9d397505dc..756a8b5ebe 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQPFastProtocolHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQPFastProtocolHandler.java
@@ -39,7 +39,7 @@ import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ConnectionCloseBody;
import org.apache.qpid.framing.HeartbeatBody;
import org.apache.qpid.framing.ProtocolInitiation;
-import org.apache.qpid.framing.ProtocolVersionList;
+import org.apache.qpid.framing.ProtocolVersion;
import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.transport.ConnectorConfiguration;
@@ -53,7 +53,7 @@ import org.apache.qpid.ssl.SSLContextFactory;
* the state for the connection.
*
*/
-public class AMQPFastProtocolHandler extends IoHandlerAdapter implements ProtocolVersionList
+public class AMQPFastProtocolHandler extends IoHandlerAdapter
{
private static final Logger _logger = Logger.getLogger(AMQPFastProtocolHandler.class);
@@ -162,12 +162,11 @@ public class AMQPFastProtocolHandler extends IoHandlerAdapter implements Protoco
AMQProtocolSession session = AMQMinaProtocolSession.getAMQProtocolSession(protocolSession);
if (throwable instanceof AMQProtocolHeaderException)
{
- /* Find last protocol version in protocol version list. Make sure last protocol version
- listed in the build file (build-module.xml) is the latest version which will be returned
- here. */
- int i = pv.length - 1;
- protocolSession.write(new ProtocolInitiation(pv[i][PROTOCOL_MAJOR], pv[i][PROTOCOL_MINOR]));
+
+ protocolSession.write(new ProtocolInitiation(ProtocolVersion.getLatestSupportedVersion()));
+
protocolSession.close();
+
_logger.error("Error in protocol initiation " + session + ": " + throwable.getMessage(), throwable);
}
else if(throwable instanceof IOException)
@@ -176,8 +175,6 @@ public class AMQPFastProtocolHandler extends IoHandlerAdapter implements Protoco
}
else
{
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
// Be aware of possible changes to parameter order as versions change.
protocolSession.write(ConnectionCloseBody.createAMQFrame(0,
session.getProtocolMajorVersion(),
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java
index 503dc8b554..4cfee06850 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java
@@ -28,6 +28,7 @@ import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.output.ProtocolOutputConverter;
import org.apache.qpid.server.virtualhost.VirtualHost;
@@ -162,4 +163,6 @@ public interface AMQProtocolSession extends AMQVersionAwareProtocolSession
void removeSessionCloseTask(Task task);
+ public ProtocolOutputConverter getProtocolOutputConverter();
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java
index ea89136a62..50cbc35266 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java
@@ -24,6 +24,7 @@ import javax.management.JMException;
import javax.management.MBeanException;
import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
+import javax.management.NotCompliantMBeanException;
import javax.management.monitor.MonitorNotification;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
@@ -39,6 +40,7 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ConnectionCloseBody;
+import org.apache.qpid.framing.amqp_8_0.ConnectionCloseBodyImpl;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.management.AMQManagedObject;
@@ -65,7 +67,7 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
new AMQShortString("Broker Management Console has closed the connection.");
@MBeanConstructor("Creates an MBean exposing an AMQ Broker Connection")
- public AMQProtocolSessionMBean(AMQMinaProtocolSession session) throws JMException
+ public AMQProtocolSessionMBean(AMQMinaProtocolSession session) throws NotCompliantMBeanException, OpenDataException
{
super(ManagedConnection.class, ManagedConnection.TYPE);
_session = session;
@@ -74,6 +76,8 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
_name = jmxEncode(new StringBuffer(remote), 0).toString();
init();
}
+
+
static
{
try
@@ -94,7 +98,7 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
{
_channelType = new CompositeType("Channel", "Channel Details", _channelAtttibuteNames,
- _channelAtttibuteNames, _channelAttributeTypes);
+ _channelAtttibuteNames, _channelAttributeTypes);
_channelsType = new TabularType("Channels", "Channels", _channelType, _indexNames);
}
@@ -215,18 +219,11 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
*/
public void closeConnection() throws JMException
{
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- final AMQFrame response = ConnectionCloseBody.createAMQFrame(0,
- _session.getProtocolMajorVersion(),
- _session.getProtocolMinorVersion(), // AMQP version (major, minor)
- 0, // classId
- 0, // methodId
- AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
+ ConnectionCloseBody connectionCloseBody =
+ createConnectionCloseBody(AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
BROKER_MANAGEMENT_CONSOLE_HAS_CLOSED_THE_CONNECTION // replyText
);
- _session.writeFrame(response);
+ _session.writeFrame(new AMQFrame(0,connectionCloseBody));
try
{
@@ -238,6 +235,11 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
}
}
+ private ConnectionCloseBody createConnectionCloseBody(int code, AMQShortString replyText)
+ {
+ return new ConnectionCloseBodyImpl(code,replyText,0,0);
+ }
+
@Override
public MBeanNotificationInfo[] getNotificationInfo()
{
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/UnknnownMessageTypeException.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/UnknnownMessageTypeException.java
new file mode 100644
index 0000000000..45d09e8f3e
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/UnknnownMessageTypeException.java
@@ -0,0 +1,33 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.protocol;
+
+import org.apache.qpid.framing.AMQDataBlock;
+import org.apache.qpid.AMQException;
+
+public class UnknnownMessageTypeException extends AMQException
+{
+ public UnknnownMessageTypeException(AMQDataBlock message)
+ {
+ super("Unknown message type: " + message.getClass().getName() + ": " + message);
+
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java
index aa7ea16afc..32873c3cf5 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java
@@ -20,23 +20,34 @@
*/
package org.apache.qpid.server.queue;
-import java.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.log4j.Logger;
-import org.apache.mina.common.ByteBuffer;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.*;
+import org.apache.qpid.framing.AMQBodyImpl;
+import org.apache.qpid.framing.AMQDataBlock;
+import org.apache.qpid.framing.AMQFrame;
+import org.apache.qpid.framing.ContentHeaderBody;
+import org.apache.qpid.framing.abstraction.ContentChunk;
+import org.apache.qpid.framing.abstraction.MessagePublishInfo;
+import org.apache.qpid.framing.abstraction.ProtocolVersionMethodConverter;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.store.MessageStore;
import org.apache.qpid.server.store.StoreContext;
-import org.apache.qpid.framing.abstraction.MessagePublishInfo;
-import org.apache.qpid.framing.abstraction.ProtocolVersionMethodConverter;
-import org.apache.qpid.framing.abstraction.ContentChunk;
import org.apache.qpid.server.txn.TransactionalContext;
/** Combines the information that make up a deliverable message into a more manageable form. */
+
+import org.apache.log4j.Logger;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Combines the information that make up a deliverable message into a more manageable form.
+ */
public class AMQMessage
{
private static final Logger _log = Logger.getLogger(AMQMessage.class);
@@ -114,7 +125,7 @@ public class AMQMessage
try
{
- AMQBody cb = getProtocolVersionMethodConverter().convertToBody(_messageHandle.getContentChunk(getStoreContext(), _messageId, ++_index));
+ AMQBodyImpl cb = getProtocolVersionMethodConverter().convertToBody(_messageHandle.getContentChunk(getStoreContext(), _messageId, ++_index));
return new AMQFrame(_channel, cb);
}
catch (AMQException e)
@@ -136,7 +147,7 @@ public class AMQMessage
}
}
- private StoreContext getStoreContext()
+ public StoreContext getStoreContext()
{
return _txnContext.getStoreContext();
}
@@ -579,6 +590,7 @@ public class AMQMessage
}
}
+/*
public void writeDeliver(AMQProtocolSession protocolSession, int channelId, long deliveryTag, AMQShortString consumerTag)
throws AMQException
{
@@ -746,6 +758,12 @@ public class AMQMessage
protocolSession.writeFrame(bodyFrameIterator.next());
}
}
+*/
+
+ public AMQMessageHandle getMessageHandle()
+ {
+ return _messageHandle;
+ }
public long getSize()
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java
index 4fd89f39da..c9329a244c 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java
@@ -41,9 +41,9 @@ import javax.management.openmbean.TabularType;
import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.BasicContentHeaderProperties;
-import org.apache.qpid.framing.ContentBody;
+import org.apache.qpid.framing.CommonContentHeaderProperties;
import org.apache.qpid.framing.ContentHeaderBody;
+import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.abstraction.ContentChunk;
import org.apache.qpid.server.management.AMQManagedObject;
import org.apache.qpid.server.management.MBeanConstructor;
@@ -344,12 +344,13 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
try
{
// Create header attributes list
- BasicContentHeaderProperties headerProperties = (BasicContentHeaderProperties) msg.getContentHeaderBody().properties;
+ CommonContentHeaderProperties headerProperties = (CommonContentHeaderProperties) msg.getContentHeaderBody().properties;
String mimeType = null, encoding = null;
if (headerProperties != null)
{
- mimeType = headerProperties.getContentType();
- encoding = headerProperties.getEncoding() == null ? "" : headerProperties.getEncoding();
+ AMQShortString mimeTypeShortSting = headerProperties.getContentType();
+ mimeType = mimeTypeShortSting == null ? null : mimeTypeShortSting.toString();
+ encoding = headerProperties.getEncoding() == null ? "" : headerProperties.getEncoding().toString();
}
Object[] itemValues = {msgId, mimeType, encoding, msgContent.toArray(new Byte[0])};
return new CompositeDataSupport(_msgContentType, _msgContentAttributes, itemValues);
@@ -382,7 +383,7 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
AMQMessage msg = list.get(i - 1);
ContentHeaderBody headerBody = msg.getContentHeaderBody();
// Create header attributes list
- BasicContentHeaderProperties headerProperties = (BasicContentHeaderProperties) headerBody.properties;
+ CommonContentHeaderProperties headerProperties = (CommonContentHeaderProperties) headerBody.properties;
String[] headerAttributes = headerProperties.toString().split(",");
Object[] itemValues = {msg.getMessageId(), headerAttributes, headerBody.bodySize, msg.isRedelivered()};
CompositeData messageData = new CompositeDataSupport(_messageDataType, _msgAttributeNames, itemValues);
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/ConcurrentSelectorDeliveryManager.java b/java/broker/src/main/java/org/apache/qpid/server/queue/ConcurrentSelectorDeliveryManager.java
index 208a59516c..e70926736d 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/ConcurrentSelectorDeliveryManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/ConcurrentSelectorDeliveryManager.java
@@ -270,7 +270,8 @@ public class ConcurrentSelectorDeliveryManager implements DeliveryManager
channel.addUnacknowledgedMessage(msg, deliveryTag, null, _queue);
}
- msg.writeGetOk(protocolSession, channel.getChannelId(), deliveryTag, _queue.getMessageCount());
+ protocolSession.getProtocolOutputConverter().writeGetOk(msg, channel.getChannelId(),
+ deliveryTag, _queue.getMessageCount());
_totalMessageSize.addAndGet(-msg.getSize());
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/SubscriptionImpl.java b/java/broker/src/main/java/org/apache/qpid/server/queue/SubscriptionImpl.java
index ede7731a06..0a2e73880c 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/SubscriptionImpl.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/SubscriptionImpl.java
@@ -29,9 +29,9 @@ import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.common.ClientProperties;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.BasicCancelOkBody;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.output.ProtocolOutputConverter;
import org.apache.qpid.server.filter.FilterManager;
import org.apache.qpid.server.filter.FilterManagerFactory;
import org.apache.qpid.server.protocol.AMQProtocolSession;
@@ -258,7 +258,7 @@ public class SubscriptionImpl implements Subscription
{
channel.addUnacknowledgedBrowsedMessage(msg, deliveryTag, consumerTag, queue);
}
- msg.writeDeliver(protocolSession, channel.getChannelId(), deliveryTag, consumerTag);
+ protocolSession.getProtocolOutputConverter().writeDeliver(msg, channel.getChannelId(), deliveryTag, consumerTag);
}
}
@@ -294,7 +294,7 @@ public class SubscriptionImpl implements Subscription
msg.decrementReference(storeContext);
}
- msg.writeDeliver(protocolSession, channel.getChannelId(), deliveryTag, consumerTag);
+ protocolSession.getProtocolOutputConverter().writeDeliver(msg, channel.getChannelId(), deliveryTag, consumerTag);
}
}
@@ -466,13 +466,9 @@ public class SubscriptionImpl implements Subscription
if (_autoClose && !_sentClose)
{
_logger.info("Closing autoclose subscription:" + this);
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- protocolSession.writeFrame(BasicCancelOkBody.createAMQFrame(channel.getChannelId(),
- (byte) 8, (byte) 0, // AMQP version (major, minor)
- consumerTag // consumerTag
- ));
+ ProtocolOutputConverter converter = protocolSession.getProtocolOutputConverter();
+ converter.confirmConsumerAutoClose(channel.getChannelId(), consumerTag);
+
_sentClose = true;
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java b/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java
index d12f5cd084..73401ee664 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java
@@ -27,35 +27,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.framing.BasicAckBody;
-import org.apache.qpid.framing.BasicCancelBody;
-import org.apache.qpid.framing.BasicConsumeBody;
-import org.apache.qpid.framing.BasicGetBody;
-import org.apache.qpid.framing.BasicPublishBody;
-import org.apache.qpid.framing.BasicQosBody;
-import org.apache.qpid.framing.BasicRecoverBody;
-import org.apache.qpid.framing.ChannelCloseBody;
-import org.apache.qpid.framing.ChannelCloseOkBody;
-import org.apache.qpid.framing.ChannelFlowBody;
-import org.apache.qpid.framing.ChannelOpenBody;
-import org.apache.qpid.framing.ConnectionCloseBody;
-import org.apache.qpid.framing.ConnectionCloseOkBody;
-import org.apache.qpid.framing.ConnectionOpenBody;
-import org.apache.qpid.framing.ConnectionSecureOkBody;
-import org.apache.qpid.framing.ConnectionStartOkBody;
-import org.apache.qpid.framing.ConnectionTuneOkBody;
-import org.apache.qpid.framing.ExchangeBoundBody;
-import org.apache.qpid.framing.ExchangeDeclareBody;
-import org.apache.qpid.framing.ExchangeDeleteBody;
-import org.apache.qpid.framing.QueueBindBody;
-import org.apache.qpid.framing.QueueDeclareBody;
-import org.apache.qpid.framing.QueueDeleteBody;
-import org.apache.qpid.framing.QueuePurgeBody;
-import org.apache.qpid.framing.TxCommitBody;
-import org.apache.qpid.framing.TxRollbackBody;
-import org.apache.qpid.framing.TxSelectBody;
-import org.apache.qpid.framing.BasicRejectBody;
+import org.apache.qpid.framing.*;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
import org.apache.qpid.server.handler.BasicAckMethodHandler;
diff --git a/java/broker/src/main/java/org/apache/qpid/server/state/StateAwareMethodListener.java b/java/broker/src/main/java/org/apache/qpid/server/state/StateAwareMethodListener.java
index e3af0bc486..2f28a3125d 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/state/StateAwareMethodListener.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/state/StateAwareMethodListener.java
@@ -21,6 +21,7 @@
package org.apache.qpid.server.state;
import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.framing.AMQMethodBody;
import org.apache.qpid.protocol.AMQMethodEvent;
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/ContentChunkAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/store/ContentChunkAdapter.java
deleted file mode 100644
index 90aa7bb998..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/store/ContentChunkAdapter.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.server.store;
-
-import org.apache.qpid.framing.ContentBody;
-import org.apache.qpid.framing.abstraction.ContentChunk;
-
-import org.apache.mina.common.ByteBuffer;
-
-public class ContentChunkAdapter
-{
- public static ContentBody toConentBody(ContentChunk contentBodyChunk)
- {
- return new ContentBody(contentBodyChunk.getData());
- }
-
- public static ContentChunk toConentChunk(final ContentBody contentBodyChunk)
- {
- return new ContentChunk() {
-
- public int getSize()
- {
- return contentBodyChunk.getSize();
- }
-
- public ByteBuffer getData()
- {
- return contentBodyChunk.payload;
- }
-
- public void reduceToFit()
- {
- contentBodyChunk.reduceBufferToFit();
- }
- };
-
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/MessagePublishInfoAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/store/MessagePublishInfoAdapter.java
deleted file mode 100644
index 6ee2fa784d..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/store/MessagePublishInfoAdapter.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.apache.qpid.server.store;
-
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.BasicPublishBody;
-import org.apache.qpid.framing.abstraction.MessagePublishInfo;
-
-public class MessagePublishInfoAdapter
-{
- private final byte _majorVersion;
- private final byte _minorVersion;
- private final int _classId;
- private final int _methodId;
-
-
- public MessagePublishInfoAdapter(byte majorVersion, byte minorVersion)
- {
- _majorVersion = majorVersion;
- _minorVersion = minorVersion;
- _classId = BasicPublishBody.getClazz(majorVersion,minorVersion);
- _methodId = BasicPublishBody.getMethod(majorVersion,minorVersion);
- }
-
- public BasicPublishBody toMethodBody(MessagePublishInfo pubInfo)
- {
- return new BasicPublishBody(_majorVersion,
- _minorVersion,
- _classId,
- _methodId,
- pubInfo.getExchange(),
- pubInfo.isImmediate(),
- pubInfo.isMandatory(),
- pubInfo.getRoutingKey(),
- 0) ; // ticket
- }
-
- public MessagePublishInfo toMessagePublishInfo(final BasicPublishBody body)
- {
- return new MessagePublishInfo()
- {
-
- public AMQShortString getExchange()
- {
- return body.getExchange();
- }
-
- public boolean isImmediate()
- {
- return body.getImmediate();
- }
-
- public boolean isMandatory()
- {
- return body.getMandatory();
- }
-
- public AMQShortString getRoutingKey()
- {
- return body.getRoutingKey();
- }
- };
- }
-}
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
index 413524b6d8..1b4ae02399 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
@@ -25,7 +25,8 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.AMQUndeliveredException;
import org.apache.qpid.AMQUnresolvedAddressException;
import org.apache.qpid.client.failover.FailoverSupport;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
+import org.apache.qpid.client.protocol.AMQProtocolHandlerImpl;
+import org.apache.qpid.client.protocol.ProtocolOutputHandler;
import org.apache.qpid.client.state.AMQState;
import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.exchange.ExchangeDefaults;
@@ -36,6 +37,8 @@ import org.apache.qpid.framing.ChannelOpenBody;
import org.apache.qpid.framing.ChannelOpenOkBody;
import org.apache.qpid.framing.TxSelectBody;
import org.apache.qpid.framing.TxSelectOkBody;
+import org.apache.qpid.framing.AMQMethodFactory;
+import org.apache.qpid.framing.AMQMethodBody;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.ChannelLimitReachedException;
import org.apache.qpid.jms.Connection;
@@ -92,7 +95,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
* the handler deals with this. It also deals with the initial dispatch of any protocol frames to their appropriate
* handler.
*/
- private AMQProtocolHandler _protocolHandler;
+ private AMQProtocolHandlerImpl _protocolHandler;
/** Maps from session id (Integer) to AMQSession instance */
private final Map _sessions = new LinkedHashMap(); //fixme this is map is replicated in amqprotocolsession as _channelId2SessionMap
@@ -273,7 +276,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
_failoverPolicy = new FailoverPolicy(connectionURL);
- _protocolHandler = new AMQProtocolHandler(this);
+ _protocolHandler = new AMQProtocolHandlerImpl(this);
// We are not currently connected
_connected = false;
@@ -550,26 +553,15 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
private void createChannelOverWire(int channelId, int prefetchHigh, int prefetchLow, boolean transacted)
throws AMQException
{
+ // define this here, should be poassed in
+ final int prefetchSize = 0;
- // TODO: Be aware of possible changes to parameter order as versions change.
+ AMQMethodFactory methodFactory = getAMQMethodFactory();
- _protocolHandler.syncWrite(
- ChannelOpenBody.createAMQFrame(channelId,
- _protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion(),
- null), // outOfBand
- ChannelOpenOkBody.class);
-
- //todo send low water mark when protocol allows.
- //todo Be aware of possible changes to parameter order as versions change.
- _protocolHandler.syncWrite(
- BasicQosBody.createAMQFrame(channelId,
- _protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion(),
- false, // global
- prefetchHigh, // prefetchCount
- 0), // prefetchSize
- BasicQosOkBody.class);
+ ChannelOpenBody openBody = methodFactory.createChannelOpen();
+ sendCommandReceiveResponse(channelId, openBody);
+ AMQMethodBody qosBody = methodFactory.createMessageQos(prefetchHigh, prefetchSize);
+ sendCommandReceiveResponse(channelId, qosBody);
if (transacted)
{
@@ -578,14 +570,21 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
_logger.debug("Issuing TxSelect for " + channelId);
}
- // TODO: Be aware of possible changes to parameter order as versions change.
- _protocolHandler.syncWrite(TxSelectBody.createAMQFrame(channelId,
- _protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion()),
- TxSelectOkBody.class);
+ TxSelectBody txSelectBody = methodFactory.createTxSelect();
+ sendCommandReceiveResponse(channelId, txSelectBody);
}
}
+ private AMQMethodBody sendCommandReceiveResponse(int channelId, AMQMethodBody command) throws AMQException
+ {
+ return getProtocolOutputHandler().sendCommandReceiveResponse(channelId, command);
+ }
+
+ private AMQMethodFactory getAMQMethodFactory()
+ {
+ return getProtocolOutputHandler().getAMQMethodFactory();
+ }
+
private void reopenChannel(int channelId, int prefetchHigh, int prefetchLow, boolean transacted) throws AMQException
{
try
@@ -934,7 +933,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
return _virtualHost;
}
- public AMQProtocolHandler getProtocolHandler()
+ public AMQProtocolHandlerImpl getProtocolHandler()
{
return _protocolHandler;
}
@@ -1218,4 +1217,9 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
{
_taskPool.execute(task);
}
+
+ public ProtocolOutputHandler getProtocolOutputHandler()
+ {
+ return _protocolHandler.getOutputHandler();
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
index 89f596e541..41101ff374 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
@@ -59,6 +59,7 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.AMQUndeliveredException;
import org.apache.qpid.AMQInvalidRoutingKeyException;
import org.apache.qpid.AMQInvalidArgumentException;
+import org.apache.qpid.AMQTimeoutException;
import org.apache.qpid.client.failover.FailoverSupport;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.JMSBytesMessage;
@@ -68,41 +69,12 @@ import org.apache.qpid.client.message.JMSStreamMessage;
import org.apache.qpid.client.message.JMSTextMessage;
import org.apache.qpid.client.message.MessageFactoryRegistry;
import org.apache.qpid.client.message.UnprocessedMessage;
+import org.apache.qpid.client.protocol.AMQProtocolHandlerImpl;
import org.apache.qpid.client.protocol.AMQProtocolHandler;
-import org.apache.qpid.client.protocol.BlockingMethodFrameListener;
+import org.apache.qpid.client.protocol.ProtocolOutputHandler;
import org.apache.qpid.client.util.FlowControllingBlockingQueue;
import org.apache.qpid.common.AMQPFilterTypes;
-import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.AccessRequestBody;
-import org.apache.qpid.framing.AccessRequestOkBody;
-import org.apache.qpid.framing.BasicAckBody;
-import org.apache.qpid.framing.BasicConsumeBody;
-import org.apache.qpid.framing.BasicConsumeOkBody;
-import org.apache.qpid.framing.BasicRecoverBody;
-import org.apache.qpid.framing.ChannelCloseBody;
-import org.apache.qpid.framing.ChannelCloseOkBody;
-import org.apache.qpid.framing.ChannelFlowBody;
-import org.apache.qpid.framing.ExchangeBoundBody;
-import org.apache.qpid.framing.ExchangeBoundOkBody;
-import org.apache.qpid.framing.ExchangeDeclareBody;
-import org.apache.qpid.framing.ExchangeDeclareOkBody;
-import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.framing.FieldTableFactory;
-import org.apache.qpid.framing.QueueBindBody;
-import org.apache.qpid.framing.QueueDeclareBody;
-import org.apache.qpid.framing.QueueDeleteBody;
-import org.apache.qpid.framing.QueueDeleteOkBody;
-import org.apache.qpid.framing.TxCommitBody;
-import org.apache.qpid.framing.TxCommitOkBody;
-import org.apache.qpid.framing.TxRollbackBody;
-import org.apache.qpid.framing.TxRollbackOkBody;
-import org.apache.qpid.framing.QueueBindOkBody;
-import org.apache.qpid.framing.QueueDeclareOkBody;
-import org.apache.qpid.framing.ChannelFlowOkBody;
-import org.apache.qpid.framing.BasicRecoverOkBody;
-import org.apache.qpid.framing.BasicRejectBody;
+import org.apache.qpid.framing.*;
import org.apache.qpid.jms.Session;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
@@ -197,6 +169,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
private boolean _suspended;
private final Object _suspensionLock = new Object();
+ private static final AMQShortString CHANNEL_CLOSE_REPLY_TEXT = new AMQShortString("JMS client closing channel");
/** Responsible for decoding a message fragment and passing it to the appropriate message consumer. */
@@ -271,11 +244,11 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
if (message.getDeliverBody() != null)
{
- final BasicMessageConsumer consumer = (BasicMessageConsumer) _consumers.get(message.getDeliverBody().consumerTag);
+ final BasicMessageConsumer consumer = (BasicMessageConsumer) _consumers.get(message.getDeliverBody().getConsumerTag());
if (consumer == null)
{
- _logger.warn("Received a message from queue " + message.getDeliverBody().consumerTag + " without a handler - ignoring...");
+ _logger.warn("Received a message from queue " + message.getDeliverBody().getConsumerTag() + " without a handler - ignoring...");
_logger.warn("Consumers that exist: " + _consumers);
_logger.warn("Session hashcode: " + System.identityHashCode(this));
}
@@ -513,14 +486,11 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
i.next().acknowledgeLastDelivered();
}
- // Commits outstanding messages sent and outstanding acknowledgements.
- // TODO: Be aware of possible changes to parameter order as versions change.
- final AMQProtocolHandler handler = getProtocolHandler();
+ TxCommitBody commitBody = getAMQMethodFactory().createTxCommit();
+ sendCommandReceiveResponse(commitBody);
+
+
- handler.syncWrite(TxCommitBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(),
- getProtocolMinorVersion()),
- TxCommitOkBody.class);
}
catch (AMQException e)
{
@@ -549,8 +519,8 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
suspendChannel(true);
}
- _connection.getProtocolHandler().syncWrite(
- TxRollbackBody.createAMQFrame(_channelId, getProtocolMajorVersion(), getProtocolMinorVersion()), TxRollbackOkBody.class);
+ TxRollbackBody rollbackBody = getAMQMethodFactory().createTxRollback();
+ sendCommandReceiveResponse(rollbackBody);
if (_dispatcher != null)
{
@@ -590,15 +560,12 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
getProtocolHandler().closeSession(this);
- // TODO: Be aware of possible changes to parameter order as versions change.
- final AMQFrame frame = ChannelCloseBody.createAMQFrame(getChannelId(),
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- 0, // classId
- 0, // methodId
- AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
- new AMQShortString("JMS client closing channel")); // replyText
-
- getProtocolHandler().syncWrite(frame, ChannelCloseOkBody.class, timeout);
+ ChannelCloseBody closeBody = getAMQMethodFactory().createChannelClose(AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
+ CHANNEL_CLOSE_REPLY_TEXT);
+ sendCommandReceiveResponse(closeBody, timeout);
+
+
+
// When control resumes at this point, a reply will have been received that
// indicates the broker has closed the channel successfully
@@ -617,21 +584,17 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
}
}
- private AMQProtocolHandler getProtocolHandler()
+ private AMQProtocolHandlerImpl getProtocolHandler()
{
return _connection.getProtocolHandler();
}
-
- private byte getProtocolMinorVersion()
+ public ProtocolOutputHandler getProtocolOutputHandler()
{
- return getProtocolHandler().getProtocolMinorVersion();
+ return _connection.getProtocolOutputHandler();
}
- private byte getProtocolMajorVersion()
- {
- return getProtocolHandler().getProtocolMajorVersion();
- }
+
/**
@@ -835,14 +798,12 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
consumer.clearUnackedMessages();
}
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- _connection.getProtocolHandler().syncWrite(BasicRecoverBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(),
- getProtocolMinorVersion(),
- false) // requeue
- , BasicRecoverOkBody.class);
+ final boolean requeue = false;
+ AMQMethodBody recoverBody = getAMQMethodFactory().createRecover(requeue);
+ sendCommandReceiveResponse(recoverBody);
+
+
+
if (_dispatcher != null)
{
@@ -1226,136 +1187,60 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
public void declareExchange(AMQShortString name, AMQShortString type) throws AMQException
{
- declareExchange(name, type, getProtocolHandler());
+ ExchangeDeclareBody exchangeDeclare = getAMQMethodFactory().createExchangeDeclare(name,type,getTicket());
+ sendCommandReceiveResponse(exchangeDeclare);
}
public void declareExchangeSynch(AMQShortString name, AMQShortString type) throws AMQException
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame frame = ExchangeDeclareBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- null, // arguments
- false, // autoDelete
- false, // durable
- name, // exchange
- false, // internal
- false, // nowait
- false, // passive
- getTicket(), // ticket
- type); // type
- getProtocolHandler().syncWrite(frame, ExchangeDeclareOkBody.class);
- }
+ ExchangeDeclareBody exchangeDeclare = getAMQMethodFactory().createExchangeDeclare(name,type,getTicket());
+ sendCommandReceiveResponse(exchangeDeclare);
- private void declareExchange(AMQDestination amqd, AMQProtocolHandler protocolHandler) throws AMQException
- {
- declareExchange(amqd.getExchangeName(), amqd.getExchangeClass(), protocolHandler);
- }
-
- private void declareExchange(AMQShortString name, AMQShortString type, AMQProtocolHandler protocolHandler) throws AMQException
- {
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame exchangeDeclare = ExchangeDeclareBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- null, // arguments
- false, // autoDelete
- false, // durable
- name, // exchange
- false, // internal
- false, // nowait
- false, // passive
- getTicket(), // ticket
- type); // type
-
- protocolHandler.syncWrite(exchangeDeclare, ExchangeDeclareOkBody.class);
}
-
public void createQueue(AMQShortString name, boolean autoDelete, boolean durable, boolean exclusive) throws AMQException
{
- AMQFrame queueDeclare = QueueDeclareBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- null, // arguments
- autoDelete, // autoDelete
- durable, // durable
- exclusive, // exclusive
- false, // nowait
- false, // passive
- name, // queue
- getTicket()); // ticket
-
- getProtocolHandler().syncWrite(queueDeclare, QueueDeclareOkBody.class);
-
+ QueueDeclareBody queueDeclare = getAMQMethodFactory().createQueueDeclare(name, null, autoDelete, durable, exclusive, false ,getTicket());
+ sendCommandReceiveResponse(queueDeclare);
}
public void bindQueue(AMQShortString queueName, AMQShortString routingKey, FieldTable arguments, AMQShortString exchangeName) throws AMQException
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame queueBind = QueueBindBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- arguments, // arguments
- exchangeName, // exchange
- false, // nowait
- queueName, // queue
- routingKey, // routingKey
- getTicket()); // ticket
-
-
- getProtocolHandler().syncWrite(queueBind, QueueBindOkBody.class);
+ QueueBindBody queueBind = getAMQMethodFactory().createQueueBind(queueName,exchangeName,routingKey,arguments,getTicket());
+ sendCommandReceiveResponse(queueBind);
}
/**
* Declare the queue.
*
* @param amqd
- * @param protocolHandler
*
* @return the queue name. This is useful where the broker is generating a queue name on behalf of the client.
*
* @throws AMQException
*/
- private AMQShortString declareQueue(AMQDestination amqd, AMQProtocolHandler protocolHandler) throws AMQException
+ private AMQShortString declareQueue(AMQDestination amqd) throws AMQException
{
// For queues (but not topics) we generate the name in the client rather than the
// server. This allows the name to be reused on failover if required. In general,
// the destination indicates whether it wants a name generated or not.
if (amqd.isNameRequired())
{
- amqd.setQueueName(protocolHandler.generateQueueName());
+ amqd.setQueueName(getProtocolHandler().generateQueueName());
}
//TODO verify the destiation is valid. else throw
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame queueDeclare = QueueDeclareBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- null, // arguments
- amqd.isAutoDelete(), // autoDelete
- amqd.isDurable(), // durable
- amqd.isExclusive(), // exclusive
- false, // nowait
- false, // passive
- amqd.getAMQQueueName(), // queue
- getTicket()); // ticket
-
- protocolHandler.syncWrite(queueDeclare, QueueDeclareOkBody.class);
+ createQueue(amqd.getAMQQueueName(),amqd.isAutoDelete(),amqd.isDurable(),amqd.isExclusive());
+
+
return amqd.getAMQQueueName();
}
- private void bindQueue(AMQDestination amqd, AMQShortString queueName, AMQProtocolHandler protocolHandler, FieldTable ft) throws AMQException
+ private void bindQueue(AMQDestination amqd, AMQShortString queueName, FieldTable ft) throws AMQException
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame queueBind = QueueBindBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- ft, // arguments
- amqd.getExchangeName(), // exchange
- false, // nowait
- queueName, // queue
- amqd.getRoutingKey(), // routingKey
- getTicket()); // ticket
-
-
- protocolHandler.syncWrite(queueBind, QueueBindOkBody.class);
+ bindQueue(queueName,amqd.getRoutingKey(),ft,amqd.getExchangeName());
}
/**
@@ -1365,8 +1250,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
*
* @return the consumer tag generated by the broker
*/
- private void consumeFromQueue(BasicMessageConsumer consumer, AMQShortString queueName, AMQProtocolHandler protocolHandler,
- boolean nowait, String messageSelector) throws AMQException
+ private void consumeFromQueue(BasicMessageConsumer consumer, AMQShortString queueName, boolean nowait, String messageSelector) throws AMQException
{
//fixme prefetch values are not used here. Do we need to have them as parametsrs?
//need to generate a consumer tag on the client so we can exploit the nowait flag
@@ -1392,25 +1276,24 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
try
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame jmsConsume = BasicConsumeBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- arguments, // arguments
- tag, // consumerTag
- consumer.isExclusive(), // exclusive
- consumer.getAcknowledgeMode() == Session.NO_ACKNOWLEDGE, // noAck
- consumer.isNoLocal(), // noLocal
- nowait, // nowait
- queueName, // queue
- getTicket()); // ticket
- if (nowait)
+ final boolean noAck = consumer.getAcknowledgeMode() == Session.NO_ACKNOWLEDGE;
+
+ AMQMethodBody consumeBody = getAMQMethodFactory().createConsumer(tag,
+ queueName,
+ arguments,
+ noAck,
+ consumer.isExclusive(),
+ consumer.isNoLocal(),
+ getTicket());
+ if(nowait)
{
- protocolHandler.writeFrame(jmsConsume);
+ sendCommand(consumeBody);
}
else
{
- protocolHandler.syncWrite(jmsConsume, BasicConsumeOkBody.class);
+ sendCommandReceiveResponse(consumeBody);
}
+
}
catch (AMQException e)
{
@@ -1606,15 +1489,9 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
try
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame queueDeleteFrame = QueueDeleteBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- false, // ifEmpty
- false, // ifUnused
- true, // nowait
- queueName, // queue
- getTicket()); // ticket
- getProtocolHandler().syncWrite(queueDeleteFrame, QueueDeleteOkBody.class);
+
+ QueueDeleteBody deleteBody = getAMQMethodFactory().createQueueDelete(queueName, false, false, getTicket());
+ sendCommandReceiveResponse(deleteBody);
}
catch (AMQException e)
{
@@ -1697,23 +1574,23 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
boolean isQueueBound(AMQShortString exchangeName, AMQShortString queueName, AMQShortString routingKey) throws JMSException
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame boundFrame = ExchangeBoundBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- exchangeName, // exchange
- queueName, // queue
- routingKey); // routingKey
AMQMethodEvent response = null;
try
{
- response = getProtocolHandler().syncWrite(boundFrame, ExchangeBoundOkBody.class);
+ ExchangeBoundBody exchangeBoundBody =
+ getAMQMethodFactory().createExchangeBound(exchangeName, // exchange
+ queueName, // queue
+ routingKey); // routingKey
+
+
+ ExchangeBoundOkBody responseBody = sendCommandReceiveResponse(exchangeBoundBody, ExchangeBoundOkBody.class);
+ return (responseBody.getReplyCode() == 0);
}
catch (AMQException e)
{
throw new JMSAMQException(e);
}
- ExchangeBoundOkBody responseBody = (ExchangeBoundOkBody) response.getMethod();
- return (responseBody.replyCode == 0); //ExchangeBoundHandler.OK); Remove Broker compile dependency
+
}
private void checkTransacted() throws JMSException
@@ -1770,13 +1647,13 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
// Bounced message is processed here, away from the mina thread
AbstractJMSMessage bouncedMessage = _messageFactoryRegistry.createMessage(0,
false,
- message.getBounceBody().exchange,
- message.getBounceBody().routingKey,
+ message.getBounceBody().getExchange(),
+ message.getBounceBody().getRoutingKey(),
message.getContentHeader(),
message.getBodies());
- AMQConstant errorCode = AMQConstant.getConstant(message.getBounceBody().replyCode);
- AMQShortString reason = message.getBounceBody().replyText;
+ AMQConstant errorCode = AMQConstant.getConstant(message.getBounceBody().getReplyCode());
+ AMQShortString reason = message.getBounceBody().getReplyText();
_logger.debug("Message returned with error code " + errorCode + " (" + reason + ")");
//@TODO should this be moved to an exception handler of sorts. Somewhere errors are converted to correct execeptions.
@@ -1812,16 +1689,12 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
*/
public void acknowledgeMessage(long deliveryTag, boolean multiple)
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- final AMQFrame ackFrame = BasicAckBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(), getProtocolMinorVersion(), // AMQP version (major, minor)
- deliveryTag, // deliveryTag
- multiple); // multiple
+ AMQMethodBody ackBody = getAMQMethodFactory().createAcknowledge(deliveryTag, multiple);
if (_logger.isDebugEnabled())
{
_logger.debug("Sending ack for delivery tag " + deliveryTag + " on channel " + _channelId);
}
- getProtocolHandler().writeFrame(ackFrame);
+ sendCommand(ackBody);
}
public int getDefaultPrefetch()
@@ -1908,17 +1781,15 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
AMQDestination amqd = consumer.getDestination();
- AMQProtocolHandler protocolHandler = getProtocolHandler();
-
- declareExchange(amqd, protocolHandler);
+ declareExchange(amqd.getExchangeName(), amqd.getExchangeClass());
- AMQShortString queueName = declareQueue(amqd, protocolHandler);
+ AMQShortString queueName = declareQueue(amqd);
- bindQueue(amqd, queueName, protocolHandler, consumer.getRawSelectorFieldTable());
+ bindQueue(amqd, queueName, consumer.getRawSelectorFieldTable());
try
{
- consumeFromQueue(consumer, queueName, protocolHandler, nowait, consumer.getMessageSelector());
+ consumeFromQueue(consumer, queueName, nowait, consumer.getMessageSelector());
}
catch (JMSException e) //thrown by getMessageSelector
{
@@ -2019,14 +1890,9 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
_suspended = suspend;
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- AMQFrame channelFlowFrame = ChannelFlowBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(),
- getProtocolMinorVersion(),
- !suspend); // active
+ AMQMethodBody flowBody = getAMQMethodFactory().createChannelFlow(!suspend);
+ sendCommandReceiveResponse(flowBody);
- _connection.getProtocolHandler().syncWrite(channelFlowFrame, ChannelFlowOkBody.class);
}
}
@@ -2118,32 +1984,15 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
public void requestAccess(AMQShortString realm, boolean exclusive, boolean passive, boolean active, boolean write, boolean read) throws AMQException
{
- getProtocolHandler().writeCommandFrameAndWaitForReply(AccessRequestBody.createAMQFrame(getChannelId(),
- getProtocolMajorVersion(),
- getProtocolMinorVersion(),
- active,
- exclusive,
- passive,
- read,
- realm,
- write),
- new BlockingMethodFrameListener(_channelId)
- {
- public boolean processMethod(int channelId, AMQMethodBody frame) throws AMQException
- {
- if (frame instanceof AccessRequestOkBody)
- {
- setTicket(((AccessRequestOkBody) frame).getTicket());
- return true;
- }
- else
- {
- return false;
- }
- }
- });
+ AccessRequestBody accessRequest = getAMQMethodFactory().createAccessRequest(active,exclusive,passive,read,realm,write);
+ AccessRequestOkBody okBody = getProtocolOutputHandler().sendCommandReceiveResponse(_channelId,accessRequest, AccessRequestOkBody.class );
+ setTicket(okBody.getTicket());
+ }
+ AMQMethodFactory getAMQMethodFactory()
+ {
+ return getProtocolOutputHandler().getAMQMethodFactory();
}
private class SuspenderRunner implements Runnable
@@ -2187,7 +2036,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
UnprocessedMessage message = (UnprocessedMessage) messages.next();
- if (consumerTag == null || message.getDeliverBody().consumerTag.equals(consumerTag))
+ if (consumerTag == null || message.getDeliverBody().getConsumerTag().equals(consumerTag))
{
if (_logger.isTraceEnabled())
{
@@ -2196,7 +2045,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
messages.remove();
- rejectMessage(message.getDeliverBody().deliveryTag, requeue);
+ rejectMessage(message.getDeliverBody().getDeliveryTag(), requeue);
_logger.debug("Rejected the message(" + message.getDeliverBody() + ") for consumer :" + consumerTag);
}
@@ -2209,13 +2058,27 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
public void rejectMessage(long deliveryTag, boolean requeue)
{
- AMQFrame basicRejectBody = BasicRejectBody.createAMQFrame(_channelId,
- getProtocolMajorVersion(),
- getProtocolMinorVersion(),
- deliveryTag,
- requeue);
+ AMQMethodBody rejectBody = getAMQMethodFactory().createRejectBody(deliveryTag, requeue);
+ sendCommand(rejectBody);
+
+ }
- _connection.getProtocolHandler().writeFrame(basicRejectBody);
+ <T extends AMQMethodBody> T sendCommandReceiveResponse(AMQMethodBody command, Class<T> responseClass) throws AMQException
+ {
+ return getProtocolOutputHandler().sendCommandReceiveResponse(_channelId, command, responseClass);
+ }
+ AMQMethodBody sendCommandReceiveResponse(AMQMethodBody command) throws AMQException
+ {
+ return getProtocolOutputHandler().sendCommandReceiveResponse(_channelId, command);
+ }
+ AMQMethodBody sendCommandReceiveResponse(AMQMethodBody command, long timeout) throws AMQException
+ {
+ return getProtocolOutputHandler().sendCommandReceiveResponse(_channelId, command, timeout);
}
+
+ void sendCommand(AMQMethodBody command)
+ {
+ getProtocolOutputHandler().sendCommand(_channelId, command);
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
index e9b914425a..f0bea6cc90 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
@@ -33,6 +33,7 @@ import javax.jms.MessageListener;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
+import org.apache.qpid.AMQTimeoutException;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.MessageFactoryRegistry;
import org.apache.qpid.client.message.UnprocessedMessage;
@@ -42,6 +43,8 @@ import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.BasicCancelBody;
import org.apache.qpid.framing.BasicCancelOkBody;
import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.framing.AMQMethodFactory;
+import org.apache.qpid.framing.AMQMethodBody;
import org.apache.qpid.jms.MessageConsumer;
import org.apache.qpid.jms.Session;
@@ -438,16 +441,10 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
{
if (sendClose)
{
- // TODO: Be aware of possible changes to parameter order as versions change.
- final AMQFrame cancelFrame = BasicCancelBody.createAMQFrame(_channelId,
- _protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion(),
- _consumerTag, // consumerTag
- false); // nowait
-
try
{
- _protocolHandler.syncWrite(cancelFrame, BasicCancelOkBody.class);
+ AMQMethodBody cancelBody = getAMQMethodFactory().createConsumerCancel(_consumerTag);
+ sendCommandReceiveResponse(cancelBody);
}
catch (AMQException e)
{
@@ -467,6 +464,16 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
}
}
+ private AMQMethodBody sendCommandReceiveResponse(AMQMethodBody cancelBody) throws AMQException
+ {
+ return getSession().sendCommandReceiveResponse(cancelBody);
+ }
+
+ private AMQMethodFactory getAMQMethodFactory()
+ {
+ return getSession().getAMQMethodFactory();
+ }
+
/**
* Called when you need to invalidate a consumer. Used for example when failover has occurred and the client has
* vetoed automatic resubscription. The caller must hold the failover mutex.
@@ -490,14 +497,14 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
if (debug)
{
- _logger.debug("notifyMessage called with message number " + messageFrame.getDeliverBody().deliveryTag);
+ _logger.debug("notifyMessage called with message number " + messageFrame.getDeliverBody().getDeliveryTag());
}
try
{
- AbstractJMSMessage jmsMessage = _messageFactory.createMessage(messageFrame.getDeliverBody().deliveryTag,
- messageFrame.getDeliverBody().redelivered,
- messageFrame.getDeliverBody().exchange,
- messageFrame.getDeliverBody().routingKey,
+ AbstractJMSMessage jmsMessage = _messageFactory.createMessage(messageFrame.getDeliverBody().getDeliveryTag(),
+ messageFrame.getDeliverBody().getRedelivered(),
+ messageFrame.getDeliverBody().getExchange(),
+ messageFrame.getDeliverBody().getRoutingKey(),
messageFrame.getContentHeader(),
messageFrame.getBodies());
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
index b01e087ce1..43b9f3569a 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
@@ -38,17 +38,11 @@ import javax.jms.Topic;
import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
import org.apache.qpid.AMQException;
+import org.apache.qpid.AMQTimeoutException;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.MessageConverter;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
-import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.BasicConsumeBody;
-import org.apache.qpid.framing.BasicContentHeaderProperties;
-import org.apache.qpid.framing.BasicPublishBody;
-import org.apache.qpid.framing.CompositeAMQDataBlock;
-import org.apache.qpid.framing.ContentBody;
-import org.apache.qpid.framing.ContentHeaderBody;
-import org.apache.qpid.framing.ExchangeDeclareBody;
+import org.apache.qpid.client.protocol.AMQProtocolHandlerImpl;
+import org.apache.qpid.framing.*;
public class BasicMessageProducer extends Closeable implements org.apache.qpid.jms.MessageProducer
{
@@ -91,7 +85,7 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
*/
private String _mimeType;
- private AMQProtocolHandler _protocolHandler;
+ private AMQProtocolHandlerImpl _protocolHandler;
/**
* True if this producer was created from a transacted session
@@ -121,7 +115,7 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
private static final ContentBody[] NO_CONTENT_BODIES = new ContentBody[0];
protected BasicMessageProducer(AMQConnection connection, AMQDestination destination, boolean transacted, int channelId,
- AMQSession session, AMQProtocolHandler protocolHandler, long producerId,
+ AMQSession session, AMQProtocolHandlerImpl protocolHandler, long producerId,
boolean immediate, boolean mandatory, boolean waitUntilSent)
{
_connection = connection;
@@ -152,20 +146,28 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
private void declareDestination(AMQDestination destination)
{
// Declare the exchange
- // Note that the durable and internal arguments are ignored since passive is set to false
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame declare =
- ExchangeDeclareBody.createAMQFrame(_channelId, _protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion(), null, // arguments
- false, // autoDelete
- false, // durable
- destination.getExchangeName(), // exchange
- false, // internal
- true, // nowait
- false, // passive
- _session.getTicket(), // ticket
- destination.getExchangeClass()); // type
- _protocolHandler.writeFrame(declare);
+
+ ExchangeDeclareBody exchangeDeclareBody =
+ getAMQMethodFactory().createExchangeDeclare(destination.getExchangeName(),
+ destination.getExchangeClass(),
+ _session.getTicket());
+ sendCommand(exchangeDeclareBody);
+
+ }
+
+ private void sendCommand(AMQMethodBody command)
+ {
+ getSession().sendCommand(command);
+ }
+
+ private AMQMethodBody sendCommandReceiveResponse(AMQMethodBody command) throws AMQException
+ {
+ return getSession().sendCommandReceiveResponse(command);
+ }
+
+ private AMQMethodFactory getAMQMethodFactory()
+ {
+ return getSession().getAMQMethodFactory();
}
public void setDisableMessageID(boolean b) throws JMSException
@@ -467,21 +469,9 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
message.getJmsHeaders().setInteger(CustomJMSXProperty.JMS_QPID_DESTTYPE.getShortStringName(), type);
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- AMQFrame publishFrame =
- BasicPublishBody.createAMQFrame(
- _channelId, _protocolHandler.getProtocolMajorVersion(), _protocolHandler.getProtocolMinorVersion(),
- destination.getExchangeName(), // exchange
- immediate, // immediate
- mandatory, // mandatory
- destination.getRoutingKey(), // routingKey
- _session.getTicket()); // ticket
-
message.prepareForSending();
ByteBuffer payload = message.getData();
- BasicContentHeaderProperties contentHeaderProperties = message.getContentHeaderProperties();
+ CommonContentHeaderProperties contentHeaderProperties = message.getContentHeaderProperties();
if (!_disableTimestamps)
{
@@ -501,37 +491,15 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
contentHeaderProperties.setDeliveryMode((byte) deliveryMode);
contentHeaderProperties.setPriority((byte) priority);
- final int size = (payload != null) ? payload.limit() : 0;
- final int contentBodyFrameCount = calculateContentBodyFrameCount(payload);
- final AMQFrame[] frames = new AMQFrame[2 + contentBodyFrameCount];
+ getSession().getProtocolOutputHandler().publishMessage(getSession().getChannelId(),
+ destination.getExchangeName(),
+ destination.getRoutingKey(),
+ immediate,
+ mandatory,
+ payload,
+ contentHeaderProperties,
+ getSession().getTicket());
- if (payload != null)
- {
- createContentBodies(payload, frames, 2, _channelId);
- }
-
- if ((contentBodyFrameCount != 0) && _logger.isDebugEnabled())
- {
- _logger.debug("Sending content body frames to " + destination);
- }
-
- // weight argument of zero indicates no child content headers, just bodies
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- AMQFrame contentHeaderFrame =
- ContentHeaderBody.createAMQFrame(_channelId,
- BasicConsumeBody.getClazz(_protocolHandler.getProtocolMajorVersion(),
- _protocolHandler.getProtocolMinorVersion()), 0,
- contentHeaderProperties, size);
- if (_logger.isDebugEnabled())
- {
- _logger.debug("Sending content header frame to " + destination);
- }
-
- frames[0] = publishFrame;
- frames[1] = contentHeaderFrame;
- CompositeAMQDataBlock compositeFrame = new CompositeAMQDataBlock(frames);
- _protocolHandler.writeFrame(compositeFrame, wait);
if (message != origMessage)
{
@@ -544,6 +512,8 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
}
}
+
+
private void checkTemporaryDestination(AMQDestination destination) throws JMSException
{
if (destination instanceof TemporaryDestination)
@@ -564,59 +534,6 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j
}
}
- /**
- * Create content bodies. This will split a large message into numerous bodies depending on the negotiated
- * maximum frame size.
- *
- * @param payload
- * @param frames
- * @param offset
- * @param channelId @return the array of content bodies
- */
- private void createContentBodies(ByteBuffer payload, AMQFrame[] frames, int offset, int channelId)
- {
-
- if (frames.length == (offset + 1))
- {
- frames[offset] = ContentBody.createAMQFrame(channelId, new ContentBody(payload));
- }
- else
- {
-
- final long framePayloadMax = _session.getAMQConnection().getMaximumFrameSize() - 1;
- long remaining = payload.remaining();
- for (int i = offset; i < frames.length; i++)
- {
- payload.position((int) framePayloadMax * (i - offset));
- int length = (remaining >= framePayloadMax) ? (int) framePayloadMax : (int) remaining;
- payload.limit(payload.position() + length);
- frames[i] = ContentBody.createAMQFrame(channelId, new ContentBody(payload.slice()));
-
- remaining -= length;
- }
- }
-
- }
-
- private int calculateContentBodyFrameCount(ByteBuffer payload)
- {
- // we substract one from the total frame maximum size to account for the end of frame marker in a body frame
- // (0xCE byte).
- int frameCount;
- if ((payload == null) || (payload.remaining() == 0))
- {
- frameCount = 0;
- }
- else
- {
- int dataLength = payload.remaining();
- final long framePayloadMax = _session.getAMQConnection().getMaximumFrameSize() - 1;
- int lastFrame = ((dataLength % framePayloadMax) > 0) ? 1 : 0;
- frameCount = (int) (dataLength / framePayloadMax) + lastFrame;
- }
-
- return frameCount;
- }
public void setMimeType(String mimeType) throws JMSException
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java
index 844ecbe743..268456290e 100644
--- a/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java
@@ -25,7 +25,7 @@ import java.util.concurrent.CountDownLatch;
import org.apache.log4j.Logger;
import org.apache.mina.common.IoSession;
import org.apache.qpid.AMQDisconnectedException;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
+import org.apache.qpid.client.protocol.AMQProtocolHandlerImpl;
import org.apache.qpid.client.state.AMQStateManager;
/**
@@ -42,7 +42,7 @@ public class FailoverHandler implements Runnable
private static final Logger _logger = Logger.getLogger(FailoverHandler.class);
private final IoSession _session;
- private AMQProtocolHandler _amqProtocolHandler;
+ private AMQProtocolHandlerImpl _amqProtocolHandler;
/**
* Used where forcing the failover host
@@ -54,7 +54,7 @@ public class FailoverHandler implements Runnable
*/
private int _port;
- public FailoverHandler(AMQProtocolHandler amqProtocolHandler, IoSession session)
+ public FailoverHandler(AMQProtocolHandlerImpl amqProtocolHandler, IoSession session)
{
_amqProtocolHandler = amqProtocolHandler;
_session = session;
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ChannelCloseMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ChannelCloseMethodHandler.java
new file mode 100644
index 0000000000..994e58ed03
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ChannelCloseMethodHandler.java
@@ -0,0 +1,24 @@
+package org.apache.qpid.client.handler.amqp_0_9;
+
+import org.apache.qpid.framing.ChannelCloseOkBody;
+import org.apache.qpid.framing.amqp_0_9.ChannelCloseOkBodyImpl;
+
+import org.apache.log4j.Logger;
+
+public class ChannelCloseMethodHandler extends org.apache.qpid.client.handler.amqp_8_0.ChannelCloseMethodHandler
+{
+ private static final Logger _logger = Logger.getLogger(ChannelCloseMethodHandler.class);
+
+ private static ChannelCloseMethodHandler _handler = new ChannelCloseMethodHandler();
+
+ public static ChannelCloseMethodHandler getInstance()
+ {
+ return _handler;
+ }
+
+
+ protected ChannelCloseOkBody createChannelCloseOkBody()
+ {
+ return new ChannelCloseOkBodyImpl();
+ }
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionCloseMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionCloseMethodHandler.java
new file mode 100644
index 0000000000..b9b7074fd2
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionCloseMethodHandler.java
@@ -0,0 +1,29 @@
+package org.apache.qpid.client.handler.amqp_0_9;
+
+import org.apache.qpid.framing.ConnectionCloseOkBody;
+import org.apache.qpid.framing.amqp_0_9.ConnectionCloseOkBodyImpl;
+
+import org.apache.log4j.Logger;
+
+public class ConnectionCloseMethodHandler extends org.apache.qpid.client.handler.amqp_8_0.ConnectionCloseMethodHandler
+{
+ private static final Logger _logger = Logger.getLogger(ConnectionCloseMethodHandler.class);
+
+ private static ConnectionCloseMethodHandler _handler = new ConnectionCloseMethodHandler();
+
+ public static ConnectionCloseMethodHandler getInstance()
+ {
+ return _handler;
+ }
+
+ protected ConnectionCloseMethodHandler()
+ {
+ }
+
+
+ protected ConnectionCloseOkBody createConnectionCloseOkBody()
+ {
+ return new ConnectionCloseOkBodyImpl();
+ }
+
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionSecureMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionSecureMethodHandler.java
new file mode 100644
index 0000000000..859fd2b63b
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionSecureMethodHandler.java
@@ -0,0 +1,28 @@
+package org.apache.qpid.client.handler.amqp_0_9;
+
+import org.apache.qpid.client.state.StateAwareMethodListener;
+import org.apache.qpid.client.state.AMQStateManager;
+import org.apache.qpid.client.protocol.AMQProtocolSession;
+import org.apache.qpid.protocol.AMQMethodEvent;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.ConnectionSecureBody;
+import org.apache.qpid.framing.ConnectionSecureOkBody;
+import org.apache.qpid.framing.amqp_8_0.ConnectionSecureOkBodyImpl;
+
+import javax.security.sasl.SaslClient;
+import javax.security.sasl.SaslException;
+
+public class ConnectionSecureMethodHandler extends org.apache.qpid.client.handler.amqp_8_0.ConnectionSecureMethodHandler
+{
+ private static final ConnectionSecureMethodHandler _instance = new ConnectionSecureMethodHandler();
+
+ public static ConnectionSecureMethodHandler getInstance()
+ {
+ return _instance;
+ }
+
+ protected ConnectionSecureOkBody createConnectionSecureOkBody(byte[] response)
+ {
+ return new ConnectionSecureOkBodyImpl(response);
+ }
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionTuneMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionTuneMethodHandler.java
new file mode 100644
index 0000000000..e28619b378
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_0_9/ConnectionTuneMethodHandler.java
@@ -0,0 +1,41 @@
+package org.apache.qpid.client.handler.amqp_0_9;
+
+import org.apache.qpid.client.ConnectionTuneParameters;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.ConnectionOpenBody;
+import org.apache.qpid.framing.ConnectionTuneOkBody;
+import org.apache.qpid.framing.amqp_0_9.ConnectionOpenBodyImpl;
+import org.apache.qpid.framing.amqp_0_9.ConnectionTuneOkBodyImpl;
+
+import org.apache.log4j.Logger;
+
+public class ConnectionTuneMethodHandler extends org.apache.qpid.client.handler.amqp_8_0.ConnectionTuneMethodHandler
+{
+ private static final Logger _logger = Logger.getLogger(ConnectionTuneMethodHandler.class);
+
+ private static final ConnectionTuneMethodHandler _instance = new ConnectionTuneMethodHandler();
+
+ public static ConnectionTuneMethodHandler getInstance()
+ {
+ return _instance;
+ }
+
+
+ protected ConnectionOpenBody createConnectionOpenBody(AMQShortString path, AMQShortString capabilities, boolean insist)
+ {
+
+ return new ConnectionOpenBodyImpl(path,// virtualHost
+ capabilities, // capabilities
+ insist); // insist
+
+ }
+
+ protected ConnectionTuneOkBody createTuneOkBody(ConnectionTuneParameters params)
+ {
+ // Be aware of possible changes to parameter order as versions change.
+ return new ConnectionTuneOkBodyImpl(
+ params.getChannelMax(), // channelMax
+ params.getFrameMax(), // frameMax
+ params.getHeartbeat()); // heartbeat
+ }
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/BasicCancelOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/BasicCancelOkMethodHandler.java
index 9bd0205977..2acf3005f1 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/BasicCancelOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/BasicCancelOkMethodHandler.java
@@ -18,7 +18,7 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
@@ -45,10 +45,12 @@ public class BasicCancelOkMethodHandler implements StateAwareMethodListener
{
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
+
_logger.debug("New BasicCancelOk method received");
+ final AMQProtocolSession protocolSession = stateManager.getProtocolSession();
BasicCancelOkBody body = (BasicCancelOkBody) evt.getMethod();
- protocolSession.confirmConsumerCancelled(evt.getChannelId(), body.consumerTag);
+ protocolSession.confirmConsumerCancelled(evt.getChannelId(), body.getConsumerTag());
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/BasicDeliverMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/BasicDeliverMethodHandler.java
index d34d6688c1..47586db2f2 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/BasicDeliverMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/BasicDeliverMethodHandler.java
@@ -18,7 +18,7 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
@@ -40,8 +40,9 @@ public class BasicDeliverMethodHandler implements StateAwareMethodListener
return _instance;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
+ final AMQProtocolSession protocolSession = stateManager.getProtocolSession();
final UnprocessedMessage msg = new UnprocessedMessage(evt.getChannelId(), (BasicDeliverBody) evt.getMethod());
_logger.debug("New JmsDeliver method received");
protocolSession.unprocessedMessageReceived(msg);
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/BasicReturnMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/BasicReturnMethodHandler.java
index 02573c5d00..ad5a1331b0 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/BasicReturnMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/BasicReturnMethodHandler.java
@@ -18,7 +18,7 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
@@ -40,9 +40,10 @@ public class BasicReturnMethodHandler implements StateAwareMethodListener
return _instance;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
_logger.debug("New JmsBounce method received");
+ final AMQProtocolSession protocolSession = stateManager.getProtocolSession();
final UnprocessedMessage msg = new UnprocessedMessage(evt.getChannelId(),(BasicReturnBody)evt.getMethod());
protocolSession.unprocessedMessageReceived(msg);
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ChannelCloseMethodHandler.java
index e2b101ab79..edfd8e5110 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ChannelCloseMethodHandler.java
@@ -18,7 +18,7 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQChannelClosedException;
@@ -29,10 +29,10 @@ import org.apache.qpid.client.AMQNoRouteException;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.StateAwareMethodListener;
-import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ChannelCloseBody;
import org.apache.qpid.framing.ChannelCloseOkBody;
+import org.apache.qpid.framing.amqp_8_0.ChannelCloseOkBodyImpl;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
@@ -47,21 +47,23 @@ public class ChannelCloseMethodHandler implements StateAwareMethodListener
return _handler;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
_logger.debug("ChannelClose method received");
+ final AMQProtocolSession protocolSession = stateManager.getProtocolSession();
ChannelCloseBody method = (ChannelCloseBody) evt.getMethod();
- AMQConstant errorCode = AMQConstant.getConstant(method.replyCode);
- AMQShortString reason = method.replyText;
+ AMQConstant errorCode = AMQConstant.getConstant(method.getReplyCode());
+ AMQShortString reason = method.getReplyText();
if (_logger.isDebugEnabled())
{
_logger.debug("Channel close reply code: " + errorCode + ", reason: " + reason);
}
- // TODO: Be aware of possible changes to parameter order as versions change.
- AMQFrame frame = ChannelCloseOkBody.createAMQFrame(evt.getChannelId(), method.getMajor(), method.getMinor());
- protocolSession.writeFrame(frame);
+ protocolSession.getOutputHandler().sendCommand(evt.getChannelId(), createChannelCloseOkBody());
+
+
+
if (errorCode != AMQConstant.REPLY_SUCCESS)
{
if (_logger.isDebugEnabled())
@@ -96,4 +98,9 @@ public class ChannelCloseMethodHandler implements StateAwareMethodListener
}
protocolSession.channelClosed(evt.getChannelId(), errorCode, String.valueOf(reason));
}
+
+ protected ChannelCloseOkBody createChannelCloseOkBody()
+ {
+ return new ChannelCloseOkBodyImpl();
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ChannelCloseOkMethodHandler.java
index 794071cc34..d51f1d9c41 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelCloseOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ChannelCloseOkMethodHandler.java
@@ -18,11 +18,10 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
-import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.protocol.AMQMethodEvent;
@@ -38,7 +37,7 @@ public class ChannelCloseOkMethodHandler implements StateAwareMethodListener
return _instance;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
_logger.info("Received channel-close-ok for channel-id " + evt.getChannelId());
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelFlowOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ChannelFlowOkMethodHandler.java
index 1f003649c0..baa9cb4319 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ChannelFlowOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ChannelFlowOkMethodHandler.java
@@ -18,11 +18,10 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
-import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.ChannelFlowOkBody;
@@ -42,9 +41,9 @@ public class ChannelFlowOkMethodHandler implements StateAwareMethodListener
{
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
ChannelFlowOkBody method = (ChannelFlowOkBody) evt.getMethod();
- _logger.debug("Received Channel.Flow-Ok message, active = " + method.active);
+ _logger.debug("Received Channel.Flow-Ok message, active = " + method.getActive());
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionCloseMethodHandler.java
index 9c8e9188ec..57eaaff531 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionCloseMethodHandler.java
@@ -18,7 +18,7 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQConnectionClosedException;
@@ -31,6 +31,7 @@ import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ConnectionCloseBody;
import org.apache.qpid.framing.ConnectionCloseOkBody;
+import org.apache.qpid.framing.amqp_8_0.ConnectionCloseOkBodyImpl;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
@@ -45,26 +46,31 @@ public class ConnectionCloseMethodHandler implements StateAwareMethodListener
return _handler;
}
- private ConnectionCloseMethodHandler()
+ protected ConnectionCloseMethodHandler()
{
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
_logger.info("ConnectionClose frame received");
+ final AMQProtocolSession protocolSession = stateManager.getProtocolSession();
ConnectionCloseBody method = (ConnectionCloseBody) evt.getMethod();
// does it matter
//stateManager.changeState(AMQState.CONNECTION_CLOSING);
- AMQConstant errorCode = AMQConstant.getConstant(method.replyCode);
- AMQShortString reason = method.replyText;
+ AMQConstant errorCode = AMQConstant.getConstant(method.getReplyCode());
+ AMQShortString reason = method.getReplyText();
try
{
- // TODO: check whether channel id of zero is appropriate
- // Be aware of possible changes to parameter order as versions change.
- protocolSession.writeFrame(ConnectionCloseOkBody.createAMQFrame((short) 0, method.getMajor(), method.getMinor()));
+
+
+
+ ConnectionCloseOkBody closeOkBody = createConnectionCloseOkBody();
+ protocolSession.getOutputHandler().sendCommand(0, closeOkBody);
+
+
if (errorCode != AMQConstant.REPLY_SUCCESS)
{
@@ -97,4 +103,10 @@ public class ConnectionCloseMethodHandler implements StateAwareMethodListener
stateManager.changeState(AMQState.CONNECTION_CLOSED);
}
}
+
+ protected ConnectionCloseOkBody createConnectionCloseOkBody()
+ {
+ return new ConnectionCloseOkBodyImpl();
+ }
+
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionOpenOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionOpenOkMethodHandler.java
index 2e0f273c32..f4327ac748 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionOpenOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionOpenOkMethodHandler.java
@@ -18,10 +18,9 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.qpid.AMQException;
-import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQState;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.StateAwareMethodListener;
@@ -40,7 +39,7 @@ public class ConnectionOpenOkMethodHandler implements StateAwareMethodListener
{
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
stateManager.changeState(AMQState.CONNECTION_OPEN);
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionRedirectMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionRedirectMethodHandler.java
index 866f65b384..8291b62596 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionRedirectMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionRedirectMethodHandler.java
@@ -18,7 +18,7 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
@@ -45,12 +45,13 @@ public class ConnectionRedirectMethodHandler implements StateAwareMethodListener
{
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
_logger.info("ConnectionRedirect frame received");
+ final AMQProtocolSession protocolSession = stateManager.getProtocolSession();
ConnectionRedirectBody method = (ConnectionRedirectBody) evt.getMethod();
- String host = method.host.toString();
+ String host = method.getHost().toString();
// the host is in the form hostname:port with the port being optional
int portIndex = host.indexOf(':');
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionSecureMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionSecureMethodHandler.java
index ab6acffeaf..f5d1840f45 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionSecureMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionSecureMethodHandler.java
@@ -18,7 +18,7 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import javax.security.sasl.SaslClient;
import javax.security.sasl.SaslException;
@@ -27,9 +27,9 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.StateAwareMethodListener;
-import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.ConnectionSecureBody;
import org.apache.qpid.framing.ConnectionSecureOkBody;
+import org.apache.qpid.framing.amqp_8_0.ConnectionSecureOkBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
public class ConnectionSecureMethodHandler implements StateAwareMethodListener
@@ -41,8 +41,9 @@ public class ConnectionSecureMethodHandler implements StateAwareMethodListener
return _instance;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
+ final AMQProtocolSession protocolSession = stateManager.getProtocolSession();
SaslClient client = protocolSession.getSaslClient();
if (client == null)
{
@@ -54,14 +55,10 @@ public class ConnectionSecureMethodHandler implements StateAwareMethodListener
try
{
// Evaluate server challenge
- byte[] response = client.evaluateChallenge(body.challenge);
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- AMQFrame responseFrame = ConnectionSecureOkBody.createAMQFrame(evt.getChannelId(),
- body.getMajor(), body.getMinor(),
- response); // response
- protocolSession.writeFrame(responseFrame);
+ byte[] response = client.evaluateChallenge(body.getChallenge());
+
+ ConnectionSecureOkBody secureOkBody = createConnectionSecureOkBody(response);
+ protocolSession.getOutputHandler().sendCommand(evt.getChannelId(),secureOkBody);
}
catch (SaslException e)
{
@@ -70,4 +67,9 @@ public class ConnectionSecureMethodHandler implements StateAwareMethodListener
}
+
+ protected ConnectionSecureOkBody createConnectionSecureOkBody(byte[] response)
+ {
+ return new ConnectionSecureOkBodyImpl(response);
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionStartMethodHandler.java
index 2aa2c1872b..10473b9751 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionStartMethodHandler.java
@@ -18,7 +18,7 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import java.io.UnsupportedEncodingException;
import java.util.HashSet;
@@ -44,7 +44,8 @@ import org.apache.qpid.framing.ConnectionStartBody;
import org.apache.qpid.framing.ConnectionStartOkBody;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.framing.FieldTableFactory;
-import org.apache.qpid.framing.ProtocolVersionList;
+import org.apache.qpid.framing.ProtocolVersion;
+import org.apache.qpid.framing.amqp_8_0.ConnectionStartOkBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
public class ConnectionStartMethodHandler implements StateAwareMethodListener
@@ -61,55 +62,49 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener
private ConnectionStartMethodHandler()
{ }
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt)
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt)
throws AMQException
{
_log.debug("public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, "
+ "AMQMethodEvent evt): called");
+ final AMQProtocolSession protocolSession = stateManager.getProtocolSession();
ConnectionStartBody body = (ConnectionStartBody) evt.getMethod();
- byte major = (byte) body.versionMajor;
- byte minor = (byte) body.versionMinor;
- boolean versionOk = false;
+ ProtocolVersion pv = new ProtocolVersion((byte) body.getVersionMajor(),(byte) body.getVersionMinor());
+
// For the purposes of interop, we can make the client accept the broker's version string.
// If it does, it then internally records the version as being the latest one that it understands.
// It needs to do this since frame lookup is done by version.
- if (Boolean.getBoolean("qpid.accept.broker.version"))
+ if (Boolean.getBoolean("qpid.accept.broker.version") && !pv.isSupported())
{
- versionOk = true;
- int lastIndex = ProtocolVersionList.pv.length - 1;
- major = ProtocolVersionList.pv[lastIndex][ProtocolVersionList.PROTOCOL_MAJOR];
- minor = ProtocolVersionList.pv[lastIndex][ProtocolVersionList.PROTOCOL_MINOR];
- }
- else
- {
- versionOk = checkVersionOK(major, minor);
+
+ pv = ProtocolVersion.getLatestSupportedVersion();
}
- if (versionOk)
+ if (pv.isSupported())
{
- protocolSession.setProtocolVersion(major, minor);
+ protocolSession.setProtocolVersion(pv);
try
{
// Used to hold the SASL mechanism to authenticate with.
String mechanism;
- if (body.mechanisms == null)
+ if (body.getMechanisms() == null)
{
throw new AMQException("mechanism not specified in ConnectionStart method frame");
}
else
{
- mechanism = chooseMechanism(body.mechanisms);
+ mechanism = chooseMechanism(body.getMechanisms());
_log.debug("mechanism = " + mechanism);
}
if (mechanism == null)
{
- throw new AMQException("No supported security mechanism found, passed: " + new String(body.mechanisms));
+ throw new AMQException("No supported security mechanism found, passed: " + new String(body.getMechanisms()));
}
byte[] saslResponse;
@@ -135,12 +130,12 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener
throw new AMQException("Unable to create SASL client: " + e, e);
}
- if (body.locales == null)
+ if (body.getLocales() == null)
{
throw new AMQException("Locales is not defined in Connection Start method");
}
- final String locales = new String(body.locales, "utf8");
+ final String locales = new String(body.getLocales(), "utf8");
final StringTokenizer tokenizer = new StringTokenizer(locales, " ");
String selectedLocale = null;
if (tokenizer.hasMoreTokens())
@@ -155,24 +150,19 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener
stateManager.changeState(AMQState.CONNECTION_NOT_TUNED);
FieldTable clientProperties = FieldTableFactory.newFieldTable();
- clientProperties.setString(new AMQShortString(ClientProperties.instance.toString()),
+ clientProperties.setString(ClientProperties.instance.getName(),
protocolSession.getClientID());
- clientProperties.setString(new AMQShortString(ClientProperties.product.toString()),
+ clientProperties.setString(ClientProperties.product.getName(),
QpidProperties.getProductName());
- clientProperties.setString(new AMQShortString(ClientProperties.version.toString()),
+ clientProperties.setString(ClientProperties.version.getName(),
QpidProperties.getReleaseVersion());
- clientProperties.setString(new AMQShortString(ClientProperties.platform.toString()), getFullSystemInfo());
-
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- protocolSession.writeFrame(ConnectionStartOkBody.createAMQFrame(evt.getChannelId(),
- protocolSession.getProtocolMajorVersion(),
- protocolSession.getProtocolMinorVersion(),
- clientProperties, // clientProperties
+ clientProperties.setString(ClientProperties.platform.getName(), getFullSystemInfo());
+
+ ConnectionStartOkBody startOkBody = createConnectionStartOkBody(clientProperties, // clientProperties
new AMQShortString(selectedLocale), // locale
new AMQShortString(mechanism), // mechanism
- saslResponse)); // response
+ saslResponse); // response
+ protocolSession.getOutputHandler().sendCommand(0, startOkBody);
}
catch (UnsupportedEncodingException e)
@@ -182,27 +172,19 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener
}
else
{
- _log.error("Broker requested Protocol [" + body.versionMajor + "-" + body.versionMinor
+ _log.error("Broker requested Protocol [" + body.getVersionMajor() + "-" + body.getVersionMinor()
+ "] which is not supported by this version of the client library");
protocolSession.closeProtocolSession();
}
}
- private boolean checkVersionOK(byte versionMajor, byte versionMinor)
+ private ConnectionStartOkBody createConnectionStartOkBody(FieldTable clientProperties, AMQShortString locale, AMQShortString mechanism, byte[] saslResponse)
{
- byte[][] supportedVersions = ProtocolVersionList.pv;
- boolean supported = false;
- int i = supportedVersions.length;
- while ((i-- != 0) && !supported)
- {
- supported = (supportedVersions[i][ProtocolVersionList.PROTOCOL_MAJOR] == versionMajor)
- && (supportedVersions[i][ProtocolVersionList.PROTOCOL_MINOR] == versionMinor);
- }
-
- return supported;
+ return new ConnectionStartOkBodyImpl(clientProperties,mechanism,saslResponse,locale);
}
+
private String getFullSystemInfo()
{
StringBuffer fullSystemInfo = new StringBuffer();
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionTuneMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionTuneMethodHandler.java
index 67f1a6519f..3eb3401e37 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionTuneMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ConnectionTuneMethodHandler.java
@@ -18,7 +18,7 @@
* under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
@@ -27,11 +27,12 @@ import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQState;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.StateAwareMethodListener;
-import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ConnectionOpenBody;
import org.apache.qpid.framing.ConnectionTuneBody;
import org.apache.qpid.framing.ConnectionTuneOkBody;
+import org.apache.qpid.framing.amqp_8_0.ConnectionOpenBodyImpl;
+import org.apache.qpid.framing.amqp_8_0.ConnectionTuneOkBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
public class ConnectionTuneMethodHandler implements StateAwareMethodListener
@@ -49,9 +50,10 @@ public class ConnectionTuneMethodHandler implements StateAwareMethodListener
{
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
_logger.debug("ConnectionTune frame received");
+ final AMQProtocolSession protocolSession = stateManager.getProtocolSession();
ConnectionTuneBody frame = (ConnectionTuneBody) evt.getMethod();
ConnectionTuneParameters params = protocolSession.getConnectionTuneParameters();
@@ -60,36 +62,36 @@ public class ConnectionTuneMethodHandler implements StateAwareMethodListener
params = new ConnectionTuneParameters();
}
- params.setFrameMax(frame.frameMax);
- params.setChannelMax(frame.channelMax);
- params.setHeartbeat(Integer.getInteger("amqj.heartbeat.delay", frame.heartbeat));
+ params.setFrameMax(frame.getFrameMax());
+ params.setChannelMax(frame.getChannelMax());
+ params.setHeartbeat(Integer.getInteger("amqj.heartbeat.delay", frame.getHeartbeat()));
protocolSession.setConnectionTuneParameters(params);
stateManager.changeState(AMQState.CONNECTION_NOT_OPENED);
- protocolSession.writeFrame(createTuneOkFrame(evt.getChannelId(), params,frame.getMajor(), frame.getMinor()));
+ protocolSession.getOutputHandler().sendCommand(evt.getChannelId(),
+ createTuneOkBody(params));
String host = protocolSession.getAMQConnection().getVirtualHost();
AMQShortString virtualHost = new AMQShortString("/" + host);
- protocolSession.writeFrame(createConnectionOpenFrame(evt.getChannelId(), virtualHost, null, true,frame.getMajor(), frame.getMinor()));
+ protocolSession.getOutputHandler().sendCommand(evt.getChannelId(),
+ createConnectionOpenBody( virtualHost, null, true));
}
- protected AMQFrame createConnectionOpenFrame(int channel, AMQShortString path, AMQShortString capabilities, boolean insist, byte major, byte minor)
+ protected ConnectionOpenBody createConnectionOpenBody(AMQShortString path, AMQShortString capabilities, boolean insist)
{
- // Be aware of possible changes to parameter order as versions change.
- return ConnectionOpenBody.createAMQFrame(channel,
- major, minor, // AMQP version (major, minor)
+
+ return new ConnectionOpenBodyImpl(path,// virtualHost
capabilities, // capabilities
- insist, // insist
- path); // virtualHost
+ insist); // insist
+
}
- protected AMQFrame createTuneOkFrame(int channel, ConnectionTuneParameters params, byte major, byte minor)
+ protected ConnectionTuneOkBody createTuneOkBody(ConnectionTuneParameters params)
{
// Be aware of possible changes to parameter order as versions change.
- return ConnectionTuneOkBody.createAMQFrame(channel,
- major, minor,
+ return new ConnectionTuneOkBodyImpl(
params.getChannelMax(), // channelMax
params.getFrameMax(), // frameMax
params.getHeartbeat()); // heartbeat
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ExchangeBoundOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ExchangeBoundOkMethodHandler.java
index 146c705c00..0752b38aaf 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ExchangeBoundOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/ExchangeBoundOkMethodHandler.java
@@ -15,11 +15,10 @@
* limitations under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
-import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.ExchangeBoundOkBody;
@@ -42,13 +41,13 @@ public class ExchangeBoundOkMethodHandler implements StateAwareMethodListener
{
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
if (_logger.isDebugEnabled())
{
ExchangeBoundOkBody body = (ExchangeBoundOkBody) evt.getMethod();
- _logger.debug("Received Exchange.Bound-Ok message, response code: " + body.replyCode + " text: " +
- body.replyText);
+ _logger.debug("Received Exchange.Bound-Ok message, response code: " + body.getReplyCode() + " text: " +
+ body.getReplyText());
}
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/QueueDeleteOkMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/QueueDeleteOkMethodHandler.java
index eaf4721445..50bf03fe76 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/QueueDeleteOkMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/amqp_8_0/QueueDeleteOkMethodHandler.java
@@ -15,11 +15,10 @@
* limitations under the License.
*
*/
-package org.apache.qpid.client.handler;
+package org.apache.qpid.client.handler.amqp_8_0;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
-import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.StateAwareMethodListener;
import org.apache.qpid.framing.QueueDeleteOkBody;
@@ -42,12 +41,12 @@ public class QueueDeleteOkMethodHandler implements StateAwareMethodListener
{
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
if (_logger.isDebugEnabled())
{
QueueDeleteOkBody body = (QueueDeleteOkBody) evt.getMethod();
- _logger.debug("Received Queue.Delete-Ok message, message count: " + body.messageCount);
+ _logger.debug("Received Queue.Delete-Ok message, message count: " + body.getMessageCount());
}
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
index 36dd4d400c..66524edce3 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
@@ -121,12 +121,12 @@ public abstract class AbstractJMSMessage extends AMQMessage implements org.apach
public String getJMSMessageID() throws JMSException
{
- if (getContentHeaderProperties().getMessageId() == null)
+ if (getContentHeaderProperties().getMessageIdAsString() == null)
{
getContentHeaderProperties().setMessageId("ID:" + _deliveryTag);
}
- return getContentHeaderProperties().getMessageId();
+ return getContentHeaderProperties().getMessageIdAsString();
}
public void setJMSMessageID(String messageId) throws JMSException
@@ -146,7 +146,7 @@ public abstract class AbstractJMSMessage extends AMQMessage implements org.apach
public byte[] getJMSCorrelationIDAsBytes() throws JMSException
{
- return getContentHeaderProperties().getCorrelationId().getBytes();
+ return getContentHeaderProperties().getCorrelationIdAsString().getBytes();
}
public void setJMSCorrelationIDAsBytes(byte[] bytes) throws JMSException
@@ -161,12 +161,12 @@ public abstract class AbstractJMSMessage extends AMQMessage implements org.apach
public String getJMSCorrelationID() throws JMSException
{
- return getContentHeaderProperties().getCorrelationId();
+ return getContentHeaderProperties().getCorrelationIdAsString();
}
public Destination getJMSReplyTo() throws JMSException
{
- String replyToEncoding = getContentHeaderProperties().getReplyTo();
+ String replyToEncoding = getContentHeaderProperties().getReplyToAsString();
if (replyToEncoding == null)
{
return null;
@@ -250,7 +250,7 @@ public abstract class AbstractJMSMessage extends AMQMessage implements org.apach
public String getJMSType() throws JMSException
{
- return getContentHeaderProperties().getType();
+ return getContentHeaderProperties().getTypeAsString();
}
public void setJMSType(String string) throws JMSException
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/JMSTextMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/JMSTextMessage.java
index c05667902f..763af312f4 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/JMSTextMessage.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/JMSTextMessage.java
@@ -116,7 +116,7 @@ public class JMSTextMessage extends AbstractJMSMessage implements javax.jms.Text
_data.limit(text.length()) ;
//_data.sweep();
_data.setAutoExpand(true);
- final String encoding = getContentHeaderProperties().getEncoding();
+ final String encoding = getContentHeaderProperties().getEncodingAsString();
if (encoding == null)
{
_data.put(text.getBytes());
@@ -155,11 +155,11 @@ public class JMSTextMessage extends AbstractJMSMessage implements javax.jms.Text
{
return null;
}
- if (getContentHeaderProperties().getEncoding() != null)
+ if (getContentHeaderProperties().getEncodingAsString() != null)
{
try
{
- _decodedValue = _data.getString(Charset.forName(getContentHeaderProperties().getEncoding()).newDecoder());
+ _decodedValue = _data.getString(Charset.forName(getContentHeaderProperties().getEncodingAsString()).newDecoder());
}
catch (CharacterCodingException e)
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/MessageFactoryRegistry.java b/java/client/src/main/java/org/apache/qpid/client/message/MessageFactoryRegistry.java
index e02771d8f5..c2015f9e7c 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/MessageFactoryRegistry.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/MessageFactoryRegistry.java
@@ -92,14 +92,14 @@ public class MessageFactoryRegistry
// Get the message content type. This may be null for pure AMQP messages, but will always be set for JMS over
// AMQP. When the type is null, it can only be assumed that the message is a byte message.
- AMQShortString contentTypeShortString = properties.getContentTypeShortString();
+ AMQShortString contentTypeShortString = properties.getContentType();
contentTypeShortString = (contentTypeShortString == null) ? new AMQShortString(JMSBytesMessage.MIME_TYPE)
: contentTypeShortString;
MessageFactory mf = _mimeShortStringToFactoryMap.get(contentTypeShortString);
if (mf == null)
{
- throw new AMQException("Unsupport MIME type of " + properties.getContentType());
+ throw new AMQException("Unsupport MIME type of " + properties.getContentTypeAsString());
}
else
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
index d0cc52271a..93c0cb5c12 100644
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
@@ -1,630 +1,36 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
package org.apache.qpid.client.protocol;
-import java.util.Iterator;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.CountDownLatch;
-
-import org.apache.log4j.Logger;
-import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.IoHandlerAdapter;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.SSLFilter;
-import org.apache.mina.filter.codec.ProtocolCodecFilter;
-import org.apache.qpid.AMQConnectionClosedException;
-import org.apache.qpid.AMQDisconnectedException;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.AMQTimeoutException;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.SSLConfiguration;
-import org.apache.qpid.client.failover.FailoverHandler;
-import org.apache.qpid.client.failover.FailoverState;
-import org.apache.qpid.client.state.AMQState;
-import org.apache.qpid.client.state.AMQStateManager;
-import org.apache.qpid.client.state.listener.SpecificMethodFrameListener;
-import org.apache.qpid.codec.AMQCodecFactory;
-import org.apache.qpid.framing.AMQBody;
import org.apache.qpid.framing.AMQDataBlock;
import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.ConnectionCloseBody;
-import org.apache.qpid.framing.ConnectionCloseOkBody;
-import org.apache.qpid.framing.ContentBody;
-import org.apache.qpid.framing.ContentHeaderBody;
-import org.apache.qpid.framing.HeartbeatBody;
-import org.apache.qpid.pool.ReadWriteThreadModel;
-import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.framing.ProtocolVersion;
import org.apache.qpid.protocol.AMQMethodEvent;
-import org.apache.qpid.protocol.AMQMethodListener;
-import org.apache.qpid.ssl.SSLContextFactory;
-
+import org.apache.qpid.AMQException;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.state.AMQStateManager;
-public class AMQProtocolHandler extends IoHandlerAdapter
+/**
+ * Created by IntelliJ IDEA.
+ * User: U146758
+ * Date: 07-Mar-2007
+ * Time: 19:40:08
+ * To change this template use File | Settings | File Templates.
+ */
+public interface AMQProtocolHandler
{
- private static final Logger _logger = Logger.getLogger(AMQProtocolHandler.class);
-
- /**
- * The connection that this protocol handler is associated with. There is a 1-1 mapping between connection instances
- * and protocol handler instances.
- */
- private AMQConnection _connection;
-
- /** Our wrapper for a protocol session that provides access to session values in a typesafe manner. */
- private volatile AMQProtocolSession _protocolSession;
-
- private AMQStateManager _stateManager = new AMQStateManager();
-
- private final CopyOnWriteArraySet _frameListeners = new CopyOnWriteArraySet();
-
- /**
- * We create the failover handler when the session is created since it needs a reference to the IoSession in order
- * to be able to send errors during failover back to the client application. The session won't be available in the
- * case where we failing over due to a Connection.Redirect message from the broker.
- */
- private FailoverHandler _failoverHandler;
-
- /**
- * This flag is used to track whether failover is being attempted. It is used to prevent the application constantly
- * attempting failover where it is failing.
- */
- private FailoverState _failoverState = FailoverState.NOT_STARTED;
-
- private CountDownLatch _failoverLatch;
-
- private final long DEFAULT_SYNC_TIMEOUT = 1000 * 30;
-
- public AMQProtocolHandler(AMQConnection con)
- {
- _connection = con;
- }
-
- public void sessionCreated(IoSession session) throws Exception
- {
- _logger.debug("Protocol session created for session " + System.identityHashCode(session));
- _failoverHandler = new FailoverHandler(this, session);
-
- final ProtocolCodecFilter pcf = new ProtocolCodecFilter(new AMQCodecFactory(false));
-
- if (Boolean.getBoolean("amqj.shared_read_write_pool"))
- {
- session.getFilterChain().addBefore("AsynchronousWriteFilter", "protocolFilter", pcf);
- }
- else
- {
- session.getFilterChain().addLast("protocolFilter", pcf);
- }
- // we only add the SSL filter where we have an SSL connection
- if (_connection.getSSLConfiguration() != null)
- {
- SSLConfiguration sslConfig = _connection.getSSLConfiguration();
- SSLContextFactory sslFactory = new SSLContextFactory(sslConfig.getKeystorePath(), sslConfig.getKeystorePassword(), sslConfig.getCertType());
- SSLFilter sslFilter = new SSLFilter(sslFactory.buildClientContext());
- sslFilter.setUseClientMode(true);
- session.getFilterChain().addBefore("protocolFilter", "ssl", sslFilter);
- }
-
-
- try
- {
-
- ReadWriteThreadModel threadModel = ReadWriteThreadModel.getInstance();
- threadModel.getAsynchronousReadFilter().createNewJobForSession(session);
- threadModel.getAsynchronousWriteFilter().createNewJobForSession(session);
- }
- catch (RuntimeException e)
- {
- e.printStackTrace();
- }
-
- _protocolSession = new AMQProtocolSession(this, session, _connection, getStateManager());
- _protocolSession.init();
- }
-
- public void sessionOpened(IoSession session) throws Exception
- {
- //System.setProperty("foo", "bar");
- }
-
- /**
- * When the broker connection dies we can either get sessionClosed() called or exceptionCaught() followed by
- * sessionClosed() depending on whether we were trying to send data at the time of failure.
- *
- * @param session
- *
- * @throws Exception
- */
- public void sessionClosed(IoSession session) throws Exception
- {
- if (_connection.isClosed())
- {
- _logger.info("Session closed called by client");
- }
- else
- {
- _logger.info("Session closed called with failover state currently " + _failoverState);
-
- //reconnetablility was introduced here so as not to disturb the client as they have made their intentions
- // known through the policy settings.
-
- if ((_failoverState != FailoverState.IN_PROGRESS) && _connection.failoverAllowed())
- {
- _logger.info("FAILOVER STARTING");
- if (_failoverState == FailoverState.NOT_STARTED)
- {
- _failoverState = FailoverState.IN_PROGRESS;
- startFailoverThread();
- }
- else
- {
- _logger.info("Not starting failover as state currently " + _failoverState);
- }
- }
- else
- {
- _logger.info("Failover not allowed by policy.");
-
- if (_logger.isDebugEnabled())
- {
- _logger.debug(_connection.getFailoverPolicy().toString());
- }
-
- if (_failoverState != FailoverState.IN_PROGRESS)
- {
- _logger.info("sessionClose() not allowed to failover");
- _connection.exceptionReceived(
- new AMQDisconnectedException("Server closed connection and reconnection " +
- "not permitted."));
- }
- else
- {
- _logger.info("sessionClose() failover in progress");
- }
- }
- }
-
- _logger.info("Protocol Session [" + this + "] closed");
- }
-
- /** See {@link FailoverHandler} to see rationale for separate thread. */
- private void startFailoverThread()
- {
- Thread failoverThread = new Thread(_failoverHandler);
- failoverThread.setName("Failover");
- // Do not inherit daemon-ness from current thread as this can be a daemon
- // thread such as a AnonymousIoService thread.
- failoverThread.setDaemon(false);
- failoverThread.start();
- }
-
- public void sessionIdle(IoSession session, IdleStatus status) throws Exception
- {
- _logger.debug("Protocol Session [" + this + ":" + session + "] idle: " + status);
- if (IdleStatus.WRITER_IDLE.equals(status))
- {
- //write heartbeat frame:
- _logger.debug("Sent heartbeat");
- session.write(HeartbeatBody.FRAME);
- HeartbeatDiagnostics.sent();
- }
- else if (IdleStatus.READER_IDLE.equals(status))
- {
- //failover:
- HeartbeatDiagnostics.timeout();
- _logger.warn("Timed out while waiting for heartbeat from peer.");
- session.close();
- }
- }
-
- public void exceptionCaught(IoSession session, Throwable cause) throws Exception
- {
- if (_failoverState == FailoverState.NOT_STARTED)
- {
- //if (!(cause instanceof AMQUndeliveredException) && (!(cause instanceof AMQAuthenticationException)))
- if (cause instanceof AMQConnectionClosedException)
- {
- _logger.info("Exception caught therefore going to attempt failover: " + cause, cause);
- // this will attemp failover
-
- sessionClosed(session);
- }
- }
- // we reach this point if failover was attempted and failed therefore we need to let the calling app
- // know since we cannot recover the situation
- else if (_failoverState == FailoverState.FAILED)
- {
- _logger.error("Exception caught by protocol handler: " + cause, cause);
- // we notify the state manager of the error in case we have any clients waiting on a state
- // change. Those "waiters" will be interrupted and can handle the exception
- AMQException amqe = new AMQException("Protocol handler error: " + cause, cause);
- propagateExceptionToWaiters(amqe);
- _connection.exceptionReceived(cause);
- }
- }
-
- /**
- * There are two cases where we have other threads potentially blocking for events to be handled by this class.
- * These are for the state manager (waiting for a state change) or a frame listener (waiting for a particular type
- * of frame to arrive). When an error occurs we need to notify these waiters so that they can react appropriately.
- *
- * @param e the exception to propagate
- */
- public void propagateExceptionToWaiters(Exception e)
- {
- getStateManager().error(e);
- if (!_frameListeners.isEmpty())
- {
- final Iterator it = _frameListeners.iterator();
- while (it.hasNext())
- {
- final AMQMethodListener ml = (AMQMethodListener) it.next();
- ml.error(e);
- }
- }
- }
-
- private static int _messageReceivedCount;
-
- public void messageReceived(IoSession session, Object message) throws Exception
- {
- final boolean debug = _logger.isDebugEnabled();
- final long msgNumber = ++_messageReceivedCount;
-
- if (debug && (msgNumber % 1000 == 0))
- {
- _logger.debug("Received " + _messageReceivedCount + " protocol messages");
- }
-
- AMQFrame frame = (AMQFrame) message;
-
- final AMQBody bodyFrame = frame.getBodyFrame();
-
- HeartbeatDiagnostics.received(bodyFrame instanceof HeartbeatBody);
-
- switch (bodyFrame.getFrameType())
- {
- case AMQMethodBody.TYPE:
-
- if (debug)
- {
- _logger.debug("(" + System.identityHashCode(this) + ")Method frame received: " + frame);
- }
-
- final AMQMethodEvent<AMQMethodBody> evt = new AMQMethodEvent<AMQMethodBody>(frame.getChannel(), (AMQMethodBody) bodyFrame);
-
- try
- {
-
- boolean wasAnyoneInterested = getStateManager().methodReceived(evt);
- if (!_frameListeners.isEmpty())
- {
- Iterator it = _frameListeners.iterator();
- while (it.hasNext())
- {
- final AMQMethodListener listener = (AMQMethodListener) it.next();
- wasAnyoneInterested = listener.methodReceived(evt) || wasAnyoneInterested;
- }
- }
- if (!wasAnyoneInterested)
- {
- throw new AMQException("AMQMethodEvent " + evt + " was not processed by any listener. Listeners:" + _frameListeners);
- }
- }
- catch (AMQException e)
- {
- getStateManager().error(e);
- if (!_frameListeners.isEmpty())
- {
- Iterator it = _frameListeners.iterator();
- while (it.hasNext())
- {
- final AMQMethodListener listener = (AMQMethodListener) it.next();
- listener.error(e);
- }
- }
- exceptionCaught(session, e);
- }
- break;
-
- case ContentHeaderBody.TYPE:
-
- _protocolSession.messageContentHeaderReceived(frame.getChannel(),
- (ContentHeaderBody) bodyFrame);
- break;
-
- case ContentBody.TYPE:
-
- _protocolSession.messageContentBodyReceived(frame.getChannel(),
- (ContentBody) bodyFrame);
- break;
-
- case HeartbeatBody.TYPE:
-
- if (debug)
- {
- _logger.debug("Received heartbeat");
- }
- break;
-
- default:
-
- }
- _connection.bytesReceived(_protocolSession.getIoSession().getReadBytes());
- }
-
- private static int _messagesOut;
-
- public void messageSent(IoSession session, Object message) throws Exception
- {
- final long sentMessages = _messagesOut++;
-
- final boolean debug = _logger.isDebugEnabled();
-
- if (debug && (sentMessages % 1000 == 0))
- {
- _logger.debug("Sent " + _messagesOut + " protocol messages");
- }
- _connection.bytesSent(session.getWrittenBytes());
- if (debug)
- {
- _logger.debug("Sent frame " + message);
- }
- }
-
- /*
- public void addFrameListener(AMQMethodListener listener)
- {
- _frameListeners.add(listener);
- }
-
- public void removeFrameListener(AMQMethodListener listener)
- {
- _frameListeners.remove(listener);
- }
- */
- public void attainState(AMQState s) throws AMQException
- {
- getStateManager().attainState(s);
- }
-
- /**
- * Convenience method that writes a frame to the protocol session. Equivalent to calling
- * getProtocolSession().write().
- *
- * @param frame the frame to write
- */
- public void writeFrame(AMQDataBlock frame)
- {
- _protocolSession.writeFrame(frame);
- }
-
- public void writeFrame(AMQDataBlock frame, boolean wait)
- {
- _protocolSession.writeFrame(frame, wait);
- }
-
- /**
- * Convenience method that writes a frame to the protocol session and waits for a particular response. Equivalent to
- * calling getProtocolSession().write() then waiting for the response.
- *
- * @param frame
- * @param listener the blocking listener. Note the calling thread will block.
- */
- public AMQMethodEvent writeCommandFrameAndWaitForReply(AMQFrame frame,
- BlockingMethodFrameListener listener)
- throws AMQException
- {
- return writeCommandFrameAndWaitForReply(frame, listener, DEFAULT_SYNC_TIMEOUT);
- }
-
- /**
- * Convenience method that writes a frame to the protocol session and waits for a particular response. Equivalent to
- * calling getProtocolSession().write() then waiting for the response.
- *
- * @param frame
- * @param listener the blocking listener. Note the calling thread will block.
- */
- public AMQMethodEvent writeCommandFrameAndWaitForReply(AMQFrame frame,
- BlockingMethodFrameListener listener, long timeout)
- throws AMQException
- {
- try
- {
- _frameListeners.add(listener);
- _protocolSession.writeFrame(frame);
-
- AMQMethodEvent e = listener.blockForFrame(timeout);
- return e;
- // When control resumes before this line, a reply will have been received
- // that matches the criteria defined in the blocking listener
- }
- catch (AMQException e)
- {
- throw e;
- }
- finally
- {
- // If we don't removeKey the listener then no-one will
- _frameListeners.remove(listener);
- }
-
- }
-
- /** More convenient method to write a frame and wait for it's response. */
- public AMQMethodEvent syncWrite(AMQFrame frame, Class responseClass) throws AMQException
- {
- return syncWrite(frame, responseClass, DEFAULT_SYNC_TIMEOUT);
- }
-
- /** More convenient method to write a frame and wait for it's response. */
- public AMQMethodEvent syncWrite(AMQFrame frame, Class responseClass, long timeout) throws AMQException
- {
- return writeCommandFrameAndWaitForReply(frame,
- new SpecificMethodFrameListener(frame.getChannel(), responseClass), timeout);
- }
-
- /**
- * Convenience method to register an AMQSession with the protocol handler. Registering a session with the protocol
- * handler will ensure that messages are delivered to the consumer(s) on that session.
- *
- * @param channelId the channel id of the session
- * @param session the session instance.
- */
- public void addSessionByChannel(int channelId, AMQSession session)
- {
- _protocolSession.addSessionByChannel(channelId, session);
- }
-
- /**
- * Convenience method to deregister an AMQSession with the protocol handler.
- *
- * @param channelId then channel id of the session
- */
- public void removeSessionByChannel(int channelId)
- {
- _protocolSession.removeSessionByChannel(channelId);
- }
-
- public void closeSession(AMQSession session) throws AMQException
- {
- _protocolSession.closeSession(session);
- }
-
- public void closeConnection() throws AMQException
- {
- closeConnection(-1);
- }
-
- public void closeConnection(long timeout) throws AMQException
- {
- getStateManager().changeState(AMQState.CONNECTION_CLOSING);
-
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- final AMQFrame frame = ConnectionCloseBody.createAMQFrame(0,
- _protocolSession.getProtocolMajorVersion(),
- _protocolSession.getProtocolMinorVersion(), // AMQP version (major, minor)
- 0, // classId
- 0, // methodId
- AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
- new AMQShortString("JMS client is closing the connection.")); // replyText
-
- try
- {
- syncWrite(frame, ConnectionCloseOkBody.class, timeout);
- _protocolSession.closeProtocolSession();
- }
- catch (AMQTimeoutException e)
- {
- _protocolSession.closeProtocolSession(false);
- }
-
-
- }
-
- /** @return the number of bytes read from this protocol session */
- public long getReadBytes()
- {
- return _protocolSession.getIoSession().getReadBytes();
- }
-
- /** @return the number of bytes written to this protocol session */
- public long getWrittenBytes()
- {
- return _protocolSession.getIoSession().getWrittenBytes();
- }
-
- public void failover(String host, int port)
- {
- _failoverHandler.setHost(host);
- _failoverHandler.setPort(port);
- // see javadoc for FailoverHandler to see rationale for separate thread
- startFailoverThread();
- }
-
- public void blockUntilNotFailingOver() throws InterruptedException
- {
- if (_failoverLatch != null)
- {
- _failoverLatch.await();
- }
- }
-
- public AMQShortString generateQueueName()
- {
- return _protocolSession.generateQueueName();
- }
-
- public CountDownLatch getFailoverLatch()
- {
- return _failoverLatch;
- }
-
- public void setFailoverLatch(CountDownLatch failoverLatch)
- {
- _failoverLatch = failoverLatch;
- }
-
- public AMQConnection getConnection()
- {
- return _connection;
- }
-
- public AMQStateManager getStateManager()
- {
- return _stateManager;
- }
+ void writeFrame(AMQDataBlock frame);
- public void setStateManager(AMQStateManager stateManager)
- {
- _stateManager = stateManager;
- _protocolSession.setStateManager(stateManager);
- }
+ void closeSession(AMQSession session) throws AMQException;
- public AMQProtocolSession getProtocolSession()
- {
- return _protocolSession;
- }
+ void closeConnection() throws AMQException;
- FailoverState getFailoverState()
- {
- return _failoverState;
- }
+ AMQConnection getConnection();
- public void setFailoverState(FailoverState failoverState)
- {
- _failoverState = failoverState;
- }
+ AMQStateManager getStateManager();
- public byte getProtocolMajorVersion()
- {
- return _protocolSession.getProtocolMajorVersion();
- }
+ AMQProtocolSession getProtocolSession();
+ ProtocolOutputHandler getOutputHandler();
- public byte getProtocolMinorVersion()
- {
- return _protocolSession.getProtocolMinorVersion();
- }
+ ProtocolVersion getProtocolVersion();
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandlerImpl.java b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandlerImpl.java
new file mode 100644
index 0000000000..738531d5a5
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandlerImpl.java
@@ -0,0 +1,537 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.client.protocol;
+
+import java.util.Iterator;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.log4j.Logger;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.SSLFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.qpid.AMQConnectionClosedException;
+import org.apache.qpid.AMQDisconnectedException;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.AMQTimeoutException;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.SSLConfiguration;
+import org.apache.qpid.client.failover.FailoverHandler;
+import org.apache.qpid.client.failover.FailoverState;
+import org.apache.qpid.client.state.AMQState;
+import org.apache.qpid.client.state.AMQStateManager;
+import org.apache.qpid.client.state.listener.SpecificMethodFrameListener;
+import org.apache.qpid.codec.AMQCodecFactory;
+import org.apache.qpid.framing.*;
+import org.apache.qpid.pool.ReadWriteThreadModel;
+import org.apache.qpid.protocol.AMQMethodEvent;
+import org.apache.qpid.protocol.AMQMethodListener;
+import org.apache.qpid.ssl.SSLContextFactory;
+
+
+public class AMQProtocolHandlerImpl extends IoHandlerAdapter implements AMQProtocolHandler
+{
+ private static final Logger _logger = Logger.getLogger(AMQProtocolHandlerImpl.class);
+
+ /**
+ * The connection that this protocol handler is associated with. There is a 1-1 mapping between connection instances
+ * and protocol handler instances.
+ */
+ private AMQConnection _connection;
+
+ /** Our wrapper for a protocol session that provides access to session values in a typesafe manner. */
+ private volatile AMQProtocolSession _protocolSession;
+
+ private AMQStateManager _stateManager = new AMQStateManager();
+
+
+
+ /**
+ * We create the failover handler when the session is created since it needs a reference to the IoSession in order
+ * to be able to send errors during failover back to the client application. The session won't be available in the
+ * case where we failing over due to a Connection.Redirect message from the broker.
+ */
+ private FailoverHandler _failoverHandler;
+
+ /**
+ * This flag is used to track whether failover is being attempted. It is used to prevent the application constantly
+ * attempting failover where it is failing.
+ */
+ private FailoverState _failoverState = FailoverState.NOT_STARTED;
+
+ private CountDownLatch _failoverLatch;
+
+ private final long DEFAULT_SYNC_TIMEOUT = 1000 * 30;
+ private static final int CONTROL_CHANNEL = 0;
+
+ public AMQProtocolHandlerImpl(AMQConnection con)
+ {
+ _connection = con;
+ }
+
+ public void sessionCreated(IoSession session) throws Exception
+ {
+ _logger.debug("Protocol session created for session " + System.identityHashCode(session));
+ _failoverHandler = new FailoverHandler(this, session);
+
+ final ProtocolCodecFilter pcf = new ProtocolCodecFilter(new AMQCodecFactory(false));
+
+ if (Boolean.getBoolean("amqj.shared_read_write_pool"))
+ {
+ session.getFilterChain().addBefore("AsynchronousWriteFilter", "protocolFilter", pcf);
+ }
+ else
+ {
+ session.getFilterChain().addLast("protocolFilter", pcf);
+ }
+ // we only add the SSL filter where we have an SSL connection
+ if (_connection.getSSLConfiguration() != null)
+ {
+ SSLConfiguration sslConfig = _connection.getSSLConfiguration();
+ SSLContextFactory sslFactory = new SSLContextFactory(sslConfig.getKeystorePath(), sslConfig.getKeystorePassword(), sslConfig.getCertType());
+ SSLFilter sslFilter = new SSLFilter(sslFactory.buildClientContext());
+ sslFilter.setUseClientMode(true);
+ session.getFilterChain().addBefore("protocolFilter", "ssl", sslFilter);
+ }
+
+
+
+ ReadWriteThreadModel threadModel = ReadWriteThreadModel.getInstance();
+ threadModel.getAsynchronousReadFilter().createNewJobForSession(session);
+ threadModel.getAsynchronousWriteFilter().createNewJobForSession(session);
+
+
+ _protocolSession = new AMQProtocolSession(this, session, _connection, getStateManager());
+
+ // This starts the AMQP initiation by sending the AMQP Header
+ _protocolSession.init();
+ }
+
+ public void sessionOpened(IoSession session) throws Exception
+ {
+
+ }
+
+ /**
+ * When the broker connection dies we can either get sessionClosed() called or exceptionCaught() followed by
+ * sessionClosed() depending on whether we were trying to send data at the time of failure.
+ *
+ * @param session
+ *
+ * @throws Exception
+ */
+ public void sessionClosed(IoSession session) throws Exception
+ {
+ if (_connection.isClosed())
+ {
+ _logger.info("Session closed called by client");
+ }
+ else
+ {
+ _logger.info("Session closed called with failover state currently " + _failoverState);
+
+ //reconnetablility was introduced here so as not to disturb the client as they have made their intentions
+ // known through the policy settings.
+
+ if ((_failoverState != FailoverState.IN_PROGRESS) && _connection.failoverAllowed())
+ {
+ _logger.info("FAILOVER STARTING");
+ if (_failoverState == FailoverState.NOT_STARTED)
+ {
+ _failoverState = FailoverState.IN_PROGRESS;
+ startFailoverThread();
+ }
+ else
+ {
+ _logger.info("Not starting failover as state currently " + _failoverState);
+ }
+ }
+ else
+ {
+ _logger.info("Failover not allowed by policy.");
+
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug(_connection.getFailoverPolicy().toString());
+ }
+
+ if (_failoverState != FailoverState.IN_PROGRESS)
+ {
+ _logger.info("sessionClose() not allowed to failover");
+ _connection.exceptionReceived(
+ new AMQDisconnectedException("Server closed connection and reconnection " +
+ "not permitted."));
+ }
+ else
+ {
+ _logger.info("sessionClose() failover in progress");
+ }
+ }
+ }
+
+ _logger.info("Protocol Session [" + this + "] closed");
+ }
+
+ /** See {@link FailoverHandler} to see rationale for separate thread. */
+ private void startFailoverThread()
+ {
+ Thread failoverThread = new Thread(_failoverHandler);
+ failoverThread.setName("Failover");
+ // Do not inherit daemon-ness from current thread as this can be a daemon
+ // thread such as a AnonymousIoService thread.
+ failoverThread.setDaemon(false);
+ failoverThread.start();
+ }
+
+ public void sessionIdle(IoSession session, IdleStatus status) throws Exception
+ {
+ _logger.debug("Protocol Session [" + this + ":" + session + "] idle: " + status);
+ if (IdleStatus.WRITER_IDLE.equals(status))
+ {
+ //write heartbeat frame:
+ _logger.debug("Sent heartbeat");
+ session.write(HeartbeatBody.FRAME);
+ HeartbeatDiagnostics.sent();
+ }
+ else if (IdleStatus.READER_IDLE.equals(status))
+ {
+ //failover:
+ HeartbeatDiagnostics.timeout();
+ _logger.warn("Timed out while waiting for heartbeat from peer.");
+ session.close();
+ }
+ }
+
+ public void exceptionCaught(IoSession session, Throwable cause) throws Exception
+ {
+ if (_failoverState == FailoverState.NOT_STARTED)
+ {
+ //if (!(cause instanceof AMQUndeliveredException) && (!(cause instanceof AMQAuthenticationException)))
+ if (cause instanceof AMQConnectionClosedException)
+ {
+ _logger.info("Exception caught therefore going to attempt failover: " + cause, cause);
+ // this will attemp failover
+
+ sessionClosed(session);
+ }
+ }
+ // we reach this point if failover was attempted and failed therefore we need to let the calling app
+ // know since we cannot recover the situation
+ else if (_failoverState == FailoverState.FAILED)
+ {
+ _logger.error("Exception caught by protocol handler: " + cause, cause);
+ // we notify the state manager of the error in case we have any clients waiting on a state
+ // change. Those "waiters" will be interrupted and can handle the exception
+ AMQException amqe = new AMQException("Protocol handler error: " + cause, cause);
+ propagateExceptionToWaiters(amqe);
+ _connection.exceptionReceived(cause);
+ }
+ }
+
+ /**
+ * There are two cases where we have other threads potentially blocking for events to be handled by this class.
+ * These are for the state manager (waiting for a state change) or a frame listener (waiting for a particular type
+ * of frame to arrive). When an error occurs we need to notify these waiters so that they can react appropriately.
+ *
+ * @param e the exception to propagate
+ */
+ public void propagateExceptionToWaiters(Exception e)
+ {
+ getStateManager().error(e);
+ getProtocolSession().getOutputHandler().error(e);
+
+ }
+
+ private static int _messageReceivedCount;
+
+ public void messageReceived(IoSession session, Object message) throws Exception
+ {
+ final boolean debug = _logger.isDebugEnabled();
+ final long msgNumber = ++_messageReceivedCount;
+
+ if (debug && (msgNumber % 1000 == CONTROL_CHANNEL))
+ {
+ _logger.debug("Received " + _messageReceivedCount + " protocol messages");
+ }
+
+ AMQFrame frame = (AMQFrame) message;
+
+ final AMQBody bodyFrame = frame.getBodyFrame();
+
+ HeartbeatDiagnostics.received(bodyFrame instanceof HeartbeatBody);
+
+ switch (bodyFrame.getFrameType())
+ {
+ case AMQMethodBodyImpl.TYPE:
+
+ if (debug)
+ {
+ _logger.debug("(" + System.identityHashCode(this) + ")Method frame received: " + frame);
+ }
+
+ final AMQMethodEvent<? extends AMQMethodBody> evt = new AMQMethodEvent<AMQMethodBody>(frame.getChannel(), (AMQMethodBody) bodyFrame);
+
+ try
+ {
+
+ boolean wasAnyoneInterested = getStateManager().methodReceived(evt);
+ wasAnyoneInterested = getProtocolSession().getOutputHandler().methodReceived(evt) || wasAnyoneInterested;
+
+ if (!wasAnyoneInterested)
+ {
+ throw new AMQException("AMQMethodEvent " + evt + " was not processed by any listener.");
+ }
+ }
+ catch (AMQException e)
+ {
+ getStateManager().error(e);
+ getProtocolSession().getOutputHandler().error(e);
+ exceptionCaught(session, e);
+ }
+ break;
+
+ case ContentHeaderBody.TYPE:
+
+ _protocolSession.messageContentHeaderReceived(frame.getChannel(),
+ (ContentHeaderBody) bodyFrame);
+ break;
+
+ case ContentBody.TYPE:
+
+ _protocolSession.messageContentBodyReceived(frame.getChannel(),
+ (ContentBody) bodyFrame);
+ break;
+
+ case HeartbeatBody.TYPE:
+
+ if (debug)
+ {
+ _logger.debug("Received heartbeat");
+ }
+ break;
+
+ default:
+
+ }
+ _connection.bytesReceived(_protocolSession.getIoSession().getReadBytes());
+ }
+
+ private static int _messagesOut;
+
+ public void messageSent(IoSession session, Object message) throws Exception
+ {
+ final long sentMessages = _messagesOut++;
+
+ final boolean debug = _logger.isDebugEnabled();
+
+ if (debug && (sentMessages % 1000 == CONTROL_CHANNEL))
+ {
+ _logger.debug("Sent " + _messagesOut + " protocol messages");
+ }
+ _connection.bytesSent(session.getWrittenBytes());
+ if (debug)
+ {
+ _logger.debug("Sent frame " + message);
+ }
+ }
+
+ /*
+ public void addFrameListener(AMQMethodListener listener)
+ {
+ _frameListeners.add(listener);
+ }
+
+ public void removeFrameListener(AMQMethodListener listener)
+ {
+ _frameListeners.remove(listener);
+ }
+ */
+ public void attainState(AMQState s) throws AMQException
+ {
+ getStateManager().attainState(s);
+ }
+
+ /**
+ * Convenience method that writes a frame to the protocol session. Equivalent to calling
+ * getProtocolSession().write().
+ *
+ * @param frame the frame to write
+ */
+ public void writeFrame(AMQDataBlock frame)
+ {
+ _protocolSession.writeFrame(frame);
+ }
+
+
+
+ /**
+ * Convenience method to register an AMQSession with the protocol handler. Registering a session with the protocol
+ * handler will ensure that messages are delivered to the consumer(s) on that session.
+ *
+ * @param channelId the channel id of the session
+ * @param session the session instance.
+ */
+ public void addSessionByChannel(int channelId, AMQSession session)
+ {
+ _protocolSession.addSessionByChannel(channelId, session);
+ }
+
+ /**
+ * Convenience method to deregister an AMQSession with the protocol handler.
+ *
+ * @param channelId then channel id of the session
+ */
+ public void removeSessionByChannel(int channelId)
+ {
+ _protocolSession.removeSessionByChannel(channelId);
+ }
+
+ public void closeSession(AMQSession session) throws AMQException
+ {
+ _protocolSession.closeSession(session);
+ }
+
+ public void closeConnection() throws AMQException
+ {
+ closeConnection(-1);
+ }
+
+ public void closeConnection(long timeout) throws AMQException
+ {
+ getStateManager().changeState(AMQState.CONNECTION_CLOSING);
+
+
+ try
+ {
+ ConnectionCloseBody closeBody = getAMQMethodFactory().createConnectionClose();
+ sendCommandReceiveResponse(CONTROL_CHANNEL,closeBody);
+
+
+ _protocolSession.closeProtocolSession();
+ }
+ catch (AMQTimeoutException e)
+ {
+ _protocolSession.closeProtocolSession(false);
+ }
+
+
+ }
+
+ private void sendCommandReceiveResponse(int channelId, AMQMethodBody command) throws AMQException
+ {
+ getOutputHandler().sendCommandReceiveResponse(channelId, command);
+ }
+
+ private AMQMethodFactory getAMQMethodFactory()
+ {
+ return getOutputHandler().getAMQMethodFactory();
+ }
+
+ /** @return the number of bytes read from this protocol session */
+ public long getReadBytes()
+ {
+ return _protocolSession.getIoSession().getReadBytes();
+ }
+
+ /** @return the number of bytes written to this protocol session */
+ public long getWrittenBytes()
+ {
+ return _protocolSession.getIoSession().getWrittenBytes();
+ }
+
+ public void failover(String host, int port)
+ {
+ _failoverHandler.setHost(host);
+ _failoverHandler.setPort(port);
+ // see javadoc for FailoverHandler to see rationale for separate thread
+ startFailoverThread();
+ }
+
+ public void blockUntilNotFailingOver() throws InterruptedException
+ {
+ if (_failoverLatch != null)
+ {
+ _failoverLatch.await();
+ }
+ }
+
+ public AMQShortString generateQueueName()
+ {
+ return _protocolSession.generateQueueName();
+ }
+
+ public CountDownLatch getFailoverLatch()
+ {
+ return _failoverLatch;
+ }
+
+ public void setFailoverLatch(CountDownLatch failoverLatch)
+ {
+ _failoverLatch = failoverLatch;
+ }
+
+ public AMQConnection getConnection()
+ {
+ return _connection;
+ }
+
+ public AMQStateManager getStateManager()
+ {
+ return _stateManager;
+ }
+
+ public void setStateManager(AMQStateManager stateManager)
+ {
+ _stateManager = stateManager;
+ _protocolSession.setStateManager(stateManager);
+ }
+
+ public AMQProtocolSession getProtocolSession()
+ {
+ return _protocolSession;
+ }
+
+ public ProtocolOutputHandler getOutputHandler()
+ {
+ return getProtocolSession().getOutputHandler();
+ }
+
+ FailoverState getFailoverState()
+ {
+ return _failoverState;
+ }
+
+ public void setFailoverState(FailoverState failoverState)
+ {
+ _failoverState = failoverState;
+ }
+
+ public ProtocolVersion getProtocolVersion()
+ {
+ return _protocolSession.getProtocolVersion();
+ }
+
+
+
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
index 055109d3be..3c158415e0 100644
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
@@ -43,10 +43,11 @@ import org.apache.qpid.framing.AMQDataBlock;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ContentBody;
import org.apache.qpid.framing.ContentHeaderBody;
-import org.apache.qpid.framing.MainRegistry;
import org.apache.qpid.framing.ProtocolInitiation;
-import org.apache.qpid.framing.ProtocolVersionList;
+import org.apache.qpid.framing.ProtocolVersion;
import org.apache.qpid.framing.VersionSpecificRegistry;
+import org.apache.qpid.framing.MainRegistry;
+import org.apache.qpid.framing.MethodRegistry;
import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
import org.apache.qpid.protocol.AMQConstant;
@@ -56,7 +57,7 @@ import org.apache.qpid.protocol.AMQConstant;
* The underlying protocol session is still available but clients should not
* use it to obtain session attributes.
*/
-public class AMQProtocolSession implements ProtocolVersionList, AMQVersionAwareProtocolSession
+public class AMQProtocolSession implements AMQVersionAwareProtocolSession
{
protected static final int LAST_WRITE_FUTURE_JOIN_TIMEOUT = 1000 * 60 * 2;
@@ -81,7 +82,7 @@ public class AMQProtocolSession implements ProtocolVersionList, AMQVersionAwareP
* The handler from which this session was created and which is used to handle protocol events.
* We send failover events to the handler.
*/
- protected final AMQProtocolHandler _protocolHandler;
+ protected final AMQProtocolHandlerImpl _protocolHandler;
/**
* Maps from the channel id to the AMQSession that it represents.
@@ -102,9 +103,10 @@ public class AMQProtocolSession implements ProtocolVersionList, AMQVersionAwareP
protected int _queueId = 1;
protected final Object _queueIdLock = new Object();
- private byte _protocolMinorVersion;
- private byte _protocolMajorVersion;
- private VersionSpecificRegistry _registry = MainRegistry.getVersionSpecificRegistry(pv[pv.length-1][PROTOCOL_MAJOR],pv[pv.length-1][PROTOCOL_MINOR]);
+ private MethodRegistry _registry = MethodRegistry.getMethodRegistry(ProtocolVersion.getLatestSupportedVersion());
+ private ProtocolVersion _protocolVersion;
+ private ProtocolOutputHandler _outputHandler = ProtocolOutputHandlerFactory.createOutputHandler(ProtocolVersion.getLatestSupportedVersion(), this);
+ ;
/**
@@ -118,7 +120,7 @@ public class AMQProtocolSession implements ProtocolVersionList, AMQVersionAwareP
_stateManager = new AMQStateManager(this);
}
- public AMQProtocolSession(AMQProtocolHandler protocolHandler, IoSession protocolSession, AMQConnection connection)
+ public AMQProtocolSession(AMQProtocolHandlerImpl protocolHandler, IoSession protocolSession, AMQConnection connection)
{
_protocolHandler = protocolHandler;
_minaProtocolSession = protocolSession;
@@ -129,7 +131,7 @@ public class AMQProtocolSession implements ProtocolVersionList, AMQVersionAwareP
_stateManager = new AMQStateManager(this);
}
- public AMQProtocolSession(AMQProtocolHandler protocolHandler, IoSession protocolSession, AMQConnection connection, AMQStateManager stateManager)
+ public AMQProtocolSession(AMQProtocolHandlerImpl protocolHandler, IoSession protocolSession, AMQConnection connection, AMQStateManager stateManager)
{
_protocolHandler = protocolHandler;
_minaProtocolSession = protocolSession;
@@ -147,11 +149,8 @@ public class AMQProtocolSession implements ProtocolVersionList, AMQVersionAwareP
{
// start the process of setting up the connection. This is the first place that
// data is written to the server.
- /* Find last protocol version in protocol version list. Make sure last protocol version
- listed in the build file (build-module.xml) is the latest version which will be used
- here. */
- int i = pv.length - 1;
- _minaProtocolSession.write(new ProtocolInitiation(pv[i][PROTOCOL_MAJOR], pv[i][PROTOCOL_MINOR]));
+
+ _minaProtocolSession.write(new ProtocolInitiation(ProtocolVersion.getLatestSupportedVersion()));
}
public String getClientID()
@@ -474,26 +473,27 @@ public class AMQProtocolSession implements ProtocolVersionList, AMQVersionAwareP
session.confirmConsumerCancelled(consumerTag);
}
- public void setProtocolVersion(final byte versionMajor, final byte versionMinor)
+ public void setProtocolVersion(ProtocolVersion pv)
{
- _protocolMajorVersion = versionMajor;
- _protocolMinorVersion = versionMinor;
- _registry = MainRegistry.getVersionSpecificRegistry(versionMajor, versionMinor);
+ _protocolVersion = pv;
+
+ _registry = MethodRegistry.getMethodRegistry(pv);
}
- public byte getProtocolMinorVersion()
+ public ProtocolVersion getProtocolVersion()
{
- return _protocolMinorVersion;
+ return _protocolVersion;
}
- public byte getProtocolMajorVersion()
+ public MethodRegistry getRegistry()
{
- return _protocolMajorVersion;
+ return _registry;
}
- public VersionSpecificRegistry getRegistry()
+ public ProtocolOutputHandler getOutputHandler()
{
- return _registry;
+ return _outputHandler;
}
+
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java b/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java
index 85f98eab69..8f1f410a15 100644
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java
@@ -23,11 +23,12 @@ package org.apache.qpid.client.protocol;
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQTimeoutException;
import org.apache.qpid.client.failover.FailoverException;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.framing.AMQMethodBody;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
-public abstract class BlockingMethodFrameListener implements AMQMethodListener
+public abstract class BlockingMethodFrameListener<T extends AMQMethodBody> implements AMQMethodListener
{
private volatile boolean _ready = false;
@@ -43,7 +44,7 @@ public abstract class BlockingMethodFrameListener implements AMQMethodListener
protected int _channelId;
- protected AMQMethodEvent _doneEvt = null;
+ protected AMQMethodEvent<T> _doneEvt = null;
public BlockingMethodFrameListener(int channelId)
{
@@ -91,7 +92,7 @@ public abstract class BlockingMethodFrameListener implements AMQMethodListener
/**
* This method is called by the thread that wants to wait for a frame.
*/
- public AMQMethodEvent blockForFrame(long timeout) throws AMQException
+ public AMQMethodEvent<T> blockForFrame(long timeout) throws AMQException
{
synchronized (_lock)
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolOutputHandler.java b/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolOutputHandler.java
new file mode 100644
index 0000000000..3db6232d41
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolOutputHandler.java
@@ -0,0 +1,58 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.client.protocol;
+
+import org.apache.qpid.framing.ProtocolVersion;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodFactory;
+import org.apache.qpid.framing.CommonContentHeaderProperties;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
+import org.apache.qpid.AMQTimeoutException;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.protocol.AMQMethodEvent;
+
+import org.apache.mina.common.ByteBuffer;
+
+import java.util.Map;
+import java.util.HashMap;
+
+
+public interface ProtocolOutputHandler
+{
+
+ void sendCommand(int channelId, AMQMethodBody command);
+
+ AMQMethodBody sendCommandReceiveResponse(int channelId, AMQMethodBody command) throws AMQException;
+ AMQMethodBody sendCommandReceiveResponse(int channelId, AMQMethodBody command, long timeout) throws AMQException;
+ <T extends AMQMethodBody> T sendCommandReceiveResponse(int channelId, AMQMethodBody command, Class<T> responseClass, long timeout) throws AMQException;
+ <T extends AMQMethodBody> T sendCommandReceiveResponse(int channelId, AMQMethodBody command, Class<T> responseClass) throws AMQException;
+
+ AMQMethodFactory getAMQMethodFactory();
+
+ void publishMessage(int channelId, AMQShortString exchangeName, AMQShortString routingKey, boolean immediate, boolean mandatory, ByteBuffer payload, CommonContentHeaderProperties contentHeaderProperties, int ticket);
+
+ <M extends AMQMethodBody> boolean methodReceived(AMQMethodEvent<M> evt) throws Exception;
+
+ void error(Exception e);
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolOutputHandlerFactory.java b/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolOutputHandlerFactory.java
new file mode 100644
index 0000000000..6cc0d8d3b5
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolOutputHandlerFactory.java
@@ -0,0 +1,50 @@
+package org.apache.qpid.client.protocol;
+
+import org.apache.qpid.framing.ProtocolVersion;
+import org.apache.qpid.client.protocol.amqp_8_0.ProtocolOutputHandler_8_0;
+
+import java.util.Map;
+import java.util.HashMap;
+
+public abstract class ProtocolOutputHandlerFactory
+{
+ private static final Map<ProtocolVersion, ProtocolOutputHandlerFactory> _handlers =
+ new HashMap<ProtocolVersion, ProtocolOutputHandlerFactory>();
+
+ public ProtocolOutputHandlerFactory(ProtocolVersion pv)
+ {
+ _handlers.put(pv,this);
+ }
+
+ public abstract ProtocolOutputHandler newInstance(AMQProtocolSession amqProtocolSession);
+
+ public static ProtocolOutputHandler createOutputHandler(ProtocolVersion version, AMQProtocolSession amqProtocolSession)
+ {
+ return _handlers.get(version).newInstance(amqProtocolSession);
+ }
+
+ private static final ProtocolOutputHandlerFactory VERSION_8_0 =
+ new ProtocolOutputHandlerFactory(new ProtocolVersion((byte)8,(byte)0))
+ {
+
+ public ProtocolOutputHandler newInstance(AMQProtocolSession amqProtocolSession)
+ {
+ return new ProtocolOutputHandler_8_0(amqProtocolSession);
+ }
+ };
+
+ // TODO - HACK
+
+ private static final ProtocolOutputHandlerFactory VERSION_0_9 =
+ new ProtocolOutputHandlerFactory(new ProtocolVersion((byte)0,(byte)9))
+ {
+
+ public ProtocolOutputHandler newInstance(AMQProtocolSession amqProtocolSession)
+ {
+ return new ProtocolOutputHandler_8_0(amqProtocolSession);
+ }
+ };
+
+
+
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/amqp_8_0/ProtocolOutputHandler_8_0.java b/java/client/src/main/java/org/apache/qpid/client/protocol/amqp_8_0/ProtocolOutputHandler_8_0.java
new file mode 100644
index 0000000000..3654f46c1a
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/amqp_8_0/ProtocolOutputHandler_8_0.java
@@ -0,0 +1,278 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.client.protocol.amqp_8_0;
+
+import org.apache.qpid.framing.*;
+import org.apache.qpid.framing.amqp_8_0.*;
+import org.apache.qpid.client.protocol.ProtocolOutputHandler;
+import org.apache.qpid.client.protocol.AMQProtocolSession;
+import org.apache.qpid.client.state.listener.SpecificMethodFrameListener;
+import org.apache.qpid.AMQTimeoutException;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.protocol.AMQMethodEvent;
+import org.apache.qpid.protocol.AMQMethodListener;
+
+import org.apache.mina.common.ByteBuffer;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Collection;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+public class ProtocolOutputHandler_8_0 implements ProtocolOutputHandler
+{
+ private static final AMQMethodFactory METHOD_FACTORY = new AMQMethodFactory_8_0() ;
+
+
+ private static final Map<Class<? extends AMQMethodBody>, Class<? extends AMQMethodBody>> REQUSET_RESPONSE_METHODBODY_MAP =
+ new HashMap<Class<? extends AMQMethodBody>, Class<? extends AMQMethodBody>>();
+
+ static
+ {
+ // Basic Class
+ REQUSET_RESPONSE_METHODBODY_MAP.put(BasicCancelBody.class, BasicCancelOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(BasicConsumeBody.class, BasicConsumeOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(BasicQosBody.class, BasicQosOkBody.class);
+ // GET ???
+ REQUSET_RESPONSE_METHODBODY_MAP.put(BasicRecoverBody.class, BasicRecoverOkBody.class);
+
+ // Channel Class
+ REQUSET_RESPONSE_METHODBODY_MAP.put(ChannelCloseBody.class, ChannelCloseOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(ChannelFlowBody.class, ChannelFlowOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(ChannelOpenBody.class, ChannelOpenOkBody.class);
+
+ // Connection Class
+ REQUSET_RESPONSE_METHODBODY_MAP.put(ConnectionOpenBody.class, ConnectionOpenOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(ConnectionSecureBody.class, ConnectionSecureOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(ConnectionStartBody.class, ConnectionStartOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(ConnectionTuneBody.class, ConnectionTuneOkBody.class);
+
+ // Exchange Class
+ REQUSET_RESPONSE_METHODBODY_MAP.put(ExchangeBoundBody.class, ExchangeBoundOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(ExchangeDeclareBody.class, ExchangeDeclareOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(ExchangeDeleteBody.class, ExchangeDeleteOkBody.class);
+
+ // Queue Class
+ REQUSET_RESPONSE_METHODBODY_MAP.put(QueueBindBody.class, QueueBindOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(QueueDeclareBody.class, QueueDeclareOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(QueueDeleteBody.class, QueueDeleteOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(QueuePurgeBody.class, QueuePurgeOkBody.class);
+
+ // Tx Class
+ REQUSET_RESPONSE_METHODBODY_MAP.put(TxCommitBody.class, TxCommitOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(TxRollbackBody.class, TxRollbackOkBody.class);
+ REQUSET_RESPONSE_METHODBODY_MAP.put(TxSelectBody.class, TxSelectOkBody.class);
+
+ }
+
+
+
+
+
+ private final AMQProtocolSession _session;
+ private static final long DEFAULT_TIMEOUT = 30000;
+ private final CopyOnWriteArraySet<SpecificMethodFrameListener> _frameListeners =
+ new CopyOnWriteArraySet<SpecificMethodFrameListener>();
+
+ public ProtocolOutputHandler_8_0(AMQProtocolSession amqProtocolSession)
+ {
+ _session = amqProtocolSession;
+ }
+
+
+
+
+ private void writeFrame(AMQDataBlock frame)
+ {
+ _session.writeFrame(frame);
+ }
+
+ public void sendCommand(int channelId, AMQMethodBody command)
+ {
+ _session.writeFrame(new AMQFrame(channelId,command));
+ }
+
+ public AMQMethodBody sendCommandReceiveResponse(int channelId, AMQMethodBody command) throws AMQException
+ {
+ return sendCommandReceiveResponse(channelId, command, REQUSET_RESPONSE_METHODBODY_MAP.get(command.getClass()));
+ }
+
+ public AMQMethodBody sendCommandReceiveResponse(int channelId, AMQMethodBody command, long timeout) throws AMQException
+ {
+ return sendCommandReceiveResponse(channelId, command, REQUSET_RESPONSE_METHODBODY_MAP.get(command.getClass()), timeout);
+ }
+
+ public <T extends AMQMethodBody> T sendCommandReceiveResponse(int channelId, AMQMethodBody command, Class<T> responseClass, long timeout) throws AMQException
+ {
+ AMQFrame frame = new AMQFrame(channelId,command);
+ return writeCommandFrameAndWaitForReply(frame,
+ new SpecificMethodFrameListener<T>(channelId, responseClass), timeout);
+ }
+
+ private <T extends AMQMethodBody> T writeCommandFrameAndWaitForReply(AMQFrame frame, SpecificMethodFrameListener<T> listener, long timeout) throws AMQException
+ {
+ try
+ {
+ _frameListeners.add(listener);
+ _session.writeFrame(frame);
+
+ AMQMethodEvent<T> e = listener.blockForFrame(timeout);
+ return e.getMethod();
+ // When control resumes before this line, a reply will have been received
+ // that matches the criteria defined in the blocking listener
+ }
+ finally
+ {
+ // If we don't removeKey the listener then no-one will
+ _frameListeners.remove(listener);
+ }
+
+
+ }
+
+ public <T extends AMQMethodBody> T sendCommandReceiveResponse(int channelId, AMQMethodBody command, Class<T> responseClass) throws AMQException
+ {
+ return sendCommandReceiveResponse(channelId, command, responseClass, DEFAULT_TIMEOUT);
+ }
+
+ public AMQMethodFactory getAMQMethodFactory()
+ {
+ return METHOD_FACTORY;
+ }
+
+
+ public void publishMessage(int channelId, AMQShortString exchangeName, AMQShortString routingKey, boolean immediate, boolean mandatory, ByteBuffer payload, CommonContentHeaderProperties contentHeaderProperties, int ticket)
+ {
+ final int size = (payload != null) ? payload.limit() : 0;
+ BasicPublishBodyImpl publishBody = new BasicPublishBodyImpl(ticket, exchangeName, routingKey, mandatory, immediate);
+
+
+ final int contentBodyFrameCount = calculateContentBodyFrameCount(payload);
+ final AMQFrame[] frames = new AMQFrame[2 + contentBodyFrameCount];
+
+ if (payload != null)
+ {
+ createContentBodies(payload, frames, 2, channelId);
+ }
+
+
+
+ AMQFrame contentHeaderFrame =
+ ContentHeaderBody.createAMQFrame(channelId,
+ publishBody.CLASS_ID,
+ 0, // weight
+ contentHeaderProperties,
+ size);
+
+ frames[0] = new AMQFrame(channelId,publishBody);
+ frames[1] = contentHeaderFrame;
+ CompositeAMQDataBlock compositeFrame = new CompositeAMQDataBlock(frames);
+ writeFrame(compositeFrame);
+ }
+
+ public <M extends AMQMethodBody> boolean methodReceived(AMQMethodEvent<M> evt) throws AMQException
+ {
+ boolean wasAnyoneInterested = false;
+ if (!_frameListeners.isEmpty())
+ {
+ Iterator<SpecificMethodFrameListener> it = _frameListeners.iterator();
+ while (it.hasNext())
+ {
+ final SpecificMethodFrameListener listener = it.next();
+ wasAnyoneInterested = listener.methodReceived(evt) || wasAnyoneInterested;
+ }
+ }
+
+ return wasAnyoneInterested;
+ }
+
+ public void error(Exception e)
+ {
+ if (!_frameListeners.isEmpty())
+ {
+ final Iterator<SpecificMethodFrameListener> it = _frameListeners.iterator();
+ while (it.hasNext())
+ {
+ final SpecificMethodFrameListener ml = it.next();
+ ml.error(e);
+ }
+ }
+ }
+
+
+ /**
+ * Create content bodies. This will split a large message into numerous bodies depending on the negotiated
+ * maximum frame size.
+ *
+ * @param payload
+ * @param frames
+ * @param offset
+ * @param channelId @return the array of content bodies
+ */
+ private void createContentBodies(ByteBuffer payload, AMQFrame[] frames, int offset, int channelId)
+ {
+
+ if (frames.length == (offset + 1))
+ {
+ frames[offset] = ContentBody.createAMQFrame(channelId, new ContentBody(payload));
+ }
+ else
+ {
+
+ final long framePayloadMax = _session.getAMQConnection().getMaximumFrameSize() - 1;
+ long remaining = payload.remaining();
+ for (int i = offset; i < frames.length; i++)
+ {
+ payload.position((int) framePayloadMax * (i - offset));
+ int length = (remaining >= framePayloadMax) ? (int) framePayloadMax : (int) remaining;
+ payload.limit(payload.position() + length);
+ frames[i] = ContentBody.createAMQFrame(channelId, new ContentBody(payload.slice()));
+
+ remaining -= length;
+ }
+ }
+
+ }
+
+ private int calculateContentBodyFrameCount(ByteBuffer payload)
+ {
+ // we substract one from the total frame maximum size to account for the end of frame marker in a body frame
+ // (0xCE byte).
+ int frameCount;
+ if ((payload == null) || (payload.remaining() == 0))
+ {
+ frameCount = 0;
+ }
+ else
+ {
+ int dataLength = payload.remaining();
+ final long framePayloadMax = _session.getAMQConnection().getMaximumFrameSize() - 1;
+ int lastFrame = ((dataLength % framePayloadMax) > 0) ? 1 : 0;
+ frameCount = (int) (dataLength / framePayloadMax) + lastFrame;
+ }
+
+ return frameCount;
+ }
+
+
+
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java b/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java
index 825baf95d1..bba1c2701c 100644
--- a/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java
+++ b/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java
@@ -27,34 +27,20 @@ import java.util.concurrent.CopyOnWriteArraySet;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
-import org.apache.qpid.client.handler.BasicCancelOkMethodHandler;
-import org.apache.qpid.client.handler.BasicDeliverMethodHandler;
-import org.apache.qpid.client.handler.BasicReturnMethodHandler;
-import org.apache.qpid.client.handler.ChannelCloseMethodHandler;
-import org.apache.qpid.client.handler.ChannelCloseOkMethodHandler;
-import org.apache.qpid.client.handler.ChannelFlowOkMethodHandler;
-import org.apache.qpid.client.handler.ConnectionCloseMethodHandler;
-import org.apache.qpid.client.handler.ConnectionOpenOkMethodHandler;
-import org.apache.qpid.client.handler.ConnectionSecureMethodHandler;
-import org.apache.qpid.client.handler.ConnectionStartMethodHandler;
-import org.apache.qpid.client.handler.ConnectionTuneMethodHandler;
-import org.apache.qpid.client.handler.ExchangeBoundOkMethodHandler;
-import org.apache.qpid.client.handler.QueueDeleteOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.BasicCancelOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.BasicDeliverMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ChannelCloseOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ChannelFlowOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionOpenOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionTuneMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ExchangeBoundOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.QueueDeleteOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionCloseMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionSecureMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.BasicReturnMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.*;
import org.apache.qpid.client.protocol.AMQProtocolSession;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.framing.BasicCancelOkBody;
-import org.apache.qpid.framing.BasicDeliverBody;
-import org.apache.qpid.framing.BasicReturnBody;
-import org.apache.qpid.framing.ChannelCloseBody;
-import org.apache.qpid.framing.ChannelCloseOkBody;
-import org.apache.qpid.framing.ChannelFlowOkBody;
-import org.apache.qpid.framing.ConnectionCloseBody;
-import org.apache.qpid.framing.ConnectionOpenOkBody;
-import org.apache.qpid.framing.ConnectionSecureBody;
-import org.apache.qpid.framing.ConnectionStartBody;
-import org.apache.qpid.framing.ConnectionTuneBody;
-import org.apache.qpid.framing.ExchangeBoundOkBody;
-import org.apache.qpid.framing.QueueDeleteOkBody;
+import org.apache.qpid.framing.*;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
@@ -62,7 +48,7 @@ import org.apache.qpid.protocol.AMQMethodListener;
* The state manager is responsible for managing the state of the protocol session. <p/> For each AMQProtocolHandler
* there is a separate state manager.
*/
-public class AMQStateManager implements AMQMethodListener
+public class AMQStateManager
{
private static final Logger _logger = Logger.getLogger(AMQStateManager.class);
private AMQProtocolSession _protocolSession;
@@ -178,7 +164,7 @@ public class AMQStateManager implements AMQMethodListener
StateAwareMethodListener handler = findStateTransitionHandler(_currentState, evt.getMethod());
if (handler != null)
{
- handler.methodReceived(this, _protocolSession, evt);
+ handler.methodReceived(this, evt);
return true;
}
return false;
diff --git a/java/client/src/main/java/org/apache/qpid/client/state/StateAwareMethodListener.java b/java/client/src/main/java/org/apache/qpid/client/state/StateAwareMethodListener.java
index b3932533ce..9ddc50941b 100644
--- a/java/client/src/main/java/org/apache/qpid/client/state/StateAwareMethodListener.java
+++ b/java/client/src/main/java/org/apache/qpid/client/state/StateAwareMethodListener.java
@@ -31,6 +31,6 @@ import org.apache.qpid.protocol.AMQMethodEvent;
*/
public interface StateAwareMethodListener
{
- void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession,
- AMQMethodEvent evt) throws AMQException;
+ void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException;
+
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java b/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java
index 1c70ded62a..8a19a77776 100644
--- a/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java
+++ b/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java
@@ -22,13 +22,14 @@ package org.apache.qpid.client.state.listener;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.protocol.BlockingMethodFrameListener;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.framing.AMQMethodBody;
-public class SpecificMethodFrameListener extends BlockingMethodFrameListener
+public class SpecificMethodFrameListener<T extends AMQMethodBody> extends BlockingMethodFrameListener
{
private final Class _expectedClass;
- public SpecificMethodFrameListener(int channelId, Class expectedClass)
+ public SpecificMethodFrameListener(int channelId, Class<T> expectedClass)
{
super(channelId);
_expectedClass = expectedClass;
diff --git a/java/client/src/main/java/org/apache/qpid/client/transport/ITransportConnection.java b/java/client/src/main/java/org/apache/qpid/client/transport/ITransportConnection.java
index 7a24d6e15a..9877cd3c37 100644
--- a/java/client/src/main/java/org/apache/qpid/client/transport/ITransportConnection.java
+++ b/java/client/src/main/java/org/apache/qpid/client/transport/ITransportConnection.java
@@ -22,11 +22,11 @@ package org.apache.qpid.client.transport;
import java.io.IOException;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
+import org.apache.qpid.client.protocol.AMQProtocolHandlerImpl;
import org.apache.qpid.jms.BrokerDetails;
public interface ITransportConnection
{
- void connect(AMQProtocolHandler protocolHandler, BrokerDetails brokerDetail)
+ void connect(AMQProtocolHandlerImpl protocolHandler, BrokerDetails brokerDetail)
throws IOException;
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/transport/SocketTransportConnection.java b/java/client/src/main/java/org/apache/qpid/client/transport/SocketTransportConnection.java
index 04e7e40564..25d5a2cc1c 100644
--- a/java/client/src/main/java/org/apache/qpid/client/transport/SocketTransportConnection.java
+++ b/java/client/src/main/java/org/apache/qpid/client/transport/SocketTransportConnection.java
@@ -30,7 +30,7 @@ import org.apache.mina.common.IoConnector;
import org.apache.mina.common.SimpleByteBufferAllocator;
import org.apache.mina.transport.socket.nio.SocketConnectorConfig;
import org.apache.mina.transport.socket.nio.SocketSessionConfig;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
+import org.apache.qpid.client.protocol.AMQProtocolHandlerImpl;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.pool.ReadWriteThreadModel;
@@ -50,7 +50,7 @@ public class SocketTransportConnection implements ITransportConnection
_socketConnectorFactory = socketConnectorFactory;
}
- public void connect(AMQProtocolHandler protocolHandler, BrokerDetails brokerDetail)
+ public void connect(AMQProtocolHandlerImpl protocolHandler, BrokerDetails brokerDetail)
throws IOException
{
ByteBuffer.setUseDirectBuffers(Boolean.getBoolean("amqj.enableDirectBuffers"));
diff --git a/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java b/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java
index 104c4b43d0..4f8126f070 100644
--- a/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java
+++ b/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java
@@ -27,7 +27,7 @@ import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.IoServiceConfig;
import org.apache.mina.transport.vmpipe.VmPipeAddress;
import org.apache.mina.transport.vmpipe.VmPipeConnector;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
+import org.apache.qpid.client.protocol.AMQProtocolHandlerImpl;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.pool.PoolingFilter;
import org.apache.qpid.pool.ReferenceCountingExecutorService;
@@ -43,7 +43,7 @@ public class VmPipeTransportConnection implements ITransportConnection
_port = port;
}
- public void connect(AMQProtocolHandler protocolHandler, BrokerDetails brokerDetail) throws IOException
+ public void connect(AMQProtocolHandlerImpl protocolHandler, BrokerDetails brokerDetail) throws IOException
{
final VmPipeConnector ioConnector = new VmPipeConnector();
final IoServiceConfig cfg = ioConnector.getDefaultConfig();
diff --git a/java/client/src/old_test/java/org/apache/qpid/codec/BasicDeliverTest.java b/java/client/src/old_test/java/org/apache/qpid/codec/BasicDeliverTest.java
index 1db7e200bd..b3b26b660a 100644
--- a/java/client/src/old_test/java/org/apache/qpid/codec/BasicDeliverTest.java
+++ b/java/client/src/old_test/java/org/apache/qpid/codec/BasicDeliverTest.java
@@ -21,6 +21,8 @@
package org.apache.qpid.codec;
import org.apache.qpid.framing.*;
+import org.apache.qpid.framing.amqp_8_0.BasicDeliverBodyImpl;
+
import org.apache.mina.common.*;
import org.apache.mina.common.support.BaseIoSession;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
@@ -238,7 +240,7 @@ public class BasicDeliverTest
return new CompositeAMQDataBlock(frames);
}
- static AMQFrame wrapBody(AMQBody body)
+ static AMQFrame wrapBody(AMQBodyImpl body)
{
AMQFrame frame = new AMQFrame(1, body);
return frame;
@@ -264,13 +266,11 @@ public class BasicDeliverTest
return body;
}
- static BasicDeliverBody createBasicDeliverBody()
+ static BasicDeliverBodyImpl createBasicDeliverBody()
{
- BasicDeliverBody body = new BasicDeliverBody((byte) 8, (byte) 0,
- BasicDeliverBody.getClazz((byte) 8, (byte) 0),
- BasicDeliverBody.getMethod((byte) 8, (byte) 0),
- new AMQShortString("myConsumerTag"), 1,
- new AMQShortString("myExchange"), false,
+ BasicDeliverBodyImpl body = new BasicDeliverBodyImpl(
+ new AMQShortString("myConsumerTag"), 1,false,
+ new AMQShortString("myExchange"),
new AMQShortString("myRoutingKey"));
return body;
}
diff --git a/java/client/src/old_test/java/org/apache/qpid/framing/FieldTableTest.java b/java/client/src/old_test/java/org/apache/qpid/framing/FieldTableTest.java
index 955f82fab5..1358623bf8 100644
--- a/java/client/src/old_test/java/org/apache/qpid/framing/FieldTableTest.java
+++ b/java/client/src/old_test/java/org/apache/qpid/framing/FieldTableTest.java
@@ -118,8 +118,8 @@ public class FieldTableTest extends TestCase
//decode
buffer.flip();
- header = new ContentHeaderBody();
- header.populateFromBuffer(buffer, size);
+ header = new ContentHeaderBody(buffer, size);
+
return ((BasicContentHeaderProperties) header.properties).getHeaders();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java
index 5e45d1d537..a0c67b4e74 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java
@@ -46,13 +46,14 @@ public class ChannelCloseMethodHandlerNoCloseOk implements StateAwareMethodListe
return _handler;
}
- public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, AMQMethodEvent evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, AMQMethodEvent evt) throws AMQException
{
_logger.debug("ChannelClose method received");
+ final AMQProtocolSession protocolSession = stateManager.getProtocolSession();
ChannelCloseBody method = (ChannelCloseBody) evt.getMethod();
- AMQConstant errorCode = AMQConstant.getConstant(method.replyCode);
- AMQShortString reason = method.replyText;
+ AMQConstant errorCode = AMQConstant.getConstant(method.getReplyCode());
+ AMQShortString reason = method.getReplyText();
if (_logger.isDebugEnabled())
{
_logger.debug("Channel close reply code: " + errorCode + ", reason: " + reason);
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java
index 3431c56783..d6a4818ff7 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java
@@ -44,6 +44,9 @@ import org.apache.qpid.framing.ExchangeDeclareBody;
import org.apache.qpid.framing.ExchangeDeclareOkBody;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ChannelCloseOkBody;
+import org.apache.qpid.framing.amqp_8_0.ChannelCloseOkBodyImpl;
+import org.apache.qpid.framing.amqp_8_0.ExchangeDeclareBodyImpl;
+import org.apache.qpid.framing.amqp_8_0.ChannelOpenBodyImpl;
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQTimeoutException;
import org.apache.qpid.url.URLSyntaxException;
@@ -270,9 +273,7 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
private void sendClose(int channel)
{
- AMQFrame frame = ChannelCloseOkBody.createAMQFrame(channel,
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMajorVersion(),
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMinorVersion());
+ AMQFrame frame = new AMQFrame(channel, new ChannelCloseOkBodyImpl());
((AMQConnection) _connection).getProtocolHandler().writeFrame(frame);
}
@@ -332,37 +333,29 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con
private void declareExchange(int channelId, String _type, String _name, boolean nowait) throws AMQException
{
- AMQFrame exchangeDeclare = ExchangeDeclareBody.createAMQFrame(channelId,
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMajorVersion(),
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMinorVersion(),
- null, // arguments
- false, // autoDelete
- false, // durable
- new AMQShortString(_name), // exchange
- false, // internal
- nowait, // nowait
- true, // passive
- 0, // ticket
- new AMQShortString(_type)); // type
+ ExchangeDeclareBody exchangeDeclareBody =
+ ((AMQConnection) _connection).getProtocolOutputHandler().getAMQMethodFactory().createExchangeDeclare(new AMQShortString(_name),new AMQShortString(_type),0);
+// new ExchangeDeclareBodyImpl(0,new AMQShortString(_name),new AMQShortString(_type),true,false,false,false,nowait,null);
+
+ //AMQFrame exchangeDeclare = new AMQFrame(channelId, exchangeDeclareBody);
if (nowait)
{
- ((AMQConnection) _connection).getProtocolHandler().writeFrame(exchangeDeclare);
+ ((AMQConnection) _connection).getProtocolOutputHandler().sendCommand(channelId, exchangeDeclareBody);
+
}
else
{
- ((AMQConnection) _connection).getProtocolHandler().syncWrite(exchangeDeclare, ExchangeDeclareOkBody.class, SYNC_TIMEOUT);
+ ((AMQConnection) _connection).getProtocolOutputHandler().sendCommandReceiveResponse(channelId, exchangeDeclareBody, SYNC_TIMEOUT);
}
}
private void createChannel(int channelId) throws AMQException
{
- ((AMQConnection) _connection).getProtocolHandler().syncWrite(
- ChannelOpenBody.createAMQFrame(channelId,
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMajorVersion(),
- ((AMQConnection) _connection).getProtocolHandler().getProtocolMinorVersion(),
- null), // outOfBand
- ChannelOpenOkBody.class);
+
+ ChannelOpenBody openBody =
+ ((AMQConnection) _connection).getProtocolOutputHandler().getAMQMethodFactory().createChannelOpen();
+ ((AMQConnection) _connection).getProtocolOutputHandler().sendCommandReceiveResponse(channelId, openBody);
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/NoCloseOKStateManager.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/NoCloseOKStateManager.java
index d128f30727..29a8ecf5c1 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/NoCloseOKStateManager.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/NoCloseOKStateManager.java
@@ -22,18 +22,14 @@ package org.apache.qpid.test.unit.client.channelclose;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.AMQState;
-import org.apache.qpid.client.handler.ConnectionStartMethodHandler;
-import org.apache.qpid.client.handler.ConnectionCloseMethodHandler;
-import org.apache.qpid.client.handler.ConnectionTuneMethodHandler;
-import org.apache.qpid.client.handler.ConnectionSecureMethodHandler;
-import org.apache.qpid.client.handler.ConnectionOpenOkMethodHandler;
-import org.apache.qpid.client.handler.ChannelCloseOkMethodHandler;
-import org.apache.qpid.client.handler.BasicDeliverMethodHandler;
-import org.apache.qpid.client.handler.BasicReturnMethodHandler;
-import org.apache.qpid.client.handler.BasicCancelOkMethodHandler;
-import org.apache.qpid.client.handler.ChannelFlowOkMethodHandler;
-import org.apache.qpid.client.handler.QueueDeleteOkMethodHandler;
-import org.apache.qpid.client.handler.ExchangeBoundOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionTuneMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ChannelCloseOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.BasicDeliverMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ChannelFlowOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ExchangeBoundOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.BasicReturnMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionStartMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.*;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.framing.ConnectionStartBody;
import org.apache.qpid.framing.ConnectionCloseBody;
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java
index 4374329fb0..bf7ea4f50b 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java
@@ -24,7 +24,7 @@ import junit.framework.TestCase;
import org.apache.mina.common.IoSession;
import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
+import org.apache.qpid.client.protocol.AMQProtocolHandlerImpl;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.framing.AMQShortString;
@@ -36,7 +36,7 @@ public class AMQProtocolSessionTest extends TestCase
{
}
- public AMQProtSession(AMQProtocolHandler protocolHandler, IoSession protocolSession, AMQConnection connection)
+ public AMQProtSession(AMQProtocolHandlerImpl protocolHandler, IoSession protocolSession, AMQConnection connection)
{
super(protocolHandler,protocolSession,connection);
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQConnectionWaitException.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQConnectionWaitException.java
new file mode 100644
index 0000000000..4d2737edce
--- /dev/null
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQConnectionWaitException.java
@@ -0,0 +1,32 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.cluster;
+
+import org.apache.qpid.AMQException;
+
+public class AMQConnectionWaitException extends AMQException
+{
+ public AMQConnectionWaitException(String s, Throwable e)
+ {
+ super(s, e);
+
+ }
+}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQUnexpectedBodyTypeException.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQUnexpectedBodyTypeException.java
new file mode 100644
index 0000000000..3681fac750
--- /dev/null
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQUnexpectedBodyTypeException.java
@@ -0,0 +1,33 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.cluster;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQBodyImpl;
+
+public class AMQUnexpectedBodyTypeException extends AMQException
+{
+
+ public AMQUnexpectedBodyTypeException(Class<? extends AMQBodyImpl> expectedClass, AMQBodyImpl body)
+ {
+ super("Unexpected body type. Expected: " + expectedClass.getName() + "; got: " + body.getClass().getName());
+ }
+}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQUnexpectedFrameTypeException.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQUnexpectedFrameTypeException.java
new file mode 100644
index 0000000000..721da24d53
--- /dev/null
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/AMQUnexpectedFrameTypeException.java
@@ -0,0 +1,31 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.cluster;
+
+import org.apache.qpid.AMQException;
+
+public class AMQUnexpectedFrameTypeException extends AMQException
+{
+ public AMQUnexpectedFrameTypeException(String s)
+ {
+ super(s);
+ }
+}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/BlockingHandler.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/BlockingHandler.java
index 39508df566..aeded15eb8 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/BlockingHandler.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/BlockingHandler.java
@@ -20,26 +20,26 @@
*/
package org.apache.qpid.server.cluster;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
public class BlockingHandler implements ResponseHandler
{
private final Class _expected;
private boolean _completed;
- private AMQMethodBody _response;
+ private AMQMethodBodyImpl _response;
public BlockingHandler()
{
- this(AMQMethodBody.class);
+ this(AMQMethodBodyImpl.class);
}
- public BlockingHandler(Class<? extends AMQMethodBody> expected)
+ public BlockingHandler(Class<? extends AMQMethodBodyImpl> expected)
{
_expected = expected;
}
- public void responded(AMQMethodBody response)
+ public void responded(AMQMethodBodyImpl response)
{
if (_expected.isInstance(response))
{
@@ -74,7 +74,7 @@ public class BlockingHandler implements ResponseHandler
}
}
- AMQMethodBody getResponse()
+ AMQMethodBodyImpl getResponse()
{
return _response;
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/Broker.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/Broker.java
index 7e2cf6da83..c560a1e20c 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/Broker.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/Broker.java
@@ -22,7 +22,7 @@ package org.apache.qpid.server.cluster;
import org.apache.qpid.AMQException;
import org.apache.qpid.server.cluster.util.LogMessage;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.log4j.Logger;
import java.io.IOException;
@@ -88,7 +88,7 @@ abstract class Broker extends SimpleMemberHandle implements Member
* @param response the response received
* @return true if the response matched an outstanding request
*/
- protected synchronized boolean handleResponse(int channel, AMQMethodBody response)
+ protected synchronized boolean handleResponse(int channel, AMQMethodBodyImpl response)
{
ResponseHandler request = _requests.get(channel);
if (request == null)
@@ -174,7 +174,7 @@ abstract class Broker extends SimpleMemberHandle implements Member
/**
* Start connection process, including replay
*/
- abstract void connectAsynch(Iterable<AMQMethodBody> msgs);
+ abstract void connectAsynch(Iterable<AMQMethodBodyImpl> msgs);
/**
* Replay messages to the remote peer this instance represents. These messages
@@ -182,7 +182,7 @@ abstract class Broker extends SimpleMemberHandle implements Member
*
* @param msgs
*/
- abstract void replay(Iterable<AMQMethodBody> msgs);
+ abstract void replay(Iterable<AMQMethodBodyImpl> msgs);
/**
* establish connection, handling redirect if required...
@@ -200,7 +200,7 @@ abstract class Broker extends SimpleMemberHandle implements Member
this.channel = channel;
}
- public void responded(AMQMethodBody response)
+ public void responded(AMQMethodBodyImpl response)
{
request.responseReceived(Broker.this, response);
_requests.remove(channel);
@@ -228,7 +228,7 @@ abstract class Broker extends SimpleMemberHandle implements Member
this.channel = channel;
}
- public void responded(AMQMethodBody response)
+ public void responded(AMQMethodBodyImpl response)
{
handler.responded(response);
_requests.remove(channel);
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/BrokerGroup.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/BrokerGroup.java
index 755a341607..03de4fbbb7 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/BrokerGroup.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/BrokerGroup.java
@@ -24,7 +24,7 @@ import org.apache.log4j.Logger;
import org.apache.qpid.server.cluster.replay.ReplayManager;
import org.apache.qpid.server.cluster.util.LogMessage;
import org.apache.qpid.server.cluster.util.InvokeMultiple;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import java.io.IOException;
import java.util.ArrayList;
@@ -225,7 +225,7 @@ class BrokerGroup
if (create)
{
Broker b = _factory.create(handle);
- List<AMQMethodBody> msgs = _replayMgr.replay(isLeader(_local));
+ List<AMQMethodBodyImpl> msgs = _replayMgr.replay(isLeader(_local));
_logger.info(new LogMessage("Replaying {0} from {1} to {2}", msgs, _local, b));
b.connectAsynch(msgs);
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClientAdapter.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClientAdapter.java
index 1b4a3e8327..e3377d3ed1 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClientAdapter.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClientAdapter.java
@@ -26,7 +26,7 @@ import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.client.protocol.AMQProtocolSession;
import org.apache.qpid.client.state.AMQStateManager;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
/**
* Hack to assist with reuse of the client handlers for connection setup in
@@ -49,7 +49,7 @@ class ClientAdapter implements MethodHandler
_stateMgr = stateMgr;
}
- public void handle(int channel, AMQMethodBody method) throws AMQException
+ public void handle(int channel, AMQMethodBodyImpl method) throws AMQException
{
AMQMethodEvent evt = new AMQMethodEvent(channel, method);
_stateMgr.methodReceived(evt);
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClientHandlerRegistry.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClientHandlerRegistry.java
index 5300912716..fb9e1fa70c 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClientHandlerRegistry.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClientHandlerRegistry.java
@@ -20,11 +20,11 @@
*/
package org.apache.qpid.server.cluster;
-import org.apache.qpid.client.handler.ConnectionCloseMethodHandler;
-import org.apache.qpid.client.handler.ConnectionOpenOkMethodHandler;
-import org.apache.qpid.client.handler.ConnectionSecureMethodHandler;
-import org.apache.qpid.client.handler.ConnectionStartMethodHandler;
-import org.apache.qpid.client.handler.ConnectionTuneMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionCloseMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionOpenOkMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionSecureMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionTuneMethodHandler;
+import org.apache.qpid.client.handler.amqp_8_0.ConnectionStartMethodHandler;
import org.apache.qpid.client.state.AMQState;
import org.apache.qpid.client.state.AMQStateManager;
import org.apache.qpid.client.state.IllegalStateTransitionException;
@@ -78,14 +78,14 @@ public class ClientHandlerRegistry extends AMQStateManager
return registry;
}
- protected StateAwareMethodListener findStateTransitionHandler(AMQState state, AMQMethodBody frame) throws IllegalStateTransitionException
+ protected StateAwareMethodListener findStateTransitionHandler(AMQState state, AMQMethodBodyImpl frame) throws IllegalStateTransitionException
{
ClientRegistry registry = _handlers.get(state);
return registry == null ? null : registry.getHandler(frame);
}
- <A extends Class<AMQMethodBody>> void addHandlers(Class type, StateAwareMethodListener handler, AMQState... states)
+ <A extends Class<AMQMethodBodyImpl>> void addHandlers(Class type, StateAwareMethodListener handler, AMQState... states)
{
for (AMQState state : states)
{
@@ -93,7 +93,7 @@ public class ClientHandlerRegistry extends AMQStateManager
}
}
- <A extends Class<AMQMethodBody>> void addHandler(Class type, StateAwareMethodListener handler, AMQState state)
+ <A extends Class<AMQMethodBodyImpl>> void addHandler(Class type, StateAwareMethodListener handler, AMQState state)
{
ClientRegistry registry = _handlers.get(state);
if (registry == null)
@@ -106,15 +106,15 @@ public class ClientHandlerRegistry extends AMQStateManager
static class ClientRegistry
{
- private final Map<Class<? extends AMQMethodBody>, StateAwareMethodListener> registry
- = new HashMap<Class<? extends AMQMethodBody>, StateAwareMethodListener>();
+ private final Map<Class<? extends AMQMethodBodyImpl>, StateAwareMethodListener> registry
+ = new HashMap<Class<? extends AMQMethodBodyImpl>, StateAwareMethodListener>();
- <A extends Class<AMQMethodBody>> void add(A type, StateAwareMethodListener handler)
+ <A extends Class<AMQMethodBodyImpl>> void add(A type, StateAwareMethodListener handler)
{
registry.put(type, handler);
}
- StateAwareMethodListener getHandler(AMQMethodBody frame)
+ StateAwareMethodListener getHandler(AMQMethodBodyImpl frame)
{
return registry.get(frame.getClass());
}
@@ -122,9 +122,9 @@ public class ClientHandlerRegistry extends AMQStateManager
class ConnectionTuneHandler extends ConnectionTuneMethodHandler
{
- protected AMQFrame createConnectionOpenFrame(int channel, AMQShortString path, AMQShortString capabilities, boolean insist, byte major, byte minor)
+ protected AMQFrame createConnectionOpenBody(int channel, AMQShortString path, AMQShortString capabilities, boolean insist, byte major, byte minor)
{
- return super.createConnectionOpenFrame(channel, path, new AMQShortString(ClusterCapability.add(capabilities, _identity)), insist, major, minor);
+ return super.createConnectionOpenBody(channel, path, new AMQShortString(ClusterCapability.add(capabilities, _identity)), insist, major, minor);
}
}
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClusteredProtocolHandler.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClusteredProtocolHandler.java
index ee5aa48db9..4e0a367f40 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClusteredProtocolHandler.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/ClusteredProtocolHandler.java
@@ -24,17 +24,14 @@ import org.apache.log4j.Logger;
import org.apache.mina.common.IoSession;
import org.apache.qpid.AMQException;
import org.apache.qpid.codec.AMQCodecFactory;
-import org.apache.qpid.framing.AMQBody;
import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.ConnectionOpenBody;
import org.apache.qpid.framing.ConnectionSecureOkBody;
import org.apache.qpid.framing.ConnectionStartOkBody;
import org.apache.qpid.framing.ConnectionTuneOkBody;
import org.apache.qpid.framing.ClusterMembershipBody;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.server.protocol.AMQPFastProtocolHandler;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.cluster.util.LogMessage;
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/DefaultGroupManager.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/DefaultGroupManager.java
index 2f473b63fb..149378a626 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/DefaultGroupManager.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/DefaultGroupManager.java
@@ -230,7 +230,7 @@ public class DefaultGroupManager implements GroupManager, MemberFailureListener,
//connect to the host and port specified:
Broker prospect = connectToProspect(member);
announceMembership();
- List<AMQMethodBody> msgs = _replayMgr.replay(true);
+ List<AMQMethodBodyImpl> msgs = _replayMgr.replay(true);
_logger.info(new LogMessage("Replaying {0} from leader to {1}", msgs, prospect));
prospect.replay(msgs);
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/GroupRequest.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/GroupRequest.java
index 8ab7856e87..55b51bf736 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/GroupRequest.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/GroupRequest.java
@@ -21,7 +21,7 @@
package org.apache.qpid.server.cluster;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import java.util.ArrayList;
import java.util.HashMap;
@@ -35,7 +35,7 @@ import java.util.Map;
*/
class GroupRequest
{
- private final Map<Member, AMQMethodBody> _responses = new HashMap<Member, AMQMethodBody>();
+ private final Map<Member, AMQMethodBodyImpl> _responses = new HashMap<Member, AMQMethodBodyImpl>();
private final List<Member> _brokers = new ArrayList<Member>();
private boolean _sent;
@@ -62,7 +62,7 @@ class GroupRequest
return checkCompletion();
}
- public boolean responseReceived(Member broker, AMQMethodBody response)
+ public boolean responseReceived(Member broker, AMQMethodBodyImpl response)
{
_responses.put(broker, response);
return checkCompletion();
@@ -90,9 +90,9 @@ class GroupRequest
return true;
}
- List<AMQMethodBody> getResults()
+ List<AMQMethodBodyImpl> getResults()
{
- List<AMQMethodBody> results = new ArrayList<AMQMethodBody>(_brokers.size());
+ List<AMQMethodBodyImpl> results = new ArrayList<AMQMethodBodyImpl>(_brokers.size());
for (Member b : _brokers)
{
results.add(_responses.get(b));
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/GroupResponseHandler.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/GroupResponseHandler.java
index d2e9de2f39..d394651c26 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/GroupResponseHandler.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/GroupResponseHandler.java
@@ -20,12 +20,12 @@
*/
package org.apache.qpid.server.cluster;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import java.util.List;
public interface GroupResponseHandler
{
//Note: this implies that the response to a group request will always be a method body...
- public void response(List<AMQMethodBody> responses, List<Member> members);
+ public void response(List<AMQMethodBodyImpl> responses, List<Member> members);
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/MethodHandler.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/MethodHandler.java
index a83f034021..d3f2b9201c 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/MethodHandler.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/MethodHandler.java
@@ -21,9 +21,9 @@
package org.apache.qpid.server.cluster;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
interface MethodHandler
{
- public void handle(int channel, AMQMethodBody method) throws AMQException;
+ public void handle(int channel, AMQMethodBodyImpl method) throws AMQException;
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/MethodHandlerRegistry.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/MethodHandlerRegistry.java
index 748a660bb8..33ec771d6a 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/MethodHandlerRegistry.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/MethodHandlerRegistry.java
@@ -20,7 +20,7 @@
*/
package org.apache.qpid.server.cluster;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.server.state.StateAwareMethodListener;
import java.util.HashMap;
@@ -28,16 +28,16 @@ import java.util.Map;
public class MethodHandlerRegistry
{
- private final Map<Class<? extends AMQMethodBody>, StateAwareMethodListener<? extends AMQMethodBody>> registry =
- new HashMap<Class<? extends AMQMethodBody>, StateAwareMethodListener<? extends AMQMethodBody>>();
+ private final Map<Class<? extends AMQMethodBodyImpl>, StateAwareMethodListener<? extends AMQMethodBodyImpl>> registry =
+ new HashMap<Class<? extends AMQMethodBodyImpl>, StateAwareMethodListener<? extends AMQMethodBodyImpl>>();
- public <A extends AMQMethodBody, B extends Class<A>> MethodHandlerRegistry addHandler(B type, StateAwareMethodListener<A> handler)
+ public <A extends AMQMethodBodyImpl, B extends Class<A>> MethodHandlerRegistry addHandler(B type, StateAwareMethodListener<A> handler)
{
registry.put(type, handler);
return this;
}
- public <B extends AMQMethodBody> StateAwareMethodListener<B> getHandler(B frame)
+ public <B extends AMQMethodBodyImpl> StateAwareMethodListener<B> getHandler(B frame)
{
return (StateAwareMethodListener<B>) registry.get(frame.getClass());
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/MinaBrokerProxy.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/MinaBrokerProxy.java
index 401a54444b..1f736ad94c 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/MinaBrokerProxy.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/MinaBrokerProxy.java
@@ -33,13 +33,13 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.server.cluster.util.LogMessage;
import org.apache.qpid.client.state.AMQState;
import org.apache.qpid.codec.AMQCodecFactory;
-import org.apache.qpid.framing.AMQBody;
+import org.apache.qpid.framing.AMQBodyImpl;
import org.apache.qpid.framing.AMQDataBlock;
import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.framing.ConnectionRedirectBody;
import org.apache.qpid.framing.ProtocolInitiation;
-import org.apache.qpid.framing.ProtocolVersionList;
+import org.apache.qpid.framing.ProtocolVersion;
import java.io.IOException;
import java.net.InetSocketAddress;
@@ -57,7 +57,7 @@ public class MinaBrokerProxy extends Broker implements MethodHandler
private final MemberHandle _local;
private IoSession _session;
private MethodHandler _handler;
- private Iterable<AMQMethodBody> _replay;
+ private Iterable<AMQMethodBodyImpl> _replay;
MinaBrokerProxy(String host, int port, MemberHandle local)
{
@@ -106,13 +106,13 @@ public class MinaBrokerProxy extends Broker implements MethodHandler
return _connectionMonitor.waitUntilOpen();
}
- void connectAsynch(Iterable<AMQMethodBody> msgs)
+ void connectAsynch(Iterable<AMQMethodBodyImpl> msgs)
{
_replay = msgs;
connectImpl();
}
- void replay(Iterable<AMQMethodBody> msgs)
+ void replay(Iterable<AMQMethodBodyImpl> msgs)
{
_replay = msgs;
if(_connectionMonitor.isOpened())
@@ -138,7 +138,7 @@ public class MinaBrokerProxy extends Broker implements MethodHandler
}
}
- public void send(AMQDataBlock data) throws AMQException
+ public void send(AMQDataBlock data) throws AMQConnectionWaitException
{
if (_session == null)
{
@@ -146,9 +146,9 @@ public class MinaBrokerProxy extends Broker implements MethodHandler
{
_connectionMonitor.waitUntilOpen();
}
- catch (Exception e)
+ catch (InterruptedException e)
{
- throw new AMQException("Failed to send " + data + ": " + e, e);
+ throw new AMQConnectionWaitException("Failed to send " + data + ": " + e, e);
}
}
_session.write(data);
@@ -158,14 +158,14 @@ public class MinaBrokerProxy extends Broker implements MethodHandler
{
if(_replay != null)
{
- for(AMQMethodBody b : _replay)
+ for(AMQMethodBodyImpl b : _replay)
{
_session.write(new AMQFrame(0, b));
}
}
}
- public void handle(int channel, AMQMethodBody method) throws AMQException
+ public void handle(int channel, AMQMethodBodyImpl method) throws AMQException
{
_logger.info(new LogMessage("Handling method: {0} for channel {1}", method, channel));
if (!handleResponse(channel, method))
@@ -174,7 +174,7 @@ public class MinaBrokerProxy extends Broker implements MethodHandler
}
}
- private void handleMethod(int channel, AMQMethodBody method) throws AMQException
+ private void handleMethod(int channel, AMQMethodBodyImpl method) throws AMQException
{
if (method instanceof ConnectionRedirectBody)
{
@@ -200,14 +200,14 @@ public class MinaBrokerProxy extends Broker implements MethodHandler
private void handleFrame(AMQFrame frame) throws AMQException
{
- AMQBody body = frame.getBodyFrame();
- if (body instanceof AMQMethodBody)
+ AMQBodyImpl body = frame.getBodyFrame();
+ if (body instanceof AMQMethodBodyImpl)
{
- handleMethod(frame.getChannel(), (AMQMethodBody) body);
+ handleMethod(frame.getChannel(), (AMQMethodBodyImpl) body);
}
else
{
- throw new AMQException("Client only expects method body, got: " + body);
+ throw new AMQUnexpectedBodyTypeException(AMQMethodBodyImpl.class, body);
}
}
@@ -216,7 +216,7 @@ public class MinaBrokerProxy extends Broker implements MethodHandler
return "MinaBrokerProxy[" + (_session == null ? super.toString() : _session.getRemoteAddress()) + "]";
}
- private class MinaBinding extends IoHandlerAdapter implements ProtocolVersionList
+ private class MinaBinding extends IoHandlerAdapter
{
public void sessionCreated(IoSession session) throws Exception
{
@@ -228,8 +228,8 @@ public class MinaBrokerProxy extends Broker implements MethodHandler
/* Find last protocol version in protocol version list. Make sure last protocol version
listed in the build file (build-module.xml) is the latest version which will be used
here. */
- int i = pv.length - 1;
- session.write(new ProtocolInitiation(pv[i][PROTOCOL_MAJOR], pv[i][PROTOCOL_MINOR]));
+
+ session.write(new ProtocolInitiation(ProtocolVersion.getLatestSupportedVersion()));
}
public void sessionOpened(IoSession session) throws Exception
@@ -260,7 +260,7 @@ public class MinaBrokerProxy extends Broker implements MethodHandler
}
else
{
- throw new AMQException("Received message of unrecognised type: " + object);
+ throw new AMQUnexpectedFrameTypeException("Received message of unrecognised type: " + object);
}
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/ResponseHandler.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/ResponseHandler.java
index fe76ca6505..81341eb445 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/ResponseHandler.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/ResponseHandler.java
@@ -20,11 +20,11 @@
*/
package org.apache.qpid.server.cluster;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
public interface ResponseHandler
{
- public void responded(AMQMethodBody response);
+ public void responded(AMQMethodBodyImpl response);
public void removed();
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/ServerHandlerRegistry.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/ServerHandlerRegistry.java
index 03b0dc7f2e..ac0373cc0d 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/ServerHandlerRegistry.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/ServerHandlerRegistry.java
@@ -21,14 +21,12 @@
package org.apache.qpid.server.cluster;
import org.apache.log4j.Logger;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.server.state.AMQState;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.state.IllegalStateTransitionException;
import org.apache.qpid.server.state.StateAwareMethodListener;
import org.apache.qpid.server.cluster.util.LogMessage;
-import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
@@ -74,7 +72,7 @@ class ServerHandlerRegistry extends AMQStateManager
}
}
- protected <B extends AMQMethodBody> StateAwareMethodListener<B> findStateTransitionHandler(AMQState state, B frame) throws IllegalStateTransitionException
+ protected <B extends AMQMethodBodyImpl> StateAwareMethodListener<B> findStateTransitionHandler(AMQState state, B frame) throws IllegalStateTransitionException
{
MethodHandlerRegistry registry = _handlers.get(state);
StateAwareMethodListener<B> handler = (registry == null) ? null : registry.getHandler(frame);
@@ -85,7 +83,7 @@ class ServerHandlerRegistry extends AMQStateManager
return handler;
}
- <A extends AMQMethodBody, B extends Class<A>> void addHandler(AMQState state, B type, StateAwareMethodListener<A> handler)
+ <A extends AMQMethodBodyImpl, B extends Class<A>> void addHandler(AMQState state, B type, StateAwareMethodListener<A> handler)
{
MethodHandlerRegistry registry = _handlers.get(state);
if (registry == null)
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/SimpleBodySendable.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/SimpleBodySendable.java
index f7c40c60b3..bae930b341 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/SimpleBodySendable.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/SimpleBodySendable.java
@@ -18,16 +18,16 @@
package org.apache.qpid.server.cluster;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQBody;
+import org.apache.qpid.framing.AMQBodyImpl;
import org.apache.qpid.framing.AMQFrame;
/**
*/
public class SimpleBodySendable implements Sendable
{
- private final AMQBody _body;
+ private final AMQBodyImpl _body;
- public SimpleBodySendable(AMQBody body)
+ public SimpleBodySendable(AMQBodyImpl body)
{
_body = body;
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ChainedClusterMethodHandler.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ChainedClusterMethodHandler.java
index 86710e8a31..85955ab775 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ChainedClusterMethodHandler.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ChainedClusterMethodHandler.java
@@ -21,18 +21,14 @@
package org.apache.qpid.server.cluster.handler;
import org.apache.qpid.server.state.AMQStateManager;
-import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import java.util.List;
import java.util.ArrayList;
-public class ChainedClusterMethodHandler <A extends AMQMethodBody> extends ClusterMethodHandler<A>
+public class ChainedClusterMethodHandler <A extends AMQMethodBodyImpl> extends ClusterMethodHandler<A>
{
private final List<ClusterMethodHandler<A>> _handlers;
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ClusterMethodHandler.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ClusterMethodHandler.java
index faab99b0f6..5c7e1d7ff7 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ClusterMethodHandler.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ClusterMethodHandler.java
@@ -20,17 +20,15 @@
*/
package org.apache.qpid.server.cluster.handler;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.server.state.StateAwareMethodListener;
import org.apache.qpid.server.state.AMQStateManager;
-import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.cluster.ClusteredProtocolSession;
import org.apache.qpid.AMQException;
-public abstract class ClusterMethodHandler<A extends AMQMethodBody> implements StateAwareMethodListener<A>
+public abstract class ClusterMethodHandler<A extends AMQMethodBodyImpl> implements StateAwareMethodListener<A>
{
public final void methodReceived(AMQStateManager stateMgr, AMQMethodEvent<A> evt) throws AMQException
{
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ClusterMethodHandlerFactory.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ClusterMethodHandlerFactory.java
index e7509da32a..313ba6d304 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ClusterMethodHandlerFactory.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ClusterMethodHandlerFactory.java
@@ -222,17 +222,17 @@ public class ClusterMethodHandlerFactory implements MethodHandlerFactory
}
}
- private <B extends AMQMethodBody> ReplicatingHandler<B> replicated(StateAwareMethodListener<B> handler)
+ private <B extends AMQMethodBodyImpl> ReplicatingHandler<B> replicated(StateAwareMethodListener<B> handler)
{
return new ReplicatingHandler<B>(_groupMgr, handler);
}
- private <B extends AMQMethodBody> StateAwareMethodListener<B> alternate(StateAwareMethodListener<B> peer, StateAwareMethodListener<B> client)
+ private <B extends AMQMethodBodyImpl> StateAwareMethodListener<B> alternate(StateAwareMethodListener<B> peer, StateAwareMethodListener<B> client)
{
return new PeerHandler<B>(peer, client);
}
- private <B extends AMQMethodBody> StateAwareMethodListener<B> chain(ClusterMethodHandler<B>... h)
+ private <B extends AMQMethodBodyImpl> StateAwareMethodListener<B> chain(ClusterMethodHandler<B>... h)
{
return new ChainedClusterMethodHandler<B>(h);
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ExtendedHandler.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ExtendedHandler.java
index a2f62f714b..a9cb096d33 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ExtendedHandler.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ExtendedHandler.java
@@ -21,15 +21,12 @@
package org.apache.qpid.server.cluster.handler;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
-import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.state.StateAwareMethodListener;
-class ExtendedHandler<A extends AMQMethodBody> implements StateAwareMethodListener<A>
+class ExtendedHandler<A extends AMQMethodBodyImpl> implements StateAwareMethodListener<A>
{
private final StateAwareMethodListener<A> _base;
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/NullListener.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/NullListener.java
index 8b0bb4b127..a0b95344ee 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/NullListener.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/NullListener.java
@@ -21,15 +21,12 @@
package org.apache.qpid.server.cluster.handler;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
-import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.state.StateAwareMethodListener;
-public class NullListener<T extends AMQMethodBody> implements StateAwareMethodListener<T>
+public class NullListener<T extends AMQMethodBodyImpl> implements StateAwareMethodListener<T>
{
public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<T> evt) throws AMQException
{
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/PeerHandler.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/PeerHandler.java
index 447e51ccd9..50f25bd7fe 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/PeerHandler.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/PeerHandler.java
@@ -21,12 +21,8 @@
package org.apache.qpid.server.cluster.handler;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.server.cluster.ClusteredProtocolSession;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
-import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.state.StateAwareMethodListener;
@@ -36,7 +32,7 @@ import org.apache.qpid.server.state.StateAwareMethodListener;
* application).
*
*/
-public class PeerHandler<A extends AMQMethodBody> extends ClusterMethodHandler<A>
+public class PeerHandler<A extends AMQMethodBodyImpl> extends ClusterMethodHandler<A>
{
private final StateAwareMethodListener<A> _peer;
private final StateAwareMethodListener<A> _client;
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ReplicatingHandler.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ReplicatingHandler.java
index 888fa4e426..f7b9eb2b21 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ReplicatingHandler.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/ReplicatingHandler.java
@@ -22,7 +22,7 @@ package org.apache.qpid.server.cluster.handler;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.server.cluster.util.LogMessage;
import org.apache.qpid.server.cluster.*;
import org.apache.qpid.server.cluster.policy.StandardPolicies;
@@ -41,7 +41,7 @@ import java.util.List;
* processed locally after 'completion' of this broadcast.
*
*/
-class ReplicatingHandler<A extends AMQMethodBody> extends ClusterMethodHandler<A> implements StandardPolicies
+class ReplicatingHandler<A extends AMQMethodBodyImpl> extends ClusterMethodHandler<A> implements StandardPolicies
{
protected static final Logger _logger = Logger.getLogger(ReplicatingHandler.class);
@@ -109,7 +109,7 @@ class ReplicatingHandler<A extends AMQMethodBody> extends ClusterMethodHandler<A
_evt = evt;
}
- public void response(List<AMQMethodBody> responses, List<Member> members)
+ public void response(List<AMQMethodBodyImpl> responses, List<Member> members)
{
try
{
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/WrappedListener.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/WrappedListener.java
index 8b0c638d63..9ad8b52c83 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/WrappedListener.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/WrappedListener.java
@@ -21,15 +21,12 @@
package org.apache.qpid.server.cluster.handler;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.protocol.AMQMethodEvent;
-import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.state.StateAwareMethodListener;
-public class WrappedListener<T extends AMQMethodBody> implements StateAwareMethodListener<T>
+public class WrappedListener<T extends AMQMethodBodyImpl> implements StateAwareMethodListener<T>
{
private final StateAwareMethodListener<T> _primary;
private final StateAwareMethodListener _post;
@@ -49,7 +46,7 @@ public class WrappedListener<T extends AMQMethodBody> implements StateAwareMetho
_post.methodReceived(stateMgr, evt);
}
- private static <T extends AMQMethodBody> StateAwareMethodListener<T> check(StateAwareMethodListener<T> in)
+ private static <T extends AMQMethodBodyImpl> StateAwareMethodListener<T> check(StateAwareMethodListener<T> in)
{
return in == null ? new NullListener<T>() : in;
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/WrappingMethodHandlerFactory.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/WrappingMethodHandlerFactory.java
index 5ec3c9660a..47cec07546 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/WrappingMethodHandlerFactory.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/handler/WrappingMethodHandlerFactory.java
@@ -20,7 +20,7 @@
*/
package org.apache.qpid.server.cluster.handler;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.server.cluster.MethodHandlerFactory;
import org.apache.qpid.server.cluster.MethodHandlerRegistry;
import org.apache.qpid.server.state.AMQState;
@@ -66,12 +66,12 @@ public abstract class WrappingMethodHandlerFactory implements MethodHandlerFacto
return registry;
}
- private <A extends AMQMethodBody, B extends Class<A>> void wrap(MethodHandlerRegistry r, B type, A frame)
+ private <A extends AMQMethodBodyImpl, B extends Class<A>> void wrap(MethodHandlerRegistry r, B type, A frame)
{
r.addHandler(type, new WrappedListener<A>(r.getHandler(frame), _pre, _post));
}
- protected static class FrameDescriptor<A extends AMQMethodBody, B extends Class<A>>
+ protected static class FrameDescriptor<A extends AMQMethodBodyImpl, B extends Class<A>>
{
protected final A instance;
protected final B type;
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ChainedMethodRecorder.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ChainedMethodRecorder.java
index 3664be58bc..22e95308d7 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ChainedMethodRecorder.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ChainedMethodRecorder.java
@@ -20,9 +20,9 @@
*/
package org.apache.qpid.server.cluster.replay;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
-abstract class ChainedMethodRecorder <T extends AMQMethodBody> implements MethodRecorder<T>
+abstract class ChainedMethodRecorder <T extends AMQMethodBodyImpl> implements MethodRecorder<T>
{
private final MethodRecorder<T> _recorder;
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ConsumerCounts.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ConsumerCounts.java
index 5a433b869b..d3bf72b4fd 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ConsumerCounts.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ConsumerCounts.java
@@ -20,7 +20,7 @@
*/
package org.apache.qpid.server.cluster.replay;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.framing.BasicConsumeBody;
import org.apache.qpid.framing.AMQShortString;
@@ -48,7 +48,7 @@ class ConsumerCounts
return count == null ? 0 : count;
}
- synchronized void replay(List<AMQMethodBody> messages)
+ synchronized void replay(List<AMQMethodBodyImpl> messages)
{
for(AMQShortString queue : _counts.keySet())
{
@@ -72,7 +72,7 @@ class ConsumerCounts
}
}
- private void replay(BasicConsumeBody msg, List<AMQMethodBody> messages)
+ private void replay(BasicConsumeBody msg, List<AMQMethodBodyImpl> messages)
{
int count = _counts.get(msg.queue);
for(int i = 0; i < count; i++)
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/MethodRecorder.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/MethodRecorder.java
index e45810438e..421da7e9ea 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/MethodRecorder.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/MethodRecorder.java
@@ -20,13 +20,13 @@
*/
package org.apache.qpid.server.cluster.replay;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
/**
* Abstraction through which a method can be recorded for replay
*
*/
-interface MethodRecorder<T extends AMQMethodBody>
+interface MethodRecorder<T extends AMQMethodBodyImpl>
{
public void record(T method);
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/RecordingMethodHandlerFactory.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/RecordingMethodHandlerFactory.java
index 4d3fe1dbed..4467be4052 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/RecordingMethodHandlerFactory.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/RecordingMethodHandlerFactory.java
@@ -20,8 +20,6 @@
*/
package org.apache.qpid.server.cluster.replay;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQMethodBody;
import org.apache.qpid.framing.BasicCancelBody;
import org.apache.qpid.framing.BasicConsumeBody;
import org.apache.qpid.framing.ExchangeDeclareBody;
@@ -30,15 +28,8 @@ import org.apache.qpid.framing.QueueBindBody;
import org.apache.qpid.framing.QueueDeclareBody;
import org.apache.qpid.framing.QueueDeleteBody;
import org.apache.qpid.server.cluster.MethodHandlerFactory;
-import org.apache.qpid.server.cluster.MethodHandlerRegistry;
import org.apache.qpid.server.cluster.handler.WrappingMethodHandlerFactory;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.protocol.AMQMethodEvent;
-import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.state.AMQState;
-import org.apache.qpid.server.state.AMQStateManager;
-import org.apache.qpid.server.state.StateAwareMethodListener;
import java.util.Arrays;
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ReplayManager.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ReplayManager.java
index 898cb80cb3..799a88b265 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ReplayManager.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ReplayManager.java
@@ -20,9 +20,7 @@
*/
package org.apache.qpid.server.cluster.replay;
-import org.apache.qpid.server.cluster.Sendable;
-import org.apache.qpid.framing.AMQDataBlock;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import java.util.List;
@@ -33,5 +31,5 @@ import java.util.List;
*/
public interface ReplayManager
{
- public List<AMQMethodBody> replay(boolean isLeader);
+ public List<AMQMethodBodyImpl> replay(boolean isLeader);
}
diff --git a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ReplayStore.java b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ReplayStore.java
index d7bbb1c36b..5dfb02c7c5 100644
--- a/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ReplayStore.java
+++ b/java/cluster/src/main/java/org/apache/qpid/server/cluster/replay/ReplayStore.java
@@ -26,10 +26,8 @@ import org.apache.qpid.framing.*;
import org.apache.qpid.server.cluster.ClusteredProtocolSession;
import org.apache.qpid.server.cluster.util.LogMessage;
import org.apache.qpid.server.cluster.util.Bindings;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.state.StateAwareMethodListener;
import org.apache.qpid.server.virtualhost.VirtualHost;
@@ -48,8 +46,8 @@ public class ReplayStore implements ReplayManager, StateAwareMethodListener
{
private static final Logger _logger = Logger.getLogger(ReplayStore.class);
- private final Map<Class<? extends AMQMethodBody>, MethodRecorder> _globalRecorders = new HashMap<Class<? extends AMQMethodBody>, MethodRecorder>();
- private final Map<Class<? extends AMQMethodBody>, MethodRecorder> _localRecorders = new HashMap<Class<? extends AMQMethodBody>, MethodRecorder>();
+ private final Map<Class<? extends AMQMethodBodyImpl>, MethodRecorder> _globalRecorders = new HashMap<Class<? extends AMQMethodBodyImpl>, MethodRecorder>();
+ private final Map<Class<? extends AMQMethodBodyImpl>, MethodRecorder> _localRecorders = new HashMap<Class<? extends AMQMethodBodyImpl>, MethodRecorder>();
private final Map<AMQShortString, QueueDeclareBody> _sharedQueues = new ConcurrentHashMap<AMQShortString, QueueDeclareBody>();
private final Map<AMQShortString, QueueDeclareBody> _privateQueues = new ConcurrentHashMap<AMQShortString, QueueDeclareBody>();
private final Bindings<AMQShortString, AMQShortString, QueueBindBody> _sharedBindings = new Bindings<AMQShortString, AMQShortString, QueueBindBody>();
@@ -80,7 +78,7 @@ public class ReplayStore implements ReplayManager, StateAwareMethodListener
VirtualHost virtualHost = session.getVirtualHost();
_logger.debug(new LogMessage("Replay store received {0}", evt.getMethod()));
- AMQMethodBody request = evt.getMethod();
+ AMQMethodBodyImpl request = evt.getMethod();
//allow any (relevant) recorder registered for this type of request to record it:
MethodRecorder recorder = getRecorders(session).get(request.getClass());
@@ -90,7 +88,7 @@ public class ReplayStore implements ReplayManager, StateAwareMethodListener
}
}
- private Map<Class<? extends AMQMethodBody>, MethodRecorder> getRecorders(AMQProtocolSession session)
+ private Map<Class<? extends AMQMethodBodyImpl>, MethodRecorder> getRecorders(AMQProtocolSession session)
{
if (ClusteredProtocolSession.isPeerSession(session))
{
@@ -102,9 +100,9 @@ public class ReplayStore implements ReplayManager, StateAwareMethodListener
}
}
- public List<AMQMethodBody> replay(boolean isLeader)
+ public List<AMQMethodBodyImpl> replay(boolean isLeader)
{
- List<AMQMethodBody> methods = new ArrayList<AMQMethodBody>();
+ List<AMQMethodBodyImpl> methods = new ArrayList<AMQMethodBodyImpl>();
methods.addAll(_exchanges.values());
methods.addAll(_privateQueues.values());
synchronized(_privateBindings)
diff --git a/java/cluster/src/test/java/org/apache/qpid/server/cluster/BrokerTest.java b/java/cluster/src/test/java/org/apache/qpid/server/cluster/BrokerTest.java
index f1da312eea..ad7d7e1b5f 100644
--- a/java/cluster/src/test/java/org/apache/qpid/server/cluster/BrokerTest.java
+++ b/java/cluster/src/test/java/org/apache/qpid/server/cluster/BrokerTest.java
@@ -23,11 +23,11 @@ package org.apache.qpid.server.cluster;
import junit.framework.TestCase;
import org.apache.mina.common.ByteBuffer;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQBody;
+import org.apache.qpid.framing.AMQBodyImpl;
import org.apache.qpid.framing.AMQDataBlock;
import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.AMQFrameDecodingException;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.server.cluster.policy.StandardPolicies;
import java.util.ArrayList;
@@ -91,13 +91,13 @@ public class BrokerTest extends TestCase
//simple send (no response)
public void testSend_noResponse() throws AMQException
{
- AMQBody[] msgs = new AMQBody[]{
+ AMQBodyImpl[] msgs = new AMQBodyImpl[]{
new TestMethod("A"),
new TestMethod("B"),
new TestMethod("C")
};
RecordingBroker broker = new RecordingBroker("myhost", 1);
- for (AMQBody msg : msgs)
+ for (AMQBodyImpl msg : msgs)
{
broker.send(new SimpleBodySendable(msg), null);
}
@@ -142,7 +142,7 @@ public class BrokerTest extends TestCase
assertTrue(handler.failed());
}
- private static class TestMethod extends AMQMethodBody
+ private static class TestMethod extends AMQMethodBodyImpl
{
private final Object id;
@@ -209,19 +209,19 @@ public class BrokerTest extends TestCase
private static class GroupResponseValidator implements GroupResponseHandler
{
- private final AMQMethodBody _response;
+ private final AMQMethodBodyImpl _response;
private final List<Member> _members;
private boolean _completed = false;
- GroupResponseValidator(AMQMethodBody response, List<Member> members)
+ GroupResponseValidator(AMQMethodBodyImpl response, List<Member> members)
{
_response = response;
_members = members;
}
- public void response(List<AMQMethodBody> responses, List<Member> members)
+ public void response(List<AMQMethodBodyImpl> responses, List<Member> members)
{
- for (AMQMethodBody r : responses)
+ for (AMQMethodBodyImpl r : responses)
{
assertEquals(_response, r);
}
diff --git a/java/cluster/src/test/java/org/apache/qpid/server/cluster/TestBroker.java b/java/cluster/src/test/java/org/apache/qpid/server/cluster/TestBroker.java
index d3ccbf0ac6..7f513530e0 100644
--- a/java/cluster/src/test/java/org/apache/qpid/server/cluster/TestBroker.java
+++ b/java/cluster/src/test/java/org/apache/qpid/server/cluster/TestBroker.java
@@ -23,7 +23,7 @@ package org.apache.qpid.server.cluster;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQDataBlock;
import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import java.io.IOException;
@@ -39,16 +39,16 @@ class TestBroker extends Broker
return true;
}
- void connectAsynch(Iterable<AMQMethodBody> msgs)
+ void connectAsynch(Iterable<AMQMethodBodyImpl> msgs)
{
replay(msgs);
}
- void replay(Iterable<AMQMethodBody> msgs)
+ void replay(Iterable<AMQMethodBodyImpl> msgs)
{
try
{
- for (AMQMethodBody b : msgs)
+ for (AMQMethodBodyImpl b : msgs)
{
send(new AMQFrame(0, b));
}
diff --git a/java/cluster/src/test/java/org/apache/qpid/server/cluster/TestReplayManager.java b/java/cluster/src/test/java/org/apache/qpid/server/cluster/TestReplayManager.java
index c529c83cc0..ba62e86101 100644
--- a/java/cluster/src/test/java/org/apache/qpid/server/cluster/TestReplayManager.java
+++ b/java/cluster/src/test/java/org/apache/qpid/server/cluster/TestReplayManager.java
@@ -20,7 +20,7 @@
*/
package org.apache.qpid.server.cluster;
-import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.server.cluster.replay.ReplayManager;
import java.util.ArrayList;
@@ -28,19 +28,19 @@ import java.util.List;
class TestReplayManager implements ReplayManager
{
- private final List<AMQMethodBody> _msgs;
+ private final List<AMQMethodBodyImpl> _msgs;
TestReplayManager()
{
- this(new ArrayList<AMQMethodBody>());
+ this(new ArrayList<AMQMethodBodyImpl>());
}
- TestReplayManager(List<AMQMethodBody> msgs)
+ TestReplayManager(List<AMQMethodBodyImpl> msgs)
{
_msgs = msgs;
}
- public List<AMQMethodBody> replay(boolean isLeader)
+ public List<AMQMethodBodyImpl> replay(boolean isLeader)
{
return _msgs;
}
diff --git a/java/common/src/main/java/org/apache/qpid/AMQChannelException.java b/java/common/src/main/java/org/apache/qpid/AMQChannelException.java
index d8c9b287bd..12120bd10d 100644
--- a/java/common/src/main/java/org/apache/qpid/AMQChannelException.java
+++ b/java/common/src/main/java/org/apache/qpid/AMQChannelException.java
@@ -23,6 +23,8 @@ package org.apache.qpid;
import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ChannelCloseBody;
+import org.apache.qpid.framing.amqp_8_0.ConnectionCloseBodyImpl;
+import org.apache.qpid.framing.amqp_8_0.ChannelCloseBodyImpl;
import org.apache.qpid.protocol.AMQConstant;
public class AMQChannelException extends AMQException
@@ -53,6 +55,6 @@ public class AMQChannelException extends AMQException
public AMQFrame getCloseFrame(int channel)
{
- return ChannelCloseBody.createAMQFrame(channel, major, minor, _classId, _methodId, getErrorCode().getCode(), new AMQShortString(getMessage()));
+ return new AMQFrame(channel, new ChannelCloseBodyImpl(getErrorCode().getCode(), new AMQShortString(getMessage()),0,0));
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/AMQConnectionException.java b/java/common/src/main/java/org/apache/qpid/AMQConnectionException.java
index c4f80191a3..094e26802d 100644
--- a/java/common/src/main/java/org/apache/qpid/AMQConnectionException.java
+++ b/java/common/src/main/java/org/apache/qpid/AMQConnectionException.java
@@ -24,6 +24,7 @@ package org.apache.qpid;
import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ConnectionCloseBody;
+import org.apache.qpid.framing.amqp_8_0.ConnectionCloseBodyImpl;
import org.apache.qpid.protocol.AMQConstant;
public class AMQConnectionException extends AMQException
@@ -57,7 +58,7 @@ public class AMQConnectionException extends AMQException
public AMQFrame getCloseFrame(int channel)
{
- return ConnectionCloseBody.createAMQFrame(channel, major, minor, _classId, _methodId, getErrorCode().getCode(), new AMQShortString(getMessage()));
+ return new AMQFrame(channel, new ConnectionCloseBodyImpl(getErrorCode().getCode(), new AMQShortString(getMessage()),_classId,_methodId));
}
diff --git a/java/common/src/main/java/org/apache/qpid/codec/AMQDecoder.java b/java/common/src/main/java/org/apache/qpid/codec/AMQDecoder.java
index bb981a242f..6e0a5c3786 100644
--- a/java/common/src/main/java/org/apache/qpid/codec/AMQDecoder.java
+++ b/java/common/src/main/java/org/apache/qpid/codec/AMQDecoder.java
@@ -48,13 +48,21 @@ public class AMQDecoder extends CumulativeProtocolDecoder
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception
{
- if (_expectProtocolInitiation)
+ try
{
- return doDecodePI(session, in, out);
+ if (_expectProtocolInitiation)
+ {
+ return doDecodePI(session, in, out);
+ }
+ else
+ {
+ return doDecodeDataBlock(session, in, out);
+ }
}
- else
+ catch (Exception e)
{
- return doDecodeDataBlock(session, in, out);
+ e.printStackTrace();
+ throw e;
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/common/ClientProperties.java b/java/common/src/main/java/org/apache/qpid/common/ClientProperties.java
index 07371b5182..1f1911aa35 100644
--- a/java/common/src/main/java/org/apache/qpid/common/ClientProperties.java
+++ b/java/common/src/main/java/org/apache/qpid/common/ClientProperties.java
@@ -20,10 +20,28 @@
*/
package org.apache.qpid.common;
+import org.apache.qpid.framing.AMQShortString;
+
public enum ClientProperties
{
+
+
instance,
product,
version,
- platform
+ platform;
+
+
+ private final AMQShortString _name;
+
+ private ClientProperties()
+ {
+ _name = new AMQShortString(toString());
+ }
+
+ public AMQShortString getName()
+ {
+ return _name;
+ }
+
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQBody.java b/java/common/src/main/java/org/apache/qpid/framing/AMQBody.java
index ebeea8d2b4..4dd5ab7a9a 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQBody.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQBody.java
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -22,18 +22,15 @@ package org.apache.qpid.framing;
import org.apache.mina.common.ByteBuffer;
-public abstract class AMQBody
+public interface AMQBody
{
- public abstract byte getFrameType();
-
- /**
+ byte getFrameType();
+
+ /**
* Get the size of the body
* @return unsigned short
*/
- protected abstract int getSize();
-
- protected abstract void writePayload(ByteBuffer buffer);
-
- protected abstract void populateFromBuffer(ByteBuffer buffer, long size)
- throws AMQFrameDecodingException, AMQProtocolVersionException;
+ int getSize();
+
+ void writePayload(ByteBuffer buffer);
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQBodyImpl.java b/java/common/src/main/java/org/apache/qpid/framing/AMQBodyImpl.java
new file mode 100644
index 0000000000..6b2d1feae5
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQBodyImpl.java
@@ -0,0 +1,27 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.framing;
+
+
+public abstract class AMQBodyImpl implements AMQBody
+{
+
+}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java
index 43f888c029..2ecd4d4650 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java
@@ -72,7 +72,7 @@ public class AMQDataBlockDecoder
final byte type = in.get();
BodyFactory bodyFactory;
- if(type == AMQMethodBody.TYPE)
+ if(type == AMQMethodBodyImpl.TYPE)
{
bodyFactory = (BodyFactory) session.getAttribute(SESSION_METHOD_BODY_FACTORY);
if(bodyFactory == null)
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java
index 111d9a8f20..d61c1c3d36 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java
@@ -1,132 +1,25 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
package org.apache.qpid.framing;
-import org.apache.mina.common.ByteBuffer;
import org.apache.qpid.AMQChannelException;
import org.apache.qpid.AMQConnectionException;
import org.apache.qpid.protocol.AMQConstant;
-public abstract class AMQMethodBody extends AMQBody
+/**
+ * Created by IntelliJ IDEA.
+ * User: U146758
+ * Date: 08-Mar-2007
+ * Time: 11:30:28
+ * To change this template use File | Settings | File Templates.
+ */
+public interface AMQMethodBody extends AMQBody
{
- public static final byte TYPE = 1;
-
- /** AMQP version */
- protected byte major;
- protected byte minor;
-
- public byte getMajor()
- {
- return major;
- }
-
- public byte getMinor()
- {
- return minor;
- }
-
- public AMQMethodBody(byte major, byte minor)
- {
- this.major = major;
- this.minor = minor;
- }
-
- /** unsigned short */
- protected abstract int getBodySize();
-
- /** @return unsigned short */
- protected abstract int getClazz();
-
- /** @return unsigned short */
- protected abstract int getMethod();
-
- protected abstract void writeMethodPayload(ByteBuffer buffer);
-
- public byte getFrameType()
- {
- return TYPE;
- }
-
- protected int getSize()
- {
- return 2 + 2 + getBodySize();
- }
-
- protected void writePayload(ByteBuffer buffer)
- {
- EncodingUtils.writeUnsignedShort(buffer, getClazz());
- EncodingUtils.writeUnsignedShort(buffer, getMethod());
- writeMethodPayload(buffer);
- }
-
- protected abstract void populateMethodBodyFromBuffer(ByteBuffer buffer) throws AMQFrameDecodingException;
-
- protected void populateFromBuffer(ByteBuffer buffer, long size) throws AMQFrameDecodingException
- {
- populateMethodBodyFromBuffer(buffer);
- }
-
- public String toString()
- {
- StringBuffer buf = new StringBuffer(getClass().toString());
- buf.append(" Class: ").append(getClazz());
- buf.append(" Method: ").append(getMethod());
- return buf.toString();
- }
-
- /**
- * Creates an AMQChannelException for the corresponding body type (a channel exception should include the class and
- * method ids of the body it resulted from).
- */
-
- /**
- * Convenience Method to create a channel not found exception
- *
- * @param channelId The channel id that is not found
- *
- * @return new AMQChannelException
- */
- public AMQChannelException getChannelNotFoundException(int channelId)
- {
- return getChannelException(AMQConstant.NOT_FOUND, "Channel not found for id:" + channelId);
- }
-
- public AMQChannelException getChannelException(AMQConstant code, String message)
- {
- return new AMQChannelException(code, message, getClazz(), getMethod(), major, minor);
- }
+ AMQChannelException getChannelNotFoundException(int channelId);
- public AMQChannelException getChannelException(AMQConstant code, String message, Throwable cause)
- {
- return new AMQChannelException(code, message, getClazz(), getMethod(), major, minor, cause);
- }
+ AMQChannelException getChannelException(AMQConstant code, String message);
- public AMQConnectionException getConnectionException(AMQConstant code, String message)
- {
- return new AMQConnectionException(code, message, getClazz(), getMethod(), major, minor);
- }
+ AMQChannelException getChannelException(AMQConstant code, String message, Throwable cause);
- public AMQConnectionException getConnectionException(AMQConstant code, String message, Throwable cause)
- {
- return new AMQConnectionException(code, message, getClazz(), getMethod(), major, minor, cause);
- }
+ AMQConnectionException getConnectionException(AMQConstant code, String message);
+ AMQConnectionException getConnectionException(AMQConstant code, String message, Throwable cause);
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java
index 5293c00379..f5cd971c0e 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java
@@ -37,6 +37,6 @@ public class AMQMethodBodyFactory implements BodyFactory
public AMQBody createBody(ByteBuffer in, long bodySize) throws AMQFrameDecodingException
{
- return _protocolSession.getRegistry().get((short)in.getUnsignedShort(), (short)in.getUnsignedShort(), in, bodySize);
+ return _protocolSession.getRegistry().convertToBody(in, bodySize);
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyImpl.java b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyImpl.java
new file mode 100644
index 0000000000..1951970a72
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyImpl.java
@@ -0,0 +1,102 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.framing;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.qpid.AMQChannelException;
+import org.apache.qpid.AMQConnectionException;
+import org.apache.qpid.protocol.AMQConstant;
+
+public abstract class AMQMethodBodyImpl extends AMQBodyImpl implements AMQMethodBody
+{
+ public static final byte TYPE = 1;
+
+
+ public abstract byte getMajor();
+ public abstract byte getMinor();
+
+ /** unsigned short */
+ protected abstract int getBodySize();
+
+ /** @return unsigned short */
+ protected abstract int getClazz();
+
+ /** @return unsigned short */
+ protected abstract int getMethod();
+
+ protected abstract void writeMethodPayload(ByteBuffer buffer);
+
+ public byte getFrameType()
+ {
+ return TYPE;
+ }
+
+ public int getSize()
+ {
+ return 2 + 2 + getBodySize();
+ }
+
+ public void writePayload(ByteBuffer buffer)
+ {
+ EncodingUtils.writeUnsignedShort(buffer, getClazz());
+ EncodingUtils.writeUnsignedShort(buffer, getMethod());
+ writeMethodPayload(buffer);
+ }
+
+
+ /**
+ * Creates an AMQChannelException for the corresponding body type (a channel exception should include the class and
+ * method ids of the body it resulted from).
+ */
+
+ /**
+ * Convenience Method to create a channel not found exception
+ *
+ * @param channelId The channel id that is not found
+ *
+ * @return new AMQChannelException
+ */
+ public AMQChannelException getChannelNotFoundException(int channelId)
+ {
+ return getChannelException(AMQConstant.NOT_FOUND, "Channel not found for id:" + channelId);
+ }
+
+ public AMQChannelException getChannelException(AMQConstant code, String message)
+ {
+ return new AMQChannelException(code, message, getClazz(), getMethod(), getMajor(), getMinor());
+ }
+
+ public AMQChannelException getChannelException(AMQConstant code, String message, Throwable cause)
+ {
+ return new AMQChannelException(code, message, getClazz(), getMethod(), getMajor(), getMinor(), cause);
+ }
+
+ public AMQConnectionException getConnectionException(AMQConstant code, String message)
+ {
+ return new AMQConnectionException(code, message, getClazz(), getMethod(), getMajor(), getMinor());
+ }
+
+ public AMQConnectionException getConnectionException(AMQConstant code, String message, Throwable cause)
+ {
+ return new AMQConnectionException(code, message, getClazz(), getMethod(), getMajor(), getMinor(), cause);
+ }
+
+}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyInstanceFactory.java b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyInstanceFactory.java
index cfbc9d1828..9a7868f3cd 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyInstanceFactory.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyInstanceFactory.java
@@ -5,6 +5,5 @@ import org.apache.mina.common.ByteBuffer;
public abstract interface AMQMethodBodyInstanceFactory
{
- public AMQMethodBody newInstance(byte major, byte minor, ByteBuffer buffer, long size) throws AMQFrameDecodingException;
- public AMQMethodBody newInstance(byte major, byte minor, int clazzID, int methodID, ByteBuffer buffer, long size) throws AMQFrameDecodingException;
+ public AMQMethodBody newInstance(ByteBuffer buffer, long size) throws AMQFrameDecodingException;
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodFactory.java b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodFactory.java
new file mode 100644
index 0000000000..4ffc9e0066
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodFactory.java
@@ -0,0 +1,90 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.framing;
+
+import org.apache.mina.common.ByteBuffer;
+
+
+public interface AMQMethodFactory
+{
+
+ // Connection Methods
+
+ ConnectionCloseBody createConnectionClose();
+
+ // Access Methods
+
+ AccessRequestBody createAccessRequest(boolean active, boolean exclusive, boolean passive, boolean read, AMQShortString realm, boolean write);
+
+
+ // Tx Methods
+
+ TxSelectBody createTxSelect();
+
+ TxCommitBody createTxCommit();
+
+ TxRollbackBody createTxRollback();
+
+ // Channel Methods
+
+ ChannelOpenBody createChannelOpen();
+
+ ChannelCloseBody createChannelClose(int replyCode, AMQShortString replyText);
+
+ ChannelFlowBody createChannelFlow(boolean active);
+
+
+ // Exchange Methods
+
+
+ ExchangeBoundBody createExchangeBound(AMQShortString exchangeName,
+ AMQShortString queueName,
+ AMQShortString routingKey);
+
+ ExchangeDeclareBody createExchangeDeclare(AMQShortString name, AMQShortString type, int ticket);
+
+
+ // Queue Methods
+
+ QueueDeclareBody createQueueDeclare(AMQShortString name, FieldTable arguments, boolean autoDelete, boolean durable, boolean exclusive, boolean passive, int ticket);
+
+ QueueBindBody createQueueBind(AMQShortString queueName, AMQShortString exchangeName, AMQShortString routingKey, FieldTable arguments, int ticket);
+
+ QueueDeleteBody createQueueDelete(AMQShortString queueName, boolean ifEmpty, boolean ifUnused, int ticket);
+
+
+ // Message Methods
+
+ // In different versions of the protocol we change the class used for message transfer
+ // abstract this out so the appropriate methods are created
+ AMQMethodBody createRecover(boolean requeue);
+
+ AMQMethodBody createConsumer(AMQShortString tag, AMQShortString queueName, FieldTable arguments, boolean noAck, boolean exclusive, boolean noLocal, int ticket);
+
+ AMQMethodBody createConsumerCancel(AMQShortString consumerTag);
+
+ AMQMethodBody createAcknowledge(long deliveryTag, boolean multiple);
+
+ AMQMethodBody createRejectBody(long deliveryTag, boolean requeue);
+
+ AMQMethodBody createMessageQos(int prefetchCount, int prefetchSize);
+
+}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java b/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java
index 1045b02868..8b784fa3f7 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java
@@ -24,7 +24,7 @@ import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
-public class BasicContentHeaderProperties implements ContentHeaderProperties
+public class BasicContentHeaderProperties implements CommonContentHeaderProperties
{
private static final Logger _logger = Logger.getLogger(BasicContentHeaderProperties.class);
@@ -421,14 +421,14 @@ public class BasicContentHeaderProperties implements ContentHeaderProperties
}
}
- public AMQShortString getContentTypeShortString()
+ public AMQShortString getContentType()
{
decodeContentTypeIfNecessary();
return _contentType;
}
- public String getContentType()
+ public String getContentTypeAsString()
{
decodeContentTypeIfNecessary();
return _contentType == null ? null : _contentType.toString();
@@ -444,15 +444,19 @@ public class BasicContentHeaderProperties implements ContentHeaderProperties
public void setContentType(String contentType)
{
- clearEncodedForm();
- _propertyFlags |= (1 << 15);
- _contentType = contentType == null ? null : new AMQShortString(contentType);
+ setContentType(contentType == null ? null : new AMQShortString(contentType));
+ }
+
+ public String getEncodingAsString()
+ {
+
+ return getEncoding() == null ? null : getEncoding().toString();
}
- public String getEncoding()
+ public AMQShortString getEncoding()
{
decodeIfNecessary();
- return _encoding == null ? null : _encoding.toString();
+ return _encoding;
}
public void setEncoding(String encoding)
@@ -462,6 +466,14 @@ public class BasicContentHeaderProperties implements ContentHeaderProperties
_encoding = encoding == null ? null : new AMQShortString(encoding);
}
+ public void setEncoding(AMQShortString encoding)
+ {
+ clearEncodedForm();
+ _propertyFlags |= (1 << 14);
+ _encoding = encoding;
+ }
+
+
public FieldTable getHeaders()
{
decodeHeadersIfNecessary();
@@ -508,7 +520,13 @@ public class BasicContentHeaderProperties implements ContentHeaderProperties
_priority = priority;
}
- public String getCorrelationId()
+ public AMQShortString getCorrelationId()
+ {
+ decodeIfNecessary();
+ return _correlationId;
+ }
+
+ public String getCorrelationIdAsString()
{
decodeIfNecessary();
return _correlationId == null ? null : _correlationId.toString();
@@ -516,18 +534,23 @@ public class BasicContentHeaderProperties implements ContentHeaderProperties
public void setCorrelationId(String correlationId)
{
+ setCorrelationId(correlationId == null ? null : new AMQShortString(correlationId));
+ }
+
+ public void setCorrelationId(AMQShortString correlationId)
+ {
clearEncodedForm();
_propertyFlags |= (1 << 10);
- _correlationId = correlationId == null ? null : new AMQShortString(correlationId);
+ _correlationId = correlationId;
}
- public String getReplyTo()
+ public String getReplyToAsString()
{
decodeIfNecessary();
return _replyTo == null ? null : _replyTo.toString();
}
- public AMQShortString getReplyToAsShortString()
+ public AMQShortString getReplyTo()
{
decodeIfNecessary();
return _replyTo;
@@ -561,7 +584,13 @@ public class BasicContentHeaderProperties implements ContentHeaderProperties
}
- public String getMessageId()
+ public AMQShortString getMessageId()
+ {
+ decodeIfNecessary();
+ return _messageId;
+ }
+
+ public String getMessageIdAsString()
{
decodeIfNecessary();
return _messageId == null ? null : _messageId.toString();
@@ -574,6 +603,14 @@ public class BasicContentHeaderProperties implements ContentHeaderProperties
_messageId = messageId == null ? null : new AMQShortString(messageId);
}
+ public void setMessageId(AMQShortString messageId)
+ {
+ clearEncodedForm();
+ _propertyFlags |= (1 << 7);
+ _messageId = messageId;
+ }
+
+
public long getTimestamp()
{
decodeIfNecessary();
@@ -587,56 +624,102 @@ public class BasicContentHeaderProperties implements ContentHeaderProperties
_timestamp = timestamp;
}
- public String getType()
+ public String getTypeAsString()
{
decodeIfNecessary();
return _type == null ? null : _type.toString();
}
+
+ public AMQShortString getType()
+ {
+ decodeIfNecessary();
+ return _type;
+ }
+
+
public void setType(String type)
{
+ setType(type == null ? null : new AMQShortString(type));
+ }
+
+ public void setType(AMQShortString type)
+ {
clearEncodedForm();
_propertyFlags |= (1 << 5);
- _type = type == null ? null : new AMQShortString(type);
+ _type = type;
}
- public String getUserId()
+ public String getUserIdAsString()
{
decodeIfNecessary();
return _userId == null ? null : _userId.toString();
}
+ public AMQShortString getUserId()
+ {
+ decodeIfNecessary();
+ return _userId;
+ }
+
public void setUserId(String userId)
{
+ setUserId(userId == null ? null : new AMQShortString(userId));
+ }
+
+ public void setUserId(AMQShortString userId)
+ {
clearEncodedForm();
_propertyFlags |= (1 << 4);
- _userId = userId == null ? null : new AMQShortString(userId);
+ _userId = userId;
}
- public String getAppId()
+ public String getAppIdAsString()
{
decodeIfNecessary();
return _appId == null ? null : _appId.toString();
}
+ public AMQShortString getAppId()
+ {
+ decodeIfNecessary();
+ return _appId;
+ }
+
public void setAppId(String appId)
{
+ setAppId(appId == null ? null : new AMQShortString(appId));
+ }
+
+ public void setAppId(AMQShortString appId)
+ {
clearEncodedForm();
_propertyFlags |= (1 << 3);
- _appId = appId == null ? null : new AMQShortString(appId);
+ _appId = appId;
}
- public String getClusterId()
+ public String getClusterIdAsString()
{
decodeIfNecessary();
return _clusterId == null ? null : _clusterId.toString();
}
+ public AMQShortString getClusterId()
+ {
+ decodeIfNecessary();
+ return _clusterId;
+ }
+
public void setClusterId(String clusterId)
{
+ setClusterId(clusterId == null ? null : new AMQShortString(clusterId));
+ }
+
+ public void setClusterId(AMQShortString clusterId)
+ {
clearEncodedForm();
_propertyFlags |= (1 << 2);
- _clusterId = clusterId == null ? null : new AMQShortString(clusterId);
+ _clusterId = clusterId;
}
public String toString()
diff --git a/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java b/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java
new file mode 100644
index 0000000000..1641cbf4e8
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java
@@ -0,0 +1,65 @@
+package org.apache.qpid.framing;
+
+import org.apache.mina.common.ByteBuffer;
+
+import org.apache.log4j.Logger;
+
+public interface CommonContentHeaderProperties extends ContentHeaderProperties
+{
+
+ AMQShortString getContentType();
+
+ void setContentType(AMQShortString contentType);
+
+ FieldTable getHeaders();
+
+ void setHeaders(FieldTable headers);
+
+ byte getDeliveryMode();
+
+ void setDeliveryMode(byte deliveryMode);
+
+ byte getPriority();
+
+ void setPriority(byte priority);
+
+ AMQShortString getCorrelationId();
+
+ void setCorrelationId(AMQShortString correlationId);
+
+ AMQShortString getReplyTo();
+
+ void setReplyTo(AMQShortString replyTo);
+
+ long getExpiration();
+
+ void setExpiration(long expiration);
+
+ AMQShortString getMessageId();
+
+ void setMessageId(AMQShortString messageId);
+
+ long getTimestamp();
+
+ void setTimestamp(long timestamp);
+
+ AMQShortString getType();
+
+ void setType(AMQShortString type);
+
+ AMQShortString getUserId();
+
+ void setUserId(AMQShortString userId);
+
+ AMQShortString getAppId();
+
+ void setAppId(AMQShortString appId);
+
+ AMQShortString getClusterId();
+
+ void setClusterId(AMQShortString clusterId);
+
+ AMQShortString getEncoding();
+
+ void setEncoding(AMQShortString encoding);
+}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java b/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java
index be38695384..a1aaab06c6 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java
@@ -22,7 +22,7 @@ package org.apache.qpid.framing;
import org.apache.mina.common.ByteBuffer;
-public class ContentBody extends AMQBody
+public class ContentBody extends AMQBodyImpl
{
public static final byte TYPE = 3;
diff --git a/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java b/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java
index 5636229d53..7b6a92e691 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java
@@ -39,7 +39,7 @@ public class ContentBodyFactory implements BodyFactory
_log.debug("Creating content body factory");
}
- public AMQBody createBody(ByteBuffer in, long bodySize) throws AMQFrameDecodingException
+ public AMQBodyImpl createBody(ByteBuffer in, long bodySize) throws AMQFrameDecodingException
{
return new ContentBody(in, bodySize);
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java b/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java
index 02631a5f88..c71f47bad2 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java
@@ -22,7 +22,7 @@ package org.apache.qpid.framing;
import org.apache.mina.common.ByteBuffer;
-public class ContentHeaderBody extends AMQBody
+public class ContentHeaderBody extends AMQBodyImpl
{
public static final byte TYPE = 2;
@@ -110,7 +110,7 @@ public class ContentHeaderBody extends AMQBody
properties.writePropertyListPayload(buffer);
}
- public static AMQFrame createAMQFrame(int channelId, int classId, int weight, BasicContentHeaderProperties properties,
+ public static AMQFrame createAMQFrame(int channelId, int classId, int weight, CommonContentHeaderProperties properties,
long bodySize)
{
return new AMQFrame(channelId, new ContentHeaderBody(classId, weight, properties, bodySize));
diff --git a/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java b/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java
index 818fc9cf0c..9570ec800d 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java
@@ -39,7 +39,7 @@ public class ContentHeaderBodyFactory implements BodyFactory
_log.debug("Creating content header body factory");
}
- public AMQBody createBody(ByteBuffer in, long bodySize) throws AMQFrameDecodingException
+ public AMQBodyImpl createBody(ByteBuffer in, long bodySize) throws AMQFrameDecodingException
{
// all content headers are the same - it is only the properties that differ.
// the content header body further delegates construction of properties
diff --git a/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java b/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java
index 7dac018872..a8a8097fd2 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java
@@ -20,6 +20,8 @@
*/
package org.apache.qpid.framing;
+import org.apache.qpid.framing.amqp_8_0.BasicConsumeBodyImpl;
+
import org.apache.mina.common.ByteBuffer;
public class ContentHeaderPropertiesFactory
@@ -43,7 +45,7 @@ public class ContentHeaderPropertiesFactory
// AMQP version change: "Hardwired" version to major=8, minor=0
// TODO: Change so that the actual version is obtained from
// the ProtocolInitiation object for this session.
- if (classId == BasicConsumeBody.getClazz((byte)8, (byte)0))
+ if (classId == BasicConsumeBodyImpl.CLASS_ID)
{
properties = new BasicContentHeaderProperties();
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
index 246e5ebc90..a7544c5747 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
@@ -41,10 +41,14 @@ public class FieldTable
private LinkedHashMap<AMQShortString, AMQTypedValue> _properties;
private long _encodedSize;
private static final int INITIAL_HASHMAP_CAPACITY = 16;
+ private static final int INITIAL_ENCODED_FORM_SIZE = 256;
public FieldTable()
{
super();
+// _encodedForm = ByteBuffer.allocate(INITIAL_ENCODED_FORM_SIZE);
+// _encodedForm.setAutoExpand(true);
+// _encodedForm.limit(0);
}
/**
@@ -109,11 +113,28 @@ public class FieldTable
private AMQTypedValue setProperty(AMQShortString key, AMQTypedValue val)
{
initMapIfNecessary();
- _encodedForm = null;
- if(val == null)
+ if(_properties.containsKey(key))
+ {
+ _encodedForm = null;
+
+ if(val == null)
+ {
+ return removeKey(key);
+ }
+ }
+ else if(_encodedForm != null && val != null)
+ {
+ EncodingUtils.writeShortStringBytes(_encodedForm, key);
+ val.writeToBuffer(_encodedForm);
+
+ }
+ else if (val == null)
{
- return removeKey(key);
+ return null;
}
+
+
+
AMQTypedValue oldVal = _properties.put(key,val);
if(oldVal != null)
{
@@ -134,7 +155,7 @@ public class FieldTable
{
if(_properties == null)
{
- if(_encodedForm == null)
+ if(_encodedForm == null || _encodedSize == 0)
{
_properties = new LinkedHashMap<AMQShortString,AMQTypedValue>();
}
@@ -655,6 +676,7 @@ public class FieldTable
if (trace)
{
_logger.trace("FieldTable::writeToBuffer: Writing encoded length of " + getEncodedSize() + "...");
+ _logger.trace(_properties);
}
EncodingUtils.writeUnsignedInteger(buffer, getEncodedSize());
@@ -701,6 +723,7 @@ public class FieldTable
public void addAll(FieldTable fieldTable)
{
initMapIfNecessary();
+ _encodedForm = null;
_properties.putAll(fieldTable._properties);
recalculateEncodedSize();
}
@@ -836,7 +859,13 @@ public class FieldTable
if(_encodedForm != null)
{
- buffer.put(_encodedForm);
+
+ if(_encodedForm.position() != 0)
+ {
+ _encodedForm.flip();
+ }
+// _encodedForm.limit((int)getEncodedSize());
+ buffer.put(_encodedForm);
}
else if(_properties != null)
{
@@ -924,4 +953,33 @@ public class FieldTable
}
}
+ public int hashCode()
+ {
+ initMapIfNecessary();
+ return _properties.hashCode();
+ }
+
+
+ public boolean equals(Object o)
+ {
+ if(o == this)
+ {
+ return true;
+ }
+ if(o == null)
+ {
+ return false;
+ }
+ if(!(o instanceof FieldTable))
+ {
+ return false;
+ }
+
+ initMapIfNecessary();
+
+ FieldTable f = (FieldTable) o;
+ f.initMapIfNecessary();
+
+ return _properties.equals(f._properties);
+ }
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java b/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java
index 7246c4a1cf..17b2a2f9c2 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java
@@ -22,7 +22,7 @@ package org.apache.qpid.framing;
import org.apache.mina.common.ByteBuffer;
-public class HeartbeatBody extends AMQBody
+public class HeartbeatBody extends AMQBodyImpl
{
public static final byte TYPE = 8;
public static AMQFrame FRAME = new HeartbeatBody().toFrame();
@@ -46,12 +46,12 @@ public class HeartbeatBody extends AMQBody
return TYPE;
}
- protected int getSize()
+ public int getSize()
{
return 0;//heartbeats we generate have no payload
}
- protected void writePayload(ByteBuffer buffer)
+ public void writePayload(ByteBuffer buffer)
{
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBodyFactory.java b/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBodyFactory.java
index c7ada708dc..2249f1d1cf 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBodyFactory.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBodyFactory.java
@@ -24,7 +24,7 @@ import org.apache.mina.common.ByteBuffer;
public class HeartbeatBodyFactory implements BodyFactory
{
- public AMQBody createBody(ByteBuffer in, long bodySize) throws AMQFrameDecodingException
+ public AMQBodyImpl createBody(ByteBuffer in, long bodySize) throws AMQFrameDecodingException
{
return new HeartbeatBody();
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/MainRegistry.java b/java/common/src/main/java/org/apache/qpid/framing/MainRegistry.java
new file mode 100644
index 0000000000..d75589f914
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/framing/MainRegistry.java
@@ -0,0 +1,35 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.framing;
+
+public class MainRegistry
+{
+
+ public static VersionSpecificRegistry getVersionSpecificRegistry(byte versionMajor, byte versionMinor)
+ {
+ return null; //To change body of created methods use File | Settings | File Templates.
+ }
+
+ public static VersionSpecificRegistry getVersionSpecificRegistry(ProtocolVersion pv)
+ {
+ return null; //To change body of created methods use File | Settings | File Templates.
+ }
+}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/MethodConverter_8_0.java b/java/common/src/main/java/org/apache/qpid/framing/MethodConverter_8_0.java
index dd93cc97fa..f253372a65 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/MethodConverter_8_0.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/MethodConverter_8_0.java
@@ -4,6 +4,7 @@ import org.apache.qpid.framing.abstraction.ProtocolVersionMethodConverter;
import org.apache.qpid.framing.abstraction.ContentChunk;
import org.apache.qpid.framing.abstraction.MessagePublishInfo;
import org.apache.qpid.framing.abstraction.AbstractMethodConverter;
+import org.apache.qpid.framing.amqp_8_0.BasicPublishBodyImpl;
import org.apache.mina.common.ByteBuffer;
@@ -19,7 +20,7 @@ public class MethodConverter_8_0 extends AbstractMethodConverter implements Prot
}
- public AMQBody convertToBody(ContentChunk contentChunk)
+ public AMQBodyImpl convertToBody(ContentChunk contentChunk)
{
return new ContentBody(contentChunk.getData());
}
@@ -52,8 +53,8 @@ public class MethodConverter_8_0 extends AbstractMethodConverter implements Prot
public void configure()
{
- _basicPublishClassId = BasicPublishBody.getClazz(getProtocolMajorVersion(),getProtocolMinorVersion());
- _basicPublishMethodId = BasicPublishBody.getMethod(getProtocolMajorVersion(),getProtocolMinorVersion());
+ _basicPublishClassId = BasicPublishBodyImpl.CLASS_ID;
+ _basicPublishMethodId = BasicPublishBodyImpl.METHOD_ID;
}
@@ -87,18 +88,15 @@ public class MethodConverter_8_0 extends AbstractMethodConverter implements Prot
}
- public AMQMethodBody convertToBody(MessagePublishInfo info)
+ public AMQMethodBodyImpl convertToBody(MessagePublishInfo info)
{
- return new BasicPublishBody(getProtocolMajorVersion(),
- getProtocolMinorVersion(),
- _basicPublishClassId,
- _basicPublishMethodId,
- info.getExchange(),
- info.isImmediate(),
+ return new BasicPublishBodyImpl(0, // ticket
+ info.getExchange(),
+ info.getRoutingKey(),
info.isMandatory(),
- info.getRoutingKey(),
- 0) ; // ticket
+ info.isImmediate()
+ ) ;
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java b/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java
index 697a0f4249..8b40fe72eb 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java
@@ -25,25 +25,50 @@ import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import org.apache.qpid.AMQException;
+import java.io.UnsupportedEncodingException;
+
public class ProtocolInitiation extends AMQDataBlock implements EncodableAMQDataBlock
{
- public char[] header = new char[]{'A','M','Q','P'};
+
// TODO: generate these constants automatically from the xml protocol spec file
+ public static final byte[] AMQP_HEADER = new byte[]{(byte)'A',(byte)'M',(byte)'Q',(byte)'P'};
- private static byte CURRENT_PROTOCOL_CLASS = 1;
- private static final int CURRENT_PROTOCOL_INSTANCE = 1;
+ private static final byte CURRENT_PROTOCOL_CLASS = 1;
+ private static final byte TCP_PROTOCOL_INSTANCE = 1;
+
+ public final byte[] _protocolHeader;
+ public final byte _protocolClass;
+ public final byte _protocolInstance;
+ public final byte _protocolMajor;
+ public final byte _protocolMinor;
- public byte protocolClass = CURRENT_PROTOCOL_CLASS;
- public byte protocolInstance = CURRENT_PROTOCOL_INSTANCE;
- public byte protocolMajor;
- public byte protocolMinor;
// public ProtocolInitiation() {}
- public ProtocolInitiation(byte major, byte minor)
+ public ProtocolInitiation(byte[] protocolHeader, byte protocolClass, byte protocolInstance, byte protocolMajor, byte protocolMinor)
+ {
+ _protocolHeader = protocolHeader;
+ _protocolClass = protocolClass;
+ _protocolInstance = protocolInstance;
+ _protocolMajor = protocolMajor;
+ _protocolMinor = protocolMinor;
+ }
+
+ public ProtocolInitiation(ProtocolVersion pv)
{
- protocolMajor = major;
- protocolMinor = minor;
+ this(AMQP_HEADER, CURRENT_PROTOCOL_CLASS, TCP_PROTOCOL_INSTANCE, pv.getMajorVersion(), pv.getMinorVersion());
+ }
+
+
+ public ProtocolInitiation(ByteBuffer in)
+ {
+ _protocolHeader = new byte[4];
+ in.get(_protocolHeader);
+
+ _protocolClass = in.get();
+ _protocolInstance = in.get();
+ _protocolMajor = in.get();
+ _protocolMinor = in.get();
}
public long getSize()
@@ -53,19 +78,12 @@ public class ProtocolInitiation extends AMQDataBlock implements EncodableAMQData
public void writePayload(ByteBuffer buffer)
{
- for (int i = 0; i < header.length; i++)
- {
- buffer.put((byte) header[i]);
- }
- buffer.put(protocolClass);
- buffer.put(protocolInstance);
- buffer.put(protocolMajor);
- buffer.put(protocolMinor);
- }
- public void populateFromBuffer(ByteBuffer buffer) throws AMQException
- {
- throw new AMQException("Method not implemented");
+ buffer.put(_protocolHeader);
+ buffer.put(_protocolClass);
+ buffer.put(_protocolInstance);
+ buffer.put(_protocolMajor);
+ buffer.put(_protocolMinor);
}
public boolean equals(Object o)
@@ -76,36 +94,36 @@ public class ProtocolInitiation extends AMQDataBlock implements EncodableAMQData
}
ProtocolInitiation pi = (ProtocolInitiation) o;
- if (pi.header == null)
+ if (pi._protocolHeader == null)
{
return false;
}
- if (header.length != pi.header.length)
+ if (_protocolHeader.length != pi._protocolHeader.length)
{
return false;
}
- for (int i = 0; i < header.length; i++)
+ for (int i = 0; i < _protocolHeader.length; i++)
{
- if (header[i] != pi.header[i])
+ if (_protocolHeader[i] != pi._protocolHeader[i])
{
return false;
}
}
- return (protocolClass == pi.protocolClass &&
- protocolInstance == pi.protocolInstance &&
- protocolMajor == pi.protocolMajor &&
- protocolMinor == pi.protocolMinor);
+ return (_protocolClass == pi._protocolClass &&
+ _protocolInstance == pi._protocolInstance &&
+ _protocolMajor == pi._protocolMajor &&
+ _protocolMinor == pi._protocolMinor);
}
public static class Decoder //implements MessageDecoder
{
/**
*
- * @param session
- * @param in
+ * @param session the session
+ * @param in input buffer
* @return true if we have enough data to decode the PI frame fully, false if more
* data is required
*/
@@ -115,63 +133,62 @@ public class ProtocolInitiation extends AMQDataBlock implements EncodableAMQData
}
public void decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out)
- throws Exception
{
- byte[] theHeader = new byte[4];
- in.get(theHeader);
- ProtocolInitiation pi = new ProtocolInitiation((byte)0, (byte)0);
- pi.header = new char[]{(char) theHeader[0],(char) theHeader[CURRENT_PROTOCOL_INSTANCE],(char) theHeader[2], (char) theHeader[3]};
- String stringHeader = new String(pi.header);
- if (!"AMQP".equals(stringHeader))
- {
- throw new AMQProtocolHeaderException("Invalid protocol header - read " + stringHeader);
- }
- pi.protocolClass = in.get();
- pi.protocolInstance = in.get();
- pi.protocolMajor = in.get();
- pi.protocolMinor = in.get();
+ ProtocolInitiation pi = new ProtocolInitiation(in);
out.write(pi);
}
}
- public void checkVersion(ProtocolVersionList pvl) throws AMQException
+ public void checkVersion() throws AMQException
{
- if (protocolClass != CURRENT_PROTOCOL_CLASS)
- {
- throw new AMQProtocolClassException("Protocol class " + CURRENT_PROTOCOL_CLASS + " was expected; received " +
- protocolClass);
- }
- if (protocolInstance != CURRENT_PROTOCOL_INSTANCE)
+
+ if(_protocolHeader.length != 4)
{
- throw new AMQProtocolInstanceException("Protocol instance " + CURRENT_PROTOCOL_INSTANCE + " was expected; received " +
- protocolInstance);
+ throw new AMQProtocolHeaderException("Protocol header should have exactly four octets");
}
-
- /* Look through list of available protocol versions */
- boolean found = false;
- for (int i=0; i<pvl.pv.length; i++)
+ for(int i = 0; i < 4; i++)
{
- if (pvl.pv[i][pvl.PROTOCOL_MAJOR] == protocolMajor &&
- pvl.pv[i][pvl.PROTOCOL_MINOR] == protocolMinor)
+ if(_protocolHeader[i] != AMQP_HEADER[i])
{
- found = true;
+ try
+ {
+ throw new AMQProtocolHeaderException("Protocol header is not correct: Got " + new String(_protocolHeader,"ISO-8859-1") + " should be: " + new String(AMQP_HEADER, "ISO-8859-1"));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+
+ }
}
}
- if (!found)
+ if (_protocolClass != CURRENT_PROTOCOL_CLASS)
+ {
+ throw new AMQProtocolClassException("Protocol class " + CURRENT_PROTOCOL_CLASS + " was expected; received " +
+ _protocolClass);
+ }
+ if (_protocolInstance != TCP_PROTOCOL_INSTANCE)
+ {
+ throw new AMQProtocolInstanceException("Protocol instance " + TCP_PROTOCOL_INSTANCE + " was expected; received " +
+ _protocolInstance);
+ }
+
+ ProtocolVersion pv = new ProtocolVersion(_protocolMajor, _protocolMinor);
+
+
+ if (!pv.isSupported())
{
// TODO: add list of available versions in list to msg...
throw new AMQProtocolVersionException("Protocol version " +
- protocolMajor + "." + protocolMinor + " not found in protocol version list.");
+ _protocolMajor + "." + _protocolMinor + " not suppoerted by this version of the Qpid broker.");
}
}
public String toString()
{
- StringBuffer buffer = new StringBuffer(new String(header));
- buffer.append(Integer.toHexString(protocolClass));
- buffer.append(Integer.toHexString(protocolInstance));
- buffer.append(Integer.toHexString(protocolMajor));
- buffer.append(Integer.toHexString(protocolMinor));
+ StringBuffer buffer = new StringBuffer(new String(_protocolHeader));
+ buffer.append(Integer.toHexString(_protocolClass));
+ buffer.append(Integer.toHexString(_protocolInstance));
+ buffer.append(Integer.toHexString(_protocolMajor));
+ buffer.append(Integer.toHexString(_protocolMinor));
return buffer.toString();
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java b/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java
index ec371453aa..ebe0b91cf4 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java
@@ -179,7 +179,7 @@ public class VersionSpecificRegistry
}
- return bodyFactory.newInstance(_protocolMajorVersion, _protocolMinorVersion, classID, methodID, in, size);
+ return bodyFactory.newInstance(in, size);
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/abstraction/MessagePublishInfoConverter.java b/java/common/src/main/java/org/apache/qpid/framing/abstraction/MessagePublishInfoConverter.java
index c9e15f18e3..d5da133837 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/abstraction/MessagePublishInfoConverter.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/abstraction/MessagePublishInfoConverter.java
@@ -18,12 +18,13 @@
package org.apache.qpid.framing.abstraction;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.framing.AMQMethodBody;
public interface MessagePublishInfoConverter
{
public MessagePublishInfo convertToInfo(AMQMethodBody body);
- public AMQMethodBody convertToBody(MessagePublishInfo info);
+ public AMQMethodBodyImpl convertToBody(MessagePublishInfo info);
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/abstraction/ProtocolVersionMethodConverter.java b/java/common/src/main/java/org/apache/qpid/framing/abstraction/ProtocolVersionMethodConverter.java
index 52e82cdf07..b8e460eb05 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/abstraction/ProtocolVersionMethodConverter.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/abstraction/ProtocolVersionMethodConverter.java
@@ -18,11 +18,12 @@
package org.apache.qpid.framing.abstraction;
+import org.apache.qpid.framing.AMQBodyImpl;
import org.apache.qpid.framing.AMQBody;
public interface ProtocolVersionMethodConverter extends MessagePublishInfoConverter
{
- AMQBody convertToBody(ContentChunk contentBody);
+ AMQBodyImpl convertToBody(ContentChunk contentBody);
ContentChunk convertToContentChunk(AMQBody body);
void configure();
diff --git a/java/common/src/main/java/org/apache/qpid/framing/amqp_8_0/AMQMethodBody_8_0.java b/java/common/src/main/java/org/apache/qpid/framing/amqp_8_0/AMQMethodBody_8_0.java
new file mode 100644
index 0000000000..5e7a04cfc5
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/framing/amqp_8_0/AMQMethodBody_8_0.java
@@ -0,0 +1,160 @@
+package org.apache.qpid.framing.amqp_8_0;
+
+import org.apache.qpid.framing.EncodingUtils;
+import org.apache.qpid.framing.AMQFrameDecodingException;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.FieldTable;
+
+import org.apache.mina.common.ByteBuffer;
+
+public abstract class AMQMethodBody_8_0 extends org.apache.qpid.framing.AMQMethodBodyImpl
+{
+
+ public byte getMajor()
+ {
+ return 8;
+ }
+
+ public byte getMinor()
+ {
+ return 0;
+ }
+
+ public int getSize()
+ {
+ return 2 + 2 + getBodySize();
+ }
+
+ public void writePayload(ByteBuffer buffer)
+ {
+ EncodingUtils.writeUnsignedShort(buffer, getClazz());
+ EncodingUtils.writeUnsignedShort(buffer, getMethod());
+ writeMethodPayload(buffer);
+ }
+
+
+ protected byte readByte(ByteBuffer buffer)
+ {
+ return buffer.get();
+ }
+
+ protected AMQShortString readAMQShortString(ByteBuffer buffer)
+ {
+ return EncodingUtils.readAMQShortString(buffer);
+ }
+
+ protected int getSizeOf(AMQShortString string)
+ {
+ return EncodingUtils.encodedShortStringLength(string);
+ }
+
+ protected void writeByte(ByteBuffer buffer, byte b)
+ {
+ buffer.put(b);
+ }
+
+ protected void writeAMQShortString(ByteBuffer buffer, AMQShortString string)
+ {
+ EncodingUtils.writeShortStringBytes(buffer, string);
+ }
+
+ protected int readInt(ByteBuffer buffer)
+ {
+ return buffer.getInt();
+ }
+
+ protected void writeInt(ByteBuffer buffer, int i)
+ {
+ buffer.putInt(i);
+ }
+
+ protected FieldTable readFieldTable(ByteBuffer buffer) throws AMQFrameDecodingException
+ {
+ return EncodingUtils.readFieldTable(buffer);
+ }
+
+ protected int getSizeOf(FieldTable table)
+ {
+ return EncodingUtils.encodedFieldTableLength(table); //To change body of created methods use File | Settings | File Templates.
+ }
+
+ protected void writeFieldTable(ByteBuffer buffer, FieldTable table)
+ {
+ EncodingUtils.writeFieldTableBytes(buffer, table);
+ }
+
+ protected long readLong(ByteBuffer buffer)
+ {
+ return buffer.getLong();
+ }
+
+ protected void writeLong(ByteBuffer buffer, long l)
+ {
+ buffer.putLong(l);
+ }
+
+ protected int getSizeOf(byte[] response)
+ {
+ return response.length; //To change body of created methods use File | Settings | File Templates.
+ }
+
+ protected void writeBytes(ByteBuffer buffer, byte[] data)
+ {
+ EncodingUtils.writeLongstr(buffer,data);
+ }
+
+ protected byte[] readBytes(ByteBuffer buffer)
+ {
+ return EncodingUtils.readLongstr(buffer);
+ }
+
+ protected short readShort(ByteBuffer buffer)
+ {
+ return EncodingUtils.readShort(buffer);
+ }
+
+ protected void writeShort(ByteBuffer buffer, short s)
+ {
+ EncodingUtils.writeShort(buffer, s);
+ }
+
+ protected short readUnsignedByte(ByteBuffer buffer)
+ {
+ return buffer.getUnsigned();
+ }
+
+ protected void writeUnsignedByte(ByteBuffer buffer, short unsignedByte)
+ {
+ EncodingUtils.writeUnsignedByte(buffer, unsignedByte);
+ }
+
+ protected byte readBitfield(ByteBuffer buffer)
+ {
+ return readByte(buffer);
+ }
+
+ protected int readUnsignedShort(ByteBuffer buffer)
+ {
+ return buffer.getUnsignedShort();
+ }
+
+ protected void writeBitfield(ByteBuffer buffer, byte bitfield0)
+ {
+ buffer.put(bitfield0);
+ }
+
+ protected void writeUnsignedShort(ByteBuffer buffer, int s)
+ {
+ EncodingUtils.writeUnsignedShort(buffer, s);
+ }
+
+ protected long readUnsignedInteger(ByteBuffer buffer)
+ {
+ return buffer.getUnsignedInt();
+ }
+ protected void writeUnsignedInteger(ByteBuffer buffer, long i)
+ {
+ EncodingUtils.writeUnsignedInteger(buffer, i);
+ }
+
+}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/amqp_8_0/AMQMethodFactory_8_0.java b/java/common/src/main/java/org/apache/qpid/framing/amqp_8_0/AMQMethodFactory_8_0.java
new file mode 100644
index 0000000000..188ed07a70
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/framing/amqp_8_0/AMQMethodFactory_8_0.java
@@ -0,0 +1,117 @@
+package org.apache.qpid.framing.amqp_8_0;
+
+import org.apache.qpid.framing.*;
+import org.apache.qpid.protocol.AMQConstant;
+
+import org.apache.mina.common.ByteBuffer;
+
+
+public class AMQMethodFactory_8_0 implements AMQMethodFactory
+{
+ private static final AMQShortString CLIENT_INITIATED_CONNECTION_CLOSE =
+ new AMQShortString("Client initiated connection close");
+
+ public ConnectionCloseBody createConnectionClose()
+ {
+ return new ConnectionCloseBodyImpl(AMQConstant.REPLY_SUCCESS.getCode(),
+ CLIENT_INITIATED_CONNECTION_CLOSE,
+ 0,
+ 0);
+ }
+
+ public AccessRequestBody createAccessRequest(boolean active, boolean exclusive, boolean passive, boolean read, AMQShortString realm, boolean write)
+ {
+ return new AccessRequestBodyImpl(realm,exclusive,passive,active,write,read);
+ }
+
+ public TxSelectBody createTxSelect()
+ {
+ return new TxSelectBodyImpl();
+ }
+
+ public TxCommitBody createTxCommit()
+ {
+ return new TxCommitBodyImpl();
+ }
+
+ public TxRollbackBody createTxRollback()
+ {
+ return new TxRollbackBodyImpl();
+ }
+
+ public ChannelOpenBody createChannelOpen()
+ {
+ return new ChannelOpenBodyImpl((AMQShortString)null);
+ }
+
+ public ChannelCloseBody createChannelClose(int replyCode, AMQShortString replyText)
+ {
+ return new ChannelCloseBodyImpl(replyCode, replyText, 0, 0);
+ }
+
+ public ExchangeDeclareBody createExchangeDeclare(AMQShortString name, AMQShortString type, int ticket)
+ {
+ return new ExchangeDeclareBodyImpl(ticket,name,type,false,false,false,false,false,null);
+ }
+
+ public ExchangeBoundBody createExchangeBound(AMQShortString exchangeName, AMQShortString queueName, AMQShortString routingKey)
+ {
+ return new ExchangeBoundBodyImpl(exchangeName,routingKey,queueName);
+ }
+
+ public QueueDeclareBody createQueueDeclare(AMQShortString name, FieldTable arguments, boolean autoDelete, boolean durable, boolean exclusive, boolean passive, int ticket)
+ {
+ return new QueueDeclareBodyImpl(ticket,name,passive,durable,exclusive,autoDelete,false,arguments);
+ }
+
+ public QueueBindBody createQueueBind(AMQShortString queueName, AMQShortString exchangeName, AMQShortString routingKey, FieldTable arguments, int ticket)
+ {
+ return new QueueBindBodyImpl(ticket,queueName,exchangeName,routingKey,false,arguments);
+ }
+
+ public QueueDeleteBody createQueueDelete(AMQShortString queueName, boolean ifEmpty, boolean ifUnused, int ticket)
+ {
+ return new QueueDeleteBodyImpl(ticket,queueName,ifUnused,ifEmpty,false);
+ }
+
+ public ChannelFlowBody createChannelFlow(boolean active)
+ {
+ return new ChannelFlowBodyImpl(active);
+ }
+
+
+ // In different versions of the protocol we change the class used for message transfer
+ // abstract this out so the appropriate methods are created
+ public AMQMethodBody createRecover(boolean requeue)
+ {
+ return new BasicRecoverBodyImpl(requeue);
+ }
+
+ public AMQMethodBody createConsumer(AMQShortString tag, AMQShortString queueName, FieldTable arguments, boolean noAck, boolean exclusive, boolean noLocal, int ticket)
+ {
+ return new BasicConsumeBodyImpl(ticket,queueName,tag,noLocal,noAck,exclusive,false,arguments);
+ }
+
+ public AMQMethodBody createConsumerCancel(AMQShortString consumerTag)
+ {
+ return new BasicCancelBodyImpl(consumerTag, false);
+ }
+
+ public AMQMethodBody createAcknowledge(long deliveryTag, boolean multiple)
+ {
+ return new BasicAckBodyImpl(deliveryTag,multiple);
+ }
+
+ public AMQMethodBody createRejectBody(long deliveryTag, boolean requeue)
+ {
+ return new BasicRejectBodyImpl(deliveryTag, requeue);
+ }
+
+ public AMQMethodBody createMessageQos(int prefetchCount, int prefetchSize)
+ {
+ return new BasicQosBodyImpl(prefetchSize, prefetchCount, false);
+ }
+
+
+
+}
diff --git a/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java b/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java
index 8126ca4bc8..17a2ec5d4e 100644
--- a/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java
+++ b/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java
@@ -136,6 +136,7 @@ public class PoolingFilter extends IoFilterAdapter implements Job.JobCompletionH
public void exceptionCaught(final NextFilter nextFilter, final IoSession session,
final Throwable cause) throws Exception
{
+ cause.printStackTrace();
nextFilter.exceptionCaught(session,cause);
}
diff --git a/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodEvent.java b/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodEvent.java
index ab36041cb8..db76b6fe7e 100644
--- a/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodEvent.java
+++ b/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodEvent.java
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.protocol;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.framing.AMQMethodBody;
/**
diff --git a/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodListener.java b/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodListener.java
index 85bbe50b11..75ae6645e8 100644
--- a/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodListener.java
+++ b/java/common/src/main/java/org/apache/qpid/protocol/AMQMethodListener.java
@@ -21,6 +21,7 @@
package org.apache.qpid.protocol;
import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQMethodBodyImpl;
import org.apache.qpid.framing.AMQMethodBody;
/**
@@ -32,7 +33,6 @@ public interface AMQMethodListener
/**
* Invoked when a method frame has been received
* @param evt the event that contains the method and channel
- * @param protocolSession the protocol session associated with the event
* @return true if the handler has processed the method frame, false otherwise. Note
* that this does not prohibit the method event being delivered to subsequent listeners
* but can be used to determine if nobody has dealt with an incoming method frame.
@@ -40,7 +40,7 @@ public interface AMQMethodListener
* to all registered listeners using the error() method (see below) allowing them to
* perform cleanup if necessary.
*/
- <B extends AMQMethodBody> boolean methodReceived(AMQMethodEvent<B> evt) throws Exception;
+ <B extends AMQMethodBody> boolean methodReceived(AMQMethodEvent<B> evt) throws AMQException;
/**
* Callback when an error has occurred. Allows listeners to clean up.
diff --git a/java/common/src/main/java/org/apache/qpid/protocol/AMQVersionAwareProtocolSession.java b/java/common/src/main/java/org/apache/qpid/protocol/AMQVersionAwareProtocolSession.java
index b57c26e496..65f60e7f59 100644
--- a/java/common/src/main/java/org/apache/qpid/protocol/AMQVersionAwareProtocolSession.java
+++ b/java/common/src/main/java/org/apache/qpid/protocol/AMQVersionAwareProtocolSession.java
@@ -20,9 +20,9 @@
*/
package org.apache.qpid.protocol;
-import org.apache.qpid.framing.VersionSpecificRegistry;
+import org.apache.qpid.framing.MethodRegistry;
public interface AMQVersionAwareProtocolSession extends AMQProtocolWriter, ProtocolVersionAware
{
- public VersionSpecificRegistry getRegistry();
+ public MethodRegistry getRegistry();
}
diff --git a/java/common/src/main/java/org/apache/qpid/protocol/ProtocolVersionAware.java b/java/common/src/main/java/org/apache/qpid/protocol/ProtocolVersionAware.java
index 64db953bc2..c2c0bf29b7 100644
--- a/java/common/src/main/java/org/apache/qpid/protocol/ProtocolVersionAware.java
+++ b/java/common/src/main/java/org/apache/qpid/protocol/ProtocolVersionAware.java
@@ -20,9 +20,10 @@
*/
package org.apache.qpid.protocol;
+import org.apache.qpid.framing.ProtocolVersion;
+
public interface ProtocolVersionAware
{
- public byte getProtocolMinorVersion();
+ public ProtocolVersion getProtocolVersion();
- public byte getProtocolMajorVersion();
}
diff --git a/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java b/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java
index 0f706ac553..4fd1f60d69 100644
--- a/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java
+++ b/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java
@@ -22,8 +22,6 @@ package org.apache.qpid.framing;
import org.apache.mina.common.ByteBuffer;
-import java.util.HashMap;
-
import junit.framework.TestCase;
@@ -94,14 +92,14 @@ public class BasicContentHeaderPropertiesTest extends TestCase
{
String contentType = "contentType";
_testProperties.setContentType(contentType);
- assertEquals(contentType, _testProperties.getContentType());
+ assertEquals(contentType, _testProperties.getContentTypeAsString());
}
public void testSetGetEncoding()
{
String encoding = "encoding";
_testProperties.setEncoding(encoding);
- assertEquals(encoding, _testProperties.getEncoding());
+ assertEquals(encoding, _testProperties.getEncodingAsString());
}
public void testSetGetHeaders()
@@ -128,14 +126,14 @@ public class BasicContentHeaderPropertiesTest extends TestCase
{
String correlationId = "correlationId";
_testProperties.setCorrelationId(correlationId);
- assertEquals(correlationId, _testProperties.getCorrelationId());
+ assertEquals(correlationId, _testProperties.getCorrelationIdAsString());
}
public void testSetGetReplyTo()
{
String replyTo = "replyTo";
_testProperties.setReplyTo(replyTo);
- assertEquals(replyTo, _testProperties.getReplyTo());
+ assertEquals(replyTo, _testProperties.getReplyToAsString());
}
public void testSetGetExpiration()
@@ -149,7 +147,7 @@ public class BasicContentHeaderPropertiesTest extends TestCase
{
String messageId = "messageId";
_testProperties.setMessageId(messageId);
- assertEquals(messageId, _testProperties.getMessageId());
+ assertEquals(messageId, _testProperties.getMessageIdAsString());
}
public void testSetGetTimestamp()
@@ -163,28 +161,28 @@ public class BasicContentHeaderPropertiesTest extends TestCase
{
String type = "type";
_testProperties.setType(type);
- assertEquals(type, _testProperties.getType());
+ assertEquals(type, _testProperties.getTypeAsString());
}
public void testSetGetUserId()
{
String userId = "userId";
_testProperties.setUserId(userId);
- assertEquals(userId, _testProperties.getUserId());
+ assertEquals(userId, _testProperties.getUserIdAsString());
}
public void testSetGetAppId()
{
String appId = "appId";
_testProperties.setAppId(appId);
- assertEquals(appId, _testProperties.getAppId());
+ assertEquals(appId, _testProperties.getAppIdAsString());
}
public void testSetGetClusterId()
{
String clusterId = "clusterId";
_testProperties.setClusterId(clusterId);
- assertEquals(clusterId, _testProperties.getClusterId());
+ assertEquals(clusterId, _testProperties.getClusterIdAsString());
}
}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/queue/MockProtocolSession.java b/java/systests/src/main/java/org/apache/qpid/server/queue/MockProtocolSession.java
index bab7954d11..c334547b7f 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/queue/MockProtocolSession.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/queue/MockProtocolSession.java
@@ -26,6 +26,7 @@ import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.VersionSpecificRegistry;
import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.output.ProtocolOutputConverter;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.store.MessageStore;
@@ -170,6 +171,11 @@ public class MockProtocolSession implements AMQProtocolSession
//To change body of implemented methods use File | Settings | File Templates.
}
+ public ProtocolOutputConverter getProtocolOutputConverter()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
public byte getProtocolMajorVersion()
{
return 8; //To change body of implemented methods use File | Settings | File Templates.