From a838bf047951e264d40ae1e59fbfe88aae854bf5 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Fri, 23 Sep 2016 17:25:36 -0400 Subject: [PATCH] ARTEMIS-751 Simplification of the AMQP implementation Since we don't need client implementations any longer, given the maturity level of qpid jms, these classes can go, as a result a lot of the interfaces can be removed. As part of this I am removing proton-plug, and reorganizing the packages in a way I think it makes more sense and easier to other developers to understand and maintain it. https://issues.apache.org/jira/browse/ARTEMIS-751 --- .../activemq/artemis/utils/ByteUtil.java | 57 +++ .../src/main/assembly/dep.xml | 1 - .../src/main/resources/features.xml | 1 - .../artemis-amqp-protocol/pom.xml | 5 - .../amqp/broker/AMQPConnectionCallback.java} | 69 ++-- .../amqp/broker/AMQPSessionCallback.java} | 71 ++-- .../ActiveMQProtonRemotingConnection.java | 4 +- .../amqp/broker}/ProtonProtocolManager.java | 20 +- .../broker}/ProtonProtocolManagerFactory.java | 2 +- .../protocol/amqp/broker/package-info.java} | 15 +- .../amqp}/converter/ActiveMQJMSVendor.java | 18 +- .../converter/ProtonMessageConverter.java | 14 +- .../converter/jms/ServerDestination.java | 2 +- .../converter/jms/ServerJMSBytesMessage.java | 2 +- .../converter/jms/ServerJMSMapMessage.java | 2 +- .../amqp}/converter/jms/ServerJMSMessage.java | 2 +- .../converter/jms/ServerJMSObjectMessage.java | 2 +- .../converter/jms/ServerJMSStreamMessage.java | 2 +- .../converter/jms/ServerJMSTextMessage.java | 2 +- .../message/AMQPMessageIdHelper.java | 4 +- .../converter/message/AMQPMessageTypes.java | 2 +- .../message/AMQPNativeInboundTransformer.java | 2 +- .../AMQPNativeOutboundTransformer.java | 2 +- .../message/AMQPRawInboundTransformer.java | 2 +- .../converter/message/EncodedMessage.java | 2 +- .../converter/message/InboundTransformer.java | 2 +- .../message/JMSMappingInboundTransformer.java | 2 +- .../JMSMappingOutboundTransformer.java | 10 +- .../amqp}/converter/message/JMSVendor.java | 2 +- .../message/OutboundTransformer.java | 2 +- .../amqp/converter/package-info.java} | 11 +- .../exceptions/ActiveMQAMQPException.java | 2 +- .../ActiveMQAMQPIllegalStateException.java | 2 +- .../ActiveMQAMQPInternalErrorException.java | 2 +- .../ActiveMQAMQPInvalidFieldException.java | 2 +- .../ActiveMQAMQPNotFoundException.java | 2 +- .../ActiveMQAMQPNotImplementedException.java | 2 +- ...eMQAMQPResourceLimitExceededException.java | 2 +- .../ActiveMQAMQPTimeoutException.java | 2 +- .../ActiveMQAMQPProtocolMessageBundle.java | 10 +- .../amqp/proton/AMQPConnectionContext.java} | 206 +++++++---- .../protocol/amqp/proton}/AMQPConstants.java | 2 +- .../amqp/proton/AMQPSessionContext.java | 221 ++++++++++++ .../protocol/amqp/proton}/AmqpSupport.java | 2 +- .../amqp/proton}/ProtonDeliveryHandler.java | 4 +- .../amqp/proton/ProtonInitializable.java} | 16 +- .../proton}/ProtonServerReceiverContext.java | 82 ++++- .../proton}/ProtonServerSenderContext.java | 121 +++++-- .../proton}/ProtonTransactionHandler.java | 16 +- .../amqp/proton}/handler/EventHandler.java | 2 +- .../protocol/amqp/proton}/handler/Events.java | 5 +- .../amqp/proton}/handler/ExtCapability.java | 10 +- .../amqp/proton/handler/ProtonHandler.java} | 52 +-- .../protocol/amqp/proton/package-info.java} | 10 +- .../amqp}/sasl/AnonymousServerSASL.java | 5 +- .../amqp/sasl/PlainSASL.java} | 7 +- .../protocol/amqp}/sasl/PlainSASLResult.java | 4 +- .../protocol/amqp/sasl}/SASLResult.java | 2 +- .../protocol/amqp/sasl}/ServerSASL.java | 2 +- .../protocol/amqp}/sasl/ServerSASLPlain.java | 5 +- .../protocol/amqp}/util/CodecCache.java | 2 +- .../protocol/amqp}/util/CreditsSemaphore.java | 2 +- .../protocol/amqp}/util/DeliveryUtil.java | 2 +- .../protocol/amqp}/util/NettyWritable.java | 2 +- .../amqp}/util/ProtonServerMessage.java | 2 +- ...s.spi.core.protocol.ProtocolManagerFactory | 2 +- .../amqp/converter}/TestConversions.java | 19 +- .../protocol/amqp}/sasl/ClientSASLPlain.java | 11 +- .../protocol/amqp}/sasl/PlainSASLTest.java | 5 +- .../amqp}/util/CreditsSemaphoreTest.java | 3 +- artemis-protocols/artemis-proton-plug/pom.xml | 137 ------- .../plug/AMQPClientConnectionContext.java | 36 -- .../plug/AMQPClientReceiverContext.java | 34 -- .../proton/plug/AMQPClientSenderContext.java | 27 -- .../proton/plug/AMQPClientSessionContext.java | 30 -- .../proton/plug/AMQPConnectionCallback.java | 58 --- .../proton/plug/AMQPConnectionContext.java | 71 ---- .../plug/AMQPConnectionContextFactory.java | 39 -- .../plug/AMQPServerConnectionContext.java | 21 -- .../org/proton/plug/AMQPSessionCallback.java | 112 ------ .../org/proton/plug/AMQPSessionContext.java | 34 -- .../context/AbstractProtonContextSender.java | 153 -------- .../AbstractProtonReceiverContext.java | 88 ----- .../context/AbstractProtonSessionContext.java | 161 --------- .../plug/context/ProtonInitializable.java | 67 ---- .../client/ProtonClientConnectionContext.java | 107 ------ .../ProtonClientConnectionContextFactory.java | 50 --- .../context/client/ProtonClientContext.java | 76 ---- .../client/ProtonClientReceiverContext.java | 92 ----- .../client/ProtonClientSessionContext.java | 145 -------- .../server/ProtonServerConnectionContext.java | 94 ----- .../ProtonServerConnectionContextFactory.java | 53 --- .../server/ProtonServerSessionContext.java | 117 ------ .../proton/plug/handler/ProtonHandler.java | 133 ------- .../handler/impl/DefaultEventHandler.java | 144 -------- .../java/org/proton/plug/util/ByteUtil.java | 130 ------- .../org/proton/plug/util/FutureRunnable.java | 61 ---- .../org/proton/plug/util/ReusableLatch.java | 130 ------- .../AbstractConnectionContextTest.java | 137 ------- .../org/proton/plug/test/AbstractJMSTest.java | 93 ----- .../java/org/proton/plug/test/ProtonTest.java | 335 ------------------ .../plug/test/invm/InVMTestConnector.java | 40 --- .../proton/plug/test/invm/ProtonINVMSPI.java | 240 ------------- .../test/minimalclient/AMQPClientSPI.java | 140 -------- .../minimalclient/SimpleAMQPConnector.java | 76 ---- .../plug/test/minimalserver/DumbServer.java | 52 --- .../minimalserver/MinimalConnectionSPI.java | 171 --------- .../test/minimalserver/MinimalServer.java | 167 --------- .../test/minimalserver/MinimalSessionSPI.java | 229 ------------ .../SimpleServerThreadFactory.java | 82 ----- .../plug/test/util/ReusableLatchTest.java | 300 ---------------- .../test/util/SimpleServerAbstractTest.java | 67 ---- artemis-protocols/pom.xml | 1 - tests/integration-tests/pom.xml | 12 - .../ProtonMaxFrameSizeTest.java | 2 +- .../{proton => amqp}/ProtonPubSubTest.java | 82 +---- .../{proton => amqp}/ProtonTest.java | 174 +-------- .../{proton => amqp}/ProtonTestBase.java | 2 +- .../{proton => amqp}/ProtonTestForHeader.java | 2 +- .../{jms => }/SendingAndReceivingTest.java | 2 +- 120 files changed, 774 insertions(+), 5216 deletions(-) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton/plug/ActiveMQProtonConnectionCallback.java => protocol/amqp/broker/AMQPConnectionCallback.java} (76%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton/plug/ProtonSessionIntegrationCallback.java => protocol/amqp/broker/AMQPSessionCallback.java} (90%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp/broker}/ActiveMQProtonRemotingConnection.java (96%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp/broker}/ProtonProtocolManager.java (84%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp/broker}/ProtonProtocolManagerFactory.java (97%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonPlugSender.java => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/package-info.java} (74%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/ActiveMQJMSVendor.java (86%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/ProtonMessageConverter.java (85%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/jms/ServerDestination.java (94%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/jms/ServerJMSBytesMessage.java (98%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/jms/ServerJMSMapMessage.java (99%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/jms/ServerJMSMessage.java (99%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/jms/ServerJMSObjectMessage.java (97%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/jms/ServerJMSStreamMessage.java (99%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/jms/ServerJMSTextMessage.java (97%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/AMQPMessageIdHelper.java (98%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/AMQPMessageTypes.java (93%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/AMQPNativeInboundTransformer.java (95%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/AMQPNativeOutboundTransformer.java (96%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/AMQPRawInboundTransformer.java (96%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/EncodedMessage.java (96%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/InboundTransformer.java (99%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/JMSMappingInboundTransformer.java (98%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/JMSMappingOutboundTransformer.java (96%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/JMSVendor.java (95%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp}/converter/message/OutboundTransformer.java (96%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug/ClientSASL.java => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/package-info.java} (83%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/exceptions/ActiveMQAMQPException.java (96%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/exceptions/ActiveMQAMQPIllegalStateException.java (94%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/exceptions/ActiveMQAMQPInternalErrorException.java (95%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/exceptions/ActiveMQAMQPInvalidFieldException.java (94%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/exceptions/ActiveMQAMQPNotFoundException.java (94%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/exceptions/ActiveMQAMQPNotImplementedException.java (94%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/exceptions/ActiveMQAMQPResourceLimitExceededException.java (95%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/exceptions/ActiveMQAMQPTimeoutException.java (94%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/logger/ActiveMQAMQPProtocolMessageBundle.java (89%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractConnectionContext.java => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java} (67%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug/context => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton}/AMQPConstants.java (95%) create mode 100644 artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPSessionContext.java rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton}/AmqpSupport.java (98%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug/context => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton}/ProtonDeliveryHandler.java (91%) rename artemis-protocols/{artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/Connector.java => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonInitializable.java} (71%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug/context/server => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton}/ProtonServerReceiverContext.java (70%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug/context/server => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton}/ProtonServerSenderContext.java (82%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug/context => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton}/ProtonTransactionHandler.java (90%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton}/handler/EventHandler.java (97%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton}/handler/Events.java (97%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton}/handler/ExtCapability.java (82%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug/handler/impl/ProtonHandlerImpl.java => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java} (90%) rename artemis-protocols/{artemis-proton-plug/src/test/java/org/proton/plug/test/Constants.java => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/package-info.java} (78%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/sasl/AnonymousServerSASL.java (91%) rename artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/{core/protocol/proton/sasl/ActiveMQPlainSASL.java => protocol/amqp/sasl/PlainSASL.java} (85%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/sasl/PlainSASLResult.java (95%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl}/SASLResult.java (94%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl}/ServerSASL.java (94%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/sasl/ServerSASLPlain.java (94%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/util/CodecCache.java (96%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/util/CreditsSemaphore.java (98%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/util/DeliveryUtil.java (97%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/util/NettyWritable.java (97%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp}/util/ProtonServerMessage.java (99%) rename artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/{core/protocol/proton => protocol/amqp/converter}/TestConversions.java (95%) rename artemis-protocols/{artemis-proton-plug/src/main/java/org/proton/plug => artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp}/sasl/ClientSASLPlain.java (80%) rename artemis-protocols/{artemis-proton-plug/src/test/java/org/proton/plug/test => artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp}/sasl/PlainSASLTest.java (88%) rename artemis-protocols/{artemis-proton-plug/src/test/java/org/proton/plug/test => artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp}/util/CreditsSemaphoreTest.java (97%) delete mode 100644 artemis-protocols/artemis-proton-plug/pom.xml delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientConnectionContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientReceiverContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientSenderContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientSessionContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionCallback.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionContextFactory.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPServerConnectionContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPSessionCallback.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPSessionContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonContextSender.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonReceiverContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonSessionContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonInitializable.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientConnectionContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientConnectionContextFactory.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientReceiverContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientSessionContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContextFactory.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerSessionContext.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/ProtonHandler.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/impl/DefaultEventHandler.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ByteUtil.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/FutureRunnable.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ReusableLatch.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/context/AbstractConnectionContextTest.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/AbstractJMSTest.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/ProtonTest.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/invm/InVMTestConnector.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/invm/ProtonINVMSPI.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/AMQPClientSPI.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/SimpleAMQPConnector.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/DumbServer.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalConnectionSPI.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalServer.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalSessionSPI.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/SimpleServerThreadFactory.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/ReusableLatchTest.java delete mode 100644 artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/SimpleServerAbstractTest.java rename tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/{proton => amqp}/ProtonMaxFrameSizeTest.java (98%) rename tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/{proton => amqp}/ProtonPubSubTest.java (73%) rename tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/{proton => amqp}/ProtonTest.java (89%) rename tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/{proton => amqp}/ProtonTestBase.java (97%) rename tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/{proton => amqp}/ProtonTestForHeader.java (99%) rename tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/{jms => }/SendingAndReceivingTest.java (97%) diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java index 79210721a14..c6789411d67 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java @@ -22,6 +22,7 @@ import io.netty.buffer.UnpooledByteBufAllocator; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.SimpleString; +import org.jboss.logging.Logger; public class ByteUtil { @@ -29,6 +30,52 @@ public class ByteUtil { private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); + public static void debugFrame(Logger logger, String message, ByteBuf byteIn) { + if (logger.isTraceEnabled()) { + int location = byteIn.readerIndex(); + // debugging + byte[] frame = new byte[byteIn.writerIndex()]; + byteIn.readBytes(frame); + + try { + logger.trace(message + "\n" + ByteUtil.formatGroup(ByteUtil.bytesToHex(frame), 8, 16)); + } + catch (Exception e) { + logger.warn(e.getMessage(), e); + } + + byteIn.readerIndex(location); + } + } + + + public static String formatGroup(String str, int groupSize, int lineBreak) { + StringBuffer buffer = new StringBuffer(); + + int line = 1; + buffer.append("/* 1 */ \""); + for (int i = 0; i < str.length(); i += groupSize) { + buffer.append(str.substring(i, i + Math.min(str.length() - i, groupSize))); + + if ((i + groupSize) % lineBreak == 0) { + buffer.append("\" +\n/* "); + line++; + if (line < 10) { + buffer.append(" "); + } + buffer.append(Integer.toString(line) + " */ \""); + } + else if ((i + groupSize) % groupSize == 0 && str.length() - i > groupSize) { + buffer.append("\" + \""); + } + } + + buffer.append("\";"); + + return buffer.toString(); + + } + public static String maxString(String value, int size) { if (value.length() < size) { return value; @@ -38,6 +85,16 @@ public static String maxString(String value, int size) { } } + public static String bytesToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for (int j = 0; j < bytes.length; j++) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + public static String bytesToHex(byte[] bytes, int groupSize) { char[] hexChars = new char[bytes.length * 2 + numberOfGroups(bytes, groupSize)]; int outPos = 0; diff --git a/artemis-distribution/src/main/assembly/dep.xml b/artemis-distribution/src/main/assembly/dep.xml index a62ef25d6a6..a50fe790810 100644 --- a/artemis-distribution/src/main/assembly/dep.xml +++ b/artemis-distribution/src/main/assembly/dep.xml @@ -58,7 +58,6 @@ org.apache.activemq:artemis-native org.apache.activemq:artemis-amqp-protocol org.apache.activemq:artemis-openwire-protocol - org.apache.activemq:artemis-proton-plug org.apache.activemq:artemis-hornetq-protocol org.apache.activemq:artemis-hqclient-protocol org.apache.activemq:artemis-stomp-protocol diff --git a/artemis-features/src/main/resources/features.xml b/artemis-features/src/main/resources/features.xml index 26776261bc1..7e477aa5096 100644 --- a/artemis-features/src/main/resources/features.xml +++ b/artemis-features/src/main/resources/features.xml @@ -63,7 +63,6 @@ artemis-core wrap:mvn:org.apache.qpid/proton-j/${proton.version} wrap:mvn:org.apache.qpid/qpid-jms-client/${qpid.jms.version} - mvn:org.apache.activemq/artemis-proton-plug/${pom.version} mvn:org.apache.activemq/artemis-amqp-protocol/${pom.version} diff --git a/artemis-protocols/artemis-amqp-protocol/pom.xml b/artemis-protocols/artemis-amqp-protocol/pom.xml index e623ef8cdd4..aac507ed1d0 100644 --- a/artemis-protocols/artemis-amqp-protocol/pom.xml +++ b/artemis-protocols/artemis-amqp-protocol/pom.xml @@ -74,11 +74,6 @@ artemis-server ${project.version} - - org.apache.activemq - artemis-proton-plug - ${project.version} - org.apache.qpid proton-j diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/plug/ActiveMQProtonConnectionCallback.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPConnectionCallback.java similarity index 76% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/plug/ActiveMQProtonConnectionCallback.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPConnectionCallback.java index d5b2ff7385f..fd7954793ec 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/plug/ActiveMQProtonConnectionCallback.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPConnectionCallback.java @@ -14,12 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.plug; +package org.apache.activemq.artemis.protocol.amqp.broker; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -33,15 +30,15 @@ import org.apache.activemq.artemis.api.core.ActiveMQBuffers; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper; -import org.apache.activemq.artemis.core.protocol.proton.ActiveMQProtonRemotingConnection; -import org.apache.activemq.artemis.core.protocol.proton.ProtonProtocolManager; -import org.apache.activemq.artemis.core.protocol.proton.sasl.ActiveMQPlainSASL; +import org.apache.activemq.artemis.protocol.amqp.sasl.AnonymousServerSASL; +import org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASL; import org.apache.activemq.artemis.core.remoting.CloseListener; import org.apache.activemq.artemis.core.remoting.FailureListener; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.transaction.Transaction; import org.apache.activemq.artemis.core.transaction.impl.TransactionImpl; import org.apache.activemq.artemis.core.transaction.impl.XidImpl; +import org.apache.activemq.artemis.protocol.amqp.proton.AmqpSupport; import org.apache.activemq.artemis.spi.core.remoting.Connection; import org.apache.activemq.artemis.utils.ReusableLatch; import org.apache.activemq.artemis.utils.UUIDGenerator; @@ -49,27 +46,17 @@ import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.transport.AmqpError; import org.jboss.logging.Logger; -import org.proton.plug.AMQPConnectionCallback; -import org.proton.plug.AMQPConnectionContext; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.SASLResult; -import org.proton.plug.ServerSASL; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.handler.ExtCapability; -import org.proton.plug.logger.ActiveMQAMQPProtocolMessageBundle; -import org.proton.plug.sasl.AnonymousServerSASL; - -import static org.proton.plug.AmqpSupport.CONTAINER_ID; -import static org.proton.plug.AmqpSupport.INVALID_FIELD; -import static org.proton.plug.context.AbstractConnectionContext.CONNECTION_OPEN_FAILED; - -public class ActiveMQProtonConnectionCallback implements AMQPConnectionCallback, FailureListener, CloseListener { - private static final Logger logger = Logger.getLogger(ActiveMQProtonConnectionCallback.class); - private static final List connectedContainers = Collections.synchronizedList(new ArrayList()); +import org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult; +import org.apache.activemq.artemis.protocol.amqp.sasl.ServerSASL; +import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException; +import org.apache.activemq.artemis.protocol.amqp.proton.handler.ExtCapability; +import org.apache.activemq.artemis.protocol.amqp.logger.ActiveMQAMQPProtocolMessageBundle; - private ConcurrentMap transactions = new ConcurrentHashMap<>(); +public class AMQPConnectionCallback implements FailureListener, CloseListener { + private static final Logger logger = Logger.getLogger(AMQPConnectionCallback.class); - private static final Logger log = Logger.getLogger(ActiveMQProtonConnectionCallback.class); + private ConcurrentMap transactions = new ConcurrentHashMap<>(); private final ProtonProtocolManager manager; @@ -89,32 +76,30 @@ public class ActiveMQProtonConnectionCallback implements AMQPConnectionCallback, private ActiveMQServer server; - public ActiveMQProtonConnectionCallback(ProtonProtocolManager manager, - Connection connection, - Executor closeExecutor, - ActiveMQServer server) { + public AMQPConnectionCallback(ProtonProtocolManager manager, + Connection connection, + Executor closeExecutor, + ActiveMQServer server) { this.manager = manager; this.connection = connection; this.closeExecutor = closeExecutor; this.server = server; } - @Override public ServerSASL[] getSASLMechnisms() { ServerSASL[] result; if (isSupportsAnonymous()) { - result = new ServerSASL[]{new ActiveMQPlainSASL(manager.getServer().getSecurityStore()), new AnonymousServerSASL()}; + result = new ServerSASL[]{new PlainSASL(manager.getServer().getSecurityStore()), new AnonymousServerSASL()}; } else { - result = new ServerSASL[]{new ActiveMQPlainSASL(manager.getServer().getSecurityStore())}; + result = new ServerSASL[]{new PlainSASL(manager.getServer().getSecurityStore())}; } return result; } - @Override public boolean isSupportsAnonymous() { boolean supportsAnonymous = false; try { @@ -127,7 +112,6 @@ public boolean isSupportsAnonymous() { return supportsAnonymous; } - @Override public void close() { try { if (registeredConnectionId.getAndSet(false)) { @@ -157,12 +141,10 @@ public Executor getExeuctor() { } } - @Override public void setConnection(AMQPConnectionContext connection) { this.amqpConnection = connection; } - @Override public AMQPConnectionContext getConnection() { return amqpConnection; } @@ -176,7 +158,6 @@ public void setProtonConnectionDelegate(ActiveMQProtonRemotingConnection protonC this.protonConnectionDelegate = protonConnectionDelegate; } - @Override public void onTransport(ByteBuf byteBuf, AMQPConnectionContext amqpConnection) { final int size = byteBuf.writerIndex(); @@ -200,28 +181,25 @@ public void operationComplete(ChannelFuture future) throws Exception { amqpConnection.outputDone(size); } - @Override public AMQPSessionCallback createSessionCallback(AMQPConnectionContext connection) { - return new ProtonSessionIntegrationCallback(this, manager, connection, this.connection, closeExecutor); + return new AMQPSessionCallback(this, manager, connection, this.connection, closeExecutor); } - @Override public void sendSASLSupported() { connection.write(ActiveMQBuffers.wrappedBuffer(new byte[]{'A', 'M', 'Q', 'P', 3, 1, 0, 0})); } - @Override public boolean validateConnection(org.apache.qpid.proton.engine.Connection connection, SASLResult saslResult) { remoteContainerId = connection.getRemoteContainer(); boolean idOK = server.addClientConnection(remoteContainerId, ExtCapability.needUniqueConnection(connection)); if (!idOK) { //https://issues.apache.org/jira/browse/ARTEMIS-728 Map connProp = new HashMap<>(); - connProp.put(CONNECTION_OPEN_FAILED, "true"); + connProp.put(AmqpSupport.CONNECTION_OPEN_FAILED, "true"); connection.setProperties(connProp); connection.getCondition().setCondition(AmqpError.INVALID_FIELD); Map info = new HashMap<>(); - info.put(INVALID_FIELD, CONTAINER_ID); + info.put(AmqpSupport.INVALID_FIELD, AmqpSupport.CONTAINER_ID); connection.getCondition().setInfo(info); return false; } @@ -244,7 +222,6 @@ public void connectionFailed(ActiveMQException exception, boolean failedOver, St close(); } - @Override public Binary newTransaction() { XidImpl xid = newXID(); Transaction transaction = new TransactionImpl(xid, server.getStorageManager(), -1); @@ -252,7 +229,6 @@ public Binary newTransaction() { return new Binary(xid.getGlobalTransactionId()); } - @Override public Transaction getTransaction(Binary txid) throws ActiveMQAMQPException { XidImpl xid = newXID(txid.getArray()); Transaction tx = transactions.get(xid); @@ -264,7 +240,6 @@ public Transaction getTransaction(Binary txid) throws ActiveMQAMQPException { return tx; } - @Override public void removeTransaction(Binary txid) { XidImpl xid = newXID(txid.getArray()); transactions.remove(xid); diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/plug/ProtonSessionIntegrationCallback.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPSessionCallback.java similarity index 90% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/plug/ProtonSessionIntegrationCallback.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPSessionCallback.java index da9dd9cf745..9bdf4e10278 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/plug/ProtonSessionIntegrationCallback.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPSessionCallback.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.plug; +package org.apache.activemq.artemis.protocol.amqp.broker; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; @@ -28,8 +28,8 @@ import org.apache.activemq.artemis.api.core.client.ActiveMQClient; import org.apache.activemq.artemis.core.io.IOCallback; import org.apache.activemq.artemis.core.paging.PagingStore; -import org.apache.activemq.artemis.core.protocol.proton.ProtonProtocolManager; -import org.apache.activemq.artemis.core.protocol.proton.converter.message.EncodedMessage; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException; +import org.apache.activemq.artemis.protocol.amqp.converter.message.EncodedMessage; import org.apache.activemq.artemis.core.server.BindingQueryResult; import org.apache.activemq.artemis.core.server.MessageReference; import org.apache.activemq.artemis.core.server.QueueQueryResult; @@ -39,6 +39,7 @@ import org.apache.activemq.artemis.core.server.impl.ServerConsumerImpl; import org.apache.activemq.artemis.core.transaction.Transaction; import org.apache.activemq.artemis.jms.client.ActiveMQConnection; +import org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult; import org.apache.activemq.artemis.spi.core.protocol.SessionCallback; import org.apache.activemq.artemis.spi.core.remoting.Connection; import org.apache.activemq.artemis.spi.core.remoting.ReadyListener; @@ -55,21 +56,18 @@ import org.apache.qpid.proton.engine.Link; import org.apache.qpid.proton.engine.Receiver; import org.apache.qpid.proton.message.ProtonJMessage; -import org.proton.plug.AMQPConnectionContext; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.AMQPSessionContext; -import org.proton.plug.SASLResult; -import org.proton.plug.context.ProtonPlugSender; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.exceptions.ActiveMQAMQPInternalErrorException; -import org.proton.plug.exceptions.ActiveMQAMQPResourceLimitExceededException; -import org.proton.plug.sasl.PlainSASLResult; - -public class ProtonSessionIntegrationCallback implements AMQPSessionCallback, SessionCallback { +import org.apache.activemq.artemis.protocol.amqp.proton.AMQPSessionContext; +import org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult; +import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext; +import org.apache.activemq.artemis.protocol.amqp.proton.ProtonServerSenderContext; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException; + +public class AMQPSessionCallback implements SessionCallback { protected final IDGenerator consumerIDGenerator = new SimpleIDGenerator(0); - private final ActiveMQProtonConnectionCallback protonSPI; + private final AMQPConnectionCallback protonSPI; private final ProtonProtocolManager manager; @@ -85,11 +83,11 @@ public class ProtonSessionIntegrationCallback implements AMQPSessionCallback, Se private final AtomicBoolean draining = new AtomicBoolean(false); - public ProtonSessionIntegrationCallback(ActiveMQProtonConnectionCallback protonSPI, - ProtonProtocolManager manager, - AMQPConnectionContext connection, - Connection transportConnection, - Executor executor) { + public AMQPSessionCallback(AMQPConnectionCallback protonSPI, + ProtonProtocolManager manager, + AMQPConnectionContext connection, + Connection transportConnection, + Executor executor) { this.protonSPI = protonSPI; this.manager = manager; this.connection = connection; @@ -102,13 +100,12 @@ public boolean isWritable(ReadyListener callback) { return transportConnection.isWritable(callback); } - @Override public void onFlowConsumer(Object consumer, int credits, final boolean drain) { ServerConsumerImpl serverConsumer = (ServerConsumerImpl) consumer; if (drain) { // If the draining is already running, then don't do anything if (draining.compareAndSet(false, true)) { - final ProtonPlugSender plugSender = (ProtonPlugSender) serverConsumer.getProtocolContext(); + final ProtonServerSenderContext plugSender = (ProtonServerSenderContext) serverConsumer.getProtocolContext(); serverConsumer.forceDelivery(1, new Runnable() { @Override public void run() { @@ -132,7 +129,6 @@ public void browserFinished(ServerConsumer consumer) { } - @Override public void init(AMQPSessionContext protonSession, SASLResult saslResult) throws Exception { this.protonSession = protonSession; @@ -161,13 +157,11 @@ public void afterDelivery() throws Exception { } - @Override public void start() { } - @Override - public Object createSender(ProtonPlugSender protonSender, + public Object createSender(ProtonServerSenderContext protonSender, String queue, String filter, boolean browserOnly) throws Exception { @@ -185,29 +179,24 @@ public Object createSender(ProtonPlugSender protonSender, return consumer; } - @Override public void startSender(Object brokerConsumer) throws Exception { ServerConsumer serverConsumer = (ServerConsumer) brokerConsumer; // flow control is done at proton serverConsumer.receiveCredits(-1); } - @Override public void createTemporaryQueue(String queueName) throws Exception { serverSession.createQueue(SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(queueName), null, true, false); } - @Override public void createTemporaryQueue(String address, String queueName, String filter) throws Exception { serverSession.createQueue(SimpleString.toSimpleString(address), SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(filter), true, false); } - @Override public void createDurableQueue(String address, String queueName, String filter) throws Exception { serverSession.createQueue(SimpleString.toSimpleString(address), SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(filter), false, true); } - @Override public QueueQueryResult queueQuery(String queueName, boolean autoCreate) throws Exception { QueueQueryResult queueQueryResult = serverSession.executeQueueQuery(SimpleString.toSimpleString(queueName)); @@ -223,7 +212,6 @@ public QueueQueryResult queueQuery(String queueName, boolean autoCreate) throws return queueQueryResult; } - @Override public boolean bindingQuery(String address) throws Exception { BindingQueryResult bindingQueryResult = serverSession.executeBindingQuery(SimpleString.toSimpleString(address)); if (!bindingQueryResult.isExists() && bindingQueryResult.isAutoCreateJmsQueues()) { @@ -238,7 +226,6 @@ public boolean bindingQuery(String address) throws Exception { return bindingQueryResult.isExists(); } - @Override public void closeSender(final Object brokerConsumer) throws Exception { final ServerConsumer consumer = ((ServerConsumer) brokerConsumer); @@ -276,17 +263,14 @@ public void run() { } } - @Override public ProtonJMessage encodeMessage(Object message, int deliveryCount) throws Exception { return (ProtonJMessage) manager.getConverter().outbound((ServerMessage) message, deliveryCount); } - @Override public String tempQueueName() { return UUIDGenerator.getInstance().generateStringUUID(); } - @Override public void close() throws Exception { //need to check here as this can be called if init fails if (serverSession != null) { @@ -300,7 +284,6 @@ public void close() throws Exception { } } - @Override public void ack(Transaction transaction, Object brokerConsumer, Object message) throws Exception { if (transaction == null) { transaction = serverSession.getCurrentTransaction(); @@ -314,7 +297,6 @@ public void ack(Transaction transaction, Object brokerConsumer, Object message) } } - @Override public void cancel(Object brokerConsumer, Object message, boolean updateCounts) throws Exception { recoverContext(); try { @@ -325,12 +307,10 @@ public void cancel(Object brokerConsumer, Object message, boolean updateCounts) } } - @Override public void resumeDelivery(Object consumer) { ((ServerConsumer) consumer).receiveCredits(-1); } - @Override public void serverSend(final Transaction transaction, final Receiver receiver, final Delivery delivery, @@ -406,12 +386,10 @@ public void onError(int errorCode, String errorMessage) { } } - @Override public String getPubSubPrefix() { return manager.getPubSubPrefix(); } - @Override public void offerProducerCredit(final String address, final int credits, final int threshold, final Receiver receiver) { try { final PagingStore store = manager.getServer().getPagingManager().getPageStore(new SimpleString(address)); @@ -430,7 +408,6 @@ public void run() { } } - @Override public void deleteQueue(String queueName) throws Exception { manager.getServer().destroyQueue(new SimpleString(queueName)); } @@ -461,7 +438,7 @@ public int sendMessage(MessageReference ref, ServerMessage message, ServerConsum message.removeProperty(ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME.toString()); - ProtonPlugSender plugSender = (ProtonPlugSender) consumer.getProtocolContext(); + ProtonServerSenderContext plugSender = (ProtonServerSenderContext) consumer.getProtocolContext(); try { return plugSender.deliverMessage(message, deliveryCount); @@ -503,7 +480,7 @@ public void disconnect(ServerConsumer consumer, String queueName) { @Override public boolean hasCredits(ServerConsumer consumer) { - ProtonPlugSender plugSender = (ProtonPlugSender) consumer.getProtocolContext(); + ProtonServerSenderContext plugSender = (ProtonServerSenderContext) consumer.getProtocolContext(); if (plugSender != null && plugSender.getSender().getCredit() > 0) { return true; @@ -513,25 +490,21 @@ public boolean hasCredits(ServerConsumer consumer) { } } - @Override public Transaction getTransaction(Binary txid) throws ActiveMQAMQPException { return protonSPI.getTransaction(txid); } - @Override public Binary newTransaction() { return protonSPI.newTransaction(); } - @Override public void commitTX(Binary txid) throws Exception { Transaction tx = protonSPI.getTransaction(txid); tx.commit(true); protonSPI.removeTransaction(txid); } - @Override public void rollbackTX(Binary txid, boolean lastMessageReceived) throws Exception { Transaction tx = protonSPI.getTransaction(txid); tx.rollback(); diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ActiveMQProtonRemotingConnection.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ActiveMQProtonRemotingConnection.java similarity index 96% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ActiveMQProtonRemotingConnection.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ActiveMQProtonRemotingConnection.java index 670ca5b9637..8fd3169fbcd 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ActiveMQProtonRemotingConnection.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ActiveMQProtonRemotingConnection.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton; +package org.apache.activemq.artemis.protocol.amqp.broker; import java.util.concurrent.Executor; @@ -24,7 +24,7 @@ import org.apache.activemq.artemis.core.client.ActiveMQClientLogger; import org.apache.activemq.artemis.spi.core.protocol.AbstractRemotingConnection; import org.apache.activemq.artemis.spi.core.remoting.Connection; -import org.proton.plug.AMQPConnectionContext; +import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext; /** * This is a Server's Connection representation used by ActiveMQ Artemis. diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManager.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ProtonProtocolManager.java similarity index 84% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManager.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ProtonProtocolManager.java index a2563a17dc9..fe7b9764ecc 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManager.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ProtonProtocolManager.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton; +package org.apache.activemq.artemis.protocol.amqp.broker; import java.util.Arrays; import java.util.List; @@ -25,8 +25,8 @@ import org.apache.activemq.artemis.api.core.BaseInterceptor; import org.apache.activemq.artemis.api.core.Interceptor; import org.apache.activemq.artemis.api.core.client.ActiveMQClient; -import org.apache.activemq.artemis.core.protocol.proton.converter.ProtonMessageConverter; -import org.apache.activemq.artemis.core.protocol.proton.plug.ActiveMQProtonConnectionCallback; +import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConstants; +import org.apache.activemq.artemis.protocol.amqp.converter.ProtonMessageConverter; import org.apache.activemq.artemis.core.remoting.impl.netty.NettyServerConnection; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.management.Notification; @@ -39,11 +39,7 @@ import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection; import org.apache.activemq.artemis.spi.core.remoting.Acceptor; import org.apache.activemq.artemis.spi.core.remoting.Connection; -import org.proton.plug.AMQPServerConnectionContext; -import org.proton.plug.context.server.ProtonServerConnectionContextFactory; - -import static org.proton.plug.context.AMQPConstants.Connection.DEFAULT_CHANNEL_MAX; -import static org.proton.plug.context.AMQPConstants.Connection.DEFAULT_MAX_FRAME_SIZE; +import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext; /** * A proton protocol manager, basically reads the Proton Input and maps proton resources to ActiveMQ Artemis resources @@ -64,7 +60,7 @@ public class ProtonProtocolManager implements ProtocolManager, Noti * */ private String pubSubPrefix = ActiveMQDestination.JMS_TOPIC_ADDRESS_PREFIX; - private int maxFrameSize = DEFAULT_MAX_FRAME_SIZE; + private int maxFrameSize = AMQPConstants.Connection.DEFAULT_MAX_FRAME_SIZE; public ProtonProtocolManager(ProtonProtocolManagerFactory factory, ActiveMQServer server) { this.factory = factory; @@ -104,7 +100,7 @@ public boolean acceptsNoHandshake() { @Override public ConnectionEntry createConnectionEntry(Acceptor acceptorUsed, Connection remotingConnection) { - ActiveMQProtonConnectionCallback connectionCallback = new ActiveMQProtonConnectionCallback(this, remotingConnection, server.getExecutorFactory().getExecutor(), server); + AMQPConnectionCallback connectionCallback = new AMQPConnectionCallback(this, remotingConnection, server.getExecutorFactory().getExecutor(), server); long ttl = ActiveMQClient.DEFAULT_CONNECTION_TTL; if (server.getConfiguration().getConnectionTTLOverride() != -1) { @@ -112,8 +108,8 @@ public ConnectionEntry createConnectionEntry(Acceptor acceptorUsed, Connection r } String id = server.getConfiguration().getName(); - AMQPServerConnectionContext amqpConnection = ProtonServerConnectionContextFactory.getFactory(). - createConnection(connectionCallback, id, (int) ttl, getMaxFrameSize(), DEFAULT_CHANNEL_MAX, server.getExecutorFactory().getExecutor(), server.getScheduledPool()); + AMQPConnectionContext amqpConnection = + new AMQPConnectionContext(connectionCallback, id, (int) ttl, getMaxFrameSize(), AMQPConstants.Connection.DEFAULT_CHANNEL_MAX, server.getExecutorFactory().getExecutor(), server.getScheduledPool()); Executor executor = server.getExecutorFactory().getExecutor(); diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManagerFactory.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ProtonProtocolManagerFactory.java similarity index 97% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManagerFactory.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ProtonProtocolManagerFactory.java index e677563255b..7255ca0c3a4 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManagerFactory.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ProtonProtocolManagerFactory.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton; +package org.apache.activemq.artemis.protocol.amqp.broker; import org.apache.activemq.artemis.api.core.BaseInterceptor; import org.apache.activemq.artemis.api.core.Interceptor; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonPlugSender.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/package-info.java similarity index 74% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonPlugSender.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/package-info.java index 40232ecec68..c8a3c6a52b8 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonPlugSender.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/package-info.java @@ -14,13 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.context; -import org.apache.qpid.proton.engine.Sender; - -public interface ProtonPlugSender { - - int deliverMessage(Object message, int deliveryCount) throws Exception; - - Sender getSender(); -} +/** + * This package includes classes used to interact with the broker. + * The ProtocolManager will be here, and some classes that will interact with the PostOffice + * and other internal components directly. + */ +package org.apache.activemq.artemis.protocol.amqp.broker; \ No newline at end of file diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/ActiveMQJMSVendor.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/ActiveMQJMSVendor.java similarity index 86% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/ActiveMQJMSVendor.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/ActiveMQJMSVendor.java index 7ed95d401ff..7e3ba67f2a7 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/ActiveMQJMSVendor.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/ActiveMQJMSVendor.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter; +package org.apache.activemq.artemis.protocol.amqp.converter; import javax.jms.BytesMessage; import javax.jms.Destination; @@ -26,14 +26,14 @@ import javax.jms.TextMessage; import org.apache.activemq.artemis.core.buffers.impl.ResetLimitWrappedActiveMQBuffer; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerDestination; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSBytesMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSMapMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSObjectMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSStreamMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSTextMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.message.JMSVendor; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerDestination; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.message.JMSVendor; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage; import org.apache.activemq.artemis.core.server.ServerMessage; import org.apache.activemq.artemis.core.server.impl.ServerMessageImpl; import org.apache.activemq.artemis.jms.client.ActiveMQDestination; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/ProtonMessageConverter.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/ProtonMessageConverter.java similarity index 85% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/ProtonMessageConverter.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/ProtonMessageConverter.java index 6b4e99bf9b9..f5203870e00 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/ProtonMessageConverter.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/ProtonMessageConverter.java @@ -14,15 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter; +package org.apache.activemq.artemis.protocol.amqp.converter; import org.apache.activemq.artemis.core.client.ActiveMQClientLogger; -import org.apache.activemq.artemis.core.protocol.proton.converter.message.AMQPNativeOutboundTransformer; -import org.apache.activemq.artemis.core.protocol.proton.converter.message.EncodedMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.message.InboundTransformer; -import org.apache.activemq.artemis.core.protocol.proton.converter.message.JMSMappingInboundTransformer; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.message.JMSMappingOutboundTransformer; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.message.AMQPNativeOutboundTransformer; +import org.apache.activemq.artemis.protocol.amqp.converter.message.EncodedMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.message.InboundTransformer; +import org.apache.activemq.artemis.protocol.amqp.converter.message.JMSMappingInboundTransformer; +import org.apache.activemq.artemis.protocol.amqp.converter.message.JMSMappingOutboundTransformer; import org.apache.activemq.artemis.core.server.ServerMessage; import org.apache.activemq.artemis.spi.core.protocol.MessageConverter; import org.apache.activemq.artemis.utils.IDGenerator; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerDestination.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerDestination.java similarity index 94% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerDestination.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerDestination.java index 0a8bb293e16..967ba08b5da 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerDestination.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerDestination.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.jms; +package org.apache.activemq.artemis.protocol.amqp.converter.jms; import org.apache.activemq.artemis.jms.client.ActiveMQDestination; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSBytesMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSBytesMessage.java similarity index 98% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSBytesMessage.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSBytesMessage.java index 990c7d78096..abdf808ad9f 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSBytesMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSBytesMessage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.jms; +package org.apache.activemq.artemis.protocol.amqp.converter.jms; import javax.jms.BytesMessage; import javax.jms.JMSException; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSMapMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java similarity index 99% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSMapMessage.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java index 2083b848c0b..548deb3ac96 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSMapMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.jms; +package org.apache.activemq.artemis.protocol.amqp.converter.jms; import javax.jms.JMSException; import javax.jms.MapMessage; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMessage.java similarity index 99% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSMessage.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMessage.java index 465539b31b7..d15d22b5274 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMessage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.jms; +package org.apache.activemq.artemis.protocol.amqp.converter.jms; import javax.jms.DeliveryMode; import javax.jms.Destination; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSObjectMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java similarity index 97% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSObjectMessage.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java index fb42993d113..39e0df5bf3f 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSObjectMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.jms; +package org.apache.activemq.artemis.protocol.amqp.converter.jms; import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.core.message.impl.MessageInternal; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSStreamMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSStreamMessage.java similarity index 99% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSStreamMessage.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSStreamMessage.java index 492ae0a954e..c63b7017e55 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSStreamMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSStreamMessage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.jms; +package org.apache.activemq.artemis.protocol.amqp.converter.jms; import javax.jms.JMSException; import javax.jms.MessageEOFException; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSTextMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSTextMessage.java similarity index 97% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSTextMessage.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSTextMessage.java index a055c8e5e56..5178dc2105f 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/jms/ServerJMSTextMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSTextMessage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.jms; +package org.apache.activemq.artemis.protocol.amqp.converter.jms; import javax.jms.JMSException; import javax.jms.TextMessage; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPMessageIdHelper.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPMessageIdHelper.java similarity index 98% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPMessageIdHelper.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPMessageIdHelper.java index 479c1f7b680..9e172fad4d1 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPMessageIdHelper.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPMessageIdHelper.java @@ -18,11 +18,11 @@ * under the License. * */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException; import org.apache.qpid.proton.amqp.Binary; import org.apache.qpid.proton.amqp.UnsignedLong; -import org.proton.plug.exceptions.ActiveMQAMQPIllegalStateException; import java.nio.ByteBuffer; import java.util.UUID; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPMessageTypes.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPMessageTypes.java similarity index 93% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPMessageTypes.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPMessageTypes.java index 2e67c4d8b64..613de6de186 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPMessageTypes.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPMessageTypes.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; public class AMQPMessageTypes { public static final String AMQP_TYPE_KEY = "amqp:type"; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPNativeInboundTransformer.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPNativeInboundTransformer.java similarity index 95% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPNativeInboundTransformer.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPNativeInboundTransformer.java index e194e6bcd1a..8a5d17c4608 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPNativeInboundTransformer.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPNativeInboundTransformer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; import javax.jms.Message; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPNativeOutboundTransformer.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPNativeOutboundTransformer.java similarity index 96% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPNativeOutboundTransformer.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPNativeOutboundTransformer.java index fa7f206f70f..67175ab9b14 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPNativeOutboundTransformer.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPNativeOutboundTransformer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; import org.apache.qpid.proton.amqp.UnsignedInteger; import org.apache.qpid.proton.amqp.messaging.Header; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPRawInboundTransformer.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPRawInboundTransformer.java similarity index 96% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPRawInboundTransformer.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPRawInboundTransformer.java index fd9540d60b7..e6bf171e748 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/AMQPRawInboundTransformer.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/AMQPRawInboundTransformer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; import javax.jms.BytesMessage; import javax.jms.DeliveryMode; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/EncodedMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/EncodedMessage.java similarity index 96% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/EncodedMessage.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/EncodedMessage.java index 2857c17c5db..4a80ea681fa 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/EncodedMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/EncodedMessage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; import org.apache.qpid.proton.amqp.Binary; import org.apache.qpid.proton.message.Message; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/InboundTransformer.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/InboundTransformer.java similarity index 99% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/InboundTransformer.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/InboundTransformer.java index a437e68f164..55195eb11c9 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/InboundTransformer.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/InboundTransformer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; import org.apache.qpid.proton.amqp.Binary; import org.apache.qpid.proton.amqp.Decimal128; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSMappingInboundTransformer.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingInboundTransformer.java similarity index 98% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSMappingInboundTransformer.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingInboundTransformer.java index 62eca7c83b9..2bcbfe2b5fe 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSMappingInboundTransformer.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingInboundTransformer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; import org.apache.qpid.proton.amqp.Binary; import org.apache.qpid.proton.amqp.messaging.AmqpSequence; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSMappingOutboundTransformer.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformer.java similarity index 96% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSMappingOutboundTransformer.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformer.java index 1f202f6b639..7de94089336 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSMappingOutboundTransformer.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformer.java @@ -14,10 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; import org.apache.activemq.artemis.core.message.impl.MessageInternal; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException; import org.apache.qpid.proton.amqp.Binary; import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.UnsignedByte; @@ -34,7 +35,6 @@ import org.apache.qpid.proton.amqp.messaging.Section; import org.apache.qpid.proton.message.ProtonJMessage; import org.jboss.logging.Logger; -import org.proton.plug.exceptions.ActiveMQAMQPIllegalStateException; import javax.jms.BytesMessage; import javax.jms.DeliveryMode; @@ -142,9 +142,9 @@ public ProtonJMessage convert(Message msg) throws JMSException, UnsupportedEncod body = new AmqpValue(((ObjectMessage) msg).getObject()); } - if (body == null && msg instanceof org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSMessage) { + if (body == null && msg instanceof ServerJMSMessage) { - MessageInternal internalMessage = ((org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSMessage) msg).getInnerMessage(); + MessageInternal internalMessage = ((ServerJMSMessage) msg).getInnerMessage(); if (!internalMessage.containsProperty("AMQP_MESSAGE_FORMAT")) { int readerIndex = internalMessage.getBodyBuffer().readerIndex(); try { diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSVendor.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSVendor.java similarity index 95% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSVendor.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSVendor.java index 72552958d39..9a0ed63bfd7 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSVendor.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSVendor.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; import javax.jms.BytesMessage; import javax.jms.Destination; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/OutboundTransformer.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/OutboundTransformer.java similarity index 96% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/OutboundTransformer.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/OutboundTransformer.java index bd20eee0cf4..310d4babe4a 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/OutboundTransformer.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/message/OutboundTransformer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.converter.message; +package org.apache.activemq.artemis.protocol.amqp.converter.message; public abstract class OutboundTransformer { diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/ClientSASL.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/package-info.java similarity index 83% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/ClientSASL.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/package-info.java index c36fd19cd42..a2d78898f83 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/ClientSASL.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/package-info.java @@ -14,11 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug; -public interface ClientSASL { - - byte[] getBytes(); - - String getName(); -} +/** + * This package will include classes used to make convertions between Artemis and AMQP. + */ +package org.apache.activemq.artemis.protocol.amqp.converter; \ No newline at end of file diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPException.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPException.java similarity index 96% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPException.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPException.java index 4838d55af21..1634c89b3d4 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPException.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPException.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.exceptions; +package org.apache.activemq.artemis.protocol.amqp.exceptions; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPIllegalStateException.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPIllegalStateException.java similarity index 94% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPIllegalStateException.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPIllegalStateException.java index 7818ef980b1..7f0fc5234e3 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPIllegalStateException.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPIllegalStateException.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.exceptions; +package org.apache.activemq.artemis.protocol.amqp.exceptions; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType; import org.apache.qpid.proton.amqp.transport.AmqpError; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPInternalErrorException.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPInternalErrorException.java similarity index 95% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPInternalErrorException.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPInternalErrorException.java index 2c0b0ae45fd..0af0bbb3f37 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPInternalErrorException.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPInternalErrorException.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.exceptions; +package org.apache.activemq.artemis.protocol.amqp.exceptions; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType; import org.apache.qpid.proton.amqp.transport.AmqpError; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPInvalidFieldException.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPInvalidFieldException.java similarity index 94% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPInvalidFieldException.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPInvalidFieldException.java index f5dd168cb4b..a73811c3ae3 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPInvalidFieldException.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPInvalidFieldException.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.exceptions; +package org.apache.activemq.artemis.protocol.amqp.exceptions; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType; import org.apache.qpid.proton.amqp.transport.AmqpError; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPNotFoundException.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPNotFoundException.java similarity index 94% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPNotFoundException.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPNotFoundException.java index 02cc15c51c2..f9acae345e3 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPNotFoundException.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPNotFoundException.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.exceptions; +package org.apache.activemq.artemis.protocol.amqp.exceptions; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType; import org.apache.qpid.proton.amqp.transport.AmqpError; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPNotImplementedException.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPNotImplementedException.java similarity index 94% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPNotImplementedException.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPNotImplementedException.java index 861e2367053..d2b09c765dd 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPNotImplementedException.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPNotImplementedException.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.exceptions; +package org.apache.activemq.artemis.protocol.amqp.exceptions; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType; import org.apache.qpid.proton.amqp.transport.AmqpError; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPResourceLimitExceededException.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPResourceLimitExceededException.java similarity index 95% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPResourceLimitExceededException.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPResourceLimitExceededException.java index 2c64a8dc015..978ffb48b96 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPResourceLimitExceededException.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPResourceLimitExceededException.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.exceptions; +package org.apache.activemq.artemis.protocol.amqp.exceptions; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType; import org.apache.qpid.proton.amqp.transport.AmqpError; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPTimeoutException.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPTimeoutException.java similarity index 94% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPTimeoutException.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPTimeoutException.java index c86c25d80d9..992f34bae1a 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/exceptions/ActiveMQAMQPTimeoutException.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/exceptions/ActiveMQAMQPTimeoutException.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.exceptions; +package org.apache.activemq.artemis.protocol.amqp.exceptions; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType; import org.apache.qpid.proton.amqp.transport.AmqpError; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/logger/ActiveMQAMQPProtocolMessageBundle.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/logger/ActiveMQAMQPProtocolMessageBundle.java similarity index 89% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/logger/ActiveMQAMQPProtocolMessageBundle.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/logger/ActiveMQAMQPProtocolMessageBundle.java index 576e61ae5ae..2bfe5fc37ac 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/logger/ActiveMQAMQPProtocolMessageBundle.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/logger/ActiveMQAMQPProtocolMessageBundle.java @@ -14,15 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.logger; +package org.apache.activemq.artemis.protocol.amqp.logger; -import org.proton.plug.exceptions.ActiveMQAMQPIllegalStateException; -import org.proton.plug.exceptions.ActiveMQAMQPInternalErrorException; -import org.proton.plug.exceptions.ActiveMQAMQPInvalidFieldException; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInvalidFieldException; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException; import org.jboss.logging.annotations.Message; import org.jboss.logging.annotations.MessageBundle; import org.jboss.logging.Messages; -import org.proton.plug.exceptions.ActiveMQAMQPNotFoundException; /** * Logger Code 11 diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractConnectionContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java similarity index 67% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractConnectionContext.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java index 120a37ba408..8b14e67161d 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractConnectionContext.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java @@ -14,43 +14,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.context; - -import static org.proton.plug.AmqpSupport.PRODUCT; -import static org.proton.plug.AmqpSupport.VERSION; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; +package org.apache.activemq.artemis.protocol.amqp.proton; import io.netty.buffer.ByteBuf; +import org.apache.activemq.artemis.protocol.amqp.broker.AMQPConnectionCallback; +import org.apache.activemq.artemis.protocol.amqp.broker.AMQPSessionCallback; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException; +import org.apache.activemq.artemis.protocol.amqp.proton.handler.EventHandler; +import org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult; +import org.apache.activemq.artemis.protocol.amqp.proton.handler.ProtonHandler; +import org.apache.activemq.artemis.utils.ByteUtil; import org.apache.activemq.artemis.utils.VersionLoader; import org.apache.qpid.proton.amqp.Symbol; +import org.apache.qpid.proton.amqp.transaction.Coordinator; import org.apache.qpid.proton.engine.Connection; import org.apache.qpid.proton.engine.Delivery; import org.apache.qpid.proton.engine.Link; +import org.apache.qpid.proton.engine.Receiver; +import org.apache.qpid.proton.engine.Sender; import org.apache.qpid.proton.engine.Session; import org.apache.qpid.proton.engine.Transport; import org.jboss.logging.Logger; -import org.proton.plug.AMQPConnectionCallback; -import org.proton.plug.AMQPConnectionContext; -import org.proton.plug.SASLResult; -import org.proton.plug.context.server.ProtonServerSenderContext; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.handler.ProtonHandler; -import org.proton.plug.handler.impl.DefaultEventHandler; -import org.proton.plug.util.ByteUtil; - -import static org.proton.plug.context.AMQPConstants.Connection.DEFAULT_CHANNEL_MAX; -import static org.proton.plug.context.AMQPConstants.Connection.DEFAULT_IDLE_TIMEOUT; -import static org.proton.plug.context.AMQPConstants.Connection.DEFAULT_MAX_FRAME_SIZE; - -public abstract class AbstractConnectionContext extends ProtonInitializable implements AMQPConnectionContext { - private static final Logger log = Logger.getLogger(AbstractConnectionContext.class); +import org.apache.activemq.artemis.protocol.amqp.proton.handler.ExtCapability; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class AMQPConnectionContext extends ProtonInitializable { + + private static final Logger log = Logger.getLogger(AMQPConnectionContext.class); public static final Symbol CONNECTION_OPEN_FAILED = Symbol.valueOf("amqp:connection-establishment-failed"); public static final String AMQP_CONTAINER_ID = "amqp-container-id"; @@ -62,30 +59,28 @@ public abstract class AbstractConnectionContext extends ProtonInitializable impl private final Map connectionProperties = new HashMap<>(); private final ScheduledExecutorService scheduledPool; - private final Map sessions = new ConcurrentHashMap<>(); + private final Map sessions = new ConcurrentHashMap<>(); protected LocalListener listener = new LocalListener(); - public AbstractConnectionContext(AMQPConnectionCallback connectionCallback, Executor dispatchExecutor, ScheduledExecutorService scheduledPool) { - this(connectionCallback, null, DEFAULT_IDLE_TIMEOUT, DEFAULT_MAX_FRAME_SIZE, DEFAULT_CHANNEL_MAX, dispatchExecutor, scheduledPool); - } - public AbstractConnectionContext(AMQPConnectionCallback connectionCallback, - String containerId, - int idleTimeout, - int maxFrameSize, - int channelMax, - Executor dispatchExecutor, - ScheduledExecutorService scheduledPool) { - this.connectionCallback = connectionCallback; + + public AMQPConnectionContext(AMQPConnectionCallback connectionSP, + String containerId, + int idleTimeout, + int maxFrameSize, + int channelMax, + Executor dispatchExecutor, + ScheduledExecutorService scheduledPool) { + this.connectionCallback = connectionSP; this.containerId = (containerId != null) ? containerId : UUID.randomUUID().toString(); - connectionProperties.put(PRODUCT, "apache-activemq-artemis"); - connectionProperties.put(VERSION, VersionLoader.getVersion().getFullVersion()); + connectionProperties.put(AmqpSupport.PRODUCT, "apache-activemq-artemis"); + connectionProperties.put(AmqpSupport.VERSION, VersionLoader.getVersion().getFullVersion()); this.scheduledPool = scheduledPool; connectionCallback.setConnection(this); - this.handler = ProtonHandler.Factory.create(dispatchExecutor); + this.handler = new ProtonHandler(dispatchExecutor); Transport transport = handler.getTransport(); transport.setEmitFlowEventOnSend(false); if (idleTimeout > 0) { @@ -96,12 +91,17 @@ public AbstractConnectionContext(AMQPConnectionCallback connectionCallback, handler.addEventHandler(listener); } - @Override + protected AMQPSessionContext newSessionExtension(Session realSession) throws ActiveMQAMQPException { + AMQPSessionCallback sessionSPI = connectionCallback.createSessionCallback(this); + AMQPSessionContext protonSession = new AMQPSessionContext(sessionSPI, this, realSession); + + return protonSession; + } + public SASLResult getSASLResult() { return handler.getSASLResult(); } - @Override public void inputBuffer(ByteBuf buffer) { if (log.isTraceEnabled()) { ByteUtil.debugFrame(log, "Buffer Received ", buffer); @@ -114,41 +114,33 @@ public void destroy() { connectionCallback.close(); } - /** - * See comment at {@link org.proton.plug.AMQPConnectionContext#isSyncOnFlush()} - */ - @Override public boolean isSyncOnFlush() { return false; } - @Override public Object getLock() { return handler.getLock(); } - @Override public int capacity() { return handler.capacity(); } - @Override public void outputDone(int bytes) { handler.outputDone(bytes); } - @Override public void flush() { handler.flush(); } - @Override public void close() { handler.close(); } - protected AbstractProtonSessionContext getSessionExtension(Session realSession) throws ActiveMQAMQPException { - AbstractProtonSessionContext sessionExtension = sessions.get(realSession); + + protected AMQPSessionContext getSessionExtension(Session realSession) throws ActiveMQAMQPException { + AMQPSessionContext sessionExtension = sessions.get(realSession); if (sessionExtension == null) { // how this is possible? Log a warn here sessionExtension = newSessionExtension(realSession); @@ -158,16 +150,16 @@ protected AbstractProtonSessionContext getSessionExtension(Session realSession) return sessionExtension; } - protected abstract void remoteLinkOpened(Link link) throws Exception; - protected abstract AbstractProtonSessionContext newSessionExtension(Session realSession) throws ActiveMQAMQPException; - @Override + protected boolean validateConnection(Connection connection) { + return connectionCallback.validateConnection(connection, handler.getSASLResult()); + } + public boolean checkDataReceived() { return handler.checkDataReceived(); } - @Override public long getCreationTime() { return handler.getCreationTime(); } @@ -176,7 +168,7 @@ protected void flushBytes() { ByteBuf bytes; // handler.outputBuffer has the lock while ((bytes = handler.outputBuffer()) != null) { - connectionCallback.onTransport(bytes, AbstractConnectionContext.this); + connectionCallback.onTransport(bytes, this); } } @@ -188,15 +180,90 @@ public String getPubSubPrefix() { return null; } - protected boolean validateConnection(Connection connection) { - return true; + protected void initInternal() throws Exception { } - protected void initInternal() throws Exception { + protected void remoteLinkOpened(Link link) throws Exception { + + AMQPSessionContext protonSession = (AMQPSessionContext) getSessionExtension(link.getSession()); + + link.setSource(link.getRemoteSource()); + link.setTarget(link.getRemoteTarget()); + if (link instanceof Receiver) { + Receiver receiver = (Receiver) link; + if (link.getRemoteTarget() instanceof Coordinator) { + Coordinator coordinator = (Coordinator) link.getRemoteTarget(); + protonSession.addTransactionHandler(coordinator, receiver); + } + else { + protonSession.addReceiver(receiver); + } + } + else { + Sender sender = (Sender) link; + protonSession.addSender(sender); + sender.offer(1); + } } + public Symbol[] getConnectionCapabilitiesOffered() { + return ExtCapability.getCapabilities(); + } + + + // This listener will perform a bunch of things here - class LocalListener extends DefaultEventHandler { + class LocalListener implements EventHandler { + + @Override + public void onInit(Connection connection) throws Exception { + + } + + @Override + public void onLocalOpen(Connection connection) throws Exception { + + } + + @Override + public void onLocalClose(Connection connection) throws Exception { + + } + + @Override + public void onFinal(Connection connection) throws Exception { + + } + + @Override + public void onInit(Session session) throws Exception { + + } + + @Override + public void onFinal(Session session) throws Exception { + + } + + @Override + public void onInit(Link link) throws Exception { + + } + + @Override + public void onLocalOpen(Link link) throws Exception { + + } + + @Override + public void onLocalClose(Link link) throws Exception { + + } + + @Override + public void onFinal(Link link) throws Exception { + + } @Override public void onAuthInit(ProtonHandler handler, Connection connection, boolean sasl) { @@ -230,7 +297,7 @@ public void onRemoteOpen(Connection connection) throws Exception { connection.close(); } else { - connection.setContext(AbstractConnectionContext.this); + connection.setContext(AMQPConnectionContext.this); connection.setContainer(containerId); connection.setProperties(connectionProperties); connection.setOfferedCapabilities(getConnectionCapabilitiesOffered()); @@ -265,7 +332,7 @@ public void run() { public void onRemoteClose(Connection connection) { synchronized (getLock()) { connection.close(); - for (AbstractProtonSessionContext protonSession : sessions.values()) { + for (AMQPSessionContext protonSession : sessions.values()) { protonSession.close(); } sessions.clear(); @@ -298,7 +365,7 @@ public void onRemoteClose(Session session) throws Exception { session.close(); } - AbstractProtonSessionContext sessionContext = (AbstractProtonSessionContext) session.getContext(); + AMQPSessionContext sessionContext = (AMQPSessionContext)session.getContext(); if (sessionContext != null) { sessionContext.close(); sessions.remove(session); @@ -353,8 +420,5 @@ public void onDelivery(Delivery delivery) throws Exception { } } - @Override - public Symbol[] getConnectionCapabilitiesOffered() { - return null; - } + } diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AMQPConstants.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConstants.java similarity index 95% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AMQPConstants.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConstants.java index 6287c067cb3..728a87b1dd0 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AMQPConstants.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConstants.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.context; +package org.apache.activemq.artemis.protocol.amqp.proton; /** * Constants derived from the AMQP spec diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPSessionContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPSessionContext.java new file mode 100644 index 00000000000..9003d3bce79 --- /dev/null +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPSessionContext.java @@ -0,0 +1,221 @@ +/* + * 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.activemq.artemis.protocol.amqp.proton; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.activemq.artemis.protocol.amqp.broker.AMQPSessionCallback; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException; +import org.apache.qpid.proton.amqp.Symbol; +import org.apache.qpid.proton.amqp.transaction.Coordinator; +import org.apache.qpid.proton.amqp.transport.ErrorCondition; +import org.apache.qpid.proton.engine.Receiver; +import org.apache.qpid.proton.engine.Sender; +import org.apache.qpid.proton.engine.Session; +import org.jboss.logging.Logger; + +public class AMQPSessionContext extends ProtonInitializable { + + private static final Logger log = Logger.getLogger(AMQPSessionContext.class); + protected final AMQPConnectionContext connection; + + protected final AMQPSessionCallback sessionSPI; + + protected final Session session; + + private long currentTag = 0; + + protected Map receivers = new HashMap<>(); + + protected Map senders = new HashMap<>(); + + protected boolean closed = false; + + public AMQPSessionContext(AMQPSessionCallback sessionSPI, + AMQPConnectionContext connection, + Session session) { + this.connection = connection; + this.sessionSPI = sessionSPI; + this.session = session; + } + + protected Map serverSenders = new HashMap<>(); + + @Override + public void initialise() throws Exception { + if (!isInitialized()) { + super.initialise(); + + if (sessionSPI != null) { + try { + sessionSPI.init(this, connection.getSASLResult()); + } + catch (Exception e) { + throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e); + } + } + } + } + + /** + * @param consumer + * @param queueName + */ + public void disconnect(Object consumer, String queueName) { + ProtonServerSenderContext protonConsumer = senders.remove(consumer); + if (protonConsumer != null) { + try { + protonConsumer.close(false); + } + catch (ActiveMQAMQPException e) { + protonConsumer.getSender().setTarget(null); + protonConsumer.getSender().setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage())); + } + } + } + + + /** + * The consumer object from the broker or the key used to store the sender + * + * @param message + * @param consumer + * @param deliveryCount + * @return the number of bytes sent + */ + public int serverDelivery(Object message, Object consumer, int deliveryCount) throws Exception { + ProtonServerSenderContext protonSender = serverSenders.get(consumer); + if (protonSender != null) { + return protonSender.deliverMessage(message, deliveryCount); + } + return 0; + } + + public byte[] getTag() { + return Long.toHexString(currentTag++).getBytes(); + } + + public void replaceTag(byte[] tag) { + // TODO: do we need to reuse this? + } + + public void close() { + if (closed) { + return; + } + + // Making a copy to avoid ConcurrentModificationException during the iteration + Set receiversCopy = new HashSet<>(); + receiversCopy.addAll(receivers.values()); + + for (ProtonServerReceiverContext protonProducer : receiversCopy) { + try { + protonProducer.close(false); + } + catch (Exception e) { + log.warn(e.getMessage(), e); + } + } + receivers.clear(); + + Set protonSendersClone = new HashSet<>(); + protonSendersClone.addAll(senders.values()); + + for (ProtonServerSenderContext protonConsumer : protonSendersClone) { + try { + protonConsumer.close(false); + } + catch (Exception e) { + log.warn(e.getMessage(), e); + } + } + senders.clear(); + try { + if (sessionSPI != null) { + sessionSPI.close(); + } + } + catch (Exception e) { + log.warn(e.getMessage(), e); + } + closed = true; + } + + public void removeReceiver(Receiver receiver) { + receivers.remove(receiver); + } + + public void addTransactionHandler(Coordinator coordinator, Receiver receiver) { + ProtonTransactionHandler transactionHandler = new ProtonTransactionHandler(sessionSPI); + + coordinator.setCapabilities(Symbol.getSymbol("amqp:local-transactions"), + Symbol.getSymbol("amqp:multi-txns-per-ssn"), + Symbol.getSymbol("amqp:multi-ssns-per-txn")); + + receiver.setContext(transactionHandler); + receiver.open(); + receiver.flow(100); + } + + public void addSender(Sender sender) throws Exception { + ProtonServerSenderContext protonSender = new ProtonServerSenderContext(connection, sender, this, sessionSPI); + + try { + protonSender.initialise(); + senders.put(sender, protonSender); + serverSenders.put(protonSender.getBrokerConsumer(), protonSender); + sender.setContext(protonSender); + sender.open(); + protonSender.start(); + } + catch (ActiveMQAMQPException e) { + senders.remove(sender); + sender.setSource(null); + sender.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage())); + sender.close(); + } + } + + public void removeSender(Sender sender) throws ActiveMQAMQPException { + senders.remove(sender); + ProtonServerSenderContext senderRemoved = senders.remove(sender); + if (senderRemoved != null) { + serverSenders.remove(senderRemoved.getBrokerConsumer()); + } + } + + public void addReceiver(Receiver receiver) throws Exception { + try { + ProtonServerReceiverContext protonReceiver = new ProtonServerReceiverContext(sessionSPI, connection, this, receiver); + protonReceiver.initialise(); + receivers.put(receiver, protonReceiver); + receiver.setContext(protonReceiver); + receiver.open(); + } + catch (ActiveMQAMQPException e) { + receivers.remove(receiver); + receiver.setTarget(null); + receiver.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage())); + receiver.close(); + } + } + +} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AmqpSupport.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AmqpSupport.java similarity index 98% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AmqpSupport.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AmqpSupport.java index 4ddbbccf345..848f0d2183e 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AmqpSupport.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AmqpSupport.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug; +package org.apache.activemq.artemis.protocol.amqp.proton; import org.apache.qpid.proton.amqp.DescribedType; import org.apache.qpid.proton.amqp.Symbol; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonDeliveryHandler.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonDeliveryHandler.java similarity index 91% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonDeliveryHandler.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonDeliveryHandler.java index d861394c1e5..43f191368ff 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonDeliveryHandler.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonDeliveryHandler.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.context; +package org.apache.activemq.artemis.protocol.amqp.proton; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException; import org.apache.qpid.proton.amqp.transport.ErrorCondition; import org.apache.qpid.proton.engine.Delivery; -import org.proton.plug.exceptions.ActiveMQAMQPException; /** * An interface to handle deliveries, either messages, acks or transaction calls diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/Connector.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonInitializable.java similarity index 71% rename from artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/Connector.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonInitializable.java index e6b67c26087..3870810df04 100644 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/Connector.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonInitializable.java @@ -14,13 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.test.minimalclient; +package org.apache.activemq.artemis.protocol.amqp.proton; -import org.proton.plug.AMQPClientConnectionContext; +public class ProtonInitializable { -public interface Connector { + private boolean initialized = false; - void start(); + public boolean isInitialized() { + return initialized; + } - AMQPClientConnectionContext connect(String host, int port) throws Exception; + public void initialise() throws Exception { + if (!initialized) { + initialized = true; + } + } } diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerReceiverContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerReceiverContext.java similarity index 70% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerReceiverContext.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerReceiverContext.java index 173ff286be2..4b978318fb7 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerReceiverContext.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerReceiverContext.java @@ -14,10 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.context.server; +package org.apache.activemq.artemis.protocol.amqp.proton; import io.netty.buffer.ByteBuf; import io.netty.buffer.PooledByteBufAllocator; +import org.apache.activemq.artemis.protocol.amqp.broker.AMQPSessionCallback; +import org.apache.activemq.artemis.protocol.amqp.logger.ActiveMQAMQPProtocolMessageBundle; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException; +import org.apache.activemq.artemis.protocol.amqp.util.DeliveryUtil; import org.apache.activemq.artemis.core.transaction.Transaction; import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.messaging.Rejected; @@ -26,21 +32,22 @@ import org.apache.qpid.proton.engine.Delivery; import org.apache.qpid.proton.engine.Receiver; import org.jboss.logging.Logger; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.context.AbstractConnectionContext; -import org.proton.plug.context.AbstractProtonReceiverContext; -import org.proton.plug.context.AbstractProtonSessionContext; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.exceptions.ActiveMQAMQPInternalErrorException; -import org.proton.plug.exceptions.ActiveMQAMQPNotFoundException; -import org.proton.plug.logger.ActiveMQAMQPProtocolMessageBundle; -import static org.proton.plug.util.DeliveryUtil.readDelivery; - -public class ProtonServerReceiverContext extends AbstractProtonReceiverContext { +public class ProtonServerReceiverContext extends ProtonInitializable implements ProtonDeliveryHandler { private static final Logger log = Logger.getLogger(ProtonServerReceiverContext.class); + protected final AMQPConnectionContext connection; + + protected final AMQPSessionContext protonSession; + + protected final Receiver receiver; + + protected String address; + + protected final AMQPSessionCallback sessionSPI; + + /* The maximum number of credits we will allocate to clients. This number is also used by the broker when refresh client credits. @@ -51,10 +58,13 @@ public class ProtonServerReceiverContext extends AbstractProtonReceiverContext { private static int minCreditRefresh = 30; public ProtonServerReceiverContext(AMQPSessionCallback sessionSPI, - AbstractConnectionContext connection, - AbstractProtonSessionContext protonSession, + AMQPConnectionContext connection, + AMQPSessionContext protonSession, Receiver receiver) { - super(sessionSPI, connection, protonSession, receiver); + this.connection = connection; + this.protonSession = protonSession; + this.receiver = receiver; + this.sessionSPI = sessionSPI; } @Override @@ -128,7 +138,7 @@ public void onMessage(Delivery delivery) throws ActiveMQAMQPException { ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(10 * 1024); try { synchronized (connection.getLock()) { - readDelivery(receiver, buffer); + DeliveryUtil.readDelivery(receiver, buffer); receiver.advance(); @@ -158,4 +168,44 @@ public void onMessage(Delivery delivery) throws ActiveMQAMQPException { } } + @Override + public void close(boolean remoteLinkClose) throws ActiveMQAMQPException { + protonSession.removeReceiver(receiver); + } + + @Override + public void close(ErrorCondition condition) throws ActiveMQAMQPException { + receiver.setCondition(condition); + close(false); + } + + public void flow(int credits, int threshold) { + // Use the SessionSPI to allocate producer credits, or default, always allocate credit. + if (sessionSPI != null) { + sessionSPI.offerProducerCredit(address, credits, threshold, receiver); + } + else { + synchronized (connection.getLock()) { + receiver.flow(credits); + connection.flush(); + } + } + + } + + public void drain(int credits) { + synchronized (connection.getLock()) { + receiver.drain(credits); + } + connection.flush(); + } + + public int drained() { + return receiver.drained(); + } + + public boolean isDraining() { + return receiver.draining(); + } + } diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerSenderContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerSenderContext.java similarity index 82% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerSenderContext.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerSenderContext.java index e9bd1236e34..0a071fd487b 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerSenderContext.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerSenderContext.java @@ -14,15 +14,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.context.server; +package org.apache.activemq.artemis.protocol.amqp.proton; import java.util.Map; import java.util.Objects; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.PooledByteBufAllocator; import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.protocol.amqp.broker.AMQPSessionCallback; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException; +import org.apache.activemq.artemis.protocol.amqp.util.CreditsSemaphore; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException; import org.apache.activemq.artemis.core.server.QueueQueryResult; import org.apache.activemq.artemis.core.transaction.Transaction; import org.apache.activemq.artemis.jms.client.ActiveMQConnection; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException; +import org.apache.activemq.artemis.protocol.amqp.logger.ActiveMQAMQPProtocolMessageBundle; import org.apache.activemq.artemis.selector.filter.FilterException; import org.apache.activemq.artemis.selector.impl.SelectorParser; import org.apache.qpid.proton.amqp.DescribedType; @@ -44,22 +52,10 @@ import org.apache.qpid.proton.engine.Sender; import org.apache.qpid.proton.message.ProtonJMessage; import org.jboss.logging.Logger; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.AmqpSupport; -import org.proton.plug.context.AbstractConnectionContext; -import org.proton.plug.context.AbstractProtonContextSender; -import org.proton.plug.context.AbstractProtonSessionContext; -import org.proton.plug.context.ProtonPlugSender; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.exceptions.ActiveMQAMQPIllegalStateException; -import org.proton.plug.exceptions.ActiveMQAMQPInternalErrorException; -import org.proton.plug.exceptions.ActiveMQAMQPNotFoundException; -import org.proton.plug.logger.ActiveMQAMQPProtocolMessageBundle; - -import static org.proton.plug.AmqpSupport.JMS_SELECTOR_FILTER_IDS; -import static org.proton.plug.AmqpSupport.findFilter; - -public class ProtonServerSenderContext extends AbstractProtonContextSender implements ProtonPlugSender { +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException; +import org.apache.activemq.artemis.protocol.amqp.util.NettyWritable; + +public class ProtonServerSenderContext extends ProtonInitializable implements ProtonDeliveryHandler { private static final Logger log = Logger.getLogger(ProtonServerSenderContext.class); @@ -69,11 +65,23 @@ public class ProtonServerSenderContext extends AbstractProtonContextSender imple private Object brokerConsumer; - public ProtonServerSenderContext(AbstractConnectionContext connection, + protected final AMQPSessionContext protonSession; + protected final Sender sender; + protected final AMQPConnectionContext connection; + protected boolean closed = false; + protected final AMQPSessionCallback sessionSPI; + protected CreditsSemaphore creditsSemaphore = new CreditsSemaphore(0); + + + public ProtonServerSenderContext(AMQPConnectionContext connection, Sender sender, - AbstractProtonSessionContext protonSession, + AMQPSessionContext protonSession, AMQPSessionCallback server) { - super(connection, sender, protonSession, server); + super(); + this.connection = connection; + this.sender = sender; + this.protonSession = protonSession; + this.sessionSPI = server; } public Object getBrokerConsumer() { @@ -82,16 +90,19 @@ public Object getBrokerConsumer() { @Override public void onFlow(int currentCredits, boolean drain) { - super.onFlow(currentCredits, drain); + this.creditsSemaphore.setCredits(currentCredits); sessionSPI.onFlowConsumer(brokerConsumer, currentCredits, drain); } + public Sender getSender() { + return sender; + } + /* * start the session * */ - @Override public void start() throws ActiveMQAMQPException { - super.start(); + sessionSPI.start(); // protonSession.getServerSession().start(); //todo add flow control @@ -125,7 +136,7 @@ public void initialise() throws Exception { * even tho the filter is a map it will only return a single filter unless a nolocal is also provided * */ if (source != null) { - Map.Entry filter = findFilter(source.getFilter(), JMS_SELECTOR_FILTER_IDS); + Map.Entry filter = AmqpSupport.findFilter(source.getFilter(), AmqpSupport.JMS_SELECTOR_FILTER_IDS); if (filter != null) { selector = filter.getValue().getDescribed().toString(); // Validate the Selector. @@ -146,7 +157,7 @@ public void initialise() throws Exception { boolean isPubSub = hasCapabilities(TOPIC, source) || isPubSub(source); if (isPubSub) { - if (findFilter(source.getFilter(), AmqpSupport.NO_LOCAL_FILTER_IDS) != null) { + if (AmqpSupport.findFilter(source.getFilter(), AmqpSupport.NO_LOCAL_FILTER_IDS) != null) { String remoteContainerId = sender.getSession().getConnection().getRemoteContainer(); String noLocalFilter = ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME.toString() + "<>'" + remoteContainerId + "'"; if (selector != null) { @@ -280,7 +291,13 @@ private boolean isPubSub(Source source) { * */ @Override public void close(ErrorCondition condition) throws ActiveMQAMQPException { - super.close(condition); + closed = true; + protonSession.removeSender(sender); + synchronized (connection.getLock()) { + sender.close(); + } + connection.flush(); + try { sessionSPI.closeSender(brokerConsumer); } @@ -295,7 +312,6 @@ public void close(ErrorCondition condition) throws ActiveMQAMQPException { * */ @Override public void close(boolean remoteLinkClose) throws ActiveMQAMQPException { - super.close(remoteLinkClose); try { sessionSPI.closeSender(brokerConsumer); //if this is a link close rather than a connection close or detach, we need to delete any durable resources for @@ -406,16 +422,13 @@ else if (remoteState instanceof Rejected || remoteState instanceof Modified) { } } - @Override public synchronized void checkState() { - super.checkState(); sessionSPI.resumeDelivery(brokerConsumer); } /** * handle an out going message from ActiveMQ Artemis, send via the Proton Sender */ - @Override public int deliverMessage(Object message, int deliveryCount) throws Exception { if (closed) { System.err.println("Message can't be delivered as it's closed"); @@ -448,5 +461,53 @@ private static boolean hasCapabilities(Symbol symbol, Source source) { } return false; } + protected int performSend(ProtonJMessage serverMessage, Object context) { + if (!creditsSemaphore.tryAcquire()) { + try { + creditsSemaphore.acquire(); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + // nothing to be done here.. we just keep going + throw new IllegalStateException(e.getMessage(), e); + } + } + + //presettle means we can ack the message on the dealer side before we send it, i.e. for browsers + boolean preSettle = sender.getRemoteSenderSettleMode() == SenderSettleMode.SETTLED; + + //we only need a tag if we are going to ack later + byte[] tag = preSettle ? new byte[0] : protonSession.getTag(); + + ByteBuf nettyBuffer = PooledByteBufAllocator.DEFAULT.heapBuffer(1024); + try { + serverMessage.encode(new NettyWritable(nettyBuffer)); + + int size = nettyBuffer.writerIndex(); + + synchronized (connection.getLock()) { + final Delivery delivery; + delivery = sender.delivery(tag, 0, tag.length); + delivery.setContext(context); + + // this will avoid a copy.. patch provided by Norman using buffer.array() + sender.send(nettyBuffer.array(), nettyBuffer.arrayOffset() + nettyBuffer.readerIndex(), nettyBuffer.readableBytes()); + + if (preSettle) { + delivery.settle(); + } + else { + sender.advance(); + } + } + + connection.flush(); + + return size; + } + finally { + nettyBuffer.release(); + } + } } diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonTransactionHandler.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonTransactionHandler.java similarity index 90% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonTransactionHandler.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonTransactionHandler.java index 263d3e686bb..6d4e73ae997 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonTransactionHandler.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonTransactionHandler.java @@ -14,10 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.context; +package org.apache.activemq.artemis.protocol.amqp.proton; import io.netty.buffer.ByteBuf; import io.netty.buffer.PooledByteBufAllocator; +import org.apache.activemq.artemis.protocol.amqp.broker.AMQPSessionCallback; +import org.apache.activemq.artemis.protocol.amqp.logger.ActiveMQAMQPProtocolMessageBundle; +import org.apache.activemq.artemis.protocol.amqp.util.DeliveryUtil; import org.apache.qpid.proton.amqp.Binary; import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.messaging.Accepted; @@ -31,12 +34,7 @@ import org.apache.qpid.proton.engine.Receiver; import org.apache.qpid.proton.message.impl.MessageImpl; import org.jboss.logging.Logger; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.logger.ActiveMQAMQPProtocolMessageBundle; - -import static org.proton.plug.util.DeliveryUtil.decodeMessageImpl; -import static org.proton.plug.util.DeliveryUtil.readDelivery; +import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException; /** * handles an amqp Coordinator to deal with transaction boundaries etc @@ -63,11 +61,11 @@ public void onMessage(Delivery delivery) throws ActiveMQAMQPException { return; } - readDelivery(receiver, buffer); + DeliveryUtil.readDelivery(receiver, buffer); receiver.advance(); - MessageImpl msg = decodeMessageImpl(buffer); + MessageImpl msg = DeliveryUtil.decodeMessageImpl(buffer); Object action = ((AmqpValue) msg.getBody()).getValue(); diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/EventHandler.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/EventHandler.java similarity index 97% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/EventHandler.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/EventHandler.java index c020cbbe6f6..91c9a67cfbb 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/EventHandler.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/EventHandler.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.handler; +package org.apache.activemq.artemis.protocol.amqp.proton.handler; import org.apache.qpid.proton.engine.Connection; import org.apache.qpid.proton.engine.Delivery; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/Events.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/Events.java similarity index 97% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/Events.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/Events.java index 2f978c7de29..6552f64ee30 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/Events.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/Events.java @@ -14,14 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.handler; +package org.apache.activemq.artemis.protocol.amqp.proton.handler; import org.apache.qpid.proton.engine.Event; import org.apache.qpid.proton.engine.Transport; -/** - * TODO : this needs a better home - */ public final class Events { public static void dispatchTransport(Transport transport, EventHandler handler) throws Exception { diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/ExtCapability.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ExtCapability.java similarity index 82% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/ExtCapability.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ExtCapability.java index cbb96fd1d21..b2a62304b91 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/ExtCapability.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ExtCapability.java @@ -14,18 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.handler; +package org.apache.activemq.artemis.protocol.amqp.proton.handler; +import org.apache.activemq.artemis.protocol.amqp.proton.AmqpSupport; import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.engine.Connection; -import static org.proton.plug.AmqpSupport.DELAYED_DELIVERY; -import static org.proton.plug.AmqpSupport.SOLE_CONNECTION_CAPABILITY; - public class ExtCapability { public static final Symbol[] capabilities = new Symbol[] { - SOLE_CONNECTION_CAPABILITY, DELAYED_DELIVERY + AmqpSupport.SOLE_CONNECTION_CAPABILITY, AmqpSupport.DELAYED_DELIVERY }; public static Symbol[] getCapabilities() { @@ -36,7 +34,7 @@ public static boolean needUniqueConnection(Connection connection) { Symbol[] extCapabilities = connection.getRemoteDesiredCapabilities(); if (extCapabilities != null) { for (Symbol sym : extCapabilities) { - if (sym.compareTo(SOLE_CONNECTION_CAPABILITY) == 0) { + if (sym.compareTo(AmqpSupport.SOLE_CONNECTION_CAPABILITY) == 0) { return true; } } diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/impl/ProtonHandlerImpl.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java similarity index 90% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/impl/ProtonHandlerImpl.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java index b2f640664a9..2efaa1b7163 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/impl/ProtonHandlerImpl.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.handler.impl; +package org.apache.activemq.artemis.protocol.amqp.proton.handler; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -25,6 +25,10 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.PooledByteBufAllocator; +import org.apache.activemq.artemis.protocol.amqp.proton.ProtonInitializable; +import org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult; +import org.apache.activemq.artemis.protocol.amqp.sasl.ServerSASL; +import org.apache.activemq.artemis.utils.ByteUtil; import org.apache.qpid.proton.Proton; import org.apache.qpid.proton.amqp.transport.ErrorCondition; import org.apache.qpid.proton.engine.Collector; @@ -34,21 +38,10 @@ import org.apache.qpid.proton.engine.Sasl; import org.apache.qpid.proton.engine.Transport; import org.jboss.logging.Logger; -import org.proton.plug.ClientSASL; -import org.proton.plug.ServerSASL; -import org.proton.plug.handler.EventHandler; -import org.proton.plug.handler.Events; -import org.proton.plug.handler.ProtonHandler; -import org.proton.plug.context.ProtonInitializable; -import org.proton.plug.SASLResult; -import org.proton.plug.util.ByteUtil; - -/** - * Clebert Suconic - */ -public class ProtonHandlerImpl extends ProtonInitializable implements ProtonHandler { - private static final Logger log = Logger.getLogger(ProtonHandlerImpl.class); +public class ProtonHandler extends ProtonInitializable { + + private static final Logger log = Logger.getLogger(ProtonHandler.class); private static final byte SASL = 0x03; @@ -89,14 +82,13 @@ public void run() { private int offset = 0; - public ProtonHandlerImpl(Executor dispatchExecutor) { + public ProtonHandler(Executor dispatchExecutor) { this.dispatchExecutor = dispatchExecutor; this.creationTime = System.currentTimeMillis(); transport.bind(connection); connection.collect(collector); } - @Override public long tick(boolean firstTick) { if (!firstTick) { try { @@ -117,35 +109,29 @@ public long tick(boolean firstTick) { return transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); } - @Override public int capacity() { synchronized (lock) { return transport.capacity(); } } - @Override public Object getLock() { return lock; } - @Override public Transport getTransport() { return transport; } - @Override public Connection getConnection() { return connection; } - @Override public ProtonHandler addEventHandler(EventHandler handler) { handlers.add(handler); return this; } - @Override public void createServerSASL(ServerSASL[] handlers) { this.serverSasl = transport.sasl(); saslHandlers = new HashMap<>(); @@ -160,12 +146,10 @@ public void createServerSASL(ServerSASL[] handlers) { } - @Override public SASLResult getSASLResult() { return saslResult; } - @Override public void inputBuffer(ByteBuf buffer) { dataReceived = true; synchronized (lock) { @@ -211,7 +195,6 @@ public void inputBuffer(ByteBuf buffer) { } } - @Override public boolean checkDataReceived() { boolean res = dataReceived; @@ -220,12 +203,10 @@ public boolean checkDataReceived() { return res; } - @Override public long getCreationTime() { return creationTime; } - @Override public void outputDone(int bytes) { synchronized (lock) { transport.pop(bytes); @@ -240,7 +221,6 @@ public void outputDone(int bytes) { flush(); } - @Override public ByteBuf outputBuffer() { synchronized (lock) { @@ -271,17 +251,6 @@ public ByteBuf outputBuffer() { } } - @Override - public void createClientSasl(ClientSASL clientSASL) { - if (clientSASL != null) { - clientSasl = transport.sasl(); - clientSasl.setMechanisms(clientSASL.getName()); - byte[] initialSasl = clientSASL.getBytes(); - clientSasl.send(initialSasl, 0, initialSasl.length); - } - } - - @Override public void flush() { synchronized (lock) { transport.process(); @@ -293,7 +262,6 @@ public void flush() { dispatchExecutor.execute(dispatchRunnable); } - @Override public void close() { synchronized (lock) { connection.close(); @@ -361,7 +329,7 @@ private void dispatch() { // while processing events (for instance onTransport) // while a client is also trying to write here while ((ev = popEvent()) != null) { - for (EventHandler h : handlers) { + for ( EventHandler h : handlers) { if (log.isTraceEnabled()) { log.trace("Handling " + ev + " towards " + h); } diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/Constants.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/package-info.java similarity index 78% rename from artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/Constants.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/package-info.java index bacfd7b75b8..8476f5b5ec3 100644 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/Constants.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/package-info.java @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.test; -public class Constants { - - public static final int PORT = 5672; -} +/** + * This package includes classes used on the interaction with Proton, including Context classes that will be translated + * through the model event. + */ +package org.apache.activemq.artemis.protocol.amqp.proton; \ No newline at end of file diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/AnonymousServerSASL.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/AnonymousServerSASL.java similarity index 91% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/AnonymousServerSASL.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/AnonymousServerSASL.java index d52df404d44..013b73b51d1 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/AnonymousServerSASL.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/AnonymousServerSASL.java @@ -14,10 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.sasl; - -import org.proton.plug.SASLResult; -import org.proton.plug.ServerSASL; +package org.apache.activemq.artemis.protocol.amqp.sasl; public class AnonymousServerSASL implements ServerSASL { diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/sasl/ActiveMQPlainSASL.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/PlainSASL.java similarity index 85% rename from artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/sasl/ActiveMQPlainSASL.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/PlainSASL.java index bf4f043f999..cb82eba42ab 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/sasl/ActiveMQPlainSASL.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/PlainSASL.java @@ -14,16 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton.sasl; +package org.apache.activemq.artemis.protocol.amqp.sasl; import org.apache.activemq.artemis.core.security.SecurityStore; -import org.proton.plug.sasl.ServerSASLPlain; -public class ActiveMQPlainSASL extends ServerSASLPlain { +public class PlainSASL extends ServerSASLPlain { private final SecurityStore securityStore; - public ActiveMQPlainSASL(SecurityStore securityStore) { + public PlainSASL(SecurityStore securityStore) { this.securityStore = securityStore; } diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/PlainSASLResult.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/PlainSASLResult.java similarity index 95% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/PlainSASLResult.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/PlainSASLResult.java index fe33886d769..f138ae36145 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/PlainSASLResult.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/PlainSASLResult.java @@ -14,9 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.sasl; - -import org.proton.plug.SASLResult; +package org.apache.activemq.artemis.protocol.amqp.sasl; public class PlainSASLResult implements SASLResult { diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/SASLResult.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/SASLResult.java similarity index 94% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/SASLResult.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/SASLResult.java index f7ff6711273..f8c42973f7b 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/SASLResult.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/SASLResult.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug; +package org.apache.activemq.artemis.protocol.amqp.sasl; public interface SASLResult { diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/ServerSASL.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/ServerSASL.java similarity index 94% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/ServerSASL.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/ServerSASL.java index ed1c361abc2..43d57d057c4 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/ServerSASL.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/ServerSASL.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug; +package org.apache.activemq.artemis.protocol.amqp.sasl; public interface ServerSASL { diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/ServerSASLPlain.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/ServerSASLPlain.java similarity index 94% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/ServerSASLPlain.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/ServerSASLPlain.java index 37c8dd3de04..da26d2efc6e 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/ServerSASLPlain.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/ServerSASLPlain.java @@ -14,10 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.sasl; - -import org.proton.plug.SASLResult; -import org.proton.plug.ServerSASL; +package org.apache.activemq.artemis.protocol.amqp.sasl; public class ServerSASLPlain implements ServerSASL { diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/CodecCache.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/CodecCache.java similarity index 96% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/CodecCache.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/CodecCache.java index 014efb0b1b3..53d0bc1c2f4 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/CodecCache.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/CodecCache.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.util; +package org.apache.activemq.artemis.protocol.amqp.util; import org.apache.qpid.proton.codec.AMQPDefinedTypes; import org.apache.qpid.proton.codec.DecoderImpl; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/CreditsSemaphore.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/CreditsSemaphore.java similarity index 98% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/CreditsSemaphore.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/CreditsSemaphore.java index a175805de9d..3eda1990ec0 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/CreditsSemaphore.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/CreditsSemaphore.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.util; +package org.apache.activemq.artemis.protocol.amqp.util; import java.util.concurrent.locks.AbstractQueuedSynchronizer; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/DeliveryUtil.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/DeliveryUtil.java similarity index 97% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/DeliveryUtil.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/DeliveryUtil.java index ae988910fdc..9257c6bfaa9 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/DeliveryUtil.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/DeliveryUtil.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.util; +package org.apache.activemq.artemis.protocol.amqp.util; import io.netty.buffer.ByteBuf; import org.apache.qpid.proton.engine.Receiver; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/NettyWritable.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyWritable.java similarity index 97% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/NettyWritable.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyWritable.java index 98afd303c5e..75d39b63665 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/NettyWritable.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyWritable.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.util; +package org.apache.activemq.artemis.protocol.amqp.util; import java.nio.ByteBuffer; diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ProtonServerMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/ProtonServerMessage.java similarity index 99% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ProtonServerMessage.java rename to artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/ProtonServerMessage.java index c3fab5dc50c..c15741e47a3 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ProtonServerMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/ProtonServerMessage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.util; +package org.apache.activemq.artemis.protocol.amqp.util; import java.nio.ByteBuffer; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/resources/META-INF/services/org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory b/artemis-protocols/artemis-amqp-protocol/src/main/resources/META-INF/services/org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory index 2cd27f44f8a..93b9dfa4d1c 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/resources/META-INF/services/org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory +++ b/artemis-protocols/artemis-amqp-protocol/src/main/resources/META-INF/services/org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory @@ -1 +1 @@ -org.apache.activemq.artemis.core.protocol.proton.ProtonProtocolManagerFactory \ No newline at end of file +org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFactory \ No newline at end of file diff --git a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/core/protocol/proton/TestConversions.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/TestConversions.java similarity index 95% rename from artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/core/protocol/proton/TestConversions.java rename to artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/TestConversions.java index fc77c7d0da9..19524b04297 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/core/protocol/proton/TestConversions.java +++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/TestConversions.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.protocol.proton; +package org.apache.activemq.artemis.protocol.amqp.converter; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -28,9 +28,13 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.PooledByteBufAllocator; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSObjectMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.message.EncodedMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.message.EncodedMessage; import org.apache.activemq.artemis.core.server.impl.ServerMessageImpl; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage; import org.apache.blacklist.ABadClass; import org.apache.qpid.proton.amqp.Binary; import org.apache.qpid.proton.amqp.messaging.AmqpSequence; @@ -42,17 +46,12 @@ import org.apache.qpid.proton.message.impl.MessageImpl; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.core.journal.EncodingSupport; -import org.apache.activemq.artemis.core.protocol.proton.converter.ProtonMessageConverter; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSBytesMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSMapMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSStreamMessage; -import org.apache.activemq.artemis.core.protocol.proton.converter.jms.ServerJMSTextMessage; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage; import org.apache.activemq.artemis.core.server.ServerMessage; import org.apache.activemq.artemis.utils.SimpleIDGenerator; import org.junit.Assert; import org.junit.Test; -import org.proton.plug.util.NettyWritable; +import org.apache.activemq.artemis.protocol.amqp.util.NettyWritable; public class TestConversions extends Assert { diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/ClientSASLPlain.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/sasl/ClientSASLPlain.java similarity index 80% rename from artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/ClientSASLPlain.java rename to artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/sasl/ClientSASLPlain.java index 59685ada5e4..0e9d0d43efa 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/sasl/ClientSASLPlain.java +++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/sasl/ClientSASLPlain.java @@ -14,15 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.sasl; - -import org.proton.plug.ClientSASL; +package org.apache.activemq.artemis.protocol.amqp.sasl; /** - * This is a simple implementation provided with just user/password - * TODO: this interface will probaby change as we are challenged with more SASL cases where there is a communication between client and server to determine the authentication + * This will generate what a client would generate for bytes on Plain sasl. Used on test */ -public class ClientSASLPlain implements ClientSASL { +public class ClientSASLPlain { private String username; private String password; @@ -32,12 +29,10 @@ public ClientSASLPlain(String user, String password) { this.password = password; } - @Override public String getName() { return "PLAIN"; } - @Override public byte[] getBytes() { if (username == null) { diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/sasl/PlainSASLTest.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/sasl/PlainSASLTest.java similarity index 88% rename from artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/sasl/PlainSASLTest.java rename to artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/sasl/PlainSASLTest.java index a085eab219b..d259de2d090 100644 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/sasl/PlainSASLTest.java +++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/sasl/PlainSASLTest.java @@ -14,13 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.test.sasl; +package org.apache.activemq.artemis.protocol.amqp.sasl; import org.junit.Assert; import org.junit.Test; -import org.proton.plug.sasl.ClientSASLPlain; -import org.proton.plug.sasl.PlainSASLResult; -import org.proton.plug.sasl.ServerSASLPlain; public class PlainSASLTest { diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/CreditsSemaphoreTest.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/CreditsSemaphoreTest.java similarity index 97% rename from artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/CreditsSemaphoreTest.java rename to artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/CreditsSemaphoreTest.java index b7ae38b942b..c608b854b35 100644 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/CreditsSemaphoreTest.java +++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/CreditsSemaphoreTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.proton.plug.test.util; +package org.apache.activemq.artemis.protocol.amqp.util; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -22,7 +22,6 @@ import org.junit.Assert; import org.junit.Test; -import org.proton.plug.util.CreditsSemaphore; public class CreditsSemaphoreTest { diff --git a/artemis-protocols/artemis-proton-plug/pom.xml b/artemis-protocols/artemis-proton-plug/pom.xml deleted file mode 100644 index 2412a43b03f..00000000000 --- a/artemis-protocols/artemis-proton-plug/pom.xml +++ /dev/null @@ -1,137 +0,0 @@ - - - - artemis-protocols - org.apache.activemq - 1.5.0-SNAPSHOT - - 4.0.0 - - artemis-proton-plug - ActiveMQ Artemis Proton Protocol - - - ${project.basedir}/../.. - - - - - - org.apache.activemq - artemis-jms-client - ${project.version} - - - org.apache.activemq - artemis-core-client - ${project.version} - - - org.jboss.logging - jboss-logging-processor - provided - true - - - - - - - org.jboss.logmanager - jboss-logmanager - test - - - - - org.apache.activemq - artemis-commons - ${project.version} - test - - - - org.jboss.logging - jboss-logging - - - org.apache.activemq - artemis-server - ${project.version} - - - org.apache.activemq - artemis-commons - ${project.version} - - - org.apache.qpid - proton-j - - - - org.apache.qpid - qpid-client - 0.24 - test - - - org.apache.qpid - qpid-jms-client - 0.5.0 - test - - - - - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - provided - - - junit - junit - test - - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - - - test-jar - - - - - - - - bundle - diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientConnectionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientConnectionContext.java deleted file mode 100644 index 1abd96f2813..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientConnectionContext.java +++ /dev/null @@ -1,36 +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.proton.plug; - -import org.proton.plug.exceptions.ActiveMQAMQPException; - -/** - * This is valid only on a client connection. - */ -public interface AMQPClientConnectionContext extends AMQPConnectionContext { - - /** - * This will send an open and block for its return on AMQP protocol. - * - * @throws Exception - */ - void clientOpen(ClientSASL sasl) throws Exception; - - AMQPClientSessionContext createClientSession() throws ActiveMQAMQPException; - - void setContainer(String containerID); -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientReceiverContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientReceiverContext.java deleted file mode 100644 index 514ee195fac..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientReceiverContext.java +++ /dev/null @@ -1,34 +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.proton.plug; - -import java.util.concurrent.TimeUnit; - -import org.apache.qpid.proton.message.ProtonJMessage; - -public interface AMQPClientReceiverContext { - - ProtonJMessage receiveMessage(int time, TimeUnit unit) throws Exception; - - void flow(int credits); - - void drain(int i); - - int drained(); - - boolean isDraining(); -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientSenderContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientSenderContext.java deleted file mode 100644 index 44d10561e58..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientSenderContext.java +++ /dev/null @@ -1,27 +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.proton.plug; - -import org.apache.qpid.proton.message.ProtonJMessage; - -public interface AMQPClientSenderContext { - - void send(ProtonJMessage message); - - String getAddress(); - -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientSessionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientSessionContext.java deleted file mode 100644 index 44cec7c8507..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPClientSessionContext.java +++ /dev/null @@ -1,30 +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.proton.plug; - -import org.proton.plug.exceptions.ActiveMQAMQPException; - -public interface AMQPClientSessionContext extends AMQPSessionContext { - - AMQPClientSenderContext createSender(String address, boolean preSettled) throws ActiveMQAMQPException; - - AMQPClientSenderContext createDynamicSender(boolean preSettled) throws ActiveMQAMQPException; - - AMQPClientReceiverContext createReceiver(String address) throws ActiveMQAMQPException; - - AMQPClientReceiverContext createReceiver(String name, String address) throws ActiveMQAMQPException; -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionCallback.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionCallback.java deleted file mode 100644 index f4ed64cd9ba..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionCallback.java +++ /dev/null @@ -1,58 +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.proton.plug; - -import io.netty.buffer.ByteBuf; -import org.apache.activemq.artemis.core.transaction.Transaction; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.engine.Connection; -import org.proton.plug.exceptions.ActiveMQAMQPException; - -public interface AMQPConnectionCallback { - - void close(); - - /** - * this is called when bytes are available to be sent to the client. - * you have to callback {@link org.proton.plug.AMQPConnectionContext#outputDone(int)} after you're done with this buffer - * - * @param bytes - */ - void onTransport(ByteBuf bytes, AMQPConnectionContext connection); - - AMQPSessionCallback createSessionCallback(AMQPConnectionContext connection); - - void setConnection(AMQPConnectionContext connection); - - AMQPConnectionContext getConnection(); - - ServerSASL[] getSASLMechnisms(); - - boolean isSupportsAnonymous(); - - void sendSASLSupported(); - - boolean validateConnection(Connection connection, SASLResult saslResult); - - Binary newTransaction(); - - Transaction getTransaction(Binary txid) throws ActiveMQAMQPException; - - void removeTransaction(Binary txid); - - -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionContext.java deleted file mode 100644 index 9123006fb3c..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionContext.java +++ /dev/null @@ -1,71 +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.proton.plug; - -import org.apache.qpid.proton.amqp.Symbol; - -import io.netty.buffer.ByteBuf; - -public interface AMQPConnectionContext { - - void close(); - - Object getLock(); - - boolean checkDataReceived(); - - long getCreationTime(); - - SASLResult getSASLResult(); - - /** - * Load and return a []Symbol that contains the connection capabilities - * offered to new connections - * - * @return the capabilities that are offered to new remote peers on connect. - */ - Symbol[] getConnectionCapabilitiesOffered(); - - /** - * Even though we are currently always sending packets asynchronsouly - * we have a possibility to start trusting on the network flow control - * and always sync on the send of the packet - * - * This is for future use and should be kept returning false. - * - * We will have to do some testing before we make this return true - */ - boolean isSyncOnFlush(); - - int capacity(); - - /** - * This is for the Remoting layer to push bytes on the AMQP Connection - * The buffer readerIndex should be at the latest read byte after this method is called - */ - void inputBuffer(ByteBuf buffer); - - void flush(); - - /** - * To be called when the bytes were sent down the stream (flushed on the socket for example) - * - * @param numberOfBytes - */ - void outputDone(int numberOfBytes); - -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionContextFactory.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionContextFactory.java deleted file mode 100644 index eb2a778a30d..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPConnectionContextFactory.java +++ /dev/null @@ -1,39 +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.proton.plug; - -import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; - -public abstract class AMQPConnectionContextFactory { - - /** - * @return - */ - public abstract AMQPConnectionContext createConnection(AMQPConnectionCallback connectionCallback, - String containerId, - int idleTimeout, - int maxFrameSize, - int channelMax, - Executor dispatchExecutor, - ScheduledExecutorService scheduledPool); - - /** - * @return - */ - public abstract AMQPConnectionContext createConnection(AMQPConnectionCallback connectionCallback, Executor dispatchExecutor, ScheduledExecutorService scheduledPool); -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPServerConnectionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPServerConnectionContext.java deleted file mode 100644 index 518c79e2b73..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPServerConnectionContext.java +++ /dev/null @@ -1,21 +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.proton.plug; - -public interface AMQPServerConnectionContext extends AMQPConnectionContext { - -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPSessionCallback.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPSessionCallback.java deleted file mode 100644 index 5f3b6dd57bd..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPSessionCallback.java +++ /dev/null @@ -1,112 +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.proton.plug; - -import io.netty.buffer.ByteBuf; -import org.apache.activemq.artemis.core.server.QueueQueryResult; -import org.apache.activemq.artemis.core.transaction.Transaction; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.message.ProtonJMessage; -import org.proton.plug.context.ProtonPlugSender; -import org.proton.plug.exceptions.ActiveMQAMQPException; - -/** - * These are methods where the Proton Plug component will call your server - */ -public interface AMQPSessionCallback { - - void init(AMQPSessionContext session, SASLResult saslResult) throws Exception; - - void start(); - - void onFlowConsumer(Object consumer, int credits, boolean drain); - - Object createSender(ProtonPlugSender protonSender, String queue, String filer, boolean browserOnly) throws Exception; - - void startSender(Object brokerConsumer) throws Exception; - - void createTemporaryQueue(String queueName) throws Exception; - - void createTemporaryQueue(String address, String queueName, String filter) throws Exception; - - void createDurableQueue(String address, String queueName, String filter) throws Exception; - - void offerProducerCredit(String address, int credits, int threshold, Receiver receiver); - - void deleteQueue(String address) throws Exception; - - /** - * Returns true if a queue is found with matching name, if autoCreate=true and autoCreateJMSQueues is switched on then - * this method will auto create the queue, with name=queueName, address=queueName, filter=null. - * - * @param queueName - * @param autoCreate - * @return - * @throws Exception - */ - QueueQueryResult queueQuery(String queueName, boolean autoCreate) throws Exception; - - boolean bindingQuery(String address) throws Exception; - - void closeSender(Object brokerConsumer) throws Exception; - - // This one can be a lot improved - ProtonJMessage encodeMessage(Object message, int deliveryCount) throws Exception; - - String tempQueueName(); - - - Transaction getTransaction(Binary txid) throws ActiveMQAMQPException; - - Binary newTransaction(); - - void commitTX(Binary txid) throws Exception; - - void rollbackTX(Binary txid, boolean lastMessageReceived) throws Exception; - - void close() throws Exception; - - void ack(Transaction transaction, Object brokerConsumer, Object message) throws Exception; - - /** - * @param brokerConsumer - * @param message - * @param updateCounts this identified if the cancel was because of a failure or just cleaning up the - * client's cache. - * in some implementations you could call this failed - */ - void cancel(Object brokerConsumer, Object message, boolean updateCounts) throws Exception; - - void resumeDelivery(Object consumer); - - /** - * @param delivery - * @param address - * @param messageFormat - * @param messageEncoded a Heap Buffer ByteBuffer (safe to convert into byte[]) - */ - void serverSend(Transaction transaction, - Receiver receiver, - Delivery delivery, - String address, - int messageFormat, - ByteBuf messageEncoded) throws Exception; - - String getPubSubPrefix(); -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPSessionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPSessionContext.java deleted file mode 100644 index 66e9c5ae593..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/AMQPSessionContext.java +++ /dev/null @@ -1,34 +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.proton.plug; - -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.engine.Sender; -import org.proton.plug.exceptions.ActiveMQAMQPException; - -public interface AMQPSessionContext { - - byte[] getTag(); - - void replaceTag(byte[] tag); - - void close(); - - void removeSender(Sender sender) throws ActiveMQAMQPException; - - void removeReceiver(Receiver receiver); -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonContextSender.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonContextSender.java deleted file mode 100644 index 29e3459e494..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonContextSender.java +++ /dev/null @@ -1,153 +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.proton.plug.context; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.PooledByteBufAllocator; -import org.apache.qpid.proton.amqp.transport.ErrorCondition; -import org.apache.qpid.proton.amqp.transport.SenderSettleMode; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.Sender; -import org.apache.qpid.proton.message.ProtonJMessage; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.util.CreditsSemaphore; -import org.proton.plug.util.NettyWritable; - -/** - * A this is a wrapper around an ActiveMQ Artemis ServerConsumer for handling outgoing messages and incoming acks via a Proton Sender - */ -public abstract class AbstractProtonContextSender extends ProtonInitializable implements ProtonDeliveryHandler { - - protected final AbstractProtonSessionContext protonSession; - protected final Sender sender; - protected final AbstractConnectionContext connection; - protected boolean closed = false; - protected final AMQPSessionCallback sessionSPI; - protected CreditsSemaphore creditsSemaphore = new CreditsSemaphore(0); - - public AbstractProtonContextSender(AbstractConnectionContext connection, - Sender sender, - AbstractProtonSessionContext protonSession, - AMQPSessionCallback server) { - this.connection = connection; - this.sender = sender; - this.protonSession = protonSession; - this.sessionSPI = server; - } - - @Override - public void onFlow(int credits, boolean drain) { - this.creditsSemaphore.setCredits(credits); - } - - /* - * start the session - * */ - public void start() throws ActiveMQAMQPException { - sessionSPI.start(); - // protonSession.getServerSession().start(); - } - - /* - * close the session - * */ - @Override - public void close(boolean linkRemoteClose) throws ActiveMQAMQPException { - closed = true; - protonSession.removeSender(sender); - synchronized (connection.getLock()) { - sender.close(); - } - - connection.flush(); - } - - /* - * close the session - * */ - @Override - public void close(ErrorCondition condition) throws ActiveMQAMQPException { - closed = true; - sender.setCondition(condition); - close(false); - } - - @Override - /* - * handle an incoming Ack from Proton, basically pass to ActiveMQ Artemis to handle - * */ public abstract void onMessage(Delivery delivery) throws ActiveMQAMQPException; - - /* - * check the state of the consumer, i.e. are there any more messages. only really needed for browsers? - * */ - public void checkState() { - } - - public Sender getSender() { - return sender; - } - - protected int performSend(ProtonJMessage serverMessage, Object context) { - if (!creditsSemaphore.tryAcquire()) { - try { - creditsSemaphore.acquire(); - } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); - // nothing to be done here.. we just keep going - throw new IllegalStateException(e.getMessage(), e); - } - } - - //presettle means we can ack the message on the dealer side before we send it, i.e. for browsers - boolean preSettle = sender.getRemoteSenderSettleMode() == SenderSettleMode.SETTLED; - - //we only need a tag if we are going to ack later - byte[] tag = preSettle ? new byte[0] : protonSession.getTag(); - - ByteBuf nettyBuffer = PooledByteBufAllocator.DEFAULT.heapBuffer(1024); - try { - serverMessage.encode(new NettyWritable(nettyBuffer)); - - int size = nettyBuffer.writerIndex(); - - synchronized (connection.getLock()) { - final Delivery delivery; - delivery = sender.delivery(tag, 0, tag.length); - delivery.setContext(context); - - // this will avoid a copy.. patch provided by Norman using buffer.array() - sender.send(nettyBuffer.array(), nettyBuffer.arrayOffset() + nettyBuffer.readerIndex(), nettyBuffer.readableBytes()); - - if (preSettle) { - delivery.settle(); - } - else { - sender.advance(); - } - } - - connection.flush(); - - return size; - } - finally { - nettyBuffer.release(); - } - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonReceiverContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonReceiverContext.java deleted file mode 100644 index c21095062b6..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonReceiverContext.java +++ /dev/null @@ -1,88 +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.proton.plug.context; - -import org.apache.qpid.proton.amqp.transport.ErrorCondition; -import org.apache.qpid.proton.engine.Receiver; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.exceptions.ActiveMQAMQPException; - -/** - * handles incoming messages via a Proton Receiver and forwards them to ActiveMQ - */ -public abstract class AbstractProtonReceiverContext extends ProtonInitializable implements ProtonDeliveryHandler { - - protected final AbstractConnectionContext connection; - - protected final AbstractProtonSessionContext protonSession; - - protected final Receiver receiver; - - protected String address; - - protected final AMQPSessionCallback sessionSPI; - - public AbstractProtonReceiverContext(AMQPSessionCallback sessionSPI, - AbstractConnectionContext connection, - AbstractProtonSessionContext protonSession, - Receiver receiver) { - this.connection = connection; - this.protonSession = protonSession; - this.receiver = receiver; - this.sessionSPI = sessionSPI; - } - - @Override - public void close(boolean remoteLinkClose) throws ActiveMQAMQPException { - protonSession.removeReceiver(receiver); - } - - @Override - public void close(ErrorCondition condition) throws ActiveMQAMQPException { - receiver.setCondition(condition); - close(false); - } - - public void flow(int credits, int threshold) { - // Use the SessionSPI to allocate producer credits, or default, always allocate credit. - if (sessionSPI != null) { - sessionSPI.offerProducerCredit(address, credits, threshold, receiver); - } - else { - synchronized (connection.getLock()) { - receiver.flow(credits); - connection.flush(); - } - } - - } - - public void drain(int credits) { - synchronized (connection.getLock()) { - receiver.drain(credits); - } - connection.flush(); - } - - public int drained() { - return receiver.drained(); - } - - public boolean isDraining() { - return receiver.draining(); - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonSessionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonSessionContext.java deleted file mode 100644 index 5c0a626f689..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractProtonSessionContext.java +++ /dev/null @@ -1,161 +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.proton.plug.context; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.qpid.proton.amqp.transport.ErrorCondition; -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.engine.Sender; -import org.apache.qpid.proton.engine.Session; -import org.jboss.logging.Logger; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.AMQPSessionContext; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.exceptions.ActiveMQAMQPInternalErrorException; - -/** - * ProtonSession is a direct representation of the session on the broker. - * It has a link between a ProtonSession and a Broker or Client Session - * The Broker Session is linked through the ProtonSessionSPI - */ -public abstract class AbstractProtonSessionContext extends ProtonInitializable implements AMQPSessionContext { - - private static final Logger log = Logger.getLogger(AbstractProtonSessionContext.class); - protected final AbstractConnectionContext connection; - - protected final AMQPSessionCallback sessionSPI; - - protected final Session session; - - private long currentTag = 0; - - protected Map receivers = new HashMap<>(); - - protected Map senders = new HashMap<>(); - - protected boolean closed = false; - - public AbstractProtonSessionContext(AMQPSessionCallback sessionSPI, - AbstractConnectionContext connection, - Session session) { - this.connection = connection; - this.sessionSPI = sessionSPI; - this.session = session; - } - - @Override - public void initialise() throws Exception { - if (!isInitialized()) { - super.initialise(); - - if (sessionSPI != null) { - try { - sessionSPI.init(this, connection.getSASLResult()); - } - catch (Exception e) { - throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e); - } - } - } - } - - /** - * TODO: maybe it needs to go? - * - * @param consumer - * @param queueName - */ - public void disconnect(Object consumer, String queueName) { - AbstractProtonContextSender protonConsumer = senders.remove(consumer); - if (protonConsumer != null) { - try { - protonConsumer.close(false); - } - catch (ActiveMQAMQPException e) { - protonConsumer.getSender().setTarget(null); - protonConsumer.getSender().setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage())); - } - } - } - - @Override - public byte[] getTag() { - return Long.toHexString(currentTag++).getBytes(); - } - - @Override - public void replaceTag(byte[] tag) { - // TODO: do we need to reuse this? - } - - @Override - public void close() { - if (closed) { - return; - } - - // Making a copy to avoid ConcurrentModificationException during the iteration - Set receiversCopy = new HashSet<>(); - receiversCopy.addAll(receivers.values()); - - for (AbstractProtonReceiverContext protonProducer : receiversCopy) { - try { - protonProducer.close(false); - } - catch (Exception e) { - log.warn(e.getMessage(), e); - } - } - receivers.clear(); - - Set protonSendersClone = new HashSet<>(); - protonSendersClone.addAll(senders.values()); - - for (AbstractProtonContextSender protonConsumer : protonSendersClone) { - try { - protonConsumer.close(false); - } - catch (Exception e) { - log.warn(e.getMessage(), e); - } - } - senders.clear(); - try { - if (sessionSPI != null) { - sessionSPI.close(); - } - } - catch (Exception e) { - log.warn(e.getMessage(), e); - } - closed = true; - } - - @Override - public void removeSender(Sender sender) throws ActiveMQAMQPException { - senders.remove(sender); - } - - @Override - public void removeReceiver(Receiver receiver) { - receivers.remove(receiver); - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonInitializable.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonInitializable.java deleted file mode 100644 index 266e8b2183a..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/ProtonInitializable.java +++ /dev/null @@ -1,67 +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.proton.plug.context; - -import java.util.concurrent.TimeUnit; - -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.exceptions.ActiveMQAMQPIllegalStateException; -import org.proton.plug.exceptions.ActiveMQAMQPTimeoutException; -import org.proton.plug.util.FutureRunnable; - -public class ProtonInitializable { - - private Runnable afterInit; - - private boolean initialized = false; - - public void afterInit(Runnable afterInit) { - this.afterInit = afterInit; - } - - public boolean isInitialized() { - return initialized; - } - - public void initialise() throws Exception { - if (!initialized) { - initialized = true; - try { - if (afterInit != null) { - afterInit.run(); - } - } - finally { - afterInit = null; - } - } - } - - public void waitWithTimeout(FutureRunnable latch) throws ActiveMQAMQPException { - try { - // TODO Configure this - if (!latch.await(30, TimeUnit.SECONDS)) { - throw new ActiveMQAMQPTimeoutException("Timed out waiting for response"); - } - } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new ActiveMQAMQPIllegalStateException(e.getMessage()); - } - } - -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientConnectionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientConnectionContext.java deleted file mode 100644 index 49d42f9443e..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientConnectionContext.java +++ /dev/null @@ -1,107 +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.proton.plug.context.client; - -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Session; -import org.proton.plug.AMQPClientConnectionContext; -import org.proton.plug.AMQPClientSessionContext; -import org.proton.plug.ClientSASL; -import org.proton.plug.AMQPConnectionCallback; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.context.AbstractConnectionContext; -import org.proton.plug.context.AbstractProtonSessionContext; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.context.ProtonInitializable; -import org.proton.plug.util.FutureRunnable; - -import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; - -public class ProtonClientConnectionContext extends AbstractConnectionContext implements AMQPClientConnectionContext { - - public ProtonClientConnectionContext(AMQPConnectionCallback connectionCallback, Executor dispatchExecutor, ScheduledExecutorService scheduledPool) { - super(connectionCallback, dispatchExecutor, scheduledPool); - } - - public ProtonClientConnectionContext(AMQPConnectionCallback connectionCallback, - String containerId, - int idleTimeout, - int maxFrameSize, - int channelMax, - Executor dispatchExecutor, - ScheduledExecutorService scheduledPool) { - super(connectionCallback, containerId, idleTimeout, maxFrameSize, channelMax, dispatchExecutor, scheduledPool); - } - - // Maybe a client interface? - @Override - public void clientOpen(ClientSASL sasl) throws Exception { - FutureRunnable future = new FutureRunnable(1); - synchronized (handler.getLock()) { - this.afterInit(future); - if (sasl != null) { - handler.createClientSasl(sasl); - } - handler.getConnection().open(); - } - - flush(); - - waitWithTimeout(future); - } - - @Override - public AMQPClientSessionContext createClientSession() throws ActiveMQAMQPException { - - FutureRunnable futureRunnable = new FutureRunnable(1); - ProtonClientSessionContext sessionImpl; - synchronized (handler.getLock()) { - Session session = handler.getConnection().session(); - sessionImpl = (ProtonClientSessionContext) getSessionExtension(session); - sessionImpl.afterInit(futureRunnable); - session.open(); - } - - flush(); - waitWithTimeout(futureRunnable); - - return sessionImpl; - } - - @Override - public void setContainer(String containerID) { - handler.getConnection().setContainer(containerID); - } - - @Override - protected AbstractProtonSessionContext newSessionExtension(Session realSession) throws ActiveMQAMQPException { - AMQPSessionCallback sessionSPI = connectionCallback.createSessionCallback(this); - AbstractProtonSessionContext protonSession = new ProtonClientSessionContext(sessionSPI, this, realSession); - - return protonSession; - - } - - @Override - protected void remoteLinkOpened(Link link) throws Exception { - Object context = link.getContext(); - if (context != null && context instanceof ProtonInitializable) { - ((ProtonInitializable) context).initialise(); - } - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientConnectionContextFactory.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientConnectionContextFactory.java deleted file mode 100644 index c0c0716e3c0..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientConnectionContextFactory.java +++ /dev/null @@ -1,50 +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.proton.plug.context.client; - -import org.proton.plug.AMQPConnectionContext; -import org.proton.plug.AMQPConnectionContextFactory; -import org.proton.plug.AMQPConnectionCallback; - -import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; - -public class ProtonClientConnectionContextFactory extends AMQPConnectionContextFactory { - - private static final AMQPConnectionContextFactory theInstance = new ProtonClientConnectionContextFactory(); - - public static AMQPConnectionContextFactory getFactory() { - return theInstance; - } - - @Override - public AMQPConnectionContext createConnection(AMQPConnectionCallback connectionCallback, Executor dispatchExecutor, ScheduledExecutorService scheduledPool) { - return new ProtonClientConnectionContext(connectionCallback, dispatchExecutor, scheduledPool); - } - - - @Override - public AMQPConnectionContext createConnection(AMQPConnectionCallback connectionCallback, - String containerId, - int idleTimeout, - int maxFrameSize, - int channelMax, - Executor dispatchExecutor, - ScheduledExecutorService scheduledPool) { - return new ProtonClientConnectionContext(connectionCallback, containerId, idleTimeout, maxFrameSize, channelMax, dispatchExecutor, scheduledPool); - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientContext.java deleted file mode 100644 index f442b9efa11..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientContext.java +++ /dev/null @@ -1,76 +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.proton.plug.context.client; - -import java.util.concurrent.TimeUnit; - -import org.apache.qpid.proton.amqp.messaging.Accepted; -import org.apache.qpid.proton.amqp.transport.SenderSettleMode; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.Sender; -import org.apache.qpid.proton.message.ProtonJMessage; -import org.proton.plug.AMQPClientSenderContext; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.context.AbstractConnectionContext; -import org.proton.plug.context.AbstractProtonContextSender; -import org.proton.plug.context.AbstractProtonSessionContext; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.util.FutureRunnable; - -public class ProtonClientContext extends AbstractProtonContextSender implements AMQPClientSenderContext { - - FutureRunnable catchUpRunnable = new FutureRunnable(); - - public ProtonClientContext(AbstractConnectionContext connection, - Sender sender, - AbstractProtonSessionContext protonSession, - AMQPSessionCallback server) { - super(connection, sender, protonSession, server); - } - - @Override - public void onMessage(Delivery delivery) throws ActiveMQAMQPException { - if (delivery.getRemoteState() instanceof Accepted) { - if (delivery.getContext() instanceof FutureRunnable) { - ((FutureRunnable) delivery.getContext()).countDown(); - } - } - } - - @Override - public void send(ProtonJMessage message) { - if (sender.getSenderSettleMode() != SenderSettleMode.SETTLED) { - catchUpRunnable.countUp(); - } - performSend(message, catchUpRunnable); - } - - public boolean sync(long timeout, TimeUnit unit) { - try { - return catchUpRunnable.await(timeout, unit); - } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return false; - } - } - - @Override - public String getAddress() { - return sender.getRemoteTarget().getAddress(); - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientReceiverContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientReceiverContext.java deleted file mode 100644 index c06ae58d249..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientReceiverContext.java +++ /dev/null @@ -1,92 +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.proton.plug.context.client; - -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.TimeUnit; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.PooledByteBufAllocator; -import org.apache.qpid.proton.amqp.messaging.Accepted; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.message.ProtonJMessage; -import org.apache.qpid.proton.message.impl.MessageImpl; -import org.proton.plug.AMQPClientReceiverContext; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.context.AbstractConnectionContext; -import org.proton.plug.context.AbstractProtonReceiverContext; -import org.proton.plug.context.AbstractProtonSessionContext; -import org.proton.plug.exceptions.ActiveMQAMQPException; - -import static org.proton.plug.util.DeliveryUtil.readDelivery; -import static org.proton.plug.util.DeliveryUtil.decodeMessageImpl; - -public class ProtonClientReceiverContext extends AbstractProtonReceiverContext implements AMQPClientReceiverContext { - - public ProtonClientReceiverContext(AMQPSessionCallback sessionSPI, - AbstractConnectionContext connection, - AbstractProtonSessionContext protonSession, - Receiver receiver) { - super(sessionSPI, connection, protonSession, receiver); - } - - @Override - public void onFlow(int credits, boolean drain) { - } - - LinkedBlockingDeque queues = new LinkedBlockingDeque<>(); - - /* - * called when Proton receives a message to be delivered via a Delivery. - * - * This may be called more than once per deliver so we have to cache the buffer until we have received it all. - * - * */ - @Override - public void onMessage(Delivery delivery) throws ActiveMQAMQPException { - ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(1024); - try { - synchronized (connection.getLock()) { - readDelivery(receiver, buffer); - MessageImpl clientMessage = decodeMessageImpl(buffer); - - // This second method could be better - // clientMessage.decode(buffer.nioBuffer()); - - receiver.advance(); - delivery.disposition(Accepted.getInstance()); - queues.add(clientMessage); - - } - } - finally { - buffer.release(); - } - } - - @Override - public ProtonJMessage receiveMessage(int time, TimeUnit unit) throws Exception { - return queues.poll(time, unit); - } - - @Override - public void flow(int credits) { - flow(credits, Integer.MAX_VALUE); - } - -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientSessionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientSessionContext.java deleted file mode 100644 index 9079dc37693..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/client/ProtonClientSessionContext.java +++ /dev/null @@ -1,145 +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.proton.plug.context.client; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.messaging.Accepted; -import org.apache.qpid.proton.amqp.messaging.DeleteOnClose; -import org.apache.qpid.proton.amqp.messaging.Rejected; -import org.apache.qpid.proton.amqp.messaging.Source; -import org.apache.qpid.proton.amqp.messaging.Target; -import org.apache.qpid.proton.amqp.messaging.TerminusDurability; -import org.apache.qpid.proton.amqp.messaging.TerminusExpiryPolicy; -import org.apache.qpid.proton.amqp.transport.SenderSettleMode; -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.engine.Sender; -import org.apache.qpid.proton.engine.Session; -import org.proton.plug.AMQPClientReceiverContext; -import org.proton.plug.AMQPClientSenderContext; -import org.proton.plug.AMQPClientSessionContext; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.AmqpSupport; -import org.proton.plug.context.AbstractConnectionContext; -import org.proton.plug.context.AbstractProtonSessionContext; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.util.FutureRunnable; - -public class ProtonClientSessionContext extends AbstractProtonSessionContext implements AMQPClientSessionContext { - - public ProtonClientSessionContext(AMQPSessionCallback sessionSPI, - AbstractConnectionContext connection, - Session session) { - super(sessionSPI, connection, session); - } - - @Override - public AMQPClientSenderContext createSender(String address, boolean preSettled) throws ActiveMQAMQPException { - FutureRunnable futureRunnable = new FutureRunnable(1); - - ProtonClientContext amqpSender; - synchronized (connection.getLock()) { - Sender sender = session.sender(address); - sender.setSenderSettleMode(SenderSettleMode.SETTLED); - Target target = new Target(); - target.setAddress(address); - sender.setTarget(target); - amqpSender = new ProtonClientContext(connection, sender, this, sessionSPI); - amqpSender.afterInit(futureRunnable); - sender.setContext(amqpSender); - sender.open(); - } - - connection.flush(); - - waitWithTimeout(futureRunnable); - return amqpSender; - } - - @Override - public AMQPClientSenderContext createDynamicSender(boolean preSettled) throws ActiveMQAMQPException { - FutureRunnable futureRunnable = new FutureRunnable(1); - - ProtonClientContext amqpSender; - synchronized (connection.getLock()) { - final String senderName = "Dynamic-" + UUID.randomUUID().toString(); - - Sender sender = session.sender(senderName); - sender.setSenderSettleMode(SenderSettleMode.SETTLED); - - Symbol[] outcomes = new Symbol[]{Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL}; - Source source = new Source(); - source.setAddress(senderName); - source.setOutcomes(outcomes); - - Target target = new Target(); - target.setDynamic(true); - target.setDurable(TerminusDurability.NONE); - target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH); - - // Set the dynamic node lifetime-policy - Map dynamicNodeProperties = new HashMap<>(); - dynamicNodeProperties.put(AmqpSupport.LIFETIME_POLICY, DeleteOnClose.getInstance()); - target.setDynamicNodeProperties(dynamicNodeProperties); - - amqpSender = new ProtonClientContext(connection, sender, this, sessionSPI); - amqpSender.afterInit(futureRunnable); - sender.setSource(source); - sender.setTarget(target); - sender.setContext(amqpSender); - sender.open(); - } - - connection.flush(); - - waitWithTimeout(futureRunnable); - return amqpSender; - } - - @Override - public AMQPClientReceiverContext createReceiver(String address) throws ActiveMQAMQPException { - return createReceiver(address, address); - } - - @Override - public AMQPClientReceiverContext createReceiver(String name, String address) throws ActiveMQAMQPException { - FutureRunnable futureRunnable = new FutureRunnable(1); - - ProtonClientReceiverContext amqpReceiver; - - synchronized (connection.getLock()) { - Receiver receiver = session.receiver(name); - Source source = new Source(); - source.setAddress(address); - receiver.setSource(source); - amqpReceiver = new ProtonClientReceiverContext(sessionSPI, connection, this, receiver); - receiver.setContext(amqpReceiver); - amqpReceiver.afterInit(futureRunnable); - receiver.open(); - } - - connection.flush(); - - waitWithTimeout(futureRunnable); - - return amqpReceiver; - - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContext.java deleted file mode 100644 index 3386732b71c..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContext.java +++ /dev/null @@ -1,94 +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.proton.plug.context.server; - -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.transaction.Coordinator; -import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.engine.Sender; -import org.apache.qpid.proton.engine.Session; -import org.proton.plug.AMQPConnectionCallback; -import org.proton.plug.AMQPServerConnectionContext; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.context.AbstractConnectionContext; -import org.proton.plug.context.AbstractProtonSessionContext; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.handler.ExtCapability; - -import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; - -public class ProtonServerConnectionContext extends AbstractConnectionContext implements AMQPServerConnectionContext { - - public ProtonServerConnectionContext(AMQPConnectionCallback connectionSP, Executor dispatchExecutor, ScheduledExecutorService scheduledPool) { - super(connectionSP, dispatchExecutor, scheduledPool); - } - - public ProtonServerConnectionContext(AMQPConnectionCallback connectionSP, - String containerId, - int idleTimeout, - int maxFrameSize, - int channelMax, - Executor dispatchExecutor, - ScheduledExecutorService scheduledPool) { - super(connectionSP, containerId, idleTimeout, maxFrameSize, channelMax, dispatchExecutor, scheduledPool); - } - - @Override - protected AbstractProtonSessionContext newSessionExtension(Session realSession) throws ActiveMQAMQPException { - AMQPSessionCallback sessionSPI = connectionCallback.createSessionCallback(this); - AbstractProtonSessionContext protonSession = new ProtonServerSessionContext(sessionSPI, this, realSession); - - return protonSession; - } - - @Override - protected boolean validateConnection(Connection connection) { - return connectionCallback.validateConnection(connection, handler.getSASLResult()); - } - - @Override - protected void remoteLinkOpened(Link link) throws Exception { - - ProtonServerSessionContext protonSession = (ProtonServerSessionContext) getSessionExtension(link.getSession()); - - link.setSource(link.getRemoteSource()); - link.setTarget(link.getRemoteTarget()); - if (link instanceof Receiver) { - Receiver receiver = (Receiver) link; - if (link.getRemoteTarget() instanceof Coordinator) { - Coordinator coordinator = (Coordinator) link.getRemoteTarget(); - protonSession.addTransactionHandler(coordinator, receiver); - } - else { - protonSession.addReceiver(receiver); - } - } - else { - Sender sender = (Sender) link; - protonSession.addSender(sender); - sender.offer(1); - } - } - - @Override - public Symbol[] getConnectionCapabilitiesOffered() { - return ExtCapability.getCapabilities(); - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContextFactory.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContextFactory.java deleted file mode 100644 index d5ab9ead95b..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContextFactory.java +++ /dev/null @@ -1,53 +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.proton.plug.context.server; - -import org.proton.plug.AMQPConnectionContextFactory; -import org.proton.plug.AMQPConnectionCallback; -import org.proton.plug.AMQPServerConnectionContext; - -import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; - -import static org.proton.plug.context.AMQPConstants.Connection.DEFAULT_IDLE_TIMEOUT; -import static org.proton.plug.context.AMQPConstants.Connection.DEFAULT_CHANNEL_MAX; -import static org.proton.plug.context.AMQPConstants.Connection.DEFAULT_MAX_FRAME_SIZE; - -public class ProtonServerConnectionContextFactory extends AMQPConnectionContextFactory { - - private static final ProtonServerConnectionContextFactory theInstance = new ProtonServerConnectionContextFactory(); - - public static ProtonServerConnectionContextFactory getFactory() { - return theInstance; - } - - @Override - public AMQPServerConnectionContext createConnection(AMQPConnectionCallback connectionCallback, Executor dispatchExecutor, ScheduledExecutorService scheduledPool) { - return createConnection(connectionCallback, null, DEFAULT_IDLE_TIMEOUT, DEFAULT_MAX_FRAME_SIZE, DEFAULT_CHANNEL_MAX, dispatchExecutor, scheduledPool); - } - - @Override - public AMQPServerConnectionContext createConnection(AMQPConnectionCallback connectionCallback, - String containerId, - int idleTimeout, - int maxFrameSize, - int channelMax, - Executor dispatchExecutor, - ScheduledExecutorService scheduledPool) { - return new ProtonServerConnectionContext(connectionCallback, containerId, idleTimeout, maxFrameSize, channelMax, dispatchExecutor, scheduledPool); - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerSessionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerSessionContext.java deleted file mode 100644 index 983fa4e9024..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerSessionContext.java +++ /dev/null @@ -1,117 +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.proton.plug.context.server; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.transaction.Coordinator; -import org.apache.qpid.proton.amqp.transport.ErrorCondition; -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.engine.Sender; -import org.apache.qpid.proton.engine.Session; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.context.AbstractConnectionContext; -import org.proton.plug.context.AbstractProtonContextSender; -import org.proton.plug.context.AbstractProtonReceiverContext; -import org.proton.plug.context.AbstractProtonSessionContext; -import org.proton.plug.context.ProtonTransactionHandler; -import org.proton.plug.exceptions.ActiveMQAMQPException; - -public class ProtonServerSessionContext extends AbstractProtonSessionContext { - - public ProtonServerSessionContext(AMQPSessionCallback sessionSPI, - AbstractConnectionContext connection, - Session session) { - super(sessionSPI, connection, session); - } - - protected Map serverSenders = new HashMap<>(); - - /** - * The consumer object from the broker or the key used to store the sender - * - * @param message - * @param consumer - * @param deliveryCount - * @return the number of bytes sent - */ - public int serverDelivery(Object message, Object consumer, int deliveryCount) throws Exception { - ProtonServerSenderContext protonSender = (ProtonServerSenderContext) serverSenders.get(consumer); - if (protonSender != null) { - return protonSender.deliverMessage(message, deliveryCount); - } - return 0; - } - - public void addTransactionHandler(Coordinator coordinator, Receiver receiver) { - ProtonTransactionHandler transactionHandler = new ProtonTransactionHandler(sessionSPI); - - coordinator.setCapabilities(Symbol.getSymbol("amqp:local-transactions"), - Symbol.getSymbol("amqp:multi-txns-per-ssn"), - Symbol.getSymbol("amqp:multi-ssns-per-txn")); - - receiver.setContext(transactionHandler); - receiver.open(); - receiver.flow(100); - } - - public void addSender(Sender sender) throws Exception { - ProtonServerSenderContext protonSender = new ProtonServerSenderContext(connection, sender, this, sessionSPI); - - try { - protonSender.initialise(); - senders.put(sender, protonSender); - serverSenders.put(protonSender.getBrokerConsumer(), protonSender); - sender.setContext(protonSender); - sender.open(); - protonSender.start(); - } - catch (ActiveMQAMQPException e) { - senders.remove(sender); - sender.setSource(null); - sender.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage())); - sender.close(); - } - } - - @Override - public void removeSender(Sender sender) throws ActiveMQAMQPException { - ProtonServerSenderContext senderRemoved = (ProtonServerSenderContext) senders.remove(sender); - if (senderRemoved != null) { - serverSenders.remove(senderRemoved.getBrokerConsumer()); - } - } - - public void addReceiver(Receiver receiver) throws Exception { - try { - AbstractProtonReceiverContext protonReceiver = new ProtonServerReceiverContext(sessionSPI, connection, this, receiver); - protonReceiver.initialise(); - receivers.put(receiver, protonReceiver); - receiver.setContext(protonReceiver); - receiver.open(); - } - catch (ActiveMQAMQPException e) { - receivers.remove(receiver); - receiver.setTarget(null); - receiver.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage())); - receiver.close(); - } - } - -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/ProtonHandler.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/ProtonHandler.java deleted file mode 100644 index d02546bbf65..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/ProtonHandler.java +++ /dev/null @@ -1,133 +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.proton.plug.handler; - -import java.util.concurrent.Executor; - -import io.netty.buffer.ByteBuf; -import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.Transport; -import org.proton.plug.ClientSASL; -import org.proton.plug.ServerSASL; -import org.proton.plug.SASLResult; -import org.proton.plug.handler.impl.ProtonHandlerImpl; - -/** - * This is a definition of the public interface for {@link org.proton.plug.handler.impl.ProtonHandlerImpl} - */ -public interface ProtonHandler { - - long tick(boolean firstTick); - - final class Factory { - public static ProtonHandler create(Executor dispatchExecutor) { - return new ProtonHandlerImpl(dispatchExecutor); - } - } - - /** - * It returns true if the transport connection has any capacity available - * - * @return - */ - int capacity(); - - Transport getTransport(); - - Connection getConnection(); - - /** - * Add an event handler to the chain - * - * @param handler - * @return - */ - ProtonHandler addEventHandler(EventHandler handler); - - void createClientSasl(ClientSASL clientSASL); - - /** - * To be used on server connections. To define SASL integration. - * - * @param handlers - */ - void createServerSASL(ServerSASL[] handlers); - - /** - * To return the SASL Mechanism that was successful with the connection. - * This should contain any state such as user and password - * - * @return - */ - SASLResult getSASLResult(); - - /** - * The input on the Handler. - * Notice that buffer will be positioned up to where we needed - * - * @param buffer - */ - void inputBuffer(ByteBuf buffer); - - /** - * To be used at your discretion to verify if the client was active since you last checked - * it can be used to implement server TTL cleanup and verifications - * - * @return - */ - boolean checkDataReceived(); - - /** - * Return the creation time of the handler - * - * @return - */ - long getCreationTime(); - - /** - * To be called after you used the outputBuffer - * - * @param bytes number of bytes you used already on the output - */ - void outputDone(int bytes); - - /** - * it will return pending bytes you have on the Transport - * after you are done with it you must call {@link #outputDone(int)} - * - * @return - */ - ByteBuf outputBuffer(); - - /** - * It will process the transport and cause events to be called - */ - void flush(); - - /** - * It will close the connection and flush events - */ - void close(); - - /** - * Get the object used to lock transport, connection and events operations - * - * @return - */ - Object getLock(); - -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/impl/DefaultEventHandler.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/impl/DefaultEventHandler.java deleted file mode 100644 index 45d5b67cfc5..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/handler/impl/DefaultEventHandler.java +++ /dev/null @@ -1,144 +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.proton.plug.handler.impl; - -import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Session; -import org.apache.qpid.proton.engine.Transport; -import org.proton.plug.handler.EventHandler; - -/** - * This is useful for cases where you only want to implement a few methods - */ -public abstract class DefaultEventHandler implements EventHandler { - - @Override - public void onInit(Connection connection) throws Exception { - - } - - @Override - public void onLocalOpen(Connection connection) throws Exception { - - } - - @Override - public void onRemoteOpen(Connection connection) throws Exception { - - } - - @Override - public void onLocalClose(Connection connection) throws Exception { - - } - - @Override - public void onRemoteClose(Connection connection) throws Exception { - } - - @Override - public void onFinal(Connection connection) throws Exception { - - } - - @Override - public void onInit(Session session) throws Exception { - - } - - @Override - public void onLocalOpen(Session session) throws Exception { - - } - - @Override - public void onRemoteOpen(Session session) throws Exception { - - } - - @Override - public void onLocalClose(Session session) throws Exception { - - } - - @Override - public void onRemoteClose(Session session) throws Exception { - - } - - @Override - public void onFinal(Session session) throws Exception { - - } - - @Override - public void onInit(Link link) throws Exception { - - } - - @Override - public void onLocalOpen(Link link) throws Exception { - - } - - @Override - public void onRemoteOpen(Link link) throws Exception { - - } - - @Override - public void onLocalClose(Link link) throws Exception { - - } - - @Override - public void onRemoteClose(Link link) throws Exception { - - } - - @Override - public void onFlow(Link link) throws Exception { - - } - - @Override - public void onFinal(Link link) throws Exception { - - } - - @Override - public void onRemoteDetach(Link link) throws Exception { - - } - - @Override - public void onDetach(Link link) throws Exception { - - } - - @Override - public void onDelivery(Delivery delivery) throws Exception { - - } - - @Override - public void onTransport(Transport transport) throws Exception { - - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ByteUtil.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ByteUtil.java deleted file mode 100644 index e1e69446c54..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ByteUtil.java +++ /dev/null @@ -1,130 +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.proton.plug.util; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import org.jboss.logging.Logger; - -public class ByteUtil { - - public static void debugFrame(Logger logger, String message, ByteBuf byteIn) { - if (logger.isTraceEnabled()) { - int location = byteIn.readerIndex(); - // debugging - byte[] frame = new byte[byteIn.writerIndex()]; - byteIn.readBytes(frame); - - try { - logger.trace(message + "\n" + ByteUtil.formatGroup(ByteUtil.bytesToHex(frame), 8, 16)); - } - catch (Exception e) { - logger.warn(e.getMessage(), e); - } - - byteIn.readerIndex(location); - } - } - - public static String formatGroup(String str, int groupSize, int lineBreak) { - StringBuffer buffer = new StringBuffer(); - - int line = 1; - buffer.append("/* 1 */ \""); - for (int i = 0; i < str.length(); i += groupSize) { - buffer.append(str.substring(i, i + Math.min(str.length() - i, groupSize))); - - if ((i + groupSize) % lineBreak == 0) { - buffer.append("\" +\n/* "); - line++; - if (line < 10) { - buffer.append(" "); - } - buffer.append(Integer.toString(line) + " */ \""); - } - else if ((i + groupSize) % groupSize == 0 && str.length() - i > groupSize) { - buffer.append("\" + \""); - } - } - - buffer.append("\";"); - - return buffer.toString(); - - } - - protected static final char[] hexArray = "0123456789ABCDEF".toCharArray(); - - public static String bytesToHex(byte[] bytes) { - char[] hexChars = new char[bytes.length * 2]; - for (int j = 0; j < bytes.length; j++) { - int v = bytes[j] & 0xFF; - hexChars[j * 2] = hexArray[v >>> 4]; - hexChars[j * 2 + 1] = hexArray[v & 0x0F]; - } - return new String(hexChars); - } - - public static byte[] hexStringToByteArray(String s) { - int len = s.length(); - byte[] data = new byte[len / 2]; - for (int i = 0; i < len; i += 2) { - data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); - } - return data; - } - - public static byte[] longToBytes(long x) { - ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.heapBuffer(8, 8); - buffer.writeLong(x); - return buffer.array(); - } - - public static String maxString(String value, int size) { - if (value.length() < size) { - return value; - } - else { - return value.substring(0, size / 2) + " ... " + value.substring(value.length() - size / 2); - } - } - - public static String bytesToHex(byte[] bytes, int groupSize) { - char[] hexChars = new char[bytes.length * 2 + numberOfGroups(bytes, groupSize)]; - int outPos = 0; - for (int j = 0; j < bytes.length; j++) { - if (j > 0 && j % groupSize == 0) { - hexChars[outPos++] = ' '; - } - int v = bytes[j] & 0xFF; - hexChars[outPos++] = hexArray[v >>> 4]; - hexChars[outPos++] = hexArray[v & 0x0F]; - } - return new String(hexChars); - } - - private static int numberOfGroups(byte[] bytes, int groupSize) { - int groups = bytes.length / groupSize; - - if (bytes.length % groupSize == 0) { - groups--; - } - - return groups; - } - -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/FutureRunnable.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/FutureRunnable.java deleted file mode 100644 index 20095ff2ff1..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/FutureRunnable.java +++ /dev/null @@ -1,61 +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.proton.plug.util; - -import java.util.concurrent.TimeUnit; - -public class FutureRunnable implements Runnable { - - private final ReusableLatch latch; - - public FutureRunnable(final int initialIterations) { - latch = new ReusableLatch(initialIterations); - } - - public FutureRunnable() { - this(0); - } - - @Override - public void run() { - latch.countDown(); - } - - public void countUp() { - latch.countUp(); - } - - public void countDown() { - latch.countDown(); - } - - public int getCount() { - return latch.getCount(); - } - - public void await() throws InterruptedException { - latch.await(); - } - - public boolean await(long timeWait, TimeUnit timeUnit) throws InterruptedException { - return latch.await(timeWait, timeUnit); - } - - public boolean await(long milliseconds) throws InterruptedException { - return latch.await(milliseconds); - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ReusableLatch.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ReusableLatch.java deleted file mode 100644 index beccc03987d..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/util/ReusableLatch.java +++ /dev/null @@ -1,130 +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.proton.plug.util; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.AbstractQueuedSynchronizer; - -/** - *

This class will use the framework provided to by AbstractQueuedSynchronizer.

- *

AbstractQueuedSynchronizer is the framework for any sort of concurrent synchronization, such as Semaphores, events, etc, based on AtomicIntegers.

- *

This class works just like CountDownLatch, with the difference you can also increase the counter

- *

It could be used for sync points when one process is feeding the latch while another will wait when everything is done. (e.g. waiting IO completions to finish)

- *

On ActiveMQ Artemis we have the requirement of increment and decrement a counter until the user fires a ready handler (commit). At that point we just act as a regular countDown.

- *

Note: This latch is reusable. Once it reaches zero, you can call up again, and reuse it on further waits.

- *

For example: prepareTransaction will wait for the current completions, and further adds will be called on the latch. Later on when commit is called you can reuse the same latch.

- */ -public class ReusableLatch { - - /** - * Look at the doc and examples provided by AbstractQueuedSynchronizer for more information - * - * @see AbstractQueuedSynchronizer - */ - @SuppressWarnings("serial") - private static class CountSync extends AbstractQueuedSynchronizer { - - private CountSync(int count) { - setState(count); - } - - public int getCount() { - return getState(); - } - - public void setCount(final int count) { - setState(count); - } - - @Override - public int tryAcquireShared(final int numberOfAqcquires) { - return getState() == 0 ? 1 : -1; - } - - public void add() { - for (;;) { - int actualState = getState(); - int newState = actualState + 1; - if (compareAndSetState(actualState, newState)) { - return; - } - } - } - - @Override - public boolean tryReleaseShared(final int numberOfReleases) { - for (;;) { - int actualState = getState(); - if (actualState == 0) { - return true; - } - - int newState = actualState - numberOfReleases; - - if (newState < 0) { - newState = 0; - } - - if (compareAndSetState(actualState, newState)) { - return newState == 0; - } - } - } - } - - private final CountSync control; - - public ReusableLatch() { - this(0); - } - - public ReusableLatch(final int count) { - control = new CountSync(count); - } - - public int getCount() { - return control.getCount(); - } - - public void setCount(final int count) { - control.setCount(count); - } - - public void countUp() { - control.add(); - } - - public void countDown() { - control.releaseShared(1); - } - - public void countDown(final int count) { - control.releaseShared(count); - } - - public void await() throws InterruptedException { - control.acquireSharedInterruptibly(1); - } - - public boolean await(final long milliseconds) throws InterruptedException { - return control.tryAcquireSharedNanos(1, TimeUnit.MILLISECONDS.toNanos(milliseconds)); - } - - public boolean await(final long timeWait, TimeUnit timeUnit) throws InterruptedException { - return control.tryAcquireSharedNanos(1, timeUnit.toNanos(timeWait)); - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/context/AbstractConnectionContextTest.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/context/AbstractConnectionContextTest.java deleted file mode 100644 index 825b98709b7..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/context/AbstractConnectionContextTest.java +++ /dev/null @@ -1,137 +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.proton.plug.context; - -import java.util.concurrent.Executors; - -import io.netty.buffer.ByteBuf; - -import org.apache.activemq.artemis.core.transaction.Transaction; -import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Session; -import org.junit.Test; -import org.proton.plug.AMQPConnectionCallback; -import org.proton.plug.AMQPConnectionContext; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.SASLResult; -import org.proton.plug.ServerSASL; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.handler.EventHandler; - -public class AbstractConnectionContextTest { - - @Test - public void testListenerDoesntThrowNPEWhenClosingLinkWithNullContext() throws Exception { - TestConnectionContext connectionContext = new TestConnectionContext(new TestConnectionCallback()); - EventHandler listener = connectionContext.getListener(); - - Connection protonConnection = Connection.Factory.create(); - Session protonSession = protonConnection.session(); - Link link = protonSession.receiver("link"); - - link.setContext(null); - - listener.onRemoteClose(link); - } - - private class TestConnectionContext extends AbstractConnectionContext { - - private TestConnectionContext(AMQPConnectionCallback connectionCallback) { - super(connectionCallback, Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()), null); - } - - @Override - protected void remoteLinkOpened(Link link) throws Exception { - - } - - @Override - protected AbstractProtonSessionContext newSessionExtension(Session realSession) throws ActiveMQAMQPException { - return null; - } - - public EventHandler getListener() { - return listener; - } - } - - private class TestConnectionCallback implements AMQPConnectionCallback { - - @Override - public void close() { - - } - - @Override - public Binary newTransaction() { - return null; - } - - @Override - public Transaction getTransaction(Binary txid) throws ActiveMQAMQPException { - return null; - } - - @Override - public void removeTransaction(Binary txid) { - - } - - @Override - public void onTransport(ByteBuf bytes, AMQPConnectionContext connection) { - - } - - @Override - public AMQPSessionCallback createSessionCallback(AMQPConnectionContext connection) { - return null; - } - - @Override - public void setConnection(AMQPConnectionContext connection) { - - } - - @Override - public AMQPConnectionContext getConnection() { - return null; - } - - @Override - public ServerSASL[] getSASLMechnisms() { - return null; - } - - @Override - public boolean isSupportsAnonymous() { - return true; - } - - @Override - public void sendSASLSupported() { - - } - - @Override - public boolean validateConnection(Connection connection, SASLResult saslResult) { - return true; - } - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/AbstractJMSTest.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/AbstractJMSTest.java deleted file mode 100644 index 0046dd6e85b..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/AbstractJMSTest.java +++ /dev/null @@ -1,93 +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.proton.plug.test; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.Queue; -import javax.jms.Session; - -import java.lang.ref.WeakReference; - -import org.apache.qpid.jms.JmsConnectionFactory; -import org.jboss.logging.Logger; -import org.proton.plug.test.minimalserver.DumbServer; -import org.proton.plug.test.minimalserver.MinimalServer; - -public class AbstractJMSTest { - - private static final Logger log = Logger.getLogger(AbstractJMSTest.class); - - protected final boolean useSASL; - - protected String address = "exampleQueue"; - protected MinimalServer server = new MinimalServer(); - - public AbstractJMSTest(boolean useSASL) { - this.useSASL = useSASL; - } - - public void tearDown() throws Exception { - server.stop(); - DumbServer.clear(); - } - - public static void forceGC() { - System.out.println("#test forceGC"); - WeakReference dumbReference = new WeakReference<>(new Object()); - // A loop that will wait GC, using the minimalserver time as possible - while (dumbReference.get() != null) { - System.gc(); - try { - Thread.sleep(100); - } - catch (InterruptedException e) { - } - } - System.out.println("#test forceGC Done"); - } - - protected Connection createConnection() throws JMSException { - final ConnectionFactory factory = createConnectionFactory(); - final Connection connection = factory.createConnection(); - connection.setExceptionListener(new ExceptionListener() { - @Override - public void onException(JMSException exception) { - log.warn(exception.getMessage(), exception); - } - }); - connection.start(); - return connection; - } - - protected ConnectionFactory createConnectionFactory() { - if (useSASL) { - return new JmsConnectionFactory("aaaaaaaa", "aaaaaaa", "amqp://localhost:5672"); - } - else { - return new JmsConnectionFactory( "amqp://localhost:5672"); - - } - } - - protected Queue createQueue(Session session) throws Exception { - return session.createQueue(address); - } - -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/ProtonTest.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/ProtonTest.java deleted file mode 100644 index 4c3aaf4e429..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/ProtonTest.java +++ /dev/null @@ -1,335 +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.proton.plug.test; - -import javax.jms.BytesMessage; -import javax.jms.Connection; -import javax.jms.DeliveryMode; -import javax.jms.JMSException; -import javax.jms.MapMessage; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; - -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.amqp.messaging.Properties; -import org.apache.qpid.proton.message.Message; -import org.apache.qpid.proton.message.impl.MessageImpl; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.proton.plug.AMQPClientConnectionContext; -import org.proton.plug.AMQPClientSenderContext; -import org.proton.plug.AMQPClientSessionContext; -import org.proton.plug.sasl.ClientSASLPlain; -import org.proton.plug.test.minimalclient.SimpleAMQPConnector; -import org.proton.plug.test.minimalserver.DumbServer; -import org.proton.plug.util.ByteUtil; - -/** - * This is simulating a JMS client against a simple server - * This is being effectively tested by {@link org.apache.activemq.artemis.tests.integration.proton.ProtonTest} with a proper framework in place. - * This test eventually hungs on the testsuite. - * While it is still valid for debugging, for that reason the test will be ignored. - * and will be kept here for debug purposes. - */ -@Ignore // remove this to debug it -@RunWith(Parameterized.class) -public class ProtonTest extends AbstractJMSTest { - - protected Connection connection; - - @Parameterized.Parameters(name = "sasl={0}") - public static Collection data() { - List list = Arrays.asList(new Object[][]{{Boolean.TRUE}, {Boolean.FALSE}}); - System.out.println("Size = " + list.size()); - return list; - } - - public ProtonTest(boolean useSASL) { - super(useSASL); - } - - @Before - public void setUp() throws Exception { - DumbServer.clear(); - AbstractJMSTest.forceGC(); - server.start("127.0.0.1", Constants.PORT, true); - connection = createConnection(); - } - - @Override - @After - public void tearDown() throws Exception { - if (connection != null) { - connection.close(); - } - - super.tearDown(); - } - - @Test - public void testMessagesReceivedInParallel() throws Throwable { - final int numMessages = getNumberOfMessages(); - long time = System.currentTimeMillis(); - - final ArrayList exceptions = new ArrayList<>(); - - Thread t = new Thread(new Runnable() { - @Override - public void run() { - Connection connectionConsumer = null; - try { - connectionConsumer = createConnection(); - // connectionConsumer = connection; - connectionConsumer.start(); - Session sessionConsumer = connectionConsumer.createSession(false, Session.AUTO_ACKNOWLEDGE); - final Queue queue = createQueue(sessionConsumer); - final MessageConsumer consumer = sessionConsumer.createConsumer(queue); - - int count = numMessages; - while (count > 0) { - try { - BytesMessage m = (BytesMessage) consumer.receive(1000); - if (count % 1000 == 0) { - System.out.println("Count = " + count + ", property=" + m.getStringProperty("XX")); - } - Assert.assertNotNull("Could not receive message count=" + count + " on consumer", m); - count--; - } - catch (JMSException e) { - break; - } - } - } - catch (Throwable e) { - exceptions.add(e); - e.printStackTrace(); - } - finally { - try { - // if the createconnecion wasn't commented out - if (connectionConsumer != connection) { - connectionConsumer.close(); - } - } - catch (Throwable ignored) { - // NO OP - } - } - } - }); - - Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE); - - t.start(); - final Queue queue = createQueue(session); - - MessageProducer p = session.createProducer(queue); - p.setDeliveryMode(DeliveryMode.PERSISTENT); - for (int i = 0; i < numMessages; i++) { - BytesMessage message = session.createBytesMessage(); - // TODO: this will break stuff if I use a large number - message.writeBytes(new byte[5]); - message.setIntProperty("count", i); - message.setStringProperty("XX", "count" + i); - p.send(message); - } - - long taken = (System.currentTimeMillis() - time); - System.out.println("taken on send = " + taken + " sasl = " + useSASL); - t.join(); - - for (Throwable e : exceptions) { - throw e; - } - taken = (System.currentTimeMillis() - time); - System.out.println("taken = " + taken + " sasl = " + useSASL); - - connection.close(); - // assertEquals(0, q.getMessageCount()); - } - - @Test - public void testSimpleCreateSessionAndClose() throws Throwable { - - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Queue queue = session.createQueue(address); - Thread.sleep(1000); - session.close(); - connection.close(); - } - - @Test - public void testSimpleBinary() throws Throwable { - final int numMessages = 5; - long time = System.currentTimeMillis(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - Queue queue = createQueue(session); - - byte[] bytes = new byte[0xf + 1]; - for (int i = 0; i <= 0xf; i++) { - bytes[i] = (byte) i; - } - - MessageProducer p = session.createProducer(queue); - for (int i = 0; i < numMessages; i++) { - BytesMessage message = session.createBytesMessage(); - - message.writeBytes(bytes); - message.setIntProperty("count", i); - p.send(message); - } - - session.close(); - - Session sessionConsumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - final MessageConsumer consumer = sessionConsumer.createConsumer(queue); - - for (int i = 0; i < numMessages; i++) { - BytesMessage m = (BytesMessage) consumer.receive(5000); - - System.out.println("length " + m.getBodyLength()); - Assert.assertNotNull("Could not receive message count=" + i + " on consumer", m); - - m.reset(); - - long size = m.getBodyLength(); - byte[] bytesReceived = new byte[(int) size]; - m.readBytes(bytesReceived); - - System.out.println("Received " + ByteUtil.bytesToHex(bytesReceived, 1)); - - Assert.assertArrayEquals(bytes, bytesReceived); - } - - // assertEquals(0, q.getMessageCount()); - long taken = (System.currentTimeMillis() - time) / 1000; - System.out.println("taken = " + taken); - } - - @Test - public void testMapMessage() throws Exception { - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Queue queue = createQueue(session); - MessageProducer p = session.createProducer(queue); - for (int i = 0; i < 10; i++) { - MapMessage message = session.createMapMessage(); - message.setInt("x", i); - message.setString("str", "str" + i); - p.send(message); - } - MessageConsumer messageConsumer = session.createConsumer(queue); - for (int i = 0; i < 10; i++) { - MapMessage m = (MapMessage) messageConsumer.receive(5000); - Assert.assertNotNull(m); - Assert.assertEquals(i, m.getInt("x")); - Assert.assertEquals("str" + i, m.getString("str")); - } - - Assert.assertNull(messageConsumer.receiveNoWait()); - } - - @Test - public void testProperties() throws Exception { - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Queue queue = createQueue(session); - MessageProducer p = session.createProducer(queue); - TextMessage message = session.createTextMessage(); - message.setText("msg:0"); - message.setBooleanProperty("true", true); - message.setBooleanProperty("false", false); - message.setStringProperty("foo", "bar"); - message.setDoubleProperty("double", 66.6); - message.setFloatProperty("float", 56.789f); - message.setIntProperty("int", 8); - message.setByteProperty("byte", (byte) 10); - p.send(message); - p.send(message); - connection.start(); - MessageConsumer messageConsumer = session.createConsumer(queue); - TextMessage m = (TextMessage) messageConsumer.receive(5000); - Assert.assertNotNull(m); - Assert.assertEquals("msg:0", m.getText()); - Assert.assertEquals(m.getBooleanProperty("true"), true); - Assert.assertEquals(m.getBooleanProperty("false"), false); - Assert.assertEquals(m.getStringProperty("foo"), "bar"); - Assert.assertEquals(m.getDoubleProperty("double"), 66.6, 0.0001); - Assert.assertEquals(m.getFloatProperty("float"), 56.789f, 0.0001); - Assert.assertEquals(m.getIntProperty("int"), 8); - Assert.assertEquals(m.getByteProperty("byte"), (byte) 10); - m = (TextMessage) messageConsumer.receive(5000); - Assert.assertNotNull(m); - connection.close(); - } - - // @Test - public void testSendWithSimpleClient() throws Exception { - SimpleAMQPConnector connector = new SimpleAMQPConnector(); - connector.start(); - AMQPClientConnectionContext clientConnection = connector.connect("127.0.0.1", Constants.PORT); - - clientConnection.clientOpen(new ClientSASLPlain("aa", "aa")); - - AMQPClientSessionContext session = clientConnection.createClientSession(); - AMQPClientSenderContext clientSender = session.createSender(address, true); - - Properties props = new Properties(); - for (int i = 0; i < 1; i++) { - MessageImpl message = (MessageImpl) Message.Factory.create(); - - HashMap map = new HashMap(); - - map.put("i", i); - AmqpValue value = new AmqpValue(map); - message.setBody(value); - message.setProperties(props); - clientSender.send(message); - } - - Session clientSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - connection.start(); - - MessageConsumer consumer = clientSession.createConsumer(createQueue(clientSession)); - for (int i = 0; i < 1; i++) { - MapMessage msg = (MapMessage) consumer.receive(5000); - System.out.println("Msg " + msg); - Assert.assertNotNull(msg); - - System.out.println("Receive message " + i); - - Assert.assertEquals(0, msg.getInt("i")); - } - } - - protected int getNumberOfMessages() { - return 10000; - } - -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/invm/InVMTestConnector.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/invm/InVMTestConnector.java deleted file mode 100644 index 197c39ea891..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/invm/InVMTestConnector.java +++ /dev/null @@ -1,40 +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.proton.plug.test.invm; - -import java.util.concurrent.Executors; - -import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; -import org.proton.plug.AMQPClientConnectionContext; -import org.proton.plug.context.client.ProtonClientConnectionContext; -import org.proton.plug.test.minimalclient.Connector; - -/** - * This is used for testing, where we bypass Netty or any networking for test conditions only - */ -public class InVMTestConnector implements Connector { - - @Override - public void start() { - - } - - @Override - public AMQPClientConnectionContext connect(String host, int port) throws Exception { - return new ProtonClientConnectionContext(new ProtonINVMSPI(), Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()), null); - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/invm/ProtonINVMSPI.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/invm/ProtonINVMSPI.java deleted file mode 100644 index a35e8ac13fb..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/invm/ProtonINVMSPI.java +++ /dev/null @@ -1,240 +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.proton.plug.test.invm; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import io.netty.buffer.ByteBuf; -import org.apache.activemq.artemis.core.transaction.Transaction; -import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.engine.Connection; -import org.jboss.logging.Logger; -import org.proton.plug.AMQPConnectionContext; -import org.proton.plug.AMQPConnectionCallback; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.SASLResult; -import org.proton.plug.ServerSASL; -import org.proton.plug.context.server.ProtonServerConnectionContext; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.sasl.AnonymousServerSASL; -import org.proton.plug.sasl.ServerSASLPlain; -import org.proton.plug.test.minimalserver.MinimalSessionSPI; -import org.proton.plug.util.ByteUtil; - -public class ProtonINVMSPI implements AMQPConnectionCallback { - - private static final Logger log = Logger.getLogger(ProtonINVMSPI.class); - - - AMQPConnectionContext returningConnection; - - ProtonServerConnectionContext serverConnection = new ProtonServerConnectionContext(new ReturnSPI(), Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()), null); - - final ExecutorService mainExecutor = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()); - - final ExecutorService returningExecutor = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()); - - public ProtonINVMSPI() { - mainExecutor.execute(new Runnable() { - @Override - public void run() { - Thread.currentThread().setName("MainExecutor-INVM"); - } - }); - returningExecutor.execute(new Runnable() { - @Override - public void run() { - Thread.currentThread().setName("ReturningExecutor-INVM"); - } - }); - } - - @Override - public void close() { - mainExecutor.shutdown(); - } - - @Override - public ServerSASL[] getSASLMechnisms() { - return new ServerSASL[]{new AnonymousServerSASL(), new ServerSASLPlain()}; - } - - @Override - public boolean isSupportsAnonymous() { - return true; - } - - @Override - public void sendSASLSupported() { - - } - - @Override - public boolean validateConnection(Connection connection, SASLResult saslResult) { - return true; - } - - @Override - public void onTransport(final ByteBuf bytes, final AMQPConnectionContext connection) { - if (log.isTraceEnabled()) { - ByteUtil.debugFrame(log, "InVM->", bytes); - } - final int size = bytes.writerIndex(); - - bytes.retain(); - mainExecutor.execute(new Runnable() { - @Override - public void run() { - try { - if (log.isTraceEnabled()) { - ByteUtil.debugFrame(log, "InVMDone->", bytes); - } - serverConnection.inputBuffer(bytes); - try { - connection.outputDone(size); - } - catch (Exception e) { - log.warn(e.getMessage(), e); - } - } - finally { - bytes.release(); - } - } - }); - } - - @Override - public void setConnection(AMQPConnectionContext connection) { - returningConnection = connection; - } - - @Override - public AMQPConnectionContext getConnection() { - return returningConnection; - } - - @Override - public AMQPSessionCallback createSessionCallback(AMQPConnectionContext connection) { - return null; - } - - @Override - public Binary newTransaction() { - return null; - } - - @Override - public Transaction getTransaction(Binary txid) throws ActiveMQAMQPException { - return null; - } - - @Override - public void removeTransaction(Binary txid) { - - } - - class ReturnSPI implements AMQPConnectionCallback { - - @Override - public void close() { - - } - - @Override - public Binary newTransaction() { - return null; - } - - @Override - public Transaction getTransaction(Binary txid) throws ActiveMQAMQPException { - return null; - } - - @Override - public void removeTransaction(Binary txid) { - - } - - @Override - public ServerSASL[] getSASLMechnisms() { - return new ServerSASL[]{new AnonymousServerSASL(), new ServerSASLPlain()}; - } - - @Override - public boolean isSupportsAnonymous() { - return false; - } - - @Override - public void sendSASLSupported() { - - } - - @Override - public boolean validateConnection(Connection connection, SASLResult saslResult) { - return true; - } - - @Override - public void onTransport(final ByteBuf bytes, final AMQPConnectionContext connection) { - - final int size = bytes.writerIndex(); - ByteUtil.debugFrame(log, "InVM<-", bytes); - - bytes.retain(); - returningExecutor.execute(new Runnable() { - @Override - public void run() { - try { - - ByteUtil.debugFrame(log, "InVM done<-", bytes); - - returningConnection.inputBuffer(bytes); - try { - connection.outputDone(size); - } - catch (Exception e) { - log.warn(e.getMessage(), e); - } - - } - finally { - bytes.release(); - } - } - }); - } - - @Override - public AMQPSessionCallback createSessionCallback(AMQPConnectionContext connection) { - return new MinimalSessionSPI(); - } - - @Override - public void setConnection(AMQPConnectionContext connection) { - - } - - @Override - public AMQPConnectionContext getConnection() { - return null; - } - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/AMQPClientSPI.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/AMQPClientSPI.java deleted file mode 100644 index 85e4c0247e2..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/AMQPClientSPI.java +++ /dev/null @@ -1,140 +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.proton.plug.test.minimalclient; - -import java.util.concurrent.TimeUnit; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import org.apache.activemq.artemis.core.transaction.Transaction; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.engine.Connection; -import org.jboss.logging.Logger; -import org.proton.plug.AMQPConnectionContext; -import org.proton.plug.AMQPConnectionCallback; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.SASLResult; -import org.proton.plug.ServerSASL; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.sasl.AnonymousServerSASL; -import org.proton.plug.sasl.ServerSASLPlain; -import org.proton.plug.util.ByteUtil; -import org.proton.plug.util.ReusableLatch; - -public class AMQPClientSPI implements AMQPConnectionCallback { - - private static final Logger log = Logger.getLogger(AMQPClientSPI.class); - final Channel channel; - protected AMQPConnectionContext connection; - - public AMQPClientSPI(Channel channel) { - this.channel = channel; - } - - @Override - public void setConnection(AMQPConnectionContext connection) { - this.connection = connection; - } - - @Override - public AMQPConnectionContext getConnection() { - return connection; - } - - @Override - public void close() { - - } - - @Override - public ServerSASL[] getSASLMechnisms() { - return new ServerSASL[]{new AnonymousServerSASL(), new ServerSASLPlain()}; - } - - @Override - public boolean isSupportsAnonymous() { - return true; - } - - @Override - public void sendSASLSupported() { - - } - - @Override - public Binary newTransaction() { - return null; - } - - @Override - public Transaction getTransaction(Binary txid) throws ActiveMQAMQPException { - return null; - } - - @Override - public void removeTransaction(Binary txid) { - - } - - @Override - public boolean validateConnection(Connection connection, SASLResult saslResult) { - return true; - } - - final ReusableLatch latch = new ReusableLatch(0); - - @Override - public void onTransport(final ByteBuf bytes, final AMQPConnectionContext connection) { - if (log.isTraceEnabled()) { - ByteUtil.debugFrame(log, "Bytes leaving client", bytes); - } - - final int bufferSize = bytes.writerIndex(); - - latch.countUp(); - - channel.writeAndFlush(bytes).addListener(new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture future) throws Exception { - // - // connection.outputDone(bufferSize); - latch.countDown(); - } - }); - - if (connection.isSyncOnFlush()) { - try { - if (!latch.await(5, TimeUnit.SECONDS)) { - log.debug("Flush took longer than 5 seconds!!!"); - } - } - catch (Throwable e) { - log.warn(e.getMessage(), e); - } - } - - connection.outputDone(bufferSize); - - } - - @Override - public AMQPSessionCallback createSessionCallback(AMQPConnectionContext connection) { - return null; - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/SimpleAMQPConnector.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/SimpleAMQPConnector.java deleted file mode 100644 index 59772f079b4..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalclient/SimpleAMQPConnector.java +++ /dev/null @@ -1,76 +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.proton.plug.test.minimalclient; - -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.concurrent.Executors; - -import io.netty.bootstrap.Bootstrap; -import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.channel.ChannelDuplexHandler; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioSocketChannel; -import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; -import org.proton.plug.AMQPClientConnectionContext; -import org.proton.plug.context.client.ProtonClientConnectionContextFactory; - -public class SimpleAMQPConnector implements Connector { - - private Bootstrap bootstrap; - - @Override - public void start() { - - bootstrap = new Bootstrap(); - bootstrap.channel(NioSocketChannel.class); - bootstrap.group(new NioEventLoopGroup(10)); - - bootstrap.handler(new ChannelInitializer() { - @Override - public void initChannel(Channel channel) throws Exception { - } - }); - } - - @Override - public AMQPClientConnectionContext connect(String host, int port) throws Exception { - SocketAddress remoteDestination = new InetSocketAddress(host, port); - - ChannelFuture future = bootstrap.connect(remoteDestination); - - future.awaitUninterruptibly(); - - AMQPClientSPI clientConnectionSPI = new AMQPClientSPI(future.channel()); - - final AMQPClientConnectionContext connection = (AMQPClientConnectionContext) ProtonClientConnectionContextFactory.getFactory().createConnection(clientConnectionSPI, Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()), null); - - future.channel().pipeline().addLast(new ChannelDuplexHandler() { - @Override - public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception { - ByteBuf buffer = (ByteBuf) msg; - connection.inputBuffer(buffer); - } - }); - - return connection; - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/DumbServer.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/DumbServer.java deleted file mode 100644 index 10499ef166d..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/DumbServer.java +++ /dev/null @@ -1,52 +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.proton.plug.test.minimalserver; - -import java.util.concurrent.BlockingDeque; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.LinkedBlockingDeque; - -public class DumbServer { - - static ConcurrentMap> maps = new ConcurrentHashMap<>(); - - public static BlockingDeque getQueue(String name) { - BlockingDeque q = maps.get(name); - if (q == null) { - q = new LinkedBlockingDeque<>(); - BlockingDeque oldValue = maps.putIfAbsent(name, q); - if (oldValue != null) { - q = oldValue; - } - } - return q; - } - - public static void clear() { - for (BlockingDeque queue : maps.values()) { - // We clear the queues just in case there is a component holding it - queue.clear(); - } - maps.clear(); - } - - public static void put(String queue, Object message) { - getQueue(queue).add(message); - } - -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalConnectionSPI.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalConnectionSPI.java deleted file mode 100644 index 6325ad7b0fd..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalConnectionSPI.java +++ /dev/null @@ -1,171 +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.proton.plug.test.minimalserver; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import org.apache.activemq.artemis.core.transaction.Transaction; -import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.engine.Connection; -import org.jboss.logging.Logger; -import org.proton.plug.AMQPConnectionContext; -import org.proton.plug.AMQPConnectionCallback; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.SASLResult; -import org.proton.plug.ServerSASL; -import org.proton.plug.exceptions.ActiveMQAMQPException; -import org.proton.plug.sasl.AnonymousServerSASL; -import org.proton.plug.sasl.ServerSASLPlain; -import org.proton.plug.util.ByteUtil; -import org.proton.plug.util.ReusableLatch; - -public class MinimalConnectionSPI implements AMQPConnectionCallback { - - private static final Logger logger = Logger.getLogger(MinimalConnectionSPI.class); - Channel channel; - - private AMQPConnectionContext connection; - - public MinimalConnectionSPI(Channel channel) { - this.channel = channel; - } - - ExecutorService executorService = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()); - - @Override - public void close() { - executorService.shutdown(); - } - - @Override - public void setConnection(AMQPConnectionContext connection) { - this.connection = connection; - } - - @Override - public AMQPConnectionContext getConnection() { - return connection; - } - - final ReusableLatch latch = new ReusableLatch(0); - - @Override - public ServerSASL[] getSASLMechnisms() { - return new ServerSASL[]{new AnonymousServerSASL(), new ServerSASLPlain()}; - } - - @Override - public boolean isSupportsAnonymous() { - return true; - } - - @Override - public void sendSASLSupported() { - - } - - @Override - public boolean validateConnection(Connection connection, SASLResult saslResult) { - return true; - } - - @Override - public Binary newTransaction() { - return null; - } - - @Override - public Transaction getTransaction(Binary txid) throws ActiveMQAMQPException { - return null; - } - - @Override - public void removeTransaction(Binary txid) { - - } - - @Override - public void onTransport(final ByteBuf bytes, final AMQPConnectionContext connection) { - final int bufferSize = bytes.writerIndex(); - - if (logger.isTraceEnabled()) { - // some debug - byte[] frame = new byte[bytes.writerIndex()]; - int readerOriginalPos = bytes.readerIndex(); - - bytes.getBytes(0, frame); - - try { - System.err.println("Buffer Outgoing: " + "\n" + ByteUtil.formatGroup(ByteUtil.bytesToHex(frame), 4, 16)); - } - catch (Exception e) { - e.printStackTrace(); - } - - bytes.readerIndex(readerOriginalPos); - } - - latch.countUp(); - // ^^ debug - - channel.writeAndFlush(bytes).addListener(new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture future) throws Exception { - latch.countDown(); - - // https://issues.apache.org/jira/browse/PROTON-645 - // connection.outputDone(bufferSize); - // if (connection.capacity() > 0) - // { - // channel.read(); - // } - } - }); - - channel.flush(); - - if (connection.isSyncOnFlush()) { - try { - if (!latch.await(5, TimeUnit.SECONDS)) { - // TODO logs - System.err.println("Flush took longer than 5 seconds!!!"); - } - } - catch (Throwable e) { - e.printStackTrace(); - } - } - connection.outputDone(bufferSize); - - // if (connection.capacity() > 0) - // { - // channel.read(); - // } - } - - @Override - public AMQPSessionCallback createSessionCallback(AMQPConnectionContext connection) { - return new MinimalSessionSPI(); - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalServer.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalServer.java deleted file mode 100644 index 8729cb40be2..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalServer.java +++ /dev/null @@ -1,167 +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.proton.plug.test.minimalserver; - -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.List; -import java.util.concurrent.Executors; - -import io.netty.bootstrap.ServerBootstrap; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.PooledByteBufAllocator; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelOption; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.ServerChannel; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.group.ChannelGroupFuture; -import io.netty.channel.group.DefaultChannelGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.handler.codec.ByteToMessageDecoder; -import io.netty.util.ResourceLeakDetector; -import io.netty.util.concurrent.GlobalEventExecutor; - -import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; -import org.proton.plug.AMQPServerConnectionContext; -import org.proton.plug.context.server.ProtonServerConnectionContextFactory; -import org.proton.plug.test.Constants; - -/** - * A Netty TCP Acceptor that supports SSL - */ -public class MinimalServer { - - static { - // Disable resource leak detection for performance reasons by default - ResourceLeakDetector.setEnabled(false); - } - - private Class channelClazz; - - private EventLoopGroup eventLoopGroup; - - private volatile ChannelGroup serverChannelGroup; - - private volatile ChannelGroup channelGroup; - - private ServerBootstrap bootstrap; - - private String host; - - private boolean sasl; - - // Constants.PORT is the default here - private int port; - - public synchronized void start(String host, int port, final boolean sasl) throws Exception { - this.host = host; - this.port = port; - this.sasl = sasl; - - if (channelClazz != null) { - // Already started - return; - } - - int threadsToUse = Runtime.getRuntime().availableProcessors() * 3; - channelClazz = NioServerSocketChannel.class; - eventLoopGroup = new NioEventLoopGroup(threadsToUse, new SimpleServerThreadFactory("simple-server", true, Thread.currentThread().getContextClassLoader())); - - bootstrap = new ServerBootstrap(); - bootstrap.group(eventLoopGroup); - bootstrap.channel(channelClazz); - - ChannelInitializer factory = new ChannelInitializer() { - @Override - public void initChannel(Channel channel) throws Exception { - ChannelPipeline pipeline = channel.pipeline(); - pipeline.addLast("amqp-handler", new ProtocolDecoder()); - } - }; - bootstrap.childHandler(factory); - - bootstrap.option(ChannelOption.SO_REUSEADDR, true). - childOption(ChannelOption.SO_REUSEADDR, true). - childOption(ChannelOption.SO_KEEPALIVE, true). - // childOption(ChannelOption.AUTO_READ, false). - childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); - - channelGroup = new DefaultChannelGroup("activemq-accepted-channels", GlobalEventExecutor.INSTANCE); - - serverChannelGroup = new DefaultChannelGroup("activemq-acceptor-channels", GlobalEventExecutor.INSTANCE); - - SocketAddress address; - address = new InetSocketAddress(host, port); - Channel serverChannel = bootstrap.bind(address).syncUninterruptibly().channel(); - serverChannelGroup.add(serverChannel); - - } - - class ProtocolDecoder extends ByteToMessageDecoder { - - AMQPServerConnectionContext connection; - - ProtocolDecoder() { - } - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - super.channelActive(ctx); - connection = ProtonServerConnectionContextFactory.getFactory().createConnection(new MinimalConnectionSPI(ctx.channel()), Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()), null); - //ctx.read(); - } - - @Override - protected void decode(final ChannelHandlerContext ctx, ByteBuf byteIn, List out) throws Exception { - connection.inputBuffer(byteIn); - ctx.flush(); - // if (connection.capacity() > 0) - // { - // ctx.read(); - // } - } - } - - public synchronized void stop() { - if (serverChannelGroup != null) { - serverChannelGroup.close().awaitUninterruptibly(); - } - - if (channelGroup != null) { - ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly(); - } - } - - public static void main(String[] arg) { - MinimalServer server = new MinimalServer(); - try { - server.start("127.0.0.1", Constants.PORT, true); - - while (true) { - Thread.sleep(360000000); - } - } - catch (Throwable e) { - e.printStackTrace(); - } - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalSessionSPI.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalSessionSPI.java deleted file mode 100644 index d366c5b2dcb..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalSessionSPI.java +++ /dev/null @@ -1,229 +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.proton.plug.test.minimalserver; - -import java.util.concurrent.BlockingDeque; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import io.netty.buffer.ByteBuf; -import org.apache.activemq.artemis.api.core.SimpleString; -import org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager; -import org.apache.activemq.artemis.core.server.QueueQueryResult; -import org.apache.activemq.artemis.core.transaction.Transaction; -import org.apache.activemq.artemis.core.transaction.impl.TransactionImpl; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.message.ProtonJMessage; -import org.proton.plug.AMQPSessionCallback; -import org.proton.plug.AMQPSessionContext; -import org.proton.plug.SASLResult; -import org.proton.plug.context.ProtonPlugSender; -import org.proton.plug.context.server.ProtonServerSessionContext; -import org.proton.plug.util.ProtonServerMessage; - -public class MinimalSessionSPI implements AMQPSessionCallback { - - private SASLResult result; - ProtonServerSessionContext session; - - @Override - public void init(AMQPSessionContext session, SASLResult result) { - this.session = (ProtonServerSessionContext) session; - this.result = result; - } - - @Override - public void start() { - } - - static AtomicInteger tempQueueGenerator = new AtomicInteger(0); - - @Override - public String tempQueueName() { - return "TempQueueName" + tempQueueGenerator.incrementAndGet(); - } - - @Override - public Object createSender(ProtonPlugSender plugSender, String queue, String filer, boolean browserOnly) { - Consumer consumer = new Consumer(DumbServer.getQueue(queue)); - return consumer; - } - - @Override - public void startSender(Object brokerConsumer) { - ((Consumer) brokerConsumer).start(); - } - - @Override - public void createTemporaryQueue(String queueName) { - - } - - @Override - public void createDurableQueue(String address, String queueName, String filter) throws Exception { - - } - - @Override - public void offerProducerCredit(String address, int credits, int threshold, Receiver receiver) { - - } - - @Override - public void createTemporaryQueue(String address, String queueName, String filter) throws Exception { - - } - - @Override - public void deleteQueue(String address) throws Exception { - - } - - @Override - public String getPubSubPrefix() { - return null; - } - - @Override - public void onFlowConsumer(Object consumer, int credits, boolean drain) { - } - - @Override - public QueueQueryResult queueQuery(String queueName, boolean autoCreate) { - return new QueueQueryResult(SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(queueName), false, false, null, 0, 0, false); - } - - @Override - public boolean bindingQuery(String address) throws Exception { - return true; - } - - @Override - public void closeSender(Object brokerConsumer) { - ((Consumer) brokerConsumer).close(); - } - - @Override - public ProtonJMessage encodeMessage(Object message, int deliveryCount) { - // We are storing internally as EncodedMessage on this minimalserver server - return (ProtonServerMessage) message; - } - - @Override - public Transaction getTransaction(Binary txid) { - return new TransactionImpl(new NullStorageManager()); - } - - @Override - public Binary newTransaction() { - return null; - } - - @Override - public void commitTX(Binary txid) throws Exception { - - } - - @Override - public void rollbackTX(Binary txid, boolean lastMessageReceived) throws Exception { - - } - - @Override - public void close() { - - } - - @Override - public void ack(Transaction tx, Object brokerConsumer, Object message) { - - } - - @Override - public void cancel(Object brokerConsumer, Object message, boolean updateCounts) { - - } - - @Override - public void resumeDelivery(Object consumer) { - System.out.println("Resume delivery!!!"); - ((Consumer) consumer).start(); - } - - @Override - public void serverSend(Transaction tx, Receiver receiver, Delivery delivery, String address, int messageFormat, ByteBuf buffer) { - ProtonServerMessage serverMessage = new ProtonServerMessage(); - serverMessage.decode(buffer.nioBuffer()); - - BlockingDeque queue = DumbServer.getQueue(address); - queue.add(serverMessage); - } - - class Consumer { - - final BlockingDeque queue; - - Consumer(BlockingDeque queue) { - this.queue = queue; - } - - boolean running = false; - volatile Thread thread; - - public void close() { - System.out.println("Closing!!!"); - running = false; - if (thread != null && Thread.currentThread() != thread) { - try { - thread.join(1000); - } - catch (Throwable ignored) { - } - } - - thread = null; - } - - public synchronized void start() { - running = true; - if (thread == null) { - System.out.println("Start!!!"); - thread = new Thread() { - @Override - public void run() { - try { - while (running) { - Object msg = queue.poll(1, TimeUnit.SECONDS); - - if (msg != null) { - session.serverDelivery(msg, Consumer.this, 1); - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - }; - thread.start(); - } - } - - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/SimpleServerThreadFactory.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/SimpleServerThreadFactory.java deleted file mode 100644 index ac1d28f8b41..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/SimpleServerThreadFactory.java +++ /dev/null @@ -1,82 +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.proton.plug.test.minimalserver; - -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; - -public final class SimpleServerThreadFactory implements ThreadFactory { - - private final ThreadGroup group; - - private final AtomicInteger threadCount = new AtomicInteger(0); - - private final int threadPriority; - - private final boolean daemon; - - private final ClassLoader tccl; - - public SimpleServerThreadFactory(final String groupName, final boolean daemon, final ClassLoader tccl) { - group = new ThreadGroup(groupName + "-" + System.identityHashCode(this)); - - this.threadPriority = Thread.NORM_PRIORITY; - - this.tccl = tccl; - - this.daemon = daemon; - } - - @Override - public Thread newThread(final Runnable command) { - final Thread t; - // attach the thread to a group only if there is no security manager: - // when sandboxed, the code does not have the RuntimePermission modifyThreadGroup - if (System.getSecurityManager() == null) { - t = new Thread(group, command, "Thread-" + threadCount.getAndIncrement() + " (" + group.getName() + ")"); - } - else { - t = new Thread(command, "Thread-" + threadCount.getAndIncrement()); - } - - AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Object run() { - t.setDaemon(daemon); - t.setPriority(threadPriority); - return null; - } - }); - - try { - AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Object run() { - t.setContextClassLoader(tccl); - return null; - } - }); - } - catch (java.security.AccessControlException e) { - e.printStackTrace(); - } - - return t; - } -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/ReusableLatchTest.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/ReusableLatchTest.java deleted file mode 100644 index 8909b5e3bfd..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/ReusableLatchTest.java +++ /dev/null @@ -1,300 +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.proton.plug.test.util; - -import java.util.concurrent.CountDownLatch; - -import org.junit.Assert; -import org.junit.Test; -import org.proton.plug.util.ReusableLatch; - -public class ReusableLatchTest { - - @Test - public void testLatchWithParameterizedDown() throws Exception { - ReusableLatch latch = new ReusableLatch(1000); - - latch.countDown(5000); - - Assert.assertTrue(latch.await(1000)); - - Assert.assertEquals(0, latch.getCount()); - } - - @Test - public void testLatchOnSingleThread() throws Exception { - ReusableLatch latch = new ReusableLatch(); - - for (int i = 1; i <= 100; i++) { - latch.countUp(); - Assert.assertEquals(i, latch.getCount()); - } - - for (int i = 100; i > 0; i--) { - Assert.assertEquals(i, latch.getCount()); - latch.countDown(); - Assert.assertEquals(i - 1, latch.getCount()); - } - - latch.await(); - } - - /** - * This test will open numberOfThreads threads, and add numberOfAdds on the - * VariableLatch After those addthreads are finished, the latch count should - * be numberOfThreads * numberOfAdds Then it will open numberOfThreads - * threads again releasing numberOfAdds on the VariableLatch After those - * releaseThreads are finished, the latch count should be 0 And all the - * waiting threads should be finished also - * - * @throws Exception - */ - @Test - public void testLatchOnMultiThread() throws Exception { - final ReusableLatch latch = new ReusableLatch(); - - latch.countUp(); // We hold at least one, so ThreadWaits won't go away - - final int numberOfThreads = 100; - final int numberOfAdds = 100; - - class ThreadWait extends Thread { - - private volatile boolean waiting = true; - - @Override - public void run() { - try { - if (!latch.await(5000)) { - System.err.println("Latch timed out"); - } - } - catch (Exception e) { - e.printStackTrace(); - } - waiting = false; - } - } - - class ThreadAdd extends Thread { - - private final CountDownLatch latchReady; - - private final CountDownLatch latchStart; - - ThreadAdd(final CountDownLatch latchReady, final CountDownLatch latchStart) { - this.latchReady = latchReady; - this.latchStart = latchStart; - } - - @Override - public void run() { - try { - latchReady.countDown(); - // Everybody should start at the same time, to worse concurrency - // effects - latchStart.await(); - for (int i = 0; i < numberOfAdds; i++) { - latch.countUp(); - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - } - - CountDownLatch latchReady = new CountDownLatch(numberOfThreads); - CountDownLatch latchStart = new CountDownLatch(1); - - ThreadAdd[] threadAdds = new ThreadAdd[numberOfThreads]; - ThreadWait[] waits = new ThreadWait[numberOfThreads]; - - for (int i = 0; i < numberOfThreads; i++) { - threadAdds[i] = new ThreadAdd(latchReady, latchStart); - threadAdds[i].start(); - waits[i] = new ThreadWait(); - waits[i].start(); - } - - latchReady.await(); - latchStart.countDown(); - - for (int i = 0; i < numberOfThreads; i++) { - threadAdds[i].join(); - } - - for (int i = 0; i < numberOfThreads; i++) { - Assert.assertTrue(waits[i].waiting); - } - - Assert.assertEquals(numberOfThreads * numberOfAdds + 1, latch.getCount()); - - class ThreadDown extends Thread { - - private final CountDownLatch latchReady; - - private final CountDownLatch latchStart; - - ThreadDown(final CountDownLatch latchReady, final CountDownLatch latchStart) { - this.latchReady = latchReady; - this.latchStart = latchStart; - } - - @Override - public void run() { - try { - latchReady.countDown(); - // Everybody should start at the same time, to worse concurrency - // effects - latchStart.await(); - for (int i = 0; i < numberOfAdds; i++) { - latch.countDown(); - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - } - - latchReady = new CountDownLatch(numberOfThreads); - latchStart = new CountDownLatch(1); - - ThreadDown[] down = new ThreadDown[numberOfThreads]; - - for (int i = 0; i < numberOfThreads; i++) { - down[i] = new ThreadDown(latchReady, latchStart); - down[i].start(); - } - - latchReady.await(); - latchStart.countDown(); - - for (int i = 0; i < numberOfThreads; i++) { - down[i].join(); - } - - Assert.assertEquals(1, latch.getCount()); - - for (int i = 0; i < numberOfThreads; i++) { - Assert.assertTrue(waits[i].waiting); - } - - latch.countDown(); - - for (int i = 0; i < numberOfThreads; i++) { - waits[i].join(); - } - - Assert.assertEquals(0, latch.getCount()); - - for (int i = 0; i < numberOfThreads; i++) { - Assert.assertFalse(waits[i].waiting); - } - } - - @Test - public void testReuseLatch() throws Exception { - final ReusableLatch latch = new ReusableLatch(5); - for (int i = 0; i < 5; i++) { - latch.countDown(); - } - - latch.countUp(); - - class ThreadWait extends Thread { - - private volatile boolean waiting = false; - - private volatile Exception e; - - private final CountDownLatch readyLatch = new CountDownLatch(1); - - @Override - public void run() { - waiting = true; - readyLatch.countDown(); - try { - if (!latch.await(1000)) { - System.err.println("Latch timed out!"); - } - } - catch (Exception e) { - e.printStackTrace(); - this.e = e; - } - waiting = false; - } - } - - ThreadWait t = new ThreadWait(); - t.start(); - - t.readyLatch.await(); - - Assert.assertEquals(true, t.waiting); - - latch.countDown(); - - t.join(); - - Assert.assertEquals(false, t.waiting); - - Assert.assertNull(t.e); - - latch.countUp(); - - t = new ThreadWait(); - t.start(); - - t.readyLatch.await(); - - Assert.assertEquals(true, t.waiting); - - latch.countDown(); - - t.join(); - - Assert.assertEquals(false, t.waiting); - - Assert.assertNull(t.e); - - Assert.assertTrue(latch.await(1000)); - - Assert.assertEquals(0, latch.getCount()); - - latch.countDown(); - - Assert.assertEquals(0, latch.getCount()); - - } - - @Test - public void testTimeout() throws Exception { - ReusableLatch latch = new ReusableLatch(); - - latch.countUp(); - - long start = System.currentTimeMillis(); - Assert.assertFalse(latch.await(1000)); - long end = System.currentTimeMillis(); - - Assert.assertTrue("Timeout didn't work correctly", end - start >= 1000 && end - start < 2000); - } - -} diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/SimpleServerAbstractTest.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/SimpleServerAbstractTest.java deleted file mode 100644 index 1bfa0b47e31..00000000000 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/util/SimpleServerAbstractTest.java +++ /dev/null @@ -1,67 +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.proton.plug.test.util; - -import org.proton.plug.test.AbstractJMSTest; -import org.proton.plug.test.Constants; -import org.proton.plug.test.invm.InVMTestConnector; -import org.proton.plug.test.minimalclient.Connector; -import org.proton.plug.test.minimalclient.SimpleAMQPConnector; -import org.proton.plug.test.minimalserver.DumbServer; -import org.proton.plug.test.minimalserver.MinimalServer; -import org.junit.After; -import org.junit.Before; - -public class SimpleServerAbstractTest { - - protected final boolean useSASL; - protected final boolean useInVM; - protected MinimalServer server = new MinimalServer(); - - public SimpleServerAbstractTest(boolean useSASL, boolean useInVM) { - this.useSASL = useSASL; - this.useInVM = useInVM; - } - - @Before - public void setUp() throws Exception { - DumbServer.clear(); - AbstractJMSTest.forceGC(); - if (!useInVM) { - server.start("127.0.0.1", Constants.PORT, useSASL); - } - - } - - @After - public void tearDown() throws Exception { - if (!useInVM) { - server.stop(); - } - DumbServer.clear(); - } - - protected Connector newConnector() { - if (useInVM) { - return new InVMTestConnector(); - } - else { - return new SimpleAMQPConnector(); - } - } - -} diff --git a/artemis-protocols/pom.xml b/artemis-protocols/pom.xml index 3eb9ade2930..29289acf72c 100644 --- a/artemis-protocols/pom.xml +++ b/artemis-protocols/pom.xml @@ -36,7 +36,6 @@ artemis-amqp-protocol artemis-stomp-protocol artemis-openwire-protocol - artemis-proton-plug artemis-hornetq-protocol artemis-hqclient-protocol artemis-mqtt-protocol diff --git a/tests/integration-tests/pom.xml b/tests/integration-tests/pom.xml index 4f56ca8747b..9ac3a72b13a 100644 --- a/tests/integration-tests/pom.xml +++ b/tests/integration-tests/pom.xml @@ -151,18 +151,6 @@ artemis-openwire-protocol ${project.version} - - org.apache.activemq - artemis-proton-plug - ${project.version} - - - org.apache.activemq - artemis-proton-plug - ${project.version} - test - test-jar - org.apache.activemq artemis-hornetq-protocol diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonMaxFrameSizeTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonMaxFrameSizeTest.java similarity index 98% rename from tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonMaxFrameSizeTest.java rename to tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonMaxFrameSizeTest.java index 908285eefe0..9f22362476a 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonMaxFrameSizeTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonMaxFrameSizeTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.tests.integration.proton; +package org.apache.activemq.artemis.tests.integration.amqp; import org.apache.activemq.transport.amqp.client.AmqpClient; import org.apache.activemq.transport.amqp.client.AmqpConnection; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonPubSubTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonPubSubTest.java similarity index 73% rename from tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonPubSubTest.java rename to tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonPubSubTest.java index 35700acc5f3..c8fc454d13a 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonPubSubTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonPubSubTest.java @@ -14,21 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.tests.integration.proton; +package org.apache.activemq.artemis.tests.integration.amqp; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.qpid.jms.JmsConnectionFactory; -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.message.ProtonJMessage; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.proton.plug.AMQPClientConnectionContext; -import org.proton.plug.AMQPClientReceiverContext; -import org.proton.plug.AMQPClientSessionContext; -import org.proton.plug.test.Constants; -import org.proton.plug.test.minimalclient.SimpleAMQPConnector; import javax.jms.Connection; import javax.jms.ExceptionListener; @@ -42,7 +35,6 @@ import javax.jms.TopicSession; import javax.jms.TopicSubscriber; import java.util.Map; -import java.util.concurrent.TimeUnit; public class ProtonPubSubTest extends ProtonTestBase { @@ -253,78 +245,6 @@ public void testDurablePubSubUnsubscribe() throws Exception { } - @Test - public void testPubSubWithSimpleClient() throws Exception { - SimpleAMQPConnector connector = new SimpleAMQPConnector(); - connector.start(); - AMQPClientConnectionContext clientConnection = connector.connect("127.0.0.1", Constants.PORT); - - clientConnection.setContainer("myContainerID"); - - clientConnection.clientOpen(null); - - AMQPClientSessionContext clientSession = clientConnection.createClientSession(); - AMQPClientReceiverContext receiver = clientSession.createReceiver(prefixedPubAddress); - int numMessages = 100; - Topic topic = createTopic(prefixedPubAddress); - Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer producer = sendSession.createProducer(topic); - connection.start(); - for (int i = 0; i < numMessages; i++) { - producer.send(sendSession.createTextMessage("message:" + i)); - } - - receiver.flow(100); - for (int i = 0; i < numMessages; i++) { - ProtonJMessage protonJMessage = receiver.receiveMessage(5000, TimeUnit.MILLISECONDS); - assertNotNull(protonJMessage); - assertEquals(((AmqpValue) protonJMessage.getBody()).getValue(), "message:" + i); - } - - } - - - @Test - public void testMultiplePubSubWithSimpleClient() throws Exception { - SimpleAMQPConnector connector = new SimpleAMQPConnector(); - connector.start(); - AMQPClientConnectionContext clientConnection = connector.connect("127.0.0.1", Constants.PORT); - - clientConnection.setContainer("myContainerID"); - - clientConnection.clientOpen(null); - - AMQPClientSessionContext clientSession = clientConnection.createClientSession(); - AMQPClientReceiverContext receiver = clientSession.createReceiver("sub1", prefixedPubAddress); - AMQPClientReceiverContext receiver2 = clientSession.createReceiver("sub2", prefixedPubAddress); - AMQPClientReceiverContext receiver3 = clientSession.createReceiver("sub3", prefixedPubAddress); - int numMessages = 100; - Topic topic = createTopic(prefixedPubAddress); - Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer producer = sendSession.createProducer(topic); - receiver.flow(100); - receiver2.flow(100); - receiver3.flow(100); - connection.start(); - for (int i = 0; i < numMessages; i++) { - producer.send(sendSession.createTextMessage("message:" + i)); - } - - for (int i = 0; i < numMessages; i++) { - ProtonJMessage protonJMessage = receiver.receiveMessage(5000, TimeUnit.MILLISECONDS); - assertNotNull("did not get message " + i, protonJMessage); - assertEquals(((AmqpValue) protonJMessage.getBody()).getValue(), "message:" + i); - protonJMessage = receiver2.receiveMessage(5000, TimeUnit.MILLISECONDS); - assertNotNull("did not get message " + i, protonJMessage); - assertEquals(((AmqpValue) protonJMessage.getBody()).getValue(), "message:" + i); - protonJMessage = receiver3.receiveMessage(5000, TimeUnit.MILLISECONDS); - assertNotNull("did not get message " + i, protonJMessage); - assertEquals(((AmqpValue) protonJMessage.getBody()).getValue(), "message:" + i); - } - - } - - private javax.jms.Topic createTopic(String address) throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java similarity index 89% rename from tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java rename to tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java index 984459ed20c..53e676f034b 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java @@ -14,12 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.tests.integration.proton; +package org.apache.activemq.artemis.tests.integration.amqp; -import static org.proton.plug.AmqpSupport.contains; -import static org.proton.plug.AmqpSupport.DELAYED_DELIVERY; -import static org.proton.plug.AmqpSupport.PRODUCT; -import static org.proton.plug.AmqpSupport.VERSION; +import static org.apache.activemq.artemis.protocol.amqp.proton.AmqpSupport.contains; +import static org.apache.activemq.artemis.protocol.amqp.proton.AmqpSupport.DELAYED_DELIVERY; +import static org.apache.activemq.artemis.protocol.amqp.proton.AmqpSupport.PRODUCT; +import static org.apache.activemq.artemis.protocol.amqp.proton.AmqpSupport.VERSION; import javax.jms.BytesMessage; import javax.jms.Connection; @@ -51,7 +51,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Enumeration; -import java.util.HashMap; import java.util.Map; import java.util.Random; import java.util.concurrent.CountDownLatch; @@ -59,13 +58,11 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.activemq.artemis.api.core.SimpleString; -import org.apache.activemq.artemis.api.core.TransportConfiguration; import org.apache.activemq.artemis.core.postoffice.Bindings; import org.apache.activemq.artemis.core.remoting.CloseListener; import org.apache.activemq.artemis.core.server.Queue; import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.artemis.utils.ByteUtil; import org.apache.activemq.artemis.utils.VersionLoader; import org.apache.activemq.transport.amqp.client.AmqpClient; @@ -78,23 +75,13 @@ import org.apache.qpid.jms.JmsConnectionFactory; import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.amqp.messaging.Properties; -import org.apache.qpid.proton.message.ProtonJMessage; -import org.apache.qpid.proton.message.impl.MessageImpl; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static org.junit.Assume.assumeTrue; -import org.proton.plug.AMQPClientConnectionContext; -import org.proton.plug.AMQPClientReceiverContext; -import org.proton.plug.AMQPClientSenderContext; -import org.proton.plug.AMQPClientSessionContext; -import org.proton.plug.context.server.ProtonServerReceiverContext; -import org.proton.plug.test.Constants; -import org.proton.plug.test.minimalclient.SimpleAMQPConnector; +import org.apache.activemq.artemis.protocol.amqp.proton.ProtonServerReceiverContext; @RunWith(Parameterized.class) public class ProtonTest extends ProtonTestBase { @@ -122,7 +109,7 @@ public class ProtonTest extends ProtonTestBase { public static Collection getParameters() { // these 3 are for comparison - return Arrays.asList(new Object[][]{{"AMQP", 0}, {"ActiveMQ (InVM)", 1}, {"ActiveMQ (Netty)", 2}, {"AMQP_ANONYMOUS", 3}}); + return Arrays.asList(new Object[][]{{"AMQP", 0}, {"AMQP_ANONYMOUS", 3}}); } ConnectionFactory factory; @@ -191,7 +178,6 @@ public void tearDown() throws Exception { @Test public void testDurableSubscriptionUnsubscribe() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol Connection connection = createConnection("myClientId"); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); @@ -218,7 +204,6 @@ public void testDurableSubscriptionUnsubscribe() throws Exception { @Test public void testTemporarySubscriptionDeleted() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol try { TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic("amqp_testtopic"); @@ -247,8 +232,6 @@ public void connectionClosed() { @Test public void testBrokerContainerId() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol - AmqpClient client = new AmqpClient(new URI(tcpAmqpConnectionUri), userName, password); AmqpConnection amqpConnection = client.connect(); try { @@ -261,8 +244,6 @@ public void testBrokerContainerId() throws Exception { @Test public void testBrokerConnectionProperties() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol - AmqpClient client = new AmqpClient(new URI(tcpAmqpConnectionUri), userName, password); AmqpConnection amqpConnection = client.connect(); try { @@ -280,8 +261,6 @@ public void testBrokerConnectionProperties() throws Exception { @Test(timeout = 60000) public void testConnectionCarriesExpectedCapabilities() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol - AmqpClient client = new AmqpClient(new URI(tcpAmqpConnectionUri), userName, password); assertNotNull(client); @@ -322,8 +301,6 @@ public void inspectOpenedResource(org.apache.qpid.proton.engine.Connection conne @Test(timeout = 60000) public void testSendWithDeliveryTimeHoldsMessage() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol - AmqpClient client = new AmqpClient(new URI(tcpAmqpConnectionUri), userName, password); assertNotNull(client); @@ -353,8 +330,6 @@ public void testSendWithDeliveryTimeHoldsMessage() throws Exception { @Test(timeout = 60000) public void testSendWithDeliveryTimeDeliversMessageAfterDelay() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol - AmqpClient client = new AmqpClient(new URI(tcpAmqpConnectionUri), userName, password); assertNotNull(client); @@ -388,8 +363,6 @@ public void testSendWithDeliveryTimeDeliversMessageAfterDelay() throws Exception @Test public void testCreditsAreAllocatedOnlyOnceOnLinkCreate() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol - // Only allow 1 credit to be submitted at a time. Field maxCreditAllocation = ProtonServerReceiverContext.class.getDeclaredField("maxCreditAllocation"); maxCreditAllocation.setAccessible(true); @@ -524,7 +497,6 @@ public void testRollbackConsumer() throws Throwable { @Test public void testResourceLimitExceptionOnAddressFull() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol setAddressFullBlockPolicy(); String destinationAddress = address + 1; fillAddress(destinationAddress); @@ -535,7 +507,6 @@ public void testResourceLimitExceptionOnAddressFull() throws Exception { @Test public void testAddressIsBlockedForOtherProdudersWhenFull() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol setAddressFullBlockPolicy(); String destinationAddress = address + 1; @@ -561,7 +532,6 @@ public void testAddressIsBlockedForOtherProdudersWhenFull() throws Exception { @Test public void testCreditsAreNotAllocatedWhenAddressIsFull() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol setAddressFullBlockPolicy(); // Only allow 1 credit to be submitted at a time. @@ -595,7 +565,6 @@ public void testCreditsAreNotAllocatedWhenAddressIsFull() throws Exception { @Test public void testCreditsAreRefreshedWhenAddressIsUnblocked() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol setAddressFullBlockPolicy(); String destinationAddress = address + 1; @@ -633,7 +602,6 @@ public void testCreditsAreRefreshedWhenAddressIsUnblocked() throws Exception { @Test public void testNewLinkAttachAreNotAllocatedCreditsWhenAddressIsBlocked() throws Exception { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol setAddressFullBlockPolicy(); fillAddress(address + 1); @@ -653,7 +621,6 @@ public void testNewLinkAttachAreNotAllocatedCreditsWhenAddressIsBlocked() throws @Test public void testTxIsRolledBackOnRejectedPreSettledMessage() throws Throwable { - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol setAddressFullBlockPolicy(); // Create the link attach before filling the address to ensure the link is allocated credit. @@ -796,7 +763,6 @@ public void testSendingAndReceivingToQueueWithDifferentAddressAndQueueName() thr @Test public void testManagementQueryOverAMQP() throws Throwable { - assumeTrue(protocol == 0 || protocol == 3); // Only run this test for AMQP protocol AmqpClient client = new AmqpClient(new URI(tcpAmqpConnectionUri), userName, password); AmqpConnection amqpConnection = client.connect(); @@ -950,98 +916,6 @@ public void run() throws Throwable { Assert.assertTrue("Test had to interrupt on all occasions.. this is beyond the expected for the test", success); } - @Test - public void testReceiveImmediate() throws Exception { - testReceiveImmediate(1000, 1000); - } - - @Test - public void testReceiveImmediateMoreCredits() throws Exception { - testReceiveImmediate(1000, 100); - } - - @Test - public void testReceiveImmediateMoreMessages() throws Exception { - testReceiveImmediate(100, 1000); - } - - public void testReceiveImmediate(int noCredits, int noMessages) throws Exception { - - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol - - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - javax.jms.Queue queue = createQueue(address); - MessageProducer p = session.createProducer(queue); - - TextMessage message = session.createTextMessage(); - message.setText("Message temporary"); - for (int i = 0; i < noMessages; i++) { - message.setText("msg:" + i); - p.send(message); - } - - SimpleAMQPConnector connector = new SimpleAMQPConnector(); - connector.start(); - AMQPClientConnectionContext clientConnection = connector.connect("127.0.0.1", Constants.PORT); - - clientConnection.clientOpen(null); - - AMQPClientSessionContext csession = clientConnection.createClientSession(); - AMQPClientReceiverContext receiver = csession.createReceiver(address); - receiver.drain(noCredits); - - int expectedNumberMessages = noCredits > noMessages ? noMessages : noCredits; - for (int i = 0; i < expectedNumberMessages; i++) { - ProtonJMessage protonJMessage = receiver.receiveMessage(500, TimeUnit.SECONDS); - Assert.assertNotNull(protonJMessage); - } - ProtonJMessage protonJMessage = receiver.receiveMessage(500, TimeUnit.MILLISECONDS); - Assert.assertNull(protonJMessage); - - assertFalse(receiver.isDraining()); - if (noCredits >= noMessages) { - assertEquals(noCredits - noMessages, receiver.drained()); - } - else { - assertEquals(0, receiver.drained()); - } - } - - @Test - public void testDynamicSenderLink() throws Exception { - - if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol - - SimpleAMQPConnector connector = new SimpleAMQPConnector(); - connector.start(); - AMQPClientConnectionContext clientConnection = connector.connect("127.0.0.1", Constants.PORT); - - clientConnection.clientOpen(null); - - AMQPClientSessionContext csession = clientConnection.createClientSession(); - AMQPClientSenderContext sender = csession.createDynamicSender(false); - - String address = sender.getAddress(); - - AMQPClientReceiverContext receiver = csession.createReceiver(address); - receiver.flow(1); - - // Send one on the dynamic address - MessageImpl message = (MessageImpl) org.apache.qpid.proton.message.Message.Factory.create(); - - Properties props = new Properties(); - Map map = new HashMap<>(); - - map.put("some-property", 1); - AmqpValue value = new AmqpValue(map); - message.setBody(value); - message.setProperties(props); - sender.send(message); - - ProtonJMessage protonJMessage = receiver.receiveMessage(500, TimeUnit.MILLISECONDS); - Assert.assertNotNull(protonJMessage); - } - @Test public void testConnection() throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); @@ -1599,17 +1473,8 @@ else if (protocol == 0) { connection = factory.createConnection(); } else { - TransportConfiguration transport; - - if (protocol == 1) { - transport = new TransportConfiguration(INVM_CONNECTOR_FACTORY); - factory = new ActiveMQConnectionFactory("vm:/0"); - } - else { - factory = new ActiveMQConnectionFactory(); - } - - connection = factory.createConnection(userName, password); + Assert.fail("protocol = " + protocol + " not supported"); + return null; // just to compile, the previous statement will throw an exception } if (isStart) { connection.setExceptionListener(new ExceptionListener() { @@ -1651,25 +1516,8 @@ public void onException(JMSException exception) { connection.start(); } else { - TransportConfiguration transport; - - if (protocol == 1) { - transport = new TransportConfiguration(INVM_CONNECTOR_FACTORY); - factory = new ActiveMQConnectionFactory("vm:/0"); - } - else { - factory = new ActiveMQConnectionFactory(); - } - - connection = factory.createConnection(userName, password); - connection.setClientID(clientId); - connection.setExceptionListener(new ExceptionListener() { - @Override - public void onException(JMSException exception) { - exception.printStackTrace(); - } - }); - connection.start(); + Assert.fail("protocol = " + protocol + " not supported"); + return null; // just to compile, the previous statement will throw an exception } return connection; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTestBase.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTestBase.java similarity index 97% rename from tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTestBase.java rename to tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTestBase.java index cec59da7bbc..d6369ebe519 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTestBase.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTestBase.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.tests.integration.proton; +package org.apache.activemq.artemis.tests.integration.amqp; import org.apache.activemq.artemis.api.core.TransportConfiguration; import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTestForHeader.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTestForHeader.java similarity index 99% rename from tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTestForHeader.java rename to tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTestForHeader.java index d23bd5b6365..a50af0d9705 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTestForHeader.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTestForHeader.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.tests.integration.proton; +package org.apache.activemq.artemis.tests.integration.amqp; import java.io.IOException; import java.io.InputStream; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/jms/SendingAndReceivingTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/SendingAndReceivingTest.java similarity index 97% rename from tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/jms/SendingAndReceivingTest.java rename to tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/SendingAndReceivingTest.java index d2982671beb..0c9783efeac 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/jms/SendingAndReceivingTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/SendingAndReceivingTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.tests.integration.amqp.jms; +package org.apache.activemq.artemis.tests.integration.amqp; import java.util.Random;