From a3047f65e740f287b2ced28ed6f916f18d15e7e3 Mon Sep 17 00:00:00 2001 From: "Stephen D. Huston" Date: Tue, 10 Mar 2009 23:10:57 +0000 Subject: Merge in trunk to r752275 git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/qpid-1673@752300 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/configure.ac | 59 +- qpid/cpp/examples/direct/Makefile.am | 1 + qpid/cpp/examples/failover/Makefile.am | 1 + qpid/cpp/examples/fanout/Makefile.am | 1 + qpid/cpp/examples/makedist.mk | 5 +- qpid/cpp/examples/pub-sub/Makefile.am | 1 + qpid/cpp/examples/qmf-console/Makefile.am | 2 +- qpid/cpp/examples/request-response/Makefile.am | 1 + qpid/cpp/examples/tradedemo/Makefile.am | 1 + qpid/cpp/examples/xml-exchange/Makefile.am | 1 + qpid/cpp/src/Makefile.am | 9 +- qpid/cpp/src/acl.mk | 4 + qpid/cpp/src/cluster.mk | 11 +- qpid/cpp/src/common.vcproj | 6 + qpid/cpp/src/qpid/SessionId.cpp | 2 +- qpid/cpp/src/qpid/SessionState.cpp | 14 +- qpid/cpp/src/qpid/SessionState.h | 15 + qpid/cpp/src/qpid/acl/AclPlugin.cpp | 13 +- qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp | 8 +- qpid/cpp/src/qpid/amqp_0_10/SessionHandler.cpp | 1 - qpid/cpp/src/qpid/assert.cpp | 2 +- qpid/cpp/src/qpid/broker/Bridge.cpp | 44 +- qpid/cpp/src/qpid/broker/Bridge.h | 5 +- qpid/cpp/src/qpid/broker/Broker.cpp | 1 + qpid/cpp/src/qpid/broker/Connection.cpp | 14 +- qpid/cpp/src/qpid/broker/Connection.h | 5 +- qpid/cpp/src/qpid/broker/ConnectionState.h | 22 +- qpid/cpp/src/qpid/broker/Daemon.h | 4 +- qpid/cpp/src/qpid/broker/Exchange.cpp | 8 +- qpid/cpp/src/qpid/broker/Exchange.h | 7 +- qpid/cpp/src/qpid/broker/HeadersExchange.cpp | 45 +- qpid/cpp/src/qpid/broker/Link.cpp | 43 +- qpid/cpp/src/qpid/broker/Link.h | 1 + qpid/cpp/src/qpid/broker/LinkRegistry.cpp | 8 +- qpid/cpp/src/qpid/broker/LinkRegistry.h | 1 + qpid/cpp/src/qpid/broker/Message.cpp | 5 + qpid/cpp/src/qpid/broker/Message.h | 1 + qpid/cpp/src/qpid/broker/Queue.cpp | 40 +- qpid/cpp/src/qpid/broker/Queue.h | 10 +- qpid/cpp/src/qpid/broker/QueueEvents.cpp | 19 +- qpid/cpp/src/qpid/broker/QueueEvents.h | 3 + qpid/cpp/src/qpid/broker/QueuePolicy.cpp | 28 +- qpid/cpp/src/qpid/broker/QueueRegistry.cpp | 10 +- qpid/cpp/src/qpid/broker/QueueRegistry.h | 5 + qpid/cpp/src/qpid/broker/RecoveryManagerImpl.cpp | 3 +- qpid/cpp/src/qpid/broker/SaslAuthenticator.cpp | 28 +- qpid/cpp/src/qpid/broker/SemanticState.cpp | 22 +- qpid/cpp/src/qpid/broker/SessionAdapter.cpp | 4 - qpid/cpp/src/qpid/broker/SessionHandler.cpp | 25 +- qpid/cpp/src/qpid/broker/SessionHandler.h | 23 +- qpid/cpp/src/qpid/broker/SessionState.cpp | 31 +- qpid/cpp/src/qpid/broker/SessionState.h | 11 +- qpid/cpp/src/qpid/broker/TxAccept.cpp | 4 +- qpid/cpp/src/qpid/client/ConnectionImpl.cpp | 3 + qpid/cpp/src/qpid/client/Connector.cpp | 51 +- qpid/cpp/src/qpid/client/Dispatcher.cpp | 3 +- qpid/cpp/src/qpid/client/FailoverManager.cpp | 11 +- qpid/cpp/src/qpid/client/SessionImpl.cpp | 4 +- qpid/cpp/src/qpid/client/SslConnector.cpp | 2 +- qpid/cpp/src/qpid/cluster/Cluster.cpp | 235 +- qpid/cpp/src/qpid/cluster/Cluster.h | 123 +- qpid/cpp/src/qpid/cluster/ClusterPlugin.cpp | 1 - qpid/cpp/src/qpid/cluster/ClusterSettings.h | 2 +- qpid/cpp/src/qpid/cluster/Connection.cpp | 67 +- qpid/cpp/src/qpid/cluster/Connection.h | 26 +- qpid/cpp/src/qpid/cluster/ConnectionCodec.cpp | 15 +- qpid/cpp/src/qpid/cluster/ConnectionCodec.h | 4 +- qpid/cpp/src/qpid/cluster/ConnectionDecoder.cpp | 57 - qpid/cpp/src/qpid/cluster/ConnectionDecoder.h | 61 - qpid/cpp/src/qpid/cluster/ConnectionMap.cpp | 96 - qpid/cpp/src/qpid/cluster/ConnectionMap.h | 88 - qpid/cpp/src/qpid/cluster/Cpg.cpp | 15 +- qpid/cpp/src/qpid/cluster/Cpg.h | 2 - qpid/cpp/src/qpid/cluster/Decoder.cpp | 46 +- qpid/cpp/src/qpid/cluster/Decoder.h | 32 +- qpid/cpp/src/qpid/cluster/Event.cpp | 31 +- qpid/cpp/src/qpid/cluster/Event.h | 19 +- qpid/cpp/src/qpid/cluster/EventFrame.cpp | 8 +- qpid/cpp/src/qpid/cluster/EventFrame.h | 15 +- qpid/cpp/src/qpid/cluster/ExpiryPolicy.cpp | 50 +- qpid/cpp/src/qpid/cluster/ExpiryPolicy.h | 24 +- qpid/cpp/src/qpid/cluster/LockedConnectionMap.h | 62 + qpid/cpp/src/qpid/cluster/McastFrameHandler.h | 46 + qpid/cpp/src/qpid/cluster/Multicaster.cpp | 6 + qpid/cpp/src/qpid/cluster/Multicaster.h | 1 + qpid/cpp/src/qpid/cluster/OutputInterceptor.cpp | 11 +- qpid/cpp/src/qpid/cluster/PollableQueue.h | 2 + qpid/cpp/src/qpid/cluster/UpdateClient.cpp | 93 +- qpid/cpp/src/qpid/cluster/UpdateClient.h | 11 +- qpid/cpp/src/qpid/cluster/UpdateExchange.h | 45 + qpid/cpp/src/qpid/cluster/types.h | 11 +- qpid/cpp/src/qpid/console/ClassKey.cpp | 1 + qpid/cpp/src/qpid/framing/AMQFrame.cpp | 2 +- qpid/cpp/src/qpid/framing/AMQFrame.h | 4 - qpid/cpp/src/qpid/framing/FrameDecoder.cpp | 12 +- qpid/cpp/src/qpid/framing/FrameDecoder.h | 9 +- qpid/cpp/src/qpid/framing/Uuid.h | 3 +- qpid/cpp/src/qpid/log/Selector.cpp | 1 + qpid/cpp/src/qpid/log/posix/SinkOptions.cpp | 6 +- qpid/cpp/src/qpid/management/ManagementBroker.cpp | 11 +- qpid/cpp/src/qpid/management/ManagementBroker.h | 1 + .../qpid/replication/ReplicatingEventListener.cpp | 5 +- .../qpid/replication/ReplicatingEventListener.h | 2 +- .../src/qpid/replication/ReplicationExchange.cpp | 44 +- .../cpp/src/qpid/replication/ReplicationExchange.h | 2 + qpid/cpp/src/qpid/sys/Codec.h | 4 +- qpid/cpp/src/qpid/sys/ConnectionOutputHandlerPtr.h | 2 +- qpid/cpp/src/qpid/sys/CopyOnWriteArray.h | 2 +- qpid/cpp/src/qpid/sys/DispatchHandle.cpp | 129 +- qpid/cpp/src/qpid/sys/DispatchHandle.h | 1 + qpid/cpp/src/qpid/sys/PollableQueue.h | 2 +- qpid/cpp/src/qpid/sys/Poller.h | 5 +- qpid/cpp/src/qpid/sys/Socket.h | 4 +- qpid/cpp/src/qpid/sys/Thread.h | 2 + qpid/cpp/src/qpid/sys/epoll/EpollPoller.cpp | 111 +- qpid/cpp/src/qpid/sys/posix/AsynchIO.cpp | 4 +- qpid/cpp/src/qpid/sys/posix/Socket.cpp | 43 +- qpid/cpp/src/qpid/sys/solaris/ECFPoller.cpp | 234 +- qpid/cpp/src/qpid/sys/solaris/SystemInfo.cpp | 123 + qpid/cpp/src/qpid/sys/ssl/SslIo.cpp | 2 +- qpid/cpp/src/qpid/sys/ssl/SslSocket.cpp | 4 +- qpid/cpp/src/qpid/sys/ssl/SslSocket.h | 2 +- qpid/cpp/src/qpid/sys/windows/IntegerTypes.h | 1 - qpid/cpp/src/qpid/sys/windows/Socket.cpp | 4 +- qpid/cpp/src/qpid/xml/XmlExchange.cpp | 128 +- qpid/cpp/src/qpid/xml/XmlExchange.h | 5 +- qpid/cpp/src/replication.mk | 6 + qpid/cpp/src/tests/ClientSessionTest.cpp | 22 +- qpid/cpp/src/tests/ClusterFixture.cpp | 2 +- qpid/cpp/src/tests/DispatcherTest.cpp | 79 +- qpid/cpp/src/tests/ForkedBroker.cpp | 7 +- qpid/cpp/src/tests/FrameDecoder.cpp | 73 + qpid/cpp/src/tests/Makefile.am | 15 +- qpid/cpp/src/tests/MessageUtils.h | 2 +- qpid/cpp/src/tests/PollerTest.cpp | 2 +- qpid/cpp/src/tests/QueueEvents.cpp | 6 +- qpid/cpp/src/tests/QueuePolicyTest.cpp | 9 + qpid/cpp/src/tests/SocketProxy.h | 2 +- qpid/cpp/src/tests/cluster.mk | 5 +- qpid/cpp/src/tests/cluster_test.cpp | 191 +- qpid/cpp/src/tests/clustered_replication_test | 127 + qpid/cpp/src/tests/failover_soak.cpp | 331 ++- qpid/cpp/src/tests/federated_cluster_test | 42 +- .../tests/federated_cluster_test_with_node_failure | 23 + qpid/cpp/src/tests/receiver.cpp | 18 +- qpid/cpp/src/tests/replaying_sender.cpp | 4 +- qpid/cpp/src/tests/replication_test | 6 + qpid/cpp/src/tests/resuming_receiver.cpp | 19 +- qpid/cpp/src/tests/run_failover_soak | 12 +- qpid/cpp/src/tests/sender.cpp | 28 +- qpid/cpp/src/tests/ssl_test | 3 +- qpid/cpp/src/tests/start_cluster | 3 +- qpid/cpp/src/tests/txshift.cpp | 4 +- qpid/cpp/xml/cluster.xml | 7 +- qpid/java/08ExcludeList | 1 + qpid/java/08ExcludeList-nonvm | 1 + qpid/java/ExcludeList | 12 +- qpid/java/broker/etc/config.xml | 1 - qpid/java/broker/etc/debug.log4j.xml | 26 +- qpid/java/broker/etc/log4j.xml | 24 +- qpid/java/broker/etc/persistent_config.xml | 1 - qpid/java/broker/etc/transient_config.xml | 1 - .../apache/qpid/server/AMQBrokerManagerMBean.java | 2 +- .../java/org/apache/qpid/server/AMQChannel.java | 5 +- .../src/main/java/org/apache/qpid/server/Main.java | 57 +- .../java/org/apache/qpid/server/ack/TxAck.java | 2 +- .../server/ack/UnacknowledgedMessageMapImpl.java | 6 +- .../server/configuration/QueueConfiguration.java | 20 +- .../server/configuration/ServerConfiguration.java | 75 +- .../configuration/VirtualHostConfiguration.java | 47 +- .../management/ConfigurationManagement.java | 43 + .../management/ConfigurationManagementMBean.java | 49 + .../qpid/server/exchange/AbstractExchange.java | 6 +- .../qpid/server/exchange/ManagedExchange.java | 1 + .../qpid/server/flow/BytesOnlyCreditManager.java | 6 +- .../apache/qpid/server/flow/FlowCreditManager.java | 3 +- .../qpid/server/flow/LimitlessCreditManager.java | 4 +- .../server/flow/MessageAndBytesCreditManager.java | 6 +- .../qpid/server/flow/MessageOnlyCreditManager.java | 4 +- .../qpid/server/flow/Pre0_10CreditManager.java | 12 +- .../qpid/server/handler/BasicGetMethodHandler.java | 6 +- .../server/handler/BasicRejectMethodHandler.java | 2 +- .../logging/management/LoggingManagement.java | 129 + .../logging/management/LoggingManagementMBean.java | 667 ++++++ .../qpid/server/management/AMQManagedObject.java | 4 +- .../server/management/DefaultManagedObject.java | 11 +- .../management/JMXManagedObjectRegistry.java | 280 +-- .../management/MBeanInvocationHandlerImpl.java | 44 +- .../qpid/server/management/ManagedBroker.java | 4 +- .../apache/qpid/server/plugins/PluginManager.java | 2 + .../server/protocol/AMQProtocolSessionMBean.java | 4 +- .../qpid/server/protocol/ManagedConnection.java | 1 + .../org/apache/qpid/server/queue/AMQMessage.java | 38 +- .../apache/qpid/server/queue/AMQMessageHandle.java | 75 - .../apache/qpid/server/queue/AMQPriorityQueue.java | 4 +- .../org/apache/qpid/server/queue/AMQQueue.java | 10 + .../apache/qpid/server/queue/AMQQueueFactory.java | 66 +- .../apache/qpid/server/queue/AMQQueueMBean.java | 50 +- .../qpid/server/queue/FileQueueBackingStore.java | 358 +++ .../server/queue/FileQueueBackingStoreFactory.java | 166 ++ .../server/queue/FlowableBaseQueueEntryList.java | 485 ++++ .../org/apache/qpid/server/queue/ManagedQueue.java | 62 +- .../qpid/server/queue/NotificationCheck.java | 16 +- .../qpid/server/queue/PersistentAMQMessage.java | 11 +- .../qpid/server/queue/PriorityQueueEntryList.java | 466 ++++ .../qpid/server/queue/PriorityQueueList.java | 160 -- .../qpid/server/queue/QueueBackingStore.java | 36 + .../server/queue/QueueBackingStoreFactory.java | 32 + .../org/apache/qpid/server/queue/QueueEntry.java | 51 +- .../apache/qpid/server/queue/QueueEntryImpl.java | 248 +- .../apache/qpid/server/queue/QueueEntryList.java | 70 +- .../apache/qpid/server/queue/SimpleAMQQueue.java | 118 +- .../qpid/server/queue/SimpleQueueEntryList.java | 17 +- .../qpid/server/queue/TransientAMQMessage.java | 119 +- .../server/queue/UnableToFlowMessageException.java | 29 + .../queue/UnableToRecoverMessageException.java | 29 + .../qpid/server/registry/ApplicationRegistry.java | 3 +- .../qpid/server/registry/IApplicationRegistry.java | 3 +- .../qpid/server/security/access/ACLManager.java | 9 +- .../qpid/server/security/access/ACLPlugin.java | 3 +- .../server/security/access/ACLPluginFactory.java | 3 +- .../access/management/AMQUserManagementMBean.java | 170 +- .../security/access/management/UserManagement.java | 3 + .../access/plugins/network/FirewallFactory.java | 3 +- .../access/plugins/network/FirewallPlugin.java | 39 +- .../Base64MD5PasswordFilePrincipalDatabase.java | 49 +- .../server/security/auth/database/HashedUser.java | 43 +- .../PlainPasswordFilePrincipalDatabase.java | 334 ++- .../server/security/auth/database/PlainUser.java | 106 + .../auth/rmi/RMIPasswordAuthenticator.java | 81 +- .../qpid/server/subscription/SubscriptionImpl.java | 6 +- .../qpid/server/txn/NonTransactionalContext.java | 8 +- .../server/virtualhost/ManagedVirtualHost.java | 1 + .../qpid/server/virtualhost/VirtualHost.java | 39 +- .../qpid/tools/messagestore/commands/Move.java | 2 +- .../qpid/tools/messagestore/commands/Show.java | 2 +- .../qpid/server/ExtractResendAndRequeueTest.java | 2 +- .../configuration/ServerConfigurationTest.java | 330 ++- .../VirtualHostConfigurationTest.java | 28 + .../exchange/AbstractHeadersExchangeTestBase.java | 41 +- .../qpid/server/exchange/DestWildExchangeTest.java | 26 +- .../management/LoggingManagementMBeanTest.java | 413 ++++ .../qpid/server/queue/AMQPriorityQueueTest.java | 121 +- .../qpid/server/queue/AMQQueueAlertTest.java | 2 +- .../server/queue/AMQQueueFactoryPriorityTest.java | 70 + .../qpid/server/queue/AMQQueueFactoryTest.java | 40 +- .../qpid/server/queue/AMQQueueMBeanTest.java | 6 +- .../qpid/server/queue/AMQQueueThreadPoolTest.java | 98 + .../server/queue/FileQueueBackingStoreTest.java | 223 ++ .../apache/qpid/server/queue/MockAMQMessage.java | 2 + .../org/apache/qpid/server/queue/MockAMQQueue.java | 32 +- .../qpid/server/queue/QueueEntryImplTest.java | 199 +- .../qpid/server/queue/SimpleAMQQueueTest.java | 184 +- .../server/queue/SimpleAMQQueueThreadPoolTest.java | 60 - .../qpid/server/queue/TransientMessageTest.java | 177 +- .../server/security/access/ACLManagerTest.java | 5 +- .../management/AMQUserManagementMBeanTest.java | 229 +- ...Base64MD5PasswordFilePrincipalDatabaseTest.java | 156 +- .../security/auth/database/HashedUserTest.java | 6 +- .../PlainPasswordFilePrincipalDatabaseTest.java | 396 +++ .../security/auth/database/PlainUserTest.java | 78 + .../qpid/server/subscription/MockSubscription.java | 29 +- qpid/java/build.deps | 16 +- .../qpid/example/amqpexample/direct/Listener.java | 2 + .../qpid/example/amqpexample/fanout/Listener.java | 2 + .../qpid/example/amqpexample/headers/Listener.java | 2 + .../qpid/example/amqpexample/lvq/Listener.java | 2 + .../example/amqpexample/pubsub/TopicListener.java | 2 + .../java/org/apache/qpid/client/AMQConnection.java | 58 +- .../qpid/client/AMQConnectionDelegate_0_10.java | 6 - .../org/apache/qpid/client/AMQQueueBrowser.java | 68 +- .../java/org/apache/qpid/client/AMQSession.java | 52 +- .../org/apache/qpid/client/AMQSession_0_10.java | 117 +- .../org/apache/qpid/client/AMQSession_0_8.java | 8 +- .../apache/qpid/client/BasicMessageConsumer.java | 26 +- .../qpid/client/BasicMessageConsumer_0_10.java | 74 +- .../qpid/client/BasicMessageConsumer_0_8.java | 20 +- .../apache/qpid/client/BasicMessageProducer.java | 24 + .../qpid/client/BasicMessageProducer_0_10.java | 8 +- .../client/configuration/ClientProperties.java | 13 + .../qpid/client/message/JMSObjectMessage.java | 6 +- .../java/org/apache/qpid/client/url/URLParser.java | 23 +- .../java/org/apache/qpid/jms/ConnectionURL.java | 6 +- .../qpid/jms/failover/FailoverExchangeMethod.java | 158 +- .../jms/failover/FailoverRoundRobinServers.java | 10 +- .../client/connectionurl/ConnectionURLTest.java | 13 + .../qpid/test/unit/message/TestAMQSession.java | 7 +- .../src/main/java/org/apache/qpid/ToyClient.java | 2 + .../java/org/apache/qpid/transport/Connection.java | 2 +- .../main/java/org/apache/qpid/transport/Echo.java | 2 + .../java/org/apache/qpid/transport/Session.java | 64 +- .../org/apache/qpid/transport/SessionListener.java | 2 + .../main/java/org/apache/qpid/transport/Sink.java | 2 + .../main/java/org/apache/qpid/util/FileUtils.java | 6 +- .../org/apache/qpid/transport/ConnectionTest.java | 54 +- .../java/org/apache/qpid/util/FileUtilsTest.java | 24 + qpid/java/cpp.cluster.testprofile | 3 + ...g.apache.commons.codec_1.3.0.v20080530-1600.jar | Bin 0 -> 53757 bytes .../META-INF/ECLIPSE.RSA | Bin 0 -> 3487 bytes .../META-INF/ECLIPSE.SF | 17 + .../META-INF/MANIFEST.MF | 25 + .../META-INF/eclipse.inf | 3 + .../about.html | 28 + .../eclipse_1115.so | Bin 0 -> 169725 bytes .../launcher.gtk.linux.x86_64.properties | 12 + .../META-INF/ECLIPSE.RSA | Bin 0 -> 3487 bytes .../META-INF/ECLIPSE.SF | 17 + .../META-INF/MANIFEST.MF | 25 + .../META-INF/eclipse.inf | 3 + .../about.html | 28 + .../eclipse_1115.so | Bin 0 -> 76500 bytes .../launcher.gtk.solaris.sparc.properties | 12 + ...g.eclipse.swt.gtk.linux.x86_64_3.4.1.v3449c.jar | Bin 0 -> 2123120 bytes ....eclipse.swt.gtk.solaris.sparc_3.4.1.v3449c.jar | Bin 0 -> 1877410 bytes .../java/management/client/bin/qman-wsdm-start.cmd | 1 - qpid/java/management/client/bin/qman-wsdm-start.sh | 2 +- qpid/java/management/client/build.xml | 6 +- .../client/console/brokers_management.jsp | 2 +- .../management/client/console/fragments/menu.jsp | 4 +- .../java/management/client/console/wsdl-viewer.xsl | 2523 -------------------- .../client/console/wsdm_rmd_perspective.jsp | 10 +- .../client/console/wsdm_wsdl_perspective.jsp | 8 +- .../src/example/PauseAndResumeSubscription.out.ok | 133 ++ .../example/ConsumerAndProducerExample.java | 51 +- .../example/PausableSubscriptionExample.java | 88 + qpid/java/management/client/src/main/java/muse.xml | 2 +- .../java/org/apache/qpid/management/Messages.java | 2 +- .../java/org/apache/qpid/management/Names.java | 4 +- .../configuration/AccessModeMapping.java | 83 - .../management/configuration/Configuration.java | 94 +- .../management/configuration/Configurator.java | 45 - .../qpid/management/configuration/TypeMapping.java | 90 - .../qpid/management/domain/model/JmxService.java | 28 +- .../qpid/management/domain/services/QMan.java | 86 +- .../management/domain/services/QpidService.java | 2 + .../qpid/management/web/action/BrokerModel.java | 42 +- .../web/action/BrokersManagementAction.java | 30 +- .../action/WsdmPropertiesPerspectiveAction.java | 3 - .../web/action/WsdmRmdPerspectiveAction.java | 78 +- .../web/action/WsdmWsdlPerspectiveAction.java | 16 +- .../qpid/management/wsdm/QEmuInitializer.java | 8 +- .../management/wsdm/capabilities/Constants.java | 44 + .../wsdm/capabilities/ConsumerCapability.java | 2 + .../wsdm/capabilities/DummyCapabilityBuilder.java | 37 +- .../wsdm/capabilities/MBeanCapability.java | 8 +- .../wsdm/capabilities/MBeanCapabilityBuilder.java | 8 + .../QManMetadataExchangeCapability.java | 36 + .../qpid/management/wsdm/capabilities/Result.java | 64 +- .../management/wsdm/capabilities/RmdBuilder.java | 3 +- .../wsdm/capabilities/WSDMArtifactsDirector.java | 5 +- .../wsdm/capabilities/WsArtifactsFactory.java | 9 +- .../management/wsdm/capabilities/WsdlBuilder.java | 414 ++-- .../wsdm/common/EntityInstanceNotFoundFault.java | 5 +- .../qpid/management/wsdm/common/ThreadSession.java | 8 +- .../wsdm/muse/engine/WSDMAdapterEnvironment.java | 15 + .../serializer/InvocationResultSerializer.java | 32 +- .../wsdm/muse/serializer/MapSerializer.java | 30 +- .../client/src/main/java/wsdl/QManWsResource.wsdl | 28 +- .../main/java/wsdl/WS-BaseNotification-1_3.wsdl | 13 +- .../main/java/wsdl/WS-ServiceGroupEntry-1_2.wsdl | 2 +- .../org/apache/qpid/management/TestConstants.java | 2 +- .../configuration/ConfigurationTest.java | 39 +- .../management/wsdm/BaseWsDmAdapterTestCase.java | 143 ++ .../GetMultipleResourcePropertiesTestCase.java | 125 + .../wsdm/GetResourcePropertiesTestCase.java | 105 + .../wsdm/GetResourcePropertyDocumentTestCase.java | 134 ++ .../wsdm/MetadataExchangeInterfaceTestCase.java | 169 ++ .../wsdm/OperationInvocationInterfaceTestCase.java | 580 +++++ .../wsdm/SetResourcePropertiesTestCase.java | 219 ++ .../qpid/management/wsdm/WsDmAdapterTest.java | 975 +------- .../management/eclipse-plugin/META-INF/MANIFEST.MF | 4 +- .../build-release-linux-gtk-x86_64.properties | 36 + .../build-release-solaris-gtk-sparc.properties | 39 + .../management/eclipse-plugin/build-release.xml | 14 +- qpid/java/management/eclipse-plugin/build.xml | 13 + .../org/apache/qpid/management/ui/Constants.java | 5 +- .../org/apache/qpid/management/ui/ManagedBean.java | 63 +- .../apache/qpid/management/ui/ManagedServer.java | 19 - .../qpid/management/ui/actions/AddServer.java | 41 +- .../management/ui/actions/ReconnectServer.java | 18 +- .../qpid/management/ui/jmx/ClientListener.java | 2 +- .../ui/jmx/ClientNotificationListener.java | 1 - .../qpid/management/ui/jmx/JMXServerRegistry.java | 1 - .../qpid/management/ui/jmx/MBeanUtility.java | 12 - .../apache/qpid/management/ui/views/MBeanView.java | 14 +- .../qpid/management/ui/views/NavigationView.java | 205 +- .../management/ui/views/OperationTabControl.java | 43 +- .../management/ui/views/QueueTypeTabControl.java | 42 +- .../qpid/management/ui/views/ViewUtility.java | 342 ++- .../linux-gtk-x86/Configuration/config.ini | 3 +- .../linux-gtk-x86_64/Configuration/config.ini | 49 + .../resources/linux-gtk-x86_64/libcairo-swt.so | Bin 0 -> 335360 bytes .../src/main/resources/linux-gtk-x86_64/qpidmc | Bin 0 -> 67927 bytes .../src/main/resources/linux-gtk-x86_64/qpidmc.ini | 37 + .../main/resources/macosx/Configuration/config.ini | 3 +- .../qpid-management-common-plugin/MANIFEST.MF | 2 +- .../solaris-gtk-sparc/Configuration/config.ini | 49 + .../main/resources/solaris-gtk-sparc/Qpidmc.l.pm | 311 +++ .../main/resources/solaris-gtk-sparc/Qpidmc.m.pm | 295 +++ .../main/resources/solaris-gtk-sparc/Qpidmc.s.pm | 287 +++ .../main/resources/solaris-gtk-sparc/Qpidmc.t.pm | 279 +++ .../src/main/resources/solaris-gtk-sparc/qpidmc | Bin 0 -> 31668 bytes .../main/resources/solaris-gtk-sparc/qpidmc.ini | 40 + .../win32-win32-x86/Configuration/config.ini | 3 +- .../apache/qpid/client/MessageListenerTest.java | 8 + .../apache/qpid/server/queue/QueueCreateTest.java | 179 ++ .../test/client/QueueBrowsingFlowToDiskTest.java | 69 + .../qpid/test/client/failover/FailoverTest.java | 237 +- .../test/client/message/ObjectMessageTest.java | 136 ++ .../apache/qpid/test/utils/FailoverBaseCase.java | 35 +- .../org/apache/qpid/test/utils/QpidTestCase.java | 6 +- qpid/java/test-provider.properties | 2 +- .../main/java/org/apache/qpid/tools/QpidBench.java | 2 + qpid/python/commands/qpid-cluster | 3 + qpid/python/commands/qpid-config | 2 +- qpid/python/commands/qpid-stat | 449 ++++ qpid/python/qmf/console.py | 6 +- qpid/python/qpid/codec010.py | 25 +- qpid/python/qpid/datatypes.py | 3 +- qpid/python/qpid/disp.py | 165 +- qpid/python/qpid/managementdata.py | 2 +- qpid/python/qpid/spec010.py | 41 +- qpid/python/tests/codec010.py | 21 +- qpid/python/tests_0-10/message.py | 36 + qpid/ruby/Makefile | 47 + qpid/specs/management-schema.xml | 1 + 426 files changed, 15990 insertions(+), 7631 deletions(-) delete mode 100644 qpid/cpp/src/qpid/cluster/ConnectionDecoder.cpp delete mode 100644 qpid/cpp/src/qpid/cluster/ConnectionDecoder.h delete mode 100644 qpid/cpp/src/qpid/cluster/ConnectionMap.cpp delete mode 100644 qpid/cpp/src/qpid/cluster/ConnectionMap.h create mode 100644 qpid/cpp/src/qpid/cluster/LockedConnectionMap.h create mode 100644 qpid/cpp/src/qpid/cluster/McastFrameHandler.h create mode 100644 qpid/cpp/src/qpid/cluster/UpdateExchange.h create mode 100755 qpid/cpp/src/qpid/sys/solaris/SystemInfo.cpp create mode 100644 qpid/cpp/src/tests/FrameDecoder.cpp create mode 100755 qpid/cpp/src/tests/clustered_replication_test create mode 100755 qpid/cpp/src/tests/federated_cluster_test_with_node_failure create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/management/ConfigurationManagement.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/management/ConfigurationManagementMBean.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagement.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagementMBean.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessageHandle.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FileQueueBackingStore.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FileQueueBackingStoreFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FlowableBaseQueueEntryList.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueEntryList.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueBackingStore.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueBackingStoreFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/queue/UnableToFlowMessageException.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/queue/UnableToRecoverMessageException.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainUser.java create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/logging/management/LoggingManagementMBeanTest.java create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryPriorityTest.java create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueThreadPoolTest.java create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/queue/FileQueueBackingStoreTest.java delete mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainUserTest.java create mode 100644 qpid/java/lib/org.apache.commons.codec_1.3.0.v20080530-1600.jar create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/ECLIPSE.RSA create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/ECLIPSE.SF create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/MANIFEST.MF create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/eclipse.inf create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/about.html create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/eclipse_1115.so create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/launcher.gtk.linux.x86_64.properties create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/ECLIPSE.RSA create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/ECLIPSE.SF create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/MANIFEST.MF create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/eclipse.inf create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/about.html create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/eclipse_1115.so create mode 100644 qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/launcher.gtk.solaris.sparc.properties create mode 100644 qpid/java/lib/org.eclipse.swt.gtk.linux.x86_64_3.4.1.v3449c.jar create mode 100644 qpid/java/lib/org.eclipse.swt.gtk.solaris.sparc_3.4.1.v3449c.jar delete mode 100644 qpid/java/management/client/console/wsdl-viewer.xsl create mode 100644 qpid/java/management/client/src/example/PauseAndResumeSubscription.out.ok create mode 100644 qpid/java/management/client/src/example/org/apache/qpid/management/example/PausableSubscriptionExample.java delete mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java delete mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/Constants.java create mode 100644 qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/BaseWsDmAdapterTestCase.java create mode 100644 qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetMultipleResourcePropertiesTestCase.java create mode 100644 qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetResourcePropertiesTestCase.java create mode 100644 qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetResourcePropertyDocumentTestCase.java create mode 100644 qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/MetadataExchangeInterfaceTestCase.java create mode 100644 qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/OperationInvocationInterfaceTestCase.java create mode 100644 qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/SetResourcePropertiesTestCase.java create mode 100644 qpid/java/management/eclipse-plugin/build-release-linux-gtk-x86_64.properties create mode 100644 qpid/java/management/eclipse-plugin/build-release-solaris-gtk-sparc.properties create mode 100644 qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/Configuration/config.ini create mode 100644 qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/libcairo-swt.so create mode 100644 qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/qpidmc create mode 100644 qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/qpidmc.ini create mode 100644 qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Configuration/config.ini create mode 100644 qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.l.pm create mode 100644 qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.m.pm create mode 100644 qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.s.pm create mode 100644 qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.t.pm create mode 100755 qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/qpidmc create mode 100644 qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/qpidmc.ini create mode 100644 qpid/java/systests/src/main/java/org/apache/qpid/server/queue/QueueCreateTest.java create mode 100644 qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowsingFlowToDiskTest.java create mode 100644 qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/ObjectMessageTest.java create mode 100755 qpid/python/commands/qpid-stat create mode 100644 qpid/ruby/Makefile diff --git a/qpid/cpp/configure.ac b/qpid/cpp/configure.ac index 90b943f047..144ca3b607 100644 --- a/qpid/cpp/configure.ac +++ b/qpid/cpp/configure.ac @@ -87,13 +87,14 @@ else AC_CHECK_DECL([__SUNPRO_CC], [SUNCC=yes], [SUNCC=no]) # Set up for sun CC compiler - if test x$SUNCC = xno; then + if test x$SUNCC = xyes; then if test "${enableval}" = yes; then WARNING_FLAGS=+w fi CXXFLAGS="$CXXFLAGS -library=stlport4 -mt" LD="$CXX" LDFLAGS="$LDFLAGS -library=stlport4 -mt" + AC_SUBST([SUNCC_RUNTIME_LIBS], [-lCrun]) fi fi @@ -150,8 +151,9 @@ test -z "$RUBY" && AC_MSG_ERROR([Missing ruby installation (try "yum install rub specdir=`pwd`/$srcdir/../specs AMQP_FINAL_XML=$specdir/amqp.0-10-qpid-errata.xml +test -f $AMQP_FINAL_XML || test -d $srcdir/src/gen || AC_MSG_ERROR([Neither AMQP specs nor spec-generated code present; cannot build.]) AC_SUBST(AMQP_FINAL_XML) -AM_CONDITIONAL([GENERATE], [ls $AMQP_FINAL_XML >/dev/null]) +AM_CONDITIONAL([GENERATE], [test -f $AMQP_FINAL_XML]) # URL and download URL for the package. URL=http://rhm.et.redhat.com/qpidc @@ -311,14 +313,19 @@ LIBS=$tmp_LIBS AM_CONDITIONAL([RDMA], [test x$with_RDMA = xyes]) # Setup --with-ssl/--without-ssl as arguments to configure -tmp_LIBS=$LIBS +SSL_CFLAGS="" +SSL_LDFLAGS="" AC_ARG_WITH([ssl], [AS_HELP_STRING([--with-ssl], [Build with support for SSL])], [case ${withval} in yes) with_SSL=yes - PKG_CHECK_MODULES([SSL], [nspr],,[AC_MSG_ERROR([nspr not found])]) - PKG_CHECK_MODULES([SSL], [nss],,[AC_MSG_ERROR([nss not found])]) + AC_PATH_PROG([NSPR_CONFIG], [nspr-config]) + AS_IF([test x$NSPR_CONFIG = x], [AC_MSG_ERROR([libnspr not found])], []) + AC_PATH_PROG([NSS_CONFIG], [nss-config]) + AS_IF([test x$NSS_CONFIG = x], [AC_MSG_ERROR([libnss not found])], []) + SSL_CFLAGS="`$NSPR_CONFIG --cflags` `$NSS_CONFIG --cflags`" + SSL_LDFLAGS="`$NSPR_CONFIG --libs` `$NSS_CONFIG --libs`" ;; no) with_SSL=no @@ -329,13 +336,18 @@ AC_ARG_WITH([ssl], esac], [ with_SSL=yes - PKG_CHECK_MODULES([SSL], [nspr],,[with_SSL=no]) - PKG_CHECK_MODULES([SSL], [nss],,[with_SSL=no]) + AC_PATH_PROG([NSPR_CONFIG], [nspr-config]) + AS_IF([test x$NSPR_CONFIG = x], [with_SSL=no], + [AC_PATH_PROG([NSS_CONFIG], [nss-config]) + AS_IF([test x$NSS_CONFIG = x], [with_SSL=no], + [SSL_CFLAGS="`$NSPR_CONFIG --cflags` `$NSS_CONFIG --cflags`" + SSL_LDFLAGS="`$NSPR_CONFIG --libs` `$NSS_CONFIG --libs`"])]) ] ) # Remove from LIBS, we will link it explicitly in make files. -LIBS=$tmp_LIBS AM_CONDITIONAL([SSL], [test x$with_SSL = xyes]) +AC_SUBST([SSL_CFLAGS]) +AC_SUBST([SSL_LDFLAGS]) poller=no @@ -367,6 +379,37 @@ if test $poller = xno; then AC_MSG_ERROR([Polling mechanism not implemented for $host]) fi +#Guess host architecture, to choose platform-dependent objects +case "$host" in + *sun-solaris*) + arch=solaris + ;; +esac +AM_CONDITIONAL([SUNOS], [test x$arch = xsolaris]) + +# Check for some syslog capabilities not present in all systems +AC_TRY_COMPILE([#include ], + [int v = LOG_AUTHPRIV;], + [AC_DEFINE([HAVE_LOG_AUTHPRIV], [1], [Set to 1 whether LOG_AUTHPRIV is supported.])],) + +AC_TRY_COMPILE([#include ], + [int v = LOG_FTP;], + [AC_DEFINE([HAVE_LOG_FTP], [1], [Set to 1 whether LOG_FTP is supported.])],) + +#Check if we need to include libacl to provide acl API +gl_saved_libs=$LIBS + AC_SEARCH_LIBS(acl, [acl], + [test "$ac_cv_search_acl" = "none required" || + LIB_ACL=$ac_cv_search_acl]) + AC_SUBST([LIB_ACL]) +LIBS=$gl_saved_libs + +SOCKLIBS="" +AC_CHECK_LIB([socket],[socket],[SOCKET_LIB="-lsocket"],[SOCKET_LIB=""],[]) +AC_CHECK_LIB([nsl],[getipnodebyname],[NSL_LIB="-lnsl"],[NSL_LIB=""],[]) +SOCKLIBS="$SOCKET_LIB $NSL_LIB" +AC_SUBST([SOCKLIBS]) + AM_PATH_PYTHON() # Files to generate diff --git a/qpid/cpp/examples/direct/Makefile.am b/qpid/cpp/examples/direct/Makefile.am index 07431f6fe4..8f220d1b7e 100644 --- a/qpid/cpp/examples/direct/Makefile.am +++ b/qpid/cpp/examples/direct/Makefile.am @@ -18,6 +18,7 @@ # examplesdir=$(pkgdatadir)/examples/direct +MAKELDFLAGS=$(CLIENTFLAGS) include $(top_srcdir)/examples/makedist.mk noinst_PROGRAMS=direct_producer listener declare_queues diff --git a/qpid/cpp/examples/failover/Makefile.am b/qpid/cpp/examples/failover/Makefile.am index c41f26eaba..67d9eb4b95 100644 --- a/qpid/cpp/examples/failover/Makefile.am +++ b/qpid/cpp/examples/failover/Makefile.am @@ -18,6 +18,7 @@ # examplesdir=$(pkgdatadir)/examples/failover +MAKELDFLAGS=$(CLIENTFLAGS) include $(top_srcdir)/examples/makedist.mk noinst_PROGRAMS=declare_queues resuming_receiver replaying_sender diff --git a/qpid/cpp/examples/fanout/Makefile.am b/qpid/cpp/examples/fanout/Makefile.am index 6cbf2c93ad..395fcec9aa 100644 --- a/qpid/cpp/examples/fanout/Makefile.am +++ b/qpid/cpp/examples/fanout/Makefile.am @@ -18,6 +18,7 @@ # examplesdir=$(pkgdatadir)/examples/fanout +MAKELDFLAGS=$(CLIENTFLAGS) include $(top_srcdir)/examples/makedist.mk noinst_PROGRAMS=fanout_producer listener diff --git a/qpid/cpp/examples/makedist.mk b/qpid/cpp/examples/makedist.mk index 4345378983..ce34fd31e2 100644 --- a/qpid/cpp/examples/makedist.mk +++ b/qpid/cpp/examples/makedist.mk @@ -3,7 +3,8 @@ AM_CXXFLAGS = $(WARNING_CFLAGS) INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/gen -I$(top_builddir)/src -I$(top_builddir)/src/gen CLIENT_LIB=$(top_builddir)/src/libqpidclient.la CONSOLE_LIB=$(top_builddir)/src/libqmfconsole.la -MAKELDFLAG ?= qpidclient +CLIENTFLAGS=-lqpidclient +CONSOLEFLAGS=-lqmfconsole # Generate a simple non-automake Makefile for distribution. MAKEDIST=.libs/Makefile @@ -12,7 +13,7 @@ $(MAKEDIST): Makefile mkdir -p .libs @$(ECHO) CXX=$(CXX) > $(MAKEDIST) @$(ECHO) CXXFLAGS=$(CXXFLAGS) >> $(MAKEDIST) - @$(ECHO) LDFLAGS=-l$(MAKELDFLAG) >> $(MAKEDIST) + @$(ECHO) LDFLAGS=-l$(MAKELDFLAGS) >> $(MAKEDIST) @$(ECHO) >> $(MAKEDIST) @$(ECHO) all: $(noinst_PROGRAMS) >> $(MAKEDIST) @$(ECHO) >> $(MAKEDIST) diff --git a/qpid/cpp/examples/pub-sub/Makefile.am b/qpid/cpp/examples/pub-sub/Makefile.am index bdbf0f8d20..1d52daf638 100644 --- a/qpid/cpp/examples/pub-sub/Makefile.am +++ b/qpid/cpp/examples/pub-sub/Makefile.am @@ -18,6 +18,7 @@ # examplesdir=$(pkgdatadir)/examples/pub-sub +MAKELDFLAGS=$(CLIENTFLAGS) include $(top_srcdir)/examples/makedist.mk noinst_PROGRAMS=topic_listener topic_publisher diff --git a/qpid/cpp/examples/qmf-console/Makefile.am b/qpid/cpp/examples/qmf-console/Makefile.am index 471620f465..04a92c214e 100644 --- a/qpid/cpp/examples/qmf-console/Makefile.am +++ b/qpid/cpp/examples/qmf-console/Makefile.am @@ -19,7 +19,7 @@ examplesdir=$(pkgdatadir)/examples/qmf-console -MAKELDFLAG = qmfconsole +MAKELDFLAGS=$(CONSOLEFLAGS) include $(top_srcdir)/examples/makedist.mk noinst_PROGRAMS=console printevents ping queuestats diff --git a/qpid/cpp/examples/request-response/Makefile.am b/qpid/cpp/examples/request-response/Makefile.am index 8fb95f24fc..d7e7d692de 100644 --- a/qpid/cpp/examples/request-response/Makefile.am +++ b/qpid/cpp/examples/request-response/Makefile.am @@ -18,6 +18,7 @@ # examplesdir=$(pkgdatadir)/examples/request-response +MAKELDFLAGS=$(CLIENTFLAGS) include $(top_srcdir)/examples/makedist.mk noinst_PROGRAMS=client server diff --git a/qpid/cpp/examples/tradedemo/Makefile.am b/qpid/cpp/examples/tradedemo/Makefile.am index ef90e04bb0..a3c7fabd65 100644 --- a/qpid/cpp/examples/tradedemo/Makefile.am +++ b/qpid/cpp/examples/tradedemo/Makefile.am @@ -18,6 +18,7 @@ # examplesdir=$(pkgdatadir)/examples/tradedemo +MAKELDFLAGS=$(CLIENTFLAGS) include $(top_srcdir)/examples/makedist.mk noinst_PROGRAMS=topic_listener topic_publisher declare_queues diff --git a/qpid/cpp/examples/xml-exchange/Makefile.am b/qpid/cpp/examples/xml-exchange/Makefile.am index 0f99aea44e..aa450a32c2 100644 --- a/qpid/cpp/examples/xml-exchange/Makefile.am +++ b/qpid/cpp/examples/xml-exchange/Makefile.am @@ -18,6 +18,7 @@ # examplesdir=$(pkgdatadir)/examples/xml-exchange +MAKELDFLAGS=$(CLIENTFLAGS) include $(top_srcdir)/examples/makedist.mk noinst_PROGRAMS=declare_queues xml_producer listener diff --git a/qpid/cpp/src/Makefile.am b/qpid/cpp/src/Makefile.am index 05fba55251..0eece459b6 100644 --- a/qpid/cpp/src/Makefile.am +++ b/qpid/cpp/src/Makefile.am @@ -127,7 +127,6 @@ posix_plat_src = \ qpid/sys/posix/Time.cpp \ qpid/sys/posix/Thread.cpp \ qpid/sys/posix/Shlib.cpp \ - qpid/sys/posix/SystemInfo.cpp \ qpid/sys/posix/Mutex.cpp \ qpid/sys/posix/Fork.cpp \ qpid/sys/posix/StrError.cpp \ @@ -151,7 +150,13 @@ if HAVE_ECF poller = qpid/sys/solaris/ECFPoller.cpp endif -platform_src = $(posix_plat_src) $(poller) +if SUNOS + systeminfo = qpid/sys/solaris/SystemInfo.cpp +else + systeminfo = qpid/sys/posix/SystemInfo.cpp +endif + +platform_src = $(posix_plat_src) $(poller) $(systeminfo) platform_hdr = $(posix_plat_hdr) posix_broker_src = \ diff --git a/qpid/cpp/src/acl.mk b/qpid/cpp/src/acl.mk index 2b3ab4dfd9..95b47acc1c 100644 --- a/qpid/cpp/src/acl.mk +++ b/qpid/cpp/src/acl.mk @@ -31,4 +31,8 @@ acl_la_SOURCES = \ qpid/acl/AclReader.h acl_la_LIBADD = libqpidbroker.la +if SUNOS + acl_la_LIBADD += libqmfagent.la libqmfconsole.la libqpidcommon.la -lboost_program_options $(SUNCC_RUNTIME_LIBS) +endif + acl_la_LDFLAGS = $(PLUGINLDFLAGS) diff --git a/qpid/cpp/src/cluster.mk b/qpid/cpp/src/cluster.mk index 0d34788d2e..e2054d75e9 100644 --- a/qpid/cpp/src/cluster.mk +++ b/qpid/cpp/src/cluster.mk @@ -40,6 +40,8 @@ cluster_la_SOURCES = \ $(CMAN_SOURCES) \ qpid/cluster/Cluster.cpp \ qpid/cluster/Cluster.h \ + qpid/cluster/Decoder.cpp \ + qpid/cluster/Decoder.h \ qpid/cluster/PollableQueue.h \ qpid/cluster/ClusterMap.cpp \ qpid/cluster/ClusterMap.h \ @@ -49,14 +51,8 @@ cluster_la_SOURCES = \ qpid/cluster/Connection.h \ qpid/cluster/ConnectionCodec.cpp \ qpid/cluster/ConnectionCodec.h \ - qpid/cluster/ConnectionMap.h \ - qpid/cluster/ConnectionMap.cpp \ qpid/cluster/Cpg.cpp \ qpid/cluster/Cpg.h \ - qpid/cluster/Decoder.cpp \ - qpid/cluster/Decoder.h \ - qpid/cluster/ConnectionDecoder.cpp \ - qpid/cluster/ConnectionDecoder.h \ qpid/cluster/Dispatchable.h \ qpid/cluster/UpdateClient.cpp \ qpid/cluster/UpdateClient.h \ @@ -68,8 +64,11 @@ cluster_la_SOURCES = \ qpid/cluster/ExpiryPolicy.cpp \ qpid/cluster/FailoverExchange.cpp \ qpid/cluster/FailoverExchange.h \ + qpid/cluster/UpdateExchange.h \ + qpid/cluster/LockedConnectionMap.h \ qpid/cluster/Multicaster.cpp \ qpid/cluster/Multicaster.h \ + qpid/cluster/McastFrameHandler.h \ qpid/cluster/NoOpConnectionOutputHandler.h \ qpid/cluster/OutputInterceptor.cpp \ qpid/cluster/OutputInterceptor.h \ diff --git a/qpid/cpp/src/common.vcproj b/qpid/cpp/src/common.vcproj index 893c5bfd7b..5ab2dbafde 100644 --- a/qpid/cpp/src/common.vcproj +++ b/qpid/cpp/src/common.vcproj @@ -419,6 +419,9 @@ + + @@ -1125,6 +1128,9 @@ + + diff --git a/qpid/cpp/src/qpid/SessionId.cpp b/qpid/cpp/src/qpid/SessionId.cpp index fce6619f5d..098998015f 100644 --- a/qpid/cpp/src/qpid/SessionId.cpp +++ b/qpid/cpp/src/qpid/SessionId.cpp @@ -35,7 +35,7 @@ bool SessionId::operator==(const SessionId& id) const { } std::ostream& operator<<(std::ostream& o, const SessionId& id) { - return o << id.getName() << "@" << id.getUserId(); + return o << id.getUserId() << "." << id.getName(); } std::string SessionId::str() const { diff --git a/qpid/cpp/src/qpid/SessionState.cpp b/qpid/cpp/src/qpid/SessionState.cpp index ac75b5c5ff..3e844fb24b 100644 --- a/qpid/cpp/src/qpid/SessionState.cpp +++ b/qpid/cpp/src/qpid/SessionState.cpp @@ -113,7 +113,8 @@ SessionState::ReplayRange SessionState::senderExpected(const SessionPoint& expec void SessionState::senderRecord(const AMQFrame& f) { if (isControl(f)) return; // Ignore control frames. - QPID_LOG_IF(debug, f.getMethod(), getId() << ": sent cmd " << sender.sendPoint.command << ": " << *f.getMethod()); + QPID_LOG(trace, getId() << ": sent cmd " << sender.sendPoint.command << ": " << *f.getBody()); + stateful = true; if (timeout) sender.replayList.push_back(f); sender.unflushedSize += f.encodedSize(); @@ -183,6 +184,7 @@ void SessionState::receiverSetCommandPoint(const SessionPoint& point) { } bool SessionState::receiverRecord(const AMQFrame& f) { + if (receiverTrackingDisabled) return true; //Very nasty hack for push bridges if (isControl(f)) return true; // Ignore control frames. stateful = true; receiver.expected.advance(f); @@ -192,12 +194,13 @@ bool SessionState::receiverRecord(const AMQFrame& f) { receiver.received = receiver.expected; receiver.incomplete += receiverGetCurrent(); } - QPID_LOG_IF(debug, f.getMethod(), getId() << ": recv cmd " << receiverGetCurrent() << ": " << *f.getMethod()); - QPID_LOG_IF(debug, !firstTime, "Ignoring duplicate frame: " << receiverGetCurrent() << ": " << f); + QPID_LOG(trace, getId() << ": recv cmd " << receiverGetCurrent() << ": " << *f.getBody()); + if (!firstTime) QPID_LOG(trace, "Ignoring duplicate frame."); return firstTime; } void SessionState::receiverCompleted(SequenceNumber command, bool cumulative) { + if (receiverTrackingDisabled) return; //Very nasty hack for push bridges assert(receiver.incomplete.contains(command)); // Internal error to complete command twice. SequenceNumber first =cumulative ? receiver.incomplete.front() : command; SequenceNumber last = command; @@ -237,7 +240,7 @@ SessionState::Configuration::Configuration(size_t flush, size_t hard) : replayFlushLimit(flush), replayHardLimit(hard) {} SessionState::SessionState(const SessionId& i, const Configuration& c) - : id(i), timeout(), config(c), stateful() + : id(i), timeout(), config(c), stateful(), receiverTrackingDisabled(false) { QPID_LOG(debug, "SessionState::SessionState " << id << ": " << this); } @@ -275,4 +278,7 @@ void SessionState::setState( receiver.bytesSinceKnownCompleted = 0; } +void SessionState::disableReceiverTracking() { receiverTrackingDisabled = true; } +void SessionState::enableReceiverTracking() { receiverTrackingDisabled = false; } + } // namespace qpid diff --git a/qpid/cpp/src/qpid/SessionState.h b/qpid/cpp/src/qpid/SessionState.h index cdf59506a0..a37ce804e4 100644 --- a/qpid/cpp/src/qpid/SessionState.h +++ b/qpid/cpp/src/qpid/SessionState.h @@ -182,6 +182,20 @@ class SessionState { const SequenceSet& receivedIncomplete ); + /** + * So called 'push' bridges work by faking a subscribe request + * (and the accompanyingflows etc) to the local broker to initiate + * the outflow of messages for the bridge. + * + * As the peer doesn't send these it cannot include them in its + * session state. To keep the session state on either side of the + * bridge in sync, this hack allows the tracking of state for + * received messages to be disabled for the faked commands and + * subsequently re-enabled. + */ + void disableReceiverTracking(); + void enableReceiverTracking(); + private: struct SendState { @@ -210,6 +224,7 @@ class SessionState { uint32_t timeout; Configuration config; bool stateful; + bool receiverTrackingDisabled;//very nasty hack for 'push' bridges }; inline bool operator==(const SessionId& id, const SessionState& s) { return s == id; } diff --git a/qpid/cpp/src/qpid/acl/AclPlugin.cpp b/qpid/cpp/src/qpid/acl/AclPlugin.cpp index 7310139041..4c6efa19dd 100644 --- a/qpid/cpp/src/qpid/acl/AclPlugin.cpp +++ b/qpid/cpp/src/qpid/acl/AclPlugin.cpp @@ -62,15 +62,10 @@ struct AclPlugin : public Plugin { if (acl) throw Exception("ACL plugin cannot be initialized twice in one process."); - if (values.aclFile.at(0) == '/') - { - values.aclFile = values.aclFile; - } - else - { - std::ostringstream oss; - oss << b.getDataDir().getPath() << "/" << values.aclFile; - values.aclFile = oss.str(); + if (values.aclFile.at(0) != '/' && !b.getDataDir().getPath().empty()) { + std::ostringstream oss; + oss << b.getDataDir().getPath() << "/" << values.aclFile; + values.aclFile = oss.str(); } acl = new Acl(values, b); diff --git a/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp b/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp index 1e2f4cdd78..7c70c12213 100644 --- a/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp +++ b/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp @@ -151,7 +151,7 @@ void ManagementAgentImpl::init(const client::ConnectionSettings& settings, // TODO: Abstract the socket calls for portability if (extThread) { int pair[2]; - int result = socketpair(PF_LOCAL, SOCK_STREAM, 0, pair); + int result = socketpair(PF_UNIX, SOCK_STREAM, 0, pair); if (result == -1) { return; } @@ -485,6 +485,9 @@ void ManagementAgentImpl::handleGetQuery(Buffer& inBuffer, uint32_t sequence, st Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE); uint32_t outLen; + if (object->getConfigChanged() || object->getInstChanged()) + object->setUpdateTime(); + encodeHeader(outBuffer, 'g', sequence); object->writeProperties(outBuffer); object->writeStatistics(outBuffer, true); @@ -508,6 +511,9 @@ void ManagementAgentImpl::handleGetQuery(Buffer& inBuffer, uint32_t sequence, st Buffer outBuffer(outputBuffer, MA_BUFFER_SIZE); uint32_t outLen; + if (object->getConfigChanged() || object->getInstChanged()) + object->setUpdateTime(); + encodeHeader(outBuffer, 'g', sequence); object->writeProperties(outBuffer); object->writeStatistics(outBuffer, true); diff --git a/qpid/cpp/src/qpid/amqp_0_10/SessionHandler.cpp b/qpid/cpp/src/qpid/amqp_0_10/SessionHandler.cpp index f58d59cbd7..db957051d8 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/SessionHandler.cpp +++ b/qpid/cpp/src/qpid/amqp_0_10/SessionHandler.cpp @@ -277,7 +277,6 @@ void SessionHandler::sendCompletion() { } void SessionHandler::sendAttach(bool force) { - CHECK_ATTACHED("session.send-attach"); QPID_LOG(debug, "SessionHandler::sendAttach attach id=" << getState()->getId()); peer.attach(getState()->getId().getName(), force); if (getState()->hasState()) diff --git a/qpid/cpp/src/qpid/assert.cpp b/qpid/cpp/src/qpid/assert.cpp index 5d039da528..bf36d3be86 100644 --- a/qpid/cpp/src/qpid/assert.cpp +++ b/qpid/cpp/src/qpid/assert.cpp @@ -35,7 +35,7 @@ void assert_fail(char const * expr, char const * function, char const * file, lo #ifdef NDEBUG throw framing::InternalErrorException(msg.str()); #else - std::cerr << msg << std::endl; + std::cerr << msg.str() << std::endl; abort(); #endif } diff --git a/qpid/cpp/src/qpid/broker/Bridge.cpp b/qpid/cpp/src/qpid/broker/Bridge.cpp index cc28213884..4d275b958f 100644 --- a/qpid/cpp/src/qpid/broker/Bridge.cpp +++ b/qpid/cpp/src/qpid/broker/Bridge.cpp @@ -22,6 +22,7 @@ #include "ConnectionState.h" #include "Connection.h" #include "LinkRegistry.h" +#include "SessionState.h" #include "qpid/agent/ManagementAgent.h" #include "qpid/framing/FieldTable.h" @@ -80,31 +81,31 @@ Bridge::~Bridge() mgmtObject->resourceDestroy(); } -void Bridge::create(ConnectionState& c) +void Bridge::create(Connection& c) { + connState = &c; FieldTable options; if (args.i_sync) options.setInt("qpid.sync_frequency", args.i_sync); - connState = &c; + SessionHandler& sessionHandler = c.getChannel(id); if (args.i_srcIsLocal) { if (args.i_dynamic) throw Exception("Dynamic routing not supported for push routes"); // Point the bridging commands at the local connection handler - Connection* conn = dynamic_cast(&c); - if (conn == 0) - return; - pushHandler.reset(new PushHandler(conn)); + pushHandler.reset(new PushHandler(&c)); channelHandler.reset(new framing::ChannelHandler(id, pushHandler.get())); + + session.reset(new framing::AMQP_ServerProxy::Session(*channelHandler)); + peer.reset(new framing::AMQP_ServerProxy(*channelHandler)); + + session->attach(name, false); + session->commandPoint(0,0); } else { + sessionHandler.attachAs(name); // Point the bridging commands at the remote peer broker - channelHandler.reset(new framing::ChannelHandler(id, &(connState->getOutput()))); + peer.reset(new framing::AMQP_ServerProxy(sessionHandler.out)); } - session.reset(new framing::AMQP_ServerProxy::Session(*channelHandler)); - peer.reset(new framing::AMQP_ServerProxy(*channelHandler)); - - session->attach(name, false); - session->commandPoint(0,0); - + if (args.i_srcIsLocal) sessionHandler.getSession()->disableReceiverTracking(); if (args.i_srcIsQueue) { peer->getMessage().subscribe(args.i_src, args.i_dest, args.i_sync ? 0 : 1, 0, false, "", 0, options); peer->getMessage().flow(args.i_dest, 0, 0xFFFFFFFF); @@ -116,7 +117,7 @@ void Bridge::create(ConnectionState& c) if (args.i_tag.size()) { queueSettings.setString("qpid.trace.id", args.i_tag); } else { - const string& peerTag = connState->getFederationPeerTag(); + const string& peerTag = c.getFederationPeerTag(); if (peerTag.size()) queueSettings.setString("qpid.trace.id", peerTag); } @@ -129,7 +130,7 @@ void Bridge::create(ConnectionState& c) queueSettings.setString("qpid.trace.exclude", localTag); } - bool durable = false;//should this be an arg, or would be use srcIsQueue for durable queues? + bool durable = false;//should this be an arg, or would we use srcIsQueue for durable queues? bool autoDelete = !durable;//auto delete transient queues? peer->getQueue().declare(queueName, "", false, durable, true, autoDelete, queueSettings); if (!args.i_dynamic) @@ -148,12 +149,23 @@ void Bridge::create(ConnectionState& c) QPID_LOG(debug, "Activated static route from exchange " << args.i_src << " to " << args.i_dest); } } + if (args.i_srcIsLocal) sessionHandler.getSession()->enableReceiverTracking(); } -void Bridge::cancel() +void Bridge::cancel(Connection& c) { + if (args.i_srcIsLocal) { + //recreate peer to be sure that the session handler reference + //is valid (it could have been deleted due to a detach) + SessionHandler& sessionHandler = c.getChannel(id); + peer.reset(new framing::AMQP_ServerProxy(sessionHandler.out)); + } peer->getMessage().cancel(args.i_dest); peer->getSession().detach(name); +} + +void Bridge::closed() +{ if (args.i_dynamic) { Exchange::shared_ptr exchange = link->getBroker()->getExchanges().get(args.i_src); if (exchange.get() != 0) diff --git a/qpid/cpp/src/qpid/broker/Bridge.h b/qpid/cpp/src/qpid/broker/Bridge.h index c530a5d696..dae28ddeaa 100644 --- a/qpid/cpp/src/qpid/broker/Bridge.h +++ b/qpid/cpp/src/qpid/broker/Bridge.h @@ -52,8 +52,9 @@ public: const qmf::org::apache::qpid::broker::ArgsLinkBridge& args); ~Bridge(); - void create(ConnectionState& c); - void cancel(); + void create(Connection& c); + void cancel(Connection& c); + void closed(); void destroy(); bool isDurable() { return args.i_durable; } diff --git a/qpid/cpp/src/qpid/broker/Broker.cpp b/qpid/cpp/src/qpid/broker/Broker.cpp index 95f55bb596..b999a62965 100644 --- a/qpid/cpp/src/qpid/broker/Broker.cpp +++ b/qpid/cpp/src/qpid/broker/Broker.cpp @@ -199,6 +199,7 @@ Broker::Broker(const Broker::Options& conf) : } QueuePolicy::setDefaultMaxSize(conf.queueLimit); + queues.setQueueEvents(&queueEvents); // Early-Initialize plugins const Plugin::Plugins& plugins=Plugin::getPlugins(); diff --git a/qpid/cpp/src/qpid/broker/Connection.cpp b/qpid/cpp/src/qpid/broker/Connection.cpp index b7446a2220..b06e06d353 100644 --- a/qpid/cpp/src/qpid/broker/Connection.cpp +++ b/qpid/cpp/src/qpid/broker/Connection.cpp @@ -80,7 +80,8 @@ Connection::Connection(ConnectionOutputHandler* out_, Broker& broker_, const std void Connection::requestIOProcessing(boost::function0 callback) { - ioCallback = callback; + ScopedLock l(ioCallbackLock); + ioCallbacks.push(callback); out.activateOutput(); } @@ -221,10 +222,13 @@ bool Connection::hasOutput() { return outputTasks.hasOutput(); } bool Connection::doOutput() { try{ - if (ioCallback) - ioCallback(); // Lend the IO thread for management processing - ioCallback = 0; - + { + ScopedLock l(ioCallbackLock); + while (!ioCallbacks.empty()) { + ioCallbacks.front()(); // Lend the IO thread for management processing + ioCallbacks.pop(); + } + } if (mgmtClosing) close(connection::CLOSE_CODE_CONNECTION_FORCED, "Closed by Management Request"); else diff --git a/qpid/cpp/src/qpid/broker/Connection.h b/qpid/cpp/src/qpid/broker/Connection.h index b1e1cda973..b659fe6468 100644 --- a/qpid/cpp/src/qpid/broker/Connection.h +++ b/qpid/cpp/src/qpid/broker/Connection.h @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -47,6 +48,7 @@ #include "qpid/sys/ConnectionOutputHandler.h" #include "qpid/sys/Socket.h" #include "qpid/sys/TimeoutHandler.h" +#include "qpid/sys/Mutex.h" #include #include @@ -119,7 +121,8 @@ class Connection : public sys::ConnectionInputHandler, const bool isLink; bool mgmtClosing; const std::string mgmtId; - boost::function0 ioCallback; + sys::Mutex ioCallbackLock; + std::queue > ioCallbacks; qmf::org::apache::qpid::broker::Connection* mgmtObject; LinkRegistry& links; management::ManagementAgent* agent; diff --git a/qpid/cpp/src/qpid/broker/ConnectionState.h b/qpid/cpp/src/qpid/broker/ConnectionState.h index 0e9d211b56..b712af11f5 100644 --- a/qpid/cpp/src/qpid/broker/ConnectionState.h +++ b/qpid/cpp/src/qpid/broker/ConnectionState.h @@ -48,8 +48,9 @@ class ConnectionState : public ConnectionToken, public management::Manageable heartbeatmax(120), stagingThreshold(broker.getStagingThreshold()), federationLink(true), - clientSupportsThrottling(false) - {} + clientSupportsThrottling(false), + clusterOrderOut(0) + {} virtual ~ConnectionState () {} @@ -75,7 +76,7 @@ class ConnectionState : public ConnectionToken, public management::Manageable const string& getFederationPeerTag() const { return federationPeerTag; } std::vector& getKnownHosts() { return knownHosts; } - void setClientThrottling() { clientSupportsThrottling = true; } + void setClientThrottling(bool set=true) { clientSupportsThrottling = set; } bool getClientThrottling() const { return clientSupportsThrottling; } Broker& getBroker() { return broker; } @@ -86,11 +87,21 @@ class ConnectionState : public ConnectionToken, public management::Manageable //contained output tasks sys::AggregateOutput outputTasks; - sys::ConnectionOutputHandlerPtr& getOutput() { return out; } + sys::ConnectionOutputHandler& getOutput() { return out; } framing::ProtocolVersion getVersion() const { return version; } - void setOutputHandler(qpid::sys::ConnectionOutputHandler* o) { out.set(o); } + /** + * If the broker is part of a cluster, this is a handler provided + * by cluster code. It ensures consistent ordering of commands + * that are sent based on criteria that are not predictably + * ordered cluster-wide, e.g. a timer firing. + */ + framing::FrameHandler* getClusterOrderOutput() { return clusterOrderOut; } + void setClusterOrderOutput(framing::FrameHandler& fh) { clusterOrderOut = &fh; } + + virtual void requestIOProcessing (boost::function0) = 0; + protected: framing::ProtocolVersion version; uint32_t framemax; @@ -103,6 +114,7 @@ class ConnectionState : public ConnectionToken, public management::Manageable string federationPeerTag; std::vector knownHosts; bool clientSupportsThrottling; + framing::FrameHandler* clusterOrderOut; }; }} diff --git a/qpid/cpp/src/qpid/broker/Daemon.h b/qpid/cpp/src/qpid/broker/Daemon.h index 98468debb7..a9cd98bce2 100644 --- a/qpid/cpp/src/qpid/broker/Daemon.h +++ b/qpid/cpp/src/qpid/broker/Daemon.h @@ -19,10 +19,12 @@ * */ -#include +#include "qpid/sys/IntegerTypes.h" #include #include #include +#include + namespace qpid { namespace broker { diff --git a/qpid/cpp/src/qpid/broker/Exchange.cpp b/qpid/cpp/src/qpid/broker/Exchange.cpp index f8b9e4b183..dd1fe98b2c 100644 --- a/qpid/cpp/src/qpid/broker/Exchange.cpp +++ b/qpid/cpp/src/qpid/broker/Exchange.cpp @@ -102,8 +102,8 @@ static const std::string QPID_MANAGEMENT("qpid.management"); Exchange::Exchange(const string& _name, bool _durable, const qpid::framing::FieldTable& _args, Manageable* parent) - : name(_name), durable(_durable), args(_args), alternateUsers(0), persistenceId(0), - sequence(false), sequenceNo(0), ive(false), mgmtExchange(0) + : name(_name), durable(_durable), alternateUsers(0), persistenceId(0), + args(_args), sequence(false), sequenceNo(0), ive(false), mgmtExchange(0) { if (parent != 0) { @@ -275,3 +275,7 @@ bool Exchange::MatchQueue::operator()(Exchange::Binding::shared_ptr b) { return b->queue == queue; } + +void Exchange::setProperties(const boost::intrusive_ptr& msg) { + msg->getProperties()->setExchange(getName()); +} diff --git a/qpid/cpp/src/qpid/broker/Exchange.h b/qpid/cpp/src/qpid/broker/Exchange.h index 4591216aaf..45f71a039d 100644 --- a/qpid/cpp/src/qpid/broker/Exchange.h +++ b/qpid/cpp/src/qpid/broker/Exchange.h @@ -59,12 +59,12 @@ public: private: const std::string name; const bool durable; - mutable qpid::framing::FieldTable args; boost::shared_ptr alternate; uint32_t alternateUsers; mutable uint64_t persistenceId; protected: + mutable qpid::framing::FieldTable args; bool sequence; mutable qpid::sys::Mutex sequenceLock; int64_t sequenceNo; @@ -140,13 +140,14 @@ public: virtual bool bind(Queue::shared_ptr queue, const std::string& routingKey, const qpid::framing::FieldTable* args) = 0; virtual bool unbind(Queue::shared_ptr queue, const std::string& routingKey, const qpid::framing::FieldTable* args) = 0; virtual bool isBound(Queue::shared_ptr queue, const std::string* const routingKey, const qpid::framing::FieldTable* const args) = 0; + virtual void setProperties(const boost::intrusive_ptr&); virtual void route(Deliverable& msg, const std::string& routingKey, const qpid::framing::FieldTable* args) = 0; - + //PersistableExchange: void setPersistenceId(uint64_t id) const; uint64_t getPersistenceId() const { return persistenceId; } uint32_t encodedSize() const; - QPID_BROKER_EXTERN void encode(framing::Buffer& buffer) const; + QPID_BROKER_EXTERN virtual void encode(framing::Buffer& buffer) const; static QPID_BROKER_EXTERN Exchange::shared_ptr decode(ExchangeRegistry& exchanges, framing::Buffer& buffer); diff --git a/qpid/cpp/src/qpid/broker/HeadersExchange.cpp b/qpid/cpp/src/qpid/broker/HeadersExchange.cpp index 104b34da8b..09fb2d9bef 100644 --- a/qpid/cpp/src/qpid/broker/HeadersExchange.cpp +++ b/qpid/cpp/src/qpid/broker/HeadersExchange.cpp @@ -105,33 +105,42 @@ bool HeadersExchange::unbind(Queue::shared_ptr queue, const string& bindingKey, void HeadersExchange::route(Deliverable& msg, const string& /*routingKey*/, const FieldTable* args){ - if (!args) return;//can't match if there were no headers passed in + if (!args) { + //can't match if there were no headers passed in + if (mgmtExchange != 0) { + mgmtExchange->inc_msgReceives(); + mgmtExchange->inc_byteReceives(msg.contentSize()); + mgmtExchange->inc_msgDrops(); + mgmtExchange->inc_byteDrops(msg.contentSize()); + } + return; + } + PreRoute pr(msg, this); uint32_t count(0); Bindings::ConstPtr p = bindings.snapshot(); if (p.get()){ - for (std::vector::const_iterator i = p->begin(); i != p->end(); ++i, count++) { - if (match((*i)->args, *args)) msg.deliverTo((*i)->queue); - if ((*i)->mgmtBinding != 0) - (*i)->mgmtBinding->inc_msgMatched (); + for (std::vector::const_iterator i = p->begin(); i != p->end(); ++i) { + if (match((*i)->args, *args)) { + msg.deliverTo((*i)->queue); + count++; + if ((*i)->mgmtBinding != 0) + (*i)->mgmtBinding->inc_msgMatched(); + } } } - if (mgmtExchange != 0) - { - mgmtExchange->inc_msgReceives (); - mgmtExchange->inc_byteReceives (msg.contentSize ()); - if (count == 0) - { - mgmtExchange->inc_msgDrops (); - mgmtExchange->inc_byteDrops (msg.contentSize ()); - } - else - { - mgmtExchange->inc_msgRoutes (count); - mgmtExchange->inc_byteRoutes (count * msg.contentSize ()); + if (mgmtExchange != 0) { + mgmtExchange->inc_msgReceives(); + mgmtExchange->inc_byteReceives(msg.contentSize()); + if (count == 0) { + mgmtExchange->inc_msgDrops(); + mgmtExchange->inc_byteDrops(msg.contentSize()); + } else { + mgmtExchange->inc_msgRoutes(count); + mgmtExchange->inc_byteRoutes(count * msg.contentSize()); } } } diff --git a/qpid/cpp/src/qpid/broker/Link.cpp b/qpid/cpp/src/qpid/broker/Link.cpp index e36635831b..dd1a1fa0b4 100644 --- a/qpid/cpp/src/qpid/broker/Link.cpp +++ b/qpid/cpp/src/qpid/broker/Link.cpp @@ -158,7 +158,7 @@ void Link::closed (int, std::string text) } for (Bridges::iterator i = active.begin(); i != active.end(); i++) { - (*i)->cancel(); + (*i)->closed(); created.push_back(*i); } active.clear(); @@ -217,21 +217,27 @@ void Link::add(Bridge::shared_ptr bridge) void Link::cancel(Bridge::shared_ptr bridge) { - Mutex::ScopedLock mutex(lock); - - for (Bridges::iterator i = created.begin(); i != created.end(); i++) { - if ((*i).get() == bridge.get()) { - created.erase(i); - break; + { + Mutex::ScopedLock mutex(lock); + + for (Bridges::iterator i = created.begin(); i != created.end(); i++) { + if ((*i).get() == bridge.get()) { + created.erase(i); + break; + } } - } - for (Bridges::iterator i = active.begin(); i != active.end(); i++) { - if ((*i).get() == bridge.get()) { - bridge->cancel(); - active.erase(i); - break; + for (Bridges::iterator i = active.begin(); i != active.end(); i++) { + if ((*i).get() == bridge.get()) { + cancellations.push_back(bridge); + bridge->closed(); + active.erase(i); + break; + } } } + if (!cancellations.empty()) { + connection->requestIOProcessing (boost::bind(&Link::ioThreadProcessing, this)); + } } void Link::ioThreadProcessing() @@ -242,7 +248,7 @@ void Link::ioThreadProcessing() return; QPID_LOG(debug, "Link::ioThreadProcessing()"); - //process any pending creates + //process any pending creates and/or cancellations if (!created.empty()) { for (Bridges::iterator i = created.begin(); i != created.end(); ++i) { active.push_back(*i); @@ -250,6 +256,13 @@ void Link::ioThreadProcessing() } created.clear(); } + if (!cancellations.empty()) { + for (Bridges::iterator i = cancellations.begin(); i != cancellations.end(); ++i) { + active.push_back(*i); + (*i)->cancel(*connection); + } + cancellations.clear(); + } } void Link::setConnection(Connection* c) @@ -284,7 +297,7 @@ void Link::maintenanceVisit () } } } - else if (state == STATE_OPERATIONAL && !created.empty() && connection != 0) + else if (state == STATE_OPERATIONAL && (!created.empty() || !cancellations.empty()) && connection != 0) connection->requestIOProcessing (boost::bind(&Link::ioThreadProcessing, this)); } diff --git a/qpid/cpp/src/qpid/broker/Link.h b/qpid/cpp/src/qpid/broker/Link.h index 8e741c6eb7..39014b0ec0 100644 --- a/qpid/cpp/src/qpid/broker/Link.h +++ b/qpid/cpp/src/qpid/broker/Link.h @@ -67,6 +67,7 @@ namespace qpid { typedef std::vector Bridges; Bridges created; // Bridges pending creation Bridges active; // Bridges active + Bridges cancellations; // Bridges pending cancellation uint channelCounter; Connection* connection; management::ManagementAgent* agent; diff --git a/qpid/cpp/src/qpid/broker/LinkRegistry.cpp b/qpid/cpp/src/qpid/broker/LinkRegistry.cpp index 97b1c32d64..d4ae0aedd8 100644 --- a/qpid/cpp/src/qpid/broker/LinkRegistry.cpp +++ b/qpid/cpp/src/qpid/broker/LinkRegistry.cpp @@ -19,19 +19,24 @@ * */ #include "LinkRegistry.h" +#include "Connection.h" #include "qpid/log/Statement.h" #include +#include using namespace qpid::broker; using namespace qpid::sys; using std::pair; using std::stringstream; using boost::intrusive_ptr; +using boost::format; +using boost::str; namespace _qmf = qmf::org::apache::qpid::broker; #define LINK_MAINT_INTERVAL 2 -LinkRegistry::LinkRegistry (Broker* _broker) : broker(_broker), parent(0), store(0), passive(false), passiveChanged(false) +LinkRegistry::LinkRegistry (Broker* _broker) : broker(_broker), parent(0), store(0), passive(false), passiveChanged(false), + realm(broker ? broker->getOptions().realm : "") { timer.add (intrusive_ptr (new Periodic(*this))); } @@ -241,6 +246,7 @@ void LinkRegistry::notifyConnection(const std::string& key, Connection* c) { l->second->established(); l->second->setConnection(c); + c->setUserId(str(format("%1%@%2%") % l->second->getUsername() % realm)); } } diff --git a/qpid/cpp/src/qpid/broker/LinkRegistry.h b/qpid/cpp/src/qpid/broker/LinkRegistry.h index 884228bd63..92064692f5 100644 --- a/qpid/cpp/src/qpid/broker/LinkRegistry.h +++ b/qpid/cpp/src/qpid/broker/LinkRegistry.h @@ -66,6 +66,7 @@ namespace broker { MessageStore* store; bool passive; bool passiveChanged; + std::string realm; void periodicMaintenance (); bool updateAddress(const std::string& oldKey, const TcpAddress& newAddress); diff --git a/qpid/cpp/src/qpid/broker/Message.cpp b/qpid/cpp/src/qpid/broker/Message.cpp index 133e2b5ad1..30294b4507 100644 --- a/qpid/cpp/src/qpid/broker/Message.cpp +++ b/qpid/cpp/src/qpid/broker/Message.cpp @@ -382,4 +382,9 @@ void Message::resetEnqueueCompleteCallback() { enqueueCallback = 0; } void Message::setDequeueCompleteCallback(MessageCallback& cb) { dequeueCallback = &cb; } void Message::resetDequeueCompleteCallback() { dequeueCallback = 0; } +framing::FieldTable& Message::getOrInsertHeaders() +{ + return getProperties()->getApplicationHeaders(); +} + }} // namespace qpid::broker diff --git a/qpid/cpp/src/qpid/broker/Message.h b/qpid/cpp/src/qpid/broker/Message.h index a41ecd76be..458c6c7d1a 100644 --- a/qpid/cpp/src/qpid/broker/Message.h +++ b/qpid/cpp/src/qpid/broker/Message.h @@ -73,6 +73,7 @@ public: QPID_BROKER_EXTERN std::string getExchangeName() const; bool isImmediate() const; QPID_BROKER_EXTERN const framing::FieldTable* getApplicationHeaders() const; + framing::FieldTable& getOrInsertHeaders(); QPID_BROKER_EXTERN bool isPersistent(); bool requiresAccept(); diff --git a/qpid/cpp/src/qpid/broker/Queue.cpp b/qpid/cpp/src/qpid/broker/Queue.cpp index 3ae53c8ea9..a1a83926bf 100644 --- a/qpid/cpp/src/qpid/broker/Queue.cpp +++ b/qpid/cpp/src/qpid/broker/Queue.cpp @@ -93,7 +93,8 @@ Queue::Queue(const string& _name, bool _autodelete, policyExceeded(false), mgmtObject(0), eventMode(0), - eventMgr(0) + eventMgr(0), + insertSeqNo(0) { if (parent != 0) { @@ -176,7 +177,7 @@ void Queue::deliver(boost::intrusive_ptr& msg){ void Queue::recover(boost::intrusive_ptr& msg){ - push(msg); + push(msg, true); msg->enqueueComplete(); // mark the message as enqueued mgntEnqStats(msg); @@ -545,12 +546,13 @@ void Queue::popMsg(QueuedMessage& qmsg) ++dequeueTracker; } -void Queue::push(boost::intrusive_ptr& msg){ +void Queue::push(boost::intrusive_ptr& msg, bool isRecovery){ QueueListeners::NotificationSet copy; { Mutex::ScopedLock locker(messageLock); QueuedMessage qm(this, msg, ++sequence); if (policy.get()) policy->tryEnqueue(qm); + if (insertSeqNo) msg->getOrInsertHeaders().setInt64(seqNoKey, sequence); LVQ::iterator i; const framing::FieldTable* ft = msg->getApplicationHeaders(); @@ -566,14 +568,21 @@ void Queue::push(boost::intrusive_ptr& msg){ boost::intrusive_ptr old = i->second->getReplacementMessage(this); if (!old) old = i->second; i->second->setReplacementMessage(msg,this); - dequeued(QueuedMessage(qm.queue, old, qm.position)); + if (isRecovery) { + //can't issue new requests for the store until + //recovery is complete + pendingDequeues.push_back(QueuedMessage(qm.queue, old, qm.position)); + } else { + dequeue(0, QueuedMessage(qm.queue, old, qm.position)); + } } }else { messages.push_back(qm); listeners.populate(copy); } - if (eventMode && eventMgr) { - eventMgr->enqueued(qm); + if (eventMode) { + if (eventMgr) eventMgr->enqueued(qm); + else QPID_LOG(warning, "Enqueue manager not set, events not generated for " << getName()); } } copy.notify(); @@ -664,7 +673,7 @@ bool Queue::enqueue(TransactionContext* ctxt, boost::intrusive_ptr msg) msg->addTraceId(traceId); } - if (msg->isPersistent() && store && !lastValueQueue) { + if (msg->isPersistent() && store) { msg->enqueueAsync(shared_from_this(), store); //increment to async counter -- for message sent to more than one queue boost::intrusive_ptr pmsg = boost::static_pointer_cast(msg); store->enqueue(ctxt, pmsg, *this); @@ -676,14 +685,14 @@ bool Queue::enqueue(TransactionContext* ctxt, boost::intrusive_ptr msg) // return true if store exists, bool Queue::dequeue(TransactionContext* ctxt, const QueuedMessage& msg) { - if (policy.get() && !policy->isEnqueued(msg)) return false; { Mutex::ScopedLock locker(messageLock); + if (policy.get() && !policy->isEnqueued(msg)) return false; if (!ctxt) { dequeued(msg); } } - if (msg.payload->isPersistent() && store && !lastValueQueue) { + if (msg.payload->isPersistent() && store) { msg.payload->dequeueAsync(shared_from_this(), store); //increment to async counter -- for message sent to more than one queue boost::intrusive_ptr pmsg = boost::static_pointer_cast(msg.payload); store->dequeue(ctxt, pmsg, *this); @@ -976,3 +985,16 @@ void Queue::setQueueEventManager(QueueEvents& mgr) { eventMgr = &mgr; } + +void Queue::recoveryComplete() +{ + //process any pending dequeues + for_each(pendingDequeues.begin(), pendingDequeues.end(), boost::bind(&Queue::dequeue, this, (TransactionContext*) 0, _1)); + pendingDequeues.clear(); +} + +void Queue::insertSequenceNumbers(const std::string& key) +{ + seqNoKey = key; + insertSeqNo = !seqNoKey.empty(); +} diff --git a/qpid/cpp/src/qpid/broker/Queue.h b/qpid/cpp/src/qpid/broker/Queue.h index 822e827f35..d1f71581d6 100644 --- a/qpid/cpp/src/qpid/broker/Queue.h +++ b/qpid/cpp/src/qpid/broker/Queue.h @@ -87,6 +87,7 @@ namespace qpid { std::vector traceExclude; QueueListeners listeners; Messages messages; + Messages pendingDequeues;//used to avoid dequeuing during recovery LVQ lvq; mutable qpid::sys::Mutex consumerLock; mutable qpid::sys::Mutex messageLock; @@ -102,8 +103,10 @@ namespace qpid { RateTracker dequeueTracker; int eventMode; QueueEvents* eventMgr; + bool insertSeqNo; + std::string seqNoKey; - void push(boost::intrusive_ptr& msg); + void push(boost::intrusive_ptr& msg, bool isRecovery=false); void setPolicy(std::auto_ptr policy); bool seek(QueuedMessage& msg, Consumer::shared_ptr position); bool getNextMessage(QueuedMessage& msg, Consumer::shared_ptr c); @@ -298,6 +301,11 @@ namespace qpid { void setPosition(framing::SequenceNumber pos); int getEventMode(); void setQueueEventManager(QueueEvents&); + void insertSequenceNumbers(const std::string& key); + /** + * Notify queue that recovery has completed. + */ + void recoveryComplete(); }; } } diff --git a/qpid/cpp/src/qpid/broker/QueueEvents.cpp b/qpid/cpp/src/qpid/broker/QueueEvents.cpp index a6517e1bfe..7525e4cb76 100644 --- a/qpid/cpp/src/qpid/broker/QueueEvents.cpp +++ b/qpid/cpp/src/qpid/broker/QueueEvents.cpp @@ -20,12 +20,13 @@ */ #include "QueueEvents.h" #include "qpid/Exception.h" +#include "qpid/log/Statement.h" namespace qpid { namespace broker { QueueEvents::QueueEvents(const boost::shared_ptr& poller) : - eventQueue(boost::bind(&QueueEvents::handle, this, _1), poller) + eventQueue(boost::bind(&QueueEvents::handle, this, _1), poller), enabled(true) { eventQueue.start(); } @@ -37,12 +38,12 @@ QueueEvents::~QueueEvents() void QueueEvents::enqueued(const QueuedMessage& m) { - eventQueue.push(Event(ENQUEUE, m)); + if (enabled) eventQueue.push(Event(ENQUEUE, m)); } void QueueEvents::dequeued(const QueuedMessage& m) { - eventQueue.push(Event(DEQUEUE, m)); + if (enabled) eventQueue.push(Event(DEQUEUE, m)); } void QueueEvents::registerListener(const std::string& id, const EventListener& listener) @@ -81,6 +82,18 @@ void QueueEvents::shutdown() if (!eventQueue.empty() && !listeners.empty()) eventQueue.shutdown(); } +void QueueEvents::enable() +{ + enabled = true; + QPID_LOG(debug, "Queue events enabled"); +} + +void QueueEvents::disable() +{ + enabled = false; + QPID_LOG(debug, "Queue events disabled"); +} + QueueEvents::Event::Event(EventType t, const QueuedMessage& m) : type(t), msg(m) {} diff --git a/qpid/cpp/src/qpid/broker/QueueEvents.h b/qpid/cpp/src/qpid/broker/QueueEvents.h index 9bb56f888d..82abd3d20a 100644 --- a/qpid/cpp/src/qpid/broker/QueueEvents.h +++ b/qpid/cpp/src/qpid/broker/QueueEvents.h @@ -61,6 +61,8 @@ class QueueEvents QPID_BROKER_EXTERN void registerListener(const std::string& id, const EventListener&); QPID_BROKER_EXTERN void unregisterListener(const std::string& id); + void enable(); + void disable(); //process all outstanding events QPID_BROKER_EXTERN void shutdown(); private: @@ -69,6 +71,7 @@ class QueueEvents EventQueue eventQueue; Listeners listeners; + volatile bool enabled; qpid::sys::Mutex lock;//protect listeners from concurrent access void handle(EventQueue::Queue& e); diff --git a/qpid/cpp/src/qpid/broker/QueuePolicy.cpp b/qpid/cpp/src/qpid/broker/QueuePolicy.cpp index 41a6709d27..c59736969f 100644 --- a/qpid/cpp/src/qpid/broker/QueuePolicy.cpp +++ b/qpid/cpp/src/qpid/broker/QueuePolicy.cpp @@ -126,7 +126,7 @@ std::string QueuePolicy::getType(const FieldTable& settings) FieldTable::ValuePtr v = settings.get(typeKey); if (v && v->convertsTo()) { std::string t = v->get(); - transform(t.begin(), t.end(), t.begin(), tolower); + std::transform(t.begin(), t.end(), t.begin(), tolower); if (t == REJECT || t == FLOW_TO_DISK || t == RING || t == RING_STRICT) return t; } return FLOW_TO_DISK; @@ -197,11 +197,12 @@ void RingQueuePolicy::enqueued(const QueuedMessage& m) void RingQueuePolicy::dequeued(const QueuedMessage& m) { qpid::sys::Mutex::ScopedLock l(lock); - QueuePolicy::dequeued(m); //find and remove m from queue - for (Messages::iterator i = queue.begin(); i != queue.end() && m.position <= i->position; i++) { - if (i->position == m.position) { + for (Messages::iterator i = queue.begin(); i != queue.end(); i++) { + if (i->payload == m.payload) { queue.erase(i); + //now update count and size + QueuePolicy::dequeued(m); break; } } @@ -210,9 +211,11 @@ void RingQueuePolicy::dequeued(const QueuedMessage& m) bool RingQueuePolicy::isEnqueued(const QueuedMessage& m) { qpid::sys::Mutex::ScopedLock l(lock); - //for non-strict ring policy, a message can be dequeued before acked; need to detect this - for (Messages::iterator i = queue.begin(); i != queue.end() && m.position <= i->position; i++) { - if (i->position == m.position) { + //for non-strict ring policy, a message can be replaced (and + //therefore dequeued) before it is accepted or released by + //subscriber; need to detect this + for (Messages::const_iterator i = queue.begin(); i != queue.end(); i++) { + if (i->payload == m.payload) { return true; } } @@ -236,13 +239,10 @@ bool RingQueuePolicy::checkLimit(const QueuedMessage& m) oldest = queue.front(); } if (oldest.queue->acquire(oldest) || !strict) { - qpid::sys::Mutex::ScopedLock l(lock); - if (oldest.position == queue.front().position) { - queue.pop_front(); - QPID_LOG(debug, "Ring policy triggered in queue " - << (m.queue ? m.queue->getName() : std::string("unknown queue")) - << ": removed message " << oldest.position << " to make way for " << m.position); - } + oldest.queue->dequeue(0, oldest); + QPID_LOG(debug, "Ring policy triggered in queue " + << (m.queue ? m.queue->getName() : std::string("unknown queue")) + << ": removed message " << oldest.position << " to make way for " << m.position); return true; } else { QPID_LOG(debug, "Ring policy could not be triggered in queue " diff --git a/qpid/cpp/src/qpid/broker/QueueRegistry.cpp b/qpid/cpp/src/qpid/broker/QueueRegistry.cpp index 2cb801bf83..d079e543c4 100644 --- a/qpid/cpp/src/qpid/broker/QueueRegistry.cpp +++ b/qpid/cpp/src/qpid/broker/QueueRegistry.cpp @@ -19,6 +19,7 @@ * */ #include "QueueRegistry.h" +#include "QueueEvents.h" #include "qpid/log/Statement.h" #include #include @@ -27,7 +28,7 @@ using namespace qpid::broker; using namespace qpid::sys; QueueRegistry::QueueRegistry() : - counter(1), store(0), parent(0), lastNode(false) {} + counter(1), store(0), events(0), parent(0), lastNode(false) {} QueueRegistry::~QueueRegistry(){} @@ -43,7 +44,8 @@ QueueRegistry::declare(const string& declareName, bool durable, if (i == queues.end()) { Queue::shared_ptr queue(new Queue(name, autoDelete, durable ? store : 0, owner, parent)); queues[name] = queue; - if (lastNode) queue->setLastNodeFailure(); + if (lastNode) queue->setLastNodeFailure(); + if (events) queue->setQueueEventManager(*events); return std::pair(queue, true); } else { @@ -105,3 +107,7 @@ void QueueRegistry::updateQueueClusterState(bool _lastNode) lastNode = _lastNode; } +void QueueRegistry::setQueueEvents(QueueEvents* e) +{ + events = e; +} diff --git a/qpid/cpp/src/qpid/broker/QueueRegistry.h b/qpid/cpp/src/qpid/broker/QueueRegistry.h index 07bb550fd4..3c02afedc4 100644 --- a/qpid/cpp/src/qpid/broker/QueueRegistry.h +++ b/qpid/cpp/src/qpid/broker/QueueRegistry.h @@ -32,6 +32,8 @@ namespace qpid { namespace broker { +class QueueEvents; + /** * A registry of queues indexed by queue name. * @@ -90,6 +92,8 @@ class QueueRegistry { */ string generateName(); + void setQueueEvents(QueueEvents*); + /** * Set the store to use. May only be called once. */ @@ -124,6 +128,7 @@ private: mutable qpid::sys::RWlock lock; int counter; MessageStore* store; + QueueEvents* events; management::Manageable* parent; bool lastNode; //used to set mode on queue declare diff --git a/qpid/cpp/src/qpid/broker/RecoveryManagerImpl.cpp b/qpid/cpp/src/qpid/broker/RecoveryManagerImpl.cpp index 8030cf7d0e..5f8b57fa0b 100644 --- a/qpid/cpp/src/qpid/broker/RecoveryManagerImpl.cpp +++ b/qpid/cpp/src/qpid/broker/RecoveryManagerImpl.cpp @@ -149,7 +149,8 @@ RecoverableConfig::shared_ptr RecoveryManagerImpl::recoverConfig(framing::Buffer void RecoveryManagerImpl::recoveryComplete() { - //TODO (finalise binding setup etc) + //notify all queues + queues.eachQueue(boost::bind(&Queue::recoveryComplete, _1)); } bool RecoverableMessageImpl::loadContent(uint64_t available) diff --git a/qpid/cpp/src/qpid/broker/SaslAuthenticator.cpp b/qpid/cpp/src/qpid/broker/SaslAuthenticator.cpp index 736b051945..edc66444ec 100644 --- a/qpid/cpp/src/qpid/broker/SaslAuthenticator.cpp +++ b/qpid/cpp/src/qpid/broker/SaslAuthenticator.cpp @@ -141,21 +141,31 @@ NullAuthenticator::~NullAuthenticator() {} void NullAuthenticator::getMechanisms(Array& mechanisms) { mechanisms.add(boost::shared_ptr(new Str16Value("ANONYMOUS"))); + mechanisms.add(boost::shared_ptr(new Str16Value("PLAIN")));//useful for testing } void NullAuthenticator::start(const string& mechanism, const string& response) { if (mechanism == "PLAIN") { // Old behavior - if (response.size() > 0 && response[0] == (char) 0) { - string temp = response.substr(1); - string::size_type i = temp.find((char)0); - string uid = temp.substr(0, i); - string pwd = temp.substr(i + 1); - i = uid.find_last_of(realm); - if (i == string::npos || i != (uid.size() - 1)) { - uid = str(format("%1%@%2%") % uid % realm); + if (response.size() > 0) { + string uid; + string::size_type i = response.find((char)0); + if (i == 0 && response.size() > 1) { + //no authorization id; use authentication id + i = response.find((char)0, 1); + if (i != string::npos) uid = response.substr(1, i-1); + } else if (i != string::npos) { + //authorization id is first null delimited field + uid = response.substr(0, i); + }//else not a valid SASL PLAIN response, throw error? + if (!uid.empty()) { + //append realm if it has not already been added + i = uid.find(realm); + if (i == string::npos || realm.size() + i < uid.size()) { + uid = str(format("%1%@%2%") % uid % realm); + } + connection.setUserId(uid); } - connection.setUserId(uid); } } else { connection.setUserId("anonymous"); diff --git a/qpid/cpp/src/qpid/broker/SemanticState.cpp b/qpid/cpp/src/qpid/broker/SemanticState.cpp index 4f751e43b7..3c7c6d9afa 100644 --- a/qpid/cpp/src/qpid/broker/SemanticState.cpp +++ b/qpid/cpp/src/qpid/broker/SemanticState.cpp @@ -355,20 +355,12 @@ const std::string nullstring; } void SemanticState::route(intrusive_ptr msg, Deliverable& strategy) { + msg->setTimestamp(getSession().getBroker().getExpiryPolicy()); + std::string exchangeName = msg->getExchangeName(); - //TODO: the following should be hidden behind message (using MessageAdapter or similar) - - if (msg->isA()) { - // Do not replace the delivery-properties.exchange if it is is already set. - // This is used internally (by the cluster) to force the exchange name on a message. - // The client library ensures this is always empty for messages from normal clients. - if (!msg->hasProperties() || msg->getProperties()->getExchange().empty()) - msg->getProperties()->setExchange(exchangeName); - msg->setTimestamp(getSession().getBroker().getExpiryPolicy()); - } - if (!cacheExchange || cacheExchange->getName() != exchangeName){ + if (!cacheExchange || cacheExchange->getName() != exchangeName) cacheExchange = session.getBroker().getExchanges().get(exchangeName); - } + cacheExchange->setProperties(msg); /* verify the userid if specified: */ std::string id = @@ -516,14 +508,16 @@ void SemanticState::ConsumerImpl::setCreditMode() void SemanticState::ConsumerImpl::addByteCredit(uint32_t value) { if (byteCredit != 0xFFFFFFFF) { - byteCredit += value; + if (value == 0xFFFFFFFF) byteCredit = value; + else byteCredit += value; } } void SemanticState::ConsumerImpl::addMessageCredit(uint32_t value) { if (msgCredit != 0xFFFFFFFF) { - msgCredit += value; + if (value == 0xFFFFFFFF) msgCredit = value; + else msgCredit += value; } } diff --git a/qpid/cpp/src/qpid/broker/SessionAdapter.cpp b/qpid/cpp/src/qpid/broker/SessionAdapter.cpp index ae160fabc7..96c47085f0 100644 --- a/qpid/cpp/src/qpid/broker/SessionAdapter.cpp +++ b/qpid/cpp/src/qpid/broker/SessionAdapter.cpp @@ -362,10 +362,6 @@ void SessionAdapter::QueueHandlerImpl::declare(const string& name, const string& getBroker().getExchanges().getDefault()->bind(queue, name, 0); queue->bound(getBroker().getExchanges().getDefault()->getName(), name, arguments); - //if event generation is turned on, pass in a pointer to - //the QueueEvents instance to use - if (queue->getEventMode()) queue->setQueueEventManager(getBroker().getQueueEvents()); - //handle automatic cleanup: if (exclusive) { exclusiveQueues.push_back(queue); diff --git a/qpid/cpp/src/qpid/broker/SessionHandler.cpp b/qpid/cpp/src/qpid/broker/SessionHandler.cpp index 2c4de478f6..442c3eb34b 100644 --- a/qpid/cpp/src/qpid/broker/SessionHandler.cpp +++ b/qpid/cpp/src/qpid/broker/SessionHandler.cpp @@ -34,7 +34,8 @@ using namespace qpid::sys; SessionHandler::SessionHandler(Connection& c, ChannelId ch) : amqp_0_10::SessionHandler(&c.getOutput(), ch), connection(c), - proxy(out) + proxy(out), + clusterOrderProxy(c.getClusterOrderOutput() ? new SetChannelProxy(ch, c.getClusterOrderOutput()) : 0) {} SessionHandler::~SessionHandler() {} @@ -84,11 +85,23 @@ void SessionHandler::readyToSend() { if (session.get()) session->readyToSend(); } -// TODO aconway 2008-05-12: hacky - handle attached for bridge clients. -// We need to integrate the client code so we can run a real client -// in the bridge. -// -void SessionHandler::attached(const std::string& name) { +/** + * Used by inter-broker bridges to set up session id and attach + */ +void SessionHandler::attachAs(const std::string& name) +{ + SessionId id(connection.getUserId(), name); + SessionState::Configuration config = connection.broker.getSessionManager().getSessionConfig(); + session.reset(new SessionState(connection.getBroker(), *this, id, config)); + sendAttach(false); +} + +/** + * TODO: this is a little ugly, fix it; its currently still relied on + * for 'push' bridges + */ +void SessionHandler::attached(const std::string& name) +{ if (session.get()) { amqp_0_10::SessionHandler::attached(name); } else { diff --git a/qpid/cpp/src/qpid/broker/SessionHandler.h b/qpid/cpp/src/qpid/broker/SessionHandler.h index 7449db1560..ffc032f64c 100644 --- a/qpid/cpp/src/qpid/broker/SessionHandler.h +++ b/qpid/cpp/src/qpid/broker/SessionHandler.h @@ -54,10 +54,20 @@ class SessionHandler : public amqp_0_10::SessionHandler { framing::AMQP_ClientProxy& getProxy() { return proxy; } const framing::AMQP_ClientProxy& getProxy() const { return proxy; } + /** + * If commands are sent based on the local time (e.g. in timers), they don't have + * a well-defined ordering across cluster nodes. + * This proxy is for sending such commands. In a clustered broker it will take steps + * to synchronize command order across the cluster. In a stand-alone broker + * it is just a synonym for getProxy() + */ + framing::AMQP_ClientProxy& getClusterOrderProxy() { + return clusterOrderProxy.get() ? *clusterOrderProxy : proxy; + } + virtual void handleDetach(); - - // Overrides - void attached(const std::string& name); + void attached(const std::string& name);//used by 'pushing' inter-broker bridges + void attachAs(const std::string& name);//used by 'pulling' inter-broker bridges protected: virtual void setState(const std::string& sessionName, bool force); @@ -69,9 +79,16 @@ class SessionHandler : public amqp_0_10::SessionHandler { virtual void readyToSend(); private: + struct SetChannelProxy : public framing::AMQP_ClientProxy { // Proxy that sets the channel. + framing::ChannelHandler setChannel; + SetChannelProxy(uint16_t ch, framing::FrameHandler* out) + : framing::AMQP_ClientProxy(setChannel), setChannel(ch, out) {} + }; + Connection& connection; framing::AMQP_ClientProxy proxy; std::auto_ptr session; + std::auto_ptr clusterOrderProxy; }; }} // namespace qpid::broker diff --git a/qpid/cpp/src/qpid/broker/SessionState.cpp b/qpid/cpp/src/qpid/broker/SessionState.cpp index dffc7cf6af..7e5f605753 100644 --- a/qpid/cpp/src/qpid/broker/SessionState.cpp +++ b/qpid/cpp/src/qpid/broker/SessionState.cpp @@ -66,7 +66,7 @@ SessionState::SessionState( uint32_t maxRate = broker.getOptions().maxSessionRate; if (maxRate) { if (handler->getConnection().getClientThrottling()) { - rateFlowcontrol = new RateFlowcontrol(maxRate); + rateFlowcontrol.reset(new RateFlowcontrol(maxRate)); } else { QPID_LOG(warning, getId() << ": Unable to flow control client - client doesn't support"); } @@ -210,14 +210,17 @@ struct ScheduledCreditTask : public TimerTask { {} void fire() { - QPID_LOG(critical, "ScheduledCreditTask fired"); // FIXME aconway 2009-02-23: REMOVE // This is the best we can currently do to avoid a destruction/fire race if (!isCancelled()) { - if ( !sessionState.processSendCredit(0) ) { - QPID_LOG(warning, sessionState.getId() << ": Reschedule sending credit"); - reset(); - timer.add(this); - } + sessionState.getConnection().requestIOProcessing(boost::bind(&ScheduledCreditTask::sendCredit, this)); + } + } + + void sendCredit() { + if ( !sessionState.processSendCredit(0) ) { + QPID_LOG(warning, sessionState.getId() << ": Reschedule sending credit"); + reset(); + timer.add(this); } } }; @@ -275,7 +278,8 @@ bool SessionState::processSendCredit(uint32_t msgs) if ( msgs > 0 && rateFlowcontrol->flowStopped() ) { QPID_LOG(warning, getId() << ": producer throttling violation"); // TODO: Probably do message.stop("") first time then disconnect - getProxy().getMessage().stop(""); + // See comment on getClusterOrderProxy() in .h file + getClusterOrderProxy().getMessage().stop(""); return true; } AbsTime now = AbsTime::now(); @@ -283,7 +287,7 @@ bool SessionState::processSendCredit(uint32_t msgs) if (mgmtObject) mgmtObject->dec_clientCredit(msgs); if ( sendCredit>0 ) { QPID_LOG(debug, getId() << ": send producer credit " << sendCredit); - getProxy().getMessage().flow("", 0, sendCredit); + getClusterOrderProxy().getMessage().flow("", 0, sendCredit); rateFlowcontrol->sentCredit(now, sendCredit); if (mgmtObject) mgmtObject->inc_clientCredit(sendCredit); return true; @@ -364,8 +368,9 @@ void SessionState::readyToSend() { // Issue initial credit - use a heuristic here issue min of 300 messages or 1 secs worth uint32_t credit = std::min(rateFlowcontrol->getRate(), 300U); QPID_LOG(debug, getId() << ": Issuing producer message credit " << credit); - getProxy().getMessage().setFlowMode("", 0); - getProxy().getMessage().flow("", 0, credit); + // See comment on getClusterOrderProxy() in .h file + getClusterOrderProxy().getMessage().setFlowMode("", 0); + getClusterOrderProxy().getMessage().flow("", 0, credit); rateFlowcontrol->sentCredit(AbsTime::now(), credit); if (mgmtObject) mgmtObject->inc_clientCredit(credit); } @@ -373,4 +378,8 @@ void SessionState::readyToSend() { Broker& SessionState::getBroker() { return broker; } +framing::AMQP_ClientProxy& SessionState::getClusterOrderProxy() { + return handler->getClusterOrderProxy(); +} + }} // namespace qpid::broker diff --git a/qpid/cpp/src/qpid/broker/SessionState.h b/qpid/cpp/src/qpid/broker/SessionState.h index 1b7f2420a9..bdfed87905 100644 --- a/qpid/cpp/src/qpid/broker/SessionState.h +++ b/qpid/cpp/src/qpid/broker/SessionState.h @@ -125,6 +125,15 @@ class SessionState : public qpid::SessionState, void sendAcceptAndCompletion(); + /** + * If commands are sent based on the local time (e.g. in timers), they don't have + * a well-defined ordering across cluster nodes. + * This proxy is for sending such commands. In a clustered broker it will take steps + * to synchronize command order across the cluster. In a stand-alone broker + * it is just a synonym for getProxy() + */ + framing::AMQP_ClientProxy& getClusterOrderProxy(); + Broker& broker; SessionHandler* handler; sys::AbsTime expiry; // Used by SessionManager. @@ -138,7 +147,7 @@ class SessionState : public qpid::SessionState, // State used for producer flow control (rate limited) qpid::sys::Mutex rateLock; - RateFlowcontrol* rateFlowcontrol; + boost::scoped_ptr rateFlowcontrol; boost::intrusive_ptr flowControlTimer; friend class SessionManager; diff --git a/qpid/cpp/src/qpid/broker/TxAccept.cpp b/qpid/cpp/src/qpid/broker/TxAccept.cpp index c7001e5526..73f365d509 100644 --- a/qpid/cpp/src/qpid/broker/TxAccept.cpp +++ b/qpid/cpp/src/qpid/broker/TxAccept.cpp @@ -50,12 +50,12 @@ void TxAccept::RangeOps::operator()(SequenceNumber start, SequenceNumber end) void TxAccept::RangeOps::prepare(TransactionContext* ctxt) { - for_each(ranges.begin(), ranges.end(), bind(&RangeOp::prepare, _1, ctxt)); + std::for_each(ranges.begin(), ranges.end(), bind(&RangeOp::prepare, _1, ctxt)); } void TxAccept::RangeOps::commit() { - for_each(ranges.begin(), ranges.end(), bind(&RangeOp::commit, _1)); + std::for_each(ranges.begin(), ranges.end(), bind(&RangeOp::commit, _1)); //now remove if isRedundant(): if (!ranges.empty()) { ack_iterator i = ranges.front().range.start; diff --git a/qpid/cpp/src/qpid/client/ConnectionImpl.cpp b/qpid/cpp/src/qpid/client/ConnectionImpl.cpp index 8e27d78479..745bdb63b5 100644 --- a/qpid/cpp/src/qpid/client/ConnectionImpl.cpp +++ b/qpid/cpp/src/qpid/client/ConnectionImpl.cpp @@ -180,6 +180,9 @@ void ConnectionImpl::close() template void ConnectionImpl::closeInternal(const F& f) { + if (heartbeatTask) { + heartbeatTask->cancel(); + } { Mutex::ScopedUnlock u(lock); connector->close(); diff --git a/qpid/cpp/src/qpid/client/Connector.cpp b/qpid/cpp/src/qpid/client/Connector.cpp index e6355601df..c251233082 100644 --- a/qpid/cpp/src/qpid/client/Connector.cpp +++ b/qpid/cpp/src/qpid/client/Connector.cpp @@ -92,8 +92,6 @@ class TCPConnector : public Connector, public sys::Codec, private sys::Runnable framing::ProtocolVersion version; bool initiated; - - sys::Mutex closedLock; bool closed; bool joined; @@ -185,7 +183,7 @@ TCPConnector::~TCPConnector() { } void TCPConnector::connect(const std::string& host, int port){ - Mutex::ScopedLock l(closedLock); + Mutex::ScopedLock l(lock); assert(closed); try { socket.connect(host, port); @@ -207,7 +205,7 @@ void TCPConnector::connect(const std::string& host, int port){ } void TCPConnector::init(){ - Mutex::ScopedLock l(closedLock); + Mutex::ScopedLock l(lock); assert(joined); ProtocolInitiation init(version); writeDataBlock(init); @@ -216,17 +214,21 @@ void TCPConnector::init(){ } bool TCPConnector::closeInternal() { - Mutex::ScopedLock l(closedLock); - bool ret = !closed; + bool ret; + { + Mutex::ScopedLock l(lock); + ret = !closed; if (!closed) { closed = true; + aio->queueForDeletion(); poller->shutdown(); } - if (!joined && receiver.id() != Thread::current().id()) { - joined = true; - Mutex::ScopedUnlock u(closedLock); - receiver.join(); + if (joined || receiver.id() == Thread::current().id()) { + return ret; } + joined = true; + } + receiver.join(); return ret; } @@ -259,21 +261,19 @@ const std::string& TCPConnector::getIdentifier() const { } void TCPConnector::send(AMQFrame& frame) { + Mutex::ScopedLock l(lock); + frames.push_back(frame); + //only ask to write if this is the end of a frameset or if we + //already have a buffers worth of data + currentSize += frame.encodedSize(); bool notifyWrite = false; - { - Mutex::ScopedLock l(lock); - frames.push_back(frame); - //only ask to write if this is the end of a frameset or if we - //already have a buffers worth of data - currentSize += frame.encodedSize(); - if (frame.getEof()) { - lastEof = frames.size(); - notifyWrite = true; - } else { - notifyWrite = (currentSize >= maxFrameSize); - } + if (frame.getEof()) { + lastEof = frames.size(); + notifyWrite = true; + } else { + notifyWrite = (currentSize >= maxFrameSize); } - if (notifyWrite) aio->notifyPendingWrite(); + if (notifyWrite && !closed) aio->notifyPendingWrite(); } void TCPConnector::handleClosed() { @@ -384,14 +384,13 @@ void TCPConnector::run() { assert(protect); try { Dispatcher d(poller); - + for (int i = 0; i < 32; i++) { aio->queueReadBuffer(new Buff(maxFrameSize)); } - + aio->start(poller); d.run(); - aio->queueForDeletion(); socket.close(); } catch (const std::exception& e) { QPID_LOG(error, QPID_MSG("FAIL " << identifier << ": " << e.what())); diff --git a/qpid/cpp/src/qpid/client/Dispatcher.cpp b/qpid/cpp/src/qpid/client/Dispatcher.cpp index 27cc4184f9..8d8574520a 100644 --- a/qpid/cpp/src/qpid/client/Dispatcher.cpp +++ b/qpid/cpp/src/qpid/client/Dispatcher.cpp @@ -136,8 +136,7 @@ void Dispatcher::listen(const boost::intrusive_ptr& subscripti void Dispatcher::cancel(const std::string& destination) { ScopedLock l(lock); - listeners.erase(destination); - if (autoStop && listeners.empty()) + if (listeners.erase(destination) && running && autoStop && listeners.empty()) queue->close(); } diff --git a/qpid/cpp/src/qpid/client/FailoverManager.cpp b/qpid/cpp/src/qpid/client/FailoverManager.cpp index ab9dbca70f..86b50a0a61 100644 --- a/qpid/cpp/src/qpid/client/FailoverManager.cpp +++ b/qpid/cpp/src/qpid/client/FailoverManager.cpp @@ -21,12 +21,15 @@ #include "FailoverManager.h" #include "qpid/Exception.h" #include "qpid/log/Statement.h" +#include "qpid/sys/Time.h" namespace qpid { namespace client { using qpid::sys::Monitor; +using qpid::sys::AbsTime; +using qpid::sys::Duration; FailoverManager::FailoverManager(const ConnectionSettings& s, ReconnectionStrategy* rs) : settings(s), strategy(rs), state(IDLE) {} @@ -35,15 +38,21 @@ void FailoverManager::execute(Command& c) { bool retry = false; bool completed = false; + AbsTime failed; while (!completed) { try { AsyncSession session = connect().newSession(); + if (retry) { + Duration failoverTime(failed, AbsTime::now()); + QPID_LOG(info, "Failed over for " << &c << " in " << (failoverTime/qpid::sys::TIME_MSEC) << " milliseconds"); + } c.execute(session, retry); session.sync();//TODO: shouldn't be required session.close(); completed = true; } catch(const TransportFailure&) { - retry = true; + retry = true; + failed = AbsTime::now(); } } } diff --git a/qpid/cpp/src/qpid/client/SessionImpl.cpp b/qpid/cpp/src/qpid/client/SessionImpl.cpp index ee542a9cf8..5df376efa0 100644 --- a/qpid/cpp/src/qpid/client/SessionImpl.cpp +++ b/qpid/cpp/src/qpid/client/SessionImpl.cpp @@ -512,6 +512,7 @@ void SessionImpl::detach(const std::string& _name) if (id.getName() != _name) throw InternalErrorException("Incorrect session name"); setState(DETACHED); QPID_LOG(info, "Session detached by peer: " << id); + proxy.detached(_name, DETACH_CODE_NORMAL); } void SessionImpl::detached(const std::string& _name, uint8_t _code) { @@ -744,7 +745,8 @@ void SessionImpl::assertOpen() const void SessionImpl::handleClosed() { - demux.close(exceptionHolder.empty() ? new ClosedException() : exceptionHolder); + demux.close(exceptionHolder.empty() ? + sys::ExceptionHolder(new ClosedException()) : exceptionHolder); results.close(); } diff --git a/qpid/cpp/src/qpid/client/SslConnector.cpp b/qpid/cpp/src/qpid/client/SslConnector.cpp index 75c3f5677e..a4298dd4ca 100644 --- a/qpid/cpp/src/qpid/client/SslConnector.cpp +++ b/qpid/cpp/src/qpid/client/SslConnector.cpp @@ -221,6 +221,7 @@ bool SslConnector::closeInternal() { bool ret = !closed; if (!closed) { closed = true; + aio->queueForDeletion(); poller->shutdown(); } if (!joined && receiver.id() != Thread::current().id()) { @@ -386,7 +387,6 @@ void SslConnector::run(){ aio->start(poller); d.run(); - aio->queueForDeletion(); socket.close(); } catch (const std::exception& e) { QPID_LOG(error, e.what()); diff --git a/qpid/cpp/src/qpid/cluster/Cluster.cpp b/qpid/cpp/src/qpid/cluster/Cluster.cpp index 6221b0054c..f8e412f1e6 100644 --- a/qpid/cpp/src/qpid/cluster/Cluster.cpp +++ b/qpid/cpp/src/qpid/cluster/Cluster.cpp @@ -21,7 +21,9 @@ #include "Connection.h" #include "UpdateClient.h" #include "FailoverExchange.h" +#include "UpdateExchange.h" +#include "qpid/assert.h" #include "qmf/org/apache/qpid/cluster/ArgsClusterStopClusterNode.h" #include "qmf/org/apache/qpid/cluster/Package.h" #include "qpid/broker/Broker.h" @@ -91,9 +93,10 @@ Cluster::Cluster(const ClusterSettings& set, broker::Broker& b) : cpg(*this), name(settings.name), myUrl(settings.url.empty() ? Url() : Url(settings.url)), - myId(cpg.self()), + self(cpg.self()), readMax(settings.readMax), writeEstimate(settings.writeEstimate), + expiryPolicy(new ExpiryPolicy(mcast, self, broker.getTimer())), mcast(cpg, poller, boost::bind(&Cluster::leave, this)), dispatcher(cpg, poller, boost::bind(&Cluster::leave, this)), deliverEventQueue(boost::bind(&Cluster::deliveredEvent, this, _1), @@ -104,15 +107,12 @@ Cluster::Cluster(const ClusterSettings& set, broker::Broker& b) : boost::bind(&Cluster::leave, this), "Error delivering frames", poller), - connections(*this), - decoder(boost::bind(&PollableFrameQueue::push, &deliverFrameQueue, _1), connections), - expiryPolicy(new ExpiryPolicy(boost::bind(&Cluster::isLeader, this), mcast, myId, broker.getTimer())), - frameId(0), initialized(false), + decoder(boost::bind(&Cluster::deliverFrame, this, _1)), + discarding(true), state(INIT), lastSize(0), - lastBroker(false), - sequence(0) + lastBroker(false) { mAgent = ManagementAgent::Singleton::getInstance(); if (mAgent != 0){ @@ -122,7 +122,13 @@ Cluster::Cluster(const ClusterSettings& set, broker::Broker& b) : mgmtObject->set_status("JOINING"); } + // Failover exchange provides membership updates to clients. failoverExchange.reset(new FailoverExchange(this)); + broker.getExchanges().registerExchange(failoverExchange); + + // Update exchange is used during updates to replicate messages without modifying delivery-properties.exchange. + broker.getExchanges().registerExchange(boost::shared_ptr(new UpdateExchange(this))); + if (settings.quorum) quorum.init(); cpg.join(name); // pump the CPG dispatch manually till we get initialized. @@ -149,21 +155,21 @@ void Cluster::initialize() { // Called in connection thread to insert a client connection. void Cluster::addLocalConnection(const boost::intrusive_ptr& c) { - Lock l(lock); - connections.insert(c); + localConnections.insert(c); } // Called in connection thread to insert an updated shadow connection. void Cluster::addShadowConnection(const boost::intrusive_ptr& c) { - Lock l(lock); - assert(state <= UPDATEE); // Only during update. - connections.insert(c); + // Safe to use connections here because we're pre-catchup, either + // discarding or stalled, so deliveredFrame is not processing any + // connection events. + assert(discarding); + connections.insert(ConnectionMap::value_type(c->getId(), c)); } +// Called by Connection::deliverClose() in deliverFrameQueue thread. void Cluster::erase(const ConnectionId& id) { - // Called only by Connection::deliverClose in deliver thread, no need to lock. connections.erase(id); - decoder.erase(id); } std::vector Cluster::getIds() const { @@ -193,7 +199,6 @@ void Cluster::leave(Lock&) { if (state != LEFT) { state = LEFT; QPID_LOG(notice, *this << " leaving cluster " << name); - connections.clear(); try { broker.shutdown(); } catch (const std::exception& e) { QPID_LOG(critical, *this << " error during broker shutdown: " << e.what()); @@ -213,52 +218,88 @@ void Cluster::deliver( MemberId from(nodeid, pid); framing::Buffer buf(static_cast(msg), msg_len); Event e(Event::decodeCopy(from, buf)); - e.setSequence(sequence++); - if (from == myId) // Record self-deliveries for flow control. + if (from == self) // Record self-deliveries for flow control. mcast.selfDeliver(e); - deliver(e); + deliverEvent(e); } -void Cluster::deliver(const Event& e) { - if (state == LEFT) return; - QPID_LATENCY_INIT(e); +void Cluster::deliverEvent(const Event& e) { deliverEventQueue.push(e); } -// Handler for deliverEventQueue +void Cluster::deliverFrame(const EventFrame& e) { + deliverFrameQueue.push(e); +} + +// Handler for deliverEventQueue. +// This thread decodes frames from events. void Cluster::deliveredEvent(const Event& e) { - QPID_LATENCY_RECORD("delivered event queue", e); - Buffer buf(const_cast(e.getData()), e.getSize()); - if (e.getType() == CONTROL) { - AMQFrame frame; - while (frame.decode(buf)) - deliverFrameQueue.push(EventFrame(e, frame)); + QPID_LOG(trace, *this << " DLVR: " << e); + if (e.isCluster()) { + EventFrame ef(e, e.getFrame()); + // Stop the deliverEventQueue on update offers. + // This preserves the connection decoder fragments for an update. + ClusterUpdateOfferBody* offer = dynamic_cast(ef.frame.getBody()); + if (offer) + deliverEventQueue.stop(); + deliverFrame(ef); } - else if (e.getType() == DATA) - decoder.decode(e, e.getData()); + else if(!discarding) { + if (e.isControl()) + deliverFrame(EventFrame(e, e.getFrame())); + else + decoder.decode(e, e.getData()); +} + else // Discard connection events if discarding is set. + QPID_LOG(trace, *this << " DROP: " << e); } -// Handler for deliverFrameQueue +// Handler for deliverFrameQueue. +// This thread executes the main logic. void Cluster::deliveredFrame(const EventFrame& e) { Mutex::ScopedLock l(lock); - const_cast(e.frame).setClusterId(frameId++); - QPID_LOG(trace, *this << " DLVR: " << e); - QPID_LATENCY_RECORD("delivered frame queue", e.frame); - if (e.isCluster()) { // Cluster control frame + if (e.isCluster()) { + QPID_LOG(trace, *this << " DLVR: " << e); ClusterDispatcher dispatch(*this, e.connectionId.getMember(), l); if (!framing::invoke(dispatch, *e.frame.getBody()).wasHandled()) throw Exception(QPID_MSG("Invalid cluster control")); } - else { // Connection frame. - if (state <= UPDATEE) { - QPID_LOG(trace, *this << " DROP: " << e); - return; - } - boost::intrusive_ptr connection = connections.get(e.connectionId); - if (connection) // Ignore frames to closed local connections. + else if (state >= CATCHUP) { + QPID_LOG(trace, *this << " DLVR: " << e); + ConnectionPtr connection = getConnection(e.connectionId, l); + if (connection) connection->deliveredFrame(e); } - QPID_LATENCY_RECORD("processed", e.frame); + else // Drop connection frames while state < CATCHUP + QPID_LOG(trace, *this << " DROP: " << e); +} + +// Called in deliverFrameQueue thread +ConnectionPtr Cluster::getConnection(const ConnectionId& id, Lock&) { + ConnectionPtr cp; + ConnectionMap::iterator i = connections.find(id); + if (i != connections.end()) + cp = i->second; + else { + if(id.getMember() == self) + cp = localConnections.getErase(id); + else { + // New remote connection, create a shadow. + std::ostringstream mgmtId; + mgmtId << id; + cp = new Connection(*this, shadowOut, mgmtId.str(), id); + } + if (cp) + connections.insert(ConnectionMap::value_type(id, cp)); + } + return cp; +} + +Cluster::ConnectionVector Cluster::getConnections(Lock&) { + ConnectionVector result(connections.size()); + std::transform(connections.begin(), connections.end(), result.begin(), + boost::bind(&ConnectionMap::value_type::second, _1)); + return result; } struct AddrList { @@ -306,42 +347,45 @@ void Cluster::configChange ( std::string addresses; for (cpg_address* p = current; p < current+nCurrent; ++p) addresses.append(MemberId(*p).str()); - deliver(Event::control(ClusterConfigChangeBody(ProtocolVersion(), addresses), myId)); + deliverEvent(Event::control(ClusterConfigChangeBody(ProtocolVersion(), addresses), self)); } void Cluster::setReady(Lock&) { state = READY; if (mgmtObject!=0) mgmtObject->set_status("ACTIVE"); mcast.release(); + broker.getQueueEvents().enable(); } void Cluster::configChange(const MemberId&, const std::string& addresses, Lock& l) { bool memberChange = map.configChange(addresses); if (state == LEFT) return; - if (!map.isAlive(myId)) { // Final config change. + if (!map.isAlive(self)) { // Final config change. leave(l); return; } if (state == INIT) { // First configChange if (map.aliveCount() == 1) { - setClusterId(true); + setClusterId(true, l); + discarding = false; setReady(l); - map = ClusterMap(myId, myUrl, true); + map = ClusterMap(self, myUrl, true); memberUpdate(l); QPID_LOG(notice, *this << " first in cluster"); } else { // Joining established group. state = JOINER; QPID_LOG(info, *this << " joining cluster: " << map); - mcast.mcastControl(ClusterUpdateRequestBody(ProtocolVersion(), myUrl.str()), myId); + mcast.mcastControl(ClusterUpdateRequestBody(ProtocolVersion(), myUrl.str()), self); elders = map.getAlive(); - elders.erase(myId); + elders.erase(self); broker.getLinks().setPassive(true); + broker.getQueueEvents().disable(); } - } - else if (state >= READY && memberChange) { + } + else if (state >= CATCHUP && memberChange) { memberUpdate(l); elders = ClusterMap::intersection(elders, map.getAlive()); if (elders.empty()) { @@ -351,13 +395,11 @@ void Cluster::configChange(const MemberId&, const std::string& addresses, Lock& } } -bool Cluster::isLeader() const { return elders.empty(); } - -void Cluster::tryMakeOffer(const MemberId& id, Lock& ) { +void Cluster::makeOffer(const MemberId& id, Lock& ) { if (state == READY && map.isJoiner(id)) { state = OFFER; QPID_LOG(info, *this << " send update-offer to " << id); - mcast.mcastControl(ClusterUpdateOfferBody(ProtocolVersion(), id, clusterId), myId); + mcast.mcastControl(ClusterUpdateOfferBody(ProtocolVersion(), id, clusterId), self); } } @@ -367,88 +409,89 @@ void Cluster::tryMakeOffer(const MemberId& id, Lock& ) { // callbacks will be invoked. // void Cluster::brokerShutdown() { - if (state != LEFT) { - try { cpg.shutdown(); } - catch (const std::exception& e) { - QPID_LOG(error, *this << " shutting down CPG: " << e.what()); - } + try { cpg.shutdown(); } + catch (const std::exception& e) { + QPID_LOG(error, *this << " shutting down CPG: " << e.what()); } delete this; } void Cluster::updateRequest(const MemberId& id, const std::string& url, Lock& l) { map.updateRequest(id, url); - tryMakeOffer(id, l); + makeOffer(id, l); } void Cluster::ready(const MemberId& id, const std::string& url, Lock& l) { if (map.ready(id, Url(url))) memberUpdate(l); - if (state == CATCHUP && id == myId) { + if (state == CATCHUP && id == self) { setReady(l); QPID_LOG(notice, *this << " caught up, active cluster member"); } } void Cluster::updateOffer(const MemberId& updater, uint64_t updateeInt, const Uuid& uuid, Lock& l) { + // NOTE: deliverEventQueue has been stopped at the update offer by + // deliveredEvent in case an update is required. if (state == LEFT) return; MemberId updatee(updateeInt); boost::optional url = map.updateOffer(updater, updatee); - if (updater == myId) { + if (updater == self) { assert(state == OFFER); - if (url) { // My offer was first. + if (url) // My offer was first. updateStart(updatee, *url, l); - } else { // Another offer was first. + deliverEventQueue.start(); // Don't need to update setReady(l); QPID_LOG(info, *this << " cancelled update offer to " << updatee); - tryMakeOffer(map.firstJoiner(), l); // Maybe make another offer. + makeOffer(map.firstJoiner(), l); // Maybe make another offer. } } - else if (updatee == myId && url) { + else if (updatee == self && url) { assert(state == JOINER); - setClusterId(uuid); + setClusterId(uuid, l); state = UPDATEE; QPID_LOG(info, *this << " receiving update from " << updater); - deliverFrameQueue.stop(); checkUpdateIn(l); } + else + deliverEventQueue.start(); // Don't need to update } -void Cluster::updateStart(const MemberId& updatee, const Url& url, Lock&) { +void Cluster::updateStart(const MemberId& updatee, const Url& url, Lock& l) { + // NOTE: deliverEventQueue is already stopped at the stall point by deliveredEvent. if (state == LEFT) return; assert(state == OFFER); state = UPDATER; - QPID_LOG(info, *this << " stall for update to " << updatee << " at " << url); - deliverFrameQueue.stop(); - if (updateThread.id()) updateThread.join(); // Join the previous updatethread. + QPID_LOG(info, *this << " sending update to " << updatee << " at " << url); + if (updateThread.id()) + updateThread.join(); // Join the previous updateThread to avoid leaks. client::ConnectionSettings cs; cs.username = settings.username; cs.password = settings.password; cs.mechanism = settings.mechanism; updateThread = Thread( - new UpdateClient(myId, updatee, url, broker, map, frameId, connections.values(), + new UpdateClient(self, updatee, url, broker, map, *expiryPolicy, getConnections(l), decoder, boost::bind(&Cluster::updateOutDone, this), boost::bind(&Cluster::updateOutError, this, _1), cs)); } // Called in update thread. -void Cluster::updateInDone(const ClusterMap& m, uint64_t fid) { +void Cluster::updateInDone(const ClusterMap& m) { Lock l(lock); updatedMap = m; - frameId = fid; checkUpdateIn(l); } -void Cluster::checkUpdateIn(Lock& ) { - if (state == LEFT) return; +void Cluster::checkUpdateIn(Lock&) { if (state == UPDATEE && updatedMap) { map = *updatedMap; - mcast.mcastControl(ClusterReadyBody(ProtocolVersion(), myUrl.str()), myId); + mcast.mcastControl(ClusterReadyBody(ProtocolVersion(), myUrl.str()), self); state = CATCHUP; + discarding = false; // ok to set, we're stalled for update. QPID_LOG(info, *this << " received update, starting catch-up"); - deliverFrameQueue.start(); + deliverEventQueue.start(); } } @@ -462,8 +505,8 @@ void Cluster::updateOutDone(Lock& l) { assert(state == UPDATER); state = READY; mcast.release(); - deliverFrameQueue.start(); - tryMakeOffer(map.firstJoiner(), l); // Try another offer + deliverEventQueue.start(); // Start processing events again. + makeOffer(map.firstJoiner(), l); // Try another offer } void Cluster::updateOutError(const std::exception& e) { @@ -487,7 +530,7 @@ Manageable::status_t Cluster::ManagementMethod (uint32_t methodId, Args& args, s { _qmf::ArgsClusterStopClusterNode& iargs = (_qmf::ArgsClusterStopClusterNode&) args; stringstream stream; - stream << myId; + stream << self; if (iargs.i_brokerId == stream.str()) stopClusterNode(l); } @@ -508,7 +551,7 @@ void Cluster::stopClusterNode(Lock& l) { void Cluster::stopFullCluster(Lock& ) { QPID_LOG(notice, *this << " shutting down cluster " << name); - mcast.mcastControl(ClusterShutdownBody(), myId); + mcast.mcastControl(ClusterShutdownBody(), self); } void Cluster::memberUpdate(Lock& l) { @@ -518,13 +561,13 @@ void Cluster::memberUpdate(Lock& l) { size_t size = urls.size(); failoverExchange->setUrls(urls); - if (size == 1 && lastSize > 1 && state >= READY) { - QPID_LOG(info, *this << " last broker standing, update queue policies"); + if (size == 1 && lastSize > 1 && state >= CATCHUP) { + QPID_LOG(notice, *this << " last broker standing, update queue policies"); lastBroker = true; broker.getQueues().updateQueueClusterState(true); } else if (size > 1 && lastBroker) { - QPID_LOG(info, *this << " last broker standing joined by " << size-1 << " replicas, updating queue policies" << size); + QPID_LOG(notice, *this << " last broker standing joined by " << size-1 << " replicas, updating queue policies" << size); lastBroker = false; broker.getQueues().updateQueueClusterState(false); } @@ -546,17 +589,23 @@ void Cluster::memberUpdate(Lock& l) { mgmtObject->set_memberIDs(idstr); } - // Close connections belonging to members that have now been excluded - connections.update(myId, map); + // Erase connections belonging to members that have left the cluster. + ConnectionMap::iterator i = connections.begin(); + while (i != connections.end()) { + ConnectionMap::iterator j = i++; + MemberId m = j->second->getId().getMember(); + if (m != self && !map.isMember(m)) + connections.erase(j); + } } std::ostream& operator<<(std::ostream& o, const Cluster& cluster) { static const char* STATE[] = { "INIT", "JOINER", "UPDATEE", "CATCHUP", "READY", "OFFER", "UPDATER", "LEFT" }; - return o << cluster.myId << "(" << STATE[cluster.state] << ")"; + return o << cluster.self << "(" << STATE[cluster.state] << ")"; } MemberId Cluster::getId() const { - return myId; // Immutable, no need to lock. + return self; // Immutable, no need to lock. } broker::Broker& Cluster::getBroker() const { @@ -571,11 +620,11 @@ void Cluster::checkQuorum() { } } -void Cluster::setClusterId(const Uuid& uuid) { +void Cluster::setClusterId(const Uuid& uuid, Lock&) { clusterId = uuid; if (mgmtObject) { stringstream stream; - stream << myId; + stream << self; mgmtObject->set_clusterID(clusterId.str()); mgmtObject->set_memberID(stream.str()); } diff --git a/qpid/cpp/src/qpid/cluster/Cluster.h b/qpid/cpp/src/qpid/cluster/Cluster.h index 8c5eb06ff7..b716e2d781 100644 --- a/qpid/cpp/src/qpid/cluster/Cluster.h +++ b/qpid/cpp/src/qpid/cluster/Cluster.h @@ -19,34 +19,34 @@ * */ -#include "ClusterSettings.h" #include "ClusterMap.h" -#include "ConnectionMap.h" +#include "ClusterSettings.h" #include "Cpg.h" +#include "Decoder.h" #include "Event.h" +#include "EventFrame.h" +#include "ExpiryPolicy.h" #include "FailoverExchange.h" +#include "LockedConnectionMap.h" #include "Multicaster.h" -#include "EventFrame.h" #include "NoOpConnectionOutputHandler.h" +#include "PollableQueue.h" #include "PollerDispatch.h" #include "Quorum.h" -#include "Decoder.h" -#include "PollableQueue.h" -#include "ExpiryPolicy.h" +#include "qmf/org/apache/qpid/cluster/Cluster.h" +#include "qpid/Url.h" #include "qpid/broker/Broker.h" -#include "qpid/sys/Monitor.h" #include "qpid/management/Manageable.h" -#include "qpid/Url.h" -#include "qmf/org/apache/qpid/cluster/Cluster.h" +#include "qpid/sys/Monitor.h" -#include #include +#include #include #include -#include #include +#include namespace qpid { @@ -58,6 +58,7 @@ class Uuid; namespace cluster { class Connection; +class EventFrame; /** * Connection to the cluster @@ -65,82 +66,91 @@ class Connection; class Cluster : private Cpg::Handler, public management::Manageable { public: typedef boost::intrusive_ptr ConnectionPtr; - typedef std::vector Connections; + typedef std::vector ConnectionVector; - /** Construct the cluster in plugin earlyInitialize */ + // Public functions are thread safe unless otherwise mentioned in a comment. + + // Construct the cluster in plugin earlyInitialize. Cluster(const ClusterSettings&, broker::Broker&); virtual ~Cluster(); - /** Join the cluster in plugin initialize. Requires transport - * plugins to be available.. */ + // Called by plugin initialize: cluster start-up requires transport plugins . + // Thread safety: only called by plugin initialize. void initialize(); - // Connection map - called in connection threads. + // Connection map. void addLocalConnection(const ConnectionPtr&); void addShadowConnection(const ConnectionPtr&); void erase(const ConnectionId&); - // URLs of current cluster members - called in connection threads. + // URLs of current cluster members. std::vector getIds() const; std::vector getUrls() const; boost::shared_ptr getFailoverExchange() const { return failoverExchange; } - // Leave the cluster - called in any thread. + // Leave the cluster - called when fatal errors occur. void leave(); // Update completed - called in update thread - void updateInDone(const ClusterMap&, uint64_t frameId); + void updateInDone(const ClusterMap&); MemberId getId() const; broker::Broker& getBroker() const; Multicaster& getMulticast() { return mcast; } - boost::function isQuorate; - void checkQuorum(); // called in connection threads. + void checkQuorum(); size_t getReadMax() { return readMax; } size_t getWriteEstimate() { return writeEstimate; } - bool isLeader() const; // Called in deliver thread. + void deliverFrame(const EventFrame&); + + // Called only during update by Connection::shadowReady + Decoder& getDecoder() { return decoder; } + + ExpiryPolicy& getExpiryPolicy() { return *expiryPolicy; } private: typedef sys::Monitor::ScopedLock Lock; typedef PollableQueue PollableEventQueue; typedef PollableQueue PollableFrameQueue; + typedef std::map ConnectionMap; - // NB: The final Lock& parameter on functions below is used to mark functions - // that should only be called by a function that already holds the lock. - // The parameter makes it hard to forget since you have to have an instance of - // a Lock to call the unlocked functions. - + // NB: A dummy Lock& parameter marks functions that must only be + // called with Cluster::lock locked. + void leave(Lock&); std::vector getIds(Lock&) const; std::vector getUrls(Lock&) const; - // Make an offer if we can - called in deliver thread. - void tryMakeOffer(const MemberId&, Lock&); - - // Called in main thread in ~Broker. + // == Called in main thread from Broker destructor. void brokerShutdown(); + // == Called in deliverEventQueue thread + void deliveredEvent(const Event&); + + // == Called in deliverFrameQueue thread + void deliveredFrame(const EventFrame&); + // Cluster controls implement XML methods from cluster.xml. - // Called in deliver thread. - // void updateRequest(const MemberId&, const std::string&, Lock&); void updateOffer(const MemberId& updater, uint64_t updatee, const framing::Uuid&, Lock&); void ready(const MemberId&, const std::string&, Lock&); void configChange(const MemberId&, const std::string& addresses, Lock& l); void messageExpired(const MemberId&, uint64_t, Lock& l); void shutdown(const MemberId&, Lock&); - void deliveredEvent(const Event&); - void deliveredFrame(const EventFrame&); - // Helper, called in deliver thread. + // Helper functions + ConnectionPtr getConnection(const ConnectionId&, Lock&); + ConnectionVector getConnections(Lock&); void updateStart(const MemberId& updatee, const Url& url, Lock&); - + void makeOffer(const MemberId&, Lock&); void setReady(Lock&); + void memberUpdate(Lock&); + void setClusterId(const framing::Uuid&, Lock&); + // == Called in CPG dispatch thread void deliver( // CPG deliver callback. cpg_handle_t /*handle*/, struct cpg_name *group, @@ -149,7 +159,7 @@ class Cluster : private Cpg::Handler, public management::Manageable { void* /*msg*/, int /*msg_len*/); - void deliver(const Event&); + void deliverEvent(const Event&); void configChange( // CPG config change callback. cpg_handle_t /*handle*/, @@ -159,23 +169,21 @@ class Cluster : private Cpg::Handler, public management::Manageable { struct cpg_address */*joined*/, int /*nJoined*/ ); + // == Called in management threads. virtual qpid::management::ManagementObject* GetManagementObject() const; virtual management::Manageable::status_t ManagementMethod (uint32_t methodId, management::Args& args, std::string& text); void stopClusterNode(Lock&); void stopFullCluster(Lock&); - void memberUpdate(Lock&); - // Called in connection IO threads . + // == Called in connection IO threads . void checkUpdateIn(Lock&); - // Called in UpdateClient thread. + // == Called in UpdateClient thread. void updateOutDone(); void updateOutError(const std::exception&); void updateOutDone(Lock&); - void setClusterId(const framing::Uuid&); - // Immutable members set on construction, never changed. ClusterSettings settings; broker::Broker& broker; @@ -184,34 +192,38 @@ class Cluster : private Cpg::Handler, public management::Manageable { Cpg cpg; const std::string name; Url myUrl; - const MemberId myId; + const MemberId self; const size_t readMax; const size_t writeEstimate; framing::Uuid clusterId; NoOpConnectionOutputHandler shadowOut; qpid::management::ManagementAgent* mAgent; + boost::intrusive_ptr expiryPolicy; // Thread safe members Multicaster mcast; PollerDispatch dispatcher; PollableEventQueue deliverEventQueue; PollableFrameQueue deliverFrameQueue; - ConnectionMap connections; boost::shared_ptr failoverExchange; Quorum quorum; - - // Used only in delivery thread - Decoder decoder; - ClusterMap::Set elders; - boost::intrusive_ptr expiryPolicy; - uint64_t frameId; + LockedConnectionMap localConnections; // Used only during initialization bool initialized; - // Remaining members are protected by lock + // Used only in deliverEventQueue thread or when stalled for update. + Decoder decoder; + bool discarding; + + // Remaining members are protected by lock. + // FIXME aconway 2009-03-06: Most of these members are also only used in + // deliverFrameQueue thread or during stall. Review and separate members + // that require a lock, drop lock when not needed. + // mutable sys::Monitor lock; + // Local cluster state, cluster map enum { INIT, ///< Initial state, no CPG messages received. @@ -223,15 +235,16 @@ class Cluster : private Cpg::Handler, public management::Manageable { UPDATER, ///< Offer accepted, sending a state update. LEFT ///< Final state, left the cluster. } state; + + ConnectionMap connections; ClusterMap map; + ClusterMap::Set elders; size_t lastSize; bool lastBroker; - uint64_t sequence; - - // Update related sys::Thread updateThread; boost::optional updatedMap; + friend std::ostream& operator<<(std::ostream&, const Cluster&); friend class ClusterDispatcher; }; diff --git a/qpid/cpp/src/qpid/cluster/ClusterPlugin.cpp b/qpid/cpp/src/qpid/cluster/ClusterPlugin.cpp index 132043f91a..adb6621caf 100644 --- a/qpid/cpp/src/qpid/cluster/ClusterPlugin.cpp +++ b/qpid/cpp/src/qpid/cluster/ClusterPlugin.cpp @@ -138,7 +138,6 @@ struct ClusterPlugin : public Plugin { broker->setConnectionFactory( boost::shared_ptr( new ConnectionCodec::Factory(broker->getConnectionFactory(), *cluster))); - broker->getExchanges().registerExchange(cluster->getFailoverExchange()); ManagementBroker* mgmt = dynamic_cast(ManagementAgent::Singleton::getInstance()); if (mgmt) { std::auto_ptr allocator(new UpdateClientIdAllocator()); diff --git a/qpid/cpp/src/qpid/cluster/ClusterSettings.h b/qpid/cpp/src/qpid/cluster/ClusterSettings.h index a8f33be75e..88e8829dfe 100644 --- a/qpid/cpp/src/qpid/cluster/ClusterSettings.h +++ b/qpid/cpp/src/qpid/cluster/ClusterSettings.h @@ -35,7 +35,7 @@ struct ClusterSettings { size_t readMax, writeEstimate; std::string username, password, mechanism; - ClusterSettings() : quorum(false), readMax(10), writeEstimate(64), username("guest"), password("guest") {} + ClusterSettings() : quorum(false), readMax(10), writeEstimate(64) {} Url getUrl(uint16_t port) const { if (url.empty()) return Url::getIpAddressesUrl(port); diff --git a/qpid/cpp/src/qpid/cluster/Connection.cpp b/qpid/cpp/src/qpid/cluster/Connection.cpp index 1a3f7c4ef7..aa7d082720 100644 --- a/qpid/cpp/src/qpid/cluster/Connection.cpp +++ b/qpid/cpp/src/qpid/cluster/Connection.cpp @@ -40,6 +40,7 @@ #include "qpid/framing/ConnectionCloseOkBody.h" #include "qpid/log/Statement.h" #include "qpid/sys/LatencyMetric.h" +#include "qpid/sys/AtomicValue.h" #include @@ -58,27 +59,36 @@ using namespace framing; NoOpConnectionOutputHandler Connection::discardHandler; -// Shadow connections -Connection::Connection(Cluster& c, sys::ConnectionOutputHandler& out, - const std::string& wrappedId, ConnectionId myId) - : cluster(c), self(myId), catchUp(false), output(*this, out), - connection(&output, cluster.getBroker(), wrappedId), expectProtocolHeader(false) +namespace { +sys::AtomicValue idCounter; +} + +// Shadow connection +Connection::Connection(Cluster& c, sys::ConnectionOutputHandler& out, const std::string& logId, const ConnectionId& id) + : cluster(c), self(id), catchUp(false), output(*this, out), + connection(&output, cluster.getBroker(), logId), expectProtocolHeader(false), + mcastFrameHandler(cluster.getMulticast(), self) { init(); } -// Local connections +// Local connection Connection::Connection(Cluster& c, sys::ConnectionOutputHandler& out, - const std::string& wrappedId, MemberId myId, bool isCatchUp, bool isLink) - : cluster(c), self(myId, this), catchUp(isCatchUp), output(*this, out), - connection(&output, cluster.getBroker(), wrappedId, isLink, catchUp ? ++catchUpId : 0), - expectProtocolHeader(isLink) + const std::string& logId, MemberId member, bool isCatchUp, bool isLink) + : cluster(c), self(member, ++idCounter), catchUp(isCatchUp), output(*this, out), + connection(&output, cluster.getBroker(), logId, isLink, catchUp ? ++catchUpId : 0), + expectProtocolHeader(isLink), mcastFrameHandler(cluster.getMulticast(), self) { init(); } void Connection::init() { QPID_LOG(debug, cluster << " new connection: " << *this); - if (isLocalClient()) { + if (isLocalClient()) { + connection.setClusterOrderOutput(mcastFrameHandler); // Actively send cluster-order frames from local node cluster.addLocalConnection(this); giveReadCredit(cluster.getReadMax()); } + else { // Shadow or catch-up connection + connection.setClusterOrderOutput(nullFrameHandler); // Passive, discard cluster-order frames + connection.setClientThrottling(false); // Disable client throttling, done by active node. + } } void Connection::giveReadCredit(int credit) { @@ -140,10 +150,16 @@ bool Connection::checkUnsupported(const AMQBody& body) { void Connection::deliveredFrame(const EventFrame& f) { assert(!catchUp); currentChannel = f.frame.getChannel(); - if (!framing::invoke(*this, *f.frame.getBody()).wasHandled() // Connection contol. + if (f.frame.getBody() // frame can be emtpy with just readCredit + && !framing::invoke(*this, *f.frame.getBody()).wasHandled() // Connection contol. && !checkUnsupported(*f.frame.getBody())) // Unsupported operation. { - connection.received(const_cast(f.frame)); // Pass to broker connection. + if (f.type == DATA) // incoming data frames to broker::Connection + connection.received(const_cast(f.frame)); + else { // frame control, send frame via SessionState + broker::SessionState* ss = connection.getChannel(f.frame.getChannel()).getSession(); + if (ss) ss->out(const_cast(f.frame)); + } } giveReadCredit(f.readCredit); } @@ -186,12 +202,12 @@ void Connection::left() { connection.closed(); } -// Decode data from local clients. +// ConnectoinCodec::decode receives read buffers from directly-connected clients. size_t Connection::decode(const char* buffer, size_t size) { if (catchUp) { // Handle catch-up locally. Buffer buf(const_cast(buffer), size); while (localDecoder.decode(buf)) - received(localDecoder.frame); + received(localDecoder.getFrame()); } else { // Multicast local connections. assert(isLocal()); @@ -242,6 +258,7 @@ void Connection::sessionState( const SequenceSet& unknownCompleted, const SequenceSet& receivedIncomplete) { + sessionState().setState( replayStart, sendCommandPoint, @@ -253,21 +270,23 @@ void Connection::sessionState( QPID_LOG(debug, cluster << " received session state update for " << sessionState().getId()); } -void Connection::shadowReady(uint64_t memberId, uint64_t connectionId, const string& username) { - ConnectionId shadow = ConnectionId(memberId, connectionId); - QPID_LOG(debug, cluster << " catch-up connection " << *this << " becomes shadow " << shadow); - self = shadow; +void Connection::shadowReady(uint64_t memberId, uint64_t connectionId, const string& username, const string& fragment) { + ConnectionId shadowId = ConnectionId(memberId, connectionId); + QPID_LOG(debug, cluster << " catch-up connection " << *this << " becomes shadow " << shadowId); + self = shadowId; connection.setUserId(username); + // OK to use decoder here because we are stalled for update. + cluster.getDecoder().get(self).setFragment(fragment.data(), fragment.size()); } -void Connection::membership(const FieldTable& joiners, const FieldTable& members, uint64_t frameId) { +void Connection::membership(const FieldTable& joiners, const FieldTable& members) { QPID_LOG(debug, cluster << " incoming update complete on connection " << *this); - cluster.updateInDone(ClusterMap(joiners, members), frameId); + cluster.updateInDone(ClusterMap(joiners, members)); self.second = 0; // Mark this as completed update connection. } bool Connection::isLocal() const { - return self.first == cluster.getId() && self.second == this; + return self.first == cluster.getId() && self.second; } bool Connection::isShadow() const { @@ -333,6 +352,10 @@ void Connection::queuePosition(const string& qname, const SequenceNumber& positi q->setPosition(position); } +void Connection::expiryId(uint64_t id) { + cluster.getExpiryPolicy().setId(id); +} + std::ostream& operator<<(std::ostream& o, const Connection& c) { const char* type="unknown"; if (c.isLocal()) type = "local"; diff --git a/qpid/cpp/src/qpid/cluster/Connection.h b/qpid/cpp/src/qpid/cluster/Connection.h index 98b47e1bc0..6434f763a8 100644 --- a/qpid/cpp/src/qpid/cluster/Connection.h +++ b/qpid/cpp/src/qpid/cluster/Connection.h @@ -27,14 +27,15 @@ #include "OutputInterceptor.h" #include "NoOpConnectionOutputHandler.h" #include "EventFrame.h" +#include "McastFrameHandler.h" #include "qpid/broker/Connection.h" #include "qpid/amqp_0_10/Connection.h" #include "qpid/sys/AtomicValue.h" #include "qpid/sys/ConnectionInputHandler.h" #include "qpid/sys/ConnectionOutputHandler.h" -#include "qpid/framing/FrameDecoder.h" #include "qpid/framing/SequenceNumber.h" +#include "qpid/framing/FrameDecoder.h" #include @@ -63,10 +64,10 @@ class Connection : public: typedef sys::PollableQueue PollableFrameQueue; - /** Local connection, use this in ConnectionId */ - Connection(Cluster&, sys::ConnectionOutputHandler& out, const std::string& id, MemberId, bool catchUp, bool isLink); - /** Shadow connection */ - Connection(Cluster&, sys::ConnectionOutputHandler& out, const std::string& id, ConnectionId); + /** Local connection. */ + Connection(Cluster&, sys::ConnectionOutputHandler& out, const std::string& logId, MemberId, bool catchUp, bool isLink); + /** Shadow connection. */ + Connection(Cluster&, sys::ConnectionOutputHandler& out, const std::string& logId, const ConnectionId& id); ~Connection(); ConnectionId getId() const { return self; } @@ -99,7 +100,7 @@ class Connection : /** Called if the connectors member has left the cluster */ void left(); - // ConnectionCodec methods + // ConnectionCodec methods - called by IO layer with a read buffer. size_t decode(const char* buffer, size_t size); // Called for data delivered from the cluster. @@ -117,9 +118,9 @@ class Connection : const framing::SequenceNumber& received, const framing::SequenceSet& unknownCompleted, const SequenceSet& receivedIncomplete); - void shadowReady(uint64_t memberId, uint64_t connectionId, const std::string& username); + void shadowReady(uint64_t memberId, uint64_t connectionId, const std::string& username, const std::string& fragment); - void membership(const framing::FieldTable&, const framing::FieldTable&, uint64_t frameId); + void membership(const framing::FieldTable&, const framing::FieldTable&); void deliveryRecord(const std::string& queue, const framing::SequenceNumber& position, @@ -134,6 +135,7 @@ class Connection : uint32_t credit); void queuePosition(const std::string&, const framing::SequenceNumber&); + void expiryId(uint64_t); void txStart(); void txAccept(const framing::SequenceSet&); @@ -148,8 +150,12 @@ class Connection : void exchange(const std::string& encoded); void giveReadCredit(int credit); - + private: + struct NullFrameHandler : public framing::FrameHandler { + void handle(framing::AMQFrame&) {} + }; + void init(); bool checkUnsupported(const framing::AMQBody& body); void deliverClose(); @@ -174,6 +180,8 @@ class Connection : framing::ChannelId currentChannel; boost::shared_ptr txBuffer; bool expectProtocolHeader; + McastFrameHandler mcastFrameHandler; + NullFrameHandler nullFrameHandler; static qpid::sys::AtomicValue catchUpId; diff --git a/qpid/cpp/src/qpid/cluster/ConnectionCodec.cpp b/qpid/cpp/src/qpid/cluster/ConnectionCodec.cpp index 442ac1438f..007337792b 100644 --- a/qpid/cpp/src/qpid/cluster/ConnectionCodec.cpp +++ b/qpid/cpp/src/qpid/cluster/ConnectionCodec.cpp @@ -44,18 +44,15 @@ ConnectionCodec::Factory::create(ProtocolVersion v, sys::OutputControl& out, con return 0; } -// Used for outgoing Link connections, we don't care. +// Used for outgoing Link connections sys::ConnectionCodec* -ConnectionCodec::Factory::create(sys::OutputControl& out, const std::string& id) { - return new ConnectionCodec(out, id, cluster, false, true); - //return next->create(out, id); +ConnectionCodec::Factory::create(sys::OutputControl& out, const std::string& logId) { + return new ConnectionCodec(out, logId, cluster, false, true); } -ConnectionCodec::ConnectionCodec(sys::OutputControl& out, const std::string& id, Cluster& cluster, bool catchUp, bool isLink) - : codec(out, id, isLink), - interceptor(new Connection(cluster, codec, id, cluster.getId(), catchUp, isLink)), - id(interceptor->getId()), - localId(id) +ConnectionCodec::ConnectionCodec(sys::OutputControl& out, const std::string& logId, Cluster& cluster, bool catchUp, bool isLink) + : codec(out, logId, isLink), + interceptor(new Connection(cluster, codec, logId, cluster.getId(), catchUp, isLink)) { std::auto_ptr ih(new ProxyInputHandler(interceptor)); codec.setInputHandler(ih); diff --git a/qpid/cpp/src/qpid/cluster/ConnectionCodec.h b/qpid/cpp/src/qpid/cluster/ConnectionCodec.h index 69c2b0c3c8..ea01b7abb9 100644 --- a/qpid/cpp/src/qpid/cluster/ConnectionCodec.h +++ b/qpid/cpp/src/qpid/cluster/ConnectionCodec.h @@ -56,7 +56,7 @@ class ConnectionCodec : public sys::ConnectionCodec { sys::ConnectionCodec* create(sys::OutputControl&, const std::string& id); }; - ConnectionCodec(sys::OutputControl& out, const std::string& id, Cluster& c, bool catchUp, bool isLink); + ConnectionCodec(sys::OutputControl& out, const std::string& logId, Cluster& c, bool catchUp, bool isLink); ~ConnectionCodec(); // ConnectionCodec functions. @@ -71,8 +71,6 @@ class ConnectionCodec : public sys::ConnectionCodec { private: amqp_0_10::Connection codec; boost::intrusive_ptr interceptor; - cluster::ConnectionId id; - std::string localId; }; }} // namespace qpid::cluster diff --git a/qpid/cpp/src/qpid/cluster/ConnectionDecoder.cpp b/qpid/cpp/src/qpid/cluster/ConnectionDecoder.cpp deleted file mode 100644 index 3c18cf751e..0000000000 --- a/qpid/cpp/src/qpid/cluster/ConnectionDecoder.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -#include "ConnectionDecoder.h" -#include "EventFrame.h" -#include "ConnectionMap.h" - -namespace qpid { -namespace cluster { - -using namespace framing; - -ConnectionDecoder::ConnectionDecoder(const Handler& h) : handler(h) {} - -void ConnectionDecoder::decode(const EventHeader& eh, const void* data, ConnectionMap& map) { - assert(eh.getType() == DATA); // Only handle connection data events. - const char* cp = static_cast(data); - Buffer buf(const_cast(cp), eh.getSize()); - if (decoder.decode(buf)) { // Decoded a frame - AMQFrame frame(decoder.frame); - while (decoder.decode(buf)) { - handler(EventFrame(eh, frame)); - frame = decoder.frame; - } - // Set read-credit on the last frame ending in this event. - // Credit will be given when this frame is processed. - handler(EventFrame(eh, frame, 1)); - } - else { - // We must give 1 unit read credit per event. - // This event does not complete any frames so - // we give read credit directly. - ConnectionPtr connection = map.getLocal(eh.getConnectionId()); - if (connection) - connection->giveReadCredit(1); - } -} - -}} // namespace qpid::cluster diff --git a/qpid/cpp/src/qpid/cluster/ConnectionDecoder.h b/qpid/cpp/src/qpid/cluster/ConnectionDecoder.h deleted file mode 100644 index 449387c1cc..0000000000 --- a/qpid/cpp/src/qpid/cluster/ConnectionDecoder.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef QPID_CLUSTER_CONNECTIONDECODER_H -#define QPID_CLUSTER_CONNECTIONDECODER_H - -/* - * - * 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. - * - */ - -#include "qpid/framing/FrameDecoder.h" -#include - -namespace qpid { -namespace cluster { - -class EventHeader; -class EventFrame; -class ConnectionMap; - -/** - * Decodes delivered connection data Event's as EventFrame's for a - * connection replica, local or shadow. Manages state for frame - * fragments and flow control. - * - * THREAD UNSAFE: connection events are decoded in sequence. - */ -class ConnectionDecoder -{ - public: - typedef boost::function Handler; - - ConnectionDecoder(const Handler& h); - - /** Takes EventHeader + data rather than Event so that the caller can - * pass a pointer to connection data or a CPG buffer directly without copy. - */ - void decode(const EventHeader& eh, const void* data, ConnectionMap& connections); - - private: - Handler handler; - framing::FrameDecoder decoder; -}; - -}} // namespace qpid::cluster - -#endif /*!QPID_CLUSTER_CONNECTIONDECODER_H*/ diff --git a/qpid/cpp/src/qpid/cluster/ConnectionMap.cpp b/qpid/cpp/src/qpid/cluster/ConnectionMap.cpp deleted file mode 100644 index b412bb13cc..0000000000 --- a/qpid/cpp/src/qpid/cluster/ConnectionMap.cpp +++ /dev/null @@ -1,96 +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. - * - */ -#include "ConnectionMap.h" -#include "Cluster.h" -#include "qpid/framing/reply_exceptions.h" -#include "qpid/log/Statement.h" - -namespace qpid { -namespace cluster { - -using framing::InternalErrorException; - -void ConnectionMap::insert(ConnectionPtr p) { - std::pair ib = map.insert(Map::value_type(p->getId(), p)); - if (!ib.second) { - assert(0); - throw InternalErrorException(QPID_MSG("Duplicate connection replica: " << p->getId())); - } -} - -void ConnectionMap::erase(const ConnectionId& id) { - Map::iterator i = map.find(id); - if (i == map.end()) { - assert(0); - QPID_LOG(warning, "Erase non-existent connection replica: " << id); - } - map.erase(i); -} - -ConnectionMap::ConnectionPtr ConnectionMap::get(const ConnectionId& id) { - Map::const_iterator i = map.find(id); - if (i == map.end()) { - // Deleted local connection. - if(id.getMember() == cluster.getId()) - return 0; - // New remote connection, create a shadow. - std::ostringstream mgmtId; - mgmtId << id; - ConnectionPtr cp = new Connection(cluster, shadowOut, mgmtId.str(), id); - std::pair ib = map.insert(Map::value_type(id, cp)); - if (!ib.second) - throw InternalErrorException(QPID_MSG("Duplicate entry in cluster connection map: " << id)); - i = ib.first; - } - return i->second; -} - -ConnectionMap::ConnectionPtr ConnectionMap::getLocal(const ConnectionId& id) { - if (id.getMember() != cluster.getId()) return 0; - Map::const_iterator i = map.find(id); - assert(i != map.end()); // FIXME aconway 2009-02-11: remove or exception. - return i == map.end() ? 0 : i->second; -} - -ConnectionMap::Vector ConnectionMap::values() const { - Vector result(map.size()); - std::transform(map.begin(), map.end(), result.begin(), - boost::bind(&Map::value_type::second, _1)); - return result; -} - -void ConnectionMap::update(MemberId myId, const ClusterMap& cluster) { - for (Map::iterator i = map.begin(); i != map.end(); ) { - MemberId member = i->first.getMember(); - if (member != myId && !cluster.isMember(member)) { - i->second->left(); - map.erase(i++); - } else { - i++; - } - } -} - -void ConnectionMap::clear() { - map.clear(); -} - -}} // namespace qpid::cluster diff --git a/qpid/cpp/src/qpid/cluster/ConnectionMap.h b/qpid/cpp/src/qpid/cluster/ConnectionMap.h deleted file mode 100644 index f8aa663339..0000000000 --- a/qpid/cpp/src/qpid/cluster/ConnectionMap.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef QPID_CLUSTER_CONNECTIONMAP_H -#define QPID_CLUSTER_CONNECTIONMAP_H - -/* - * - * 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. - * - */ -#include "types.h" -#include "Connection.h" -#include "ClusterMap.h" -#include "NoOpConnectionOutputHandler.h" -#include "qpid/sys/Mutex.h" -#include -#include - -namespace qpid { -namespace cluster { - -class Cluster; - -/** - * Thread safe map of connections. The map is used in: - * - deliver thread to look connections and create new shadow connections. - * - local catch-up connection threads to add a caught-up shadow connections. - * - local client connection threads when local connections are created. - */ -class ConnectionMap { - public: - typedef boost::intrusive_ptr ConnectionPtr; - typedef std::vector Vector; - - ConnectionMap(Cluster& c) : cluster(c) {} - - /** Insert a local connection or a caught up shadow connection. - * Called in local connection thread. - */ - void insert(ConnectionPtr p); - - /** Erase a closed connection. Called in deliver thread. */ - void erase(const ConnectionId& id); - - /** Get an existing connection. Returns 0 if id is a closed local - * connections, frames for closed connections should be ignored. - */ - ConnectionPtr get(const ConnectionId& id); - - /** If ID is a local connection and in the map return it, else return 0 */ - ConnectionPtr getLocal(const ConnectionId& id); - - /** Get connections for sending an update. */ - Vector values() const; - - /** Remove connections who's members are no longer in the cluster. Deliver thread. */ - void update(MemberId myId, const ClusterMap& cluster); - - - void clear(); - - size_t size() const; - - private: - typedef std::map Map; - - Cluster& cluster; - NoOpConnectionOutputHandler shadowOut; - Map map; -}; - - -}} // namespace qpid::cluster - -#endif /*!QPID_CLUSTER_CONNECTIONMAP_H*/ diff --git a/qpid/cpp/src/qpid/cluster/Cpg.cpp b/qpid/cpp/src/qpid/cluster/Cpg.cpp index c5a1b72003..92fceba904 100644 --- a/qpid/cpp/src/qpid/cluster/Cpg.cpp +++ b/qpid/cpp/src/qpid/cluster/Cpg.cpp @@ -107,17 +107,16 @@ void Cpg::leave() { check(cpg_leave(handle, &group), cantLeaveMsg(group)); } -bool Cpg::isFlowControlEnabled() { - cpg_flow_control_state_t flowState; - check(cpg_flow_control_state_get(handle, &flowState), "Cannot get CPG flow control status."); - return flowState == CPG_FLOW_CONTROL_ENABLED; -} + + bool Cpg::mcast(const iovec* iov, int iovLen) { - if (isFlowControlEnabled()) { - QPID_LOG(debug, "CPG flow control enabled") + // Check for flow control + cpg_flow_control_state_t flowState; + check(cpg_flow_control_state_get(handle, &flowState), "Cannot get CPG flow control status."); + if (flowState == CPG_FLOW_CONTROL_ENABLED) return false; - } + cpg_error_t result; do { result = cpg_mcast_joined(handle, CPG_TYPE_AGREED, const_cast(iov), iovLen); diff --git a/qpid/cpp/src/qpid/cluster/Cpg.h b/qpid/cpp/src/qpid/cluster/Cpg.h index 5ac5a5bdbc..ac27a09ae6 100644 --- a/qpid/cpp/src/qpid/cluster/Cpg.h +++ b/qpid/cpp/src/qpid/cluster/Cpg.h @@ -114,8 +114,6 @@ class Cpg : public sys::IOHandle { int getFd(); - bool isFlowControlEnabled(); - private: static std::string errorStr(cpg_error_t err, const std::string& msg); static std::string cantJoinMsg(const Name&); diff --git a/qpid/cpp/src/qpid/cluster/Decoder.cpp b/qpid/cpp/src/qpid/cluster/Decoder.cpp index 1ba36bb521..4de586d89f 100644 --- a/qpid/cpp/src/qpid/cluster/Decoder.cpp +++ b/qpid/cpp/src/qpid/cluster/Decoder.cpp @@ -18,33 +18,43 @@ * under the License. * */ - #include "Decoder.h" -#include "Event.h" +#include "EventFrame.h" +#include "qpid/framing/ClusterConnectionDeliverCloseBody.h" #include "qpid/framing/Buffer.h" -#include "qpid/ptr_map.h" +#include "qpid/framing/AMQFrame.h" + namespace qpid { namespace cluster { -using namespace framing; - -Decoder::Decoder(const Handler& h, ConnectionMap& cm) : handler(h), connections(cm) {} - -void Decoder::decode(const EventHeader& eh, const void* data) { - ConnectionId id = eh.getConnectionId(); - Map::iterator i = map.find(id); - if (i == map.end()) { - std::pair ib = map.insert(id, new ConnectionDecoder(handler)); - i = ib.first; +void Decoder::decode(const EventHeader& eh, const char* data) { + assert(eh.getType() == DATA); // Only handle connection data events. + const char* cp = static_cast(data); + framing::Buffer buf(const_cast(cp), eh.getSize()); + framing::FrameDecoder& decoder = map[eh.getConnectionId()]; + if (decoder.decode(buf)) { // Decoded a frame + framing::AMQFrame frame(decoder.getFrame()); + while (decoder.decode(buf)) { + process(EventFrame(eh, frame)); + frame = decoder.getFrame(); + } + // Set read-credit on the last frame ending in this event. + // Credit will be given when this frame is processed. + process(EventFrame(eh, frame, 1)); } - ptr_map_ptr(i)->decode(eh, data, connections); + else { + // We must give 1 unit read credit per event. + // This event does not complete any frames so + // send an empty frame with the read credit. + process(EventFrame(EventHeader(), framing::AMQFrame(), 1)); + } } -void Decoder::erase(const ConnectionId& c) { - Map::iterator i = map.find(c); - if (i != map.end()) - map.erase(i); +void Decoder::process(const EventFrame& ef) { + if (ef.frame.getMethod() && ef.frame.getMethod()->isA()) + map.erase(ef.connectionId); + callback(ef); } }} // namespace qpid::cluster diff --git a/qpid/cpp/src/qpid/cluster/Decoder.h b/qpid/cpp/src/qpid/cluster/Decoder.h index 50f6afa491..acde4258a2 100644 --- a/qpid/cpp/src/qpid/cluster/Decoder.h +++ b/qpid/cpp/src/qpid/cluster/Decoder.h @@ -22,44 +22,36 @@ * */ -#include "ConnectionDecoder.h" #include "types.h" -#include +#include "qpid/framing/FrameDecoder.h" +#include +#include namespace qpid { namespace cluster { +class EventFrame; class EventHeader; -class ConnectionMap; /** - * Holds a map of ConnectionDecoders. Decodes Events into EventFrames - * and forwards EventFrames to a handler. - * - * THREAD UNSAFE: Called sequentially with un-decoded cluster events from CPG. + * A map of decoders for connections. */ class Decoder { public: - typedef boost::function Handler; - - Decoder(const Handler& h, ConnectionMap&); + typedef boost::function FrameHandler; - /** Takes EventHeader + data rather than Event so that the caller can - * pass a pointer to connection data or a CPG buffer directly without copy. - */ - void decode(const EventHeader& eh, const void* data); - - /** Erase the decoder for a connection. */ + Decoder(FrameHandler fh) : callback(fh) {} + void decode(const EventHeader& eh, const char* data); void erase(const ConnectionId&); + framing::FrameDecoder& get(const ConnectionId& c) { return map[c]; } private: - typedef boost::ptr_map Map; - Handler handler; + typedef std::map Map; Map map; - ConnectionMap& connections; + void process(const EventFrame&); + FrameHandler callback; }; - }} // namespace qpid::cluster #endif /*!QPID_CLUSTER_DECODER_H*/ diff --git a/qpid/cpp/src/qpid/cluster/Event.cpp b/qpid/cpp/src/qpid/cluster/Event.cpp index e30b961b3e..1cb010c266 100644 --- a/qpid/cpp/src/qpid/cluster/Event.cpp +++ b/qpid/cpp/src/qpid/cluster/Event.cpp @@ -23,6 +23,7 @@ #include "Cpg.h" #include "qpid/framing/Buffer.h" #include "qpid/framing/AMQFrame.h" +#include "qpid/assert.h" #include #include #include @@ -31,6 +32,7 @@ namespace qpid { namespace cluster { using framing::Buffer; +using framing::AMQFrame; const size_t EventHeader::HEADER_SIZE = sizeof(uint8_t) + // type @@ -42,7 +44,7 @@ const size_t EventHeader::HEADER_SIZE = ; EventHeader::EventHeader(EventType t, const ConnectionId& c, size_t s) - : type(t), connectionId(c), size(s), sequence(0) {} + : type(t), connectionId(c), size(s) {} Event::Event() {} @@ -57,7 +59,7 @@ void EventHeader::decode(const MemberId& m, framing::Buffer& buf) { type = (EventType)buf.getOctet(); if(type != DATA && type != CONTROL) throw Exception("Invalid multicast event type"); - connectionId = ConnectionId(m, reinterpret_cast(buf.getLongLong())); + connectionId = ConnectionId(m, buf.getLongLong()); size = buf.getLong(); #ifdef QPID_LATENCY_METRIC latency_metric_timestamp = buf.getLongLong(); @@ -74,14 +76,17 @@ Event Event::decodeCopy(const MemberId& m, framing::Buffer& buf) { return e; } -Event Event::control(const framing::AMQBody& body, const ConnectionId& cid) { - framing::AMQFrame f(body); +Event Event::control(const framing::AMQFrame& f, const ConnectionId& cid) { Event e(CONTROL, cid, f.encodedSize()); Buffer buf(e); f.encode(buf); return e; } +Event Event::control(const framing::AMQBody& body, const ConnectionId& cid) { + return control(framing::AMQFrame(body), cid); +} + iovec Event::toIovec() { encodeHeader(); iovec iov = { const_cast(getStore()), getStoreSize() }; @@ -90,7 +95,7 @@ iovec Event::toIovec() { void EventHeader::encode(Buffer& b) const { b.putOctet(type); - b.putLongLong(reinterpret_cast(connectionId.getPointer())); + b.putLongLong(connectionId.getNumber()); b.putLong(size); #ifdef QPID_LATENCY_METRIC b.putLongLong(latency_metric_timestamp); @@ -108,12 +113,22 @@ Event::operator Buffer() const { return Buffer(const_cast(getData()), getSize()); } +AMQFrame Event::getFrame() const { + assert(type == CONTROL); + Buffer buf(*this); + AMQFrame frame; + QPID_ASSERT(frame.decode(buf)); + return frame; +} + static const char* EVENT_TYPE_NAMES[] = { "data", "control" }; +std::ostream& operator << (std::ostream& o, EventType t) { + return o << EVENT_TYPE_NAMES[t]; +} + std::ostream& operator << (std::ostream& o, const EventHeader& e) { - o << "[event " << e.getConnectionId() << "/" << e.getSequence() - << " " << EVENT_TYPE_NAMES[e.getType()] - << " " << e.getSize() << " bytes]"; + o << "Event[" << e.getConnectionId() << " " << e.getType() << " " << e.getSize() << " bytes]"; return o; } diff --git a/qpid/cpp/src/qpid/cluster/Event.h b/qpid/cpp/src/qpid/cluster/Event.h index f1de248f89..e05ad60bcf 100644 --- a/qpid/cpp/src/qpid/cluster/Event.h +++ b/qpid/cpp/src/qpid/cluster/Event.h @@ -24,6 +24,7 @@ #include "types.h" #include "qpid/RefCountedBuffer.h" +#include "qpid/framing/AMQFrame.h" #include "qpid/sys/LatencyMetric.h" #include // For iovec #include @@ -34,6 +35,7 @@ namespace qpid { namespace framing { class AMQBody; +class AMQFrame; class Buffer; } @@ -55,11 +57,9 @@ class EventHeader : public ::qpid::sys::LatencyMetricTimestamp { /** Size of header + payload. */ size_t getStoreSize() { return size + HEADER_SIZE; } - uint64_t getSequence() const { return sequence; } - void setSequence(uint64_t n) { sequence = n; } - - bool isCluster() const { return connectionId.getPointer() == 0; } - bool isConnection() const { return connectionId.getPointer() != 0; } + bool isCluster() const { return connectionId.getNumber() == 0; } + bool isConnection() const { return connectionId.getNumber() != 0; } + bool isControl() const { return type == CONTROL; } protected: static const size_t HEADER_SIZE; @@ -67,7 +67,6 @@ class EventHeader : public ::qpid::sys::LatencyMetricTimestamp { EventType type; ConnectionId connectionId; size_t size; - uint64_t sequence; }; /** @@ -83,8 +82,11 @@ class Event : public EventHeader { /** Create an event copied from delivered data. */ static Event decodeCopy(const MemberId& m, framing::Buffer&); - /** Create an event containing a control */ + /** Create a control event. */ static Event control(const framing::AMQBody&, const ConnectionId&); + + /** Create a control event. */ + static Event control(const framing::AMQFrame&, const ConnectionId&); // Data excluding header. char* getData() { return store + HEADER_SIZE; } @@ -93,6 +95,8 @@ class Event : public EventHeader { // Store including header char* getStore() { return store; } const char* getStore() const { return store; } + + framing::AMQFrame getFrame() const; operator framing::Buffer() const; @@ -105,6 +109,7 @@ class Event : public EventHeader { }; std::ostream& operator << (std::ostream&, const EventHeader&); + }} // namespace qpid::cluster #endif /*!QPID_CLUSTER_EVENT_H*/ diff --git a/qpid/cpp/src/qpid/cluster/EventFrame.cpp b/qpid/cpp/src/qpid/cluster/EventFrame.cpp index ba01c170dd..8259b6da6e 100644 --- a/qpid/cpp/src/qpid/cluster/EventFrame.cpp +++ b/qpid/cpp/src/qpid/cluster/EventFrame.cpp @@ -24,16 +24,18 @@ namespace qpid { namespace cluster { -EventFrame::EventFrame() : sequence(0) {} +EventFrame::EventFrame() {} EventFrame::EventFrame(const EventHeader& e, const framing::AMQFrame& f, int rc) - : connectionId(e.getConnectionId()), frame(f), sequence(e.getSequence()), readCredit(rc) + : connectionId(e.getConnectionId()), frame(f), readCredit(rc), type(e.getType()) { QPID_LATENCY_INIT(frame); } std::ostream& operator<<(std::ostream& o, const EventFrame& e) { - return o << e.connectionId << "/" << e.sequence << " " << e.frame << " rc=" << e.readCredit; + return o << e.frame << " " << e.type << " " << e.connectionId; + if (e.readCredit) o << " read-credit=" << e.readCredit; + return o; } }} // namespace qpid::cluster diff --git a/qpid/cpp/src/qpid/cluster/EventFrame.h b/qpid/cpp/src/qpid/cluster/EventFrame.h index 7f33cedb5b..d6ff58dd38 100644 --- a/qpid/cpp/src/qpid/cluster/EventFrame.h +++ b/qpid/cpp/src/qpid/cluster/EventFrame.h @@ -42,22 +42,15 @@ struct EventFrame EventFrame(const EventHeader& e, const framing::AMQFrame& f, int rc=0); - bool isCluster() const { return !connectionId.getPointer(); } - bool isConnection() const { return connectionId.getPointer(); } + bool isCluster() const { return connectionId.getNumber() == 0; } + bool isConnection() const { return connectionId.getNumber() != 0; } bool isLastInEvent() const { return readCredit; } - // True if this frame follows immediately after frame e. - bool follows(const EventFrame& e) const { - return sequence == e.sequence || (sequence == e.sequence+1 && e.readCredit); - } - - bool operator<(const EventFrame& e) const { return sequence < e.sequence; } - ConnectionId connectionId; framing::AMQFrame frame; - uint64_t sequence; - int readCredit; // last frame in an event, give credit when processed. + int readCredit; ///< last frame in an event, give credit when processed. + EventType type; }; std::ostream& operator<<(std::ostream& o, const EventFrame& e); diff --git a/qpid/cpp/src/qpid/cluster/ExpiryPolicy.cpp b/qpid/cpp/src/qpid/cluster/ExpiryPolicy.cpp index 690acfc3ad..409180c499 100644 --- a/qpid/cpp/src/qpid/cluster/ExpiryPolicy.cpp +++ b/qpid/cpp/src/qpid/cluster/ExpiryPolicy.cpp @@ -30,48 +30,46 @@ namespace qpid { namespace cluster { -ExpiryPolicy::ExpiryPolicy(const boost::function & f, Multicaster& m, const MemberId& id, broker::Timer& t) - : expiredPolicy(new Expired), isLeader(f), mcast(m), memberId(id), timer(t) {} - -namespace { -uint64_t clusterId(const broker::Message& m) { - assert(m.getFrames().begin() != m.getFrames().end()); - return m.getFrames().begin()->getClusterId(); -} +ExpiryPolicy::ExpiryPolicy(Multicaster& m, const MemberId& id, broker::Timer& t) + : expiryId(0), expiredPolicy(new Expired), mcast(m), memberId(id), timer(t) {} struct ExpiryTask : public broker::TimerTask { ExpiryTask(const boost::intrusive_ptr& policy, uint64_t id, sys::AbsTime when) - : TimerTask(when), expiryPolicy(policy), messageId(id) {} - void fire() { expiryPolicy->sendExpire(messageId); } + : TimerTask(when), expiryPolicy(policy), expiryId(id) {} + void fire() { expiryPolicy->sendExpire(expiryId); } boost::intrusive_ptr expiryPolicy; - const uint64_t messageId; + const uint64_t expiryId; }; -} void ExpiryPolicy::willExpire(broker::Message& m) { - timer.add(new ExpiryTask(this, clusterId(m), m.getExpiration())); + uint64_t id = expiryId++; + assert(unexpiredById.find(id) == unexpiredById.end()); + assert(unexpiredByMessage.find(&m) == unexpiredByMessage.end()); + unexpiredById[id] = &m; + unexpiredByMessage[&m] = id; + timer.add(new ExpiryTask(this, id, m.getExpiration())); } bool ExpiryPolicy::hasExpired(broker::Message& m) { - sys::Mutex::ScopedLock l(lock); - IdSet::iterator i = expired.find(clusterId(m)); - if (i != expired.end()) { - expired.erase(i); - const_cast(m).setExpiryPolicy(expiredPolicy); // hasExpired() == true; - return true; - } - return false; + return unexpiredByMessage.find(&m) == unexpiredByMessage.end(); } void ExpiryPolicy::sendExpire(uint64_t id) { - sys::Mutex::ScopedLock l(lock); - if (isLeader()) - mcast.mcastControl(framing::ClusterMessageExpiredBody(framing::ProtocolVersion(), id), memberId); + mcast.mcastControl(framing::ClusterMessageExpiredBody(framing::ProtocolVersion(), id), memberId); } void ExpiryPolicy::deliverExpire(uint64_t id) { - sys::Mutex::ScopedLock l(lock); - expired.insert(id); + IdMessageMap::iterator i = unexpiredById.find(id); + if (i != unexpiredById.end()) { + i->second->setExpiryPolicy(expiredPolicy); // hasExpired() == true; + unexpiredByMessage.erase(i->second); + unexpiredById.erase(i); + } +} + +boost::optional ExpiryPolicy::getId(broker::Message& m) { + MessageIdMap::iterator i = unexpiredByMessage.find(&m); + return i == unexpiredByMessage.end() ? boost::optional() : i->second; } bool ExpiryPolicy::Expired::hasExpired(broker::Message&) { return true; } diff --git a/qpid/cpp/src/qpid/cluster/ExpiryPolicy.h b/qpid/cpp/src/qpid/cluster/ExpiryPolicy.h index 7fb63c731e..9f8b1a9236 100644 --- a/qpid/cpp/src/qpid/cluster/ExpiryPolicy.h +++ b/qpid/cpp/src/qpid/cluster/ExpiryPolicy.h @@ -27,11 +27,15 @@ #include "qpid/sys/Mutex.h" #include #include -#include +#include +#include namespace qpid { -namespace broker { class Timer; } +namespace broker { +class Timer; +class Message; +} namespace cluster { class Multicaster; @@ -42,7 +46,7 @@ class Multicaster; class ExpiryPolicy : public broker::ExpiryPolicy { public: - ExpiryPolicy(const boost::function & isLeader, Multicaster&, const MemberId&, broker::Timer&); + ExpiryPolicy(Multicaster&, const MemberId&, broker::Timer&); void willExpire(broker::Message&); @@ -54,18 +58,24 @@ class ExpiryPolicy : public broker::ExpiryPolicy // Cluster delivers expiry notice. void deliverExpire(uint64_t); + void setId(uint64_t id) { expiryId = id; } + uint64_t getId() const { return expiryId; } + + boost::optional getId(broker::Message&); + private: - sys::Mutex lock; - typedef std::set IdSet; + typedef std::map MessageIdMap; + typedef std::map IdMessageMap; struct Expired : public broker::ExpiryPolicy { bool hasExpired(broker::Message&); void willExpire(broker::Message&); }; - IdSet expired; + MessageIdMap unexpiredByMessage; + IdMessageMap unexpiredById; + uint64_t expiryId; boost::intrusive_ptr expiredPolicy; - boost::function isLeader; Multicaster& mcast; MemberId memberId; broker::Timer& timer; diff --git a/qpid/cpp/src/qpid/cluster/LockedConnectionMap.h b/qpid/cpp/src/qpid/cluster/LockedConnectionMap.h new file mode 100644 index 0000000000..8b2f6dae8e --- /dev/null +++ b/qpid/cpp/src/qpid/cluster/LockedConnectionMap.h @@ -0,0 +1,62 @@ +#ifndef QPID_CLUSTER_LOCKEDCONNECTIONMAP_H +#define QPID_CLUSTER_LOCKEDCONNECTIONMAP_H + +/* + * + * 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. + * + */ + +#include "types.h" +#include "qpid/sys/Mutex.h" +#include "Connection.h" + +namespace qpid { +namespace cluster { + +/** + * Thread safe map of connections. + */ +class LockedConnectionMap +{ + public: + void insert(const ConnectionPtr& c) { + sys::Mutex::ScopedLock l(lock); + map[c->getId()] = c; + } + + ConnectionPtr getErase(const ConnectionId& c) { + sys::Mutex::ScopedLock l(lock); + Map::iterator i = map.find(c); + if (i != map.end()) { + ConnectionPtr cp = i->second; + map.erase(i); + return cp; + } + else + return 0; + } + + private: + typedef std::map Map; + mutable sys::Mutex lock; + Map map; +}; +}} // namespace qpid::cluster + +#endif /*!QPID_CLUSTER_LOCKEDCONNECTIONMAP_H*/ diff --git a/qpid/cpp/src/qpid/cluster/McastFrameHandler.h b/qpid/cpp/src/qpid/cluster/McastFrameHandler.h new file mode 100644 index 0000000000..5127c31c84 --- /dev/null +++ b/qpid/cpp/src/qpid/cluster/McastFrameHandler.h @@ -0,0 +1,46 @@ +#ifndef QPID_CLUSTER_MCASTFRAMEHANDLER_H +#define QPID_CLUSTER_MCASTFRAMEHANDLER_H + +/* + * + * 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. + * + */ + +#include "types.h" +#include "Multicaster.h" +#include "qpid/framing/FrameHandler.h" + +namespace qpid { +namespace cluster { + +/** + * A frame handler that multicasts frames as CONTROL events. + */ +class McastFrameHandler : public framing::FrameHandler +{ + public: + McastFrameHandler(Multicaster& m, const ConnectionId& cid) : mcast(m), connection(cid) {} + void handle(framing::AMQFrame& frame) { mcast.mcastControl(frame, connection); } + private: + Multicaster& mcast; + ConnectionId connection; +}; +}} // namespace qpid::cluster + +#endif /*!QPID_CLUSTER_MCASTFRAMEHANDLER_H*/ diff --git a/qpid/cpp/src/qpid/cluster/Multicaster.cpp b/qpid/cpp/src/qpid/cluster/Multicaster.cpp index 239b3f5f35..f0738ab08f 100644 --- a/qpid/cpp/src/qpid/cluster/Multicaster.cpp +++ b/qpid/cpp/src/qpid/cluster/Multicaster.cpp @@ -24,6 +24,7 @@ #include "qpid/log/Statement.h" #include "qpid/sys/LatencyMetric.h" #include "qpid/framing/AMQBody.h" +#include "qpid/framing/AMQFrame.h" namespace qpid { namespace cluster { @@ -43,6 +44,11 @@ void Multicaster::mcastControl(const framing::AMQBody& body, const ConnectionId& mcast(Event::control(body, id)); } +void Multicaster::mcastControl(const framing::AMQFrame& frame, const ConnectionId& id) { + QPID_LOG(trace, "MCAST " << id << ": " << frame); + mcast(Event::control(frame, id)); +} + void Multicaster::mcastBuffer(const char* data, size_t size, const ConnectionId& id) { Event e(DATA, id, size); memcpy(e.getData(), data, size); diff --git a/qpid/cpp/src/qpid/cluster/Multicaster.h b/qpid/cpp/src/qpid/cluster/Multicaster.h index 1dfee47bd5..d1c3115977 100644 --- a/qpid/cpp/src/qpid/cluster/Multicaster.h +++ b/qpid/cpp/src/qpid/cluster/Multicaster.h @@ -50,6 +50,7 @@ class Multicaster boost::function onError ); void mcastControl(const framing::AMQBody& controlBody, const ConnectionId&); + void mcastControl(const framing::AMQFrame& controlFrame, const ConnectionId&); void mcastBuffer(const char*, size_t, const ConnectionId&); void mcast(const Event& e); /** End holding mode, held events are mcast */ diff --git a/qpid/cpp/src/qpid/cluster/OutputInterceptor.cpp b/qpid/cpp/src/qpid/cluster/OutputInterceptor.cpp index 45a369eea9..cd42446016 100644 --- a/qpid/cpp/src/qpid/cluster/OutputInterceptor.cpp +++ b/qpid/cpp/src/qpid/cluster/OutputInterceptor.cpp @@ -70,17 +70,12 @@ void OutputInterceptor::giveReadCredit(int32_t credit) { // Called in write thread when the IO layer has no more data to write. // We do nothing in the write thread, we run doOutput only on delivery // of doOutput requests. -bool OutputInterceptor::doOutput() { - QPID_LOG(trace, parent << " write idle."); - return false; -} +bool OutputInterceptor::doOutput() { return false; } // Delivery of doOutput allows us to run the real connection doOutput() // which tranfers frames to the codec for writing. // void OutputInterceptor::deliverDoOutput(size_t requested) { - QPID_LATENCY_RECORD("deliver do-output", *this); - QPID_LATENCY_CLEAR(*this); size_t buf = getBuffered(); if (parent.isLocal()) writeEstimate.delivered(requested, sent, buf); // Update the estimate. @@ -91,9 +86,7 @@ void OutputInterceptor::deliverDoOutput(size_t requested) { moreOutput = parent.getBrokerConnection().doOutput(); } while (sent < requested && moreOutput); sent += buf; // Include buffered data in the sent total. - - QPID_LOG(trace, "Delivered doOutput: requested=" << requested << " output=" << sent << " more=" << moreOutput); - + QPID_LOG(trace, parent << " delivereDoOutput: requested=" << requested << " sent=" << sent << " more=" << moreOutput); if (parent.isLocal() && moreOutput) { QPID_LOG(trace, parent << " deliverDoOutput - sending doOutput, more output available."); sendDoOutput(); diff --git a/qpid/cpp/src/qpid/cluster/PollableQueue.h b/qpid/cpp/src/qpid/cluster/PollableQueue.h index e0422e2449..a44c39ad85 100644 --- a/qpid/cpp/src/qpid/cluster/PollableQueue.h +++ b/qpid/cpp/src/qpid/cluster/PollableQueue.h @@ -52,6 +52,8 @@ template class PollableQueue : public sys::PollableQueue { } catch (const std::exception& e) { QPID_LOG(error, message << ": " << e.what()); + values.clear(); + this->stop(); error(); } } diff --git a/qpid/cpp/src/qpid/cluster/UpdateClient.cpp b/qpid/cpp/src/qpid/cluster/UpdateClient.cpp index 18746ccb7e..97eae7efa3 100644 --- a/qpid/cpp/src/qpid/cluster/UpdateClient.cpp +++ b/qpid/cpp/src/qpid/cluster/UpdateClient.cpp @@ -22,6 +22,8 @@ #include "Cluster.h" #include "ClusterMap.h" #include "Connection.h" +#include "Decoder.h" +#include "ExpiryPolicy.h" #include "qpid/client/SessionBase_0_10Access.h" #include "qpid/client/ConnectionAccess.h" #include "qpid/broker/Broker.h" @@ -86,33 +88,40 @@ void send(client::AsyncSession& s, const AMQBody& body) { // TODO aconway 2008-09-24: optimization: update connections/sessions in parallel. UpdateClient::UpdateClient(const MemberId& updater, const MemberId& updatee, const Url& url, - broker::Broker& broker, const ClusterMap& m, uint64_t frameId_, - const Cluster::Connections& cons, + broker::Broker& broker, const ClusterMap& m, ExpiryPolicy& expiry_, + const Cluster::ConnectionVector& cons, Decoder& decoder_, const boost::function& ok, const boost::function& fail, const client::ConnectionSettings& cs ) : updaterId(updater), updateeId(updatee), updateeUrl(url), updaterBroker(broker), map(m), - frameId(frameId_), connections(cons), + expiry(expiry_), connections(cons), decoder(decoder_), connection(catchUpConnection()), shadowConnection(catchUpConnection()), - done(ok), failed(fail) + done(ok), failed(fail), connectionSettings(cs) { connection.open(url, cs); - session = connection.newSession("update_shared"); + session = connection.newSession(UPDATE); } UpdateClient::~UpdateClient() {} // Reserved exchange/queue name for catch-up, avoid clashes with user queues/exchanges. -const std::string UpdateClient::UPDATE("qpid.qpid-update"); +const std::string UpdateClient::UPDATE("qpid.cluster-update"); + +void UpdateClient::run() { + try { + update(); + done(); + } catch (const std::exception& e) { + failed(e); + } + delete this; +} void UpdateClient::update() { QPID_LOG(debug, updaterId << " updating state to " << updateeId << " at " << updateeUrl); Broker& b = updaterBroker; b.getExchanges().eachExchange(boost::bind(&UpdateClient::updateExchange, this, _1)); - - // Update exchange is used to route messages to the proper queue without modifying routing key. - session.exchangeDeclare(arg::exchange=UPDATE, arg::type="fanout", arg::autoDelete=true); b.getQueues().eachQueue(boost::bind(&UpdateClient::updateQueue, this, _1)); // Update queue is used to transfer acquired messages that are no longer on their original queue. session.queueDeclare(arg::queue=UPDATE, arg::autoDelete=true); @@ -121,25 +130,15 @@ void UpdateClient::update() { std::for_each(connections.begin(), connections.end(), boost::bind(&UpdateClient::updateConnection, this, _1)); + ClusterConnectionProxy(session).expiryId(expiry.getId()); ClusterConnectionMembershipBody membership; map.toMethodBody(membership); - membership.setFrameId(frameId); AMQFrame frame(membership); client::ConnectionAccess::getImpl(connection)->handle(frame); connection.close(); QPID_LOG(debug, updaterId << " updated state to " << updateeId << " at " << updateeUrl); } -void UpdateClient::run() { - try { - update(); - done(); - } catch (const std::exception& e) { - failed(e); - } - delete this; -} - namespace { template std::string encode(const T& t) { std::string encoded; @@ -152,8 +151,7 @@ template std::string encode(const T& t) { void UpdateClient::updateExchange(const boost::shared_ptr& ex) { QPID_LOG(debug, updaterId << " updating exchange " << ex->getName()); - ClusterConnectionProxy proxy(session); - proxy.exchange(encode(*ex)); + ClusterConnectionProxy(session).exchange(encode(*ex)); } /** Bind a queue to the update exchange and update messges to it @@ -164,24 +162,40 @@ class MessageUpdater { bool haveLastPos; framing::SequenceNumber lastPos; client::AsyncSession session; - + ExpiryPolicy& expiry; + public: - MessageUpdater(const string& q, const client::AsyncSession s) : queue(q), haveLastPos(false), session(s) { + MessageUpdater(const string& q, const client::AsyncSession s, ExpiryPolicy& expiry_) : queue(q), haveLastPos(false), session(s), expiry(expiry_) { session.exchangeBind(queue, UpdateClient::UPDATE); } ~MessageUpdater() { - session.exchangeUnbind(queue, UpdateClient::UPDATE); + try { + session.exchangeUnbind(queue, UpdateClient::UPDATE); + } + catch (const std::exception& e) { + // Don't throw in a destructor. + QPID_LOG(error, "Unbinding update queue " << queue << ": " << e.what()); + } } void updateQueuedMessage(const broker::QueuedMessage& message) { + // Send the queue position if necessary. if (!haveLastPos || message.position - lastPos != 1) { ClusterConnectionProxy(session).queuePosition(queue, message.position.getValue()-1); haveLastPos = true; } lastPos = message.position; + + // Send the expiry ID if necessary. + if (message.payload->getProperties()->getTtl()) { + boost::optional expiryId = expiry.getId(*message.payload); + if (!expiryId) return; // Message already expired, don't replicate. + ClusterConnectionProxy(session).expiryId(*expiryId); + } + SessionBase_0_10Access sb(session); framing::MessageTransferBody transfer( framing::ProtocolVersion(), UpdateClient::UPDATE, message::ACCEPT_MODE_NONE, message::ACQUIRE_MODE_PRE_ACQUIRED); @@ -204,16 +218,13 @@ class MessageUpdater { void updateMessage(const boost::intrusive_ptr& message) { updateQueuedMessage(broker::QueuedMessage(0, message, haveLastPos? lastPos.getValue()+1 : 1)); } - - }; - void UpdateClient::updateQueue(const boost::shared_ptr& q) { QPID_LOG(debug, updaterId << " updating queue " << q->getName()); ClusterConnectionProxy proxy(session); proxy.queue(encode(*q)); - MessageUpdater updater(q->getName(), session); + MessageUpdater updater(q->getName(), session, expiry); q->eachMessage(boost::bind(&MessageUpdater::updateQueuedMessage, &updater, _1)); q->eachBinding(boost::bind(&UpdateClient::updateBinding, this, q->getName(), _1)); } @@ -228,13 +239,16 @@ void UpdateClient::updateConnection(const boost::intrusive_ptr& upda shadowConnection = catchUpConnection(); broker::Connection& bc = updateConnection->getBrokerConnection(); - // FIXME aconway 2008-10-20: What authentication info to use on reconnect? - shadowConnection.open(updateeUrl, bc.getUserId(), ""/*password*/, "/"/*vhost*/, bc.getFrameMax()); + connectionSettings.maxFrameSize = bc.getFrameMax(); + shadowConnection.open(updateeUrl, connectionSettings); bc.eachSessionHandler(boost::bind(&UpdateClient::updateSession, this, _1)); + // Safe to use decoder here because we are stalled for update. + std::pair fragment = decoder.get(updateConnection->getId()).getFragment(); ClusterConnectionProxy(shadowConnection).shadowReady( updateConnection->getId().getMember(), - reinterpret_cast(updateConnection->getId().getPointer()), - updateConnection->getBrokerConnection().getUserId() + updateConnection->getId().getNumber(), + bc.getUserId(), + string(fragment.first, fragment.second) ); shadowConnection.close(); QPID_LOG(debug, updaterId << " updated connection " << *updateConnection); @@ -269,7 +283,7 @@ void UpdateClient::updateSession(broker::SessionHandler& sh) { SequenceNumber received = ss->receiverGetReceived().command; if (inProgress) --received; - + // Reset command-sequence state. proxy.sessionState( ss->senderGetReplayPoint().command, @@ -285,9 +299,6 @@ void UpdateClient::updateSession(broker::SessionHandler& sh) { if (inProgress) { inProgress->getFrames().map(simpl->out); } - - // FIXME aconway 2008-09-23: update session replay list. - QPID_LOG(debug, updaterId << " updated session " << sh.getSession()->getId()); } @@ -322,7 +333,7 @@ void UpdateClient::updateUnacked(const broker::DeliveryRecord& dr) { // If the message is acquired then it is no longer on the // updatees queue, put it on the update queue for updatee to pick up. // - MessageUpdater(UPDATE, shadowSession).updateQueuedMessage(dr.getMessage()); + MessageUpdater(UPDATE, shadowSession, expiry).updateQueuedMessage(dr.getMessage()); } ClusterConnectionProxy(shadowSession).deliveryRecord( dr.getQueue()->getName(), @@ -341,8 +352,8 @@ void UpdateClient::updateUnacked(const broker::DeliveryRecord& dr) { class TxOpUpdater : public broker::TxOpConstVisitor, public MessageUpdater { public: - TxOpUpdater(UpdateClient& dc, client::AsyncSession s) - : MessageUpdater(UpdateClient::UPDATE, s), parent(dc), session(s), proxy(s) {} + TxOpUpdater(UpdateClient& dc, client::AsyncSession s, ExpiryPolicy& expiry) + : MessageUpdater(UpdateClient::UPDATE, s, expiry), parent(dc), session(s), proxy(s) {} void operator()(const broker::DtxAck& ) { throw InternalErrorException("DTX transactions not currently supported by cluster."); @@ -385,7 +396,7 @@ void UpdateClient::updateTxState(broker::SemanticState& s) { broker::TxBuffer::shared_ptr txBuffer = s.getTxBuffer(); if (txBuffer) { proxy.txStart(); - TxOpUpdater updater(*this, shadowSession); + TxOpUpdater updater(*this, shadowSession, expiry); txBuffer->accept(updater); proxy.txEnd(); } diff --git a/qpid/cpp/src/qpid/cluster/UpdateClient.h b/qpid/cpp/src/qpid/cluster/UpdateClient.h index 23f647c820..23d061b7e4 100644 --- a/qpid/cpp/src/qpid/cluster/UpdateClient.h +++ b/qpid/cpp/src/qpid/cluster/UpdateClient.h @@ -46,6 +46,7 @@ class SessionHandler; class DeliveryRecord; class SessionState; class SemanticState; +class Decoder; } // namespace broker @@ -54,6 +55,8 @@ namespace cluster { class Cluster; class Connection; class ClusterMap; +class Decoder; +class ExpiryPolicy; /** * A client that updates the contents of a local broker to a remote one using AMQP. @@ -63,8 +66,8 @@ class UpdateClient : public sys::Runnable { static const std::string UPDATE; // Name for special update queue and exchange. UpdateClient(const MemberId& updater, const MemberId& updatee, const Url&, - broker::Broker& donor, const ClusterMap& map, uint64_t sequence, - const std::vector >& , + broker::Broker& donor, const ClusterMap& map, ExpiryPolicy& expiry, + const std::vector >&, Decoder&, const boost::function& done, const boost::function& fail, const client::ConnectionSettings& @@ -92,12 +95,14 @@ class UpdateClient : public sys::Runnable { Url updateeUrl; broker::Broker& updaterBroker; ClusterMap map; - uint64_t frameId; + ExpiryPolicy& expiry; std::vector > connections; + Decoder& decoder; client::Connection connection, shadowConnection; client::AsyncSession session, shadowSession; boost::function done; boost::function failed; + client::ConnectionSettings connectionSettings; }; }} // namespace qpid::cluster diff --git a/qpid/cpp/src/qpid/cluster/UpdateExchange.h b/qpid/cpp/src/qpid/cluster/UpdateExchange.h new file mode 100644 index 0000000000..7a4a484c8a --- /dev/null +++ b/qpid/cpp/src/qpid/cluster/UpdateExchange.h @@ -0,0 +1,45 @@ +#ifndef QPID_CLUSTER_UPDATEEXCHANGE_H +#define QPID_CLUSTER_UPDATEEXCHANGE_H + +/* + * + * 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. + * + */ + +#include "UpdateClient.h" +#include "qpid/broker/FanOutExchange.h" + + +namespace qpid { +namespace cluster { + +/** + * A keyless exchange (like fanout exchange) that does not modify deliver-properties.exchange + * on messages. + */ +class UpdateExchange : public broker::FanOutExchange +{ + public: + UpdateExchange(management::Manageable* parent) : broker::Exchange(UpdateClient::UPDATE, parent), broker::FanOutExchange(UpdateClient::UPDATE, parent) {} + void setProperties(const boost::intrusive_ptr&) {} +}; + +}} // namespace qpid::cluster + +#endif /*!QPID_CLUSTER_UPDATEEXCHANGE_H*/ diff --git a/qpid/cpp/src/qpid/cluster/types.h b/qpid/cpp/src/qpid/cluster/types.h index d1d6fdc427..c19152e4d8 100644 --- a/qpid/cpp/src/qpid/cluster/types.h +++ b/qpid/cpp/src/qpid/cluster/types.h @@ -68,16 +68,17 @@ inline bool operator==(const cpg_address& caddr, const MemberId& id) { return id std::ostream& operator<<(std::ostream&, const MemberId&); -struct ConnectionId : public std::pair { - ConnectionId(const MemberId& m=MemberId(), Connection* c=0) : std::pair (m,c) {} - ConnectionId(uint64_t m, uint64_t c) - : std::pair(MemberId(m), reinterpret_cast(c)) {} +struct ConnectionId : public std::pair { + ConnectionId(const MemberId& m=MemberId(), uint64_t c=0) : std::pair (m,c) {} + ConnectionId(uint64_t m, uint64_t c) : std::pair(MemberId(m), c) {} MemberId getMember() const { return first; } - Connection* getPointer() const { return second; } + uint64_t getNumber() const { return second; } }; std::ostream& operator<<(std::ostream&, const ConnectionId&); +std::ostream& operator<<(std::ostream&, EventType); + }} // namespace qpid::cluster #endif /*!QPID_CLUSTER_TYPES_H*/ diff --git a/qpid/cpp/src/qpid/console/ClassKey.cpp b/qpid/cpp/src/qpid/console/ClassKey.cpp index 1780b03f94..b97eb3ca44 100644 --- a/qpid/cpp/src/qpid/console/ClassKey.cpp +++ b/qpid/cpp/src/qpid/console/ClassKey.cpp @@ -21,6 +21,7 @@ #include "ClassKey.h" #include +#include using namespace std; using namespace qpid::console; diff --git a/qpid/cpp/src/qpid/framing/AMQFrame.cpp b/qpid/cpp/src/qpid/framing/AMQFrame.cpp index 80c8e0b56d..9473b2a513 100644 --- a/qpid/cpp/src/qpid/framing/AMQFrame.cpp +++ b/qpid/cpp/src/qpid/framing/AMQFrame.cpp @@ -41,7 +41,7 @@ AMQFrame::AMQFrame(const boost::intrusive_ptr& b) : body(b) { init(); } AMQFrame::AMQFrame(const AMQBody& b) : body(b.clone()) { init(); } -AMQFrame::~AMQFrame() {} +AMQFrame::~AMQFrame() { init(); } AMQBody* AMQFrame::getBody() { // Non-const AMQBody* may be used to modify the body. diff --git a/qpid/cpp/src/qpid/framing/AMQFrame.h b/qpid/cpp/src/qpid/framing/AMQFrame.h index cf384e61e8..34319e7ed4 100644 --- a/qpid/cpp/src/qpid/framing/AMQFrame.h +++ b/qpid/cpp/src/qpid/framing/AMQFrame.h @@ -93,9 +93,6 @@ class AMQFrame : public AMQDataBlock, public sys::LatencyMetricTimestamp /** Must point to at least DECODE_SIZE_MIN bytes of data */ static uint16_t decodeSize(char* data); - uint64_t getClusterId() const { return clusterId; } - void setClusterId(uint64_t id) { clusterId = id; } - private: void init(); @@ -107,7 +104,6 @@ class AMQFrame : public AMQDataBlock, public sys::LatencyMetricTimestamp bool bos : 1; bool eos : 1; mutable uint32_t encodedSizeCache; - uint64_t clusterId; // Used to identify frames in a clustered broekr. }; QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream&, const AMQFrame&); diff --git a/qpid/cpp/src/qpid/framing/FrameDecoder.cpp b/qpid/cpp/src/qpid/framing/FrameDecoder.cpp index cbdac181e9..1e73ee1e51 100644 --- a/qpid/cpp/src/qpid/framing/FrameDecoder.cpp +++ b/qpid/cpp/src/qpid/framing/FrameDecoder.cpp @@ -21,8 +21,9 @@ #include "FrameDecoder.h" #include "Buffer.h" #include "qpid/log/Statement.h" -#include #include "qpid/framing/reply_exceptions.h" +#include +#include namespace qpid { namespace framing { @@ -67,4 +68,13 @@ bool FrameDecoder::decode(Buffer& buffer) { return false; } +void FrameDecoder::setFragment(const char* data, size_t size) { + fragment.resize(size); + ::memcpy(&fragment[0], data, size); +} + +std::pair FrameDecoder::getFragment() const { + return std::pair(&fragment[0], fragment.size()); +} + }} // namespace qpid::framing diff --git a/qpid/cpp/src/qpid/framing/FrameDecoder.h b/qpid/cpp/src/qpid/framing/FrameDecoder.h index 7f974dadc3..961cc666a9 100644 --- a/qpid/cpp/src/qpid/framing/FrameDecoder.h +++ b/qpid/cpp/src/qpid/framing/FrameDecoder.h @@ -35,9 +35,16 @@ class FrameDecoder { public: bool decode(Buffer& buffer); - AMQFrame frame; + const AMQFrame& getFrame() const { return frame; } + AMQFrame& getFrame() { return frame; } + + void setFragment(const char*, size_t); + std::pair getFragment() const; + private: std::vector fragment; + AMQFrame frame; + }; }} // namespace qpid::framing diff --git a/qpid/cpp/src/qpid/framing/Uuid.h b/qpid/cpp/src/qpid/framing/Uuid.h index 42dc31a26d..fe0c32dc0b 100644 --- a/qpid/cpp/src/qpid/framing/Uuid.h +++ b/qpid/cpp/src/qpid/framing/Uuid.h @@ -19,8 +19,9 @@ * */ -#include "qpid/sys/uuid.h" #include "qpid/CommonImportExport.h" +#include "qpid/sys/uuid.h" +#include "qpid/sys/IntegerTypes.h" #include diff --git a/qpid/cpp/src/qpid/log/Selector.cpp b/qpid/cpp/src/qpid/log/Selector.cpp index 4d1c5b6e0c..0a629edc3e 100644 --- a/qpid/cpp/src/qpid/log/Selector.cpp +++ b/qpid/cpp/src/qpid/log/Selector.cpp @@ -20,6 +20,7 @@ #include "Options.h" #include #include +#include namespace qpid { namespace log { diff --git a/qpid/cpp/src/qpid/log/posix/SinkOptions.cpp b/qpid/cpp/src/qpid/log/posix/SinkOptions.cpp index 9d51358e2e..985cb32c5c 100644 --- a/qpid/cpp/src/qpid/log/posix/SinkOptions.cpp +++ b/qpid/cpp/src/qpid/log/posix/SinkOptions.cpp @@ -42,10 +42,14 @@ public: struct NameValue { const char* name; int value; }; NameValue nameValue[] = { { "AUTH", LOG_AUTH }, +#ifdef HAVE_LOG_AUTHPRIV { "AUTHPRIV", LOG_AUTHPRIV }, +#endif { "CRON", LOG_CRON }, { "DAEMON", LOG_DAEMON }, +#ifdef HAVE_LOG_FTP { "FTP", LOG_FTP }, +#endif { "KERN", LOG_KERN }, { "LOCAL0", LOG_LOCAL0 }, { "LOCAL1", LOG_LOCAL1 }, @@ -72,7 +76,7 @@ public: int value(const string& name) const { string key(name); - transform(key.begin(), key.end(), key.begin(), ::toupper); + std::transform(key.begin(), key.end(), key.begin(), ::toupper); ByName::const_iterator i = byName.find(key); if (i == byName.end()) throw Exception("Not a valid syslog facility: " + name); diff --git a/qpid/cpp/src/qpid/management/ManagementBroker.cpp b/qpid/cpp/src/qpid/management/ManagementBroker.cpp index 0f96e97fb0..729826e0cd 100644 --- a/qpid/cpp/src/qpid/management/ManagementBroker.cpp +++ b/qpid/cpp/src/qpid/management/ManagementBroker.cpp @@ -80,7 +80,7 @@ ManagementBroker::RemoteAgent::~RemoteAgent () } ManagementBroker::ManagementBroker () : - threadPoolSize(1), interval(10), broker(0) + threadPoolSize(1), interval(10), broker(0), startTime(uint64_t(Duration(now()))) { nextObjectId = 1; brokerBank = 1; @@ -346,6 +346,9 @@ void ManagementBroker::periodicProcessing (void) string routingKey; list > deleteList; + uint64_t uptime = uint64_t(Duration(now())) - startTime; + static_cast<_qmf::Broker*>(broker->GetManagementObject())->set_uptime(uptime); + moveNewObjectsLH(); if (clientWasAdded) { @@ -844,6 +847,9 @@ void ManagementBroker::handleGetQueryLH (Buffer& inBuffer, string replyToKey, ui Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE); uint32_t outLen; + if (object->getConfigChanged() || object->getInstChanged()) + object->setUpdateTime(); + encodeHeader(outBuffer, 'g', sequence); object->writeProperties(outBuffer); object->writeStatistics(outBuffer, true); @@ -865,6 +871,9 @@ void ManagementBroker::handleGetQueryLH (Buffer& inBuffer, string replyToKey, ui Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE); uint32_t outLen; + if (object->getConfigChanged() || object->getInstChanged()) + object->setUpdateTime(); + encodeHeader(outBuffer, 'g', sequence); object->writeProperties(outBuffer); object->writeStatistics(outBuffer, true); diff --git a/qpid/cpp/src/qpid/management/ManagementBroker.h b/qpid/cpp/src/qpid/management/ManagementBroker.h index f65d6a345e..a57f73be15 100644 --- a/qpid/cpp/src/qpid/management/ManagementBroker.h +++ b/qpid/cpp/src/qpid/management/ManagementBroker.h @@ -182,6 +182,7 @@ private: uint32_t nextRemoteBank; uint32_t nextRequestSequence; bool clientWasAdded; + const uint64_t startTime; std::auto_ptr allocator; diff --git a/qpid/cpp/src/qpid/replication/ReplicatingEventListener.cpp b/qpid/cpp/src/qpid/replication/ReplicatingEventListener.cpp index 2d8af3b052..e3990a13cc 100644 --- a/qpid/cpp/src/qpid/replication/ReplicatingEventListener.cpp +++ b/qpid/cpp/src/qpid/replication/ReplicatingEventListener.cpp @@ -57,7 +57,6 @@ void ReplicatingEventListener::deliverDequeueMessage(const QueuedMessage& dequeu { FieldTable headers; headers.setString(REPLICATION_TARGET_QUEUE, dequeued.queue->getName()); - headers.setInt(REPLICATION_EVENT_SEQNO, ++sequence); headers.setInt(REPLICATION_EVENT_TYPE, DEQUEUE); headers.setInt(DEQUEUED_MESSAGE_POSITION, dequeued.position); boost::intrusive_ptr msg(createMessage(headers)); @@ -69,7 +68,6 @@ void ReplicatingEventListener::deliverEnqueueMessage(const QueuedMessage& enqueu boost::intrusive_ptr msg(cloneMessage(*(enqueued.queue), enqueued.payload)); FieldTable& headers = msg->getProperties()->getApplicationHeaders(); headers.setString(REPLICATION_TARGET_QUEUE, enqueued.queue->getName()); - headers.setInt(REPLICATION_EVENT_SEQNO, ++sequence); headers.setInt(REPLICATION_EVENT_TYPE, ENQUEUE); queue->deliver(msg); } @@ -131,12 +129,14 @@ void ReplicatingEventListener::initialize(Plugin::Target& target) { Broker* broker = dynamic_cast(&target); if (broker && !options.queue.empty()) { + broker->addFinalizer(boost::bind(&ReplicatingEventListener::shutdown, this)); if (options.createQueue) { queue = broker->getQueues().declare(options.queue).first; } else { queue = broker->getQueues().find(options.queue); } if (queue) { + queue->insertSequenceNumbers(REPLICATION_EVENT_SEQNO); QueueEvents::EventListener callback = boost::bind(&ReplicatingEventListener::handle, this, _1); broker->getQueueEvents().registerListener(options.name, callback); QPID_LOG(info, "Registered replicating queue event listener"); @@ -147,6 +147,7 @@ void ReplicatingEventListener::initialize(Plugin::Target& target) } void ReplicatingEventListener::earlyInitialize(Target&) {} +void ReplicatingEventListener::shutdown() { queue.reset(); } ReplicatingEventListener::PluginOptions::PluginOptions() : Options("Queue Replication Options"), name("replicator"), diff --git a/qpid/cpp/src/qpid/replication/ReplicatingEventListener.h b/qpid/cpp/src/qpid/replication/ReplicatingEventListener.h index 7616c7ac8a..3d8f23e7ac 100644 --- a/qpid/cpp/src/qpid/replication/ReplicatingEventListener.h +++ b/qpid/cpp/src/qpid/replication/ReplicatingEventListener.h @@ -58,10 +58,10 @@ class ReplicatingEventListener : public Plugin PluginOptions options; qpid::broker::Queue::shared_ptr queue; - qpid::framing::SequenceNumber sequence; void deliverDequeueMessage(const qpid::broker::QueuedMessage& enqueued); void deliverEnqueueMessage(const qpid::broker::QueuedMessage& enqueued); + void shutdown(); boost::intrusive_ptr createMessage(const qpid::framing::FieldTable& headers); boost::intrusive_ptr cloneMessage(qpid::broker::Queue& queue, diff --git a/qpid/cpp/src/qpid/replication/ReplicationExchange.cpp b/qpid/cpp/src/qpid/replication/ReplicationExchange.cpp index 639cfb5d2e..88c94ad7ba 100644 --- a/qpid/cpp/src/qpid/replication/ReplicationExchange.cpp +++ b/qpid/cpp/src/qpid/replication/ReplicationExchange.cpp @@ -34,11 +34,13 @@ using namespace qpid::broker; using namespace qpid::framing; using namespace qpid::replication::constants; +const std::string SEQUENCE_VALUE("qpid.replication-event.sequence"); ReplicationExchange::ReplicationExchange(const std::string& name, bool durable, const FieldTable& args, QueueRegistry& qr, Manageable* parent) - : Exchange(name, durable, args, parent), queues(qr), init(false) {} + : Exchange(name, durable, args, parent), queues(qr), sequence(args.getAsInt64(SEQUENCE_VALUE)), init(false) + {} std::string ReplicationExchange::getType() const { return typeName; } @@ -68,26 +70,33 @@ void ReplicationExchange::handleEnqueueEvent(const FieldTable* args, Deliverable { std::string queueName = args->getAsString(REPLICATION_TARGET_QUEUE); Queue::shared_ptr queue = queues.find(queueName); - FieldTable& headers = msg.getMessage().getProperties()->getApplicationHeaders(); - headers.erase(REPLICATION_TARGET_QUEUE); - headers.erase(REPLICATION_EVENT_SEQNO); - headers.erase(REPLICATION_EVENT_TYPE); - msg.deliverTo(queue); - QPID_LOG(debug, "Enqueued replicated message onto " << queue); + if (queue) { + FieldTable& headers = msg.getMessage().getProperties()->getApplicationHeaders(); + headers.erase(REPLICATION_TARGET_QUEUE); + headers.erase(REPLICATION_EVENT_SEQNO); + headers.erase(REPLICATION_EVENT_TYPE); + msg.deliverTo(queue); + QPID_LOG(debug, "Enqueued replicated message onto " << queueName); + } else { + QPID_LOG(error, "Cannot enqueue replicated message. Queue " << queueName << " does not exist"); + } } void ReplicationExchange::handleDequeueEvent(const FieldTable* args) { std::string queueName = args->getAsString(REPLICATION_TARGET_QUEUE); Queue::shared_ptr queue = queues.find(queueName); - SequenceNumber position(args->getAsInt(DEQUEUED_MESSAGE_POSITION)); - - QueuedMessage dequeued; - if (queue->acquireMessageAt(position, dequeued)) { - queue->dequeue(0, dequeued); - QPID_LOG(debug, "Processed replicated 'dequeue' event from " << queueName << " at position " << position); + if (queue) { + SequenceNumber position(args->getAsInt(DEQUEUED_MESSAGE_POSITION)); + QueuedMessage dequeued; + if (queue->acquireMessageAt(position, dequeued)) { + queue->dequeue(0, dequeued); + QPID_LOG(debug, "Processed replicated 'dequeue' event from " << queueName << " at position " << position); + } else { + QPID_LOG(warning, "Could not acquire message " << position << " from " << queueName); + } } else { - QPID_LOG(warning, "Could not acquire message " << position << " from " << queueName); + QPID_LOG(error, "Cannot process replicated 'dequeue' event. Queue " << queueName << " does not exist"); } } @@ -128,6 +137,13 @@ bool ReplicationExchange::isBound(Queue::shared_ptr /*queue*/, const string* con const std::string ReplicationExchange::typeName("replication"); +void ReplicationExchange::encode(Buffer& buffer) const +{ + args.setInt64(std::string(SEQUENCE_VALUE), sequence); + Exchange::encode(buffer); +} + + struct ReplicationExchangePlugin : Plugin { Broker* broker; diff --git a/qpid/cpp/src/qpid/replication/ReplicationExchange.h b/qpid/cpp/src/qpid/replication/ReplicationExchange.h index 897e4a954e..4cc45ed5f5 100644 --- a/qpid/cpp/src/qpid/replication/ReplicationExchange.h +++ b/qpid/cpp/src/qpid/replication/ReplicationExchange.h @@ -22,6 +22,7 @@ * */ #include "qpid/broker/Exchange.h" +#include "qpid/framing/Buffer.h" #include "qpid/framing/SequenceNumber.h" namespace qpid { @@ -58,6 +59,7 @@ class ReplicationExchange : public qpid::broker::Exchange bool isDuplicate(const qpid::framing::FieldTable* args); void handleEnqueueEvent(const qpid::framing::FieldTable* args, qpid::broker::Deliverable& msg); void handleDequeueEvent(const qpid::framing::FieldTable* args); + void encode(framing::Buffer& buffer) const; }; }} // namespace qpid::replication diff --git a/qpid/cpp/src/qpid/sys/Codec.h b/qpid/cpp/src/qpid/sys/Codec.h index f9645f554e..ace721fbcc 100644 --- a/qpid/cpp/src/qpid/sys/Codec.h +++ b/qpid/cpp/src/qpid/sys/Codec.h @@ -38,11 +38,11 @@ class Codec * @return may be less than size if there was incomplete * data at the end of the buffer. */ - virtual size_t decode(const char* buffer, size_t size) = 0; + virtual std::size_t decode(const char* buffer, std::size_t size) = 0; /** Encode into buffer, return number of bytes encoded */ - virtual size_t encode(const char* buffer, size_t size) = 0; + virtual std::size_t encode(const char* buffer, std::size_t size) = 0; /** Return true if we have data to encode */ virtual bool canEncode() = 0; diff --git a/qpid/cpp/src/qpid/sys/ConnectionOutputHandlerPtr.h b/qpid/cpp/src/qpid/sys/ConnectionOutputHandlerPtr.h index df6de89982..32809d86a1 100644 --- a/qpid/cpp/src/qpid/sys/ConnectionOutputHandlerPtr.h +++ b/qpid/cpp/src/qpid/sys/ConnectionOutputHandlerPtr.h @@ -30,7 +30,7 @@ namespace sys { /** * A ConnectionOutputHandler that delegates to another * ConnectionOutputHandler. Allows the "real" ConnectionOutputHandler - * to be changed modified without updating all the pointers/references + * to be changed without updating all the pointers/references * using the ConnectionOutputHandlerPtr */ class ConnectionOutputHandlerPtr : public ConnectionOutputHandler diff --git a/qpid/cpp/src/qpid/sys/CopyOnWriteArray.h b/qpid/cpp/src/qpid/sys/CopyOnWriteArray.h index a09ee9d441..577a475afd 100644 --- a/qpid/cpp/src/qpid/sys/CopyOnWriteArray.h +++ b/qpid/cpp/src/qpid/sys/CopyOnWriteArray.h @@ -80,7 +80,7 @@ public: bool add_unless(T& t, F f) { Mutex::ScopedLock l(lock); - if (array && find_if(array->begin(), array->end(), f) != array->end()) { + if (array && std::find_if(array->begin(), array->end(), f) != array->end()) { return false; } else { ArrayPtr copy(array ? new std::vector(*array) : new std::vector()); diff --git a/qpid/cpp/src/qpid/sys/DispatchHandle.cpp b/qpid/cpp/src/qpid/sys/DispatchHandle.cpp index cbdee7eda6..cd7dec7fa6 100644 --- a/qpid/cpp/src/qpid/sys/DispatchHandle.cpp +++ b/qpid/cpp/src/qpid/sys/DispatchHandle.cpp @@ -21,6 +21,8 @@ #include "DispatchHandle.h" +#include + #include #include @@ -29,7 +31,6 @@ namespace qpid { namespace sys { DispatchHandle::~DispatchHandle() { - stopWatch(); } void DispatchHandle::startWatch(Poller::shared_ptr poller0) { @@ -37,13 +38,21 @@ void DispatchHandle::startWatch(Poller::shared_ptr poller0) { bool w = writableCallback; ScopedLock lock(stateLock); - assert(state == IDLE); + assert(state == IDLE || state == DELAYED_IDLE); // If no callbacks set then do nothing (that is what we were asked to do!) // TODO: Maybe this should be an assert instead if (!r && !w) { - state = INACTIVE; - return; + switch (state) { + case IDLE: + state = INACTIVE; + return; + case DELAYED_IDLE: + state = DELAYED_INACTIVE; + return; + default: + assert(state == IDLE || state == DELAYED_IDLE); + } } Poller::Direction d = r ? @@ -53,9 +62,20 @@ void DispatchHandle::startWatch(Poller::shared_ptr poller0) { poller = poller0; poller->addFd(*this, d); - state = r ? - (w ? ACTIVE_RW : ACTIVE_R) : - ACTIVE_W; + switch (state) { + case IDLE: + state = r ? + (w ? ACTIVE_RW : ACTIVE_R) : + ACTIVE_W; + return; + case DELAYED_IDLE: + state = r ? + (w ? DELAYED_RW : DELAYED_R) : + DELAYED_W; + return; + default: + assert(state == IDLE || state == DELAYED_IDLE); + } } void DispatchHandle::rewatch() { @@ -93,6 +113,8 @@ void DispatchHandle::rewatch() { case ACTIVE_RW: // Don't need to do anything already waiting for readable/writable break; + case ACTIVE_DELETE: + assert(state != ACTIVE_DELETE); } } @@ -130,6 +152,8 @@ void DispatchHandle::rewatchRead() { poller->modFd(*this, Poller::INOUT); state = ACTIVE_RW; break; + case ACTIVE_DELETE: + assert(state != ACTIVE_DELETE); } } @@ -167,6 +191,8 @@ void DispatchHandle::rewatchWrite() { case ACTIVE_RW: // Nothing to do: already waiting for writable break; + case ACTIVE_DELETE: + assert(state != ACTIVE_DELETE); } } @@ -203,6 +229,8 @@ void DispatchHandle::unwatchRead() { case ACTIVE_W: case INACTIVE: break; + case ACTIVE_DELETE: + assert(state != ACTIVE_DELETE); } } @@ -239,6 +267,8 @@ void DispatchHandle::unwatchWrite() { case ACTIVE_R: case INACTIVE: break; + case ACTIVE_DELETE: + assert(state != ACTIVE_DELETE); } } @@ -261,6 +291,8 @@ void DispatchHandle::unwatch() { poller->modFd(*this, Poller::NONE); state = INACTIVE; break; + case ACTIVE_DELETE: + assert(state != ACTIVE_DELETE); } } @@ -280,47 +312,72 @@ void DispatchHandle::stopWatch() { default: state = IDLE; break; + case ACTIVE_DELETE: + assert(state != ACTIVE_DELETE); } assert(poller); poller->delFd(*this); poller.reset(); } +// If we are already in the IDLE state we can't do the callback as we might +// race to delete and callback at the same time +// TODO: might be able to fix this by adding a new state, but would make +// the state machine even more complex void DispatchHandle::call(Callback iCb) { assert(iCb); ScopedLock lock(stateLock); - interruptedCallbacks.push(iCb); - - (void) poller->interrupt(*this); + switch (state) { + case IDLE: + case ACTIVE_DELETE: + assert(false); + return; + default: + interruptedCallbacks.push(iCb); + assert(poller); + (void) poller->interrupt(*this); + } } // The slightly strange switch structure // is to ensure that the lock is released before // we do the delete void DispatchHandle::doDelete() { - // Ensure that we're no longer watching anything - stopWatch(); - - // If we're in the middle of a callback defer the delete { ScopedLock lock(stateLock); + // Ensure that we're no longer watching anything switch (state) { + case DELAYED_R: + case DELAYED_W: + case DELAYED_RW: + case DELAYED_INACTIVE: + assert(poller); + poller->delFd(*this); + poller.reset(); + // Fallthrough case DELAYED_IDLE: - case DELAYED_DELETE: state = DELAYED_DELETE; + // Fallthrough + case DELAYED_DELETE: + case ACTIVE_DELETE: return; case IDLE: break; default: - // Can only get out of stopWatch() in DELAYED_IDLE/DELAYED_DELETE/IDLE states - assert(false); + state = ACTIVE_DELETE; + assert(poller); + (void) poller->interrupt(*this); + poller->delFd(*this); + return; } } - // If we're not then do it right away + // If we're IDLE we can do this right away delete this; } void DispatchHandle::processEvent(Poller::EventType type) { + CallbackQueue callbacks; + // Note that we are now doing the callbacks { ScopedLock lock(stateLock); @@ -336,6 +393,16 @@ void DispatchHandle::processEvent(Poller::EventType type) { case ACTIVE_RW: state = DELAYED_RW; break; + case ACTIVE_DELETE: + // Need to make sure we clean up any pending callbacks in this case + std::swap(callbacks, interruptedCallbacks); + goto saybyebye; + // Can get here in idle if we are stopped in a different thread + // just after we return with this handle in Poller::wait + case IDLE: + // Can get here in INACTIVE if a non connection thread unwatches + // whilst we were stuck in the above lock + case INACTIVE: // Can only get here in a DELAYED_* state in the rare case // that we're already here for reading and we get activated for // writing and we can write (it might be possible the other way @@ -348,9 +415,9 @@ void DispatchHandle::processEvent(Poller::EventType type) { case DELAYED_IDLE: case DELAYED_DELETE: return; - default: - assert(false); } + + std::swap(callbacks, interruptedCallbacks); } // Do callbacks - whilst we are doing the callbacks we are prevented from processing @@ -378,8 +445,8 @@ void DispatchHandle::processEvent(Poller::EventType type) { break; case Poller::INTERRUPTED: { - ScopedLock lock(stateLock); - assert(interruptedCallbacks.size() > 0); + // We could only be interrupted if we also had a callback to do + assert(callbacks.size() > 0); // We'll actually do the interrupt below } break; @@ -387,16 +454,18 @@ void DispatchHandle::processEvent(Poller::EventType type) { assert(false); } - { - ScopedLock lock(stateLock); - // If we've got a pending interrupt do it now - while (interruptedCallbacks.size() > 0) { - Callback cb = interruptedCallbacks.front(); + // If we have any callbacks do them now - + // (because we use a copy from before the previous callbacks we won't + // do anything yet that was just added) + while (callbacks.size() > 0) { + Callback cb = callbacks.front(); assert(cb); cb(*this); - interruptedCallbacks.pop(); + callbacks.pop(); } + { + ScopedLock lock(stateLock); // If any of the callbacks re-enabled reading/writing then actually // do it now switch (state) { @@ -425,7 +494,9 @@ void DispatchHandle::processEvent(Poller::EventType type) { case DELAYED_DELETE: break; } - } + } + +saybyebye: delete this; } diff --git a/qpid/cpp/src/qpid/sys/DispatchHandle.h b/qpid/cpp/src/qpid/sys/DispatchHandle.h index 63cd25f8fd..bc9f98775e 100644 --- a/qpid/cpp/src/qpid/sys/DispatchHandle.h +++ b/qpid/cpp/src/qpid/sys/DispatchHandle.h @@ -65,6 +65,7 @@ private: Mutex stateLock; enum { IDLE, INACTIVE, ACTIVE_R, ACTIVE_W, ACTIVE_RW, + ACTIVE_DELETE, DELAYED_IDLE, DELAYED_INACTIVE, DELAYED_R, DELAYED_W, DELAYED_RW, DELAYED_DELETE } state; diff --git a/qpid/cpp/src/qpid/sys/PollableQueue.h b/qpid/cpp/src/qpid/sys/PollableQueue.h index a23cc5137a..f8acf0a5f6 100644 --- a/qpid/cpp/src/qpid/sys/PollableQueue.h +++ b/qpid/cpp/src/qpid/sys/PollableQueue.h @@ -53,7 +53,7 @@ class PollableQueue { * @param values Queue of values to process. Any items remaining * on return from Callback are put back on the queue. */ - typedef boost::function Callback; + typedef boost::function Callback; /** * Constructor; sets necessary parameters. diff --git a/qpid/cpp/src/qpid/sys/Poller.h b/qpid/cpp/src/qpid/sys/Poller.h index 49d7b321d7..825ad8bfed 100644 --- a/qpid/cpp/src/qpid/sys/Poller.h +++ b/qpid/cpp/src/qpid/sys/Poller.h @@ -86,8 +86,9 @@ public: // with the handle and the INTERRUPTED event type // if it returns false then the handle is not being monitored by the poller // - This can either be because it has just received an event which has been - // reported and has not been reenabled since. Or because it was removed - // from the monitoring set + // reported and has not been reenabled since. + // - Because it was removed from the monitoring set + // - Or because it is already being interrupted QPID_COMMON_EXTERN bool interrupt(PollerHandle& handle); // Poller run loop diff --git a/qpid/cpp/src/qpid/sys/Socket.h b/qpid/cpp/src/qpid/sys/Socket.h index a81d823d0c..e6555f5774 100644 --- a/qpid/cpp/src/qpid/sys/Socket.h +++ b/qpid/cpp/src/qpid/sys/Socket.h @@ -27,8 +27,6 @@ #include "qpid/CommonImportExport.h" #include -struct sockaddr; - namespace qpid { namespace sys { @@ -93,7 +91,7 @@ public: /** Accept a connection from a socket that is already listening * and has an incoming connection */ - QPID_COMMON_EXTERN Socket* accept(struct sockaddr *addr, socklen_t *addrlen) const; + QPID_COMMON_EXTERN Socket* accept() const; // TODO The following are raw operations, maybe they need better wrapping? QPID_COMMON_EXTERN int read(void *buf, size_t count) const; diff --git a/qpid/cpp/src/qpid/sys/Thread.h b/qpid/cpp/src/qpid/sys/Thread.h index 14e2fef1c0..b532d4d80a 100644 --- a/qpid/cpp/src/qpid/sys/Thread.h +++ b/qpid/cpp/src/qpid/sys/Thread.h @@ -28,6 +28,8 @@ # define QPID_TSS __declspec(thread) #elif defined (__GNUC__) # define QPID_TSS __thread +#elif defined (__SUNPRO_CC) +# define QPID_TSS __thread #else # error "Dont know how to define QPID_TSS for this platform" #endif diff --git a/qpid/cpp/src/qpid/sys/epoll/EpollPoller.cpp b/qpid/cpp/src/qpid/sys/epoll/EpollPoller.cpp index 10705e12da..42b5d8b1aa 100644 --- a/qpid/cpp/src/qpid/sys/epoll/EpollPoller.cpp +++ b/qpid/cpp/src/qpid/sys/epoll/EpollPoller.cpp @@ -54,17 +54,20 @@ class PollerHandlePrivate { INACTIVE, HUNGUP, MONITORED_HUNGUP, + INTERRUPTED, DELETED }; int fd; ::__uint32_t events; + PollerHandle* pollerHandle; FDStat stat; Mutex lock; - PollerHandlePrivate(int f) : + PollerHandlePrivate(int f, PollerHandle* p) : fd(f), events(0), + pollerHandle(p), stat(ABSENT) { } @@ -101,6 +104,14 @@ class PollerHandlePrivate { stat = HUNGUP; } + bool isInterrupted() const { + return stat == INTERRUPTED; + } + + void setInterrupted() { + stat = INTERRUPTED; + } + bool isDeleted() const { return stat == DELETED; } @@ -111,7 +122,7 @@ class PollerHandlePrivate { }; PollerHandle::PollerHandle(const IOHandle& h) : - impl(new PollerHandlePrivate(toFd(h.impl))) + impl(new PollerHandlePrivate(toFd(h.impl), this)) {} PollerHandle::~PollerHandle() { @@ -120,6 +131,10 @@ PollerHandle::~PollerHandle() { if (impl->isDeleted()) { return; } + if (impl->isInterrupted()) { + impl->setDeleted(); + return; + } if (impl->isActive()) { impl->setDeleted(); } @@ -243,23 +258,21 @@ class PollerPrivate { ::close(epollFd); } - void interrupt(bool all=false) { + void interrupt() { ::epoll_event epe; - if (all) { - // Not EPOLLONESHOT, so we eventually get all threads - epe.events = ::EPOLLIN; - epe.data.u64 = 0; // Keep valgrind happy - } else { - // Use EPOLLONESHOT so we only wake a single thread - epe.events = ::EPOLLIN | ::EPOLLONESHOT; - epe.data.u64 = 0; // Keep valgrind happy - epe.data.ptr = &static_cast(interruptHandle); - } + // Use EPOLLONESHOT so we only wake a single thread + epe.events = ::EPOLLIN | ::EPOLLONESHOT; + epe.data.u64 = 0; // Keep valgrind happy + epe.data.ptr = &static_cast(interruptHandle); QPID_POSIX_CHECK(::epoll_ctl(epollFd, EPOLL_CTL_MOD, alwaysReadableFd, &epe)); } void interruptAll() { - interrupt(true); + ::epoll_event epe; + // Not EPOLLONESHOT, so we eventually get all threads + epe.events = ::EPOLLIN; + epe.data.u64 = 0; // Keep valgrind happy + QPID_POSIX_CHECK(::epoll_ctl(epollFd, EPOLL_CTL_MOD, alwaysReadableFd, &epe)); } }; @@ -281,7 +294,7 @@ void Poller::addFd(PollerHandle& handle, Direction dir) { epe.events = eh.events | PollerPrivate::directionToEpollEvent(dir); } epe.data.u64 = 0; // Keep valgrind happy - epe.data.ptr = &handle; + epe.data.ptr = &eh; QPID_POSIX_CHECK(::epoll_ctl(impl->epollFd, op, eh.fd, &epe)); @@ -312,7 +325,7 @@ void Poller::modFd(PollerHandle& handle, Direction dir) { ::epoll_event epe; epe.events = PollerPrivate::directionToEpollEvent(dir) | ::EPOLLONESHOT; epe.data.u64 = 0; // Keep valgrind happy - epe.data.ptr = &handle; + epe.data.ptr = &eh; QPID_POSIX_CHECK(::epoll_ctl(impl->epollFd, EPOLL_CTL_MOD, eh.fd, &epe)); @@ -329,7 +342,7 @@ void Poller::rearmFd(PollerHandle& handle) { ::epoll_event epe; epe.events = eh.events; epe.data.u64 = 0; // Keep valgrind happy - epe.data.ptr = &handle; + epe.data.ptr = &eh; QPID_POSIX_CHECK(::epoll_ctl(impl->epollFd, EPOLL_CTL_MOD, eh.fd, &epe)); @@ -355,15 +368,14 @@ bool Poller::interrupt(PollerHandle& handle) { { PollerHandlePrivate& eh = *handle.impl; ScopedLock l(eh.lock); - if (eh.isInactive()) { + if (!eh.isActive()) { return false; } ::epoll_event epe; epe.events = 0; epe.data.u64 = 0; // Keep valgrind happy - epe.data.ptr = &eh; QPID_POSIX_CHECK(::epoll_ctl(impl->epollFd, EPOLL_CTL_MOD, eh.fd, &epe)); - eh.setInactive(); + eh.setInterrupted(); } PollerPrivate::InterruptHandle& ih = impl->interruptHandle; @@ -422,37 +434,54 @@ Poller::Event Poller::wait(Duration timeout) { #else int rc = ::epoll_pwait(impl->epollFd, &epe, 1, timeoutMs, &impl->sigMask); #endif - // Check for shutdown - if (impl->isShutdown) { - PollerHandleDeletionManager.markAllUnusedInThisThread(); - return Event(0, SHUTDOWN); - } if (rc ==-1 && errno != EINTR) { QPID_POSIX_CHECK(rc); } else if (rc > 0) { assert(rc == 1); - PollerHandle* handle = static_cast(epe.data.ptr); + void* dataPtr = epe.data.ptr; + + // Check if this is an interrupt + PollerPrivate::InterruptHandle& interruptHandle = impl->interruptHandle; + if (dataPtr == &interruptHandle) { + PollerHandle* wrappedHandle = 0; + { + ScopedLock l(interruptHandle.impl->lock); + if (interruptHandle.impl->isActive()) { + wrappedHandle = interruptHandle.getHandle(); + // If there is an interrupt queued behind this one we need to arm it + // We do it this way so that another thread can pick it up + if (interruptHandle.queuedHandles()) { + impl->interrupt(); + interruptHandle.impl->setActive(); + } else { + interruptHandle.impl->setInactive(); + } + } + } + if (wrappedHandle) { + ScopedLock l(wrappedHandle->impl->lock); + if (!wrappedHandle->impl->isDeleted()) { + wrappedHandle->impl->setInactive(); + return Event(wrappedHandle, INTERRUPTED); + } + PollerHandleDeletionManager.markForDeletion(wrappedHandle->impl); + } + continue; + } + + // Check for shutdown + if (impl->isShutdown) { + PollerHandleDeletionManager.markAllUnusedInThisThread(); + return Event(0, SHUTDOWN); + } - PollerHandlePrivate& eh = *handle->impl; + PollerHandlePrivate& eh = *static_cast(dataPtr); ScopedLock l(eh.lock); // the handle could have gone inactive since we left the epoll_wait if (eh.isActive()) { - - // Check if this is an interrupt - if (handle == &impl->interruptHandle) { - PollerHandle* wrappedHandle = impl->interruptHandle.getHandle(); - // If there is an interrupt queued behind this one we need to arm it - // We do it this way so that another thread can pick it up - if (impl->interruptHandle.queuedHandles()) { - impl->interrupt(); - eh.setActive(); - } else { - eh.setInactive(); - } - return Event(wrappedHandle, INTERRUPTED); - } + PollerHandle* handle = eh.pollerHandle; // If the connection has been hungup we could still be readable // (just not writable), allow us to readable until we get here again diff --git a/qpid/cpp/src/qpid/sys/posix/AsynchIO.cpp b/qpid/cpp/src/qpid/sys/posix/AsynchIO.cpp index a356a72650..a914dc817a 100644 --- a/qpid/cpp/src/qpid/sys/posix/AsynchIO.cpp +++ b/qpid/cpp/src/qpid/sys/posix/AsynchIO.cpp @@ -123,7 +123,7 @@ void AsynchAcceptorPrivate::readable(DispatchHandle& h) { // TODO: Currently we ignore the peers address, perhaps we should // log it or use it for connection acceptance. try { - s = socket.accept(0, 0); + s = socket.accept(); if (s) { acceptedCallback(*s); } else { @@ -474,7 +474,7 @@ void AsynchIO::readable(DispatchHandle& h) { break; } else { // Report error then just treat as a socket disconnect - QPID_LOG(error, "Error reading socket: " << qpid::sys::strError(rc) << "(" << rc << ")" ); + QPID_LOG(error, "Error reading socket: " << qpid::sys::strError(errno) << "(" << errno << ")" ); eofCallback(*this); h.unwatchRead(); break; diff --git a/qpid/cpp/src/qpid/sys/posix/Socket.cpp b/qpid/cpp/src/qpid/sys/posix/Socket.cpp index 415d5293ef..ab0c28c48c 100644 --- a/qpid/cpp/src/qpid/sys/posix/Socket.cpp +++ b/qpid/cpp/src/qpid/sys/posix/Socket.cpp @@ -108,7 +108,7 @@ void Socket::createTcp() const { int& socket = impl->fd; if (socket != -1) Socket::close(); - int s = ::socket (PF_INET, SOCK_STREAM, 0); + int s = ::socket (AF_INET, SOCK_STREAM, 0); if (s < 0) throw QPID_POSIX_ERROR(errno); socket = s; } @@ -138,25 +138,30 @@ const char* h_errstr(int e) { } } -void Socket::connect(const std::string& host, uint16_t port) const +void Socket::connect(const std::string& host, uint16_t p) const { - std::stringstream namestream; - namestream << host << ":" << port; - connectname = namestream.str(); + std::stringstream portstream; + portstream << p; + std::string port = portstream.str(); + connectname = host + ":" + port; const int& socket = impl->fd; - struct sockaddr_in name; - name.sin_family = AF_INET; - name.sin_port = htons(port); - // TODO: Be good to make this work for IPv6 as well as IPv4 - // Use more modern lookup functions - struct hostent* hp = gethostbyname ( host.c_str() ); - if (hp == 0) - throw Exception(QPID_MSG("Cannot resolve " << host << ": " << h_errstr(h_errno))); - ::memcpy(&name.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length); - if ((::connect(socket, (struct sockaddr*)(&name), sizeof(name)) < 0) && - (errno != EINPROGRESS)) + + ::addrinfo *res; + ::addrinfo hints; + ::memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; // In order to allow AF_INET6 we'd have to change createTcp() as well + hints.ai_socktype = SOCK_STREAM; + int n = ::getaddrinfo(host.c_str(), port.c_str(), &hints, &res); + if (n != 0) + throw Exception(QPID_MSG("Cannot resolve " << host << ": " << ::gai_strerror(n))); + // TODO the correct thing to do here is loop on failure until you've used all the returned addresses + if ((::connect(socket, res->ai_addr, res->ai_addrlen) < 0) && + (errno != EINPROGRESS)) { + ::freeaddrinfo(res); throw qpid::Exception(QPID_MSG(strError(errno) << ": " << host << ":" << port)); + } + ::freeaddrinfo(res); } void @@ -189,9 +194,9 @@ int Socket::listen(uint16_t port, int backlog) const return ntohs(name.sin_port); } -Socket* Socket::accept(struct sockaddr *addr, socklen_t *addrlen) const +Socket* Socket::accept() const { - int afd = ::accept(impl->fd, addr, addrlen); + int afd = ::accept(impl->fd, 0, 0); if ( afd >= 0) return new Socket(new IOHandlePrivate(afd)); else if (errno == EAGAIN) @@ -238,7 +243,7 @@ uint16_t Socket::getLocalPort() const uint16_t Socket::getRemotePort() const { - return atoi(getService(impl->fd, true).c_str()); + return std::atoi(getService(impl->fd, true).c_str()); } int Socket::getError() const diff --git a/qpid/cpp/src/qpid/sys/solaris/ECFPoller.cpp b/qpid/cpp/src/qpid/sys/solaris/ECFPoller.cpp index 783f84576b..71fbea27c2 100644 --- a/qpid/cpp/src/qpid/sys/solaris/ECFPoller.cpp +++ b/qpid/cpp/src/qpid/sys/solaris/ECFPoller.cpp @@ -30,9 +30,11 @@ #include #include #include +#include +#include #include -#include +#include #include @@ -43,11 +45,11 @@ namespace qpid { namespace sys { // Deletion manager to handle deferring deletion of PollerHandles to when they definitely aren't being used -DeletionManager PollerHandleDeletionManager; +DeletionManager PollerHandleDeletionManager; // Instantiate (and define) class static for DeletionManager template <> -DeletionManager::AllThreadsStatuses DeletionManager::allThreadsStatuses(0); +DeletionManager::AllThreadsStatuses DeletionManager::allThreadsStatuses(0); class PollerHandlePrivate { friend class Poller; @@ -58,7 +60,8 @@ class PollerHandlePrivate { MONITORED, INACTIVE, HUNGUP, - MONITORED_HUNGUP + MONITORED_HUNGUP, + DELETED }; int fd; @@ -104,6 +107,14 @@ class PollerHandlePrivate { assert(stat == MONITORED); stat = HUNGUP; } + + bool isDeleted() const { + return stat == DELETED; + } + + void setDeleted() { + stat = DELETED; + } }; PollerHandle::PollerHandle(const IOHandle& h) : @@ -111,11 +122,16 @@ PollerHandle::PollerHandle(const IOHandle& h) : {} PollerHandle::~PollerHandle() { - delete impl; -} - -void PollerHandle::deferDelete() { - PollerHandleDeletionManager.markForDeletion(this); + { + ScopedLock l(impl->lock); + if (impl->isDeleted()) { + return; + } + if (impl->isActive()) { + impl->setDeleted(); + } + } + PollerHandleDeletionManager.markForDeletion(impl); } /** @@ -125,35 +141,80 @@ void PollerHandle::deferDelete() { class PollerPrivate { friend class Poller; - const int portId; + class InterruptHandle: public PollerHandle { + std::queue handles; + + void processEvent(Poller::EventType) { + PollerHandle* handle = handles.front(); + handles.pop(); + assert(handle); + + //Synthesise event + Poller::Event event(handle, Poller::INTERRUPTED); + + //Process synthesised event + event.process(); + } + public: + InterruptHandle() : PollerHandle(DummyIOHandle) {} + + void addHandle(PollerHandle& h) { + handles.push(&h); + } + + PollerHandle *getHandle() { + PollerHandle* handle = handles.front(); + handles.pop(); + return handle; + } + + bool queuedHandles() { + return handles.size() > 0; + } + }; + + const int portId; + bool isShutdown; + InterruptHandle interruptHandle; + static uint32_t directionToPollEvent(Poller::Direction dir) { switch (dir) { - case Poller::INPUT: return POLLIN; - case Poller::OUTPUT: return POLLOUT; - case Poller::INOUT: return POLLIN | POLLOUT; - default: return 0; + case Poller::INPUT: return POLLIN; + case Poller::OUTPUT: return POLLOUT; + case Poller::INOUT: return POLLIN | POLLOUT; + default: return 0; } } static Poller::EventType pollToDirection(uint32_t events) { uint32_t e = events & (POLLIN | POLLOUT); switch (e) { - case POLLIN: return Poller::READABLE; - case POLLOUT: return Poller::WRITABLE; - case POLLIN | POLLOUT: return Poller::READ_WRITABLE; - default: - return (events & (POLLHUP | POLLERR)) ? - Poller::DISCONNECTED : Poller::INVALID; + case POLLIN: return Poller::READABLE; + case POLLOUT: return Poller::WRITABLE; + case POLLIN | POLLOUT: return Poller::READ_WRITABLE; + default: + return (events & (POLLHUP | POLLERR)) ? + Poller::DISCONNECTED : Poller::INVALID; } } - + PollerPrivate() : - portId(::port_create()) { + portId(::port_create()), + isShutdown(false) { + QPID_POSIX_CHECK(portId); } ~PollerPrivate() { } + + void interrupt() { + //Send an Alarm to the port + //We need to send a nonzero event mask, using POLLHUP, + //nevertheless the wait method will only look for a PORT_ALERT_SET + QPID_POSIX_CHECK(::port_alert(portId, PORT_ALERT_SET, POLLHUP, + &static_cast(interruptHandle))); + } }; void Poller::addFd(PollerHandle& handle, Direction dir) { @@ -177,7 +238,6 @@ void Poller::addFd(PollerHandle& handle, Direction dir) { QPID_LOG(trace, "Poller::addFd(handle=" << &handle << "[" << typeid(&handle).name() << "], fd=" << eh.fd << ")"); - //assert(dynamic_cast(&handle)); } void Poller::delFd(PollerHandle& handle) { @@ -223,17 +283,56 @@ void Poller::rearmFd(PollerHandle& handle) { } void Poller::shutdown() { - //Send an Alarm to the port - //We need to send a nonzero event mask, using POLLHUP, but - //The wait method will only look for a PORT_ALERT_SET - QPID_POSIX_CHECK(::port_alert(impl->portId, PORT_ALERT_SET, POLLHUP, NULL)); - QPID_LOG(trace, "Poller::shutdown"); + //Allow sloppy code to shut us down more than once + if (impl->isShutdown) + return; + + impl->isShutdown = true; + impl->interrupt(); +} + +bool Poller::interrupt(PollerHandle& handle) { + PollerPrivate::InterruptHandle& ih = impl->interruptHandle; + PollerHandlePrivate& eh = *static_cast(ih).impl; + ScopedLock l(eh.lock); + ih.addHandle(handle); + impl->interrupt(); + eh.setActive(); + return true; +} + +void Poller::run() { + // Make sure we can't be interrupted by signals at a bad time + ::sigset_t ss; + ::sigfillset(&ss); + ::pthread_sigmask(SIG_SETMASK, &ss, 0); + + do { + Event event = wait(); + + // If can read/write then dispatch appropriate callbacks + if (event.handle) { + event.process(); + } else { + // Handle shutdown + switch (event.type) { + case SHUTDOWN: + return; + default: + // This should be impossible + assert(false); + } + } + } while (true); } Poller::Event Poller::wait(Duration timeout) { timespec_t tout; timespec_t* ptout = NULL; port_event_t pe; + + AbsTime targetTimeout = (timeout == TIME_INFINITE) ? FAR_FUTURE : + AbsTime(now(), timeout); if (timeout != TIME_INFINITE) { tout.tv_sec = 0; @@ -246,9 +345,15 @@ Poller::Event Poller::wait(Duration timeout) { QPID_LOG(trace, "About to enter port_get. Thread " << pthread_self() << ", timeout=" << timeout); - + + int rc = ::port_get(impl->portId, &pe, ptout); + if (impl->isShutdown) { + PollerHandleDeletionManager.markAllUnusedInThisThread(); + return Event(0, SHUTDOWN); + } + if (rc < 0) { switch (errno) { case EINTR: @@ -259,33 +364,60 @@ Poller::Event Poller::wait(Duration timeout) { QPID_POSIX_CHECK(rc); } } else { - //We use alert mode to notify the shutdown of the Poller - if (pe.portev_source == PORT_SOURCE_ALERT) { - return Event(0, SHUTDOWN); - } - if (pe.portev_source == PORT_SOURCE_FD) { - PollerHandle *handle = static_cast(pe.portev_user); - PollerHandlePrivate& eh = *handle->impl; - ScopedLock l(eh.lock); - QPID_LOG(trace, "About to send handle: " << handle); + PollerHandle* handle = static_cast(pe.portev_user); + PollerHandlePrivate& eh = *handle->impl; + ScopedLock l(eh.lock); + + if (eh.isActive()) { + //We use alert mode to notify interrupts + if (pe.portev_source == PORT_SOURCE_ALERT && + handle == &impl->interruptHandle) { + PollerHandle* wrappedHandle = impl->interruptHandle.getHandle(); + + if (impl->interruptHandle.queuedHandles()) { + impl->interrupt(); + eh.setActive(); + } else { + eh.setInactive(); + } + return Event(wrappedHandle, INTERRUPTED); + } - if (eh.isActive()) { - if (pe.portev_events & POLLHUP) { - if (eh.isHungup()) { - return Event(handle, DISCONNECTED); + return Event(0, SHUTDOWN); + + if (pe.portev_source == PORT_SOURCE_FD) { + QPID_LOG(trace, "About to send handle: " << handle); + if (pe.portev_events & POLLHUP) { + if (eh.isHungup()) { + return Event(handle, DISCONNECTED); + } + eh.setHungup(); + } else { + eh.setInactive(); } - eh.setHungup(); - } else { - eh.setInactive(); - } - QPID_LOG(trace, "Sending event (thread: " - << pthread_self() << ") for handle " << handle - << ", direction= " - << PollerPrivate::pollToDirection(pe.portev_events)); - return Event(handle, PollerPrivate::pollToDirection(pe.portev_events)); + QPID_LOG(trace, "Sending event (thread: " + << pthread_self() << ") for handle " << handle + << ", direction= " + << PollerPrivate::pollToDirection(pe.portev_events)); + return Event(handle, PollerPrivate::pollToDirection(pe.portev_events)); + } + } else if (eh.isDeleted()) { + //Remove the handle from the poller + int rc = ::port_dissociate(impl->portId, PORT_SOURCE_FD, + (uintptr_t) eh.fd); + if (rc == -1 && errno != EBADFD) { + QPID_POSIX_CHECK(rc); } } } + + if (timeout == TIME_INFINITE) { + continue; + } + if (rc == 0 && now() > targetTimeout) { + PollerHandleDeletionManager.markAllUnusedInThisThread(); + return Event(0, TIMEOUT); + } } while (true); } diff --git a/qpid/cpp/src/qpid/sys/solaris/SystemInfo.cpp b/qpid/cpp/src/qpid/sys/solaris/SystemInfo.cpp new file mode 100755 index 0000000000..0075a89021 --- /dev/null +++ b/qpid/cpp/src/qpid/sys/solaris/SystemInfo.cpp @@ -0,0 +1,123 @@ +/* + * 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. + * + */ + +#include "qpid/sys/SystemInfo.h" + +#define BSD_COMP +#include +#include +#undef BDS_COMP + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +namespace qpid { +namespace sys { + +long SystemInfo::concurrency() { + return sysconf(_SC_NPROCESSORS_ONLN); +} + +bool SystemInfo::getLocalHostname(TcpAddress &address) { + char name[MAXHOSTNAMELEN]; + if (::gethostname(name, sizeof(name)) != 0) + return false; + address.host = name; + return true; +} + +static const string LOCALHOST("127.0.0.1"); + +void SystemInfo::getLocalIpAddresses(uint16_t port, + std::vector
&addrList) { + int s = socket(PF_INET, SOCK_STREAM, 0); + for (int i=1;;i++) { + struct lifreq ifr; + ifr.lifr_index = i; + if (::ioctl(s, SIOCGIFADDR, &ifr) < 0) { + break; + } + struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.lifr_addr; + std::string addr(inet_ntoa(sin->sin_addr)); + if (addr != LOCALHOST) + addrList.push_back(TcpAddress(addr, port)); + } + if (addrList.empty()) { + addrList.push_back(TcpAddress(LOCALHOST, port)); + } + close (s); +} + +void SystemInfo::getSystemId(std::string &osName, + std::string &nodeName, + std::string &release, + std::string &version, + std::string &machine) { + struct utsname _uname; + if (uname (&_uname) == 0) { + osName = _uname.sysname; + nodeName = _uname.nodename; + release = _uname.release; + version = _uname.version; + machine = _uname.machine; + } +} + +uint32_t SystemInfo::getProcessId() +{ + return (uint32_t) ::getpid(); +} + +uint32_t SystemInfo::getParentProcessId() +{ + return (uint32_t) ::getppid(); +} + +string SystemInfo::getProcessName() +{ + psinfo processInfo; + char procfile[PATH_MAX]; + int fd; + string value; + + snprintf(procfile, PATH_MAX, "/proc/%d/psinfo", getProcessId()); + if ((fd = open(procfile, O_RDONLY)) >= 0) { + if (read(fd, (void *) &processInfo, sizeof(processInfo)) == sizeof(processInfo)) { + value = processInfo.pr_fname; + } + } + return value; +} + +}} // namespace qpid::sys diff --git a/qpid/cpp/src/qpid/sys/ssl/SslIo.cpp b/qpid/cpp/src/qpid/sys/ssl/SslIo.cpp index 9be75af47d..624683ae7d 100644 --- a/qpid/cpp/src/qpid/sys/ssl/SslIo.cpp +++ b/qpid/cpp/src/qpid/sys/ssl/SslIo.cpp @@ -90,7 +90,7 @@ void SslAcceptor::readable(DispatchHandle& h) { // TODO: Currently we ignore the peers address, perhaps we should // log it or use it for connection acceptance. try { - s = socket.accept(0, 0); + s = socket.accept(); if (s) { acceptedCallback(*s); } else { diff --git a/qpid/cpp/src/qpid/sys/ssl/SslSocket.cpp b/qpid/cpp/src/qpid/sys/ssl/SslSocket.cpp index 597fbe57db..dc816b403b 100644 --- a/qpid/cpp/src/qpid/sys/ssl/SslSocket.cpp +++ b/qpid/cpp/src/qpid/sys/ssl/SslSocket.cpp @@ -201,9 +201,9 @@ int SslSocket::listen(uint16_t port, int backlog, const std::string& certName, b return ntohs(name.sin_port); } -SslSocket* SslSocket::accept(struct sockaddr *addr, socklen_t *addrlen) const +SslSocket* SslSocket::accept() const { - int afd = ::accept(impl->fd, addr, addrlen); + int afd = ::accept(impl->fd, 0, 0); if ( afd >= 0) { return new SslSocket(new IOHandlePrivate(afd), prototype); } else if (errno == EAGAIN) { diff --git a/qpid/cpp/src/qpid/sys/ssl/SslSocket.h b/qpid/cpp/src/qpid/sys/ssl/SslSocket.h index a82e9133e8..7434667b78 100644 --- a/qpid/cpp/src/qpid/sys/ssl/SslSocket.h +++ b/qpid/cpp/src/qpid/sys/ssl/SslSocket.h @@ -64,7 +64,7 @@ public: * Accept a connection from a socket that is already listening * and has an incoming connection */ - SslSocket* accept(struct sockaddr *addr, socklen_t *addrlen) const; + SslSocket* accept() const; // TODO The following are raw operations, maybe they need better wrapping? int read(void *buf, size_t count) const; diff --git a/qpid/cpp/src/qpid/sys/windows/IntegerTypes.h b/qpid/cpp/src/qpid/sys/windows/IntegerTypes.h index 80168fab88..4b72154cd0 100755 --- a/qpid/cpp/src/qpid/sys/windows/IntegerTypes.h +++ b/qpid/cpp/src/qpid/sys/windows/IntegerTypes.h @@ -32,7 +32,6 @@ typedef __int64 int64_t; // Visual Studio doesn't define other common types, so set them up here too. typedef int pid_t; -typedef int socklen_t; typedef unsigned int size_t; typedef int ssize_t; typedef unsigned int uint; diff --git a/qpid/cpp/src/qpid/sys/windows/Socket.cpp b/qpid/cpp/src/qpid/sys/windows/Socket.cpp index a9959bf43e..93059d03ef 100755 --- a/qpid/cpp/src/qpid/sys/windows/Socket.cpp +++ b/qpid/cpp/src/qpid/sys/windows/Socket.cpp @@ -262,9 +262,9 @@ int Socket::listen(uint16_t port, int backlog) const return ntohs(name.sin_port); } -Socket* Socket::accept(struct sockaddr *addr, socklen_t *addrlen) const +Socket* Socket::accept() const { - SOCKET afd = ::accept(impl->fd, addr, addrlen); + SOCKET afd = ::accept(impl->fd, 0, 0); if (afd != INVALID_SOCKET) return new Socket(new IOHandlePrivate(afd)); else if (WSAGetLastError() == EAGAIN) diff --git a/qpid/cpp/src/qpid/xml/XmlExchange.cpp b/qpid/cpp/src/qpid/xml/XmlExchange.cpp index 5197b239d0..4e9de49ad5 100644 --- a/qpid/cpp/src/qpid/xml/XmlExchange.cpp +++ b/qpid/cpp/src/qpid/xml/XmlExchange.cpp @@ -33,6 +33,9 @@ #include "qpid/Plugin.h" #include + +#include + #include #include @@ -62,17 +65,6 @@ XmlExchange::XmlExchange(const std::string& _name, bool _durable, mgmtExchange->set_type (typeName); } -/* - * Use the name of the query as the binding key. - * - * The first time a given name is used in a binding, the query body - * must be provided.After that, no query body should be present. - * - * To modify an installed query, the user must first unbind the - * existing query, then replace it by binding again with the same - * name. - * - */ // #### TODO: The Binding should take the query text // #### only. Consider encapsulating the entire block, including @@ -94,6 +86,21 @@ bool XmlExchange::bind(Queue::shared_ptr queue, const string& routingKey, const bindings.add(binding); QPID_LOG(trace, "Bound successfully with query: " << queryText ); + binding->parse_message_content = false; + + if (query->getQueryBody()->getStaticAnalysis().areContextFlagsUsed()) { + binding->parse_message_content = true; + } + else { + GlobalVariables &vars = const_cast(query->getVariables()); + for(GlobalVariables::iterator it = vars.begin(); it != vars.end(); ++it) { + if ((*it)->getStaticAnalysis().areContextFlagsUsed()) { + binding->parse_message_content = true; + break; + } + } + } + if (mgmtExchange != 0) { mgmtExchange->inc_bindingCount(); ((_qmf::Queue*) queue->GetManagementObject())->inc_bindingCount(); @@ -126,59 +133,74 @@ bool XmlExchange::unbind(Queue::shared_ptr queue, const string& routingKey, cons } } -bool XmlExchange::matches(Query& query, Deliverable& msg, const qpid::framing::FieldTable* args) +bool XmlExchange::matches(Query& query, Deliverable& msg, const qpid::framing::FieldTable* args, bool parse_message_content) { - // ### TODO: Need istream for frameset - // Hack alert - the following code does not work for really large messages - string msgContent; try { - msg.getMessage().getFrames().getContent(msgContent); - - QPID_LOG(trace, "matches: query is [" << UTF8(query->getQueryText()) << "]"); - QPID_LOG(trace, "matches: message content is [" << msgContent << "]"); - - boost::scoped_ptr context(query->createDynamicContext()); - if (!context.get()) { - throw InternalErrorException(QPID_MSG("Query context looks munged ...")); - } - - XERCES_CPP_NAMESPACE::MemBufInputSource xml((const XMLByte*) msgContent.c_str(), - msgContent.length(), "input" ); - Sequence seq(context->parseDocument(xml)); - - if (args) { - FieldTable::ValueMap::const_iterator v = args->begin(); - for(; v != args->end(); ++v) { - // ### TODO: Do types properly - if (v->second->convertsTo()) { - QPID_LOG(trace, "XmlExchange, external variable: " << v->first << " = " << v->second->getData().getString().c_str()); - Item::Ptr value = context->getItemFactory()->createString(X(v->second->getData().getString().c_str()), context.get()); - context->setExternalVariable(X(v->first.c_str()), value); - } - } - } - - if(!seq.isEmpty() && seq.first()->isNode()) { - context->setContextItem(seq.first()); - context->setContextPosition(1); - context->setContextSize(1); - } - Result result = query->execute(context.get()); - return result->getEffectiveBooleanValue(context.get(), 0); + QPID_LOG(trace, "matches: query is [" << UTF8(query->getQueryText()) << "]"); + + boost::scoped_ptr context(query->createDynamicContext()); + if (!context.get()) { + throw InternalErrorException(QPID_MSG("Query context looks munged ...")); + } + + if (parse_message_content) { + + msg.getMessage().getFrames().getContent(msgContent); + + QPID_LOG(trace, "matches: message content is [" << msgContent << "]"); + + XERCES_CPP_NAMESPACE::MemBufInputSource xml((const XMLByte*) msgContent.c_str(), + msgContent.length(), "input" ); + + // This will parse the document using either Xerces or FastXDM, depending + // on your XQilla configuration. FastXDM can be as much as 10x faster. + + Sequence seq(context->parseDocument(xml)); + + if(!seq.isEmpty() && seq.first()->isNode()) { + context->setContextItem(seq.first()); + context->setContextPosition(1); + context->setContextSize(1); + } + } + + if (args) { + FieldTable::ValueMap::const_iterator v = args->begin(); + for(; v != args->end(); ++v) { + // ### TODO: Do types properly + if (v->second->convertsTo()) { + QPID_LOG(trace, "XmlExchange, external variable: " << v->first << " = " << v->second->getData().getString().c_str()); + Item::Ptr value = context->getItemFactory()->createString(X(v->second->getData().getString().c_str()), context.get()); + context->setExternalVariable(X(v->first.c_str()), value); + } + } + } + + Result result = query->execute(context.get()); + return result->getEffectiveBooleanValue(context.get(), 0); } catch (XQException& e) { - QPID_LOG(warning, "Could not parse XML content (or message headers):" << msgContent); - return 0; + QPID_LOG(warning, "Could not parse XML content (or message headers):" << msgContent); } catch (...) { - QPID_LOG(warning, "Unexpected error routing message: " << msgContent); - return 0; + QPID_LOG(warning, "Unexpected error routing message: " << msgContent); } return 0; } +// Future optimization: If any query in a binding for a given routing key requires +// message content, parse the message once, and use that parsed form for all bindings. +// +// Future optimization: XQilla does not currently do document projection for data +// accessed via the context item. If there is a single query for a given routing key, +// and it accesses document data, this could be a big win. +// +// Document projection often is not a win if you have multiple queries on the same data. +// But for very large messages, if all these queries are on the first part of the data, +// it could still be a big win. + void XmlExchange::route(Deliverable& msg, const string& routingKey, const FieldTable* args) { PreRoute pr(msg, this); @@ -192,7 +214,7 @@ void XmlExchange::route(Deliverable& msg, const string& routingKey, const FieldT int count(0); for (std::vector::const_iterator i = p->begin(); i != p->end(); i++) { - if ((*i)->xquery && matches((*i)->xquery, msg, args)) { // Overly defensive? There should always be a query ... + if (matches((*i)->xquery, msg, args, (*i)->parse_message_content)) { msg.deliverTo((*i)->queue); count++; QPID_LOG(trace, "Delivered to queue" ); diff --git a/qpid/cpp/src/qpid/xml/XmlExchange.h b/qpid/cpp/src/qpid/xml/XmlExchange.h index 066a26489d..7bec480bde 100644 --- a/qpid/cpp/src/qpid/xml/XmlExchange.h +++ b/qpid/cpp/src/qpid/xml/XmlExchange.h @@ -46,9 +46,10 @@ class XmlExchange : public virtual Exchange { typedef qpid::sys::CopyOnWriteArray vector; boost::shared_ptr xquery; + bool parse_message_content; XmlBinding(const std::string& key, const Queue::shared_ptr queue, Exchange* parent, Query query): - Binding(key, queue, parent), xquery(query) {} + Binding(key, queue, parent), xquery(query), parse_message_content(true) {} }; @@ -58,7 +59,7 @@ class XmlExchange : public virtual Exchange { XQilla xqilla; qpid::sys::RWlock lock; - bool matches(Query& query, Deliverable& msg, const qpid::framing::FieldTable* args); + bool matches(Query& query, Deliverable& msg, const qpid::framing::FieldTable* args, bool parse_message_content); public: static const std::string typeName; diff --git a/qpid/cpp/src/replication.mk b/qpid/cpp/src/replication.mk index 6830f99d36..c65a7ae3b9 100644 --- a/qpid/cpp/src/replication.mk +++ b/qpid/cpp/src/replication.mk @@ -29,6 +29,9 @@ replicating_listener_la_SOURCES = \ qpid/replication/ReplicatingEventListener.h replicating_listener_la_LIBADD = libqpidbroker.la +if SUNOS + replicating_listener_la_LIBADD += libqpidcommon.la -lboost_program_options -luuid $(SUNCC_RUNTIME_LIBS) +endif replicating_listener_la_LDFLAGS = $(PLUGINLDFLAGS) @@ -43,4 +46,7 @@ replication_exchange_la_SOURCES = \ replication_exchange_la_LIBADD = libqpidbroker.la +if SUNOS + replication_exchange_la_LIBADD += libqpidcommon.la -lboost_program_options -lCrun -luuid +endif replication_exchange_la_LDFLAGS = $(PLUGINLDFLAGS) diff --git a/qpid/cpp/src/tests/ClientSessionTest.cpp b/qpid/cpp/src/tests/ClientSessionTest.cpp index 1658f3d4ec..589e1154e1 100644 --- a/qpid/cpp/src/tests/ClientSessionTest.cpp +++ b/qpid/cpp/src/tests/ClientSessionTest.cpp @@ -428,8 +428,8 @@ QPID_AUTO_TEST_CASE(testConcurrentSenders) for (size_t i = 0; i < 5; i++) { publishers.push_back(new Publisher(connection, message, 100)); } - for_each(publishers.begin(), publishers.end(), boost::bind(&Publisher::start, _1)); - for_each(publishers.begin(), publishers.end(), boost::bind(&Publisher::join, _1)); + std::for_each(publishers.begin(), publishers.end(), boost::bind(&Publisher::start, _1)); + std::for_each(publishers.begin(), publishers.end(), boost::bind(&Publisher::join, _1)); connection.close(); } @@ -564,6 +564,24 @@ QPID_AUTO_TEST_CASE(testSessionManagerSetFlowControl) { BOOST_CHECK_EQUAL("my-message", got.getData()); } +QPID_AUTO_TEST_CASE(testGetThenSubscribe) { + ClientSessionFixture fix; + std::string name("myqueue"); + fix.session.queueDeclare(arg::queue=name, arg::exclusive=true, arg::autoDelete=true); + fix.session.messageTransfer(arg::content=Message("one", name)); + fix.session.messageTransfer(arg::content=Message("two", name)); + Message got; + BOOST_CHECK(fix.subs.get(got, name)); + BOOST_CHECK_EQUAL("one", got.getData()); + + DummyListener listener(fix.session, name, 1); + listener.run(); + BOOST_CHECK_EQUAL(1u, listener.messages.size()); + if (!listener.messages.empty()) { + BOOST_CHECK_EQUAL("two", listener.messages[0].getData()); + } +} + QPID_AUTO_TEST_SUITE_END() diff --git a/qpid/cpp/src/tests/ClusterFixture.cpp b/qpid/cpp/src/tests/ClusterFixture.cpp index 3a0ea74098..5658957b48 100644 --- a/qpid/cpp/src/tests/ClusterFixture.cpp +++ b/qpid/cpp/src/tests/ClusterFixture.cpp @@ -109,7 +109,7 @@ void ClusterFixture::addLocal() { Args args(makeArgs(prefix)); vector argv(args.size()); transform(args.begin(), args.end(), argv.begin(), boost::bind(&string::c_str, _1)); - qpid::log::Logger::instance().setPrefix(os.str()); + qpid::log::Logger::instance().setPrefix(prefix); localBroker.reset(new BrokerFixture(parseOpts(argv.size(), &argv[0]))); push_back(localBroker->getPort()); forkedBrokers.push_back(shared_ptr()); diff --git a/qpid/cpp/src/tests/DispatcherTest.cpp b/qpid/cpp/src/tests/DispatcherTest.cpp index c2f6bca12a..c619a36438 100644 --- a/qpid/cpp/src/tests/DispatcherTest.cpp +++ b/qpid/cpp/src/tests/DispatcherTest.cpp @@ -78,9 +78,6 @@ void reader(DispatchHandle& h, int fd) { h.rewatch(); } -DispatchHandle* rh = 0; -DispatchHandle* wh = 0; - void rInterrupt(DispatchHandle&) { cerr << "R"; } @@ -92,9 +89,27 @@ void wInterrupt(DispatchHandle&) { DispatchHandle::Callback rcb = rInterrupt; DispatchHandle::Callback wcb = wInterrupt; +DispatchHandleRef *volatile rh = 0; +DispatchHandleRef *volatile wh = 0; + +volatile bool stopWait = false; +volatile bool phase1finished = false; + +timer_t timer; + +void stop_handler(int /*signo*/, siginfo_t* /*info*/, void* /*context*/) { + stopWait = true; +} + void timer_handler(int /*signo*/, siginfo_t* /*info*/, void* /*context*/) { - rh->call(rcb); - wh->call(wcb); + static int count = 0; + if (count++ < 10) { + rh->call(rcb); + wh->call(wcb); + } else { + phase1finished = true; + assert(::timer_delete(timer) == 0); + } } int main(int /*argc*/, char** /*argv*/) @@ -114,7 +129,7 @@ int main(int /*argc*/, char** /*argv*/) // Setup sender and receiver int sv[2]; - int rc = ::socketpair(AF_LOCAL, SOCK_STREAM, 0, sv); + int rc = ::socketpair(AF_UNIX, SOCK_STREAM, 0, sv); assert(rc >= 0); // Set non-blocking @@ -132,8 +147,8 @@ int main(int /*argc*/, char** /*argv*/) PosixIOHandle f0(sv[0]); PosixIOHandle f1(sv[1]); - rh = new DispatchHandle(f0, boost::bind(reader, _1, sv[0]), 0, 0); - wh = new DispatchHandle(f1, 0, boost::bind(writer, _1, sv[1], testString), 0); + rh = new DispatchHandleRef(f0, boost::bind(reader, _1, sv[0]), 0, 0); + wh = new DispatchHandleRef(f1, 0, boost::bind(writer, _1, sv[1], testString), 0); rh->startWatch(poller); wh->startWatch(poller); @@ -155,10 +170,9 @@ int main(int /*argc*/, char** /*argv*/) assert(rc == 0); ::sigevent se; + ::memset(&se, 0, sizeof(se)); // Clear to make valgrind happy (this *is* the neatest way to do this portably - sigh) se.sigev_notify = SIGEV_SIGNAL; se.sigev_signo = SIGRTMIN; - se.sigev_value.sival_ptr = 0; - timer_t timer; rc = ::timer_create(CLOCK_REALTIME, &se, &timer); assert(rc == 0); @@ -169,11 +183,52 @@ int main(int /*argc*/, char** /*argv*/) rc = ::timer_settime(timer, 0, &ts, 0); assert(rc == 0); - // wait 2 minutes then shutdown - ::sleep(60); + // wait + while (!phase1finished) { + ::sleep(1); + } + + // Now test deleting/creating DispatchHandles in tight loop, so that we are likely to still be using the + // attached PollerHandles after deleting the DispatchHandle + DispatchHandleRef* t = wh; + wh = 0; + delete t; + t = rh; + rh = 0; + delete t; + + sa.sa_sigaction = stop_handler; + rc = ::sigaction(SIGRTMIN, &sa,0); + assert(rc == 0); + + itimerspec nts = { + /*.it_value = */ {30, 0}, // s, ns + /*.it_interval = */ {30, 0}}; // s, ns + + rc = ::timer_create(CLOCK_REALTIME, &se, &timer); + assert(rc == 0); + rc = ::timer_settime(timer, 0, &nts, 0); + assert(rc == 0); + + DispatchHandleRef* rh1; + DispatchHandleRef* wh1; + + struct timespec w = {0, 1000000}; + while (!stopWait) { + rh1 = new DispatchHandleRef(f0, boost::bind(reader, _1, sv[0]), 0, 0); + wh1 = new DispatchHandleRef(f1, 0, boost::bind(writer, _1, sv[1], testString), 0); + rh1->startWatch(poller); + wh1->startWatch(poller); + + ::nanosleep(&w, 0); + + delete wh1; + delete rh1; + } rc = ::timer_delete(timer); assert(rc == 0); + poller->shutdown(); dt.join(); dt1.join(); diff --git a/qpid/cpp/src/tests/ForkedBroker.cpp b/qpid/cpp/src/tests/ForkedBroker.cpp index 2b90068549..f90f76aeb2 100644 --- a/qpid/cpp/src/tests/ForkedBroker.cpp +++ b/qpid/cpp/src/tests/ForkedBroker.cpp @@ -22,6 +22,9 @@ #include "ForkedBroker.h" #include #include +#include +#include +#include ForkedBroker::ForkedBroker(const Args& args) { init(args); } @@ -41,9 +44,9 @@ void ForkedBroker::kill(int sig) { if (::kill(savePid, sig) < 0) throw ErrnoException("kill failed"); int status; - if (::waitpid(savePid, &status, 0) < 0) + if (::waitpid(savePid, &status, 0) < 0 && sig != 9) throw ErrnoException("wait for forked process failed"); - if (WEXITSTATUS(status) != 0) + if (WEXITSTATUS(status) != 0 && sig != 9) throw qpid::Exception(QPID_MSG("Forked broker exited with: " << WEXITSTATUS(status))); } diff --git a/qpid/cpp/src/tests/FrameDecoder.cpp b/qpid/cpp/src/tests/FrameDecoder.cpp new file mode 100644 index 0000000000..f5db66d5fe --- /dev/null +++ b/qpid/cpp/src/tests/FrameDecoder.cpp @@ -0,0 +1,73 @@ +/* + * + * 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. + * + */ + +#include "unit_test.h" +#include "qpid/framing/AMQFrame.h" +#include "qpid/framing/FrameDecoder.h" +#include "qpid/framing/AMQContentBody.h" +#include "qpid/framing/Buffer.h" +#include + + +QPID_AUTO_TEST_SUITE(FrameDecoderTest) + +using namespace std; +using namespace qpid::framing; + + +string makeData(int size) { + string data; + data.resize(size); + for (int i =0; i < size; ++i) + data[i] = 'a' + (i%26); + return data; +} +string encodeFrame(string data) { + AMQFrame f((AMQContentBody(data))); + string encoded; + encoded.resize(f.encodedSize()); + Buffer b(&encoded[0], encoded.size()); + f.encode(b); + return encoded; +} + +string getData(const AMQFrame& frame) { + const AMQContentBody* content = dynamic_cast(frame.getBody()); + BOOST_CHECK(content); + return content->getData(); +} + +QPID_AUTO_TEST_CASE(testByteFragments) { + string data = makeData(42); + string encoded = encodeFrame(data); + FrameDecoder decoder; + for (size_t i = 0; i < encoded.size()-1; ++i) { + Buffer buf(&encoded[i], 1); + BOOST_CHECK(!decoder.decode(buf)); + } + Buffer buf(&encoded[encoded.size()-1], 1); + BOOST_CHECK(decoder.decode(buf)); + BOOST_CHECK_EQUAL(data, getData(decoder.getFrame())); +} + + + +QPID_AUTO_TEST_SUITE_END() diff --git a/qpid/cpp/src/tests/Makefile.am b/qpid/cpp/src/tests/Makefile.am index 9da85eaad4..7a33a7257b 100644 --- a/qpid/cpp/src/tests/Makefile.am +++ b/qpid/cpp/src/tests/Makefile.am @@ -94,7 +94,8 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \ QueueEvents.cpp \ ProxyTest.cpp \ RetryList.cpp \ - RateFlowcontrolTest.cpp + RateFlowcontrolTest.cpp \ + FrameDecoder.cpp if HAVE_XML unit_test_SOURCES+= XmlClientSessionTest.cpp @@ -163,7 +164,7 @@ header_test_LDADD=$(lib_client) check_PROGRAMS+=failover_soak failover_soak_SOURCES=failover_soak.cpp ForkedBroker.h ForkedBroker.cpp -failover_soak_LDADD=$(lib_client) +failover_soak_LDADD=$(lib_client) $(lib_broker) check_PROGRAMS+=declare_queues declare_queues_SOURCES=declare_queues.cpp @@ -195,11 +196,11 @@ sender_LDADD=$(lib_client) check_PROGRAMS+=PollerTest PollerTest_SOURCES=PollerTest.cpp -PollerTest_LDADD=$(lib_common) +PollerTest_LDADD=$(lib_common) $(SOCKLIBS) check_PROGRAMS+=DispatcherTest DispatcherTest_SOURCES=DispatcherTest.cpp -DispatcherTest_LDADD=$(lib_common) +DispatcherTest_LDADD=$(lib_common) $(SOCKLIBS) TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir) QPID_DATA_DIR= BOOST_TEST_SHOW_PROGRESS=yes $(srcdir)/run_test @@ -255,9 +256,11 @@ CLEANFILES+=valgrind.out *.log *.vglog* dummy_test $(unit_wrappers) # Longer running stability tests, not run by default check: target. # Not run under valgrind, too slow -LONG_TESTS+=start_broker fanout_perftest shared_perftest multiq_perftest topic_perftest run_failover_soak stop_broker reliable_replication_test +LONG_TESTS+=start_broker fanout_perftest shared_perftest multiq_perftest topic_perftest run_failover_soak stop_broker \ + reliable_replication_test federated_cluster_test_with_node_failure -EXTRA_DIST+=fanout_perftest shared_perftest multiq_perftest topic_perftest run_failover_soak reliable_replication_test +EXTRA_DIST+=fanout_perftest shared_perftest multiq_perftest topic_perftest run_failover_soak reliable_replication_test \ + federated_cluster_test_with_node_failure check-long: $(MAKE) check TESTS="$(LONG_TESTS)" VALGRIND= diff --git a/qpid/cpp/src/tests/MessageUtils.h b/qpid/cpp/src/tests/MessageUtils.h index 67a852aa10..6a12c72007 100644 --- a/qpid/cpp/src/tests/MessageUtils.h +++ b/qpid/cpp/src/tests/MessageUtils.h @@ -33,7 +33,7 @@ struct MessageUtils static boost::intrusive_ptr createMessage(const string& exchange="", const string& routingKey="", const Uuid& messageId=Uuid(true), uint64_t contentSize = 0) { - boost::intrusive_ptr msg(new Message()); + boost::intrusive_ptr msg(new broker::Message()); AMQFrame method(( MessageTransferBody(ProtocolVersion(), exchange, 0, 0))); AMQFrame header((AMQHeaderBody())); diff --git a/qpid/cpp/src/tests/PollerTest.cpp b/qpid/cpp/src/tests/PollerTest.cpp index 4f11dc5901..5b6b09ef65 100644 --- a/qpid/cpp/src/tests/PollerTest.cpp +++ b/qpid/cpp/src/tests/PollerTest.cpp @@ -74,7 +74,7 @@ int main(int /*argc*/, char** /*argv*/) try { int sv[2]; - int rc = ::socketpair(AF_LOCAL, SOCK_STREAM, 0, sv); + int rc = ::socketpair(AF_UNIX, SOCK_STREAM, 0, sv); assert(rc >= 0); // Set non-blocking diff --git a/qpid/cpp/src/tests/QueueEvents.cpp b/qpid/cpp/src/tests/QueueEvents.cpp index df3c937e33..cd9439355e 100644 --- a/qpid/cpp/src/tests/QueueEvents.cpp +++ b/qpid/cpp/src/tests/QueueEvents.cpp @@ -38,7 +38,7 @@ using namespace qpid::broker; using namespace qpid::sys; using qpid::framing::SequenceNumber; -struct DummyListener +struct EventChecker { typedef std::deque Events; @@ -71,9 +71,9 @@ QPID_AUTO_TEST_CASE(testBasicEventProcessing) sys::Dispatcher dispatcher(poller); Thread dispatchThread(dispatcher); QueueEvents events(poller); - DummyListener listener; + EventChecker listener; listener.poller = poller; - events.registerListener("dummy", boost::bind(&DummyListener::handle, &listener, _1)); + events.registerListener("dummy", boost::bind(&EventChecker::handle, &listener, _1)); //signal occurence of some events: Queue queue("queue1"); SequenceNumber id; diff --git a/qpid/cpp/src/tests/QueuePolicyTest.cpp b/qpid/cpp/src/tests/QueuePolicyTest.cpp index 6c650169c7..7c7f8b7a10 100644 --- a/qpid/cpp/src/tests/QueuePolicyTest.cpp +++ b/qpid/cpp/src/tests/QueuePolicyTest.cpp @@ -158,6 +158,15 @@ QPID_AUTO_TEST_CASE(testRingPolicy) BOOST_CHECK_EQUAL((boost::format("%1%_%2%") % "Message" % (i+1)).str(), msg.getData()); } BOOST_CHECK(!f.subs.get(msg, q)); + + for (int i = 10; i < 20; i++) { + f.session.messageTransfer(arg::content=client::Message((boost::format("%1%_%2%") % "Message" % (i+1)).str(), q)); + } + for (int i = 15; i < 20; i++) { + BOOST_CHECK(f.subs.get(msg, q, qpid::sys::TIME_SEC)); + BOOST_CHECK_EQUAL((boost::format("%1%_%2%") % "Message" % (i+1)).str(), msg.getData()); + } + BOOST_CHECK(!f.subs.get(msg, q)); } QPID_AUTO_TEST_CASE(testStrictRingPolicy) diff --git a/qpid/cpp/src/tests/SocketProxy.h b/qpid/cpp/src/tests/SocketProxy.h index 9722359d82..d2a93c902b 100644 --- a/qpid/cpp/src/tests/SocketProxy.h +++ b/qpid/cpp/src/tests/SocketProxy.h @@ -94,7 +94,7 @@ class SocketProxy : private qpid::sys::Runnable throwIf(!(event.type == qpid::sys::Poller::READABLE && event.handle == &listenerHandle), "SocketProxy: Accept failed"); poller.delFd(listenerHandle); - server.reset(listener.accept(0, 0)); + server.reset(listener.accept()); // Pump data between client & server sockets qpid::sys::PollerHandle clientHandle(client); diff --git a/qpid/cpp/src/tests/cluster.mk b/qpid/cpp/src/tests/cluster.mk index c3100ac968..5d115de5a5 100644 --- a/qpid/cpp/src/tests/cluster.mk +++ b/qpid/cpp/src/tests/cluster.mk @@ -29,8 +29,9 @@ if HAVE_LIBCPG # ais_check checks pre-requisites for cluster tests and runs them if ok. -TESTS+=ais_check federated_cluster_test -EXTRA_DIST+=ais_check start_cluster stop_cluster restart_cluster cluster_python_tests cluster_python_tests_failing.txt federated_cluster_test +TESTS+=ais_check federated_cluster_test clustered_replication_test +EXTRA_DIST+=ais_check start_cluster stop_cluster restart_cluster cluster_python_tests cluster_python_tests_failing.txt \ + federated_cluster_test clustered_replication_test check_PROGRAMS+=cluster_test cluster_test_SOURCES=unit_test.cpp cluster_test.cpp ClusterFixture.cpp ClusterFixture.h ForkedBroker.h ForkedBroker.cpp diff --git a/qpid/cpp/src/tests/cluster_test.cpp b/qpid/cpp/src/tests/cluster_test.cpp index c880f30e6b..eee2df58cc 100644 --- a/qpid/cpp/src/tests/cluster_test.cpp +++ b/qpid/cpp/src/tests/cluster_test.cpp @@ -27,6 +27,7 @@ #include "qpid/client/ConnectionAccess.h" #include "qpid/client/Session.h" #include "qpid/client/FailoverListener.h" +#include "qpid/client/FailoverManager.h" #include "qpid/cluster/Cluster.h" #include "qpid/cluster/Cpg.h" #include "qpid/cluster/UpdateClient.h" @@ -35,6 +36,8 @@ #include "qpid/framing/reply_exceptions.h" #include "qpid/framing/enum.h" #include "qpid/log/Logger.h" +#include "qpid/sys/Monitor.h" +#include "qpid/sys/Thread.h" #include #include @@ -148,49 +151,65 @@ vector browse(Client& c, const string& q, int n) { c.subs.subscribe(lq, q, browseSettings); vector result; for (int i = 0; i < n; ++i) { - result.push_back(lq.get(TIMEOUT).getData()); + Message m; + if (!lq.get(m, TIMEOUT)) + break; + result.push_back(m.getData()); } c.subs.getSubscription(q).cancel(); return result; } +ConnectionSettings aclSettings(int port, const std::string& id) { + ConnectionSettings settings; + settings.port = port; + settings.mechanism = "PLAIN"; + settings.username = id; + settings.password = id; + return settings; +} + +#if 0 +// FIXME aconway 2009-03-10: This test passes but exposes a memory leak in the SASL client code. +// Enable it when the leak is fixed. + +QPID_AUTO_TEST_CASE(testAcl) { + ofstream policyFile("cluster_test.acl"); + // FIXME aconway 2009-02-12: guest -> qpidd? + policyFile << "acl allow foo@QPID create queue name=foo" << endl + << "acl allow foo@QPID create queue name=foo2" << endl + << "acl deny foo@QPID create queue name=bar" << endl + << "acl allow all all" << endl; + policyFile.close(); + char cwd[1024]; + BOOST_CHECK(::getcwd(cwd, sizeof(cwd))); + ClusterFixture cluster(2,-1, list_of + ("--no-data-dir") + ("--auth=no") + ("--acl-file="+string(cwd)+"/cluster_test.acl") + ("--cluster-mechanism=PLAIN") + ("--cluster-username=cluster") + ("--cluster-password=cluster") + ("--load-module=../.libs/acl.so")); + + Client c0(aclSettings(cluster[0], "c0"), "c0"); + Client c1(aclSettings(cluster[1], "c1"), "c1"); + Client foo(aclSettings(cluster[1], "foo"), "foo"); + + foo.session.queueDeclare("foo"); + BOOST_CHECK_EQUAL(c0.session.queueQuery("foo").getQueue(), "foo"); + + BOOST_CHECK_THROW(foo.session.queueDeclare("bar"), framing::NotAllowedException); + BOOST_CHECK(c0.session.queueQuery("bar").getQueue().empty()); + BOOST_CHECK(c1.session.queueQuery("bar").getQueue().empty()); -// FIXME aconway 2009-02-12: need to figure out how to test this properly. -// Current problems: -// - all brokers share the same data-dir (set ACL without data dir?) -// - updater's user name not making it through to updatee for ACL checks. -// -// QPID_AUTO_TEST_CASE(testAcl) { -// ofstream policyFile("cluster_test.acl"); -// // FIXME aconway 2009-02-12: guest -> qpidd? -// policyFile << "acl allow guest@QPID all all" << endl -// << "acl allow foo@QPID create queue name=foo" << endl -// << "acl allow bar@QPID create queue name=bar" << endl -// << "acl deny all create queue" << endl -// << "acl allow all all" << endl; -// policyFile.close(); -// ClusterFixture cluster(2,-1, list_of -// ("--data-dir=.") ("--auth=no") -// ("--acl-file=cluster_test.acl") -// ("--cluster-mechanism=PLAIN") -// ("--load-module=../.libs/acl.so")); -// Client c0(cluster[0], "c0"); -// Client c1(cluster[1], "c1"); - -// ConnectionSettings settings; -// settings.port = cluster[0]; -// settings.username = "foo"; -// Client foo(settings, "foo"); - -// foo.session.queueDeclare("foo"); -// BOOST_CHECK_EQUAL(c0.session.queueQuery("foo").getQueue(), "foo"); -// BOOST_CHECK_EQUAL(c1.session.queueQuery("foo").getQueue(), "foo"); - -// BOOST_CHECK_THROW(foo.session.queueDeclare("bar"), int); -// BOOST_CHECK_EQUAL(c0.session.queueQuery("bar").getQueue(), ""); -// BOOST_CHECK_EQUAL(c1.session.queueQuery("bar").getQueue(), ""); -// } + cluster.add(); + Client c2(aclSettings(cluster[2], "c2"), "c2"); + BOOST_CHECK_THROW(foo.session.queueDeclare("bar"), framing::NotAllowedException); + BOOST_CHECK(c2.session.queueQuery("bar").getQueue().empty()); +} +#endif QPID_AUTO_TEST_CASE(testMessageTimeToLive) { // Note: this doesn't actually test for cluster race conditions around TTL, @@ -199,13 +218,23 @@ QPID_AUTO_TEST_CASE(testMessageTimeToLive) { ClusterFixture cluster(2); Client c0(cluster[0], "c0"); Client c1(cluster[1], "c1"); + c0.session.queueDeclare("p"); c0.session.queueDeclare("q"); c0.session.messageTransfer(arg::content=ttlMessage("a", "q", 200)); c0.session.messageTransfer(arg::content=Message("b", "q")); - BOOST_CHECK_EQUAL(browse(c1, "q", 2), list_of("a")("b")); - sys::usleep(300*1000); + c0.session.messageTransfer(arg::content=ttlMessage("x", "p", 10000)); + c0.session.messageTransfer(arg::content=Message("y", "p")); + cluster.add(); + Client c2(cluster[1], "c2"); + + BOOST_CHECK_EQUAL(browse(c0, "p", 2), list_of("x")("y")); + BOOST_CHECK_EQUAL(browse(c1, "p", 2), list_of("x")("y")); + BOOST_CHECK_EQUAL(browse(c2, "p", 2), list_of("x")("y")); + + sys::usleep(200*1000); BOOST_CHECK_EQUAL(browse(c0, "q", 1), list_of("b")); BOOST_CHECK_EQUAL(browse(c1, "q", 1), list_of("b")); + BOOST_CHECK_EQUAL(browse(c2, "q", 1), list_of("b")); } QPID_AUTO_TEST_CASE(testSequenceOptions) { @@ -506,10 +535,11 @@ QPID_AUTO_TEST_CASE(testCatchupSharedState) { c0.session.queueDeclare("q"); c0.session.messageTransfer(arg::content=Message("foo","q")); c0.session.messageTransfer(arg::content=Message("bar","q")); + while (c0.session.queueQuery("q").getMessageCount() != 2) sys::usleep(1000); // Wait for message to show up on broker 0. - // Add a new broker, it should catch up. + // Add a new broker, it will catch up. cluster.add(); // Do some work post-add @@ -527,6 +557,7 @@ QPID_AUTO_TEST_CASE(testCatchupSharedState) { BOOST_CHECK(c1.subs.get(m, "q", TIMEOUT)); BOOST_CHECK_EQUAL(m.getData(), "foo"); + BOOST_CHECK_EQUAL(m.getDeliveryProperties().getExchange(), ""); BOOST_CHECK(c1.subs.get(m, "q", TIMEOUT)); BOOST_CHECK_EQUAL(m.getData(), "bar"); BOOST_CHECK_EQUAL(c1.session.queueQuery("q").getMessageCount(), 0u); @@ -628,4 +659,86 @@ QPID_AUTO_TEST_CASE(testDequeueWaitingSubscription) { BOOST_CHECK_EQUAL(0u, c2.session.queueQuery("q").getMessageCount()); } +QPID_AUTO_TEST_CASE(testHeartbeatCancelledOnFailover) +{ + struct Sender : FailoverManager::Command + { + std::string queue; + std::string content; + + Sender(const std::string& q, const std::string& c) : queue(q), content(c) {} + + void execute(AsyncSession& session, bool) + { + session.messageTransfer(arg::content=Message(content, queue)); + } + }; + + struct Receiver : FailoverManager::Command, MessageListener, qpid::sys::Runnable + { + FailoverManager& mgr; + std::string queue; + std::string expectedContent; + qpid::client::Subscription subscription; + qpid::sys::Monitor lock; + bool ready; + + Receiver(FailoverManager& m, const std::string& q, const std::string& c) : mgr(m), queue(q), expectedContent(c), ready(false) {} + + void received(Message& message) + { + BOOST_CHECK_EQUAL(expectedContent, message.getData()); + subscription.cancel(); + } + + void execute(AsyncSession& session, bool) + { + session.queueDeclare(arg::queue=queue); + SubscriptionManager subs(session); + subscription = subs.subscribe(*this, queue); + session.sync(); + setReady(); + subs.run(); + //cleanup: + session.queueDelete(arg::queue=queue); + } + + void run() + { + mgr.execute(*this); + } + + void waitForReady() + { + qpid::sys::Monitor::ScopedLock l(lock); + while (!ready) { + lock.wait(); + } + } + + void setReady() + { + qpid::sys::Monitor::ScopedLock l(lock); + ready = true; + lock.notify(); + } + }; + + ClusterFixture cluster(2); + ConnectionSettings settings; + settings.port = cluster[1]; + settings.heartbeat = 1; + FailoverManager fmgr(settings); + Sender sender("my-queue", "my-data"); + Receiver receiver(fmgr, "my-queue", "my-data"); + qpid::sys::Thread runner(receiver); + receiver.waitForReady(); + cluster.kill(1); + //sleep for 2 secs to allow the heartbeat task to fire on the now dead connection: + ::usleep(2*1000*1000); + fmgr.execute(sender); + runner.join(); + fmgr.close(); +} + QPID_AUTO_TEST_SUITE_END() diff --git a/qpid/cpp/src/tests/clustered_replication_test b/qpid/cpp/src/tests/clustered_replication_test new file mode 100755 index 0000000000..2a3e742632 --- /dev/null +++ b/qpid/cpp/src/tests/clustered_replication_test @@ -0,0 +1,127 @@ +#!/bin/sh + +# +# 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. +# + +# Test reliability of the replication feature in the face of link +# failures: +srcdir=`dirname $0` +PYTHON_DIR=$srcdir/../../../python + +trap stop_brokers INT EXIT + +fail() { + echo $1 + exit 1 +} +with_ais_group() { + id -nG | grep '\' >/dev/null || { echo "You are not a member of the ais group." 1>&2; exit 1; } + echo $* | newgrp ais +} + +stop_brokers() { + if [[ $PRIMARY1 ]] ; then + ../qpidd -q --port $PRIMARY1 + unset PRIMARY1 + fi + if [[ $PRIMARY2 ]] ; then + ../qpidd -q --port $PRIMARY2 + unset PRIMARY2 + fi + if [[ $DR1 ]] ; then + ../qpidd -q --port $DR1 + unset DR1 + fi + if [[ $DR2 ]] ; then + ../qpidd -q --port $DR2 + unset DR2 + fi +} + +if test -d ${PYTHON_DIR}; then + id -nG | grep '\' >/dev/null || \ + NOGROUP="You are not a member of the ais group." + ps -u root | grep 'aisexec\|corosync' >/dev/null || \ + NOAISEXEC="The aisexec or corosync daemon is not running as root" + + if test -n "$NOGROUP" -o -n "$NOAISEXEC"; then + cat < /dev/null + + #add new node to primary cluster, testing correct transfer of state: + echo Adding node to primary cluster + PRIMARY2=$(with_ais_group ../qpidd $GENERAL_OPTS $PRIMARY_OPTS --log-to-file repl.primary.2.tmp) + + #start DR cluster, set up test queue there and establish replication bridge + echo Starting DR cluster + DR1=$(with_ais_group ../qpidd $GENERAL_OPTS $DR_OPTS --log-to-file repl.dr.1.tmp) + DR2=$(with_ais_group ../qpidd $GENERAL_OPTS $DR_OPTS --log-to-file repl.dr.2.tmp) + + $PYTHON_DIR/commands/qpid-config -a "localhost:$DR1" add queue test-queue + $PYTHON_DIR/commands/qpid-config -a "localhost:$DR1" add queue control-queue + $PYTHON_DIR/commands/qpid-config -a "localhost:$DR1" add exchange replication REPLICATION_EXCHANGE + $PYTHON_DIR/commands/qpid-route queue add localhost:$DR2 localhost:$PRIMARY2 REPLICATION_EXCHANGE REPLICATION_QUEUE + + #send more messages to primary + for i in `seq 11 20`; do echo Message$i; done | ./sender --port $PRIMARY1 --send-eos 1 + + #wait for replication events to all be processed: + echo Waiting for replication to complete + echo Done | ./sender --port $PRIMARY1 --routing-key control-queue --send-eos 1 + ./receiver --queue control-queue --port $DR1 > /dev/null + + #verify contents of test queue on dr cluster: + echo Verifying... + ./receiver --port $DR2 > repl.out.tmp + for i in `seq 6 20`; do echo Message$i; done | diff repl.out.tmp - || FAIL=1 + + if [[ $FAIL ]]; then + echo Clustered replication test failed: expectations not met! + exit 1 + else + echo Clustered replication test passed + rm -f repl*.tmp + fi + +fi diff --git a/qpid/cpp/src/tests/failover_soak.cpp b/qpid/cpp/src/tests/failover_soak.cpp index 129c6b9745..4f16e469b8 100644 --- a/qpid/cpp/src/tests/failover_soak.cpp +++ b/qpid/cpp/src/tests/failover_soak.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include @@ -34,7 +36,11 @@ #include +#include "qpid/framing/Uuid.h" + #include +#include + @@ -42,6 +48,9 @@ using namespace std; using boost::assign::list_of; +using namespace qpid::framing; +using namespace qpid::client; + @@ -56,11 +65,34 @@ typedef enum childStatus; +typedef enum +{ + NO_TYPE, + DECLARING_CLIENT, + SENDING_CLIENT, + RECEIVING_CLIENT +} +childType; + + +ostream& operator<< ( ostream& os, const childType& ct ) { + switch ( ct ) { + case DECLARING_CLIENT: os << "Declaring Client"; break; + case SENDING_CLIENT: os << "Sending Client"; break; + case RECEIVING_CLIENT: os << "Receiving Client"; break; + default: os << "No Client"; break; + } + + return os; +} + + + struct child { - child ( string & name, pid_t pid ) - : name(name), pid(pid), retval(-999), status(RUNNING) + child ( string & name, pid_t pid, childType type ) + : name(name), pid(pid), retval(-999), status(RUNNING), type(type) { gettimeofday ( & startTime, 0 ); } @@ -75,10 +107,18 @@ struct child } + void + setType ( childType t ) + { + type = t; + } + + string name; pid_t pid; int retval; childStatus status; + childType type; struct timeval startTime, stopTime; }; @@ -88,10 +128,11 @@ struct child struct children : public vector { + void - add ( string & name, pid_t pid ) + add ( string & name, pid_t pid, childType type ) { - push_back(new child ( name, pid )); + push_back ( new child ( name, pid, type ) ); } @@ -113,7 +154,7 @@ struct children : public vector child * kid = get ( pid ); if(! kid) { - if ( verbosity > 0 ) + if ( verbosity > 1 ) { cerr << "children::exited warning: Can't find child with pid " << pid @@ -143,10 +184,15 @@ struct children : public vector int checkChildren ( ) { - vector::iterator i; + vector::iterator i; for ( i = begin(); i != end(); ++ i ) if ( (COMPLETED == (*i)->status) && (0 != (*i)->retval) ) - return (*i)->retval; + { + cerr << "checkChildren: error on child of type " + << (*i)->type + << endl; + return (*i)->retval; + } return 0; } @@ -181,22 +227,43 @@ struct children : public vector If it has been at least that long since a shild stopped running, we judge the system to have hung. */ - bool + int hanging ( int hangTime ) { struct timeval now, duration; gettimeofday ( &now, 0 ); + int how_many_hanging = 0; + vector::iterator i; for ( i = begin(); i != end(); ++ i ) { - timersub ( & now, &((*i)->startTime), & duration ); - if ( duration.tv_sec >= hangTime ) - return true; + //Not in POSIX + //timersub ( & now, &((*i)->startTime), & duration ); + duration.tv_sec = now.tv_sec - (*i)->startTime.tv_sec; + duration.tv_usec = now.tv_usec - (*i)->startTime.tv_usec; + if (duration.tv_usec < 0) { + --duration.tv_sec; + duration.tv_usec += 1000000; + } + + if ( (COMPLETED != (*i)->status) // child isn't done running + && + ( duration.tv_sec >= hangTime ) // it's been too long + ) + { + std::cerr << "Child of type " + << (*i)->type + << " hanging. " + << "PID is " + << (*i)->pid + << endl; + ++ how_many_hanging; + } } - return false; + return how_many_hanging; } @@ -211,9 +278,8 @@ children allMyChildren; void -childExit ( int signalNumber ) +childExit ( int ) { - signalNumber ++; // Now maybe the compiler willleave me alone? int childReturnCode; pid_t pid = waitpid ( 0, & childReturnCode, WNOHANG); @@ -240,10 +306,9 @@ mrand ( int minDesiredVal, int maxDesiredVal ) { void -makeClusterName ( string & s, int & num ) { - num = mrand(1000); +makeClusterName ( string & s ) { stringstream ss; - ss << "soakTestCluster_" << num; + ss << "soakTestCluster_" << Uuid(true).str(); s = ss.str(); } @@ -268,64 +333,136 @@ printBrokers ( brokerVector & brokers ) +ForkedBroker * newbie = 0; +int newbie_port = 0; + + + +bool +wait_for_newbie ( ) +{ + if ( ! newbie ) + return true; + + try + { + Connection connection; + connection.open ( "127.0.0.1", newbie_port ); + connection.close(); + newbie = 0; // He's no newbie anymore! + return true; + } + catch ( const std::exception& error ) + { + std::cerr << "wait_for_newbie error: " + << error.what() + << endl; + return false; + } +} + + + void startNewBroker ( brokerVector & brokers, char const * srcRoot, char const * moduleDir, - string const clusterName ) + string const clusterName, + int verbosity ) { static int brokerId = 0; stringstream path, prefix, module; module << moduleDir << "/cluster.so"; path << srcRoot << "/qpidd"; - prefix << "soak-" << brokerId++; - - std::vector argv = - list_of ("qpidd") - ("--no-module-dir") - ("--load-module=cluster.so") - ("--cluster-name") - (clusterName) - ("--auth=no") - ("--no-data-dir") - ("--mgmt-enable=no") - ("--log-prefix") - (prefix.str()) - ("--log-to-file") - ("/tmp/qpidd.log"); - - brokers.push_back ( new ForkedBroker ( argv ) ); + prefix << "soak-" << brokerId; + std::vector argv = list_of + ("qpidd") + ("--no-module-dir") + ("--load-module=cluster.so") + ("--cluster-name") + (clusterName) + ("--auth=no") + ("--no-data-dir") + ("--mgmt-enable=no") + ("--log-prefix") + (prefix.str()) + ("--log-to-file") + (prefix.str()+".log"); + + newbie = new ForkedBroker ( argv ); + newbie_port = newbie->getPort(); + ForkedBroker * broker = newbie; + + if ( verbosity > 0 ) + std::cerr << "new broker created: pid == " + << broker->getPID() + << " log-prefix == " + << "soak-" << brokerId + << endl; + brokers.push_back ( broker ); + + ++ brokerId; } -void +bool killFrontBroker ( brokerVector & brokers, int verbosity ) { + cerr << "killFrontBroker: waiting for newbie sync...\n"; + if ( ! wait_for_newbie() ) + return false; + cerr << "killFrontBroker: newbie synced.\n"; + if ( verbosity > 0 ) cout << "killFrontBroker pid: " << brokers[0]->getPID() << " on port " << brokers[0]->getPort() << endl; try { brokers[0]->kill(9); } catch ( const exception& error ) { if ( verbosity > 0 ) - cout << "error killing broker: " << error.what() << endl; + { + cout << "error killing broker: " + << error.what() + << endl; + } + + return false; } delete brokers[0]; brokers.erase ( brokers.begin() ); + return true; } +/* + * The optional delay is to avoid killing newbie brokers that have just + * been added and are still in the process of updating. This causes + * spurious, test-generated errors that scare everybody. + */ void -killAllBrokers ( brokerVector & brokers ) +killAllBrokers ( brokerVector & brokers, int delay ) { + if ( delay > 0 ) + { + std::cerr << "Killing all brokers after delay of " << delay << endl; + sleep ( delay ); + } + for ( uint i = 0; i < brokers.size(); ++ i ) try { brokers[i]->kill(9); } - catch ( ... ) { } + catch ( const exception& error ) + { + std::cerr << "killAllBrokers Warning: exception during kill on broker " + << i + << " " + << error.what() + << endl; + } } @@ -342,7 +479,7 @@ runDeclareQueuesClient ( brokerVector brokers, string name("declareQueues"); int port = brokers[0]->getPort ( ); - if ( verbosity > 0 ) + if ( verbosity > 1 ) cout << "startDeclareQueuesClient: host: " << host << " port: " @@ -360,11 +497,11 @@ runDeclareQueuesClient ( brokerVector brokers, if ( ! pid ) { execv ( path, const_cast(&argv[0]) ); - perror ( "error executing dq: " ); + perror ( "error executing declareQueues: " ); return 0; } - allMyChildren.add ( name, pid ); + allMyChildren.add ( name, pid, DECLARING_CLIENT ); return pid; } @@ -383,12 +520,16 @@ startReceivingClient ( brokerVector brokers, string name("receiver"); int port = brokers[0]->getPort ( ); - if ( verbosity > 0 ) + if ( verbosity > 1 ) cout << "startReceivingClient: port " << port << endl; + + // verbosity has to be > 1 to let clients talk. + int client_verbosity = (verbosity > 1 ) ? 1 : 0; + char portStr[100]; char verbosityStr[100]; sprintf(portStr, "%d", port); - sprintf(verbosityStr, "%d", verbosity); + sprintf(verbosityStr, "%d", client_verbosity); vector argv; @@ -407,7 +548,7 @@ startReceivingClient ( brokerVector brokers, return 0; } - allMyChildren.add ( name, pid ); + allMyChildren.add ( name, pid, RECEIVING_CLIENT ); return pid; } @@ -427,13 +568,16 @@ startSendingClient ( brokerVector brokers, string name("sender"); int port = brokers[0]->getPort ( ); - if ( verbosity ) + if ( verbosity > 1) cout << "startSenderClient: port " << port << endl; char portStr[100]; char verbosityStr[100]; + // + // verbosity has to be > 1 to let clients talk. + int client_verbosity = (verbosity > 1 ) ? 1 : 0; sprintf ( portStr, "%d", port); - sprintf ( verbosityStr, "%d", verbosity); + sprintf ( verbosityStr, "%d", client_verbosity); vector argv; argv.push_back ( "replayingSender" ); @@ -452,19 +596,21 @@ startSendingClient ( brokerVector brokers, return 0; } - allMyChildren.add ( name, pid ); + allMyChildren.add ( name, pid, SENDING_CLIENT ); return pid; } -#define HUNKY_DORY 0 -#define BAD_ARGS 1 -#define CANT_FORK_DQ 2 -#define CANT_FORK_RECEIVER 3 -#define DQ_FAILED 4 -#define ERROR_ON_CHILD 5 -#define HANGING 6 +#define HUNKY_DORY 0 +#define BAD_ARGS 1 +#define CANT_FORK_DQ 2 +#define CANT_FORK_RECEIVER 3 +#define CANT_FORK_SENDER 4 +#define DQ_FAILED 5 +#define ERROR_ON_CHILD 6 +#define HANGING 7 +#define ERROR_KILLING_BROKER 8 int @@ -492,16 +638,15 @@ main ( int argc, char const ** argv ) allMyChildren.verbosity = verbosity; - int clusterNum; string clusterName; srand ( getpid() ); - makeClusterName ( clusterName, clusterNum ); + makeClusterName ( clusterName ); brokerVector brokers; - if ( verbosity > 0 ) + if ( verbosity > 1 ) cout << "Starting initial cluster...\n"; int nBrokers = 3; @@ -509,7 +654,8 @@ main ( int argc, char const ** argv ) startNewBroker ( brokers, srcRoot, moduleDir, - clusterName ); + clusterName, + verbosity ); } @@ -521,14 +667,14 @@ main ( int argc, char const ** argv ) pid_t dqClientPid = runDeclareQueuesClient ( brokers, host, declareQueuesPath, verbosity ); if ( -1 == dqClientPid ) { - cerr << "failoverSoak error: Couldn't fork declareQueues.\n"; + cerr << "END_OF_TEST ERROR_START_DECLARE_1\n"; return CANT_FORK_DQ; } // Don't continue until declareQueues is finished. pid_t retval = waitpid ( dqClientPid, & childStatus, 0); if ( retval != dqClientPid) { - cerr << "failoverSoak error: waitpid on declareQueues returned value " << retval << endl; + cerr << "END_OF_TEST ERROR_START_DECLARE_2\n"; return DQ_FAILED; } allMyChildren.exited ( dqClientPid, childStatus ); @@ -543,7 +689,7 @@ main ( int argc, char const ** argv ) reportFrequency, verbosity ); if ( -1 == receivingClientPid ) { - cerr << "failoverSoak error: Couldn't fork receiver.\n"; + cerr << "END_OF_TEST ERROR_START_RECEIVER\n"; return CANT_FORK_RECEIVER; } @@ -557,13 +703,13 @@ main ( int argc, char const ** argv ) reportFrequency, verbosity ); if ( -1 == sendingClientPid ) { - cerr << "failoverSoak error: Couldn't fork sender.\n"; - return CANT_FORK_RECEIVER; + cerr << "END_OF_TEST ERROR_START_SENDER\n"; + return CANT_FORK_SENDER; } - int minSleep = 3, - maxSleep = 6; + int minSleep = 2, + maxSleep = 4; for ( int totalBrokers = 3; @@ -581,11 +727,16 @@ main ( int argc, char const ** argv ) sleep ( sleepyTime ); // Kill the oldest broker. -------------------------- - killFrontBroker ( brokers, verbosity ); + if ( ! killFrontBroker ( brokers, verbosity ) ) + { + allMyChildren.killEverybody(); + std::cerr << "END_OF_TEST ERROR_BROKER\n"; + return ERROR_KILLING_BROKER; + } // Sleep for a while. ------------------------- sleepyTime = mrand ( minSleep, maxSleep ); - if ( verbosity > 0 ) + if ( verbosity > 1 ) cerr << "Sleeping for " << sleepyTime << " seconds.\n"; sleep ( sleepyTime ); @@ -596,22 +747,33 @@ main ( int argc, char const ** argv ) startNewBroker ( brokers, srcRoot, moduleDir, - clusterName ); + clusterName, + verbosity ); - if ( verbosity > 0 ) + if ( verbosity > 1 ) printBrokers ( brokers ); // If all children have exited, quit. int unfinished = allMyChildren.unfinished(); if ( ! unfinished ) { - killAllBrokers ( brokers ); + killAllBrokers ( brokers, 5 ); - if ( verbosity > 0 ) + if ( verbosity > 1 ) cout << "failoverSoak: all children have exited.\n"; int retval = allMyChildren.checkChildren(); - if ( verbosity > 0 ) + if ( verbosity > 1 ) std::cerr << "failoverSoak: checkChildren: " << retval << endl; - return retval ? ERROR_ON_CHILD : HUNKY_DORY; + + if ( retval ) + { + std::cerr << "END_OF_TEST ERROR_CLIENT\n"; + return ERROR_ON_CHILD; + } + else + { + std::cerr << "END_OF_TEST SUCCESSFUL\n"; + return HUNKY_DORY; + } } // Even if some are still running, if there's an error, quit. @@ -620,35 +782,38 @@ main ( int argc, char const ** argv ) if ( verbosity > 0 ) cout << "failoverSoak: error on child.\n"; allMyChildren.killEverybody(); - killAllBrokers ( brokers ); + killAllBrokers ( brokers, 5 ); + std::cerr << "END_OF_TEST ERROR_CLIENT\n"; return ERROR_ON_CHILD; } // If one is hanging, quit. if ( allMyChildren.hanging ( 120 ) ) { - if ( verbosity > 0 ) - cout << "failoverSoak: child hanging.\n"; - allMyChildren.killEverybody(); - killAllBrokers ( brokers ); + /* + * Don't kill any processes. Leave alive for questioning. + * */ + std::cerr << "END_OF_TEST ERROR_HANGING\n"; return HANGING; } - if ( verbosity > 0 ) { + if ( verbosity > 1 ) { std::cerr << "------- next kill-broker loop --------\n"; allMyChildren.print(); } } retval = allMyChildren.checkChildren(); - if ( verbosity > 0 ) + if ( verbosity > 1 ) std::cerr << "failoverSoak: checkChildren: " << retval << endl; - if ( verbosity > 0 ) + if ( verbosity > 1 ) cout << "failoverSoak: maxBrokers reached.\n"; allMyChildren.killEverybody(); - killAllBrokers ( brokers ); + killAllBrokers ( brokers, 5 ); + + std::cerr << "END_OF_TEST SUCCESSFUL\n"; return retval ? ERROR_ON_CHILD : HUNKY_DORY; } diff --git a/qpid/cpp/src/tests/federated_cluster_test b/qpid/cpp/src/tests/federated_cluster_test index ef0db4cb8e..575a5d9c9b 100755 --- a/qpid/cpp/src/tests/federated_cluster_test +++ b/qpid/cpp/src/tests/federated_cluster_test @@ -22,7 +22,7 @@ # Test reliability of the replication feature in the face of link # failures: srcdir=`dirname $0` -PYTHON_DIR=${srcdir}/../../../python +PYTHON_DIR=$srcdir/../../../python trap stop_brokers EXIT @@ -37,9 +37,14 @@ stop_brokers() { unset BROKER_A fi if [[ $NODE_1 ]] ; then - ./stop_cluster + ../qpidd -q --port $NODE_1 unset NODE_1 fi + if [[ $NODE_2 ]] ; then + ../qpidd -q --port $NODE_2 + unset NODE_2 + fi + rm cluster.ports } start_brokers() { @@ -60,8 +65,8 @@ setup() { $PYTHON_DIR/commands/qpid-config -a "localhost:$NODE_1" add exchange direct test-exchange #create dynamic routes for test exchange - $PYTHON_DIR/commands/qpid-route dynamic add "localhost:$NODE_1" "localhost:$BROKER_A" test-exchange - $PYTHON_DIR/commands/qpid-route dynamic add "localhost:$BROKER_A" "localhost:$NODE_1" test-exchange + $PYTHON_DIR/commands/qpid-route dynamic add "localhost:$NODE_2" "localhost:$BROKER_A" test-exchange + $PYTHON_DIR/commands/qpid-route dynamic add "localhost:$BROKER_A" "localhost:$NODE_2" test-exchange #create test queue on cluster and bind it to the test exchange $PYTHON_DIR/commands/qpid-config -a "localhost:$NODE_1" add queue test-queue @@ -72,7 +77,7 @@ setup() { $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_A" bind test-exchange test-queue from-cluster } -run_test_pull_to_cluster() { +run_test_pull_to_cluster_two_consumers() { #start consumers on each of the two nodes of the cluster ./receiver --port $NODE_1 --queue test-queue --credit-window 1 > fed1.out.tmp & ./receiver --port $NODE_2 --queue test-queue --credit-window 1 > fed2.out.tmp & @@ -89,6 +94,20 @@ run_test_pull_to_cluster() { rm -f fed*.tmp #cleanup } +run_test_pull_to_cluster() { + #send stream of messages to test exchange on single broker + for i in `seq 1 1000`; do echo Message $i >> fed.in.tmp; done + ./sender --port $BROKER_A --exchange test-exchange --routing-key to-cluster --send-eos 1 < fed.in.tmp + + #consume from remaining node of the cluster + ./receiver --port $NODE_2 --queue test-queue > fed.out.tmp + + #verify all messages are received + diff fed.in.tmp fed.out.tmp || fail "federated link to cluster failed: expectations not met!" + + rm -f fed*.tmp #cleanup +} + run_test_pull_from_cluster() { #start consumer on single broker ./receiver --port $BROKER_A --queue test-queue --credit-window 1 > fed.out.tmp & @@ -125,8 +144,19 @@ EOF echo "brokers started" setup echo "setup completed" - run_test_pull_to_cluster + run_test_pull_to_cluster_two_consumers echo "federated link to cluster verified" run_test_pull_from_cluster echo "federated link from cluster verified" + if [[ $TEST_NODE_FAILURE ]] ; then + #kill first cluster node and retest + kill -9 $(../qpidd --check --port $NODE_1) && unset NODE_1 + echo "killed first cluster node; waiting for links to re-establish themselves..." + sleep 5 + echo "retesting..." + run_test_pull_to_cluster + echo "federated link to cluster verified" + run_test_pull_from_cluster + echo "federated link from cluster verified" + fi fi diff --git a/qpid/cpp/src/tests/federated_cluster_test_with_node_failure b/qpid/cpp/src/tests/federated_cluster_test_with_node_failure new file mode 100755 index 0000000000..f144a676de --- /dev/null +++ b/qpid/cpp/src/tests/federated_cluster_test_with_node_failure @@ -0,0 +1,23 @@ +#!/bin/sh + +# +# 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. +# + +srcdir=`dirname $0` +TEST_NODE_FAILURE=1 $srcdir/federated_cluster_test diff --git a/qpid/cpp/src/tests/receiver.cpp b/qpid/cpp/src/tests/receiver.cpp index 1ecaece51e..49f7ff0338 100644 --- a/qpid/cpp/src/tests/receiver.cpp +++ b/qpid/cpp/src/tests/receiver.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include "TestOptions.h" #include @@ -43,15 +43,17 @@ struct Args : public qpid::TestOptions bool ignoreDuplicates; uint creditWindow; uint ackFrequency; + bool browse; - Args() : queue("test-queue"), messages(0), ignoreDuplicates(false), creditWindow(0), ackFrequency(1) + Args() : queue("test-queue"), messages(0), ignoreDuplicates(false), creditWindow(0), ackFrequency(1), browse(false) { addOptions() ("queue", qpid::optValue(queue, "QUEUE NAME"), "Queue from which to request messages") ("messages", qpid::optValue(messages, "N"), "Number of messages to receive; 0 means receive indefinitely") ("ignore-duplicates", qpid::optValue(ignoreDuplicates), "Detect and ignore duplicates (by checking 'sn' header)") ("credit-window", qpid::optValue(creditWindow, "N"), "Credit window (0 implies infinite window)") - ("ack-frequency", qpid::optValue(ackFrequency, "N"), "Ack frequency (0 implies none of the messages will get accepted)"); + ("ack-frequency", qpid::optValue(ackFrequency, "N"), "Ack frequency (0 implies none of the messages will get accepted)") + ("browse", qpid::optValue(browse), "Browse rather than consuming"); } }; @@ -60,7 +62,7 @@ const string EOS("eos"); class Receiver : public MessageListener, public FailoverManager::Command { public: - Receiver(const string& queue, uint messages, bool ignoreDuplicates, uint creditWindow, uint ackFrequency); + Receiver(const string& queue, uint messages, bool ignoreDuplicates, uint creditWindow, uint ackFrequency, bool browse); void received(Message& message); void execute(AsyncSession& session, bool isRetry); private: @@ -75,9 +77,10 @@ class Receiver : public MessageListener, public FailoverManager::Command bool isDuplicate(Message& message); }; -Receiver::Receiver(const string& q, uint messages, bool ignoreDuplicates, uint creditWindow, uint ackFrequency) : +Receiver::Receiver(const string& q, uint messages, bool ignoreDuplicates, uint creditWindow, uint ackFrequency, bool browse) : queue(q), count(messages), skipDups(ignoreDuplicates), processed(0), lastSn(0) { + if (browse) settings.acquireMode = ACQUIRE_MODE_NOT_ACQUIRED; if (creditWindow) settings.flowControl = FlowControl::messageWindow(creditWindow); settings.autoAck = ackFrequency; } @@ -107,6 +110,9 @@ void Receiver::execute(AsyncSession& session, bool /*isRetry*/) SubscriptionManager subs(session); subscription = subs.subscribe(*this, queue, settings); subs.run(); + if (settings.autoAck) { + subscription.accept(subscription.getUnaccepted()); + } } int main(int argc, char ** argv) @@ -115,7 +121,7 @@ int main(int argc, char ** argv) try { opts.parse(argc, argv); FailoverManager connection(opts.con); - Receiver receiver(opts.queue, opts.messages, opts.ignoreDuplicates, opts.creditWindow, opts.ackFrequency); + Receiver receiver(opts.queue, opts.messages, opts.ignoreDuplicates, opts.creditWindow, opts.ackFrequency, opts.browse); connection.execute(receiver); connection.close(); return 0; diff --git a/qpid/cpp/src/tests/replaying_sender.cpp b/qpid/cpp/src/tests/replaying_sender.cpp index 7e148e277f..ea2a13bd54 100644 --- a/qpid/cpp/src/tests/replaying_sender.cpp +++ b/qpid/cpp/src/tests/replaying_sender.cpp @@ -60,6 +60,8 @@ Sender::Sender(const std::string& queue, uint count_, uint reportFreq ) : sender void Sender::execute(AsyncSession& session, bool isRetry) { + if (verbosity > 0) + std::cout << "replaying_sender " << (isRetry ? "first " : "re-") << "connect." << endl; if (isRetry) sender.replay(session); else sender.init(session); while (sent < count) { @@ -70,7 +72,7 @@ void Sender::execute(AsyncSession& session, bool isRetry) sender.send(message); if (count > reportFrequency && !(sent % reportFrequency)) { if ( verbosity > 0 ) - std::cout << "sent " << sent << " of " << count << std::endl; + std::cout << "Sender sent " << sent << " of " << count << std::endl; } } message.setData("That's all, folks!"); diff --git a/qpid/cpp/src/tests/replication_test b/qpid/cpp/src/tests/replication_test index 9b6e5cfb29..605ee1376c 100755 --- a/qpid/cpp/src/tests/replication_test +++ b/qpid/cpp/src/tests/replication_test @@ -55,10 +55,12 @@ if test -d ${PYTHON_DIR} && test -e ../.libs/replicating_listener.so && test -e $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_A" add queue queue-a --generate-queue-events 2 $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_A" add queue queue-b --generate-queue-events 2 $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_A" add queue queue-c --generate-queue-events 1 + $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_A" add queue queue-d --generate-queue-events 2 $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_B" add queue queue-a $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_B" add queue queue-b $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_B" add queue queue-c + #queue-d deliberately not declared on DR; this error case should be handled #publish and consume from test queus on broker A: for i in `seq 1 10`; do echo Message $i for A >> queue-a-input.repl; done @@ -68,10 +70,12 @@ if test -d ${PYTHON_DIR} && test -e ../.libs/replicating_listener.so && test -e ./sender --port $BROKER_A --routing-key queue-a --send-eos 1 < queue-a-input.repl ./sender --port $BROKER_A --routing-key queue-b --send-eos 1 < queue-b-input.repl ./sender --port $BROKER_A --routing-key queue-c --send-eos 1 < queue-c-input.repl + echo dummy | ./sender --port $BROKER_A --routing-key queue-d --send-eos 1 ./receiver --port $BROKER_A --queue queue-a --messages 5 > /dev/null ./receiver --port $BROKER_A --queue queue-b --messages 10 > /dev/null ./receiver --port $BROKER_A --queue queue-c --messages 10 > /dev/null + ./receiver --port $BROKER_A --queue queue-d > /dev/null #shutdown broker A then check that broker Bs versions of the queues are as expected ../qpidd -q --port $BROKER_A @@ -90,6 +94,8 @@ if test -d ${PYTHON_DIR} && test -e ../.libs/replicating_listener.so && test -e diff queue-b-backup.repl queue-b-expected.repl || FAIL=1 diff queue-c-backup.repl queue-c-input.repl || FAIL=1 + grep 'queue-d does not exist' replication-dest.log > /dev/null || echo "WARNING: Expected error to be logged!" + if [[ $FAIL ]]; then echo replication test failed: expectations not met! exit 1 diff --git a/qpid/cpp/src/tests/resuming_receiver.cpp b/qpid/cpp/src/tests/resuming_receiver.cpp index f49a115e1e..ef559a009d 100644 --- a/qpid/cpp/src/tests/resuming_receiver.cpp +++ b/qpid/cpp/src/tests/resuming_receiver.cpp @@ -53,6 +53,7 @@ class Listener : public MessageListener, bool gaps; uint reportFrequency; int verbosity; + bool done; }; @@ -62,7 +63,8 @@ Listener::Listener(int freq, int verbosity) lastSn(0), gaps(false), reportFrequency(freq), - verbosity(verbosity) + verbosity(verbosity), + done(false) {} @@ -70,6 +72,7 @@ void Listener::received(Message & message) { if (message.getData() == "That's all, folks!") { + done = true; if(verbosity > 0 ) { std::cout << "Shutting down listener for " @@ -111,14 +114,14 @@ void Listener::check() if (gaps) throw Exception("Detected gaps in sequence; messages appear to have been lost."); } -void Listener::execute(AsyncSession& session, bool isRetry) -{ - if (isRetry) { - // std::cout << "Resuming from " << count << std::endl; +void Listener::execute(AsyncSession& session, bool isRetry) { + if (verbosity > 0) + std::cout << "resuming_receiver " << (isRetry ? "first " : "re-") << "connect." << endl; + if (!done) { + SubscriptionManager subs(session); + subscription = subs.subscribe(*this, "message_queue"); + subs.run(); } - SubscriptionManager subs(session); - subscription = subs.subscribe(*this, "message_queue"); - subs.run(); } void Listener::editUrlList(std::vector& urls) diff --git a/qpid/cpp/src/tests/run_failover_soak b/qpid/cpp/src/tests/run_failover_soak index 9dddf59cf1..36dfed79a6 100755 --- a/qpid/cpp/src/tests/run_failover_soak +++ b/qpid/cpp/src/tests/run_failover_soak @@ -22,8 +22,8 @@ # Check AIS requirements and run tests if found. id -ng | grep '\' >/dev/null || \ NOGROUP="The ais group is not your primary group." -ps -u root | grep aisexec >/dev/null || \ - NOAISEXEC="The aisexec daemon is not running as root" +ps -u root | grep 'aisexec\|corosync' >/dev/null || \ + NOAISEXEC="The aisexec/corosync daemon is not running as root" if test -n "$NOGROUP" -o -n "$NOAISEXEC"; then cat < #include #include +#include #include #include "TestOptions.h" @@ -40,13 +41,17 @@ struct Args : public qpid::TestOptions string destination; string key; uint sendEos; + bool durable; + string lvqMatchValue; - Args() : key("test-queue"), sendEos(0) + Args() : key("test-queue"), sendEos(0), durable(false) { - addOptions() + addOptions() ("exchange", qpid::optValue(destination, "EXCHANGE"), "Exchange to send messages to") ("routing-key", qpid::optValue(key, "KEY"), "Routing key to add to messages") - ("send-eos", qpid::optValue(sendEos, "N"), "Send N EOS messages to mark end of input"); + ("send-eos", qpid::optValue(sendEos, "N"), "Send N EOS messages to mark end of input") + ("durable", qpid::optValue(durable, "true|false"), "Mark messages as durable.") + ("lvq-match-value", qpid::optValue(lvqMatchValue, "KEY"), "The value to set for the LVQ match key property"); } }; @@ -55,7 +60,7 @@ const string EOS("eos"); class Sender : public FailoverManager::Command { public: - Sender(const std::string& destination, const std::string& key, uint sendEos); + Sender(const std::string& destination, const std::string& key, uint sendEos, bool durable, const std::string& lvqMatchValue); void execute(AsyncSession& session, bool isRetry); private: const std::string destination; @@ -65,8 +70,17 @@ class Sender : public FailoverManager::Command uint sent; }; -Sender::Sender(const std::string& dest, const std::string& key, uint eos) : - destination(dest), sender(10), message("", key), sendEos(eos), sent(0) {} +Sender::Sender(const std::string& dest, const std::string& key, uint eos, bool durable, const std::string& lvqMatchValue) : + destination(dest), sender(10), message("", key), sendEos(eos), sent(0) +{ + if (durable){ + message.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT); + } + + if (!lvqMatchValue.empty()) { + message.getHeaders().setString(QueueOptions::strLVQMatchProperty, lvqMatchValue); + } +} void Sender::execute(AsyncSession& session, bool isRetry) { @@ -90,7 +104,7 @@ int main(int argc, char ** argv) try { opts.parse(argc, argv); FailoverManager connection(opts.con); - Sender sender(opts.destination, opts.key, opts.sendEos); + Sender sender(opts.destination, opts.key, opts.sendEos, opts.durable, opts.lvqMatchValue); connection.execute(sender); connection.close(); return 0; diff --git a/qpid/cpp/src/tests/ssl_test b/qpid/cpp/src/tests/ssl_test index c7b59b62ef..13965f3a03 100755 --- a/qpid/cpp/src/tests/ssl_test +++ b/qpid/cpp/src/tests/ssl_test @@ -39,8 +39,7 @@ create_certs() { } start_broker() { - ../qpidd --daemon --transport ssl --port 0 --ssl-port 0 --no-data-dir --no-module-dir --auth no --config $CONFIG --load-module ../.libs/ssl.so --ssl-cert-db $CERT_DIR --ssl-cert-password-file $CERT_PW_FILE > qpidd.port - PORT=`cat qpidd.port` + PORT=`../qpidd --daemon --transport ssl --port 0 --ssl-port 0 --no-data-dir --no-module-dir --auth no --config $CONFIG --load-module ../.libs/ssl.so --ssl-cert-db $CERT_DIR --ssl-cert-password-file $CERT_PW_FILE` } stop_broker() { diff --git a/qpid/cpp/src/tests/start_cluster b/qpid/cpp/src/tests/start_cluster index 4f0516500c..053b23da33 100755 --- a/qpid/cpp/src/tests/start_cluster +++ b/qpid/cpp/src/tests/start_cluster @@ -28,11 +28,10 @@ with_ais_group() { echo $* | newgrp ais } -test -f cluster.ports && { echo "cluster.ports file already exists" ; exit 1; } rm -f cluster*.log SIZE=${1:-1}; shift CLUSTER=`pwd` # Cluster name=pwd, avoid clashes. -OPTS="-d --no-module-dir --load-module ../.libs/cluster.so --cluster-name=$CLUSTER --no-data-dir --auth=no $*" +OPTS="-d --no-module-dir --load-module ../.libs/cluster.so --cluster-name=$CLUSTER --no-data-dir --auth=no $@" for (( i=0; i + - > @@ -139,11 +139,12 @@ - + - + + diff --git a/qpid/java/08ExcludeList b/qpid/java/08ExcludeList index 88eb754950..1d8950dddf 100644 --- a/qpid/java/08ExcludeList +++ b/qpid/java/08ExcludeList @@ -6,3 +6,4 @@ org.apache.qpid.test.testcases.FailoverTest#* org.apache.qpid.test.client.failover.FailoverTest#test4MinuteFailover // Those tests are written against the 0.10 path org.apache.qpid.test.unit.message.UTF8Test#* +org.apache.qpid.client.MessageListenerTest#testSynchronousRecieveNoWait diff --git a/qpid/java/08ExcludeList-nonvm b/qpid/java/08ExcludeList-nonvm index eb6c60b225..546dc01f5b 100644 --- a/qpid/java/08ExcludeList-nonvm +++ b/qpid/java/08ExcludeList-nonvm @@ -27,3 +27,4 @@ org.apache.qpid.server.security.acl.SimpleACLTest#* // Those tests are written against the 0.10 path org.apache.qpid.test.unit.message.UTF8Test#* +org.apache.qpid.client.MessageListenerTest#testSynchronousRecieveNoWait diff --git a/qpid/java/ExcludeList b/qpid/java/ExcludeList index 509f74bbbd..5566c0eb9f 100644 --- a/qpid/java/ExcludeList +++ b/qpid/java/ExcludeList @@ -1,8 +1,6 @@ org.apache.qpid.client.MultipleJCAProviderRegistrationTest#test -// QPID-1451 : testBrowsingWithSelector test is not correct. -org.apache.qpid.test.client.QueueBrowserAutoAckTest#testBrowsingWithSelector -org.apache.qpid.test.client.QueueBrowserClientAckTest#testBrowsingWithSelector -org.apache.qpid.test.client.QueueBrowserDupsOkTest#testBrowsingWithSelector -org.apache.qpid.test.client.QueueBrowserNoAckTest#testBrowsingWithSelector -org.apache.qpid.test.client.QueueBrowserPreAckTest#testBrowsingWithSelector -org.apache.qpid.test.client.QueueBrowserTransactedTest#testBrowsingWithSelector +// QPID-1715, QPID-1715 : Client Error Handling on close is still broken +org.apache.qpid.server.queue.QueueCreateTest#testCreatePriorityString +org.apache.qpid.server.queue.QueueCreateTest#testCreateFlowToDiskValidNoSize +org.apache.qpid.server.queue.QueueCreateTest#testCreateFlowToDiskInvalid +org.apache.qpid.server.queue.QueueCreateTest#testCreateFlowToDiskInvalidSize diff --git a/qpid/java/broker/etc/config.xml b/qpid/java/broker/etc/config.xml index b2b3625cca..e0045c1e74 100644 --- a/qpid/java/broker/etc/config.xml +++ b/qpid/java/broker/etc/config.xml @@ -45,7 +45,6 @@ true 8999 - false true diff --git a/qpid/java/broker/etc/debug.log4j.xml b/qpid/java/broker/etc/debug.log4j.xml index 71f9502b75..fc0bd9f34f 100644 --- a/qpid/java/broker/etc/debug.log4j.xml +++ b/qpid/java/broker/etc/debug.log4j.xml @@ -1,4 +1,4 @@ - + - - - + --> + + + @@ -48,7 +48,7 @@ - + @@ -57,7 +57,7 @@ - + @@ -66,28 +66,28 @@ - + - + - + - @@ -96,11 +96,11 @@ - - diff --git a/qpid/java/broker/etc/log4j.xml b/qpid/java/broker/etc/log4j.xml index eff5d17588..a395d0fd56 100644 --- a/qpid/java/broker/etc/log4j.xml +++ b/qpid/java/broker/etc/log4j.xml @@ -1,4 +1,4 @@ - + - - - + --> + + + @@ -48,7 +48,7 @@ - + @@ -57,25 +57,25 @@ - + - - + + - + - + @@ -83,7 +83,7 @@ - diff --git a/qpid/java/broker/etc/persistent_config.xml b/qpid/java/broker/etc/persistent_config.xml index ed2c2cab1f..67ef28117d 100644 --- a/qpid/java/broker/etc/persistent_config.xml +++ b/qpid/java/broker/etc/persistent_config.xml @@ -37,7 +37,6 @@ true 8999 - false true diff --git a/qpid/java/broker/etc/transient_config.xml b/qpid/java/broker/etc/transient_config.xml index 19ffeb9720..a21afe7d21 100644 --- a/qpid/java/broker/etc/transient_config.xml +++ b/qpid/java/broker/etc/transient_config.xml @@ -37,7 +37,6 @@ true 8999 - false true diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java index 7216841a94..22bdae8267 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java @@ -77,7 +77,7 @@ public class AMQBrokerManagerMBean extends AMQManagedObject implements ManagedBr @MBeanConstructor("Creates the Broker Manager MBean") public AMQBrokerManagerMBean(VirtualHost.VirtualHostMBean virtualHostMBean) throws JMException { - super(ManagedBroker.class, ManagedBroker.TYPE); + super(ManagedBroker.class, ManagedBroker.TYPE, ManagedBroker.VERSION); _virtualHostMBean = virtualHostMBean; VirtualHost virtualHost = virtualHostMBean.getVirtualHost(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java index 5a01888ccf..72a2780c32 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java @@ -251,7 +251,6 @@ public class AMQChannel } catch (NoRouteException e) { - //_currentMessage.takeReference(); _returnMessages.add(e); } } @@ -432,7 +431,7 @@ public class AMQChannel { if (_log.isDebugEnabled()) { - _log.debug(debugIdentity() + " Adding unacked message(" + entry.getMessage().toString() + " DT:" + deliveryTag + _log.debug(debugIdentity() + " Adding unacked message(" + entry.toString() + " DT:" + deliveryTag + ") with a queue(" + entry.getQueue() + ") for " + subscription); } } @@ -552,7 +551,7 @@ public class AMQChannel } else { - _log.warn(System.identityHashCode(this) + " Requested requeue of message(" + unacked.getMessage().debugIdentity() + _log.warn(System.identityHashCode(this) + " Requested requeue of message(" + unacked.debugIdentity() + "):" + deliveryTag + " but no queue defined and no DeadLetter queue so DROPPING message."); unacked.dequeueAndDelete(_storeContext); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java index 780a17940e..49619ac5b0 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java @@ -26,6 +26,8 @@ import java.net.BindException; import java.net.InetAddress; import java.net.InetSocketAddress; +import javax.management.NotCompliantMBeanException; + import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; @@ -42,10 +44,13 @@ import org.apache.mina.common.IoAcceptor; import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; import org.apache.mina.transport.socket.nio.SocketSessionConfig; import org.apache.mina.util.NewThreadExecutor; +import org.apache.qpid.AMQException; import org.apache.qpid.common.QpidProperties; import org.apache.qpid.framing.ProtocolVersion; import org.apache.qpid.pool.ReadWriteThreadModel; import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.configuration.management.ConfigurationManagementMBean; +import org.apache.qpid.server.logging.management.LoggingManagementMBean; import org.apache.qpid.server.protocol.AMQPFastProtocolHandler; import org.apache.qpid.server.protocol.AMQPProtocolProvider; import org.apache.qpid.server.registry.ApplicationRegistry; @@ -232,16 +237,29 @@ public class Main String logConfig = commandLine.getOptionValue("l"); String logWatchConfig = commandLine.getOptionValue("w", "0"); + + int logWatchTime = 0; + try + { + logWatchTime = Integer.parseInt(logWatchConfig); + } + catch (NumberFormatException e) + { + System.err.println("Log watch configuration value of " + logWatchConfig + " is invalid. Must be " + + "a non-negative integer. Using default of zero (no watching configured"); + } + + File logConfigFile; if (logConfig != null) { - File logConfigFile = new File(logConfig); - configureLogging(logConfigFile, logWatchConfig); + logConfigFile = new File(logConfig); + configureLogging(logConfigFile, logWatchTime); } else { File configFileDirectory = configFile.getParentFile(); - File logConfigFile = new File(configFileDirectory, DEFAULT_LOG_CONFIG_FILENAME); - configureLogging(logConfigFile, logWatchConfig); + logConfigFile = new File(configFileDirectory, DEFAULT_LOG_CONFIG_FILENAME); + configureLogging(logConfigFile, logWatchTime); } ConfigurationFileApplicationRegistry config = new ConfigurationFileApplicationRegistry(configFile); @@ -249,7 +267,12 @@ public class Main updateManagementPort(serverConfig, commandLine.getOptionValue("m")); ApplicationRegistry.initialise(config); + + configureLoggingManagementMBean(logConfigFile, logWatchTime); + ConfigurationManagementMBean configMBean = new ConfigurationManagementMBean(); + configMBean.register(); + //fixme .. use QpidProperties.getVersionString when we have fixed the classpath issues // that are causing the broker build to pick up the wrong properties file and hence say // Starting Qpid Client @@ -445,19 +468,8 @@ public class Main return ip; } - private void configureLogging(File logConfigFile, String logWatchConfig) + private void configureLogging(File logConfigFile, int logWatchTime) { - int logWatchTime = 0; - try - { - logWatchTime = Integer.parseInt(logWatchConfig); - } - catch (NumberFormatException e) - { - System.err.println("Log watch configuration value of " + logWatchConfig + " is invalid. Must be " - + "a non-negative integer. Using default of zero (no watching configured"); - } - if (logConfigFile.exists() && logConfigFile.canRead()) { System.out.println("Configuring logger using configuration file " + logConfigFile.getAbsolutePath()); @@ -481,4 +493,17 @@ public class Main } } + private void configureLoggingManagementMBean(File logConfigFile, int logWatchTime) throws Exception + { + LoggingManagementMBean blm = new LoggingManagementMBean(logConfigFile.getPath(),logWatchTime); + + try + { + blm.register(); + } + catch (AMQException e) + { + throw new InitException("Unable to initialise the Logging Management MBean: ", e); + } + } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/ack/TxAck.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/ack/TxAck.java index 918fcd8407..95de0dc8c3 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/ack/TxAck.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/ack/TxAck.java @@ -102,7 +102,7 @@ public class TxAck implements TxnOp //buffer must be marked as persistent: for (QueueEntry msg : _unacked.values()) { - if (msg.getMessage().isPersistent()) + if (msg.isPersistent()) { return true; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/ack/UnacknowledgedMessageMapImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/ack/UnacknowledgedMessageMapImpl.java index ac3b0b5e49..5c38185696 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/ack/UnacknowledgedMessageMapImpl.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/ack/UnacknowledgedMessageMapImpl.java @@ -89,7 +89,7 @@ public class UnacknowledgedMessageMapImpl implements UnacknowledgedMessageMap QueueEntry message = _map.remove(deliveryTag); if(message != null) { - _unackedSize -= message.getMessage().getSize(); + _unackedSize -= message.getSize(); } @@ -115,7 +115,7 @@ public class UnacknowledgedMessageMapImpl implements UnacknowledgedMessageMap synchronized (_lock) { _map.put(deliveryTag, message); - _unackedSize += message.getMessage().getSize(); + _unackedSize += message.getSize(); _lastDeliveryTag = deliveryTag; } } @@ -181,7 +181,7 @@ public class UnacknowledgedMessageMapImpl implements UnacknowledgedMessageMap it.remove(); - _unackedSize -= unacked.getValue().getMessage().getSize(); + _unackedSize -= unacked.getValue().getSize(); if (unacked.getKey() == deliveryTag) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java index 90d6caec99..e6c5dee90d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java @@ -21,8 +21,10 @@ package org.apache.qpid.server.configuration; import java.util.List; +import java.io.File; import org.apache.commons.configuration.Configuration; +import org.apache.qpid.server.registry.ApplicationRegistry; public class QueueConfiguration { @@ -31,13 +33,20 @@ public class QueueConfiguration private Configuration _config; private String _name; + private VirtualHostConfiguration _virtualHostConfiguration; - public QueueConfiguration(String name, Configuration config) + public QueueConfiguration(String name, Configuration config, VirtualHostConfiguration virtualHostConfiguration) { + _virtualHostConfiguration = virtualHostConfiguration; _config = config; _name = name; } + public VirtualHostConfiguration getVirtualHostConfiguration() + { + return _virtualHostConfiguration; + } + public boolean getDurable() { return _config.getBoolean("durable" ,false); @@ -103,4 +112,13 @@ public class QueueConfiguration return _config.getLong("minimumAlertRepeatGap", 0); } + public long getMemoryUsageMaximum() + { + return _config.getLong("maximumMemoryUsage", 100 * 1024 * 1024); //100Meg + } + + public long getMemoryUsageMinimum() + { + return _config.getLong("minimumMemoryUsage", 0); + } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java index b3c08a2a95..c0fe42c5c2 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java @@ -33,8 +33,18 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.ConfigurationFactory; import org.apache.commons.configuration.SystemConfiguration; import org.apache.commons.configuration.XMLConfiguration; - -public class ServerConfiguration +import org.apache.qpid.server.configuration.management.ConfigurationManagementMBean; +import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.virtualhost.VirtualHost; +import org.apache.qpid.server.virtualhost.VirtualHostRegistry; +import org.apache.qpid.tools.messagestore.MessageStoreTool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import sun.misc.Signal; +import sun.misc.SignalHandler; + +public class ServerConfiguration implements SignalHandler { private static Configuration _config; @@ -52,6 +62,13 @@ public class ServerConfiguration private Map _virtualHosts = new HashMap(); private SecurityConfiguration _securityConfiguration = null; + private File _configFile; + + private Logger _log = LoggerFactory.getLogger(this.getClass()); + + private ConfigurationManagementMBean _mbean; + + // Map of environment variables to config items private static final Map envVarMap = new HashMap(); @@ -82,6 +99,8 @@ public class ServerConfiguration public ServerConfiguration(File configurationURL) throws ConfigurationException { this(parseConfig(configurationURL)); + _configFile = configurationURL; + sun.misc.Signal.handle(new sun.misc.Signal("HUP"), this); } public ServerConfiguration(Configuration conf) throws ConfigurationException @@ -94,8 +113,9 @@ public class ServerConfiguration _securityConfiguration = new SecurityConfiguration(conf.subset("security")); setupVirtualHosts(conf); + } - + private void setupVirtualHosts(Configuration conf) throws ConfigurationException { List vhosts = conf.getList("virtualhosts"); @@ -113,7 +133,7 @@ public class ServerConfiguration CompositeConfiguration mungedConf = new CompositeConfiguration(); mungedConf.addConfiguration(conf.subset("virtualhosts.virtualhost."+name)); mungedConf.addConfiguration(vhostConfiguration.subset("virtualhost." + name)); - VirtualHostConfiguration vhostConfig = new VirtualHostConfiguration(name, mungedConf); + VirtualHostConfiguration vhostConfig = new VirtualHostConfiguration(name, mungedConf, this); _virtualHosts.put(vhostConfig.getName(), vhostConfig); } } @@ -181,6 +201,42 @@ public class ServerConfiguration return conf; } + @Override + public void handle(Signal arg0) + { + try + { + reparseConfigFile(); + } + catch (ConfigurationException e) + { + _log.error("Could not reload configuration file", e); + } + } + + public void reparseConfigFile() throws ConfigurationException + { + if (_configFile != null) + { + Configuration newConfig = parseConfig(_configFile); + _securityConfiguration = new SecurityConfiguration(newConfig.subset("security")); + ApplicationRegistry.getInstance().getAccessManager().configurePlugins(_securityConfiguration); + + VirtualHostRegistry vhostRegistry = ApplicationRegistry.getInstance().getVirtualHostRegistry(); + for (String hostname : _virtualHosts.keySet()) + { + VirtualHost vhost = vhostRegistry.getVirtualHost(hostname); + SecurityConfiguration hostSecurityConfig = new SecurityConfiguration(newConfig.subset("virtualhosts.virtualhost."+hostname+".security")); + vhost.getAccessManager().configureHostPlugins(hostSecurityConfig); + } + } + } + + public String getQpidWork() + { + return System.getProperty("QPID_WORK", System.getProperty("java.io.tmpdir")); + } + public void setJMXManagementPort(int mport) { _jmxPort = mport; @@ -248,11 +304,6 @@ public class ServerConfiguration return _config.getInt("advanced.framesize", DEFAULT_FRAME_SIZE); } - public boolean getManagementSecurityEnabled() - { - return _config.getBoolean("management.security-enabled", false); - } - public boolean getProtectIOEnabled() { return _config.getBoolean("broker.connector.protectio.enabled", false); @@ -454,8 +505,10 @@ public class ServerConfiguration _config.setProperty("housekeeping.expiredMessageCheckPeriod", value); } - public long getHousekeepingExpiredMessageCheckPeriod() + public long getHousekeepingCheckPeriod() { - return _config.getLong("housekeeping.expiredMessageCheckPeriod", DEFAULT_HOUSEKEEPING_PERIOD); + return _config.getLong("housekeeping.checkPeriod", + _config.getLong("housekeeping.expiredMessageCheckPeriod", + DEFAULT_HOUSEKEEPING_PERIOD)); } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java index 91d0b8d8da..343abe4b5a 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java @@ -28,6 +28,7 @@ import java.util.Map; import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.store.MemoryMessageStore; @@ -37,10 +38,12 @@ public class VirtualHostConfiguration private String _name; private Map _queues = new HashMap(); private Map _exchanges = new HashMap(); + private ServerConfiguration _serverConfiguration; - - public VirtualHostConfiguration(String name, Configuration config) throws ConfigurationException + public VirtualHostConfiguration(String name, Configuration config, + ServerConfiguration serverConfiguration) throws ConfigurationException { + _serverConfiguration = serverConfiguration; _config = config; _name = name; @@ -52,7 +55,7 @@ public class VirtualHostConfiguration CompositeConfiguration mungedConf = new CompositeConfiguration(); mungedConf.addConfiguration(_config.subset("queues.queue." + queueName)); mungedConf.addConfiguration(_config.subset("queues")); - _queues.put(queueName, new QueueConfiguration(queueName, mungedConf)); + _queues.put(queueName, new QueueConfiguration(queueName, mungedConf, this)); } i = _config.getList("exchanges.exchange.name").iterator(); @@ -67,6 +70,21 @@ public class VirtualHostConfiguration } } + /** + * All future usages should use the constructor that takes the ServerConfiguration. + * + * This can be removed after QPID-1696 has been resolved. + * + * @param name + * @param mungedConf + * @throws ConfigurationException + */ + @Deprecated + public VirtualHostConfiguration(String name, Configuration mungedConf) throws ConfigurationException + { + this(name,mungedConf, ApplicationRegistry.getInstance().getConfiguration()); + } + public String getName() { return _name; @@ -74,7 +92,7 @@ public class VirtualHostConfiguration public long getHousekeepingExpiredMessageCheckPeriod() { - return _config.getLong("housekeeping.expiredMessageCheckPeriod", ApplicationRegistry.getInstance().getConfiguration().getHousekeepingExpiredMessageCheckPeriod()); + return _config.getLong("housekeeping.expiredMessageCheckPeriod", _serverConfiguration.getHousekeepingCheckPeriod()); } public String getAuthenticationDatabase() @@ -127,4 +145,25 @@ public class VirtualHostConfiguration return _queues.get(queueName); } + public long getMemoryUsageMaximum() + { + return _config.getLong("queues.maximumMemoryUsage", 0); + } + + public long getMemoryUsageMinimum() + { + return _config.getLong("queues.minimumMemoryUsage", 0); + } + + public ServerConfiguration getServerConfiguration() + { + return _serverConfiguration; + } + + public static final String FLOW_TO_DISK_PATH = "flowToDiskPath"; + public String getFlowToDiskLocation() + { + return _config.getString(FLOW_TO_DISK_PATH, getServerConfiguration().getQpidWork()); + } + } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/management/ConfigurationManagement.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/management/ConfigurationManagement.java new file mode 100644 index 0000000000..8e4bf01c6a --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/management/ConfigurationManagement.java @@ -0,0 +1,43 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.configuration.management; + +import javax.management.MBeanOperationInfo; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.management.MBeanOperation; + +public interface ConfigurationManagement +{ + + String TYPE = "ConfigurationManagement"; + int VERSION = 1; + + /** + * Reload the + * @throws ConfigurationException + */ + @MBeanOperation(name="reloadSecurityConfiguration", + description = "Force a reload of the security configuration sections", + impact = MBeanOperationInfo.ACTION) + void reloadSecurityConfiguration() throws ConfigurationException; + +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/management/ConfigurationManagementMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/management/ConfigurationManagementMBean.java new file mode 100644 index 0000000000..ead6053d70 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/management/ConfigurationManagementMBean.java @@ -0,0 +1,49 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.configuration.management; + +import javax.management.NotCompliantMBeanException; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.management.AMQManagedObject; +import org.apache.qpid.server.registry.ApplicationRegistry; + +public class ConfigurationManagementMBean extends AMQManagedObject implements ConfigurationManagement +{ + + public ConfigurationManagementMBean() throws NotCompliantMBeanException + { + super(ConfigurationManagement.class, ConfigurationManagement.TYPE, ConfigurationManagement.VERSION); + } + + @Override + public String getObjectInstanceName() + { + return ConfigurationManagement.TYPE; + } + + @Override + public void reloadSecurityConfiguration() throws ConfigurationException + { + ApplicationRegistry.getInstance().getConfiguration().reparseConfigFile(); + } + +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java index 8d24626b73..b6c741bbec 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java @@ -38,13 +38,9 @@ import org.apache.qpid.server.management.Managable; import org.apache.qpid.server.management.ManagedObject; import org.apache.qpid.server.management.ManagedObjectRegistry; import org.apache.qpid.server.queue.QueueRegistry; -import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.virtualhost.VirtualHost; -import java.util.List; -import java.util.Map; - public abstract class AbstractExchange implements Exchange, Managable { private AMQShortString _name; @@ -81,7 +77,7 @@ public abstract class AbstractExchange implements Exchange, Managable public ExchangeMBean() throws NotCompliantMBeanException { - super(ManagedExchange.class, ManagedExchange.TYPE); + super(ManagedExchange.class, ManagedExchange.TYPE, ManagedExchange.VERSION); } protected void init() throws OpenDataException diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ManagedExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ManagedExchange.java index 5d6d68b3c8..317ff385ab 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ManagedExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ManagedExchange.java @@ -40,6 +40,7 @@ import org.apache.qpid.server.queue.ManagedQueue; public interface ManagedExchange { static final String TYPE = "Exchange"; + static final int VERSION = 1; /** * Returns the name of the managed exchange. diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/BytesOnlyCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/BytesOnlyCreditManager.java index 0743e4bb8d..0bb428cd8f 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/BytesOnlyCreditManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/BytesOnlyCreditManager.java @@ -1,6 +1,6 @@ package org.apache.qpid.server.flow; -import org.apache.qpid.server.queue.AMQMessage; +import org.apache.qpid.server.queue.QueueEntry; import java.util.concurrent.atomic.AtomicLong; @@ -49,9 +49,9 @@ public class BytesOnlyCreditManager extends AbstractFlowCreditManager return _bytesCredit.get() > 0L; } - public boolean useCreditForMessage(AMQMessage msg) + public boolean useCreditForMessage(QueueEntry queueEntry) { - final long msgSize = msg.getSize(); + final long msgSize = queueEntry.getSize(); if(hasCredit()) { if(_bytesCredit.addAndGet(-msgSize) >= 0) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/FlowCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/FlowCreditManager.java index a249a6e63a..297e5a4826 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/FlowCreditManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/FlowCreditManager.java @@ -1,6 +1,7 @@ package org.apache.qpid.server.flow; import org.apache.qpid.server.queue.AMQMessage; +import org.apache.qpid.server.queue.QueueEntry; /* * @@ -40,5 +41,5 @@ public interface FlowCreditManager public boolean hasCredit(); - public boolean useCreditForMessage(AMQMessage msg); + public boolean useCreditForMessage(QueueEntry queueEntry); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/LimitlessCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/LimitlessCreditManager.java index d63431c3eb..437b7b0469 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/LimitlessCreditManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/LimitlessCreditManager.java @@ -1,6 +1,6 @@ package org.apache.qpid.server.flow; -import org.apache.qpid.server.queue.AMQMessage; +import org.apache.qpid.server.queue.QueueEntry; /* * @@ -37,7 +37,7 @@ public class LimitlessCreditManager extends AbstractFlowCreditManager implements return true; } - public boolean useCreditForMessage(AMQMessage msg) + public boolean useCreditForMessage(QueueEntry queueEntry) { return true; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageAndBytesCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageAndBytesCreditManager.java index 5f0acec03f..15ecb5f292 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageAndBytesCreditManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageAndBytesCreditManager.java @@ -1,6 +1,6 @@ package org.apache.qpid.server.flow; -import org.apache.qpid.server.queue.AMQMessage; +import org.apache.qpid.server.queue.QueueEntry; /* * @@ -52,7 +52,7 @@ public class MessageAndBytesCreditManager extends AbstractFlowCreditManager impl return (_messageCredit > 0L) && ( _bytesCredit > 0L ); } - public synchronized boolean useCreditForMessage(AMQMessage msg) + public synchronized boolean useCreditForMessage(QueueEntry queueEntry) { if(_messageCredit == 0L) { @@ -61,7 +61,7 @@ public class MessageAndBytesCreditManager extends AbstractFlowCreditManager impl } else { - final long msgSize = msg.getSize(); + final long msgSize = queueEntry.getSize(); if(msgSize > _bytesCredit) { setSuspended(true); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageOnlyCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageOnlyCreditManager.java index c1b3a09006..3e28d779b1 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageOnlyCreditManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageOnlyCreditManager.java @@ -1,6 +1,6 @@ package org.apache.qpid.server.flow; -import org.apache.qpid.server.queue.AMQMessage; +import org.apache.qpid.server.queue.QueueEntry; import java.util.concurrent.atomic.AtomicLong; @@ -50,7 +50,7 @@ public class MessageOnlyCreditManager extends AbstractFlowCreditManager implemen return _messageCredit.get() > 0L; } - public boolean useCreditForMessage(AMQMessage msg) + public boolean useCreditForMessage(QueueEntry queueEntry) { if(hasCredit()) { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/Pre0_10CreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/Pre0_10CreditManager.java index be0300f2c1..5cdd3a0328 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/Pre0_10CreditManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/Pre0_10CreditManager.java @@ -20,7 +20,7 @@ */ package org.apache.qpid.server.flow; -import org.apache.qpid.server.queue.AMQMessage; +import org.apache.qpid.server.queue.QueueEntry; public class Pre0_10CreditManager extends AbstractFlowCreditManager implements FlowCreditManager { @@ -123,7 +123,7 @@ public class Pre0_10CreditManager extends AbstractFlowCreditManager implements F && (_messageCreditLimit == 0L || _messageCredit > 0); } - public synchronized boolean useCreditForMessage(final AMQMessage msg) + public synchronized boolean useCreditForMessage(final QueueEntry queueEntry) { if(_messageCreditLimit != 0L) { @@ -137,10 +137,10 @@ public class Pre0_10CreditManager extends AbstractFlowCreditManager implements F } else { - if((_bytesCredit >= msg.getSize()) || (_bytesCredit == _bytesCreditLimit)) + if((_bytesCredit >= queueEntry.getSize()) || (_bytesCredit == _bytesCreditLimit)) { _messageCredit--; - _bytesCredit -= msg.getSize(); + _bytesCredit -= queueEntry.getSize(); return true; } @@ -166,9 +166,9 @@ public class Pre0_10CreditManager extends AbstractFlowCreditManager implements F } else { - if((_bytesCredit >= msg.getSize()) || (_bytesCredit == _bytesCreditLimit)) + if((_bytesCredit >= queueEntry.getSize()) || (_bytesCredit == _bytesCreditLimit)) { - _bytesCredit -= msg.getSize(); + _bytesCredit -= queueEntry.getSize(); return true; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java index 0f492a21bb..a626114792 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java @@ -129,7 +129,7 @@ public class BasicGetMethodHandler implements StateAwareMethodListener OR + * OR + * + * + * Noting also that the level/priority child element is optional too, + * and not the only possible child element. + */ + + + public synchronized TabularData viewConfigFileLoggerLevels() throws IOException + { + if (_loggerLevelTabularType == null) + { + _logger.warn("TabluarData type not set up correctly"); + return null; + } + + _logger.info("Getting logger levels from log4j configuration file"); + + Document doc = parseConfigFile(_log4jConfigFileName); + + TabularData loggerLevelList = new TabularDataSupport(_loggerLevelTabularType); + + //retrieve the 'category' element nodes + NodeList categoryElements = doc.getElementsByTagName("category"); + + String categoryName; + String priority = null; + + for (int i = 0; i < categoryElements.getLength(); i++) + { + Element categoryElement = (Element) categoryElements.item(i); + categoryName = categoryElement.getAttribute("name"); + + //retrieve the category's mandatory 'priority' or 'level' element's value. + //It may not be the only child node, so request by tag name. + NodeList priorityElements = categoryElement.getElementsByTagName("priority"); + NodeList levelElements = categoryElement.getElementsByTagName("level"); + + if (priorityElements.getLength() != 0) + { + Element priorityElement = (Element) priorityElements.item(0); + priority = priorityElement.getAttribute("value").toUpperCase(); + } + else if (levelElements.getLength() != 0) + { + Element levelElement = (Element) levelElements.item(0); + priority = levelElement.getAttribute("value").toUpperCase(); + } + else + { + //there is no exiting priority or level to view, move onto next category/logger + continue; + } + + try + { + Object[] itemData = {categoryName, priority}; + CompositeData loggerData = new CompositeDataSupport(_loggerLevelCompositeType, COMPOSITE_ITEM_NAMES, itemData); + loggerLevelList.put(loggerData); + } + catch (OpenDataException e) + { + _logger.warn("Unable to create logger level list due to :" + e); + return null; + } + } + + //retrieve the 'logger' element nodes + NodeList loggerElements = doc.getElementsByTagName("logger"); + + String loggerName; + String level; + + for (int i = 0; i < loggerElements.getLength(); i++) + { + Element loggerElement = (Element) loggerElements.item(i); + loggerName = loggerElement.getAttribute("name"); + + //retrieve the logger's mandatory 'level' element's value + //It may not be the only child node, so request by tag name. + NodeList levelElements = loggerElement.getElementsByTagName("level"); + + Element levelElement = (Element) levelElements.item(0); + level = levelElement.getAttribute("value").toUpperCase(); + + try + { + Object[] itemData = {loggerName, level}; + CompositeData loggerData = new CompositeDataSupport(_loggerLevelCompositeType, COMPOSITE_ITEM_NAMES, itemData); + loggerLevelList.put(loggerData); + } + catch (OpenDataException e) + { + _logger.warn("Unable to create logger level list due to :" + e); + return null; + } + } + + return loggerLevelList; + } + + public synchronized boolean setConfigFileLoggerLevel(String logger, String level) throws IOException + { + //check that the specified level is a valid log4j Level + try + { + getLevel(level); + } + catch (Exception e) + { + //it isnt a valid level + return false; + } + + _logger.info("Setting level to " + level + " for logger '" + logger + + "' in log4j xml configuration file: " + _log4jConfigFileName); + + Document doc = parseConfigFile(_log4jConfigFileName); + + //retrieve the 'category' and 'logger' element nodes + NodeList categoryElements = doc.getElementsByTagName("category"); + NodeList loggerElements = doc.getElementsByTagName("logger"); + + //collect them into a single elements list + List logElements = new ArrayList(); + + for (int i = 0; i < categoryElements.getLength(); i++) + { + logElements.add((Element) categoryElements.item(i)); + } + for (int i = 0; i < loggerElements.getLength(); i++) + { + logElements.add((Element) loggerElements.item(i)); + } + + //try to locate the specified logger/category in the elements retrieved + Element logElement = null; + for (Element e : logElements) + { + if (e.getAttribute("name").equals(logger)) + { + logElement = e; + break; + } + } + + if (logElement == null) + { + //no loggers/categories with given name found, does not exist to update + _logger.warn("Specified logger does not exist in the configuration file: " +logger); + return false; + } + + //retrieve the optional 'priority' or 'level' sub-element value. + //It may not be the only child node, so request by tag name. + NodeList priorityElements = logElement.getElementsByTagName("priority"); + NodeList levelElements = logElement.getElementsByTagName("level"); + + Element levelElement = null; + if (priorityElements.getLength() != 0) + { + levelElement = (Element) priorityElements.item(0); + } + else if (levelElements.getLength() != 0) + { + levelElement = (Element) levelElements.item(0); + } + else + { + //there is no exiting priority or level element to update + return false; + } + + //update the element with the new level/priority + levelElement.setAttribute("value", level); + + //output the new file + return writeUpdatedConfigFile(_log4jConfigFileName, doc); + } + + + /* The log4j XML configuration file DTD defines 2 possible element + * combinations for specifying the optional root logger level settings + * Must account for the following: + * + * OR + * + * + * Noting also that the level/priority child element is optional too, + * and not the only possible child element. + */ + + public synchronized String getConfigFileRootLoggerLevel() throws IOException + { + _logger.info("Getting root logger level from log4j configuration file"); + + Document doc = parseConfigFile(_log4jConfigFileName); + + //retrieve the optional 'root' element node + NodeList rootElements = doc.getElementsByTagName("root"); + + if (rootElements.getLength() == 0) + { + //there is not root logger definition + return null; + } + + Element rootElement = (Element) rootElements.item(0); + + //retrieve the optional 'priority' or 'level' element value. + //It may not be the only child node, so request by tag name. + NodeList priorityElements = rootElement.getElementsByTagName("priority"); + NodeList levelElements = rootElement.getElementsByTagName("level"); + String priority = null; + + if (priorityElements.getLength() != 0) + { + Element priorityElement = (Element) priorityElements.item(0); + priority = priorityElement.getAttribute("value"); + } + else if(levelElements.getLength() != 0) + { + Element levelElement = (Element) levelElements.item(0); + priority = levelElement.getAttribute("value"); + } + + if(priority != null) + { + return priority.toUpperCase(); + } + else + { + return null; + } + } + + public synchronized boolean setConfigFileRootLoggerLevel(String level) throws IOException + { + //check that the specified level is a valid log4j Level + try + { + getLevel(level); + } + catch (Exception e) + { + //it isnt a valid level + return false; + } + + _logger.info("Setting level to " + level + " for the Root logger in " + + "log4j xml configuration file: " + _log4jConfigFileName); + + Document doc = parseConfigFile(_log4jConfigFileName); + + //retrieve the optional 'root' element node + NodeList rootElements = doc.getElementsByTagName("root"); + + if (rootElements.getLength() == 0) + { + return false; + } + + Element rootElement = (Element) rootElements.item(0); + + //retrieve the optional 'priority' or 'level' sub-element value. + //It may not be the only child node, so request by tag name. + NodeList priorityElements = rootElement.getElementsByTagName("priority"); + NodeList levelElements = rootElement.getElementsByTagName("level"); + + Element levelElement = null; + if (priorityElements.getLength() != 0) + { + levelElement = (Element) priorityElements.item(0); + } + else if (levelElements.getLength() != 0) + { + levelElement = (Element) levelElements.item(0); + } + else + { + //there is no exiting priority/level to update + return false; + } + + //update the element with the new level/priority + levelElement.setAttribute("value", level); + + //output the new file + return writeUpdatedConfigFile(_log4jConfigFileName, doc); + } +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/AMQManagedObject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/AMQManagedObject.java index a2c2bd62a2..c6e07f6f48 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/AMQManagedObject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/AMQManagedObject.java @@ -50,10 +50,10 @@ public abstract class AMQManagedObject extends DefaultManagedObject protected MBeanInfo _mbeanInfo; - protected AMQManagedObject(Class managementInterface, String typeName) + protected AMQManagedObject(Class managementInterface, String typeName, int version) throws NotCompliantMBeanException { - super(managementInterface, typeName); + super(managementInterface, typeName, version); buildMBeanInfo(); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/DefaultManagedObject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/DefaultManagedObject.java index 84526dbc11..67aee90ba4 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/DefaultManagedObject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/DefaultManagedObject.java @@ -39,13 +39,15 @@ public abstract class DefaultManagedObject extends StandardMBean implements Mana private Class _managementInterface; private String _typeName; + private int _version; - protected DefaultManagedObject(Class managementInterface, String typeName) + protected DefaultManagedObject(Class managementInterface, String typeName, int version) throws NotCompliantMBeanException { super(managementInterface); _managementInterface = managementInterface; _typeName = typeName; + _version = version; } public String getType() @@ -115,6 +117,10 @@ public abstract class DefaultManagedObject extends StandardMBean implements Mana objectName.append(getHierarchicalName(this)); objectName.append("name=").append(name); + objectName.append(","); + objectName.append("version=").append(_version); + + return new ObjectName(objectName.toString()); } @@ -132,6 +138,9 @@ public abstract class DefaultManagedObject extends StandardMBean implements Mana objectName.append(hierarchyName.substring(0, hierarchyName.lastIndexOf(","))); } + objectName.append(","); + objectName.append("version=").append(_version); + return new ObjectName(objectName.toString()); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java index aea2f9d872..f02e858250 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java @@ -107,8 +107,6 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry } IApplicationRegistry appRegistry = ApplicationRegistry.getInstance(); - - boolean jmxmpSecurity = appRegistry.getConfiguration().getManagementSecurityEnabled(); int port = appRegistry.getConfiguration().getJMXManagementPort(); //retrieve the Principal Database assigned to JMX authentication duties @@ -119,184 +117,152 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry final JMXConnectorServer cs; HashMap env = new HashMap(); - if (jmxmpSecurity) + //Socket factories for the RMIConnectorServer, either default or SLL depending on configuration + RMIClientSocketFactory csf; + RMIServerSocketFactory ssf; + + //check ssl enabled option in config, default to true if option is not set + boolean sslEnabled = appRegistry.getConfiguration().getManagementSSLEnabled(); + + if (sslEnabled) { - // For SASL using JMXMP - JMXServiceURL jmxURL = new JMXServiceURL("jmxmp", null, port); + //set the SSL related system properties used by the SSL RMI socket factories to the values + //given in the configuration file, unless command line settings have already been specified + String keyStorePath; - String saslType = null; - if (db instanceof Base64MD5PasswordFilePrincipalDatabase) + if(System.getProperty("javax.net.ssl.keyStore") != null) { - saslType = "SASL/CRAM-MD5"; - env.put("jmx.remote.profiles", "SASL/CRAM-MD5"); - CRAMMD5HashedInitialiser initialiser = new CRAMMD5HashedInitialiser(); - initialiser.initialise(db); - env.put("jmx.remote.sasl.callback.handler", initialiser.getCallbackHandler()); + keyStorePath = System.getProperty("javax.net.ssl.keyStore"); } - else if (db instanceof PlainPasswordFilePrincipalDatabase) + else { - saslType = "SASL/PLAIN"; - PlainInitialiser initialiser = new PlainInitialiser(); - initialiser.initialise(db); - env.put("jmx.remote.sasl.callback.handler", initialiser.getCallbackHandler()); - env.put("jmx.remote.profiles", "SASL/PLAIN"); + keyStorePath = appRegistry.getConfiguration().getManagementKeyStorePath(); } - //workaround NPE generated from env map classloader issue when using Eclipse 3.4 to launch - env.put("jmx.remote.profile.provider.class.loader", this.getClass().getClassLoader()); - - _log.warn("Starting JMXMP based JMX ConnectorServer on port '" + port + "' with " + saslType); - _startupLog.warn("Starting JMXMP based JMX ConnectorServer on port '" + port + "' with " + saslType); - - cs = JMXConnectorServerFactory.newJMXConnectorServer(jmxURL, env, _mbeanServer); - } - else - { - //Socket factories for the RMIConnectorServer, either default or SLL depending on configuration - RMIClientSocketFactory csf; - RMIServerSocketFactory ssf; - - //check ssl enabled option in config, default to true if option is not set - boolean sslEnabled = appRegistry.getConfiguration().getManagementSSLEnabled(); - - if (sslEnabled) + //check the keystore path value is valid + if (keyStorePath == null) { - //set the SSL related system properties used by the SSL RMI socket factories to the values - //given in the configuration file, unless command line settings have already been specified - String keyStorePath; - - if(System.getProperty("javax.net.ssl.keyStore") != null) + throw new ConfigurationException("JMX management SSL keystore path not defined, " + + "unable to start SSL protected JMX ConnectorServer"); + } + else + { + //ensure the system property is set + System.setProperty("javax.net.ssl.keyStore", keyStorePath); + + //check the file is usable + File ksf = new File(keyStorePath); + + if (!ksf.exists()) { - keyStorePath = System.getProperty("javax.net.ssl.keyStore"); + throw new FileNotFoundException("Cannot find JMX management SSL keystore file " + ksf); } - else{ - keyStorePath = appRegistry.getConfiguration().getManagementKeyStorePath(); + if (!ksf.canRead()) + { + throw new FileNotFoundException("Cannot read JMX management SSL keystore file: " + + ksf + ". Check permissions."); } - //check the keystore path value is valid - if (keyStorePath == null) + _log.info("JMX ConnectorServer using SSL keystore file " + ksf.getAbsolutePath()); + _startupLog.info("JMX ConnectorServer using SSL keystore file " + ksf.getAbsolutePath()); + } + + //check the key store password is set + if (System.getProperty("javax.net.ssl.keyStorePassword") == null) + { + + if (appRegistry.getConfiguration().getManagementKeyStorePassword() == null) { - throw new ConfigurationException("JMX management SSL keystore path not defined, " + - "unable to start SSL protected JMX ConnectorServer"); + throw new ConfigurationException("JMX management SSL keystore password not defined, " + + "unable to start requested SSL protected JMX server"); } else { - //ensure the system property is set - System.setProperty("javax.net.ssl.keyStore", keyStorePath); - - //check the file is usable - File ksf = new File(keyStorePath); - - if (!ksf.exists()) - { - throw new FileNotFoundException("Cannot find JMX management SSL keystore file " + ksf); - } - if (!ksf.canRead()) - { - throw new FileNotFoundException("Cannot read JMX management SSL keystore file: " - + ksf + ". Check permissions."); - } - - _log.info("JMX ConnectorServer using SSL keystore file " + ksf.getAbsolutePath()); - _startupLog.info("JMX ConnectorServer using SSL keystore file " + ksf.getAbsolutePath()); + System.setProperty("javax.net.ssl.keyStorePassword", + appRegistry.getConfiguration().getManagementKeyStorePassword()); } + } - //check the key store password is set - if (System.getProperty("javax.net.ssl.keyStorePassword") == null) - { - - if (appRegistry.getConfiguration().getManagementKeyStorePassword() == null) - { - throw new ConfigurationException("JMX management SSL keystore password not defined, " + - "unable to start requested SSL protected JMX server"); - } - else - { - System.setProperty("javax.net.ssl.keyStorePassword", - appRegistry.getConfiguration().getManagementKeyStorePassword()); - } - } + //create the SSL RMI socket factories + csf = new SslRMIClientSocketFactory(); + ssf = new SslRMIServerSocketFactory(); - //create the SSL RMI socket factories - csf = new SslRMIClientSocketFactory(); - ssf = new SslRMIServerSocketFactory(); + _log.warn("Starting JMX ConnectorServer on port '"+ port + "' (+" + + (port +PORT_EXPORT_OFFSET) + ") with SSL"); + _startupLog.warn("Starting JMX ConnectorServer on port '"+ port + "' (+" + + (port +PORT_EXPORT_OFFSET) + ") with SSL"); + } + else + { + //Do not specify any specific RMI socket factories, resulting in use of the defaults. + csf = null; + ssf = null; - _log.warn("Starting JMX ConnectorServer on port '"+ port + "' (+" + - (port +PORT_EXPORT_OFFSET) + ") with SSL"); - _startupLog.warn("Starting JMX ConnectorServer on port '"+ port + "' (+" + - (port +PORT_EXPORT_OFFSET) + ") with SSL"); - } - else - { - //Do not specify any specific RMI socket factories, resulting in use of the defaults. - csf = null; - ssf = null; - - _log.warn("Starting JMX ConnectorServer on port '" + port + "' (+" + (port +PORT_EXPORT_OFFSET) + ")"); - _startupLog.warn("Starting JMX ConnectorServer on port '" + port + "' (+" + (port +PORT_EXPORT_OFFSET) + ")"); - } - - //add a JMXAuthenticator implementation the env map to authenticate the RMI based JMX connector server - RMIPasswordAuthenticator rmipa = new RMIPasswordAuthenticator(); - rmipa.setPrincipalDatabase(db); - env.put(JMXConnectorServer.AUTHENTICATOR, rmipa); - - /* - * Start a RMI registry on the management port, to hold the JMX RMI ConnectorServer stub. - * Using custom socket factory to prevent anyone (including us unfortunately) binding to the registry using RMI. - * As a result, only binds made using the object reference will succeed, thus securing it from external change. - */ - System.setProperty("java.rmi.server.randomIDs", "true"); - _rmiRegistry = LocateRegistry.createRegistry(port, null, new CustomRMIServerSocketFactory()); - - /* - * We must now create the RMI ConnectorServer manually, as the JMX Factory methods use RMI calls - * to bind the ConnectorServer to the registry, which will now fail as for security we have - * locked it from any RMI based modifications, including our own. Instead, we will manually bind - * the RMIConnectorServer stub to the registry using its object reference, which will still succeed. - * - * The registry is exported on the defined management port 'port'. We will export the RMIConnectorServer - * on 'port +1'. Use of these two well-defined ports will ease any navigation through firewall's. - */ - final RMIServerImpl rmiConnectorServerStub = new RMIJRMPServerImpl(port+PORT_EXPORT_OFFSET, csf, ssf, env); - final String hostname = InetAddress.getLocalHost().getHostName(); - final JMXServiceURL externalUrl = new JMXServiceURL( - "service:jmx:rmi://"+hostname+":"+(port+PORT_EXPORT_OFFSET)+"/jndi/rmi://"+hostname+":"+port+"/jmxrmi"); - - final JMXServiceURL internalUrl = new JMXServiceURL("rmi", hostname, port+PORT_EXPORT_OFFSET); - cs = new RMIConnectorServer(internalUrl, env, rmiConnectorServerStub, _mbeanServer) + _log.warn("Starting JMX ConnectorServer on port '" + port + "' (+" + (port +PORT_EXPORT_OFFSET) + ")"); + _startupLog.warn("Starting JMX ConnectorServer on port '" + port + "' (+" + (port +PORT_EXPORT_OFFSET) + ")"); + } + + //add a JMXAuthenticator implementation the env map to authenticate the RMI based JMX connector server + RMIPasswordAuthenticator rmipa = new RMIPasswordAuthenticator(); + rmipa.setPrincipalDatabase(db); + env.put(JMXConnectorServer.AUTHENTICATOR, rmipa); + + /* + * Start a RMI registry on the management port, to hold the JMX RMI ConnectorServer stub. + * Using custom socket factory to prevent anyone (including us unfortunately) binding to the registry using RMI. + * As a result, only binds made using the object reference will succeed, thus securing it from external change. + */ + System.setProperty("java.rmi.server.randomIDs", "true"); + _rmiRegistry = LocateRegistry.createRegistry(port, null, new CustomRMIServerSocketFactory()); + + /* + * We must now create the RMI ConnectorServer manually, as the JMX Factory methods use RMI calls + * to bind the ConnectorServer to the registry, which will now fail as for security we have + * locked it from any RMI based modifications, including our own. Instead, we will manually bind + * the RMIConnectorServer stub to the registry using its object reference, which will still succeed. + * + * The registry is exported on the defined management port 'port'. We will export the RMIConnectorServer + * on 'port +1'. Use of these two well-defined ports will ease any navigation through firewall's. + */ + final RMIServerImpl rmiConnectorServerStub = new RMIJRMPServerImpl(port+PORT_EXPORT_OFFSET, csf, ssf, env); + final String hostname = InetAddress.getLocalHost().getHostName(); + final JMXServiceURL externalUrl = new JMXServiceURL( + "service:jmx:rmi://"+hostname+":"+(port+PORT_EXPORT_OFFSET)+"/jndi/rmi://"+hostname+":"+port+"/jmxrmi"); + + final JMXServiceURL internalUrl = new JMXServiceURL("rmi", hostname, port+PORT_EXPORT_OFFSET); + cs = new RMIConnectorServer(internalUrl, env, rmiConnectorServerStub, _mbeanServer) + { + @Override + public synchronized void start() throws IOException { - @Override - public synchronized void start() throws IOException + try { - try - { - //manually bind the connector server to the registry at key 'jmxrmi', like the out-of-the-box agent - _rmiRegistry.bind("jmxrmi", rmiConnectorServerStub); - } - catch (AlreadyBoundException abe) - { - //key was already in use. shouldnt happen here as its a new registry, unbindable by normal means. - - //IOExceptions are the only checked type throwable by the method, wrap and rethrow - IOException ioe = new IOException(abe.getMessage()); - ioe.initCause(abe); - throw ioe; - } - - //now do the normal tasks - super.start(); - } - - @Override - public JMXServiceURL getAddress() - { - //must return our pre-crafted url that includes the full details, inc JNDI details - return externalUrl; - } + //manually bind the connector server to the registry at key 'jmxrmi', like the out-of-the-box agent + _rmiRegistry.bind("jmxrmi", rmiConnectorServerStub); + } + catch (AlreadyBoundException abe) + { + //key was already in use. shouldnt happen here as its a new registry, unbindable by normal means. - }; - } + //IOExceptions are the only checked type throwable by the method, wrap and rethrow + IOException ioe = new IOException(abe.getMessage()); + ioe.initCause(abe); + throw ioe; + } + + //now do the normal tasks + super.start(); + } + + @Override + public JMXServiceURL getAddress() + { + //must return our pre-crafted url that includes the full details, inc JNDI details + return externalUrl; + } + + }; + //Add the custom invoker as an MBeanServerForwarder, and start the RMIConnectorServer. MBeanServerForwarder mbsf = MBeanInvocationHandlerImpl.newProxyInstance(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java index a0ecc2bd85..e9b4d85e66 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java @@ -20,6 +20,8 @@ */ package org.apache.qpid.server.management; +import org.apache.qpid.server.configuration.management.ConfigurationManagement; +import org.apache.qpid.server.logging.management.LoggingManagement; import org.apache.qpid.server.security.access.management.UserManagement; import org.apache.log4j.Logger; @@ -37,6 +39,8 @@ import java.lang.reflect.Method; import java.security.AccessController; import java.security.Principal; import java.security.AccessControlContext; +import java.util.ArrayList; +import java.util.HashSet; import java.util.Set; import java.util.Properties; @@ -53,9 +57,16 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler public final static String READWRITE = "readwrite"; public final static String READONLY = "readonly"; private final static String DELEGATE = "JMImplementation:type=MBeanServerDelegate"; - private MBeanServer mbs; + private MBeanServer _mbs; private static Properties _userRoles = new Properties(); + private static HashSet _adminOnlyMethods = new HashSet(); + { + _adminOnlyMethods.add(UserManagement.TYPE); + _adminOnlyMethods.add(LoggingManagement.TYPE); + _adminOnlyMethods.add(ConfigurationManagement.TYPE); + } + public static MBeanServerForwarder newProxyInstance() { final InvocationHandler handler = new MBeanInvocationHandlerImpl(); @@ -71,7 +82,7 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler if (methodName.equals("getMBeanServer")) { - return mbs; + return _mbs; } if (methodName.equals("setMBeanServer")) @@ -80,11 +91,11 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler { throw new IllegalArgumentException("Null MBeanServer"); } - if (mbs != null) + if (_mbs != null) { throw new IllegalArgumentException("MBeanServer object already initialized"); } - mbs = (MBeanServer) args[0]; + _mbs = (MBeanServer) args[0]; return null; } @@ -95,12 +106,12 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler // Allow operations performed locally on behalf of the connector server itself if (subject == null) { - return method.invoke(mbs, args); + return method.invoke(_mbs, args); } if (args == null || DELEGATE.equals(args[0])) { - return method.invoke(mbs, args); + return method.invoke(_mbs, args); } // Restrict access to "createMBean" and "unregisterMBean" to any user @@ -124,7 +135,7 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler { if (isAdmin(identity)) { - return method.invoke(mbs, args); + return method.invoke(_mbs, args); } else { @@ -135,14 +146,14 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler // Following users can perform any operation other than "createMBean" and "unregisterMBean" if (isAllowedToModify(identity)) { - return method.invoke(mbs, args); + return method.invoke(_mbs, args); } // These users can only call "getAttribute" on the MBeanServerDelegate MBean // Here we can add other fine grained permissions like specific method for a particular mbean if (isReadOnlyUser(identity) && isReadOnlyMethod(method, args)) { - return method.invoke(mbs, args); + return method.invoke(_mbs, args); } throw new SecurityException("Access denied"); @@ -153,9 +164,9 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler if (args[0] instanceof ObjectName) { ObjectName object = (ObjectName) args[0]; - return UserManagement.TYPE.equals(object.getKeyProperty("type")); + + return _adminOnlyMethods.contains(object.getKeyProperty("type")); } - return false; } @@ -196,7 +207,10 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler private boolean isReadOnlyMethod(Method method, Object[] args) { String methodName = method.getName(); - if (methodName.startsWith("query") || methodName.startsWith("get")) + + //handle standard get/set/query and select 'is' methods from MBeanServer + if (methodName.startsWith("query") || methodName.startsWith("get") + ||methodName.startsWith("isInstanceOf") || methodName.startsWith("isRegistered")) { return true; } @@ -205,8 +219,11 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler return false; } + //handle invocation of other methods on mbeans if ((args[0] instanceof ObjectName) && (methodName.equals("invoke"))) { + + //get invoked method name String mbeanMethod = (args.length > 1) ? (String) args[1] : null; if (mbeanMethod == null) { @@ -215,7 +232,8 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler try { - MBeanInfo mbeanInfo = mbs.getMBeanInfo((ObjectName) args[0]); + //check if the given method is tagged with an INFO impact attribute + MBeanInfo mbeanInfo = _mbs.getMBeanInfo((ObjectName) args[0]); if (mbeanInfo != null) { MBeanOperationInfo[] opInfos = mbeanInfo.getOperations(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/ManagedBroker.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/ManagedBroker.java index 45e2e91ed7..c18417fc43 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/ManagedBroker.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/ManagedBroker.java @@ -40,12 +40,13 @@ public interface ManagedBroker { static final String TYPE = "VirtualHostManager"; + static final int VERSION = 1 ; + /** * Creates a new Exchange. * @param name * @param type * @param durable - * @param passive * @throws IOException * @throws JMException */ @@ -73,7 +74,6 @@ public interface ManagedBroker * @param queueName * @param durable * @param owner - * @param autoDelete * @throws IOException * @throws JMException */ diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java index 1b7919e8b7..5d8fa3e9d7 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java @@ -35,6 +35,7 @@ import org.apache.qpid.server.security.access.ACLPluginFactory; import org.apache.qpid.server.security.access.plugins.AllowAll; import org.apache.qpid.server.security.access.plugins.DenyAll; import org.apache.qpid.server.security.access.plugins.SimpleXML; +import org.apache.qpid.server.security.access.plugins.network.FirewallPlugin; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleException; import org.osgi.util.tracker.ServiceTracker; @@ -165,6 +166,7 @@ public class PluginManager _securityPlugins.put(SimpleXML.class.getName(), SimpleXML.FACTORY); _securityPlugins.put(AllowAll.class.getName(), AllowAll.FACTORY); _securityPlugins.put(DenyAll.class.getName(), DenyAll.FACTORY); + _securityPlugins.put(FirewallPlugin.class.getName(), FirewallPlugin.FACTORY); } return _securityPlugins; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java index bd072985c4..5dd3cc075a 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java @@ -37,7 +37,6 @@ */ package org.apache.qpid.server.protocol; -import java.security.Principal; import java.util.Date; import java.util.List; @@ -58,7 +57,6 @@ import javax.management.openmbean.TabularDataSupport; import javax.management.openmbean.TabularType; import org.apache.qpid.AMQException; -import org.apache.qpid.framing.AMQFrame; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.ConnectionCloseBody; import org.apache.qpid.framing.MethodRegistry; @@ -93,7 +91,7 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed @MBeanConstructor("Creates an MBean exposing an AMQ Broker Connection") public AMQProtocolSessionMBean(AMQMinaProtocolSession session) throws NotCompliantMBeanException, OpenDataException { - super(ManagedConnection.class, ManagedConnection.TYPE); + super(ManagedConnection.class, ManagedConnection.TYPE, ManagedConnection.VERSION); _session = session; String remote = getRemoteAddress(); remote = "anonymous".equals(remote) ? (remote + hashCode()) : remote; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ManagedConnection.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ManagedConnection.java index e6e713ac6d..e75b09a0cb 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ManagedConnection.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ManagedConnection.java @@ -41,6 +41,7 @@ import org.apache.qpid.server.management.MBeanOperationParameter; public interface ManagedConnection { static final String TYPE = "Connection"; + static final int VERSION = 1; @MBeanAttribute(name = "ClientId", description = "Client Id") String getClientId(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java index e96d2ba874..8dac12fe24 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java @@ -60,30 +60,6 @@ public interface AMQMessage //Check the status of this message - /** - * Called selectors to determin if the message has already been sent - * - * @return _deliveredToConsumer - */ - boolean getDeliveredToConsumer(); - - /** - * Called to enforce the 'immediate' flag. - * - * @returns true if the message is marked for immediate delivery but has not been marked as delivered - * to a consumer - */ - boolean immediateAndNotDelivered(); - - /** - * Checks to see if the message has expired. If it has the message is dequeued. - * - * @return true if the message has expire - * - * @throws org.apache.qpid.AMQException - */ - boolean expired() throws AMQException; - /** Is this a persistent message * * @return true if the message is persistent @@ -91,13 +67,8 @@ public interface AMQMessage boolean isPersistent(); - /** - * Called when this message is delivered to a consumer. (used to implement the 'immediate' flag functionality). - * And for selector efficiency. - */ - void setDeliveredToConsumer(); + boolean isImmediate(); - void setExpiration(long expiration); void setClientIdentifier(AMQProtocolSession.ProtocolSessionIdentifier sessionIdentifier); @@ -113,9 +84,16 @@ public interface AMQMessage void addContentBodyFrame(StoreContext storeContext, ContentChunk contentChunk, boolean isLastContentBody) throws AMQException; + void recoverFromMessageMetaData(MessageMetaData mmd); + + void recoverContentBodyFrame(ContentChunk contentChunk, boolean isLastContentBody) throws AMQException; String toString(); String debugIdentity(); + + void setExpiration(long expiration); + + long getExpiration(); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessageHandle.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessageHandle.java deleted file mode 100644 index 93ac21fc7c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessageHandle.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.queue; - -import org.apache.qpid.AMQException; -import org.apache.qpid.framing.ContentHeaderBody; -import org.apache.qpid.server.store.StoreContext; -import org.apache.qpid.framing.abstraction.ContentChunk; -import org.apache.qpid.framing.abstraction.MessagePublishInfo; - -/** - * A pluggable way of getting message data. Implementations can provide intelligent caching for example or - * even no caching at all to minimise the broker memory footprint. - */ -public interface AMQMessageHandle -{ - ContentHeaderBody getContentHeaderBody(StoreContext context) throws AMQException; - - /** - * - * @return the messageId for the message associated with this handle - */ - Long getMessageId(); - - - /** - * @return the number of body frames associated with this message - */ - int getBodyCount(StoreContext context) throws AMQException; - - /** - * @return the size of the body - */ - long getBodySize(StoreContext context) throws AMQException; - - /** - * Get a particular content body - * @param index the index of the body to retrieve, must be between 0 and getBodyCount() - 1 - * @return a content body - * @throws IllegalArgumentException if the index is invalid - */ - ContentChunk getContentChunk(StoreContext context, int index) throws IllegalArgumentException, AMQException; - - void addContentBodyFrame(StoreContext storeContext, ContentChunk contentBody, boolean isLastContentBody) throws AMQException; - - MessagePublishInfo getMessagePublishInfo(StoreContext context) throws AMQException; - - boolean isPersistent(); - - void setPublishAndContentHeaderBody(StoreContext storeContext, MessagePublishInfo messagePublishInfo, - ContentHeaderBody contentHeaderBody) - throws AMQException; - - void removeMessage(StoreContext storeContext) throws AMQException; - - long getArrivalTime(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQPriorityQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQPriorityQueue.java index 34a70c6969..ade780d0bb 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQPriorityQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQPriorityQueue.java @@ -36,12 +36,12 @@ public class AMQPriorityQueue extends SimpleAMQQueue int priorities) throws AMQException { - super(name, durable, owner, autoDelete, virtualHost, new PriorityQueueList.Factory(priorities)); + super(name, durable, owner, autoDelete, virtualHost, new PriorityQueueEntryList.Factory(priorities)); } public int getPriorities() { - return ((PriorityQueueList) _entries).getPriorities(); + return ((PriorityQueueEntryList) _entries).getPriorities(); } @Override diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java index 9fadbb0cdc..43ec6c4d15 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java @@ -68,6 +68,8 @@ public interface AMQQueue extends Managable, Comparable boolean isEmpty(); + boolean isFlowed(); + int getMessageCount(); int getUndeliveredMessageCount(); @@ -111,7 +113,15 @@ public interface AMQQueue extends Managable, Comparable void removeMessagesFromQueue(long fromMessageId, long toMessageId, StoreContext storeContext); + long getMemoryUsageMaximum(); + + void setMemoryUsageMaximum(long maximumMemoryUsage); + + long getMemoryUsageMinimum(); + + void setMemoryUsageMinimum(long minimumMemoryUsage); + long getMemoryUsageCurrent(); long getMaximumMessageSize(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java index eb0a011e93..6ba22321f1 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java @@ -23,13 +23,17 @@ package org.apache.qpid.server.queue; import org.apache.qpid.AMQException; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.FieldTable; +import org.apache.qpid.protocol.AMQConstant; import org.apache.qpid.server.configuration.QueueConfiguration; import org.apache.qpid.server.virtualhost.VirtualHost; - public class AMQQueueFactory { public static final AMQShortString X_QPID_PRIORITIES = new AMQShortString("x-qpid-priorities"); + public static final AMQShortString QPID_MAX_COUNT = new AMQShortString("qpid.max_count"); + public static final AMQShortString QPID_MAX_SIZE = new AMQShortString("qpid.max_size"); + public static final AMQShortString QPID_POLICY_TYPE = new AMQShortString("qpid.policy_type"); + public static final String QPID_FLOW_TO_DISK = "flow_to_disk"; public static AMQQueue createAMQQueueImpl(AMQShortString name, boolean durable, @@ -39,10 +43,26 @@ public class AMQQueueFactory throws AMQException { - final int priorities = arguments == null ? 1 : arguments.containsKey(X_QPID_PRIORITIES) ? arguments.getInteger(X_QPID_PRIORITIES) : 1; + int priorities = 1; + + if (arguments != null && arguments.containsKey(X_QPID_PRIORITIES)) + { + Integer priority = arguments.getInteger(X_QPID_PRIORITIES); + + if (priority != null) + { + priorities = priority.intValue(); + } + else + { + throw new AMQException(AMQConstant.INVALID_ARGUMENT, + "Queue create request with non integer value for :" + X_QPID_PRIORITIES + "=" + arguments.get(X_QPID_PRIORITIES), null); + } + + } AMQQueue q = null; - if(priorities > 1) + if (priorities > 1) { q = new AMQPriorityQueue(name, durable, owner, autoDelete, virtualHost, priorities); } @@ -51,6 +71,40 @@ public class AMQQueueFactory q = new SimpleAMQQueue(name, durable, owner, autoDelete, virtualHost); } + final String queuePolicyType = arguments == null ? null : + arguments.containsKey(QPID_POLICY_TYPE) ? arguments.getString(QPID_POLICY_TYPE) : null; + + if (queuePolicyType != null) + { + if (queuePolicyType.equals(QPID_FLOW_TO_DISK)) + { + if (arguments.containsKey(QPID_MAX_SIZE)) + { + + final long queueSize = arguments.getInteger(QPID_MAX_SIZE); + + if (queueSize < 0) + { + throw new AMQException(AMQConstant.INVALID_ARGUMENT, + "Queue create request with negative size:" + queueSize, null); + } + + q.setMemoryUsageMaximum(queueSize); + } + else + { + throw new AMQException(AMQConstant.INVALID_ARGUMENT, + "Queue create request with no qpid.max_size value,", null); + } + } + else + { + throw new AMQException(AMQConstant.NOT_IMPLEMENTED, + "Queue create request with unknown Policy Type:" + queuePolicyType, null); + } + + } + //Register the new queue virtualHost.getQueueRegistry().registerQueue(q); return q; @@ -66,9 +120,9 @@ public class AMQQueueFactory FieldTable arguments = null; boolean priority = config.getPriority(); int priorities = config.getPriorities(); - if(priority || priorities > 0) + if (priority || priorities > 0) { - if(arguments == null) + if (arguments == null) { arguments = new FieldTable(); } @@ -85,6 +139,8 @@ public class AMQQueueFactory q.setMaximumMessageSize(config.getMaximumMessageSize()); q.setMaximumMessageCount(config.getMaximumMessageCount()); q.setMinimumAlertRepeatGap(config.getMinimumAlertRepeatGap()); + q.setMemoryUsageMaximum(config.getMemoryUsageMaximum()); + q.setMemoryUsageMinimum(config.getMemoryUsageMinimum()); return q; } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java index a08719875d..2ff54fb748 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java @@ -100,7 +100,7 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que @MBeanConstructor("Creates an MBean exposing an AMQQueue") public AMQQueueMBean(AMQQueue queue) throws JMException { - super(ManagedQueue.class, ManagedQueue.TYPE); + super(ManagedQueue.class, ManagedQueue.TYPE, ManagedQueue.VERSION); _queue = queue; _queueName = jmxEncode(new StringBuffer(queue.getName()), 0).toString(); } @@ -221,11 +221,12 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que _queue.setMaximumMessageCount(value); } + /** + * returns the maximum total size of messages(bytes) in the queue. + */ public Long getMaximumQueueDepth() { - long queueDepthInBytes = _queue.getMaximumQueueDepth(); - - return queueDepthInBytes >> 10; + return _queue.getMaximumQueueDepth(); } public void setMaximumQueueDepth(Long value) @@ -233,20 +234,49 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que _queue.setMaximumQueueDepth(value); } + public Long getMemoryUsageMaximum() + { + return _queue.getMemoryUsageMaximum(); + } + + public void setMemoryUsageMaximum(Long maximumMemoryUsage) + { + _queue.setMemoryUsageMaximum(maximumMemoryUsage); + } + + public Long getMemoryUsageMinimum() + { + return _queue.getMemoryUsageMinimum(); + } + + public void setMemoryUsageMinimum(Long minimumMemoryUsage) + { + _queue.setMemoryUsageMinimum(minimumMemoryUsage); + } + + public Long getMemoryUsageCurrent() + { + return _queue.getMemoryUsageCurrent(); + } + + public boolean isFlowed() + { + return _queue.isFlowed(); + } + /** - * returns the size of messages(KB) in the queue. + * returns the total size of messages(bytes) in the queue. */ public Long getQueueDepth() throws JMException { - long queueBytesSize = _queue.getQueueDepth(); - - return queueBytesSize >> 10; + return _queue.getQueueDepth(); } /** * Checks if there is any notification to be send to the listeners + * @param queueEntry */ - public void checkForNotification(AMQMessage msg) throws AMQException + public void checkForNotification(QueueEntry queueEntry) throws AMQException { final Set notificationChecks = _queue.getNotificationChecks(); @@ -260,7 +290,7 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que { if (check.isMessageSpecific() || (_lastNotificationTimes[check.ordinal()] < thresholdTime)) { - if (check.notifyIfNecessary(msg, _queue, this)) + if (check.notifyIfNecessary(queueEntry, _queue, this)) { _lastNotificationTimes[check.ordinal()] = currentTime; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FileQueueBackingStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FileQueueBackingStore.java new file mode 100644 index 0000000000..0e5a4efba6 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FileQueueBackingStore.java @@ -0,0 +1,358 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +import org.apache.log4j.Logger; +import org.apache.mina.common.ByteBuffer; +import org.apache.qpid.AMQException; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.framing.BasicContentHeaderProperties; +import org.apache.qpid.framing.ContentHeaderBody; +import org.apache.qpid.framing.abstraction.ContentChunk; +import org.apache.qpid.framing.abstraction.MessagePublishInfo; +import org.apache.qpid.util.FileUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +public class FileQueueBackingStore implements QueueBackingStore +{ + private static final Logger _log = Logger.getLogger(FileQueueBackingStore.class); + + private String _flowToDiskLocation; + + public FileQueueBackingStore(String location) + { + _flowToDiskLocation = location; + } + + public AMQMessage load(Long messageId) + { + _log.info("Loading Message (ID:" + messageId + ")"); + + MessageMetaData mmd; + + File handle = getFileHandle(messageId); + + ObjectInputStream input = null; + + Exception error = null; + try + { + input = new ObjectInputStream(new FileInputStream(handle)); + + long arrivaltime = input.readLong(); + + final AMQShortString exchange = new AMQShortString(input.readUTF()); + final AMQShortString routingKey = new AMQShortString(input.readUTF()); + final boolean mandatory = input.readBoolean(); + final boolean immediate = input.readBoolean(); + + int bodySize = input.readInt(); + byte[] underlying = new byte[bodySize]; + + input.readFully(underlying, 0, bodySize); + + ByteBuffer buf = ByteBuffer.wrap(underlying); + + ContentHeaderBody chb = ContentHeaderBody.createFromBuffer(buf, bodySize); + + int chunkCount = input.readInt(); + + // There are WAY to many annonymous MPIs in the code this should be made concrete. + MessagePublishInfo info = new MessagePublishInfo() + { + + public AMQShortString getExchange() + { + return exchange; + } + + public void setExchange(AMQShortString exchange) + { + + } + + public boolean isImmediate() + { + return immediate; + } + + public boolean isMandatory() + { + return mandatory; + } + + public AMQShortString getRoutingKey() + { + return routingKey; + } + }; + + mmd = new MessageMetaData(info, chb, chunkCount); + mmd.setArrivalTime(arrivaltime); + + AMQMessage message; + if (((BasicContentHeaderProperties) chb.properties).getDeliveryMode() == 2) + { + message = new PersistentAMQMessage(messageId, null); + } + else + { + message = new TransientAMQMessage(messageId); + } + + message.recoverFromMessageMetaData(mmd); + + for (int chunk = 0; chunk < chunkCount; chunk++) + { + int length = input.readInt(); + + byte[] data = new byte[length]; + + input.readFully(data, 0, length); + + try + { + message.recoverContentBodyFrame(new RecoverDataBuffer(length, data), (chunk + 1 == chunkCount)); + } + catch (AMQException e) + { + //ignore as this will not occur. + // It is thrown by the _transactionLog method in load on PersistentAMQMessage + // but we have created the message with a null log and will never call that method. + } + } + + return message; + } + catch (Exception e) + { + error = e; + } + finally + { + try + { + input.close(); + // We can purge the message here then reflow it if required but I believe it to be cleaner to leave it + // on disk until it has been deleted from the queue at that point we can be sure we won't need the data + //handle.delete(); + } + catch (IOException e) + { + _log.info("Unable to close input on message(" + messageId + ") recovery due to:" + e.getMessage()); + } + } + + throw new UnableToRecoverMessageException(error); + } + + public void unload(AMQMessage message) throws UnableToFlowMessageException + { + long messageId = message.getMessageId(); + + File handle = getFileHandle(messageId); + + //If we have written the data once then we don't need to do it again. + if (handle.exists()) + { + if (_log.isDebugEnabled()) + { + _log.debug("Message(ID:" + messageId + ") already unloaded."); + } + return; + } + + if (_log.isInfoEnabled()) + { + _log.info("Unloading Message (ID:" + messageId + ")"); + } + + ObjectOutputStream writer = null; + Exception error = null; + + try + { + writer = new ObjectOutputStream(new FileOutputStream(handle)); + + writer.writeLong(message.getArrivalTime()); + + MessagePublishInfo mpi = message.getMessagePublishInfo(); + writer.writeUTF(String.valueOf(mpi.getExchange())); + writer.writeUTF(String.valueOf(mpi.getRoutingKey())); + writer.writeBoolean(mpi.isMandatory()); + writer.writeBoolean(mpi.isImmediate()); + ContentHeaderBody chb = message.getContentHeaderBody(); + + // write out the content header body + final int bodySize = chb.getSize(); + byte[] underlying = new byte[bodySize]; + ByteBuffer buf = ByteBuffer.wrap(underlying); + chb.writePayload(buf); + + writer.writeInt(bodySize); + writer.write(underlying, 0, bodySize); + + int bodyCount = message.getBodyCount(); + writer.writeInt(bodyCount); + + //WriteContentBody + for (int index = 0; index < bodyCount; index++) + { + ContentChunk chunk = message.getContentChunk(index); + int length = chunk.getSize(); + + byte[] chunk_underlying = new byte[length]; + + ByteBuffer chunk_buf = chunk.getData(); + + chunk_buf.duplicate().rewind().get(chunk_underlying); + + writer.writeInt(length); + writer.write(chunk_underlying, 0, length); + } + } + catch (FileNotFoundException e) + { + error = e; + } + catch (IOException e) + { + error = e; + } + finally + { + // In a FileNotFound situation writer will be null. + if (writer != null) + { + try + { + writer.flush(); + writer.close(); + } + catch (IOException e) + { + error = e; + } + } + } + + if (error != null) + { + _log.error("Unable to unload message(" + messageId + ") to disk, restoring state."); + handle.delete(); + throw new UnableToFlowMessageException(messageId, error); + } + } + + /** + * Use the messageId to calculate the file path on disk. + * + * Current implementation will give us 256 bins. + * Therefore the maximum messages that can be flowed before error/platform is: + * ext3 : 256 bins * 32000 = 8192000 + * FAT32 : 256 bins * 65534 = 16776704 + * Other FS have much greater limits than we need to worry about. + * + * @param messageId the Message we need a file Handle for. + * + * @return the File handle + */ + private File getFileHandle(long messageId) + { + // grab the 8 LSB to give us 256 bins + long bin = messageId & 0xFFL; + + String bin_path = _flowToDiskLocation + File.separator + bin; + File bin_dir = new File(bin_path); + + if (!bin_dir.exists()) + { + bin_dir.mkdirs(); + } + + String id = bin_path + File.separator + messageId; + + return new File(id); + } + + public void delete(Long messageId) + { + File handle = getFileHandle(messageId); + + if (handle.exists()) + { + if (_log.isInfoEnabled()) + { + _log.info("Message(" + messageId + ") delete flowToDisk."); + } + if (!handle.delete()) + { + throw new RuntimeException("Unable to delete flowToDisk data"); + } + } + } + + public void close() + { + _log.info("Closing Backing store at:" + _flowToDiskLocation); + if (!FileUtils.delete(new File(_flowToDiskLocation), true)) + { + _log.error("Unable to fully delete backing store location"); + } + } + + private class RecoverDataBuffer implements ContentChunk + { + private int _length; + private ByteBuffer _dataBuffer; + + public RecoverDataBuffer(int length, byte[] data) + { + _length = length; + _dataBuffer = ByteBuffer.wrap(data); + } + + public int getSize() + { + return _length; + } + + public ByteBuffer getData() + { + return _dataBuffer; + } + + public void reduceToFit() + { + + } + + } + +} + diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FileQueueBackingStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FileQueueBackingStoreFactory.java new file mode 100644 index 0000000000..21073c22ae --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FileQueueBackingStoreFactory.java @@ -0,0 +1,166 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.log4j.Logger; +import org.apache.qpid.server.configuration.VirtualHostConfiguration; +import org.apache.qpid.server.virtualhost.VirtualHost; +import org.apache.qpid.util.FileUtils; + +import java.io.File; + +public class FileQueueBackingStoreFactory implements QueueBackingStoreFactory +{ + private static final Logger _log = Logger.getLogger(FileQueueBackingStoreFactory.class); + + private String _flowToDiskLocation; + private static final String QUEUE_BACKING_DIR = "queueBacking"; + + public void configure(VirtualHost virtualHost, VirtualHostConfiguration config) throws ConfigurationException + { + setFlowToDisk(virtualHost.getName(), config.getFlowToDiskLocation()); + } + + private void setFlowToDisk(String vHostName, String location) throws ConfigurationException + { + if (vHostName == null) + { + throw new ConfigurationException("Unable to setup to Flow to Disk as Virtualhost name was not specified"); + } + + if (location == null) + { + throw new ConfigurationException("Unable to setup to Flow to Disk as location was not specified."); + } + + _flowToDiskLocation = location; + + _flowToDiskLocation += File.separator + QUEUE_BACKING_DIR + File.separator + vHostName; + + //Check the location we will create QUEUE_BACKING_DIR in. + File root = new File(location); + if (!root.exists()) + { + throw new ConfigurationException("Specified Flow to Disk root does not exist:" + root.getAbsolutePath()); + } + else + { + + if (root.isFile()) + { + throw new ConfigurationException("Unable to create Temporary Flow to Disk store as specified root is a file:" + + root.getAbsolutePath()); + } + + if (!root.canWrite()) + { + throw new ConfigurationException("Unable to create Temporary Flow to Disk store. Unable to write to specified root:" + + root.getAbsolutePath()); + } + + } + + // if we don't mark QUEUE_BAKCING_DIR as a deleteOnExit it will remain. + File backingDir = new File(location + File.separator + QUEUE_BACKING_DIR); + if (backingDir.exists()) + { + if (!FileUtils.delete(backingDir, true)) + { + throw new ConfigurationException("Unable to delete existing Flow to Disk root at:" + + backingDir.getAbsolutePath()); + } + + if (backingDir.isFile()) + { + throw new ConfigurationException("Unable to create Temporary Flow to Disk root as specified location is a file:" + + backingDir.getAbsolutePath()); + } + } + + backingDir.deleteOnExit(); + if (!backingDir.mkdirs()) + { + throw new ConfigurationException("Unable to create Temporary Flow to Disk root:" + location + File.separator + QUEUE_BACKING_DIR); + } + + + File store = new File(_flowToDiskLocation); + if (store.exists()) + { + if (!FileUtils.delete(store, true)) + { + throw new ConfigurationException("Unable to delete existing Flow to Disk store at:" + + store.getAbsolutePath()); + } + + if (store.isFile()) + { + throw new ConfigurationException("Unable to create Temporary Flow to Disk store as specified location is a file:" + + store.getAbsolutePath()); + } + + } + + _log.info("Creating Flow to Disk Store : " + store.getAbsolutePath()); + store.deleteOnExit(); + if (!store.mkdir()) + { + throw new ConfigurationException("Unable to create Temporary Flow to Disk store:" + store.getAbsolutePath()); + } + } + + public QueueBackingStore createBacking(AMQQueue queue) + { + return new FileQueueBackingStore(createStore(queue.getName().toString())); + } + + private String createStore(String name) + { + return createStore(name, 0); + } + + private String createStore(String name, int index) + { + + String store = _flowToDiskLocation + File.separator + name; + if (index > 0) + { + store += "-" + index; + } + + //TODO ensure store is safe for the OS + + File storeFile = new File(store); + + if (storeFile.exists()) + { + return createStore(name, index + 1); + } + + storeFile.mkdirs(); + + storeFile.deleteOnExit(); + + return store; + } + +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FlowableBaseQueueEntryList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FlowableBaseQueueEntryList.java new file mode 100644 index 0000000000..0c4b8a0b42 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/FlowableBaseQueueEntryList.java @@ -0,0 +1,485 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +import org.apache.log4j.Logger; +import org.apache.qpid.pool.ReferenceCountingExecutorService; +import org.apache.qpid.server.virtualhost.VirtualHost; + +import java.util.concurrent.Executor; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; + +/** This is an abstract base class to handle */ +public abstract class FlowableBaseQueueEntryList implements QueueEntryList +{ + protected static final Logger _log = Logger.getLogger(FlowableBaseQueueEntryList.class); + + private final AtomicInteger _atomicQueueCount = new AtomicInteger(0); + private final AtomicLong _atomicQueueSize = new AtomicLong(0L); + protected final AtomicLong _atomicQueueInMemory = new AtomicLong(0L); + /** The maximum amount of memory that is allocated to this queue. Beyond this the queue will flow to disk. */ + + protected long _memoryUsageMaximum = -1L; + + /** The minimum amount of memory that is allocated to this queue. If the queueDepth hits this level then more flowed data can be read in. */ + protected long _memoryUsageMinimum = 0; + private volatile AtomicBoolean _flowed; + private QueueBackingStore _backingStore; + protected AMQQueue _queue; + private Executor _inhaler; + private Executor _purger; + private AtomicBoolean _stopped; + private AtomicReference _asynchronousInhaler = new AtomicReference(null); + protected boolean _disabled; + private AtomicReference _asynchronousPurger = new AtomicReference(null); + private static final int BATCH_PROCESS_COUNT = 100; + + FlowableBaseQueueEntryList(AMQQueue queue) + { + _queue = queue; + _flowed = new AtomicBoolean(false); + VirtualHost vhost = queue.getVirtualHost(); + if (vhost != null) + { + _backingStore = vhost.getQueueBackingStoreFactory().createBacking(queue); + } + + _stopped = new AtomicBoolean(false); + _inhaler = ReferenceCountingExecutorService.getInstance().acquireExecutorService(); + _purger = ReferenceCountingExecutorService.getInstance().acquireExecutorService(); + _disabled = true; + } + + public void setFlowed(boolean flowed) + { + if (_flowed.get() != flowed) + { + _log.warn("Marking Queue(" + _queue.getName() + ") as flowed (" + flowed + ")"); + _flowed.set(flowed); + } + } + + protected void showUsage() + { + showUsage(""); + } + + protected void showUsage(String prefix) + { + if (_log.isDebugEnabled()) + { + _log.debug(prefix + " Queue(" + _queue + ":" + _queue.getName() + ") usage:" + memoryUsed() + + "/" + getMemoryUsageMinimum() + "<>" + getMemoryUsageMaximum() + + "/" + dataSize()); + } + } + + public boolean isFlowed() + { + return _flowed.get(); + } + + public int size() + { + return _atomicQueueCount.get(); + } + + public long dataSize() + { + return _atomicQueueSize.get(); + } + + public long memoryUsed() + { + return _atomicQueueInMemory.get(); + } + + public void setMemoryUsageMaximum(long maximumMemoryUsage) + { + _memoryUsageMaximum = maximumMemoryUsage; + + if (maximumMemoryUsage >= 0) + { + _disabled = false; + } + + // Don't attempt to start the inhaler/purger unless we have a minimum value specified. + if (_memoryUsageMaximum >= 0) + { + setMemoryUsageMinimum(_memoryUsageMaximum / 2); + + // if we have now have to much memory in use we need to purge. + if (_memoryUsageMaximum < _atomicQueueInMemory.get()) + { + setFlowed(true); + startPurger(); + } + } + else + { + if (_log.isInfoEnabled()) + { + _log.info("Disabling Flow to Disk for queue:" + _queue.getName()); + } + _disabled = true; + } + } + + public long getMemoryUsageMaximum() + { + return _memoryUsageMaximum; + } + + public void setMemoryUsageMinimum(long minimumMemoryUsage) + { + _memoryUsageMinimum = minimumMemoryUsage; + + // Don't attempt to start the inhaler unless we have a minimum value specified. + if (_memoryUsageMinimum > 0) + { + checkAndStartInhaler(); + } + } + + private void checkAndStartInhaler() + { + // If we've increased the minimum memory above what we have in memory then + // we need to inhale more if there is more + if (_atomicQueueInMemory.get() < _memoryUsageMinimum && _atomicQueueSize.get() > 0) + { + startInhaler(); + } + } + + private void startInhaler() + { + MessageInhaler inhaler = new MessageInhaler(); + + if (_asynchronousInhaler.compareAndSet(null, inhaler)) + { + _inhaler.execute(inhaler); + } + } + + private void startPurger() + { + MessagePurger purger = new MessagePurger(); + + if (_asynchronousPurger.compareAndSet(null, purger)) + { + _purger.execute(purger); + } + } + + public long getMemoryUsageMinimum() + { + return _memoryUsageMinimum; + } + + /** + * Only to be called by the QueueEntry + * + * @param queueEntry the entry to unload + */ + public void entryUnloadedUpdateMemory(QueueEntry queueEntry) + { + if (_atomicQueueInMemory.addAndGet(-queueEntry.getSize()) < 0) + { + _log.error("InMemory Count just went below 0:" + queueEntry.debugIdentity()); + } + + checkAndStartInhaler(); + } + + /** + * Only to be called from the QueueEntry + * + * @param queueEntry the entry to load + */ + public void entryLoadedUpdateMemory(QueueEntry queueEntry) + { + if (_atomicQueueInMemory.addAndGet(queueEntry.getSize()) > _memoryUsageMaximum) + { + _log.error("Loaded to much data!:" + _atomicQueueInMemory.get() + "/" + _memoryUsageMaximum); + setFlowed(true); + startPurger(); + } + } + + public void stop() + { + if (!_stopped.getAndSet(true)) + { + // The SimpleAMQQueue keeps running when stopped so we should just release the services + // rather than actively shutdown our threads. + //Shutdown thread for inhaler. + ReferenceCountingExecutorService.getInstance().releaseExecutorService(); + ReferenceCountingExecutorService.getInstance().releaseExecutorService(); + + _backingStore.close(); + } + } + + protected void incrementCounters(final QueueEntryImpl queueEntry) + { + _atomicQueueCount.incrementAndGet(); + _atomicQueueSize.addAndGet(queueEntry.getSize()); + long inUseMemory = _atomicQueueInMemory.addAndGet(queueEntry.getSize()); + + if (!_disabled && inUseMemory > _memoryUsageMaximum) + { + setFlowed(true); + queueEntry.unload(); + } + } + + protected void dequeued(QueueEntryImpl queueEntry) + { + _atomicQueueCount.decrementAndGet(); + _atomicQueueSize.addAndGet(-queueEntry.getSize()); + if (!queueEntry.isFlowed()) + { + if (_atomicQueueInMemory.addAndGet(-queueEntry.getSize()) < 0) + { + _log.error("InMemory Count just went below 0 on dequeue."); + } + } + } + + public QueueBackingStore getBackingStore() + { + return _backingStore; + } + + private class MessageInhaler implements Runnable + { + public void run() + { + String threadName = Thread.currentThread().getName(); + Thread.currentThread().setName("Inhaler-" + _queue.getVirtualHost().getName() + "-" + _queue.getName()); + try + { + inhaleList(this); + } + finally + { + Thread.currentThread().setName(threadName); + } + } + } + + private void inhaleList(MessageInhaler messageInhaler) + { + if (_log.isInfoEnabled()) + { + _log.info("Inhaler Running:" + _queue.getName()); + showUsage("Inhaler Running:" + _queue.getName()); + } + // If in memory count is at or over max then we can't inhale + if (_atomicQueueInMemory.get() >= _memoryUsageMaximum) + { + if (_log.isDebugEnabled()) + { + _log.debug("Unable to start inhaling as we are already over quota:" + + _atomicQueueInMemory.get() + ">=" + _memoryUsageMaximum); + } + return; + } + + _asynchronousInhaler.compareAndSet(messageInhaler, null); + int inhaled = 1; + + while ((_atomicQueueInMemory.get() < _memoryUsageMaximum) // we havn't filled our max memory + && (_atomicQueueInMemory.get() < _atomicQueueSize.get()) // we haven't loaded all that is available + && (inhaled < BATCH_PROCESS_COUNT) // limit the number of runs we do + && (inhaled > 0) // ensure we could inhale something + && _asynchronousInhaler.compareAndSet(null, messageInhaler)) // Ensure we are the running inhaler + { + inhaled = 0; + QueueEntryIterator iterator = iterator(); + + // If the inhaler is running and delivery rate picks up ensure that we just don't chase the delivery thread. + while ((_atomicQueueInMemory.get() < _memoryUsageMaximum) + && !iterator.getNode().isAvailable() && iterator.advance()) + { + //Find first AVAILABLE node + } + + // Because the above loop checks then moves on to the next entry a check for atTail will return true but + // we won't have checked the last entry to see if we can load it. So create atEndofList and update it based + // on the return from advance() which returns true if it can advance. + boolean atEndofList = false; + while ((_atomicQueueInMemory.get() < _memoryUsageMaximum) // we havn't filled our max memory + && (inhaled < BATCH_PROCESS_COUNT) // limit the number of runs we do + && !atEndofList) // We have reached end of list QueueEntries + { + QueueEntry entry = iterator.getNode(); + + if (entry.isAvailable() && entry.isFlowed()) + { + if (_atomicQueueInMemory.get() + entry.getSize() > _memoryUsageMaximum) + { + // We don't have space for this message so we need to stop inhaling. + if (_log.isDebugEnabled()) + { + _log.debug("Entry won't fit in memory stopping inhaler:" + entry.debugIdentity()); + } + inhaled = BATCH_PROCESS_COUNT; + } + else + { + entry.load(); + inhaled++; + } + } + + atEndofList = !iterator.advance(); + } + + if (iterator.atTail()) + { + setFlowed(false); + } + + _asynchronousInhaler.set(null); + } + + if (_log.isInfoEnabled()) + { + _log.info("Inhaler Stopping:" + _queue.getName()); + showUsage("Inhaler Stopping:" + _queue.getName()); + } + + //If we have become flowed or have more capacity since we stopped then schedule the thread to run again. + if (_flowed.get() && _atomicQueueInMemory.get() < _memoryUsageMaximum) + { + if (_log.isInfoEnabled()) + { + _log.info("Rescheduling Inhaler:" + _queue.getName()); + } + _inhaler.execute(messageInhaler); + } + + } + + private class MessagePurger implements Runnable + { + public void run() + { + String threadName = Thread.currentThread().getName(); + Thread.currentThread().setName("Purger-" + _queue.getVirtualHost().getName() + "-" + _queue.getName()); + try + { + purgeList(this); + } + finally + { + Thread.currentThread().setName(threadName); + } + } + } + + private void purgeList(MessagePurger messagePurger) + { + // If in memory count is at or over max then we can't inhale + if (_atomicQueueInMemory.get() <= _memoryUsageMinimum) + { + if (_log.isDebugEnabled()) + { + _log.debug("Unable to start purging as we are already below our minimum cache level:" + + _atomicQueueInMemory.get() + "<=" + _memoryUsageMinimum); + } + return; + } + + if (_log.isInfoEnabled()) + { + _log.info("Purger Running:" + _queue.getName()); + showUsage("Purger Running:" + _queue.getName()); + } + + _asynchronousPurger.compareAndSet(messagePurger, null); + int purged = 0; + + while ((_atomicQueueInMemory.get() > _memoryUsageMinimum) + && purged < BATCH_PROCESS_COUNT + && _asynchronousPurger.compareAndSet(null, messagePurger)) + { + QueueEntryIterator iterator = iterator(); + + //There are potentially AQUIRED messages that can be purged but we can't purge the last AQUIRED message + // as it may have just become AQUIRED and not yet delivered. + + //To be safe only purge available messages. This should be fine as long as we have a small prefetch. + while (!iterator.getNode().isAvailable() && iterator.advance()) + { + //Find first AVAILABLE node + } + + // Count up the memory usage to find our minimum point + long memoryUsage = 0; + boolean atTail = false; + while ((memoryUsage < _memoryUsageMaximum) && !atTail) + { + QueueEntry entry = iterator.getNode(); + + if (entry.isAvailable() && !entry.isFlowed()) + { + memoryUsage += entry.getSize(); + } + + atTail = !iterator.advance(); + } + + //Purge remainging mesages on queue + while (!atTail && (purged < BATCH_PROCESS_COUNT)) + { + QueueEntry entry = iterator.getNode(); + + if (entry.isAvailable() && !entry.isFlowed()) + { + entry.unload(); + purged++; + } + + atTail = !iterator.advance(); + } + + _asynchronousPurger.set(null); + } + + if (_log.isInfoEnabled()) + { + _log.info("Purger Stopping:" + _queue.getName()); + showUsage("Purger Stopping:" + _queue.getName()); + } + + //If we are still flowed and are over the minimum value then schedule to run again. + if (_flowed.get() && _atomicQueueInMemory.get() > _memoryUsageMinimum) + { + _log.info("Rescheduling Purger:" + _queue.getName()); + _purger.execute(messagePurger); + } + } +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ManagedQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ManagedQueue.java index 2bc94995e9..d2cf90b42d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ManagedQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ManagedQueue.java @@ -41,6 +41,7 @@ import org.apache.qpid.server.management.MBeanOperationParameter; public interface ManagedQueue { static final String TYPE = "Queue"; + static final int VERSION = 2; /** * Returns the Name of the ManagedQueue. @@ -71,7 +72,7 @@ public interface ManagedQueue * @return * @throws IOException */ - @MBeanAttribute(name="QueueDepth", description="Size of messages(KB) in the queue") + @MBeanAttribute(name="QueueDepth", description="The total size(Bytes) of messages in the queue") Long getQueueDepth() throws IOException, JMException; /** @@ -180,9 +181,66 @@ public interface ManagedQueue * @param value * @throws IOException */ - @MBeanAttribute(name="MaximumQueueDepth", description="The threshold high value(KB) for Queue Depth") + @MBeanAttribute(name="MaximumQueueDepth", description="The threshold high value(Bytes) for Queue Depth") void setMaximumQueueDepth(Long value) throws IOException; + //TODO change descriptions + /** + * View the limit on the memory that this queue will utilise. + * + * Used by Flow to Disk. + * + * @return The maximum memory(B) that the queue will occuy. + */ + public Long getMemoryUsageMaximum(); + + /** + * Place a limit on the memory that this queue will utilise. + * + * Used by Flow to Disk + * + * @param maximumMemoryUsage The new maximum memory(B) to be used by this queue + */ + @MBeanAttribute(name="MemoryUsageMaximum", description="The maximum memory(B) that the queue will occupy.") + public void setMemoryUsageMaximum(Long maximumMemoryUsage); + + /** + * View the minimum amount of memory that has been defined for this queue. + * + * Used by Flow to Disk + * + * @return The minimum amount of queue data(B) that the queue will attempt to keep in memory + */ + public Long getMemoryUsageMinimum(); + + /** + * Set the minimum amount of memory that has been defined for this queue. + * + * Used by Flow to Disk + * + * @param minimumMemoryUsage The new minimum memory(B) level to be used by this queue + */ + @MBeanAttribute(name="MemoryUsageMinimum", description="The minimum memory(B) that the queue will occupy.") + public void setMemoryUsageMinimum(Long minimumMemoryUsage); + + /** + * View the amount of memory(B) that this queue is using. + * + * @return The current memory(B) usage of this queue. + */ + @MBeanAttribute(name="MemoryUsageCurrent", description="The current amount of memory(B) used by this queue.") + public Long getMemoryUsageCurrent(); + + /** + * When a queue exceeds its MemoryUsageMaximum value then the Queue will start flowing to disk. + * + * This boolean is used to show that change in state. + * + * @return true if the Queue is currently flowing to disk + */ + @MBeanAttribute(name="isFlowed", description="true if the queue is currently flowing to disk.") + public boolean isFlowed(); + //********** Operations *****************// diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/NotificationCheck.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/NotificationCheck.java index e33b0c83c7..a83d661de2 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/NotificationCheck.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/NotificationCheck.java @@ -20,14 +20,12 @@ */ package org.apache.qpid.server.queue; -import org.apache.qpid.AMQException; - public enum NotificationCheck { MESSAGE_COUNT_ALERT { - boolean notifyIfNecessary(AMQMessage msg, AMQQueue queue, QueueNotificationListener listener) + boolean notifyIfNecessary(QueueEntry queueEntry, AMQQueue queue, QueueNotificationListener listener) { int msgCount; final long maximumMessageCount = queue.getMaximumMessageCount(); @@ -41,19 +39,19 @@ public enum NotificationCheck }, MESSAGE_SIZE_ALERT(true) { - boolean notifyIfNecessary(AMQMessage msg, AMQQueue queue, QueueNotificationListener listener) + boolean notifyIfNecessary(QueueEntry queueEntry, AMQQueue queue, QueueNotificationListener listener) { final long maximumMessageSize = queue.getMaximumMessageSize(); if(maximumMessageSize != 0) { // Check for threshold message size - long messageSize = (msg == null) ? 0 : msg.getContentHeaderBody().bodySize; + long messageSize = (queueEntry == null) ? 0 : queueEntry.getSize(); if (messageSize >= maximumMessageSize) { listener.notifyClients(this, queue, messageSize + "b : Maximum message size threshold (" + maximumMessageSize + ") breached. [Message ID=" + - (msg == null ? "null" : msg.getMessageId()) + "]"); + (queueEntry == null ? "null" : queueEntry.getMessageId()) + "]"); return true; } } @@ -63,7 +61,7 @@ public enum NotificationCheck }, QUEUE_DEPTH_ALERT { - boolean notifyIfNecessary(AMQMessage msg, AMQQueue queue, QueueNotificationListener listener) + boolean notifyIfNecessary(QueueEntry queueEntry, AMQQueue queue, QueueNotificationListener listener) { // Check for threshold queue depth in bytes final long maximumQueueDepth = queue.getMaximumQueueDepth(); @@ -84,7 +82,7 @@ public enum NotificationCheck }, MESSAGE_AGE_ALERT { - boolean notifyIfNecessary(AMQMessage msg, AMQQueue queue, QueueNotificationListener listener) + boolean notifyIfNecessary(QueueEntry queueEntry, AMQQueue queue, QueueNotificationListener listener) { final long maxMessageAge = queue.getMaximumMessageAge(); @@ -126,6 +124,6 @@ public enum NotificationCheck return _messageSpecific; } - abstract boolean notifyIfNecessary(AMQMessage msg, AMQQueue queue, QueueNotificationListener listener); + abstract boolean notifyIfNecessary(QueueEntry queueEntry, AMQQueue queue, QueueNotificationListener listener); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PersistentAMQMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PersistentAMQMessage.java index 92c10b0347..9c644cc010 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PersistentAMQMessage.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PersistentAMQMessage.java @@ -52,7 +52,8 @@ public class PersistentAMQMessage extends TransientAMQMessage throws AMQException { super.setPublishAndContentHeaderBody(storeContext, messagePublishInfo, contentHeaderBody); - MessageMetaData mmd = new MessageMetaData(messagePublishInfo, contentHeaderBody, _contentBodies == null ? 0 : _contentBodies.size(), _arrivalTime); + MessageMetaData mmd = new MessageMetaData(messagePublishInfo, contentHeaderBody, + _contentBodies == null ? 0 : _contentBodies.size(), _arrivalTime); _transactionLog.storeMessageMetaData(storeContext, _messageId, mmd); } @@ -63,13 +64,7 @@ public class PersistentAMQMessage extends TransientAMQMessage return true; } - public void recoverFromMessageMetaData(MessageMetaData mmd) - { - _arrivalTime = mmd.getArrivalTime(); - _contentHeaderBody = mmd.getContentHeaderBody(); - _messagePublishInfo = mmd.getMessagePublishInfo(); - } - + @Override public void recoverContentBodyFrame(ContentChunk contentChunk, boolean isLastContentBody) throws AMQException { super.addContentBodyFrame(null, contentChunk, isLastContentBody); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueEntryList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueEntryList.java new file mode 100644 index 0000000000..5dd76a5299 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueEntryList.java @@ -0,0 +1,466 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ +package org.apache.qpid.server.queue; + +import org.apache.qpid.framing.CommonContentHeaderProperties; + +public class PriorityQueueEntryList extends FlowableBaseQueueEntryList implements QueueEntryList +{ + private final AMQQueue _queue; + private final QueueEntryList[] _priorityLists; + private final int _priorities; + private final int _priorityOffset; + + public PriorityQueueEntryList(AMQQueue queue, int priorities) + { + super(queue); + _queue = queue; + _priorityLists = new QueueEntryList[priorities]; + _priorities = priorities; + _priorityOffset = 5 - ((priorities + 1) / 2); + for (int i = 0; i < priorities; i++) + { + _priorityLists[i] = new SimpleQueueEntryList(queue); + } + + showUsage("Created:" + _queue.getName()); + } + + public int getPriorities() + { + return _priorities; + } + + public AMQQueue getQueue() + { + return _queue; + } + + public QueueEntry add(AMQMessage message) + { + int index = ((CommonContentHeaderProperties) ((message.getContentHeaderBody().properties))).getPriority() - _priorityOffset; + if (index >= _priorities) + { + index = _priorities - 1; + } + else if (index < 0) + { + index = 0; + } + + long requriedSize = message.getSize(); + // Check and see if list would flow on adding message + if (!_disabled && !isFlowed() && _priorityLists[index].memoryUsed() + requriedSize > _priorityLists[index].getMemoryUsageMaximum()) + { + if (_log.isDebugEnabled()) + { + _log.debug("Message(" + message.debugIdentity() + ") Add of size (" + + requriedSize + ") will cause flow. Searching for space"); + } + + long reclaimed = 0; + + //work down the priorities looking for memory + + //First: Don't take all the memory. So look for a queue that has more than 50% free + long currentMax; + int scavangeIndex = 0; + + if (scavangeIndex == index) + { + scavangeIndex++; + } + + while (scavangeIndex < _priorities && reclaimed <= requriedSize) + { + currentMax = _priorityLists[scavangeIndex].getMemoryUsageMaximum(); + long used = _priorityLists[scavangeIndex].memoryUsed(); + + if (used < currentMax / 2) + { + long newMax = currentMax / 2; + + _priorityLists[scavangeIndex].setMemoryUsageMaximum(newMax); + + reclaimed += currentMax - newMax; + if (_log.isDebugEnabled()) + { + _log.debug("Reclaiming(1) :" + (currentMax - newMax) + "(" + reclaimed + "/" + requriedSize + ") from queue:" + scavangeIndex); + } + break; + } + else + { + scavangeIndex++; + if (scavangeIndex == index) + { + scavangeIndex++; + } + } + } + + //Second: Just take the free memory we need + if (scavangeIndex == _priorities) + { + scavangeIndex = 0; + if (scavangeIndex == index) + { + scavangeIndex++; + } + + while (scavangeIndex < _priorities && reclaimed <= requriedSize) + { + currentMax = _priorityLists[scavangeIndex].getMemoryUsageMaximum(); + long used = _priorityLists[scavangeIndex].memoryUsed(); + + if (used < currentMax) + { + long newMax = currentMax - used; + + // if there are no messages at this priority just take it all + if (newMax == currentMax) + { + newMax = 0; + } + + _priorityLists[scavangeIndex].setMemoryUsageMaximum(newMax); + + reclaimed += currentMax - newMax; + if (_log.isDebugEnabled()) + { + _log.debug("Reclaiming(2) :" + (currentMax - newMax) + "(" + reclaimed + "/" + requriedSize + ") from queue:" + scavangeIndex); + } + break; + } + else + { + scavangeIndex++; + if (scavangeIndex == index) + { + scavangeIndex++; + } + } + } + + //Third: Take required memory + if (scavangeIndex == _priorities) + { + scavangeIndex = 0; + if (scavangeIndex == index) + { + scavangeIndex++; + } + while (scavangeIndex < _priorities && reclaimed <= requriedSize) + { + currentMax = _priorityLists[scavangeIndex].getMemoryUsageMaximum(); + + if (currentMax > 0 ) + { + long newMax = currentMax; + // Just take the amount of space required for this message. + if (newMax > requriedSize) + { + newMax = requriedSize; + } + _priorityLists[scavangeIndex].setMemoryUsageMaximum(newMax); + + reclaimed += currentMax - newMax; + if (_log.isDebugEnabled()) + { + _log.debug("Reclaiming(3) :" + (currentMax - newMax) + "(" + reclaimed + "/" + requriedSize + ") from queue:" + scavangeIndex); + } + break; + } + else + { + scavangeIndex++; + if (scavangeIndex == index) + { + scavangeIndex++; + } + } + } + } + } + + //Increment Maximum + if (reclaimed > 0) + { + if (_log.isDebugEnabled()) + { + _log.debug("Increasing queue(" + index + ") maximum by " + reclaimed + + " to " + (_priorityLists[index].getMemoryUsageMaximum() + reclaimed)); + } + _priorityLists[index].setMemoryUsageMaximum(_priorityLists[index].getMemoryUsageMaximum() + reclaimed); + } + else + { + _log.debug("No space found."); + } + + if (_log.isTraceEnabled()) + { + showUsage("Add"); + } + } + + return _priorityLists[index].add(message); + } + + @Override + protected void showUsage(String prefix) + { + if (_log.isDebugEnabled()) + { + if (prefix.length() != 0) + { + _log.debug(prefix); + } + for (int index = 0; index < _priorities; index++) + { + QueueEntryList queueEntryList = _priorityLists[index]; + _log.debug("Queue (" + _queue + ":" + _queue.getName() + ")[" + index + "] usage:" + queueEntryList.memoryUsed() + + "/" + queueEntryList.getMemoryUsageMaximum() + + "/" + queueEntryList.dataSize()); + } + } + } + + public QueueEntry next(QueueEntry node) + { + QueueEntryImpl nodeImpl = (QueueEntryImpl) node; + QueueEntry next = nodeImpl.getNext(); + + if (next == null) + { + QueueEntryList nodeEntryList = nodeImpl.getQueueEntryList(); + int index; + for (index = _priorityLists.length - 1; _priorityLists[index] != nodeEntryList; index--) + { + ; + } + + while (next == null && index != 0) + { + index--; + next = ((QueueEntryImpl) _priorityLists[index].getHead()).getNext(); + } + + } + return next; + } + + private final class PriorityQueueEntryListIterator implements QueueEntryIterator + { + private final QueueEntryIterator[] _iterators = new QueueEntryIterator[_priorityLists.length]; + private QueueEntry _lastNode; + + PriorityQueueEntryListIterator() + { + for (int i = 0; i < _priorityLists.length; i++) + { + _iterators[i] = _priorityLists[i].iterator(); + } + _lastNode = _iterators[_iterators.length - 1].getNode(); + } + + public boolean atTail() + { + for (int i = 0; i < _iterators.length; i++) + { + if (!_iterators[i].atTail()) + { + return false; + } + } + return true; + } + + public QueueEntry getNode() + { + return _lastNode; + } + + public boolean advance() + { + for (int i = _iterators.length - 1; i >= 0; i--) + { + if (_iterators[i].advance()) + { + _lastNode = _iterators[i].getNode(); + return true; + } + } + return false; + } + } + + public QueueEntryIterator iterator() + { + return new PriorityQueueEntryListIterator(); + } + + public QueueEntry getHead() + { + return _priorityLists[_priorities - 1].getHead(); + } + + static class Factory implements QueueEntryListFactory + { + private final int _priorities; + + Factory(int priorities) + { + _priorities = priorities; + } + + public QueueEntryList createQueueEntryList(AMQQueue queue) + { + return new PriorityQueueEntryList(queue, _priorities); + } + } + + @Override + public boolean isFlowed() + { + boolean flowed = false; + boolean full = true; + + if (_log.isTraceEnabled()) + { + showUsage("isFlowed"); + } + + for (QueueEntryList queueEntryList : _priorityLists) + { + //full = full && queueEntryList.getMemoryUsageMaximum() == queueEntryList.memoryUsed(); + full = full && queueEntryList.getMemoryUsageMaximum() <= queueEntryList.dataSize(); + flowed = flowed || (queueEntryList.isFlowed()); + } + return flowed && full; + } + + @Override + public int size() + { + int size = 0; + for (QueueEntryList queueEntryList : _priorityLists) + { + size += queueEntryList.size(); + } + + return size; + } + + @Override + public long dataSize() + { + int dataSize = 0; + for (QueueEntryList queueEntryList : _priorityLists) + { + dataSize += queueEntryList.dataSize(); + } + + return dataSize; + } + + @Override + public long memoryUsed() + { + int memoryUsed = 0; + for (QueueEntryList queueEntryList : _priorityLists) + { + memoryUsed += queueEntryList.memoryUsed(); + } + + return memoryUsed; + } + + @Override + public void setMemoryUsageMaximum(long maximumMemoryUsage) + { + _memoryUsageMaximum = maximumMemoryUsage; + + if (maximumMemoryUsage >= 0) + { + _disabled = false; + } + + long share = maximumMemoryUsage / _priorities; + + //Apply a share of the maximum To each prioirty quue + for (QueueEntryList queueEntryList : _priorityLists) + { + queueEntryList.setMemoryUsageMaximum(share); + } + + if (maximumMemoryUsage < 0) + { + if (_log.isInfoEnabled()) + { + _log.info("Disabling Flow to Disk for queue:" + _queue.getName()); + } + _disabled = true; + return; + } + + //ensure we use the full allocation of memory + long remainder = maximumMemoryUsage - (share * _priorities); + if (remainder > 0) + { + _priorityLists[_priorities - 1].setMemoryUsageMaximum(share + remainder); + } + } + + @Override + public long getMemoryUsageMaximum() + { + return _memoryUsageMaximum; + } + + @Override + public void setMemoryUsageMinimum(long minimumMemoryUsage) + { + _memoryUsageMinimum = minimumMemoryUsage; + + //Apply a share of the minimum To each prioirty quue + for (QueueEntryList queueEntryList : _priorityLists) + { + queueEntryList.setMemoryUsageMaximum(minimumMemoryUsage / _priorities); + } + } + + @Override + public long getMemoryUsageMinimum() + { + return _memoryUsageMinimum; + } + + @Override + public void stop() + { + super.stop(); + for (QueueEntryList queueEntryList : _priorityLists) + { + queueEntryList.stop(); + } + } +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java deleted file mode 100644 index 7be2827e0f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java +++ /dev/null @@ -1,160 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -* -*/ -package org.apache.qpid.server.queue; - -import org.apache.qpid.framing.CommonContentHeaderProperties; -import org.apache.qpid.AMQException; - -public class PriorityQueueList implements QueueEntryList -{ - private final AMQQueue _queue; - private final QueueEntryList[] _priorityLists; - private final int _priorities; - private final int _priorityOffset; - - public PriorityQueueList(AMQQueue queue, int priorities) - { - _queue = queue; - _priorityLists = new QueueEntryList[priorities]; - _priorities = priorities; - _priorityOffset = 5-((priorities + 1)/2); - for(int i = 0; i < priorities; i++) - { - _priorityLists[i] = new SimpleQueueEntryList(queue); - } - } - - public int getPriorities() - { - return _priorities; - } - - public AMQQueue getQueue() - { - return _queue; - } - - public QueueEntry add(AMQMessage message) - { - int index = ((CommonContentHeaderProperties)((message.getContentHeaderBody().properties))).getPriority() - _priorityOffset; - if(index >= _priorities) - { - index = _priorities-1; - } - else if(index < 0) - { - index = 0; - } - return _priorityLists[index].add(message); - } - - public QueueEntry next(QueueEntry node) - { - QueueEntryImpl nodeImpl = (QueueEntryImpl)node; - QueueEntry next = nodeImpl.getNext(); - - if(next == null) - { - QueueEntryList nodeEntryList = nodeImpl.getQueueEntryList(); - int index; - for(index = _priorityLists.length-1; _priorityLists[index] != nodeEntryList; index--); - - while(next == null && index != 0) - { - index--; - next = ((QueueEntryImpl)_priorityLists[index].getHead()).getNext(); - } - - } - return next; - } - - private final class PriorityQueueEntryListIterator implements QueueEntryIterator - { - private final QueueEntryIterator[] _iterators = new QueueEntryIterator[ _priorityLists.length ]; - private QueueEntry _lastNode; - - PriorityQueueEntryListIterator() - { - for(int i = 0; i < _priorityLists.length; i++) - { - _iterators[i] = _priorityLists[i].iterator(); - } - _lastNode = _iterators[_iterators.length - 1].getNode(); - } - - - public boolean atTail() - { - for(int i = 0; i < _iterators.length; i++) - { - if(!_iterators[i].atTail()) - { - return false; - } - } - return true; - } - - public QueueEntry getNode() - { - return _lastNode; - } - - public boolean advance() - { - for(int i = _iterators.length-1; i >= 0; i--) - { - if(_iterators[i].advance()) - { - _lastNode = _iterators[i].getNode(); - return true; - } - } - return false; - } - } - - public QueueEntryIterator iterator() - { - return new PriorityQueueEntryListIterator(); - } - - public QueueEntry getHead() - { - return _priorityLists[_priorities-1].getHead(); - } - - static class Factory implements QueueEntryListFactory - { - private final int _priorities; - - Factory(int priorities) - { - _priorities = priorities; - } - - public QueueEntryList createQueueEntryList(AMQQueue queue) - { - return new PriorityQueueList(queue, _priorities); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueBackingStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueBackingStore.java new file mode 100644 index 0000000000..5efb95d0c0 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueBackingStore.java @@ -0,0 +1,36 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +import org.apache.qpid.server.configuration.VirtualHostConfiguration; +import org.apache.qpid.server.virtualhost.VirtualHost; +import org.apache.commons.configuration.ConfigurationException; + +public interface QueueBackingStore +{ + AMQMessage load(Long messageId); + + void unload(AMQMessage message) throws UnableToFlowMessageException; + + void delete(Long messageId); + + void close(); +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueBackingStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueBackingStoreFactory.java new file mode 100644 index 0000000000..3dd23a2f40 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueBackingStoreFactory.java @@ -0,0 +1,32 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +import org.apache.qpid.server.virtualhost.VirtualHost; +import org.apache.qpid.server.configuration.VirtualHostConfiguration; +import org.apache.commons.configuration.ConfigurationException; + +public interface QueueBackingStoreFactory +{ + void configure(VirtualHost virtualHost, VirtualHostConfiguration config) throws ConfigurationException; + + public QueueBackingStore createBacking(AMQQueue queue); +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java index 09600b9d28..7fc5df4e9e 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java @@ -119,18 +119,48 @@ public interface QueueEntry extends Comparable, Filterable, Filterable, Filterable + AtomicReferenceFieldUpdater _stateUpdater = - AtomicReferenceFieldUpdater.newUpdater - (QueueEntryImpl.class, EntryState.class, "_state"); - + AtomicReferenceFieldUpdater.newUpdater + (QueueEntryImpl.class, EntryState.class, "_state"); private volatile Set _stateChangeListeners; private static final - AtomicReferenceFieldUpdater - _listenersUpdater = - AtomicReferenceFieldUpdater.newUpdater - (QueueEntryImpl.class, Set.class, "_stateChangeListeners"); - + AtomicReferenceFieldUpdater + _listenersUpdater = + AtomicReferenceFieldUpdater.newUpdater + (QueueEntryImpl.class, Set.class, "_stateChangeListeners"); private static final - AtomicLongFieldUpdater + AtomicLongFieldUpdater _entryIdUpdater = - AtomicLongFieldUpdater.newUpdater - (QueueEntryImpl.class, "_entryId"); - + AtomicLongFieldUpdater.newUpdater + (QueueEntryImpl.class, "_entryId"); private volatile long _entryId; volatile QueueEntryImpl _next; + private long _messageSize; + private QueueBackingStore _backingStore; + private AtomicBoolean _flowed; + private Long _messageId; + + private byte _flags = 0; + + private long _expiration; + + private static final byte IMMEDIATE_AND_DELIVERED = (byte) (IMMEDIATE | DELIVERED_TO_CONSUMER); + private boolean _persistent; QueueEntryImpl(SimpleQueueEntryList queueEntryList) { - this(queueEntryList,null,Long.MIN_VALUE); + this(queueEntryList, null, Long.MIN_VALUE); _state = DELETED_STATE; } - public QueueEntryImpl(SimpleQueueEntryList queueEntryList, AMQMessage message, final long entryId) { - _queueEntryList = queueEntryList; - _message = message; + this(queueEntryList, message); _entryIdUpdater.set(this, entryId); } @@ -98,6 +102,20 @@ public class QueueEntryImpl implements QueueEntry { _queueEntryList = queueEntryList; _message = message; + if (message != null) + { + _messageId = message.getMessageId(); + _messageSize = message.getSize(); + + if (message.isImmediate()) + { + _flags |= IMMEDIATE; + } + _expiration = message.getExpiration(); + _persistent = message.isPersistent(); + } + _backingStore = queueEntryList.getBackingStore(); + _flowed = new AtomicBoolean(false); } protected void setEntryId(long entryId) @@ -117,22 +135,54 @@ public class QueueEntryImpl implements QueueEntry public AMQMessage getMessage() { + if (_message == null) + { + return _backingStore.load(_messageId); + } return _message; } + public Long getMessageId() + { + return _messageId; + } + public long getSize() { - return getMessage().getSize(); + return _messageSize; } public boolean getDeliveredToConsumer() { - return getMessage().getDeliveredToConsumer(); + return (_flags & DELIVERED_TO_CONSUMER) != 0; + } + + public void setDeliveredToConsumer() + { + _flags |= DELIVERED_TO_CONSUMER; + + // We have delivered this message so we can unload it if we are flowed. + if (_queueEntryList.isFlowed()) + { + unload(); + } } public boolean expired() throws AMQException { - return getMessage().expired(); + if (_expiration != 0L) + { + long now = System.currentTimeMillis(); + + return (now > _expiration); + } + + return false; + } + + public void setExpiration(final long expiration) + { + _expiration = expiration; } public boolean isAcquired() @@ -140,6 +190,11 @@ public class QueueEntryImpl implements QueueEntry return _state.getState() == State.ACQUIRED; } + public boolean isAvailable() + { + return _state.getState() == State.AVAILABLE; + } + public boolean acquire() { return acquire(NON_SUBSCRIPTION_ACQUIRED_STATE); @@ -147,8 +202,8 @@ public class QueueEntryImpl implements QueueEntry private boolean acquire(final EntryState state) { - boolean acquired = _stateUpdater.compareAndSet(this,AVAILABLE_STATE, state); - if(acquired && _stateChangeListeners != null) + boolean acquired = _stateUpdater.compareAndSet(this, AVAILABLE_STATE, state); + if (acquired && _stateChangeListeners != null) { notifyStateChange(State.AVAILABLE, State.ACQUIRED); } @@ -169,33 +224,40 @@ public class QueueEntryImpl implements QueueEntry public void setDeliveredToSubscription() { - getMessage().setDeliveredToConsumer(); + _flags |= DELIVERED_TO_CONSUMER; } public void release() { - _stateUpdater.set(this,AVAILABLE_STATE); + _stateUpdater.set(this, AVAILABLE_STATE); } public String debugIdentity() { - return getMessage().debugIdentity(); + String entry = "[State:" + _state.getState().name() + "]"; + if (_message == null) + { + return entry + "(Message Unloaded ID:" + _messageId + ")"; + } + else + { + return entry + _message.debugIdentity(); + } } - - public boolean immediateAndNotDelivered() + public boolean immediateAndNotDelivered() { - return _message.immediateAndNotDelivered(); + return (_flags & IMMEDIATE_AND_DELIVERED) == IMMEDIATE; } public ContentHeaderBody getContentHeaderBody() throws AMQException { - return _message.getContentHeaderBody(); + return getMessage().getContentHeaderBody(); } public boolean isPersistent() throws AMQException { - return _message.isPersistent(); + return _persistent; } public boolean isRedelivered() @@ -206,21 +268,21 @@ public class QueueEntryImpl implements QueueEntry public void setRedelivered(boolean redelivered) { _redelivered = redelivered; - // todo - here we could mark this message as redelivered so we don't have to mark - // all messages on recover as redelivered. + // todo - here we could record this message as redelivered on this queue in the transactionLog + // so we don't have to mark all messages on recover as redelivered. } public Subscription getDeliveredSubscription() { - EntryState state = _state; - if (state instanceof SubscriptionAcquiredState) - { - return ((SubscriptionAcquiredState) state).getSubscription(); - } - else - { - return null; - } + EntryState state = _state; + if (state instanceof SubscriptionAcquiredState) + { + return ((SubscriptionAcquiredState) state).getSubscription(); + } + else + { + return null; + } } @@ -247,7 +309,7 @@ public class QueueEntryImpl implements QueueEntry } public boolean isRejectedBy(Subscription subscription) - { + { if (_rejectedBy != null) // We have subscriptions that rejected this message { @@ -259,11 +321,10 @@ public class QueueEntryImpl implements QueueEntry } } - public void requeue(final StoreContext storeContext) throws AMQException { getQueue().requeue(storeContext, this); - if(_stateChangeListeners != null) + if (_stateChangeListeners != null) { notifyStateChange(QueueEntry.State.ACQUIRED, QueueEntry.State.AVAILABLE); } @@ -273,7 +334,7 @@ public class QueueEntryImpl implements QueueEntry { EntryState state = _state; - if((state.getState() == State.ACQUIRED) &&_stateUpdater.compareAndSet(this, state, DEQUEUED_STATE)) + if ((state.getState() == State.ACQUIRED) && _stateUpdater.compareAndSet(this, state, DEQUEUED_STATE)) { if (state instanceof SubscriptionAcquiredState) { @@ -281,6 +342,8 @@ public class QueueEntryImpl implements QueueEntry s.restoreCredit(this); } + _queueEntryList.dequeued(this); + getQueue().dequeue(storeContext, this); if (_stateChangeListeners != null) @@ -292,7 +355,7 @@ public class QueueEntryImpl implements QueueEntry private void notifyStateChange(final State oldState, final State newState) { - for(StateChangeListener l : _stateChangeListeners) + for (StateChangeListener l : _stateChangeListeners) { l.stateChanged(this, oldState, newState); } @@ -317,7 +380,7 @@ public class QueueEntryImpl implements QueueEntry public void addStateChangeListener(StateChangeListener listener) { Set listeners = _stateChangeListeners; - if(listeners == null) + if (listeners == null) { _listenersUpdater.compareAndSet(this, null, new CopyOnWriteArraySet()); listeners = _stateChangeListeners; @@ -329,7 +392,7 @@ public class QueueEntryImpl implements QueueEntry public boolean removeStateChangeListener(StateChangeListener listener) { Set listeners = _stateChangeListeners; - if(listeners != null) + if (listeners != null) { return listeners.remove(listener); } @@ -337,10 +400,66 @@ public class QueueEntryImpl implements QueueEntry return false; } + public void unload() + { + if (_message != null && _backingStore != null) + { + + try + { + _backingStore.unload(_message); + + if (_log.isDebugEnabled()) + { + _log.debug("Unloaded:" + debugIdentity()); + } + _message = null; + + //Update the memoryState if this load call resulted in the message being purged from memory + if (!_flowed.getAndSet(true)) + { + _queueEntryList.entryUnloadedUpdateMemory(this); + } + + } + catch (UnableToFlowMessageException utfme) + { + // There is no recovery needed as the memory states remain unchanged. + if (_log.isDebugEnabled()) + { + _log.debug("Unable to Flow message:" + debugIdentity() + ", due to:" + utfme.getMessage()); + } + } + } + } + + public void load() + { + if (_messageId != null && _backingStore != null) + { + _message = _backingStore.load(_messageId); + + if (_log.isDebugEnabled()) + { + _log.debug("Loaded:" + debugIdentity()); + } + + //Update the memoryState if this load call resulted in the message comming in to memory + if (_flowed.getAndSet(false)) + { + _queueEntryList.entryLoadedUpdateMemory(this); + } + } + } + + public boolean isFlowed() + { + return _flowed.get(); + } public int compareTo(final QueueEntry o) { - QueueEntryImpl other = (QueueEntryImpl)o; + QueueEntryImpl other = (QueueEntryImpl) o; return getEntryId() > other.getEntryId() ? 1 : getEntryId() < other.getEntryId() ? -1 : 0; } @@ -348,13 +467,13 @@ public class QueueEntryImpl implements QueueEntry { QueueEntryImpl next = nextNode(); - while(next != null && next.isDeleted()) + while (next != null && next.isDeleted()) { final QueueEntryImpl newNext = next.nextNode(); - if(newNext != null) + if (newNext != null) { - SimpleQueueEntryList._nextUpdater.compareAndSet(this,next, newNext); + SimpleQueueEntryList._nextUpdater.compareAndSet(this, next, newNext); next = nextNode(); } else @@ -380,9 +499,13 @@ public class QueueEntryImpl implements QueueEntry { EntryState state = _state; - if(state != DELETED_STATE && _stateUpdater.compareAndSet(this,state,DELETED_STATE)) + if (state != DELETED_STATE && _stateUpdater.compareAndSet(this, state, DELETED_STATE)) { - _queueEntryList.advanceHead(); + _queueEntryList.advanceHead(); + if (_backingStore != null) + { + _backingStore.delete(_messageId); + } return true; } else @@ -395,4 +518,5 @@ public class QueueEntryImpl implements QueueEntry { return _queueEntryList; } + } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryList.java index 313e076f61..a58c6eaf7d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryList.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryList.java @@ -1,23 +1,23 @@ /* -* -* 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. -* -*/ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ package org.apache.qpid.server.queue; public interface QueueEntryList @@ -31,4 +31,36 @@ public interface QueueEntryList QueueEntryIterator iterator(); QueueEntry getHead(); + + void setFlowed(boolean flowed); + + boolean isFlowed(); + + int size(); + + long dataSize(); + + long memoryUsed(); + + void setMemoryUsageMaximum(long maximumMemoryUsage); + + long getMemoryUsageMaximum(); + + void setMemoryUsageMinimum(long minimumMemoryUsage); + + long getMemoryUsageMinimum(); + + /** + * Immediately update memory usage based on the unload of this queueEntry, potentially start inhaler. + * @param queueEntry the entry that has been unloaded + */ + void entryUnloadedUpdateMemory(QueueEntry queueEntry); + + /** + * Immediately update memory usage based on the load of this queueEntry + * @param queueEntry the entry that has been loaded + */ + void entryLoadedUpdateMemory(QueueEntry queueEntry); + + void stop(); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java index 501e90b4d7..63ec56c1af 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java @@ -19,7 +19,6 @@ import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.pool.ReadWriteRunnable; import org.apache.qpid.pool.ReferenceCountingExecutorService; -import org.apache.qpid.server.configuration.QueueConfiguration; import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.management.ManagedObject; import org.apache.qpid.server.output.ProtocolOutputConverter; @@ -73,10 +72,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener private final List _deleteTaskList = new CopyOnWriteArrayList(); - private final AtomicInteger _atomicQueueCount = new AtomicInteger(0); - - private final AtomicLong _atomicQueueSize = new AtomicLong(0L); - private final AtomicInteger _activeSubscriberCount = new AtomicInteger(); protected final SubscriptionList _subscriptionList = new SubscriptionList(this); @@ -105,6 +100,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener /** the minimum interval between sending out consecutive alerts of the same type */ public long _minimumAlertRepeatGap = ApplicationRegistry.getInstance().getConfiguration().getMinimumAlertRepeatGap(); + private static final int MAX_ASYNC_DELIVERIES = 10; private final Set _notificationChecks = EnumSet.noneOf(NotificationCheck.class); @@ -159,7 +155,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener } resetNotifications(); - } public void resetNotifications() @@ -188,6 +183,11 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener return _autoDelete; } + public boolean isFlowed() + { + return _entries.isFlowed(); + } + public AMQShortString getOwner() { return _owner; @@ -321,10 +321,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener public QueueEntry enqueue(StoreContext storeContext, AMQMessage message) throws AMQException { - - incrementQueueCount(); - incrementQueueSize(message); - _totalMessagesReceived.incrementAndGet(); QueueEntry entry; @@ -421,7 +417,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener deliverAsync(); } - _managedObject.checkForNotification(entry.getMessage()); + _managedObject.checkForNotification(entry); return entry; } @@ -465,20 +461,11 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener // Simple Queues don't :-) } - private void incrementQueueSize(final AMQMessage message) - { - getAtomicQueueSize().addAndGet(message.getSize()); - } - - private void incrementQueueCount() - { - getAtomicQueueCount().incrementAndGet(); - } - private void deliverMessage(final Subscription sub, final QueueEntry entry) throws AMQException { _deliveredMessages.incrementAndGet(); + sub.send(entry); } @@ -573,8 +560,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener */ public void dequeue(StoreContext storeContext, QueueEntry entry) throws FailedDequeueException { - decrementQueueCount(); - decrementQueueSize(entry); if (entry.acquiredBySubscription()) { _deliveredMessages.decrementAndGet(); @@ -582,10 +567,9 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener try { - AMQMessage msg = entry.getMessage(); - if (msg.isPersistent()) + if (entry.isPersistent()) { - _virtualHost.getTransactionLog().dequeueMessage(storeContext, this, msg.getMessageId()); + _virtualHost.getTransactionLog().dequeueMessage(storeContext, this, entry.getMessageId()); } } @@ -604,15 +588,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener } - private void decrementQueueSize(final QueueEntry entry) - { - getAtomicQueueSize().addAndGet(-entry.getMessage().getSize()); - } - - void decrementQueueCount() - { - getAtomicQueueCount().decrementAndGet(); - } public boolean resend(final QueueEntry entry, final Subscription subscription) throws AMQException { @@ -658,14 +633,19 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener return getMessageCount() == 0; } + public long getMemoryUsageCurrent() + { + return getQueueInMemory(); + } + public int getMessageCount() { - return getAtomicQueueCount().get(); + return getQueueCount(); } public long getQueueDepth() { - return getAtomicQueueSize().get(); + return getQueueSize(); } public int getUndeliveredMessageCount() @@ -741,14 +721,19 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener return _name.compareTo(o.getName()); } - public AtomicInteger getAtomicQueueCount() + public int getQueueCount() + { + return _entries.size(); + } + + public long getQueueSize() { - return _atomicQueueCount; + return _entries.dataSize(); } - public AtomicLong getAtomicQueueSize() + public long getQueueInMemory() { - return _atomicQueueSize; + return _entries.memoryUsed(); } private boolean isExclusiveSubscriber() @@ -775,7 +760,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener public boolean accept(QueueEntry entry) { - final long messageId = entry.getMessage().getMessageId(); + final long messageId = entry.getMessageId(); return messageId >= fromMessageId && messageId <= toMessageId; } @@ -794,7 +779,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener public boolean accept(QueueEntry entry) { - _complete = entry.getMessage().getMessageId() == messageId; + _complete = entry.getMessageId() == messageId; return _complete; } @@ -843,7 +828,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener public boolean accept(QueueEntry entry) { - final long messageId = entry.getMessage().getMessageId(); + final long messageId = entry.getMessageId(); return (messageId >= fromMessageId) && (messageId <= toMessageId) && entry.acquire(); @@ -862,11 +847,9 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener // Move the messages in the transaction log. for (QueueEntry entry : entries) { - AMQMessage message = entry.getMessage(); - - if (message.isPersistent() && toQueue.isDurable()) + if (entry.isPersistent() && toQueue.isDurable()) { - transactionLog.enqueueMessage(storeContext, toQueue, message.getMessageId()); + transactionLog.enqueueMessage(storeContext, toQueue, entry.getMessageId()); } // dequeue will remove the messages from the queue entry.dequeue(storeContext); @@ -901,6 +884,9 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener for (QueueEntry entry : entries) { toQueue.enqueue(storeContext, entry.getMessage()); + // As we only did a dequeue above now that we have moved the message we should perform a delete. + // We cannot do this earlier as the message will be lost if flowed. + //entry.delete(); } } catch (MessageCleanupException e) @@ -927,7 +913,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener public boolean accept(QueueEntry entry) { - final long messageId = entry.getMessage().getMessageId(); + final long messageId = entry.getMessageId(); if ((messageId >= fromMessageId) && (messageId <= toMessageId)) { @@ -953,11 +939,9 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener // Move the messages in on the transaction log. for (QueueEntry entry : entries) { - AMQMessage message = entry.getMessage(); - - if (!entry.isDeleted() && message.isPersistent() && toQueue.isDurable()) + if (!entry.isDeleted() && entry.isPersistent() && toQueue.isDurable()) { - transactionLog.enqueueMessage(storeContext, toQueue, message.getMessageId()); + transactionLog.enqueueMessage(storeContext, toQueue, entry.getMessageId()); } } @@ -1016,7 +1000,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener { QueueEntry node = queueListIterator.getNode(); - final long messageId = node.getMessage().getMessageId(); + final long messageId = node.getMessageId(); if ((messageId >= fromMessageId) && (messageId <= toMessageId) @@ -1116,6 +1100,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener if (!_stopped.getAndSet(true)) { ReferenceCountingExecutorService.getInstance().releaseExecutorService(); + _entries.stop(); } } @@ -1451,12 +1436,33 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener } else { - _managedObject.checkForNotification(node.getMessage()); + _managedObject.checkForNotification(node); } } } + + public long getMemoryUsageMaximum() + { + return _entries.getMemoryUsageMaximum(); + } + + public void setMemoryUsageMaximum(long maximumMemoryUsage) + { + _entries.setMemoryUsageMaximum(maximumMemoryUsage); + } + + public long getMemoryUsageMinimum() + { + return _entries.getMemoryUsageMinimum(); + } + + public void setMemoryUsageMinimum(long minimumMemoryUsage) + { + _entries.setMemoryUsageMinimum(minimumMemoryUsage); + } + public long getMinimumAlertRepeatGap() { return _minimumAlertRepeatGap; @@ -1597,7 +1603,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener for (int i = 0; i < num && !it.atTail(); i++) { it.advance(); - ids.add(it.getNode().getMessage().getMessageId()); + ids.add(it.getNode().getMessageId()); } return ids; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java index a46c5ae2e8..a10e332ef5 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java @@ -22,8 +22,9 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; * under the License. * */ -public class SimpleQueueEntryList implements QueueEntryList +public class SimpleQueueEntryList extends FlowableBaseQueueEntryList { + private final QueueEntryImpl _head; private volatile QueueEntryImpl _tail; @@ -41,12 +42,9 @@ public class SimpleQueueEntryList implements QueueEntryList AtomicReferenceFieldUpdater.newUpdater (QueueEntryImpl.class, QueueEntryImpl.class, "_next"); - - - - public SimpleQueueEntryList(AMQQueue queue) { + super(queue); _queue = queue; _head = new QueueEntryImpl(this); _tail = _head; @@ -77,6 +75,9 @@ public class SimpleQueueEntryList implements QueueEntryList public QueueEntry add(AMQMessage message) { QueueEntryImpl node = new QueueEntryImpl(this, message); + + incrementCounters(node); + for (;;) { QueueEntryImpl tail = _tail; @@ -101,12 +102,12 @@ public class SimpleQueueEntryList implements QueueEntryList } } + public QueueEntry next(QueueEntry node) { return ((QueueEntryImpl)node).getNext(); } - public class QueueEntryIteratorImpl implements QueueEntryIterator { @@ -172,7 +173,9 @@ public class SimpleQueueEntryList implements QueueEntryList { return new SimpleQueueEntryList(queue); } + } - + + } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/TransientAMQMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/TransientAMQMessage.java index fa4e85a043..4c9fe81439 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/TransientAMQMessage.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/TransientAMQMessage.java @@ -44,8 +44,6 @@ public class TransientAMQMessage implements AMQMessage /** Used for debugging purposes. */ protected static final Logger _log = Logger.getLogger(AMQMessage.class); - private final AtomicInteger _referenceCount = new AtomicInteger(1); - protected ContentHeaderBody _contentHeaderBody; protected MessagePublishInfo _messagePublishInfo; @@ -56,23 +54,11 @@ public class TransientAMQMessage implements AMQMessage protected final Long _messageId; - /** Flag to indicate that this message requires 'immediate' delivery. */ - - private static final byte IMMEDIATE = 0x01; - - /** - * Flag to indicate whether this message has been delivered to a consumer. Used in implementing return functionality - * for messages published with the 'immediate' flag. - */ - - private static final byte DELIVERED_TO_CONSUMER = 0x02; private byte _flags = 0; - private long _expiration; - private AMQProtocolSession.ProtocolSessionIdentifier _sessionIdentifier; - private static final byte IMMEDIATE_AND_DELIVERED = (byte) (IMMEDIATE | DELIVERED_TO_CONSUMER); + private long _expiration; /** * Used to iterate through all the body frames associated with this message. Will not keep all the data in memory @@ -164,14 +150,19 @@ public class TransientAMQMessage implements AMQMessage public String debugIdentity() { - return "(HC:" + System.identityHashCode(this) + " ID:" + getMessageId() + " Ref:" + _referenceCount.get() + ")"; + return "(HC:" + System.identityHashCode(this) + " ID:" + getMessageId() +")"; } - public void setExpiration(final long expiration) + public void setExpiration(long expiration) { _expiration = expiration; } + public long getExpiration() + { + return _expiration; + } + public Iterator getBodyFrameIterator(AMQProtocolSession protocolSession, int channel) { return new BodyFrameIterator(protocolSession, channel); @@ -192,57 +183,6 @@ public class TransientAMQMessage implements AMQMessage return _messageId; } - /** - * Called selectors to determin if the message has already been sent - * - * @return _deliveredToConsumer - */ - public boolean getDeliveredToConsumer() - { - return (_flags & DELIVERED_TO_CONSUMER) != 0; - } - - /** - * Called to enforce the 'immediate' flag. - * - * @returns true if the message is marked for immediate delivery but has not been marked as delivered - * to a consumer - */ - public boolean immediateAndNotDelivered() - { - - return (_flags & IMMEDIATE_AND_DELIVERED) == IMMEDIATE; - - } - - /** - * Checks to see if the message has expired. If it has the message is dequeued. - * - * @return true if the message has expire - * - * @throws AMQException - */ - public boolean expired() throws AMQException - { - - if (_expiration != 0L) - { - long now = System.currentTimeMillis(); - - return (now > _expiration); - } - - return false; - } - - /** - * Called when this message is delivered to a consumer. (used to implement the 'immediate' flag functionality). - * And for selector efficiency. - */ - public void setDeliveredToConsumer() - { - _flags |= DELIVERED_TO_CONSUMER; - } public long getSize() { @@ -317,6 +257,11 @@ public class TransientAMQMessage implements AMQMessage return false; } + public boolean isImmediate() + { + return _messagePublishInfo.isImmediate(); + } + /** * This is called when all the content has been received. * @@ -339,33 +284,49 @@ public class TransientAMQMessage implements AMQMessage throw new NullPointerException("PublishInfo cannot be null"); } - _messagePublishInfo = messagePublishInfo; + _arrivalTime = System.currentTimeMillis(); + + _contentHeaderBody = contentHeaderBody; + _messagePublishInfo = messagePublishInfo; - if (contentHeaderBody.bodySize == 0) - { - _contentBodies = Collections.EMPTY_LIST; - } + updateHeaderAndFlags(); + } - _arrivalTime = System.currentTimeMillis(); + public long getArrivalTime() + { + return _arrivalTime; + } - if (messagePublishInfo.isImmediate()) + public void recoverFromMessageMetaData(MessageMetaData mmd) + { + _arrivalTime = mmd.getArrivalTime(); + _contentHeaderBody = mmd.getContentHeaderBody(); + _messagePublishInfo = mmd.getMessagePublishInfo(); + + updateHeaderAndFlags(); + } + + private void updateHeaderAndFlags() + { + if (_contentHeaderBody.bodySize == 0) { - _flags |= IMMEDIATE; + _contentBodies = Collections.EMPTY_LIST; } } - public long getArrivalTime() + public void recoverContentBodyFrame(ContentChunk contentChunk, boolean isLastContentBody) throws AMQException { - return _arrivalTime; + addContentBodyFrame(null, contentChunk, isLastContentBody); } + public String toString() { // return "Message[" + debugIdentity() + "]: " + _messageId + "; ref count: " + _referenceCount + "; taken : " + // _taken + " by :" + _takenBySubcription; - return "Message[" + debugIdentity() + "]: " + getMessageId() + "; ref count: " + _referenceCount; + return "Message[" + debugIdentity() + "]: " + getMessageId() ; } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/UnableToFlowMessageException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/UnableToFlowMessageException.java new file mode 100644 index 0000000000..03cfed8533 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/UnableToFlowMessageException.java @@ -0,0 +1,29 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +public class UnableToFlowMessageException extends Exception +{ + public UnableToFlowMessageException(long messageId, Exception error) + { + super("Unable to Flow Message:"+messageId, error); + } +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/UnableToRecoverMessageException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/UnableToRecoverMessageException.java new file mode 100644 index 0000000000..cae5bc6327 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/UnableToRecoverMessageException.java @@ -0,0 +1,29 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +public class UnableToRecoverMessageException extends RuntimeException +{ + public UnableToRecoverMessageException(Exception error) + { + super(error); + } +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java index 477beeadcb..22b4623ae1 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java @@ -24,6 +24,7 @@ import java.net.InetSocketAddress; import java.util.HashMap; import java.util.Map; +import org.apache.commons.configuration.ConfigurationException; import org.apache.log4j.Logger; import org.apache.mina.common.IoAcceptor; import org.apache.qpid.server.configuration.ServerConfiguration; @@ -261,7 +262,7 @@ public abstract class ApplicationRegistry implements IApplicationRegistry return _virtualHostRegistry; } - public ACLManager getAccessManager() + public ACLManager getAccessManager() throws ConfigurationException { return new ACLManager(_configuration.getSecurityConfiguration(), _pluginManager); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java index a1f30c6eed..bbfda3addc 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.net.InetSocketAddress; import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.management.ManagedObjectRegistry; import org.apache.qpid.server.plugins.PluginManager; @@ -64,7 +65,7 @@ public interface IApplicationRegistry VirtualHostRegistry getVirtualHostRegistry(); - ACLManager getAccessManager(); + ACLManager getAccessManager() throws ConfigurationException; PluginManager getPluginManager(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLManager.java index 57c6098874..6f7f66fad2 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLManager.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Map.Entry; import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.log4j.Logger; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.server.configuration.SecurityConfiguration; @@ -49,12 +50,12 @@ public class ACLManager private Map _globalPlugins = new HashMap(); private Map _hostPlugins = new HashMap(); - public ACLManager(SecurityConfiguration configuration, PluginManager manager) + public ACLManager(SecurityConfiguration configuration, PluginManager manager) throws ConfigurationException { this(configuration, manager, null); } - public ACLManager(SecurityConfiguration configuration, PluginManager manager, ACLPluginFactory securityPlugin) + public ACLManager(SecurityConfiguration configuration, PluginManager manager, ACLPluginFactory securityPlugin) throws ConfigurationException { _pluginManager = manager; @@ -73,12 +74,12 @@ public class ACLManager } - public void configureHostPlugins(SecurityConfiguration hostConfig) + public void configureHostPlugins(SecurityConfiguration hostConfig) throws ConfigurationException { _hostPlugins = configurePlugins(hostConfig); } - public Map configurePlugins(SecurityConfiguration hostConfig) + public Map configurePlugins(SecurityConfiguration hostConfig) throws ConfigurationException { Configuration securityConfig = hostConfig.getConfiguration(); Map plugins = new HashMap(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLPlugin.java index ca760f3360..032184ec39 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLPlugin.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLPlugin.java @@ -21,6 +21,7 @@ package org.apache.qpid.server.security.access; import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.protocol.AMQProtocolSession; @@ -36,7 +37,7 @@ public interface ACLPlugin ABSTAIN } - void setConfiguration(Configuration config); + void setConfiguration(Configuration config) throws ConfigurationException; // These return true if the plugin thinks the action should be allowed, and false if not. diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLPluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLPluginFactory.java index aee6af93d0..256f093477 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLPluginFactory.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ACLPluginFactory.java @@ -21,12 +21,13 @@ package org.apache.qpid.server.security.access; import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; public interface ACLPluginFactory { public boolean supportsTag(String name); - public ACLPlugin newInstance(Configuration config); + public ACLPlugin newInstance(Configuration config) throws ConfigurationException; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBean.java index f04aecd0a5..121f571abe 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBean.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBean.java @@ -64,9 +64,9 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana private static final Logger _logger = Logger.getLogger(AMQUserManagementMBean.class); private PrincipalDatabase _principalDatabase; - private String _accessFileName; private Properties _accessRights; - // private File _accessFile; + private File _accessFile; + private ReentrantLock _accessRightsUpdate = new ReentrantLock(); // Setup for the TabularType @@ -104,7 +104,7 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana public AMQUserManagementMBean() throws JMException { - super(UserManagement.class, UserManagement.TYPE); + super(UserManagement.class, UserManagement.TYPE, UserManagement.VERSION); } public String getObjectInstanceName() @@ -129,9 +129,10 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana public boolean setRights(String username, boolean read, boolean write, boolean admin) { - if (_accessRights.get(username) == null) + Object oldRights = null; + if ((oldRights =_accessRights.get(username)) == null) { - // If the user doesn't exist in the user rights file check that they at least have an account. + // If the user doesn't exist in the access rights file check that they at least have an account. if (_principalDatabase.getUser(username) == null) { return false; @@ -140,7 +141,6 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana try { - _accessRightsUpdate.lock(); // Update the access rights @@ -166,8 +166,29 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana _accessRights.remove(username); } } + + //save the rights file + try + { + saveAccessFile(); + } + catch (IOException e) + { + _logger.warn("Problem occured saving '" + _accessFile + "', the access right changes will not be preserved: " + e); - saveAccessFile(); + //the rights file was not successfully saved, restore user rights to previous value + _logger.warn("Reverting attempted rights update for user'" + username + "'"); + if (oldRights != null) + { + _accessRights.put(username, oldRights); + } + else + { + _accessRights.remove(username); + } + + return false; + } } finally { @@ -184,9 +205,23 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana { if (_principalDatabase.createPrincipal(new UsernamePrincipal(username), password)) { - _accessRights.put(username, ""); - - return setRights(username, read, write, admin); + if (!setRights(username, read, write, admin)) + { + //unable to set rights for user, remove account + try + { + _principalDatabase.deletePrincipal(new UsernamePrincipal(username)); + } + catch (AccountNotFoundException e) + { + //ignore + } + return false; + } + else + { + return true; + } } return false; @@ -194,7 +229,6 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana public boolean deleteUser(String username) { - try { if (_principalDatabase.deletePrincipal(new UsernamePrincipal(username))) @@ -204,7 +238,16 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana _accessRightsUpdate.lock(); _accessRights.remove(username); - saveAccessFile(); + + try + { + saveAccessFile(); + } + catch (IOException e) + { + _logger.warn("Problem occured saving '" + _accessFile + "', the access right changes will not be preserved: " + e); + return false; + } } finally { @@ -213,15 +256,15 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana _accessRightsUpdate.unlock(); } } - return true; } } catch (AccountNotFoundException e) { _logger.warn("Attempt to delete user (" + username + ") that doesn't exist"); + return false; } - return false; + return true; } public boolean reloadData() @@ -233,12 +276,12 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana } catch (ConfigurationException e) { - _logger.info("Reload failed due to:" + e); + _logger.warn("Reload failed due to:" + e); return false; } catch (IOException e) { - _logger.info("Reload failed due to:" + e); + _logger.warn("Reload failed due to:" + e); return false; } // Reload successful @@ -320,10 +363,24 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana */ public void setAccessFile(String accessFile) throws IOException, ConfigurationException { - _accessFileName = accessFile; - - if (_accessFileName != null) + if (accessFile != null) { + _accessFile = new File(accessFile); + if (!_accessFile.exists()) + { + throw new ConfigurationException("'" + _accessFile + "' does not exist"); + } + + if (!_accessFile.canRead()) + { + throw new ConfigurationException("Cannot read '" + _accessFile + "'."); + } + + if (!_accessFile.canWrite()) + { + _logger.warn("Unable to write to access rights file '" + _accessFile + "', changes will not be preserved."); + } + loadAccessFile(); } else @@ -334,39 +391,34 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana private void loadAccessFile() throws IOException, ConfigurationException { - try + if(_accessFile == null) { - _accessRightsUpdate.lock(); - - Properties accessRights = new Properties(); - - File accessFile = new File(_accessFileName); - - if (!accessFile.exists()) + _logger.error("No jmx access rights file has been specified."); + return; + } + + if(_accessFile.exists()) + { + try { - throw new ConfigurationException("'" + _accessFileName + "' does not exist"); - } + _accessRightsUpdate.lock(); - if (!accessFile.canRead()) - { - throw new ConfigurationException("Cannot read '" + _accessFileName + "'."); + Properties accessRights = new Properties(); + accessRights.load(new FileInputStream(_accessFile)); + checkAccessRights(accessRights); + setAccessRights(accessRights); } - - if (!accessFile.canWrite()) + finally { - _logger.warn("Unable to write to access file '" + _accessFileName + "' changes will not be preserved."); + if (_accessRightsUpdate.isHeldByCurrentThread()) + { + _accessRightsUpdate.unlock(); + } } - - accessRights.load(new FileInputStream(accessFile)); - checkAccessRights(accessRights); - setAccessRights(accessRights); } - finally + else { - if (_accessRightsUpdate.isHeldByCurrentThread()) - { - _accessRightsUpdate.unlock(); - } + _logger.error("Specified jmxaccess rights file '" + _accessFile + "' does not exist."); } } @@ -385,33 +437,24 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana } } - private void saveAccessFile() + private void saveAccessFile() throws IOException { try { _accessRightsUpdate.lock(); - try - { - // Create temporary file - File tmp = File.createTempFile(_accessFileName, ".tmp"); - // Rename current file - File rights = new File(_accessFileName); + // Create temporary file + File tmp = File.createTempFile(_accessFile.getName(), ".tmp"); - FileOutputStream output = new FileOutputStream(tmp); - _accessRights.store(output, "Generated by AMQUserManagementMBean Console : Last edited by user:" + getCurrentJMXUser()); - output.close(); + FileOutputStream output = new FileOutputStream(tmp); + _accessRights.store(output, "Generated by AMQUserManagementMBean Console : Last edited by user:" + getCurrentJMXUser()); + output.close(); - // Rename new file to main file - tmp.renameTo(rights); + // Rename new file to main file + tmp.renameTo(_accessFile); - // delete tmp - tmp.delete(); - } - catch (IOException e) - { - _logger.warn("Problem occured saving '" + _accessFileName + "' changes may not be preserved. :" + e); - } + // delete tmp + tmp.delete(); } finally { @@ -420,6 +463,7 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana _accessRightsUpdate.unlock(); } } + } private String getCurrentJMXUser() diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/UserManagement.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/UserManagement.java index 658d7ebbd3..9fcdd4cd17 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/UserManagement.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/UserManagement.java @@ -33,7 +33,9 @@ import java.io.IOException; public interface UserManagement { + String TYPE = "UserManagement"; + int VERSION = 2; //********** Operations *****************// /** @@ -115,4 +117,5 @@ public interface UserManagement impact = MBeanOperationInfo.INFO) TabularData viewUsers(); + } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/network/FirewallFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/network/FirewallFactory.java index 7fcf4a0494..a1a399e5bf 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/network/FirewallFactory.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/network/FirewallFactory.java @@ -21,6 +21,7 @@ package org.apache.qpid.server.security.access.plugins.network; import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.server.security.access.ACLPlugin; import org.apache.qpid.server.security.access.ACLPluginFactory; @@ -28,7 +29,7 @@ public class FirewallFactory implements ACLPluginFactory { @Override - public ACLPlugin newInstance(Configuration config) + public ACLPlugin newInstance(Configuration config) throws ConfigurationException { FirewallPlugin plugin = new FirewallPlugin(); plugin.setConfiguration(config); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/network/FirewallPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/network/FirewallPlugin.java index cb8b6f6fed..39397966f0 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/network/FirewallPlugin.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/network/FirewallPlugin.java @@ -23,12 +23,18 @@ package org.apache.qpid.server.security.access.plugins.network; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.util.Iterator; import java.util.List; import java.util.regex.Pattern; +import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.XMLConfiguration; import org.apache.qpid.server.protocol.AMQMinaProtocolSession; import org.apache.qpid.server.protocol.AMQProtocolSession; +import org.apache.qpid.server.security.access.ACLPlugin; +import org.apache.qpid.server.security.access.ACLPluginFactory; import org.apache.qpid.server.security.access.plugins.AbstractACLPlugin; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.util.NetMatcher; @@ -36,6 +42,21 @@ import org.apache.qpid.util.NetMatcher; public class FirewallPlugin extends AbstractACLPlugin { + public static final ACLPluginFactory FACTORY = new ACLPluginFactory() + { + public boolean supportsTag(String name) + { + return name.startsWith("firewall"); + } + + public ACLPlugin newInstance(Configuration config) throws ConfigurationException + { + FirewallPlugin plugin = new FirewallPlugin(); + plugin.setConfiguration(config); + return plugin; + } + }; + public class FirewallRule { @@ -149,7 +170,7 @@ public class FirewallPlugin extends AbstractACLPlugin } @Override - public void setConfiguration(Configuration config) + public void setConfiguration(Configuration config) throws ConfigurationException { // Get default action String defaultAction = config.getString("[@default-action]"); @@ -165,15 +186,21 @@ public class FirewallPlugin extends AbstractACLPlugin { _default = AuthzResult.DENIED; } + CompositeConfiguration finalConfig = new CompositeConfiguration(config); + + List subFiles = config.getList("firewall.xml[@fileName]"); + for (Object subFile : subFiles) + { + finalConfig.addConfiguration(new XMLConfiguration((String) subFile)); + } - int numRules = config.getList("rule[@access]").size(); // all rules must - // have an access - // attribute + // all rules must have an access attribute + int numRules = finalConfig.getList("rule[@access]").size(); _rules = new FirewallRule[numRules]; for (int i = 0; i < numRules; i++) { - FirewallRule rule = new FirewallRule(config.getString("rule(" + i + ")[@access]"), config.getList("rule(" - + i + ")[@network]"), config.getList("rule(" + i + ")[@hostname]")); + FirewallRule rule = new FirewallRule(finalConfig.getString("rule(" + i + ")[@access]"), finalConfig.getList("rule(" + + i + ")[@network]"), finalConfig.getList("rule(" + i + ")[@hostname]")); _rules[i] = rule; } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java index 69ad9014db..3c211746e3 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java @@ -152,8 +152,39 @@ public class Base64MD5PasswordFilePrincipalDatabase implements PrincipalDatabase public boolean verifyPassword(String principal, char[] password) throws AccountNotFoundException { char[] pwd = lookupPassword(principal); + + if (pwd == null) + { + throw new AccountNotFoundException("Unable to lookup the specfied users password"); + } + + byte[] byteArray = new byte[password.length]; + int index = 0; + for (char c : password) + { + byteArray[index++] = (byte) c; + } + + byte[] MD5byteArray; + try + { + MD5byteArray = HashedUser.getMD5(byteArray); + } + catch (Exception e1) + { + _logger.warn("Unable to hash password for user '" + principal + "' for comparison"); + return false; + } + + char[] hashedPassword = new char[MD5byteArray.length]; - return compareCharArray(pwd, password); + index = 0; + for (byte c : MD5byteArray) + { + hashedPassword[index++] = (char) c; + } + + return compareCharArray(pwd, hashedPassword); } private boolean compareCharArray(char[] a, char[] b) @@ -193,7 +224,7 @@ public class Base64MD5PasswordFilePrincipalDatabase implements PrincipalDatabase { _userUpdate.lock(); char[] orig = user.getPassword(); - user.setPassword(password); + user.setPassword(password,false); try { @@ -204,7 +235,7 @@ public class Base64MD5PasswordFilePrincipalDatabase implements PrincipalDatabase _logger.error("Unable to save password file, password change for user'" + principal + "' will revert at restart"); //revert the password change - user.setPassword(orig); + user.setPassword(orig,true); return false; } return true; @@ -230,7 +261,17 @@ public class Base64MD5PasswordFilePrincipalDatabase implements PrincipalDatabase return false; } - HashedUser user = new HashedUser(principal.getName(), password); + HashedUser user; + try + { + user = new HashedUser(principal.getName(), password); + } + catch (Exception e1) + { + _logger.warn("Unable to create new user '" + principal.getName() + "'"); + return false; + } + try { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/HashedUser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/HashedUser.java index 4d92e3fb4c..3690e7f92a 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/HashedUser.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/HashedUser.java @@ -25,6 +25,7 @@ import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.Principal; @@ -63,10 +64,22 @@ public class HashedUser implements Principal } } - public HashedUser(String name, char[] password) + public HashedUser(String name, char[] password) throws UnsupportedEncodingException, NoSuchAlgorithmException { _name = name; - setPassword(password); + setPassword(password,false); + } + + public static byte[] getMD5(byte[] data) throws NoSuchAlgorithmException, UnsupportedEncodingException + { + MessageDigest md = MessageDigest.getInstance("MD5"); + + for (byte b : data) + { + md.update(b); + } + + return md.digest(); } public String getName() @@ -84,9 +97,31 @@ public class HashedUser implements Principal return _password; } - void setPassword(char[] password) + void setPassword(char[] password, boolean alreadyHashed) throws UnsupportedEncodingException, NoSuchAlgorithmException { - _password = password; + if(alreadyHashed){ + _password = password; + } + else + { + byte[] byteArray = new byte[password.length]; + int index = 0; + for (char c : password) + { + byteArray[index++] = (byte) c; + } + + byte[] MD5byteArray = getMD5(byteArray); + + _password = new char[MD5byteArray.length]; + + index = 0; + for (byte c : MD5byteArray) + { + _password[index++] = (char) c; + } + } + _modified = true; _encodedPassword = null; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java index 9da954d74f..5e4678a63b 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java @@ -34,11 +34,13 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.io.PrintStream; import java.security.Principal; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; import java.util.regex.Pattern; /** @@ -50,13 +52,18 @@ import java.util.regex.Pattern; */ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase { + public static final String DEFAULT_ENCODING = "utf-8"; + private static final Logger _logger = Logger.getLogger(PlainPasswordFilePrincipalDatabase.class); - protected File _passwordFile; + private File _passwordFile; - protected Pattern _regexp = Pattern.compile(":"); + private Pattern _regexp = Pattern.compile(":"); - protected Map _saslServers; + private Map _saslServers; + + private Map _users = new HashMap(); + private ReentrantLock _userUpdate = new ReentrantLock(); public PlainPasswordFilePrincipalDatabase() { @@ -83,7 +90,7 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase _saslServers.put(cram.getMechanismName(), cram); } - public void setPasswordFile(String passwordFile) throws FileNotFoundException + public void setPasswordFile(String passwordFile) throws IOException { File f = new File(passwordFile); _logger.info("PlainPasswordFile using file " + f.getAbsolutePath()); @@ -97,10 +104,20 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase throw new FileNotFoundException("Cannot read password file " + f + ". Check permissions."); } + + loadPasswordFile(); } - public void setPassword(Principal principal, PasswordCallback callback) throws IOException, - AccountNotFoundException + /** + * SASL Callback Mechanism - sets the Password in the PasswordCallback based on the value in the PasswordFile + * If you want to change the password for a user, use updatePassword instead. + * + * @param principal The Principal to set the password for + * @param callback The PasswordCallback to call setPassword on + * + * @throws AccountNotFoundException If the Principal cannot be found in this Database + */ + public void setPassword(Principal principal, PasswordCallback callback) throws AccountNotFoundException { if (_passwordFile == null) { @@ -111,6 +128,7 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase throw new IllegalArgumentException("principal must not be null"); } char[] pwd = lookupPassword(principal.getName()); + if (pwd != null) { callback.setPassword(pwd); @@ -121,33 +139,151 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase } } + /** + * Used to verify that the presented Password is correct. Currently only used by Management Console + * + * @param principal The principal to authenticate + * @param password The plaintext password to check + * + * @return true if password is correct + * + * @throws AccountNotFoundException if the principal cannot be found + */ public boolean verifyPassword(String principal, char[] password) throws AccountNotFoundException { - try - { - char[] pwd = lookupPassword(principal); - return compareCharArray(pwd, password); - } - catch (IOException e) + char[] pwd = lookupPassword(principal); + + if (pwd == null) { - return false; + throw new AccountNotFoundException("Unable to lookup the specfied users password"); } + + return compareCharArray(pwd, password); + } + /** + * Changes the password for the specified user + * + * @param principal to change the password for + * @param password plaintext password to set the password too + */ public boolean updatePassword(Principal principal, char[] password) throws AccountNotFoundException { - return false; // updates denied + PlainUser user = _users.get(principal.getName()); + + if (user == null) + { + throw new AccountNotFoundException(principal.getName()); + } + + try + { + try + { + _userUpdate.lock(); + char[] orig = user.getPassword(); + user.setPassword(password); + + try + { + savePasswordFile(); + } + catch (IOException e) + { + _logger.error("Unable to save password file, password change for user '" + principal + "' discarded"); + //revert the password change + user.setPassword(orig); + return false; + } + return true; + } + finally + { + if (_userUpdate.isHeldByCurrentThread()) + { + _userUpdate.unlock(); + } + } + } + catch (Exception e) + { + return false; + } } public boolean createPrincipal(Principal principal, char[] password) { - return false; // updates denied + if (_users.get(principal.getName()) != null) + { + return false; + } + + PlainUser user = new PlainUser(principal.getName(), password); + + try + { + _userUpdate.lock(); + _users.put(user.getName(), user); + + try + { + savePasswordFile(); + return true; + } + catch (IOException e) + { + //remove the use on failure. + _users.remove(user.getName()); + _logger.warn("Unable to create user '" + user.getName()); + return false; + } + } + finally + { + if (_userUpdate.isHeldByCurrentThread()) + { + _userUpdate.unlock(); + } + } } public boolean deletePrincipal(Principal principal) throws AccountNotFoundException { - return false; // updates denied + PlainUser user = _users.get(principal.getName()); + + if (user == null) + { + throw new AccountNotFoundException(principal.getName()); + } + + try + { + _userUpdate.lock(); + user.delete(); + + try + { + savePasswordFile(); + } + catch (IOException e) + { + _logger.error("Unable to remove user '" + user.getName() + "' from password file."); + return false; + } + + _users.remove(user.getName()); + } + finally + { + if (_userUpdate.isHeldByCurrentThread()) + { + _userUpdate.unlock(); + } + } + + return true; } public Map getMechanisms() @@ -157,21 +293,14 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase public List getUsers() { - return new LinkedList(); //todo + return new LinkedList(_users.values()); } public Principal getUser(String username) { - try - { - if (lookupPassword(username) != null) - { - return new UsernamePrincipal(username); - } - } - catch (IOException e) + if (_users.containsKey(username)) { - //fall through to null return + return new UsernamePrincipal(username); } return null; } @@ -197,49 +326,166 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase * Looks up the password for a specified user in the password file. Note this code is not secure since it * creates strings of passwords. It should be modified to create only char arrays which get nulled out. * - * @param name the name of the principal to lookup - * - * @return char[] of the password + * @param name The principal name to lookup * - * @throws java.io.IOException whilst accessing the file + * @return a char[] for use in SASL. */ - private char[] lookupPassword(String name) throws IOException + private char[] lookupPassword(String name) + { + PlainUser user = _users.get(name); + if (user == null) + { + return null; + } + else + { + return user.getPassword(); + } + } + + private void loadPasswordFile() throws IOException + { + try + { + _userUpdate.lock(); + _users.clear(); + + BufferedReader reader = null; + try + { + reader = new BufferedReader(new FileReader(_passwordFile)); + String line; + + while ((line = reader.readLine()) != null) + { + String[] result = _regexp.split(line); + if (result == null || result.length < 2 || result[0].startsWith("#")) + { + continue; + } + + PlainUser user = new PlainUser(result); + _logger.info("Created user:" + user); + _users.put(user.getName(), user); + } + } + finally + { + if (reader != null) + { + reader.close(); + } + } + } + finally + { + if (_userUpdate.isHeldByCurrentThread()) + { + _userUpdate.unlock(); + } + } + } + + private void savePasswordFile() throws IOException { - BufferedReader reader = null; try { - reader = new BufferedReader(new FileReader(_passwordFile)); - String line; + _userUpdate.lock(); + + BufferedReader reader = null; + PrintStream writer = null; + File tmp = File.createTempFile(_passwordFile.getName(), ".tmp"); - while ((line = reader.readLine()) != null) + try { - if (!line.startsWith("#")) + writer = new PrintStream(tmp); + reader = new BufferedReader(new FileReader(_passwordFile)); + String line; + + while ((line = reader.readLine()) != null) { String[] result = _regexp.split(line); - if (result == null || result.length < 2) + if (result == null || result.length < 2 || result[0].startsWith("#")) { + writer.write(line.getBytes(DEFAULT_ENCODING)); + writer.println(); continue; } - if (name.equals(result[0])) + PlainUser user = _users.get(result[0]); + + if (user == null) { - return result[1].toCharArray(); + writer.write(line.getBytes(DEFAULT_ENCODING)); + writer.println(); + } + else if (!user.isDeleted()) + { + if (!user.isModified()) + { + writer.write(line.getBytes(DEFAULT_ENCODING)); + writer.println(); + } + else + { + byte[] password = user.getPasswordBytes(); + + writer.write((user.getName() + ":").getBytes(DEFAULT_ENCODING)); + writer.write(password); + writer.println(); + + user.saved(); + } + } + } + + for (PlainUser user : _users.values()) + { + if (user.isModified()) + { + byte[] password; + password = user.getPasswordBytes(); + writer.write((user.getName() + ":").getBytes(DEFAULT_ENCODING)); + writer.write(password); + writer.println(); + user.saved(); } } } - return null; + finally + { + if (reader != null) + { + reader.close(); + } + + if (writer != null) + { + writer.close(); + } + + // Swap temp file to main password file. + File old = new File(_passwordFile.getAbsoluteFile() + ".old"); + if (old.exists()) + { + old.delete(); + } + _passwordFile.renameTo(old); + tmp.renameTo(_passwordFile); + tmp.delete(); + } } finally { - if (reader != null) + if (_userUpdate.isHeldByCurrentThread()) { - reader.close(); + _userUpdate.unlock(); } } } - + public void reload() throws IOException { - //This PD is not cached, so do nothing. + loadPasswordFile(); } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainUser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainUser.java new file mode 100644 index 0000000000..46a78a55aa --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainUser.java @@ -0,0 +1,106 @@ +/* +* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.security.auth.database; + +import org.apache.log4j.Logger; + +import java.security.Principal; + +public class PlainUser implements Principal +{ + private String _name; + private char[] _password; + private boolean _modified = false; + private boolean _deleted = false; + + PlainUser(String[] data) + { + if (data.length != 2) + { + throw new IllegalArgumentException("User Data should be length 2, username, password"); + } + + _name = data[0]; + + _password = data[1].toCharArray(); + + } + + public PlainUser(String name, char[] password) + { + _name = name; + _password = password; + _modified = true; + } + + public String getName() + { + return _name; + } + + public String toString() + { + return _name; + } + + char[] getPassword() + { + return _password; + } + + byte[] getPasswordBytes() + { + byte[] byteArray = new byte[_password.length]; + int index = 0; + for (char c : _password) + { + byteArray[index++] = (byte) c; + } + return byteArray; + } + + void setPassword(char[] password) + { + _password = password; + _modified = true; + } + + public boolean isModified() + { + return _modified; + } + + public boolean isDeleted() + { + return _deleted; + } + + public void delete() + { + _deleted = true; + } + + public void saved() + { + _modified = false; + } + +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java index 378b17e733..77040e896c 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java @@ -20,23 +20,14 @@ */ package org.apache.qpid.server.security.auth.rmi; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; import java.util.Collections; import javax.management.remote.JMXAuthenticator; import javax.management.remote.JMXPrincipal; import javax.security.auth.Subject; -import javax.security.auth.callback.PasswordCallback; import javax.security.auth.login.AccountNotFoundException; -import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase; -import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; import org.apache.qpid.server.security.auth.database.PrincipalDatabase; -import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal; public class RMIPasswordAuthenticator implements JMXAuthenticator { @@ -48,7 +39,6 @@ public class RMIPasswordAuthenticator implements JMXAuthenticator static final String CREDENTIALS_REQUIRED = "User details are required. " + "Please ensure you are using an up to date management console to connect."; - public static final String DEFAULT_ENCODING = "utf-8"; private PrincipalDatabase _db = null; public RMIPasswordAuthenticator() @@ -91,56 +81,26 @@ public class RMIPasswordAuthenticator implements JMXAuthenticator throw new SecurityException(SHOULD_BE_NON_NULL); } + // Verify that a PD has been set. + if (_db == null) + { + throw new SecurityException(UNABLE_TO_LOOKUP); + } + boolean authenticated = false; // Perform authentication try { - PasswordCallback pwCallback = new PasswordCallback("prompt",false); - UsernamePrincipal uname = new UsernamePrincipal(username); - - if (_db instanceof Base64MD5PasswordFilePrincipalDatabase) - { - //retrieve the stored password for the given user - _db.setPassword(uname, pwCallback); - - //compare the MD5Hash of the given password with the stored value - if (Arrays.equals(getMD5Hash(password), pwCallback.getPassword())) - { - authenticated = true; - } - } - else if (_db instanceof PlainPasswordFilePrincipalDatabase) - { - //retrieve the users stored password and compare with given value - _db.setPassword(uname, pwCallback); - - if (password.equals(new String(pwCallback.getPassword()))) - { - authenticated = true; - } - } - else - { - throw new SecurityException(UNABLE_TO_LOOKUP); + if (_db.verifyPassword(username, password.toCharArray())) + { + authenticated = true; } } catch (AccountNotFoundException e) { throw new SecurityException(INVALID_CREDENTIALS); } - catch (UnsupportedEncodingException e) - { - throw new SecurityException(UNABLE_TO_LOOKUP); - } - catch (NoSuchAlgorithmException e) - { - throw new SecurityException(UNABLE_TO_LOOKUP); - } - catch (IOException e) - { - throw new SecurityException(UNABLE_TO_LOOKUP); - } if (authenticated) { @@ -155,28 +115,5 @@ public class RMIPasswordAuthenticator implements JMXAuthenticator throw new SecurityException(INVALID_CREDENTIALS); } } - - public static char[] getMD5Hash(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException - { - byte[] data = text.getBytes(DEFAULT_ENCODING); - MessageDigest md = MessageDigest.getInstance("MD5"); - - for (byte b : data) - { - md.update(b); - } - - byte[] digest = md.digest(); - - char[] hash = new char[digest.length ]; - - int index = 0; - for (byte b : digest) - { - hash[index++] = (char) b; - } - - return hash; - } } \ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionImpl.java index 119a4b1692..bc1f56fee1 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionImpl.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionImpl.java @@ -387,6 +387,7 @@ public abstract class SubscriptionImpl implements Subscription, FlowCreditManage //todo - client id should be recoreded and this test removed but handled below if (_noLocal) { + //todo getPublisherClientInstance should be moved to QueueEntryImpl final Object publisherId = entry.getMessage().getPublisherClientInstance(); // We don't want local messages so check to see if message is one we sent @@ -407,6 +408,7 @@ public abstract class SubscriptionImpl implements Subscription, FlowCreditManage //todo - client id should be recoreded and this test removed but handled here + //todo getPublisherIdentifier should be moved to QueueEntryImpl if (localInstance != null && localInstance.equals(entry.getMessage().getPublisherIdentifier())) { return false; @@ -498,9 +500,9 @@ public abstract class SubscriptionImpl implements Subscription, FlowCreditManage } - public boolean wouldSuspend(QueueEntry msg) + public boolean wouldSuspend(QueueEntry queueEntry) { - return !_creditManager.useCreditForMessage(msg.getMessage());//_channel.wouldSuspend(msg.getMessage()); + return !_creditManager.useCreditForMessage(queueEntry); } public void getSendLock() diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/NonTransactionalContext.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/NonTransactionalContext.java index 0ca8135f71..2f27e1405a 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/NonTransactionalContext.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/NonTransactionalContext.java @@ -127,9 +127,9 @@ public class NonTransactionalContext implements TransactionalContext { if (debug) { - _log.debug("Discarding message: " + queueEntry.getMessage().getMessageId()); + _log.debug("Discarding message: " + queueEntry.getMessageId()); } - if(queueEntry.getMessage().isPersistent()) + if(queueEntry.isPersistent()) { beginTranIfNecessary(); } @@ -175,9 +175,9 @@ public class NonTransactionalContext implements TransactionalContext if (debug) { - _log.debug("Discarding message: " + queueEntry.getMessage().getMessageId()); + _log.debug("Discarding message: " + queueEntry.getMessageId()); } - if(queueEntry.getMessage().isPersistent()) + if(queueEntry.isPersistent()) { beginTranIfNecessary(); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ManagedVirtualHost.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ManagedVirtualHost.java index 85d804457e..f4c81fbbb8 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ManagedVirtualHost.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ManagedVirtualHost.java @@ -31,6 +31,7 @@ import org.apache.qpid.server.management.MBeanAttribute; public interface ManagedVirtualHost { static final String TYPE = "VirtualHost"; + static final int VERSION = 1; /** * Returns the name of the managed virtualHost. diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java index e1b770b1d3..5d2a31b80d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java @@ -48,6 +48,9 @@ import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.AMQQueueFactory; import org.apache.qpid.server.queue.DefaultQueueRegistry; import org.apache.qpid.server.queue.QueueRegistry; +import org.apache.qpid.server.queue.QueueBackingStore; +import org.apache.qpid.server.queue.FileQueueBackingStoreFactory; +import org.apache.qpid.server.queue.QueueBackingStoreFactory; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.routing.RoutingTable; import org.apache.qpid.server.security.access.ACLManager; @@ -84,7 +87,10 @@ public class VirtualHost implements Accessable private ACLManager _accessManager; private final Timer _houseKeepingTimer; - + + private VirtualHostConfiguration _configuration; + private QueueBackingStoreFactory _queueBackingStoreFactory; + public void setAccessableName(String name) { _logger.warn("Setting Accessable Name for VirualHost is not allowed. (" @@ -106,6 +112,16 @@ public class VirtualHost implements Accessable return _routingTable; } + public VirtualHostConfiguration getConfiguration() + { + return _configuration ; + } + + public QueueBackingStoreFactory getQueueBackingStoreFactory() + { + return _queueBackingStoreFactory; + } + /** * Abstract MBean class. This has some of the methods implemented from management intrerface for exchanges. Any * implementaion of an Exchange MBean should extend this class. @@ -114,7 +130,7 @@ public class VirtualHost implements Accessable { public VirtualHostMBean() throws NotCompliantMBeanException { - super(ManagedVirtualHost.class, "VirtualHost"); + super(ManagedVirtualHost.class, ManagedVirtualHost.TYPE, ManagedVirtualHost.VERSION); } public String getObjectInstanceName() @@ -137,7 +153,6 @@ public class VirtualHost implements Accessable /** * Normal Constructor - * @param name * @param hostConfig * @throws Exception */ @@ -148,6 +163,7 @@ public class VirtualHost implements Accessable public VirtualHost(VirtualHostConfiguration hostConfig, TransactionLog transactionLog) throws Exception { + _configuration = hostConfig; _name = hostConfig.getName(); if (_name == null || _name.length() == 0) @@ -179,6 +195,9 @@ public class VirtualHost implements Accessable initialiseRoutingTable(hostConfig); } + _queueBackingStoreFactory = new FileQueueBackingStoreFactory(); + _queueBackingStoreFactory.configure(this, hostConfig); + _exchangeFactory.initialise(hostConfig); _exchangeRegistry.initialise(); @@ -403,6 +422,12 @@ public class VirtualHost implements Accessable //Stop Connections _connectionRegistry.close(); + //Stop Housekeeping + if (_houseKeepingTimer != null) + { + _houseKeepingTimer.cancel(); + } + //Stop the Queues processing if (_queueRegistry != null) { @@ -410,13 +435,7 @@ public class VirtualHost implements Accessable { queue.stop(); } - } - - //Stop Housekeeping - if (_houseKeepingTimer != null) - { - _houseKeepingTimer.cancel(); - } + } //Close TransactionLog if (_transactionLog != null) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Move.java b/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Move.java index a8dd58ca83..7fe16062fc 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Move.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Move.java @@ -172,7 +172,7 @@ public class Move extends AbstractCommand { for (QueueEntry msg : messages) { - ids.add(msg.getMessage().getMessageId()); + ids.add(msg.getMessageId()); } } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Show.java b/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Show.java index d46ba85069..49afcb1340 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Show.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Show.java @@ -352,7 +352,7 @@ public class Show extends AbstractCommand isredelivered.add(entry.isRedelivered() ? "true" : "false"); - isdelivered.add(msg.getDeliveredToConsumer() ? "true" : "false"); + isdelivered.add(entry.getDeliveredToConsumer() ? "true" : "false"); BasicContentHeaderProperties headers = null; diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/ExtractResendAndRequeueTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/ExtractResendAndRequeueTest.java index 2a97db6066..3ab127b59d 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/ExtractResendAndRequeueTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/ExtractResendAndRequeueTest.java @@ -87,7 +87,7 @@ public class ExtractResendAndRequeueTest extends TestCase while(queueEntries.advance()) { QueueEntry entry = queueEntries.getNode(); - _unacknowledgedMessageMap.add(entry.getMessage().getMessageId(), entry); + _unacknowledgedMessageMap.add(entry.getMessageId(), entry); // Store the entry for future inspection _referenceList.add(entry); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java index 4a69c94ee1..ad1df1c777 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java @@ -23,12 +23,24 @@ package org.apache.qpid.server.configuration; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.RandomAccessFile; import java.util.List; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.SystemConfiguration; import org.apache.commons.configuration.XMLConfiguration; +import org.apache.qpid.AMQException; +import org.apache.qpid.codec.AMQCodecFactory; +import org.apache.qpid.server.protocol.AMQMinaProtocolSession; +import org.apache.qpid.server.protocol.AMQProtocolSession; +import org.apache.qpid.server.protocol.TestIoSession; +import org.apache.qpid.server.queue.MockProtocolSession; +import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; +import org.apache.qpid.server.security.access.ACLManager; +import org.apache.qpid.server.virtualhost.VirtualHost; +import org.apache.qpid.server.virtualhost.VirtualHostRegistry; import junit.framework.TestCase; @@ -43,6 +55,12 @@ public class ServerConfigurationTest extends TestCase _config = new XMLConfiguration(); } + @Override + public void tearDown() + { + ApplicationRegistry.removeAll(); + } + public void testSetJMXManagementPort() throws ConfigurationException { ServerConfiguration serverConfig = new ServerConfiguration(_config); @@ -63,7 +81,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getPlatformMbeanserver()); - // Check value we set + // Check value we set _config.setProperty("management.platform-mbeanserver", false); serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getPlatformMbeanserver()); @@ -75,7 +93,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(null, serverConfig.getPluginDirectory()); - // Check value we set + // Check value we set _config.setProperty("plugin-directory", "/path/to/plugins"); serverConfig = new ServerConfiguration(_config); assertEquals("/path/to/plugins", serverConfig.getPluginDirectory()); @@ -87,7 +105,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(0, serverConfig.getPrincipalDatabaseNames().size()); - // Check value we set + // Check value we set _config.setProperty("security.principal-databases.principal-database(0).name", "a"); _config.setProperty("security.principal-databases.principal-database(1).name", "b"); serverConfig = new ServerConfiguration(_config); @@ -96,14 +114,14 @@ public class ServerConfigurationTest extends TestCase assertEquals("a", dbs.get(0)); assertEquals("b", dbs.get(1)); } - + public void testGetPrincipalDatabaseClass() throws ConfigurationException { // Check default ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(0, serverConfig.getPrincipalDatabaseClass().size()); - // Check value we set + // Check value we set _config.setProperty("security.principal-databases.principal-database(0).class", "a"); _config.setProperty("security.principal-databases.principal-database(1).class", "b"); serverConfig = new ServerConfiguration(_config); @@ -119,7 +137,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(0, serverConfig.getPrincipalDatabaseAttributeNames(1).size()); - // Check value we set + // Check value we set _config.setProperty("security.principal-databases.principal-database(0).attributes(0).attribute.name", "a"); _config.setProperty("security.principal-databases.principal-database(0).attributes(1).attribute.name", "b"); serverConfig = new ServerConfiguration(_config); @@ -129,14 +147,13 @@ public class ServerConfigurationTest extends TestCase assertEquals("b", dbs.get(1)); } - public void testGetPrincipalDatabaseAttributeValues() throws ConfigurationException { // Check default ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(0, serverConfig.getPrincipalDatabaseAttributeValues(1).size()); - // Check value we set + // Check value we set _config.setProperty("security.principal-databases.principal-database(0).attributes(0).attribute.value", "a"); _config.setProperty("security.principal-databases.principal-database(0).attributes(1).attribute.value", "b"); serverConfig = new ServerConfiguration(_config); @@ -152,7 +169,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(0, serverConfig.getManagementAccessList().size()); - // Check value we set + // Check value we set _config.setProperty("security.jmx.access(0)", "a"); _config.setProperty("security.jmx.access(1)", "b"); serverConfig = new ServerConfiguration(_config); @@ -168,31 +185,19 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(65536, serverConfig.getFrameSize()); - // Check value we set + // Check value we set _config.setProperty("advanced.framesize", "23"); serverConfig = new ServerConfiguration(_config); assertEquals(23, serverConfig.getFrameSize()); } - public void testGetManagementSecurityEnabled() throws ConfigurationException - { - // Check default - ServerConfiguration serverConfig = new ServerConfiguration(_config); - assertEquals(false, serverConfig.getManagementSecurityEnabled()); - - // Check value we set - _config.setProperty("management.security-enabled", true); - serverConfig = new ServerConfiguration(_config); - assertEquals(true, serverConfig.getManagementSecurityEnabled()); - } - public void testGetProtectIOEnabled() throws ConfigurationException { // Check default ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getProtectIOEnabled()); - // Check value we set + // Check value we set _config.setProperty("broker.connector.protectio.enabled", true); serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getProtectIOEnabled()); @@ -204,7 +209,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(262144, serverConfig.getBufferReadLimit()); - // Check value we set + // Check value we set _config.setProperty("broker.connector.protectio.readBufferLimitSize", 23); serverConfig = new ServerConfiguration(_config); assertEquals(23, serverConfig.getBufferReadLimit()); @@ -216,7 +221,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(262144, serverConfig.getBufferWriteLimit()); - // Check value we set + // Check value we set _config.setProperty("broker.connector.protectio.writeBufferLimitSize", 23); serverConfig = new ServerConfiguration(_config); assertEquals(23, serverConfig.getBufferWriteLimit()); @@ -228,7 +233,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getSynchedClocks()); - // Check value we set + // Check value we set _config.setProperty("advanced.synced-clocks", true); serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getSynchedClocks()); @@ -240,7 +245,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getMsgAuth()); - // Check value we set + // Check value we set _config.setProperty("security.msg-auth", true); serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getMsgAuth()); @@ -252,7 +257,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(null, serverConfig.getJMXPrincipalDatabase()); - // Check value we set + // Check value we set _config.setProperty("security.jmx.principal-database", "a"); serverConfig = new ServerConfiguration(_config); assertEquals("a", serverConfig.getJMXPrincipalDatabase()); @@ -264,7 +269,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(null, serverConfig.getManagementKeyStorePath()); - // Check value we set + // Check value we set _config.setProperty("management.ssl.keyStorePath", "a"); serverConfig = new ServerConfiguration(_config); assertEquals("a", serverConfig.getManagementKeyStorePath()); @@ -276,7 +281,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getManagementSSLEnabled()); - // Check value we set + // Check value we set _config.setProperty("management.ssl.enabled", false); serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getManagementSSLEnabled()); @@ -288,7 +293,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(null, serverConfig.getManagementKeyStorePassword()); - // Check value we set + // Check value we set _config.setProperty("management.ssl.keyStorePassword", "a"); serverConfig = new ServerConfiguration(_config); assertEquals("a", serverConfig.getManagementKeyStorePassword()); @@ -300,7 +305,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getQueueAutoRegister()); - // Check value we set + // Check value we set _config.setProperty("queue.auto_register", false); serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getQueueAutoRegister()); @@ -312,7 +317,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getManagementEnabled()); - // Check value we set + // Check value we set _config.setProperty("management.enabled", false); serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getManagementEnabled()); @@ -320,7 +325,7 @@ public class ServerConfigurationTest extends TestCase public void testSetManagementEnabled() throws ConfigurationException { - // Check value we set + // Check value we set ServerConfiguration serverConfig = new ServerConfiguration(_config); serverConfig.setManagementEnabled(false); assertEquals(false, serverConfig.getManagementEnabled()); @@ -332,7 +337,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(5, serverConfig.getHeartBeatDelay()); - // Check value we set + // Check value we set _config.setProperty("heartbeat.delay", 23); serverConfig = new ServerConfiguration(_config); assertEquals(23, serverConfig.getHeartBeatDelay()); @@ -344,7 +349,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(2.0, serverConfig.getHeartBeatTimeout()); - // Check value we set + // Check value we set _config.setProperty("heartbeat.timeoutFactor", 2.3); serverConfig = new ServerConfiguration(_config); assertEquals(2.3, serverConfig.getHeartBeatTimeout()); @@ -356,7 +361,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(0, serverConfig.getMaximumMessageAge()); - // Check value we set + // Check value we set _config.setProperty("maximumMessageAge", 10L); serverConfig = new ServerConfiguration(_config); assertEquals(10, serverConfig.getMaximumMessageAge()); @@ -368,7 +373,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(0, serverConfig.getMaximumMessageCount()); - // Check value we set + // Check value we set _config.setProperty("maximumMessageCount", 10L); serverConfig = new ServerConfiguration(_config); assertEquals(10, serverConfig.getMaximumMessageCount()); @@ -380,7 +385,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(0, serverConfig.getMaximumQueueDepth()); - // Check value we set + // Check value we set _config.setProperty("maximumQueueDepth", 10L); serverConfig = new ServerConfiguration(_config); assertEquals(10, serverConfig.getMaximumQueueDepth()); @@ -392,7 +397,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(0, serverConfig.getMaximumMessageSize()); - // Check value we set + // Check value we set _config.setProperty("maximumMessageSize", 10L); serverConfig = new ServerConfiguration(_config); assertEquals(10, serverConfig.getMaximumMessageSize()); @@ -404,7 +409,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(0, serverConfig.getMinimumAlertRepeatGap()); - // Check value we set + // Check value we set _config.setProperty("minimumAlertRepeatGap", 10L); serverConfig = new ServerConfiguration(_config); assertEquals(10, serverConfig.getMinimumAlertRepeatGap()); @@ -416,7 +421,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(4, serverConfig.getProcessors()); - // Check value we set + // Check value we set _config.setProperty("connector.processors", 10); serverConfig = new ServerConfiguration(_config); assertEquals(10, serverConfig.getProcessors()); @@ -428,7 +433,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(5672, serverConfig.getPort()); - // Check value we set + // Check value we set _config.setProperty("connector.port", 10); serverConfig = new ServerConfiguration(_config); assertEquals(10, serverConfig.getPort()); @@ -440,7 +445,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals("wildcard", serverConfig.getBind()); - // Check value we set + // Check value we set _config.setProperty("connector.bind", "a"); serverConfig = new ServerConfiguration(_config); assertEquals("a", serverConfig.getBind()); @@ -452,7 +457,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(32767, serverConfig.getReceiveBufferSize()); - // Check value we set + // Check value we set _config.setProperty("connector.socketReceiveBuffer", "23"); serverConfig = new ServerConfiguration(_config); assertEquals(23, serverConfig.getReceiveBufferSize()); @@ -464,7 +469,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(32767, serverConfig.getWriteBufferSize()); - // Check value we set + // Check value we set _config.setProperty("connector.socketWriteBuffer", "23"); serverConfig = new ServerConfiguration(_config); assertEquals(23, serverConfig.getWriteBufferSize()); @@ -476,7 +481,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getTcpNoDelay()); - // Check value we set + // Check value we set _config.setProperty("connector.tcpNoDelay", false); serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getTcpNoDelay()); @@ -488,7 +493,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getEnableExecutorPool()); - // Check value we set + // Check value we set _config.setProperty("advanced.filterchain[@enableExecutorPool]", true); serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getEnableExecutorPool()); @@ -500,7 +505,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getEnablePooledAllocator()); - // Check value we set + // Check value we set _config.setProperty("advanced.enablePooledAllocator", true); serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getEnablePooledAllocator()); @@ -512,7 +517,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getEnableDirectBuffers()); - // Check value we set + // Check value we set _config.setProperty("advanced.enableDirectBuffers", true); serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getEnableDirectBuffers()); @@ -524,7 +529,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getEnableSSL()); - // Check value we set + // Check value we set _config.setProperty("connector.ssl.enabled", true); serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getEnableSSL()); @@ -536,19 +541,19 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getSSLOnly()); - // Check value we set + // Check value we set _config.setProperty("connector.ssl.sslOnly", false); serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getSSLOnly()); } - + public void testGetSSLPort() throws ConfigurationException { // Check default ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(8672, serverConfig.getSSLPort()); - // Check value we set + // Check value we set _config.setProperty("connector.ssl.port", 23); serverConfig = new ServerConfiguration(_config); assertEquals(23, serverConfig.getSSLPort()); @@ -560,19 +565,19 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals("none", serverConfig.getKeystorePath()); - // Check value we set + // Check value we set _config.setProperty("connector.ssl.keystorePath", "a"); serverConfig = new ServerConfiguration(_config); assertEquals("a", serverConfig.getKeystorePath()); } - + public void testGetKeystorePassword() throws ConfigurationException { // Check default ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals("none", serverConfig.getKeystorePassword()); - // Check value we set + // Check value we set _config.setProperty("connector.ssl.keystorePassword", "a"); serverConfig = new ServerConfiguration(_config); assertEquals("a", serverConfig.getKeystorePassword()); @@ -584,7 +589,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals("SunX509", serverConfig.getCertType()); - // Check value we set + // Check value we set _config.setProperty("connector.ssl.certType", "a"); serverConfig = new ServerConfiguration(_config); assertEquals("a", serverConfig.getCertType()); @@ -596,7 +601,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getQpidNIO()); - // Check value we set + // Check value we set _config.setProperty("connector.qpidnio", true); serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getQpidNIO()); @@ -608,7 +613,7 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration serverConfig = new ServerConfiguration(_config); assertEquals(false, serverConfig.getUseBiasedWrites()); - // Check value we set + // Check value we set _config.setProperty("advanced.useWriteBiasedPool", true); serverConfig = new ServerConfiguration(_config); assertEquals(true, serverConfig.getUseBiasedWrites()); @@ -618,17 +623,17 @@ public class ServerConfigurationTest extends TestCase { // Check default ServerConfiguration serverConfig = new ServerConfiguration(_config); - assertEquals(30000, serverConfig.getHousekeepingExpiredMessageCheckPeriod()); + assertEquals(30000, serverConfig.getHousekeepingCheckPeriod()); - // Check value we set + // Check value we set _config.setProperty("housekeeping.expiredMessageCheckPeriod", 23L); serverConfig = new ServerConfiguration(_config); - assertEquals(23, serverConfig.getHousekeepingExpiredMessageCheckPeriod()); + assertEquals(23, serverConfig.getHousekeepingCheckPeriod()); serverConfig.setHousekeepingExpiredMessageCheckPeriod(42L); - assertEquals(42, serverConfig.getHousekeepingExpiredMessageCheckPeriod()); + assertEquals(42, serverConfig.getHousekeepingCheckPeriod()); } - public void testSingleConfiguration() throws IOException, ConfigurationException + public void testSingleConfiguration() throws IOException, ConfigurationException { File fileA = File.createTempFile(getClass().getName(), null); fileA.deleteOnExit(); @@ -638,36 +643,207 @@ public class ServerConfigurationTest extends TestCase ServerConfiguration conf = new ServerConfiguration(fileA); assertEquals(4235, conf.getSSLPort()); } - + public void testCombinedConfiguration() throws IOException, ConfigurationException { File mainFile = File.createTempFile(getClass().getName(), null); File fileA = File.createTempFile(getClass().getName(), null); File fileB = File.createTempFile(getClass().getName(), null); - + mainFile.deleteOnExit(); fileA.deleteOnExit(); fileB.deleteOnExit(); - + FileWriter out = new FileWriter(mainFile); out.write(""); - out.write(""); - out.write(""); + out.write(""); + out.write(""); out.write(""); out.close(); - + out = new FileWriter(fileA); out.write("23424235"); out.close(); - + out = new FileWriter(fileB); out.write("2345true"); out.close(); - + ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile()); - assertEquals(4235, config.getSSLPort()); // From first file, not overriden by second - assertEquals(2342, config.getPort()); // From the first file, not present in the second - assertEquals(true, config.getQpidNIO()); // From the second file, not present in the first + assertEquals(4235, config.getSSLPort()); // From first file, not + // overriden by second + assertEquals(2342, config.getPort()); // From the first file, not + // present in the second + assertEquals(true, config.getQpidNIO()); // From the second file, not + // present in the first } - + + public void testCombinedConfigurationFirewall() throws Exception + { + // Write out config + File mainFile = File.createTempFile(getClass().getName(), null); + File fileA = File.createTempFile(getClass().getName(), null); + File fileB = File.createTempFile(getClass().getName(), null); + + mainFile.deleteOnExit(); + fileA.deleteOnExit(); + fileB.deleteOnExit(); + + FileWriter out = new FileWriter(mainFile); + out.write(""); + out.write(""); + out.write(""); + out.close(); + + out = new FileWriter(fileA); + out.write("\n"); + out.write("\tfalse\n"); + out.write("\t\n"); + out.write("\t\t\n"); + out.write("\t\t\t\n"); + out.write("\t\t\t\tpasswordfile\n"); + out.write("\t\t\t\torg.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase\n"); + out.write("\t\t\t\t\n"); + out.write("\t\t\t\t\t\n"); + out.write("\t\t\t\t\t\tpasswordFile\n"); + out.write("\t\t\t\t\t\t/dev/null\n"); + out.write("\t\t\t\t\t\n"); + out.write("\t\t\t\t\n"); + out.write("\t\t\t\n"); + out.write("\t\t\n"); + out.write("\t\t\n"); + out.write("\t\t\t/dev/null\n"); + out.write("\t\t\tpasswordfile\n"); + out.write("\t\t\n"); + out.write("\t\t\n"); + out.write("\t\t\t"); + out.write("\t\t\n"); + out.write("\t\n"); + out.write("\t\n"); + out.write("\t\t\n"); + out.write("\t\t\ttest\n"); + out.write("\t\t\n"); + out.write("\t\n"); + out.write("\n"); + out.close(); + + out = new FileWriter(fileB); + out.write("\n"); + out.write("\t"); + out.write("\n"); + out.close(); + + // Load config + ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); + ApplicationRegistry.initialise(reg, 1); + + // Test config + TestIoSession iosession = new TestIoSession(); + iosession.setAddress("127.0.0.1"); + VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry(); + VirtualHost virtualHost = virtualHostRegistry.getVirtualHost("test"); + AMQCodecFactory codecFactory = new AMQCodecFactory(true); + AMQProtocolSession session = new AMQMinaProtocolSession(iosession, virtualHostRegistry, codecFactory); + assertFalse(reg.getAccessManager().authoriseConnect(session, virtualHost)); + } + + public void testCombinedConfigurationFirewallReload() throws Exception + { + // Write out config + File mainFile = File.createTempFile(getClass().getName(), null); + File fileA = File.createTempFile(getClass().getName(), null); + File fileB = File.createTempFile(getClass().getName(), null); + + mainFile.deleteOnExit(); + fileA.deleteOnExit(); + fileB.deleteOnExit(); + + FileWriter out = new FileWriter(mainFile); + out.write(""); + out.write(""); + out.write(""); + out.close(); + + out = new FileWriter(fileA); + out.write("\n"); + out.write("\tfalse\n"); + out.write("\t\n"); + out.write("\t\t\n"); + out.write("\t\t\t\n"); + out.write("\t\t\t\tpasswordfile\n"); + out.write("\t\t\t\torg.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase\n"); + out.write("\t\t\t\t\n"); + out.write("\t\t\t\t\t\n"); + out.write("\t\t\t\t\t\tpasswordFile\n"); + out.write("\t\t\t\t\t\t/dev/null\n"); + out.write("\t\t\t\t\t\n"); + out.write("\t\t\t\t\n"); + out.write("\t\t\t\n"); + out.write("\t\t\n"); + out.write("\t\t\n"); + out.write("\t\t\t/dev/null\n"); + out.write("\t\t\tpasswordfile\n"); + out.write("\t\t\n"); + out.write("\t\t\n"); + out.write("\t\t\t"); + out.write("\t\t\n"); + out.write("\t\n"); + out.write("\t\n"); + out.write("\t\t\n"); + out.write("\t\t\ttest\n"); + out.write("\t\t\n"); + out.write("\t\n"); + out.write("\n"); + out.close(); + + out = new FileWriter(fileB); + out.write("\n"); + out.write("\t"); + out.write("\n"); + out.close(); + + // Load config + ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); + ApplicationRegistry.initialise(reg, 1); + + // Test config + TestIoSession iosession = new TestIoSession(); + iosession.setAddress("127.0.0.1"); + VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry(); + VirtualHost virtualHost = virtualHostRegistry.getVirtualHost("test"); + AMQCodecFactory codecFactory = new AMQCodecFactory(true); + AMQProtocolSession session = new AMQMinaProtocolSession(iosession, virtualHostRegistry, codecFactory); + assertFalse(reg.getAccessManager().authoriseConnect(session, virtualHost)); + + RandomAccessFile fileBRandom = new RandomAccessFile(fileB, "rw"); + fileBRandom.setLength(0); + fileBRandom.seek(0); + fileBRandom.close(); + + out = new FileWriter(fileB); + out.write("\n"); + out.write("\t"); + out.write("\n"); + out.close(); + + reg.getConfiguration().reparseConfigFile(); + + assertTrue(reg.getAccessManager().authoriseConnect(session, virtualHost)); + + fileBRandom = new RandomAccessFile(fileB, "rw"); + fileBRandom.setLength(0); + fileBRandom.seek(0); + fileBRandom.close(); + + out = new FileWriter(fileB); + out.write("\n"); + out.write("\t"); + out.write("\n"); + out.close(); + + reg.getConfiguration().reparseConfigFile(); + + assertFalse(reg.getAccessManager().authoriseConnect(session, virtualHost)); + } + } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java index ba504d3064..7239ec9303 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java @@ -120,5 +120,33 @@ public class VirtualHostConfigurationTest extends TestCase assertEquals(3, bTest.getMaximumMessageAge()); } + + public void testQueueMemoryValues() throws Exception + { + // Set up queue with 5 priorities + configXml.addProperty("virtualhost.test.queues.exchange", "amq.topic"); + configXml.addProperty("virtualhost.test.queues.maximumMemoryUsage", "11"); + configXml.addProperty("virtualhost.test.queues.minimumMemoryUsage", "22"); + + configXml.addProperty("virtualhost.test.queues(-1).queue(1).name(1)", "atest"); + configXml.addProperty("virtualhost.test.queues.queue.atest(-1).exchange", "amq.direct"); + configXml.addProperty("virtualhost.test.queues.queue.atest(-1).maximumMemoryUsage", "44"); + configXml.addProperty("virtualhost.test.queues.queue.atest(-1).minimumMemoryUsage", "55"); + + configXml.addProperty("virtualhost.test.queues(-1).queue(-1).name(-1)", "btest"); + + VirtualHost vhost = new VirtualHost(new VirtualHostConfiguration("test", configXml.subset("virtualhost.test"))); + + // Check specifically configured values + AMQQueue aTest = vhost.getQueueRegistry().getQueue(new AMQShortString("atest")); + assertEquals(44, aTest.getMemoryUsageMaximum()); + assertEquals(55, aTest.getMemoryUsageMinimum()); + + // Check default values + AMQQueue bTest = vhost.getQueueRegistry().getQueue(new AMQShortString("btest")); + assertEquals(11, bTest.getMemoryUsageMaximum()); + assertEquals(22, bTest.getMemoryUsageMinimum()); + } + } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java index 78cf610f28..4c9de73a0b 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java @@ -40,6 +40,7 @@ import org.apache.qpid.server.queue.MessageCleanupException; import org.apache.qpid.server.queue.MockProtocolSession; import org.apache.qpid.server.queue.QueueEntry; import org.apache.qpid.server.queue.SimpleAMQQueue; +import org.apache.qpid.server.queue.UnableToFlowMessageException; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.store.MemoryMessageStore; import org.apache.qpid.server.store.SkeletonMessageStore; @@ -214,6 +215,11 @@ public class AbstractHeadersExchangeTestBase extends TestCase return null; //To change body of implemented methods use File | Settings | File Templates. } + public Long getMessageId() + { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + public long getSize() { return 0; //To change body of implemented methods use File | Settings | File Templates. @@ -229,11 +235,21 @@ public class AbstractHeadersExchangeTestBase extends TestCase return false; //To change body of implemented methods use File | Settings | File Templates. } + public void setExpiration(long expiration) + { + //To change body of implemented methods use File | Settings | File Templates. + } + public boolean isAcquired() { return false; //To change body of implemented methods use File | Settings | File Templates. } + public boolean isAvailable() + { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + public boolean acquire() { return false; //To change body of implemented methods use File | Settings | File Templates. @@ -264,6 +280,11 @@ public class AbstractHeadersExchangeTestBase extends TestCase //To change body of implemented methods use File | Settings | File Templates. } + public void setDeliveredToConsumer() + { + //To change body of implemented methods use File | Settings | File Templates. + } + public void release() { //To change body of implemented methods use File | Settings | File Templates. @@ -314,32 +335,38 @@ public class AbstractHeadersExchangeTestBase extends TestCase //To change body of implemented methods use File | Settings | File Templates. } - public void dispose(final StoreContext storeContext) throws MessageCleanupException + + public void dequeueAndDelete(StoreContext storeContext) throws FailedDequeueException { //To change body of implemented methods use File | Settings | File Templates. } - public void restoreCredit() + public boolean isQueueDeleted() { - //To change body of implemented methods use File | Settings | File Templates. + return false; //To change body of implemented methods use File | Settings | File Templates. } - public void dequeueAndDelete(StoreContext storeContext) throws FailedDequeueException + public void addStateChangeListener(StateChangeListener listener) { //To change body of implemented methods use File | Settings | File Templates. } - public boolean isQueueDeleted() + public boolean removeStateChangeListener(StateChangeListener listener) { return false; //To change body of implemented methods use File | Settings | File Templates. } - public void addStateChangeListener(StateChangeListener listener) + public void unload() { //To change body of implemented methods use File | Settings | File Templates. } - public boolean removeStateChangeListener(StateChangeListener listener) + public void load() + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public boolean isFlowed() { return false; //To change body of implemented methods use File | Settings | File Templates. } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DestWildExchangeTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DestWildExchangeTest.java index f8544a33bd..890b641540 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DestWildExchangeTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DestWildExchangeTest.java @@ -100,7 +100,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -140,7 +140,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -159,7 +159,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -198,7 +198,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -217,7 +217,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -236,7 +236,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -254,7 +254,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -294,7 +294,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -312,7 +312,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -352,7 +352,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -384,7 +384,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -425,7 +425,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); @@ -464,7 +464,7 @@ public class DestWildExchangeTest extends TestCase Assert.assertEquals(1, queue.getMessageCount()); - Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessage().getMessageId()); + Assert.assertEquals("Wrong message recevied", (Object) message.getMessageId(), queue.getMessagesOnTheQueue().get(0).getMessageId()); queue.deleteMessageFromTop(_context); Assert.assertEquals(0, queue.getMessageCount()); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/management/LoggingManagementMBeanTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/management/LoggingManagementMBeanTest.java new file mode 100644 index 0000000000..40153be331 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/management/LoggingManagementMBeanTest.java @@ -0,0 +1,413 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + * + */ +package org.apache.qpid.server.logging.management; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.management.JMException; +import javax.management.openmbean.CompositeData; +import javax.management.openmbean.TabularDataSupport; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; + +import junit.framework.TestCase; + +public class LoggingManagementMBeanTest extends TestCase +{ + private static final String TEST_LOGGER = "LoggingManagementMBeanTestLogger"; + private static final String TEST_LOGGER_CHILD1 = "LoggingManagementMBeanTestLogger.child1"; + private static final String TEST_LOGGER_CHILD2 = "LoggingManagementMBeanTestLogger.child2"; + + private static final String CATEGORY_PRIORITY = "LogManMBeanTest.category.priority"; + private static final String CATEGORY_LEVEL = "LogManMBeanTest.category.level"; + private static final String LOGGER_LEVEL = "LogManMBeanTest.logger.level"; + + private static final String NAME_INDEX = LoggingManagement.COMPOSITE_ITEM_NAMES[0]; + private static final String LEVEL_INDEX = LoggingManagement.COMPOSITE_ITEM_NAMES[1]; + + private static final String NEWLINE = System.getProperty("line.separator"); + + private File _testConfigFile; + + protected void setUp() throws Exception + { + _testConfigFile = createTempTestLog4JConfig(); + } + + private File createTempTestLog4JConfig() + { + File tmpFile = null; + try + { + tmpFile = File.createTempFile("LogManMBeanTestLog4jConfig", ".tmp"); + tmpFile.deleteOnExit(); + + FileWriter fstream = new FileWriter(tmpFile); + BufferedWriter writer = new BufferedWriter(fstream); + + writer.write(""+NEWLINE); + writer.write(""+NEWLINE); + + writer.write(""+NEWLINE); + + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + + //Example of a 'category' with a 'priority' + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + + //Example of a 'category' with a 'level' + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + + //Example of a 'logger' with a 'level' + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + + //'root' logger + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + writer.write(" "+NEWLINE); + + writer.write(""+NEWLINE); + + writer.flush(); + writer.close(); + } + catch (IOException e) + { + fail("Unable to create temporary test log4j configuration"); + } + + return tmpFile; + } + + + + //******* Test Methods ******* // + + public void testSetRuntimeLoggerLevel() + { + LoggingManagementMBean lm = null; + try + { + lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0); + } + catch (JMException e) + { + fail("Could not create test LoggingManagementMBean"); + } + + //create a parent test logger, set its level explicitly + Logger log = Logger.getLogger(TEST_LOGGER); + log.setLevel(Level.toLevel("info")); + + //create child1 test logger, check its *effective* level is the same as the parent, "info" + Logger log1 = Logger.getLogger(TEST_LOGGER_CHILD1); + assertTrue("Test logger's level was not the expected value", + log1.getEffectiveLevel().toString().equalsIgnoreCase("info")); + + //now change its level to "warn" + assertTrue("Failed to set logger level", lm.setRuntimeLoggerLevel(TEST_LOGGER_CHILD1, "warn")); + + //check the change, see its actual level is "warn + assertTrue("Test logger's level was not the expected value", + log1.getLevel().toString().equalsIgnoreCase("warn")); + + //try an invalid level + assertFalse("Trying to set an invalid level succeded", lm.setRuntimeLoggerLevel(TEST_LOGGER_CHILD1, "made.up.level")); + } + + public void testSetRuntimeRootLoggerLevel() + { + LoggingManagementMBean lm = null; + try + { + lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0); + } + catch (JMException e) + { + fail("Could not create test LoggingManagementMBean"); + } + + Logger log = Logger.getRootLogger(); + + //get current root logger level + Level origLevel = log.getLevel(); + + //change level twice to ensure a new level is actually selected + + //set root loggers level to info + assertTrue("Failed to set root logger level", lm.setRuntimeRootLoggerLevel("debug")); + //check it is now actually info + Level currentLevel = log.getLevel(); + assertTrue("Logger level was not expected value", currentLevel.equals(Level.toLevel("debug"))); + + //try an invalid level + assertFalse("Trying to set an invalid level succeded", lm.setRuntimeRootLoggerLevel("made.up.level")); + + //set root loggers level to warn + assertTrue("Failed to set logger level", lm.setRuntimeRootLoggerLevel("info")); + //check it is now actually warn + currentLevel = log.getLevel(); + assertTrue("Logger level was not expected value", currentLevel.equals(Level.toLevel("info"))); + + //restore original level + log.setLevel(origLevel); + } + + public void testGetRuntimeRootLoggerLevel() + { + LoggingManagementMBean lm = null; + try + { + lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0); + } + catch (JMException e) + { + fail("Could not create test LoggingManagementMBean"); + } + + Logger log = Logger.getRootLogger(); + + //get current root logger level + Level origLevel = log.getLevel(); + + //change level twice to ensure a new level is actually selected + + //set root loggers level to debug + log.setLevel(Level.toLevel("debug")); + //check it is now actually debug + assertTrue("Logger level was not expected value", lm.getRuntimeRootLoggerLevel().equalsIgnoreCase("debug")); + + + //set root loggers level to warn + log.setLevel(Level.toLevel("info")); + //check it is now actually warn + assertTrue("Logger level was not expected value", lm.getRuntimeRootLoggerLevel().equalsIgnoreCase("info")); + + //restore original level + log.setLevel(origLevel); + } + + public void testViewEffectiveRuntimeLoggerLevels() + { + LoggingManagementMBean lm = null; + try + { + lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0); + } + catch (JMException e) + { + fail("Could not create test LoggingManagementMBean"); + } + + //(re)create a parent test logger, set its level explicitly + Logger log = Logger.getLogger(TEST_LOGGER); + log.setLevel(Level.toLevel("info")); + + //retrieve the current effective runtime logger level values + TabularDataSupport levels = (TabularDataSupport) lm.viewEffectiveRuntimeLoggerLevels(); + Collection records = levels.values(); + Map list = new HashMap(); + for (Object o : records) + { + CompositeData data = (CompositeData) o; + list.put(data.get(NAME_INDEX).toString(), data.get(LEVEL_INDEX).toString()); + } + + //check child2 does not exist already + assertFalse("Did not expect this logger to exist already", list.containsKey(TEST_LOGGER_CHILD2)); + + //create child2 test logger + Logger log2 = Logger.getLogger(TEST_LOGGER_CHILD2); + + //retrieve the current effective runtime logger level values + levels = (TabularDataSupport) lm.viewEffectiveRuntimeLoggerLevels(); + records = levels.values(); + list = new HashMap(); + for (Object o : records) + { + CompositeData data = (CompositeData) o; + list.put(data.get(NAME_INDEX).toString(), data.get(LEVEL_INDEX).toString()); + } + + //verify the parent and child2 loggers are present in returned values + assertTrue(TEST_LOGGER + " logger was not in the returned list", list.containsKey(TEST_LOGGER)); + assertTrue(TEST_LOGGER_CHILD2 + " logger was not in the returned list", list.containsKey(TEST_LOGGER_CHILD2)); + + //check child2's effective level is the same as the parent, "info" + assertTrue("Test logger's level was not the expected value", + list.get(TEST_LOGGER_CHILD2).equalsIgnoreCase("info")); + + //now change its level explicitly to "warn" + log2.setLevel(Level.toLevel("warn")); + + //retrieve the current effective runtime logger level values + levels = (TabularDataSupport) lm.viewEffectiveRuntimeLoggerLevels(); + records = levels.values(); + list = new HashMap(); + for (Object o : records) + { + CompositeData data = (CompositeData) o; + list.put(data.get(NAME_INDEX).toString(), data.get(LEVEL_INDEX).toString()); + } + + //check child2's effective level is now "warn" + assertTrue("Test logger's level was not the expected value", + list.get(TEST_LOGGER_CHILD2).equalsIgnoreCase("warn")); + } + + public void testViewAndSetConfigFileLoggerLevel() throws Exception + { + LoggingManagementMBean lm =null; + try + { + lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0); + } + catch (JMException e) + { + fail("Could not create test LoggingManagementMBean"); + } + + //retrieve the current values + TabularDataSupport levels = (TabularDataSupport) lm.viewConfigFileLoggerLevels(); + Collection records = levels.values(); + Map list = new HashMap(); + for (Object o : records) + { + CompositeData data = (CompositeData) o; + list.put(data.get(NAME_INDEX).toString(), data.get(LEVEL_INDEX).toString()); + } + + //check the 3 different types of logger definition are successfully retrieved before update + assertTrue("Wrong number of items in returned list", list.size() == 3); + assertTrue(CATEGORY_PRIORITY + " logger was not in the returned list", list.containsKey(CATEGORY_PRIORITY)); + assertTrue(CATEGORY_LEVEL + " logger was not in the returned list", list.containsKey(CATEGORY_LEVEL)); + assertTrue(LOGGER_LEVEL + " logger was not in the returned list", list.containsKey(LOGGER_LEVEL)); + + //check that their level is as expected + assertTrue(CATEGORY_PRIORITY + " logger's level was incorrect", list.get(CATEGORY_PRIORITY).equalsIgnoreCase("info")); + assertTrue(CATEGORY_LEVEL + " logger's level was incorrect", list.get(CATEGORY_LEVEL).equalsIgnoreCase("warn")); + assertTrue(LOGGER_LEVEL + " logger's level was incorrect", list.get(LOGGER_LEVEL).equalsIgnoreCase("error")); + + //increase their levels a notch to test the 3 different types of logger definition are successfully updated + //change the category+priority to warn + assertTrue("failed to set new level", lm.setConfigFileLoggerLevel(CATEGORY_PRIORITY, "warn")); + //change the category+level to error + assertTrue("failed to set new level", lm.setConfigFileLoggerLevel(CATEGORY_LEVEL, "error")); + //change the logger+level to trace + assertTrue("failed to set new level", lm.setConfigFileLoggerLevel(LOGGER_LEVEL, "trace")); + + //try an invalid level + assertFalse("Use of an invalid logger level was successfull", lm.setConfigFileLoggerLevel(LOGGER_LEVEL, "made.up.level")); + + //try an invalid logger name + assertFalse("Use of an invalid logger name was successfull", lm.setConfigFileLoggerLevel("made.up.logger.name", "info")); + + //retrieve the new values from the file and check them + levels = (TabularDataSupport) lm.viewConfigFileLoggerLevels(); + records = levels.values(); + list = new HashMap(); + for (Object o : records) + { + CompositeData data = (CompositeData) o; + list.put(data.get(NAME_INDEX).toString(), data.get(LEVEL_INDEX).toString()); + } + + //check the 3 different types of logger definition are successfully retrieved after update + assertTrue("Wrong number of items in returned list", list.size() == 3); + assertTrue(CATEGORY_PRIORITY + " logger was not in the returned list", list.containsKey(CATEGORY_PRIORITY)); + assertTrue(CATEGORY_LEVEL + " logger was not in the returned list", list.containsKey(CATEGORY_LEVEL)); + assertTrue(LOGGER_LEVEL + " logger was not in the returned list", list.containsKey(LOGGER_LEVEL)); + + //check that their level is as expected after the changes + assertTrue(CATEGORY_PRIORITY + " logger's level was incorrect", list.get(CATEGORY_PRIORITY).equalsIgnoreCase("warn")); + assertTrue(CATEGORY_LEVEL + " logger's level was incorrect", list.get(CATEGORY_LEVEL).equalsIgnoreCase("error")); + assertTrue(LOGGER_LEVEL + " logger's level was incorrect", list.get(LOGGER_LEVEL).equalsIgnoreCase("trace")); + } + + public void testGetAndSetConfigFileRootLoggerLevel() throws Exception + { + LoggingManagementMBean lm =null; + try + { + lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0); + } + catch (JMException e) + { + fail("Could not create test LoggingManagementMBean"); + } + + //retrieve the current value + String level = lm.getConfigFileRootLoggerLevel(); + + //check the value was successfully retrieved before update + assertTrue("Retrieved RootLogger level was incorrect", level.equalsIgnoreCase("info")); + + //try an invalid level + assertFalse("Use of an invalid RootLogger level was successfull", lm.setConfigFileRootLoggerLevel("made.up.level")); + + //change the level to warn + assertTrue("Failed to set new RootLogger level", lm.setConfigFileRootLoggerLevel("warn")); + + //retrieve the current value + level = lm.getConfigFileRootLoggerLevel(); + + //check the value was successfully retrieved after update + assertTrue("Retrieved RootLogger level was incorrect", level.equalsIgnoreCase("warn")); + } + + public void testGetLog4jLogWatchInterval() + { + LoggingManagementMBean lm =null; + try + { + lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 5000); + } + catch (JMException e) + { + fail("Could not create test LoggingManagementMBean"); + } + + assertTrue("Wrong value returned for logWatch period", lm.getLog4jLogWatchInterval() == 5000); + } + +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java index ba02e6f6bd..d7844730d1 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java @@ -23,20 +23,21 @@ package org.apache.qpid.server.queue; import junit.framework.AssertionFailedError; import org.apache.qpid.AMQException; import org.apache.qpid.framing.BasicContentHeaderProperties; -import org.apache.qpid.framing.ContentHeaderBody; import org.apache.qpid.framing.FieldTable; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.txn.NonTransactionalContext; import java.util.ArrayList; public class AMQPriorityQueueTest extends SimpleAMQQueueTest { - private static final long MESSAGE_SIZE = 100L; + private static final int PRIORITIES = 3; @Override protected void setUp() throws Exception - { + { _arguments = new FieldTable(); - _arguments.put(AMQQueueFactory.X_QPID_PRIORITIES, 3); + _arguments.put(AMQQueueFactory.X_QPID_PRIORITIES, PRIORITIES); super.setUp(); } @@ -64,20 +65,20 @@ public class AMQPriorityQueueTest extends SimpleAMQQueueTest _queue.registerSubscription(_subscription, false); Thread.sleep(150); - ArrayList msgs = _subscription.getMessages(); + ArrayList msgs = _subscription.getQueueEntries(); try { - assertEquals(new Long(1 + messagIDOffset), msgs.get(0).getMessage().getMessageId()); - assertEquals(new Long(6 + messagIDOffset), msgs.get(1).getMessage().getMessageId()); - assertEquals(new Long(8 + messagIDOffset), msgs.get(2).getMessage().getMessageId()); + assertEquals(new Long(1 + messagIDOffset), msgs.get(0).getMessageId()); + assertEquals(new Long(6 + messagIDOffset), msgs.get(1).getMessageId()); + assertEquals(new Long(8 + messagIDOffset), msgs.get(2).getMessageId()); - assertEquals(new Long(2 + messagIDOffset), msgs.get(3).getMessage().getMessageId()); - assertEquals(new Long(5 + messagIDOffset), msgs.get(4).getMessage().getMessageId()); - assertEquals(new Long(7 + messagIDOffset), msgs.get(5).getMessage().getMessageId()); + assertEquals(new Long(2 + messagIDOffset), msgs.get(3).getMessageId()); + assertEquals(new Long(5 + messagIDOffset), msgs.get(4).getMessageId()); + assertEquals(new Long(7 + messagIDOffset), msgs.get(5).getMessageId()); - assertEquals(new Long(3 + messagIDOffset), msgs.get(6).getMessage().getMessageId()); - assertEquals(new Long(4 + messagIDOffset), msgs.get(7).getMessage().getMessageId()); - assertEquals(new Long(9 + messagIDOffset), msgs.get(8).getMessage().getMessageId()); + assertEquals(new Long(3 + messagIDOffset), msgs.get(6).getMessageId()); + assertEquals(new Long(4 + messagIDOffset), msgs.get(7).getMessageId()); + assertEquals(new Long(9 + messagIDOffset), msgs.get(8).getMessageId()); } catch (AssertionFailedError afe) { @@ -85,7 +86,6 @@ public class AMQPriorityQueueTest extends SimpleAMQQueueTest int index = 1; for (QueueEntry qe : msgs) { - System.err.println(index + ":" + qe.getMessage().getMessageId()); index++; } @@ -97,9 +97,96 @@ public class AMQPriorityQueueTest extends SimpleAMQQueueTest protected AMQMessage createMessage(byte i) throws AMQException { AMQMessage message = super.createMessage(); - - ((BasicContentHeaderProperties)message.getContentHeaderBody().properties).setPriority(i); + + ((BasicContentHeaderProperties) message.getContentHeaderBody().properties).setPriority(i); return message; } + + + public void testMessagesFlowToDiskWithPriority() throws AMQException, InterruptedException + { + int PRIORITIES = 1; + FieldTable arguments = new FieldTable(); + arguments.put(AMQQueueFactory.X_QPID_PRIORITIES, PRIORITIES); + + // Create IncomingMessage and nondurable queue + NonTransactionalContext txnContext = new NonTransactionalContext(_transactionLog, null, null, null); + + //Create a priorityQueue + _queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testMessagesFlowToDiskWithPriority"), false, _owner, false, _virtualHost, arguments); + + MESSAGE_SIZE = 1; + long MEMORY_MAX = PRIORITIES * 2; + int MESSAGE_COUNT = (int) MEMORY_MAX * 2; + //Set the Memory Usage to be very low + _queue.setMemoryUsageMaximum(MEMORY_MAX); + + for (int msgCount = 0; msgCount < MESSAGE_COUNT / 2; msgCount++) + { + sendMessage(txnContext, (msgCount % 10)); + } + + //Check that we can hold 10 messages without flowing + assertEquals(MESSAGE_COUNT / 2, _queue.getMessageCount()); + assertEquals(MEMORY_MAX, _queue.getMemoryUsageMaximum()); + assertEquals(_queue.getMemoryUsageMaximum(), _queue.getMemoryUsageCurrent()); + assertTrue("Queue is flowed.", !_queue.isFlowed()); + + // Send another and ensure we are flowed + sendMessage(txnContext, 9); + + //Give the Purging Thread a chance to run + Thread.yield(); + Thread.sleep(500); + + assertTrue("Queue is not flowed.", _queue.isFlowed()); + assertEquals("Queue contains more messages than expected.", MESSAGE_COUNT / 2 + 1, _queue.getMessageCount()); + assertEquals("Queue over memory quota.",MESSAGE_COUNT / 2, _queue.getMemoryUsageCurrent()); + + + //send another batch of messagse so the total in each queue is equal + for (int msgCount = 0; msgCount < (MESSAGE_COUNT / 2) ; msgCount++) + { + sendMessage(txnContext, (msgCount % 10)); + + long usage = _queue.getMemoryUsageCurrent(); + assertTrue("Queue has gone over quota:" + usage, + usage <= _queue.getMemoryUsageMaximum()); + + assertTrue("Queue has a negative quota:" + usage, usage > 0); + + } + assertEquals(MESSAGE_COUNT + 1, _queue.getMessageCount()); + assertEquals(MEMORY_MAX, _queue.getMemoryUsageCurrent()); + assertTrue("Queue is not flowed.", _queue.isFlowed()); + + _queue.registerSubscription(_subscription, false); + + int slept = 0; + while (_subscription.getQueueEntries().size() != MESSAGE_COUNT + 1 && slept < 10) + { + Thread.yield(); + Thread.sleep(500); + slept++; + } + + //Ensure the messages are retreived + assertEquals("Not all messages were received, slept:" + slept / 2 + "s", MESSAGE_COUNT + 1, _subscription.getQueueEntries().size()); + + //Check the queue is still within it's limits. + assertTrue("Queue has gone over quota:" + _queue.getMemoryUsageCurrent(), + _queue.getMemoryUsageCurrent() <= _queue.getMemoryUsageMaximum()); + + assertTrue("Queue has a negative quota:" + _queue.getMemoryUsageCurrent(), _queue.getMemoryUsageCurrent() >= 0); + + for (int index = 0; index < MESSAGE_COUNT; index++) + { + // Ensure that we have received the messages and it wasn't flushed to disk before we received it. + AMQMessage message = _subscription.getMessages().get(index); + assertNotNull("Message:" + message.debugIdentity() + " was null.", message); + } + + } + } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java index 75ad8380bc..237fe20f7e 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java @@ -204,7 +204,7 @@ public class AMQQueueAlertTest extends TestCase // Send messages(no of message to be little more than what can cause a Queue_Depth alert) int messageCount = Math.round(MAX_QUEUE_DEPTH / MAX_MESSAGE_SIZE) + 10; - long totalSize = (messageCount * MAX_MESSAGE_SIZE) >> 10; + long totalSize = (messageCount * MAX_MESSAGE_SIZE); sendMessages(messageCount, MAX_MESSAGE_SIZE); // Check queueDepth. There should be no messages on the queue and as the subscriber is listening diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryPriorityTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryPriorityTest.java new file mode 100644 index 0000000000..0d6c5948b4 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryPriorityTest.java @@ -0,0 +1,70 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +import org.apache.qpid.AMQException; +import org.apache.qpid.framing.AMQShortString; + +public class AMQQueueFactoryPriorityTest extends AMQQueueFactoryTest +{ + private static final int PRIORITIES = 5; + + @Override + public void setUp() + { + super.setUp(); + _arguments.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), PRIORITIES); + } + + @Override + public void testQueueRegistration() + { + try + { + AMQQueue queue = createQueue(); + + assertEquals("Queue not a priorty queue", AMQPriorityQueue.class, queue.getClass()); + + assertEquals("Incorrect number of priorities set", PRIORITIES, ((AMQPriorityQueue) queue).getPriorities()); + } + catch (AMQException e) + { + fail(e.getMessage()); + } + } + + @Override + public void testQueueValuesAfterCreation() + { + try + { + AMQQueue queue = createQueue(); + + assertEquals("MemoryMaximumSize not set correctly:", MAX_SIZE, queue.getMemoryUsageMaximum()); + //NOTE: Priority queue will show 0 as minimum as the minimum value is actually spread between its sub QELs + assertEquals("MemoryMinimumSize not 0 as expected for a priority queue:", 0, queue.getMemoryUsageMinimum()); + } + catch (AMQException e) + { + fail(e.getMessage()); + } + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java index 520e49c56a..b8aa8272ba 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java @@ -29,8 +29,11 @@ import org.apache.qpid.AMQException; public class AMQQueueFactoryTest extends TestCase { + final int MAX_SIZE = 50; + QueueRegistry _queueRegistry; VirtualHost _virtualHost; + protected FieldTable _arguments; public void setUp() { @@ -41,6 +44,15 @@ public class AMQQueueFactoryTest extends TestCase _queueRegistry = _virtualHost.getQueueRegistry(); assertEquals("Queues registered on an empty virtualhost", 0, _queueRegistry.getQueues().size()); + + + _arguments = new FieldTable(); + + //Ensure we can call createQueue with a priority int value + _arguments.put(AMQQueueFactory.QPID_POLICY_TYPE, AMQQueueFactory.QPID_FLOW_TO_DISK); + // each message in the QBAAT is around 9-10 bytes each so only give space for half + + _arguments.put(AMQQueueFactory.QPID_MAX_SIZE, MAX_SIZE); } public void tearDown() @@ -50,17 +62,19 @@ public class AMQQueueFactoryTest extends TestCase } - public void testPriorityQueueRegistration() + protected AMQQueue createQueue() throws AMQException { - FieldTable fieldTable = new FieldTable(); - fieldTable.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), 5); + return AMQQueueFactory.createAMQQueueImpl(new AMQShortString(this.getName()), false, new AMQShortString("owner"), false, + _virtualHost, _arguments); + } + + public void testQueueRegistration() + { try { - AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testPriorityQueue"), false, new AMQShortString("owner"), false, - _virtualHost, fieldTable); - - assertEquals("Queue not a priorty queue", AMQPriorityQueue.class, queue.getClass()); + AMQQueue queue = createQueue(); + assertEquals("Queue not a simple queue", SimpleAMQQueue.class, queue.getClass()); } catch (AMQException e) { @@ -68,18 +82,20 @@ public class AMQQueueFactoryTest extends TestCase } } - - public void testSimpleQueueRegistration() + public void testQueueValuesAfterCreation() { try { - AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueue"), false, new AMQShortString("owner"), false, - _virtualHost, null); - assertEquals("Queue not a simple queue", SimpleAMQQueue.class, queue.getClass()); + AMQQueue queue = createQueue(); + + assertEquals("MemoryMaximumSize not set correctly:", MAX_SIZE, queue.getMemoryUsageMaximum()); + assertEquals("MemoryMinimumSize not defaulted to half maximum:", MAX_SIZE / 2, queue.getMemoryUsageMinimum()); + } catch (AMQException e) { fail(e.getMessage()); } } + } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java index daa8e4beb7..3d189ae6c5 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java @@ -73,7 +73,7 @@ public class AMQQueueMBeanTest extends TestCase sendMessages(messageCount, false); assertTrue(_queueMBean.getMessageCount() == messageCount); assertTrue(_queueMBean.getReceivedMessageCount() == messageCount); - long queueDepth = (messageCount * MESSAGE_SIZE) >> 10; + long queueDepth = (messageCount * MESSAGE_SIZE); assertTrue(_queueMBean.getQueueDepth() == queueDepth); _queueMBean.deleteMessageFromTop(); @@ -94,7 +94,7 @@ public class AMQQueueMBeanTest extends TestCase sendMessages(messageCount, true); assertEquals("", messageCount, _queueMBean.getMessageCount().intValue()); assertTrue(_queueMBean.getReceivedMessageCount() == messageCount); - long queueDepth = (messageCount * MESSAGE_SIZE) >> 10; + long queueDepth = (messageCount * MESSAGE_SIZE); assertTrue(_queueMBean.getQueueDepth() == queueDepth); _queueMBean.deleteMessageFromTop(); @@ -175,7 +175,7 @@ public class AMQQueueMBeanTest extends TestCase assertTrue(_queueMBean.getMaximumMessageCount() == 50000); assertTrue(_queueMBean.getMaximumMessageSize() == 2000); - assertTrue(_queueMBean.getMaximumQueueDepth() == (maxQueueDepth >> 10)); + assertTrue(_queueMBean.getMaximumQueueDepth() == (maxQueueDepth)); assertTrue(_queueMBean.getName().equals("testQueue")); assertTrue(_queueMBean.getOwner().equals("AMQueueMBeanTest")); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueThreadPoolTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueThreadPoolTest.java new file mode 100644 index 0000000000..c7cf778d93 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueThreadPoolTest.java @@ -0,0 +1,98 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +import junit.framework.TestCase; +import org.apache.qpid.AMQException; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.framing.FieldTable; +import org.apache.qpid.pool.ReferenceCountingExecutorService; +import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.virtualhost.VirtualHost; + +public class AMQQueueThreadPoolTest extends TestCase +{ + + public void testSimpleAMQQueue() throws AMQException + { + int initialCount = ReferenceCountingExecutorService.getInstance().getReferenceCount(); + VirtualHost test = ApplicationRegistry.getInstance(1).getVirtualHostRegistry().getVirtualHost("test"); + + try + { + SimpleAMQQueue queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(new AMQShortString("test"), false, + new AMQShortString("owner"), + false, test, null); + + assertFalse("Creation did not start Pool.", ReferenceCountingExecutorService.getInstance().getPool().isShutdown()); + + //This is +2 because: + // 1 - asyncDelivery Thread + // 2 - queue InhalerThread + // 3 - queue PurgerThread + assertEquals("References not increased", initialCount + 3, ReferenceCountingExecutorService.getInstance().getReferenceCount()); + + queue.stop(); + + assertEquals("References not decreased", initialCount, ReferenceCountingExecutorService.getInstance().getReferenceCount()); + } + finally + { + ApplicationRegistry.remove(1); + } + } + + public void testPriorityAMQQueue() throws AMQException + { + int initialCount = ReferenceCountingExecutorService.getInstance().getReferenceCount(); + VirtualHost test = ApplicationRegistry.getInstance(1).getVirtualHostRegistry().getVirtualHost("test"); + + try + { + + FieldTable arguements = new FieldTable(); + int priorities = 10; + arguements.put(AMQQueueFactory.X_QPID_PRIORITIES, priorities); + + SimpleAMQQueue queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(new AMQShortString("test"), false, + new AMQShortString("owner"), + false, test, arguements); + + assertFalse("Creation did not start Pool.", ReferenceCountingExecutorService.getInstance().getPool().isShutdown()); + + //This is +2 because: + // 1 - asyncDelivery Thread + // 2 + 3 - queue InhalerThread, PurgerThread for the Priority Queue + // priorities * ( Inhaler , Purger) for each priority level + assertEquals("References not increased", (initialCount + 3) + priorities * 2, + ReferenceCountingExecutorService.getInstance().getReferenceCount()); + + queue.stop(); + + assertEquals("References not decreased", initialCount, ReferenceCountingExecutorService.getInstance().getReferenceCount()); + } + finally + { + ApplicationRegistry.remove(1); + } + } + +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/FileQueueBackingStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/FileQueueBackingStoreTest.java new file mode 100644 index 0000000000..d2cbd46e28 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/FileQueueBackingStoreTest.java @@ -0,0 +1,223 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +import junit.framework.TestCase; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.qpid.AMQException; +import org.apache.qpid.exchange.ExchangeDefaults; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.framing.BasicContentHeaderProperties; +import org.apache.qpid.framing.ContentHeaderBody; +import org.apache.qpid.framing.abstraction.ContentChunk; +import org.apache.qpid.framing.abstraction.MessagePublishInfo; +import org.apache.qpid.framing.abstraction.MessagePublishInfoImpl; +import org.apache.qpid.framing.amqp_8_0.BasicPublishBodyImpl; +import org.apache.qpid.server.configuration.VirtualHostConfiguration; +import org.apache.qpid.server.store.MemoryMessageStore; +import org.apache.qpid.server.transactionlog.TransactionLog; +import org.apache.qpid.server.virtualhost.VirtualHost; + +import java.io.File; + +public class FileQueueBackingStoreTest extends TestCase +{ + QueueBackingStore _backing; + private TransactionLog _transactionLog; + VirtualHost _vhost; + VirtualHostConfiguration _vhostConfig; + FileQueueBackingStoreFactory _factory; + AMQQueue _queue; + + public void setUp() throws Exception + { + _factory = new FileQueueBackingStoreFactory(); + PropertiesConfiguration config = new PropertiesConfiguration(); + config.addProperty("store.class", MemoryMessageStore.class.getName()); + _vhostConfig = new VirtualHostConfiguration(this.getName() + "-Vhost", config); + _vhost = new VirtualHost(_vhostConfig); + _transactionLog = _vhost.getTransactionLog(); + + _factory.configure(_vhost, _vhost.getConfiguration()); + + _queue = new SimpleAMQQueue(new AMQShortString(this.getName()), false, null, false, _vhost); + _backing = _factory.createBacking(_queue); + } + + private void resetBacking(Configuration configuration) throws Exception + { + configuration.addProperty("store.class", MemoryMessageStore.class.getName()); + _vhostConfig = new VirtualHostConfiguration(this.getName() + "-Vhost", configuration); + _vhost = new VirtualHost(_vhostConfig); + _transactionLog = _vhost.getTransactionLog(); + + _factory = new FileQueueBackingStoreFactory(); + + _factory.configure(_vhost, _vhost.getConfiguration()); + + _backing = _factory.createBacking(_queue); + } + + public void testInvalidSetupRootExistsIsFile() throws Exception + { + + File fileAsRoot = File.createTempFile("tmpRoot", ""); + fileAsRoot.deleteOnExit(); + + PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.addProperty(VirtualHostConfiguration.FLOW_TO_DISK_PATH, fileAsRoot.getAbsolutePath()); + + try + { + resetBacking(configuration); + fail("Exception expected to be thrown"); + } + catch (ConfigurationException ce) + { + assertTrue("Expected Exception not thrown, expecting:" + + "Unable to create Temporary Flow to Disk store as specified root is a file:", + ce.getMessage(). + startsWith("Unable to create Temporary Flow to Disk store as specified root is a file:")); + } + + } + + public void testInvalidSetupRootExistsCantWrite() throws Exception + { + + File fileAsRoot = new File("/var/log"); + + PropertiesConfiguration configuration = new PropertiesConfiguration(); + + configuration.addProperty(VirtualHostConfiguration.FLOW_TO_DISK_PATH, fileAsRoot.getAbsolutePath()); + + try + { + resetBacking(configuration); + fail("Exception expected to be thrown"); + } + catch (ConfigurationException ce) + { + assertEquals("Unable to create Temporary Flow to Disk store. Unable to write to specified root:/var/log", + ce.getMessage()); + } + + } + + public void testEmptyTransientFlowToDisk() throws UnableToFlowMessageException, AMQException + { + AMQMessage original = MessageFactory.getInstance().createMessage(null, false); + + ContentHeaderBody chb = new ContentHeaderBody(new BasicContentHeaderProperties(), BasicPublishBodyImpl.CLASS_ID); + chb.bodySize = 0L; + + runTestWithMessage(original, chb); + } + + public void testEmptyPersistentFlowToDisk() throws UnableToFlowMessageException, AMQException + { + + AMQMessage original = MessageFactory.getInstance().createMessage(_transactionLog, true); + ContentHeaderBody chb = new ContentHeaderBody(new BasicContentHeaderProperties(), BasicPublishBodyImpl.CLASS_ID); + chb.bodySize = 0L; + ((BasicContentHeaderProperties) chb.properties).setDeliveryMode((byte) 2); + + runTestWithMessage(original, chb); + + } + + public void testNonEmptyTransientFlowToDisk() throws UnableToFlowMessageException, AMQException + { + AMQMessage original = MessageFactory.getInstance().createMessage(null, false); + + ContentHeaderBody chb = new ContentHeaderBody(new BasicContentHeaderProperties(), BasicPublishBodyImpl.CLASS_ID); + chb.bodySize = 100L; + + runTestWithMessage(original, chb); + } + + public void testNonEmptyPersistentFlowToDisk() throws UnableToFlowMessageException, AMQException + { + AMQMessage original = MessageFactory.getInstance().createMessage(_transactionLog, true); + ContentHeaderBody chb = new ContentHeaderBody(new BasicContentHeaderProperties(), BasicPublishBodyImpl.CLASS_ID); + chb.bodySize = 100L; + ((BasicContentHeaderProperties) chb.properties).setDeliveryMode((byte) 2); + + runTestWithMessage(original, chb); + } + + void runTestWithMessage(AMQMessage original, ContentHeaderBody chb) throws UnableToFlowMessageException, AMQException + { + + // Create message + + original.setPublishAndContentHeaderBody(null, + new MessagePublishInfoImpl(ExchangeDefaults.DIRECT_EXCHANGE_NAME, + false, false, new AMQShortString("routing")), + chb); + if (chb.bodySize > 0) + { + ContentChunk chunk = new MockContentChunk((int) chb.bodySize / 2); + + original.addContentBodyFrame(null, chunk, false); + + chunk = new MockContentChunk((int) chb.bodySize / 2); + + original.addContentBodyFrame(null, chunk, true); + } + + _backing.unload(original); + + AMQMessage fromDisk = _backing.load(original.getMessageId()); + + assertEquals("Message IDs do not match", original.getMessageId(), fromDisk.getMessageId()); + assertEquals("Message arrival times do not match", original.getArrivalTime(), fromDisk.getArrivalTime()); + assertEquals(original.isPersistent(), fromDisk.isPersistent()); + + // Validate the MPI data was restored correctly + MessagePublishInfo originalMPI = original.getMessagePublishInfo(); + MessagePublishInfo fromDiskMPI = fromDisk.getMessagePublishInfo(); + assertEquals("Exchange", originalMPI.getExchange(), fromDiskMPI.getExchange()); + assertEquals(originalMPI.isImmediate(), fromDiskMPI.isImmediate()); + assertEquals(originalMPI.isMandatory(), fromDiskMPI.isMandatory()); + assertEquals(originalMPI.getRoutingKey(), fromDiskMPI.getRoutingKey()); + + // Validate BodyCounts. + int originalBodyCount = original.getBodyCount(); + assertEquals(originalBodyCount, fromDisk.getBodyCount()); + + if (originalBodyCount > 0) + { + for (int index = 0; index < originalBodyCount; index++) + { + ContentChunk originalChunk = original.getContentChunk(index); + ContentChunk fromDiskChunk = fromDisk.getContentChunk(index); + + assertEquals(originalChunk.getSize(), fromDiskChunk.getSize()); + assertEquals(originalChunk.getData(), fromDiskChunk.getData()); + } + } + + } + +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQMessage.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQMessage.java index cc6c486e11..b38da53406 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQMessage.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQMessage.java @@ -22,6 +22,7 @@ package org.apache.qpid.server.queue; import org.apache.qpid.server.store.StoreContext; import org.apache.qpid.AMQException; +import org.apache.qpid.framing.abstraction.MessagePublishInfoImpl; public class MockAMQMessage extends TransientAMQMessage { @@ -29,6 +30,7 @@ public class MockAMQMessage extends TransientAMQMessage throws AMQException { super(messageId); + _messagePublishInfo = new MessagePublishInfoImpl(null,false,false,null); } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java index 39b78b99d1..d9e4cc9b70 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java @@ -115,6 +115,11 @@ public class MockAMQQueue implements AMQQueue return false; //To change body of implemented methods use File | Settings | File Templates. } + public boolean isFlowed() + { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + public int getMessageCount() { return 0; //To change body of implemented methods use File | Settings | File Templates. @@ -216,6 +221,26 @@ public class MockAMQQueue implements AMQQueue //To change body of implemented methods use File | Settings | File Templates. } + public long getMemoryUsageMaximum() + { + return 0; //To change body of implemented methods use File | Settings | File Templates. + } + + public void setMemoryUsageMaximum(long maximumMemoryUsage) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public long getMemoryUsageMinimum() + { + return 0; //To change body of implemented methods use File | Settings | File Templates. + } + + public void setMemoryUsageMinimum(long minimumMemoryUsage) + { + //To change body of implemented methods use File | Settings | File Templates. + } + public long getMaximumMessageSize() { return 0; //To change body of implemented methods use File | Settings | File Templates. @@ -271,7 +296,6 @@ public class MockAMQQueue implements AMQQueue return 0; //To change body of implemented methods use File | Settings | File Templates. } - @Override public void checkMessageStatus() throws AMQException { //To change body of implemented methods use File | Settings | File Templates. @@ -302,6 +326,11 @@ public class MockAMQQueue implements AMQQueue //To change body of implemented methods use File | Settings | File Templates. } + public long getMemoryUsageCurrent() + { + return 0; + } + public ManagedObject getManagedObject() { return null; //To change body of implemented methods use File | Settings | File Templates. @@ -312,7 +341,6 @@ public class MockAMQQueue implements AMQQueue return 0; //To change body of implemented methods use File | Settings | File Templates. } - @Override public void setMinimumAlertRepeatGap(long value) { diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java index f7cd860c22..9e12e1bef7 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java @@ -21,16 +21,25 @@ package org.apache.qpid.server.queue; import junit.framework.TestCase; +import org.apache.qpid.AMQException; +import org.apache.qpid.framing.BasicContentHeaderProperties; +import org.apache.qpid.framing.ContentHeaderBody; +import org.apache.qpid.framing.ContentHeaderProperties; +import org.apache.qpid.framing.abstraction.ContentChunk; +import org.apache.qpid.framing.abstraction.MessagePublishInfo; +import org.apache.qpid.framing.abstraction.MessagePublishInfoImpl; +import org.apache.qpid.server.store.StoreContext; + +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; public class QueueEntryImplTest extends TestCase { - /** - * Test the Redelivered state of a QueueEntryImpl - */ + /** Test the Redelivered state of a QueueEntryImpl */ public void testRedelivered() { - QueueEntry entry = new QueueEntryImpl(null, null); + QueueEntry entry = new MockQueueEntry(null); assertFalse("New message should not be redelivered", entry.isRedelivered()); @@ -45,5 +54,187 @@ public class QueueEntryImplTest extends TestCase } + public void testImmediateAndNotDelivered() + { + AMQMessage message = MessageFactory.getInstance().createMessage(null, false); + + MessagePublishInfo mpi = new MessagePublishInfoImpl(null, true, false, null); + int bodySize = 0; + + BasicContentHeaderProperties props = new BasicContentHeaderProperties(); + + props.setAppId("HandleTest"); + + ContentHeaderBody chb = new ContentHeaderBody(0, 0, props, bodySize); + + try + { + message.setPublishAndContentHeaderBody(null, mpi, chb); + + QueueEntry queueEntry = new MockQueueEntry(message); + + assertTrue("Undelivered Immediate message should still be marked as so", queueEntry.immediateAndNotDelivered()); + + assertFalse("Undelivered Message should not say it is delivered.", queueEntry.getDeliveredToConsumer()); + + queueEntry.setDeliveredToConsumer(); + + assertTrue("Delivered Message should say it is delivered.", queueEntry.getDeliveredToConsumer()); + + assertFalse("Delivered Immediate message now be marked as so", queueEntry.immediateAndNotDelivered()); + } + catch (AMQException e) + { + fail(e.getMessage()); + } + } + + public void testNotImmediateAndNotDelivered() + { + AMQMessage message = MessageFactory.getInstance().createMessage(null, false); + + MessagePublishInfo mpi = new MessagePublishInfoImpl(null, false, false, null); + int bodySize = 0; + + BasicContentHeaderProperties props = new BasicContentHeaderProperties(); + + props.setAppId("HandleTest"); + + ContentHeaderBody chb = new ContentHeaderBody(0, 0, props, bodySize); + + try + { + message.setPublishAndContentHeaderBody(null, mpi, chb); + + QueueEntry queueEntry = new MockQueueEntry(message); + + assertFalse("Undelivered Non-Immediate message should not result in true.", queueEntry.immediateAndNotDelivered()); + + assertFalse("Undelivered Message should not say it is delivered.", queueEntry.getDeliveredToConsumer()); + + queueEntry.setDeliveredToConsumer(); + + assertTrue("Delivered Message should say it is delivered.", queueEntry.getDeliveredToConsumer()); + + assertFalse("Delivered Non-Immediate message not change this return", queueEntry.immediateAndNotDelivered()); + } + catch (AMQException e) + { + fail(e.getMessage()); + } + } + + public void testExpiry() + { + AMQMessage message = MessageFactory.getInstance().createMessage(null, false); + + MessagePublishInfo mpi = new MessagePublishInfoImpl(null, false, false, null); + int bodySize = 0; + + BasicContentHeaderProperties props = new BasicContentHeaderProperties(); + + props.setAppId("HandleTest"); + + ContentHeaderBody chb = new ContentHeaderBody(0, 0, props, bodySize); + + ReentrantLock waitLock = new ReentrantLock(); + Condition wait = waitLock.newCondition(); + try + { + message.setExpiration(System.currentTimeMillis() + 10L); + + message.setPublishAndContentHeaderBody(null, mpi, chb); + + QueueEntry queueEntry = new MockQueueEntry(message); + + assertFalse("New messages should not be expired.", queueEntry.expired()); + + final long MILLIS = 1000000L; + long waitTime = 20 * MILLIS; + + while (waitTime > 0) + { + try + { + waitLock.lock(); + + waitTime = wait.awaitNanos(waitTime); + } + catch (InterruptedException e) + { + //Stop if we are interrupted + fail(e.getMessage()); + } + finally + { + waitLock.unlock(); + } + + } + + assertTrue("After a sleep messages should now be expired.", queueEntry.expired()); + + } + catch (AMQException e) + { + fail(e.getMessage()); + } + } + + public void testNoExpiry() + { + AMQMessage message = MessageFactory.getInstance().createMessage(null, false); + + MessagePublishInfo mpi = new MessagePublishInfoImpl(null, false, false, null); + int bodySize = 0; + + BasicContentHeaderProperties props = new BasicContentHeaderProperties(); + + props.setAppId("HandleTest"); + + ContentHeaderBody chb = new ContentHeaderBody(0, 0, props, bodySize); + + ReentrantLock waitLock = new ReentrantLock(); + Condition wait = waitLock.newCondition(); + try + { + + message.setPublishAndContentHeaderBody(null, mpi, chb); + + QueueEntry queueEntry = new MockQueueEntry(message); + + assertFalse("New messages should not be expired.", queueEntry.expired()); + + final long MILLIS = 1000000L; + long waitTime = 10 * MILLIS; + + while (waitTime > 0) + { + try + { + waitLock.lock(); + + waitTime = wait.awaitNanos(waitTime); + } + catch (InterruptedException e) + { + //Stop if we are interrupted + fail(e.getMessage()); + } + finally + { + waitLock.unlock(); + } + + } + + assertFalse("After a sleep messages without an expiry should not expire.", queueEntry.expired()); + + } + catch (AMQException e) + { + fail(e.getMessage()); + } + } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java index 7a97837208..f39dfe765e 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java @@ -21,8 +21,6 @@ package org.apache.qpid.server.queue; */ import junit.framework.TestCase; - -import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.qpid.AMQException; import org.apache.qpid.framing.AMQShortString; @@ -31,17 +29,18 @@ import org.apache.qpid.framing.ContentHeaderBody; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.framing.abstraction.MessagePublishInfo; import org.apache.qpid.framing.abstraction.MessagePublishInfoImpl; +import org.apache.qpid.framing.amqp_8_0.BasicConsumeBodyImpl; import org.apache.qpid.server.configuration.VirtualHostConfiguration; import org.apache.qpid.server.exchange.DirectExchange; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.store.StoreContext; -import org.apache.qpid.server.store.TestableMemoryMessageStore; import org.apache.qpid.server.store.TestTransactionLog; +import org.apache.qpid.server.store.TestableMemoryMessageStore; import org.apache.qpid.server.subscription.MockSubscription; import org.apache.qpid.server.subscription.Subscription; import org.apache.qpid.server.txn.NonTransactionalContext; +import org.apache.qpid.server.txn.TransactionalContext; import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.server.transactionlog.TransactionLog; import java.util.ArrayList; import java.util.List; @@ -51,7 +50,7 @@ public class SimpleAMQQueueTest extends TestCase protected SimpleAMQQueue _queue; protected VirtualHost _virtualHost; - protected TestableMemoryMessageStore _store = new TestableMemoryMessageStore(); + protected TestableMemoryMessageStore _transactionLog = new TestableMemoryMessageStore(); protected AMQShortString _qname = new AMQShortString("qname"); protected AMQShortString _owner = new AMQShortString("owner"); protected AMQShortString _routingKey = new AMQShortString("routing key"); @@ -60,7 +59,7 @@ public class SimpleAMQQueueTest extends TestCase protected FieldTable _arguments = null; MessagePublishInfo info = new MessagePublishInfoImpl(); - private static final long MESSAGE_SIZE = 100; + protected static long MESSAGE_SIZE = 100; @Override protected void setUp() throws Exception @@ -70,7 +69,7 @@ public class SimpleAMQQueueTest extends TestCase ApplicationRegistry applicationRegistry = (ApplicationRegistry) ApplicationRegistry.getInstance(1); PropertiesConfiguration env = new PropertiesConfiguration(); - _virtualHost = new VirtualHost(new VirtualHostConfiguration(getClass().getName(), env), _store); + _virtualHost = new VirtualHost(new VirtualHostConfiguration(getClass().getSimpleName(), env), _transactionLog); applicationRegistry.getVirtualHostRegistry().registerVirtualHost(_virtualHost); _queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(_qname, false, _owner, false, _virtualHost, _arguments); @@ -320,8 +319,8 @@ public class SimpleAMQQueueTest extends TestCase public void testEnqueueDequeueOfPersistentMessageToNonDurableQueue() throws AMQException { // Create IncomingMessage and nondurable queue - NonTransactionalContext txnContext = new NonTransactionalContext(_store, null, null, null); - IncomingMessage msg = new IncomingMessage(info, txnContext, new MockProtocolSession(_store), _store); + NonTransactionalContext txnContext = new NonTransactionalContext(_transactionLog, null, null, null); + IncomingMessage msg = new IncomingMessage(info, txnContext, new MockProtocolSession(_transactionLog), _transactionLog); ContentHeaderBody contentHeaderBody = new ContentHeaderBody(); contentHeaderBody.properties = new BasicContentHeaderProperties(); @@ -335,18 +334,18 @@ public class SimpleAMQQueueTest extends TestCase // Send persistent message qs.add(_queue); msg.enqueue(qs); - msg.routingComplete(_store); + msg.routingComplete(_transactionLog); - _store.storeMessageMetaData(null, messageId, new MessageMetaData(info, contentHeaderBody, 1)); + _transactionLog.storeMessageMetaData(null, messageId, new MessageMetaData(info, contentHeaderBody, 1)); // Check that it is enqueued - List data = _store.getMessageReferenceMap(messageId); + List data = _transactionLog.getMessageReferenceMap(messageId); assertNotNull(data); // Dequeue message ContentHeaderBody header = new ContentHeaderBody(); header.bodySize = MESSAGE_SIZE; - AMQMessage message = new MockPersistentAMQMessage(msg.getMessageId(), _store); + AMQMessage message = new MockPersistentAMQMessage(msg.getMessageId(), _transactionLog); message.setPublishAndContentHeaderBody(new StoreContext(), info, header); MockQueueEntry entry = new MockQueueEntry(message, _queue); @@ -355,10 +354,164 @@ public class SimpleAMQQueueTest extends TestCase entry.dequeue(null); // Check that it is dequeued - data = _store.getMessageReferenceMap(messageId); + data = _transactionLog.getMessageReferenceMap(messageId); assertNull(data); } + public void testMessagesFlowToDisk() throws AMQException, InterruptedException + { + // Create IncomingMessage and nondurable queue + NonTransactionalContext txnContext = new NonTransactionalContext(_transactionLog, null, null, null); + + MESSAGE_SIZE = 1; + long MEMORY_MAX = 500; + int MESSAGE_COUNT = (int) MEMORY_MAX * 2; + //Set the Memory Usage to be very low + _queue.setMemoryUsageMaximum(MEMORY_MAX); + + for (int msgCount = 0; msgCount < MESSAGE_COUNT / 2; msgCount++) + { + sendMessage(txnContext); + } + + //Check that we can hold 10 messages without flowing + assertEquals(MESSAGE_COUNT / 2, _queue.getMessageCount()); + assertEquals(MEMORY_MAX, _queue.getMemoryUsageCurrent()); + assertTrue("Queue is flowed.", !_queue.isFlowed()); + + // Send anothe and ensure we are flowed + sendMessage(txnContext); + assertEquals(MESSAGE_COUNT / 2 + 1, _queue.getMessageCount()); + assertEquals(MESSAGE_COUNT / 2, _queue.getMemoryUsageCurrent()); + assertTrue("Queue is not flowed.", _queue.isFlowed()); + + //send another 99 so there are 200msgs in total on the queue + for (int msgCount = 0; msgCount < (MESSAGE_COUNT / 2) - 1; msgCount++) + { + sendMessage(txnContext); + + long usage = _queue.getMemoryUsageCurrent(); + assertTrue("Queue has gone over quota:" + usage, + usage <= _queue.getMemoryUsageMaximum()); + + assertTrue("Queue has a negative quota:" + usage, usage > 0); + + } + assertEquals(MESSAGE_COUNT, _queue.getMessageCount()); + assertEquals(MEMORY_MAX, _queue.getMemoryUsageCurrent()); + assertTrue("Queue is not flowed.", _queue.isFlowed()); + + _queue.registerSubscription(_subscription, false); + + int slept = 0; + while (_subscription.getQueueEntries().size() != MESSAGE_COUNT && slept < 10) + { + Thread.sleep(500); + slept++; + } + + //Ensure the messages are retreived + assertEquals("Not all messages were received, slept:" + slept / 2 + "s", MESSAGE_COUNT, _subscription.getQueueEntries().size()); + + //Check the queue is still within it's limits. + long current = _queue.getMemoryUsageCurrent(); + assertTrue("Queue has gone over quota:" + current + "/" + _queue.getMemoryUsageMaximum(), + current <= _queue.getMemoryUsageMaximum()); + + assertTrue("Queue has a negative quota:" + _queue.getMemoryUsageCurrent(), _queue.getMemoryUsageCurrent() >= 0); + + for (int index = 0; index < MESSAGE_COUNT; index++) + { + // Ensure that we have received the messages and it wasn't flushed to disk before we received it. + AMQMessage message = _subscription.getMessages().get(index); + assertNotNull("Message:" + message.debugIdentity() + " was null.", message); + } + } + + public void testMessagesFlowToDiskPurger() throws AMQException, InterruptedException + { + // Create IncomingMessage and nondurable queue + NonTransactionalContext txnContext = new NonTransactionalContext(_transactionLog, null, null, null); + + MESSAGE_SIZE = 1; + /** Set to larger than the purge batch size. Default 100. + * @see FlowableBaseQueueEntryList.BATCH_PROCESS_COUNT */ + long MEMORY_MAX = 500; + int MESSAGE_COUNT = (int) MEMORY_MAX; + //Set the Memory Usage to be very low + _queue.setMemoryUsageMaximum(MEMORY_MAX); + + for (int msgCount = 0; msgCount < MESSAGE_COUNT; msgCount++) + { + sendMessage(txnContext); + } + + //Check that we can hold all messages without flowing + assertEquals(MESSAGE_COUNT, _queue.getMessageCount()); + assertEquals(MEMORY_MAX, _queue.getMemoryUsageCurrent()); + assertTrue("Queue is flowed.", !_queue.isFlowed()); + + // Send anothe and ensure we are flowed + sendMessage(txnContext); + assertEquals(MESSAGE_COUNT + 1, _queue.getMessageCount()); + assertEquals(MESSAGE_COUNT, _queue.getMemoryUsageCurrent()); + assertTrue("Queue is not flowed.", _queue.isFlowed()); + + _queue.setMemoryUsageMaximum(0L); + + //Give the purger time to work maximum of 1s + int slept = 0; + while (_queue.getMemoryUsageCurrent() > 0 && slept < 5) + { + Thread.yield(); + Thread.sleep(200); + slept++; + } + + assertEquals(MESSAGE_COUNT + 1, _queue.getMessageCount()); + assertEquals(0L, _queue.getMemoryUsageCurrent()); + assertTrue("Queue is not flowed.", _queue.isFlowed()); + + } + + protected void sendMessage(TransactionalContext txnContext) throws AMQException + { + sendMessage(txnContext, 5); + } + + protected void sendMessage(TransactionalContext txnContext, int priority) throws AMQException + { + IncomingMessage msg = new IncomingMessage(info, txnContext, new MockProtocolSession(_transactionLog), _transactionLog); + + ContentHeaderBody contentHeaderBody = new ContentHeaderBody(); + contentHeaderBody.classId = BasicConsumeBodyImpl.CLASS_ID; + contentHeaderBody.bodySize = MESSAGE_SIZE; + contentHeaderBody.properties = new BasicContentHeaderProperties(); + ((BasicContentHeaderProperties) contentHeaderBody.properties).setDeliveryMode((byte) 2); + ((BasicContentHeaderProperties) contentHeaderBody.properties).setPriority((byte) priority); + msg.setContentHeaderBody(contentHeaderBody); + + long messageId = msg.getMessageId(); + + ArrayList qs = new ArrayList(); + + // Send persistent 10 messages + + qs.add(_queue); + msg.enqueue(qs); + + msg.routingComplete(_transactionLog); + + msg.addContentBodyFrame(new MockContentChunk(1)); + + msg.deliverToQueues(); + + //Check message was correctly enqueued + List data = _transactionLog.getMessageReferenceMap(messageId); + assertNotNull(data); + } + + // FIXME: move this to somewhere useful private static AMQMessage createMessage(final MessagePublishInfo publishBody) { @@ -384,7 +537,7 @@ public class SimpleAMQQueueTest extends TestCase public AMQMessage createMessage() throws AMQException { - AMQMessage message = new TestMessage(info, _store); + AMQMessage message = new TestMessage(info, _transactionLog); ContentHeaderBody header = new ContentHeaderBody(); header.bodySize = MESSAGE_SIZE; @@ -410,7 +563,6 @@ public class SimpleAMQQueueTest extends TestCase _transactionLog = transactionLog; } - void assertCountEquals(int expected) { assertEquals("Wrong count for message with tag " + _tag, expected, diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java deleted file mode 100644 index f45d887dec..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.queue; - -import junit.framework.TestCase; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.pool.ReferenceCountingExecutorService; -import org.apache.qpid.server.virtualhost.VirtualHost; - -import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.AMQException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SimpleAMQQueueThreadPoolTest extends TestCase -{ - - public void test() throws AMQException - { - assertEquals("References exist before start!", 0, ReferenceCountingExecutorService.getInstance().getReferenceCount()); - VirtualHost test = ApplicationRegistry.getInstance(1).getVirtualHostRegistry().getVirtualHost("test"); - - try - { - SimpleAMQQueue queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(new AMQShortString("test"), false, - new AMQShortString("owner"), - false, test, null); - - assertFalse("Creation did not start Pool.", ReferenceCountingExecutorService.getInstance().getPool().isShutdown()); - - queue.stop(); - - assertEquals("References still exist", 0, ReferenceCountingExecutorService.getInstance().getReferenceCount()); - - assertTrue("Stop did not clean up.", ReferenceCountingExecutorService.getInstance().getPool().isShutdown()); - } - finally - { - ApplicationRegistry.remove(1); - } - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/TransientMessageTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/TransientMessageTest.java index 16d1ab60f3..6fd153f398 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/TransientMessageTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/TransientMessageTest.java @@ -287,180 +287,5 @@ public class TransientMessageTest extends TestCase assertFalse(_message.isPersistent()); } - public void testImmediateAndNotDelivered() - { - _message = newMessage(); - - MessagePublishInfo mpi = new MessagePublishInfoImpl(null, true, false, null); - int bodySize = 0; - - BasicContentHeaderProperties props = new BasicContentHeaderProperties(); - - props.setAppId("HandleTest"); - - ContentHeaderBody chb = new ContentHeaderBody(0, 0, props, bodySize); - - try - { - _message.setPublishAndContentHeaderBody(_storeContext, mpi, chb); - - assertTrue("Undelivered Immediate message should still be marked as so", _message.immediateAndNotDelivered()); - - assertFalse("Undelivered Message should not say it is delivered.", _message.getDeliveredToConsumer()); - - _message.setDeliveredToConsumer(); - - assertTrue("Delivered Message should say it is delivered.", _message.getDeliveredToConsumer()); - - assertFalse("Delivered Immediate message now be marked as so", _message.immediateAndNotDelivered()); - } - catch (AMQException e) - { - fail(e.getMessage()); - } - } - - public void testNotImmediateAndNotDelivered() - { - _message = newMessage(); - - MessagePublishInfo mpi = new MessagePublishInfoImpl(null, false, false, null); - int bodySize = 0; - - BasicContentHeaderProperties props = new BasicContentHeaderProperties(); - - props.setAppId("HandleTest"); - - ContentHeaderBody chb = new ContentHeaderBody(0, 0, props, bodySize); - - try - { - _message.setPublishAndContentHeaderBody(_storeContext, mpi, chb); - - assertFalse("Undelivered Non-Immediate message should not result in true.", _message.immediateAndNotDelivered()); - - assertFalse("Undelivered Message should not say it is delivered.", _message.getDeliveredToConsumer()); - - _message.setDeliveredToConsumer(); - - assertTrue("Delivered Message should say it is delivered.", _message.getDeliveredToConsumer()); - - assertFalse("Delivered Non-Immediate message not change this return", _message.immediateAndNotDelivered()); - } - catch (AMQException e) - { - fail(e.getMessage()); - } - } - - public void testExpiry() - { - _message = newMessage(); - - MessagePublishInfo mpi = new MessagePublishInfoImpl(null, false, false, null); - int bodySize = 0; - - BasicContentHeaderProperties props = new BasicContentHeaderProperties(); - - props.setAppId("HandleTest"); - - ContentHeaderBody chb = new ContentHeaderBody(0, 0, props, bodySize); - - ReentrantLock waitLock = new ReentrantLock(); - Condition wait = waitLock.newCondition(); - try - { - _message.setExpiration(System.currentTimeMillis() + 10L); - - _message.setPublishAndContentHeaderBody(_storeContext, mpi, chb); - - assertFalse("New messages should not be expired.", _message.expired()); - - final long MILLIS =1000000L; - long waitTime = 20 * MILLIS; - - while (waitTime > 0) - { - try - { - waitLock.lock(); - - waitTime = wait.awaitNanos(waitTime); - } - catch (InterruptedException e) - { - //Stop if we are interrupted - fail(e.getMessage()); - } - finally - { - waitLock.unlock(); - } - - } - - assertTrue("After a sleep messages should now be expired.", _message.expired()); - - } - catch (AMQException e) - { - fail(e.getMessage()); - } - } - - - public void testNoExpiry() - { - _message = newMessage(); - - MessagePublishInfo mpi = new MessagePublishInfoImpl(null, false, false, null); - int bodySize = 0; - - BasicContentHeaderProperties props = new BasicContentHeaderProperties(); - - props.setAppId("HandleTest"); - - ContentHeaderBody chb = new ContentHeaderBody(0, 0, props, bodySize); - - ReentrantLock waitLock = new ReentrantLock(); - Condition wait = waitLock.newCondition(); - try - { - - _message.setPublishAndContentHeaderBody(_storeContext, mpi, chb); - - assertFalse("New messages should not be expired.", _message.expired()); - - final long MILLIS =1000000L; - long waitTime = 10 * MILLIS; - - while (waitTime > 0) - { - try - { - waitLock.lock(); - - waitTime = wait.awaitNanos(waitTime); - } - catch (InterruptedException e) - { - //Stop if we are interrupted - fail(e.getMessage()); - } - finally - { - waitLock.unlock(); - } - - } - - assertFalse("After a sleep messages without an expiry should not expire.", _message.expired()); - - } - catch (AMQException e) - { - fail(e.getMessage()); - } - } - + } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/access/ACLManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/access/ACLManagerTest.java index 797df0802c..6c6835ccca 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/access/ACLManagerTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/access/ACLManagerTest.java @@ -27,6 +27,7 @@ import java.io.FileWriter; import junit.framework.TestCase; import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.XMLConfiguration; import org.apache.qpid.server.configuration.SecurityConfiguration; @@ -79,7 +80,7 @@ public class ACLManagerTest extends TestCase assertTrue(_authzManager.authorisePurge(_session, queue)); } - public void testACLManagerConfigurationPluginManagerACLPlugin() + public void testACLManagerConfigurationPluginManagerACLPlugin() throws ConfigurationException { _authzManager = new ACLManager(_conf, _pluginManager, ExchangeDenier.FACTORY); @@ -87,7 +88,7 @@ public class ACLManagerTest extends TestCase assertFalse(_authzManager.authoriseDelete(_session, exchange)); } - public void testConfigurePlugins() + public void testConfigurePlugins() throws ConfigurationException { Configuration hostConfig = new PropertiesConfiguration(); hostConfig.setProperty("queueDenier", "thisoneneither"); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBeanTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBeanTest.java index f3c07d9eb2..958ee35476 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBeanTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBeanTest.java @@ -21,103 +21,213 @@ package org.apache.qpid.server.security.access.management; +import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.management.MBeanInvocationHandlerImpl; +import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; import junit.framework.TestCase; +/* Note: The main purpose is to test the jmx access rights file manipulation + * within AMQUserManagementMBean. The Principal Databases are tested by their own tests, + * this test just exercises their usage in AMQUserManagementMBean. + */ public class AMQUserManagementMBeanTest extends TestCase { - private Base64MD5PasswordFilePrincipalDatabase _database; + private PlainPasswordFilePrincipalDatabase _database; private AMQUserManagementMBean _amqumMBean; + + private File _passwordFile; + private File _accessFile; - private static final String _QPID_HOME = System.getProperty("QPID_HOME"); - - private static final String USERNAME = "testuser"; - private static final String PASSWORD = "password"; - private static final String JMXRIGHTS = "admin"; - private static final String TEMP_PASSWORD_FILE_NAME = "tempPasswordFile.tmp"; - private static final String TEMP_JMXACCESS_FILE_NAME = "tempJMXAccessFile.tmp"; + private static final String TEST_USERNAME = "testuser"; + private static final String TEST_PASSWORD = "password"; @Override protected void setUp() throws Exception { - assertNotNull("QPID_HOME not set", _QPID_HOME); - - _database = new Base64MD5PasswordFilePrincipalDatabase(); + _database = new PlainPasswordFilePrincipalDatabase(); _amqumMBean = new AMQUserManagementMBean(); + loadFreshTestPasswordFile(); + loadFreshTestAccessFile(); } @Override protected void tearDown() throws Exception { - File testFile = new File(_QPID_HOME + File.separator + TEMP_JMXACCESS_FILE_NAME + ".tmp"); - if (testFile.exists()) + _passwordFile.delete(); + _accessFile.delete(); + } + + public void testDeleteUser() + { + loadFreshTestPasswordFile(); + loadFreshTestAccessFile(); + + //try deleting a non existant user + assertFalse(_amqumMBean.deleteUser("made.up.username")); + + assertTrue(_amqumMBean.deleteUser(TEST_USERNAME)); + } + + public void testDeleteUserIsSavedToAccessFile() + { + loadFreshTestPasswordFile(); + loadFreshTestAccessFile(); + + assertTrue(_amqumMBean.deleteUser(TEST_USERNAME)); + + //check the access rights were actually deleted from the file + try{ + BufferedReader reader = new BufferedReader(new FileReader(_accessFile)); + + //check the 'generated by' comment line is present + assertTrue("File has no content", reader.ready()); + assertTrue("'Generated by' comment line was missing",reader.readLine().contains("Generated by " + + "AMQUserManagementMBean Console : Last edited by user:")); + + //there should also be a modified date/time comment line + assertTrue("File has no modified date/time comment line", reader.ready()); + assertTrue("Modification date/time comment line was missing",reader.readLine().startsWith("#")); + + //the access file should not contain any further data now as we just deleted the only user + assertFalse("User access data was present when it should have been deleted", reader.ready()); + } + catch (IOException e) { - testFile.delete(); + fail("Unable to valdate file contents due to:" + e.getMessage()); } + + } + + public void testSetRights() + { + loadFreshTestPasswordFile(); + loadFreshTestAccessFile(); + + assertFalse(_amqumMBean.setRights("made.up.username", true, false, false)); + + assertTrue(_amqumMBean.setRights(TEST_USERNAME, true, false, false)); + assertTrue(_amqumMBean.setRights(TEST_USERNAME, false, true, false)); + assertTrue(_amqumMBean.setRights(TEST_USERNAME, false, false, true)); + } + + public void testSetRightsIsSavedToAccessFile() + { + loadFreshTestPasswordFile(); + loadFreshTestAccessFile(); + + assertTrue(_amqumMBean.setRights(TEST_USERNAME, false, false, true)); + + //check the access rights were actually updated in the file + try{ + BufferedReader reader = new BufferedReader(new FileReader(_accessFile)); + + //check the 'generated by' comment line is present + assertTrue("File has no content", reader.ready()); + assertTrue("'Generated by' comment line was missing",reader.readLine().contains("Generated by " + + "AMQUserManagementMBean Console : Last edited by user:")); - testFile = new File(_QPID_HOME + File.separator + TEMP_JMXACCESS_FILE_NAME + ".old"); - if (testFile.exists()) + //there should also be a modified date/time comment line + assertTrue("File has no modified date/time comment line", reader.ready()); + assertTrue("Modification date/time comment line was missing",reader.readLine().startsWith("#")); + + //the access file should not contain any further data now as we just deleted the only user + assertTrue("User access data was not updated in the access file", + reader.readLine().equals(TEST_USERNAME + "=" + MBeanInvocationHandlerImpl.ADMIN)); + + //the access file should not contain any further data now as we just deleted the only user + assertFalse("Additional user access data was present when there should be no more", reader.ready()); + } + catch (IOException e) { - testFile.delete(); + fail("Unable to valdate file contents due to:" + e.getMessage()); } + } - testFile = new File(_QPID_HOME + File.separator + TEMP_PASSWORD_FILE_NAME + ".tmp"); - if (testFile.exists()) + public void testMBeanVersion() + { + try { - testFile.delete(); + ObjectName name = _amqumMBean.getObjectName(); + assertEquals(AMQUserManagementMBean.VERSION, Integer.parseInt(name.getKeyProperty("version"))); } - - testFile = new File(_QPID_HOME + File.separator + TEMP_PASSWORD_FILE_NAME + ".old"); - if (testFile.exists()) + catch (MalformedObjectNameException e) { - testFile.delete(); + fail(e.getMessage()); } } - public void testDeleteUser() + public void testSetAccessFileWithMissingFile() { - loadTestPasswordFile(); - loadTestAccessFile(); - - boolean deleted = false; + try + { + _amqumMBean.setAccessFile("made.up.filename"); + } + catch (IOException e) + { + fail("Should not have been an IOE." + e.getMessage()); + } + catch (ConfigurationException e) + { + assertTrue(e.getMessage(), e.getMessage().endsWith("does not exist")); + } + } + public void testSetAccessFileWithReadOnlyFile() + { + File testFile = null; try { - deleted = _amqumMBean.deleteUser(USERNAME); + testFile = File.createTempFile(this.getClass().getName(),".access.readonly"); + BufferedWriter passwordWriter = new BufferedWriter(new FileWriter(testFile, false)); + passwordWriter.write(TEST_USERNAME + ":" + TEST_PASSWORD); + passwordWriter.newLine(); + passwordWriter.flush(); + passwordWriter.close(); + + testFile.setReadOnly(); + _amqumMBean.setAccessFile(testFile.getPath()); } - catch(Exception e){ - fail("Unable to delete user: " + e.getMessage()); + catch (IOException e) + { + fail("Access file was not created." + e.getMessage()); + } + catch (ConfigurationException e) + { + fail("There should not have been a configuration exception." + e.getMessage()); } - assertTrue(deleted); + testFile.delete(); } - - + // ============================ Utility methods ========================= - private void loadTestPasswordFile() + private void loadFreshTestPasswordFile() { try { - File tempPasswordFile = new File(_QPID_HOME + File.separator + TEMP_PASSWORD_FILE_NAME); - if (tempPasswordFile.exists()) + if(_passwordFile == null) { - tempPasswordFile.delete(); + _passwordFile = File.createTempFile(this.getClass().getName(),".password"); } - tempPasswordFile.deleteOnExit(); - BufferedWriter passwordWriter = new BufferedWriter(new FileWriter(tempPasswordFile)); - passwordWriter.write(USERNAME + ":" + PASSWORD); + BufferedWriter passwordWriter = new BufferedWriter(new FileWriter(_passwordFile, false)); + passwordWriter.write(TEST_USERNAME + ":" + TEST_PASSWORD); passwordWriter.newLine(); passwordWriter.flush(); - - _database.setPasswordFile(tempPasswordFile.toString()); + passwordWriter.close(); + _database.setPasswordFile(_passwordFile.toString()); _amqumMBean.setPrincipalDatabase(_database); } catch (IOException e) @@ -126,27 +236,36 @@ public class AMQUserManagementMBeanTest extends TestCase } } - private void loadTestAccessFile() + private void loadFreshTestAccessFile() { try { - File tempAccessFile = new File(_QPID_HOME + File.separator + TEMP_JMXACCESS_FILE_NAME); - if (tempAccessFile.exists()) + if(_accessFile == null) { - tempAccessFile.delete(); + _accessFile = File.createTempFile(this.getClass().getName(),".access"); } - tempAccessFile.deleteOnExit(); - - BufferedWriter accessWriter = new BufferedWriter(new FileWriter(tempAccessFile)); - accessWriter.write(USERNAME + "=" + JMXRIGHTS); + + BufferedWriter accessWriter = new BufferedWriter(new FileWriter(_accessFile,false)); + accessWriter.write("#Last Updated By comment"); + accessWriter.newLine(); + accessWriter.write("#Date/time comment"); + accessWriter.newLine(); + accessWriter.write(TEST_USERNAME + "=" + MBeanInvocationHandlerImpl.READONLY); accessWriter.newLine(); accessWriter.flush(); + accessWriter.close(); + } + catch (IOException e) + { + fail("Unable to create test access file: " + e.getMessage()); + } - _amqumMBean.setAccessFile(tempAccessFile.toString()); + try{ + _amqumMBean.setAccessFile(_accessFile.toString()); } catch (Exception e) { - fail("Unable to create test access file: " + e.getMessage()); + fail("Unable to set access file: " + e.getMessage()); } } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java index b5034d9f5d..413b974986 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java @@ -22,8 +22,10 @@ package org.apache.qpid.server.security.auth.database; import junit.framework.TestCase; +import javax.security.auth.callback.PasswordCallback; import javax.security.auth.login.AccountNotFoundException; +import org.apache.commons.codec.binary.Base64; import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal; import java.io.BufferedReader; @@ -33,7 +35,9 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.security.Principal; +import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; @@ -41,12 +45,38 @@ public class Base64MD5PasswordFilePrincipalDatabaseTest extends TestCase { private static final String TEST_COMMENT = "# Test Comment"; - private String USERNAME = "testUser"; - private String _username = this.getClass().getName()+"username"; - private char[] _password = "password".toCharArray(); - private Principal _principal = new UsernamePrincipal(_username); + + private static final String USERNAME = "testUser"; + private static final String PASSWORD = "guest"; + private static final String PASSWORD_B64MD5HASHED = "CE4DQ6BIb/BVMN9scFyLtA=="; + private static char[] PASSWORD_MD5_CHARS; + private static final String PRINCIPAL_USERNAME = "testUserPrincipal"; + private static final Principal PRINCIPAL = new UsernamePrincipal(PRINCIPAL_USERNAME); private Base64MD5PasswordFilePrincipalDatabase _database; private File _pwdFile; + + static + { + try + { + Base64 b64 = new Base64(); + byte[] md5passBytes = PASSWORD_B64MD5HASHED.getBytes(Base64MD5PasswordFilePrincipalDatabase.DEFAULT_ENCODING); + byte[] decoded = b64.decode(md5passBytes); + + PASSWORD_MD5_CHARS = new char[decoded.length]; + + int index = 0; + for (byte c : decoded) + { + PASSWORD_MD5_CHARS[index++] = (char) c; + } + } + catch (UnsupportedEncodingException e) + { + fail("Unable to perform B64 decode to get the md5 char[] password"); + } + } + public void setUp() throws Exception { @@ -111,7 +141,56 @@ public class Base64MD5PasswordFilePrincipalDatabaseTest extends TestCase loadPasswordFile(testFile); - final String CREATED_PASSWORD = "createdPassword"; + + Principal principal = new Principal() + { + public String getName() + { + return USERNAME; + } + }; + + assertTrue("New user not created.", _database.createPrincipal(principal, PASSWORD.toCharArray())); + + PasswordCallback callback = new PasswordCallback("prompt",false); + try + { + _database.setPassword(principal, callback); + } + catch (AccountNotFoundException e) + { + fail("user account did not exist"); + } + assertTrue("Password returned was incorrect.", Arrays.equals(PASSWORD_MD5_CHARS, callback.getPassword())); + + loadPasswordFile(testFile); + + try + { + _database.setPassword(principal, callback); + } + catch (AccountNotFoundException e) + { + fail("user account did not exist"); + } + assertTrue("Password returned was incorrect.", Arrays.equals(PASSWORD_MD5_CHARS, callback.getPassword())); + + assertNotNull("Created User was not saved", _database.getUser(USERNAME)); + + assertFalse("Duplicate user created.", _database.createPrincipal(principal, PASSWORD.toCharArray())); + + testFile.delete(); + } + + public void testCreatePrincipalIsSavedToFile() + { + + File testFile = createPasswordFile(1, 0); + + loadPasswordFile(testFile); + + final String CREATED_PASSWORD = "guest"; + final String CREATED_B64MD5HASHED_PASSWORD = "CE4DQ6BIb/BVMN9scFyLtA=="; final String CREATED_USERNAME = "createdUser"; Principal principal = new Principal() @@ -122,16 +201,37 @@ public class Base64MD5PasswordFilePrincipalDatabaseTest extends TestCase } }; - assertTrue("New user not created.", _database.createPrincipal(principal, CREATED_PASSWORD.toCharArray())); + _database.createPrincipal(principal, CREATED_PASSWORD.toCharArray()); - loadPasswordFile(testFile); + try + { + BufferedReader reader = new BufferedReader(new FileReader(testFile)); + + assertTrue("File has no content", reader.ready()); + + assertEquals("Comment line has been corrupted.", TEST_COMMENT, reader.readLine()); - assertNotNull("Created User was not saved", _database.getUser(CREATED_USERNAME)); + assertTrue("File is missing user data.", reader.ready()); - assertFalse("Duplicate user created.", _database.createPrincipal(principal, CREATED_PASSWORD.toCharArray())); + String userLine = reader.readLine(); + + String[] result = Pattern.compile(":").split(userLine); + assertEquals("User line not complete '" + userLine + "'", 2, result.length); + + assertEquals("Username not correct,", CREATED_USERNAME, result[0]); + assertEquals("Password not correct,", CREATED_B64MD5HASHED_PASSWORD, result[1]); + + assertFalse("File has more content", reader.ready()); + + } + catch (IOException e) + { + fail("Unable to valdate file contents due to:" + e.getMessage()); + } testFile.delete(); } + public void testDeletePrincipal() { @@ -228,8 +328,8 @@ public class Base64MD5PasswordFilePrincipalDatabaseTest extends TestCase assertNotNull(testUser); - String NEW_PASSWORD = "NewPassword"; - String NEW_PASSWORD_HASH = "TmV3UGFzc3dvcmQ="; + String NEW_PASSWORD = "guest"; + String NEW_PASSWORD_HASH = "CE4DQ6BIb/BVMN9scFyLtA=="; try { _database.updatePassword(testUser, NEW_PASSWORD.toCharArray()); @@ -268,7 +368,7 @@ public class Base64MD5PasswordFilePrincipalDatabaseTest extends TestCase testFile.delete(); } - public void testSetPasswordWithMissingFile() + public void testSetPasswordFileWithMissingFile() { try { @@ -285,7 +385,7 @@ public class Base64MD5PasswordFilePrincipalDatabaseTest extends TestCase } - public void testSetPasswordWithReadOnlyFile() + public void testSetPasswordFileWithReadOnlyFile() { File testFile = createPasswordFile(0, 0); @@ -310,28 +410,38 @@ public class Base64MD5PasswordFilePrincipalDatabaseTest extends TestCase public void testCreateUserPrincipal() throws IOException { - _database.createPrincipal(_principal, _password); - Principal newPrincipal = _database.getUser(_username); + _database.createPrincipal(PRINCIPAL, PASSWORD.toCharArray()); + Principal newPrincipal = _database.getUser(PRINCIPAL_USERNAME); assertNotNull(newPrincipal); - assertEquals(_principal.getName(), newPrincipal.getName()); + assertEquals(PRINCIPAL.getName(), newPrincipal.getName()); } public void testVerifyPassword() throws IOException, AccountNotFoundException { testCreateUserPrincipal(); //assertFalse(_pwdDB.verifyPassword(_username, null)); - assertFalse(_database.verifyPassword(_username, new char[]{})); - assertFalse(_database.verifyPassword(_username, "massword".toCharArray())); - assertTrue(_database.verifyPassword(_username, _password)); + assertFalse(_database.verifyPassword(PRINCIPAL_USERNAME, new char[]{})); + assertFalse(_database.verifyPassword(PRINCIPAL_USERNAME, (PASSWORD+"z").toCharArray())); + assertTrue(_database.verifyPassword(PRINCIPAL_USERNAME, PASSWORD.toCharArray())); + + try + { + _database.verifyPassword("made.up.username", PASSWORD.toCharArray()); + fail("Should not have been able to verify this non-existant users password."); + } + catch (AccountNotFoundException e) + { + // pass + } } public void testUpdatePassword() throws IOException, AccountNotFoundException { testCreateUserPrincipal(); char[] newPwd = "newpassword".toCharArray(); - _database.updatePassword(_principal, newPwd); - assertFalse(_database.verifyPassword(_username, _password)); - assertTrue(_database.verifyPassword(_username, newPwd)); + _database.updatePassword(PRINCIPAL, newPwd); + assertFalse(_database.verifyPassword(PRINCIPAL_USERNAME, PASSWORD.toCharArray())); + assertTrue(_database.verifyPassword(PRINCIPAL_USERNAME, newPwd)); } - + } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/HashedUserTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/HashedUserTest.java index a7d951cb5b..aa85cac758 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/HashedUserTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/HashedUserTest.java @@ -34,7 +34,7 @@ public class HashedUserTest extends TestCase String USERNAME = "username"; String PASSWORD = "password"; - String HASHED_PASSWORD = "cGFzc3dvcmQ="; + String B64_ENCODED_PASSWORD = "cGFzc3dvcmQ="; public void testToLongArrayConstructor() { @@ -57,11 +57,11 @@ public class HashedUserTest extends TestCase { try { - HashedUser user = new HashedUser(new String[]{USERNAME, HASHED_PASSWORD}); + HashedUser user = new HashedUser(new String[]{USERNAME, B64_ENCODED_PASSWORD}); assertEquals("Username incorrect", USERNAME, user.getName()); int index = 0; - char[] hash = HASHED_PASSWORD.toCharArray(); + char[] hash = B64_ENCODED_PASSWORD.toCharArray(); try { diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java new file mode 100644 index 0000000000..20b8d0a7b4 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java @@ -0,0 +1,396 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.security.auth.database; + +import junit.framework.TestCase; + +import javax.security.auth.login.AccountNotFoundException; + +import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.security.Principal; +import java.util.List; +import java.util.regex.Pattern; + +public class PlainPasswordFilePrincipalDatabaseTest extends TestCase +{ + + private static final String TEST_COMMENT = "# Test Comment"; + private static final String TEST_PASSWORD = "testPassword"; + private static final char[] TEST_PASSWORD_CHARS = TEST_PASSWORD.toCharArray(); + private static final String TEST_USERNAME = "testUser"; + + private Principal _principal = new UsernamePrincipal(TEST_USERNAME); + private PlainPasswordFilePrincipalDatabase _database; + + public void setUp() throws Exception + { + _database = new PlainPasswordFilePrincipalDatabase(); + } + + // ******* Test Methods ********** // + + public void testCreatePrincipal() + { + File testFile = createPasswordFile(1, 0); + + loadPasswordFile(testFile); + + final String CREATED_PASSWORD = "guest"; + final String CREATED_USERNAME = "createdUser"; + + Principal principal = new Principal() + { + public String getName() + { + return CREATED_USERNAME; + } + }; + + assertTrue("New user not created.", _database.createPrincipal(principal, CREATED_PASSWORD.toCharArray())); + + loadPasswordFile(testFile); + + assertNotNull("Created User was not saved", _database.getUser(CREATED_USERNAME)); + + assertFalse("Duplicate user created.", _database.createPrincipal(principal, CREATED_PASSWORD.toCharArray())); + + testFile.delete(); + } + + public void testCreatePrincipalIsSavedToFile() + { + + File testFile = createPasswordFile(1, 0); + + loadPasswordFile(testFile); + + Principal principal = new Principal() + { + public String getName() + { + return TEST_USERNAME; + } + }; + + _database.createPrincipal(principal, TEST_PASSWORD_CHARS); + + try + { + BufferedReader reader = new BufferedReader(new FileReader(testFile)); + + assertTrue("File has no content", reader.ready()); + + assertEquals("Comment line has been corrupted.", TEST_COMMENT, reader.readLine()); + + assertTrue("File is missing user data.", reader.ready()); + + String userLine = reader.readLine(); + + String[] result = Pattern.compile(":").split(userLine); + + assertEquals("User line not complete '" + userLine + "'", 2, result.length); + + assertEquals("Username not correct,", TEST_USERNAME, result[0]); + assertEquals("Password not correct,", TEST_PASSWORD, result[1]); + + assertFalse("File has more content", reader.ready()); + + } + catch (IOException e) + { + fail("Unable to valdate file contents due to:" + e.getMessage()); + } + testFile.delete(); + } + + public void testDeletePrincipal() + { + File testFile = createPasswordFile(1, 1); + + loadPasswordFile(testFile); + + Principal user = _database.getUser(TEST_USERNAME + "0"); + assertNotNull("Generated user not present.", user); + + try + { + _database.deletePrincipal(user); + } + catch (AccountNotFoundException e) + { + fail("User should be present" + e.getMessage()); + } + + try + { + _database.deletePrincipal(user); + fail("User should not be present"); + } + catch (AccountNotFoundException e) + { + //pass + } + + loadPasswordFile(testFile); + + try + { + _database.deletePrincipal(user); + fail("User should not be present"); + } + catch (AccountNotFoundException e) + { + //pass + } + + assertNull("Deleted user still present.", _database.getUser(TEST_USERNAME + "0")); + + testFile.delete(); + } + + public void testGetUsers() + { + int USER_COUNT = 10; + File testFile = createPasswordFile(1, USER_COUNT); + + loadPasswordFile(testFile); + + Principal user = _database.getUser("MISSING_USERNAME"); + assertNull("Missing user present.", user); + + List users = _database.getUsers(); + + assertNotNull("Users list is null.", users); + + assertEquals(USER_COUNT, users.size()); + + boolean[] verify = new boolean[USER_COUNT]; + for (int i = 0; i < USER_COUNT; i++) + { + Principal principal = users.get(i); + + assertNotNull("Generated user not present.", principal); + + String name = principal.getName(); + + int id = Integer.parseInt(name.substring(TEST_USERNAME.length())); + + assertFalse("Duplicated username retrieve", verify[id]); + verify[id] = true; + } + + for (int i = 0; i < USER_COUNT; i++) + { + assertTrue("User " + i + " missing", verify[i]); + } + + testFile.delete(); + } + + public void testUpdatePasswordIsSavedToFile() + { + + File testFile = createPasswordFile(1, 1); + + loadPasswordFile(testFile); + + Principal testUser = _database.getUser(TEST_USERNAME + "0"); + + assertNotNull(testUser); + + String NEW_PASSWORD = "NewPassword"; + try + { + _database.updatePassword(testUser, NEW_PASSWORD.toCharArray()); + } + catch (AccountNotFoundException e) + { + fail(e.toString()); + } + + try + { + BufferedReader reader = new BufferedReader(new FileReader(testFile)); + + assertTrue("File has no content", reader.ready()); + + assertEquals("Comment line has been corrupted.", TEST_COMMENT, reader.readLine()); + + assertTrue("File is missing user data.", reader.ready()); + + String userLine = reader.readLine(); + + String[] result = Pattern.compile(":").split(userLine); + + assertEquals("User line not complete '" + userLine + "'", 2, result.length); + + assertEquals("Username not correct,", TEST_USERNAME + "0", result[0]); + assertEquals("New Password not correct,", NEW_PASSWORD, result[1]); + + assertFalse("File has more content", reader.ready()); + + } + catch (IOException e) + { + fail("Unable to valdate file contents due to:" + e.getMessage()); + } + testFile.delete(); + } + + public void testSetPasswordFileWithMissingFile() + { + try + { + _database.setPasswordFile("DoesntExist"); + } + catch (FileNotFoundException fnfe) + { + assertTrue(fnfe.getMessage(), fnfe.getMessage().startsWith("Cannot find password file")); + } + catch (IOException e) + { + fail("Password File was not created." + e.getMessage()); + } + + } + + public void testSetPasswordFileWithReadOnlyFile() + { + + File testFile = createPasswordFile(0, 0); + + testFile.setReadOnly(); + + try + { + _database.setPasswordFile(testFile.toString()); + } + catch (FileNotFoundException fnfe) + { + assertTrue(fnfe.getMessage().startsWith("Cannot read password file ")); + } + catch (IOException e) + { + fail("Password File was not created." + e.getMessage()); + } + + testFile.delete(); + } + + private void createUserPrincipal() throws IOException + { + File testFile = createPasswordFile(0, 0); + loadPasswordFile(testFile); + + _database.createPrincipal(_principal, TEST_PASSWORD_CHARS); + Principal newPrincipal = _database.getUser(TEST_USERNAME); + assertNotNull(newPrincipal); + assertEquals(_principal.getName(), newPrincipal.getName()); + } + + public void testVerifyPassword() throws IOException, AccountNotFoundException + { + createUserPrincipal(); + assertFalse(_database.verifyPassword(TEST_USERNAME, new char[]{})); + assertFalse(_database.verifyPassword(TEST_USERNAME, "massword".toCharArray())); + assertTrue(_database.verifyPassword(TEST_USERNAME, TEST_PASSWORD_CHARS)); + + try + { + _database.verifyPassword("made.up.username", TEST_PASSWORD_CHARS); + fail("Should not have been able to verify this non-existant users password."); + } + catch (AccountNotFoundException e) + { + // pass + } + } + + public void testUpdatePassword() throws IOException, AccountNotFoundException + { + createUserPrincipal(); + char[] newPwd = "newpassword".toCharArray(); + _database.updatePassword(_principal, newPwd); + assertFalse(_database.verifyPassword(TEST_USERNAME, TEST_PASSWORD_CHARS)); + assertTrue(_database.verifyPassword(TEST_USERNAME, newPwd)); + } + + + + // *********** Utility Methods ******** // + + private File createPasswordFile(int commentLines, int users) + { + try + { + File testFile = File.createTempFile(this.getClass().getName(),"tmp"); + testFile.deleteOnExit(); + + BufferedWriter writer = new BufferedWriter(new FileWriter(testFile)); + + for (int i = 0; i < commentLines; i++) + { + writer.write(TEST_COMMENT); + writer.newLine(); + } + + for (int i = 0; i < users; i++) + { + writer.write(TEST_USERNAME + i + ":" + TEST_PASSWORD); + writer.newLine(); + } + + writer.flush(); + writer.close(); + + return testFile; + + } + catch (IOException e) + { + fail("Unable to create test password file." + e.getMessage()); + } + + return null; + } + + private void loadPasswordFile(File file) + { + try + { + _database.setPasswordFile(file.toString()); + } + catch (IOException e) + { + fail("Password File was not created." + e.getMessage()); + } + } + + +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainUserTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainUserTest.java new file mode 100644 index 0000000000..7f0843d46e --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainUserTest.java @@ -0,0 +1,78 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.security.auth.database; + +import junit.framework.TestCase; + +/* + Note PlainUser is mainly tested by PlainPFPDTest, this is just to catch the extra methods + */ +public class PlainUserTest extends TestCase +{ + + String USERNAME = "username"; + String PASSWORD = "password"; + + public void testTooLongArrayConstructor() + { + try + { + PlainUser user = new PlainUser(new String[]{USERNAME, PASSWORD, USERNAME}); + fail("Error expected"); + } + catch (IllegalArgumentException e) + { + assertEquals("User Data should be length 2, username, password", e.getMessage()); + } + } + + public void testStringArrayConstructor() + { + PlainUser user = new PlainUser(new String[]{USERNAME, PASSWORD}); + assertEquals("Username incorrect", USERNAME, user.getName()); + int index = 0; + + char[] password = PASSWORD.toCharArray(); + + try + { + for (byte c : user.getPasswordBytes()) + { + assertEquals("Password incorrect", password[index], (char) c); + index++; + } + } + catch (Exception e) + { + fail(e.getMessage()); + } + + password = PASSWORD.toCharArray(); + + index=0; + for (char c : user.getPassword()) + { + assertEquals("Password incorrect", password[index], c); + index++; + } + } +} + diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java index 33fd669d5c..ab0870144b 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java @@ -30,10 +30,13 @@ import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.server.AMQChannel; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.QueueEntry; +import org.apache.qpid.server.queue.AMQMessage; import org.apache.qpid.server.queue.QueueEntry.SubscriptionAcquiredState; +import org.apache.log4j.Logger; public class MockSubscription implements Subscription { + private static final Logger _logger = Logger.getLogger(MockSubscription.class); private boolean _closed = false; private AMQShortString tag = new AMQShortString("mocktag"); @@ -41,8 +44,12 @@ public class MockSubscription implements Subscription private StateListener _listener = null; private QueueEntry lastSeen = null; private State _state = State.ACTIVE; - private ArrayList messages = new ArrayList(); + private ArrayList _queueEntries = new ArrayList(); private final Lock _stateChangeLock = new ReentrantLock(); + private ArrayList _messages = new ArrayList(); + + + public void close() { @@ -136,10 +143,14 @@ public class MockSubscription implements Subscription { } - public void send(QueueEntry msg) throws AMQException + public void send(QueueEntry entry) throws AMQException { - lastSeen = msg; - messages.add(msg); + _logger.info("Sending Message(" + entry.debugIdentity() + ") to subscription:" + this); + + lastSeen = entry; + _queueEntries.add(entry); + _messages.add(entry.getMessage()); + entry.setDeliveredToSubscription(); } public boolean setLastSeenEntry(QueueEntry expected, QueueEntry newValue) @@ -173,8 +184,14 @@ public class MockSubscription implements Subscription return false; } - public ArrayList getMessages() + public ArrayList getQueueEntries() { - return messages; + return _queueEntries; } + + public ArrayList getMessages() + { + return _messages; + } + } diff --git a/qpid/java/build.deps b/qpid/java/build.deps index 24710893bc..d62e414639 100644 --- a/qpid/java/build.deps +++ b/qpid/java/build.deps @@ -92,7 +92,6 @@ integrationtests.libs=${systests.libs} client-example.libs=${client.libs} testkit.libs=${client.libs} - ibm-icu=lib/com.ibm.icu_3.8.1.v20080530.jar ecl-core-jface=lib/org.eclipse.jface_3.4.1.M20080827-2000.jar ecl-core-jface-databinding=lib/org.eclipse.jface.databinding_1.2.1.M20080827-0800a.jar @@ -114,30 +113,41 @@ ecl-swt=lib/org.eclipse.swt_3.4.1.v3449c.jar ecl-ui=lib/org.eclipse.ui_3.4.1.M20080910-0800.jar ecl-ui-forms=lib/org.eclipse.ui.forms_3.3.101.v20080708_34x.jar ecl-ui-workbench=lib/org.eclipse.ui.workbench_3.4.1.M20080827-0800a.jar +apache-commons-codec=lib/org.apache.commons.codec_1.3.0.v20080530-1600.jar ecl-swt-win32-win32-x86=lib/org.eclipse.swt.win32.win32.x86_3.4.1.v3449c.jar ecl-equinox-launcher-win32-win32-x86=lib/org.eclipse.equinox.launcher.win32.win32.x86_1.0.101.R34x_v20080731/** ecl-swt-linux-gtk-x86=lib/org.eclipse.swt.gtk.linux.x86_3.4.1.v3449c.jar ecl-equinox-launcher-linux-gtk-x86=lib/org.eclipse.equinox.launcher.gtk.linux.x86_1.0.101.R34x_v20080805/** +ecl-swt-linux-gtk-x86_64=lib/org.eclipse.swt.gtk.linux.x86_64_3.4.1.v3449c.jar +ecl-equinox-launcher-linux-gtk-x86_64=lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/** ecl-swt-macosx-carbon=lib/org.eclipse.swt.carbon.macosx_3.4.1.v3449c.jar ecl-equinox-launcher-macosx-carbon=lib/org.eclipse.equinox.launcher.carbon.macosx_1.0.101.R34x_v20080731/** +ecl-swt-solaris-gtk-sparc=lib/org.eclipse.swt.gtk.solaris.sparc_3.4.1.v3449c.jar +ecl-equinox-launcher-solaris-gtk-sparc=lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/** management-eclipse-plugin-win32-win32-x86.libs=${management-eclipse-plugin.core-libs} \ ${ecl-swt-win32-win32-x86} ${ecl-equinox-launcher-win32-win32-x86} management-eclipse-plugin-linux-gtk-x86.libs=${management-eclipse-plugin.core-libs} \ ${ecl-swt-linux-gtk-x86} ${ecl-equinox-launcher-linux-gtk-x86} +management-eclipse-plugin-linux-gtk-x86_64.libs=${management-eclipse-plugin.core-libs} \ + ${ecl-swt-linux-gtk-x86_64} ${ecl-equinox-launcher-linux-gtk-x86_64} management-eclipse-plugin-macosx.libs=${management-eclipse-plugin.core-libs} \ ${ecl-swt-macosx-carbon} ${ecl-equinox-launcher-macosx-carbon} +management-eclipse-plugin-solaris-gtk-sparc.libs=${management-eclipse-plugin.core-libs} \ + ${ecl-swt-solaris-gtk-sparc} ${ecl-equinox-launcher-solaris-gtk-sparc} management-eclipse-plugin.core-libs=${ibm-icu} ${ecl-core-jface} ${ecl-core-jface-databinding} \ ${ecl-core-commands} ${ecl-core-contenttype} ${ecl-core-databinding} ${ecl-core-expressions} \ ${ecl-core-jobs} ${ecl-core-runtime} ${ecl-core-runtime-compat-registry} ${ecl-equinox-app} \ ${ecl-equinox-common} ${ecl-equinox-launcher} ${ecl-equinox-prefs} ${ecl-equinox-registry} \ - ${ecl-help} ${ecl-osgi} ${ecl-swt} ${ecl-ui} ${ecl-ui-forms} ${ecl-ui-workbench} + ${ecl-help} ${ecl-osgi} ${ecl-swt} ${ecl-ui} ${ecl-ui-forms} ${ecl-ui-workbench} ${apache-commons-codec} management-eclipse-plugin.platform-libs=${ecl-equinox-launcher-win32-win32-x86} \ ${ecl-equinox-launcher-linux-gtk-x86} ${ecl-equinox-launcher-macosx-carbon} \ - ${ecl-swt-win32-win32-x86} ${ecl-swt-linux-gtk-x86} ${ecl-swt-macosx-carbon} + ${ecl-swt-win32-win32-x86} ${ecl-swt-linux-gtk-x86} ${ecl-swt-macosx-carbon} \ + ${ecl-swt-linux-gtk-x86_64} ${ecl-equinox-launcher-linux-gtk-x86_64} \ + ${ecl-swt-solaris-gtk-sparc} ${ecl-equinox-launcher-solaris-gtk-sparc} management-eclipse-plugin.libs=${management-eclipse-plugin.core-libs} ${management-eclipse-plugin.platform-libs} diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/direct/Listener.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/direct/Listener.java index 93bb097268..1ac3e85f7a 100755 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/direct/Listener.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/direct/Listener.java @@ -42,6 +42,8 @@ public class Listener implements SessionListener public void opened(Session ssn) {} + public void resumed(Session ssn) {} + public void message(Session ssn, MessageTransfer xfr) { System.out.println("Message: " + xfr); diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/fanout/Listener.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/fanout/Listener.java index 4c72ce75a5..21f9c43cd2 100755 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/fanout/Listener.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/fanout/Listener.java @@ -42,6 +42,8 @@ public class Listener implements SessionListener public void opened(Session ssn) {} + public void resumed(Session ssn) {} + public void message(Session ssn, MessageTransfer xfr) { System.out.println("Message: " + xfr); diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/headers/Listener.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/headers/Listener.java index aa1c9b0a41..dff49228a1 100644 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/headers/Listener.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/headers/Listener.java @@ -32,6 +32,8 @@ public class Listener implements SessionListener public void opened(Session ssn) {} + public void resumed(Session ssn) {} + public void message(Session ssn, MessageTransfer xfr) { String body = xfr.getBodyString(); diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/lvq/Listener.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/lvq/Listener.java index b930062813..e17d3eef9f 100644 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/lvq/Listener.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/lvq/Listener.java @@ -44,6 +44,8 @@ public class Listener implements SessionListener public void opened(Session ssn) {} + public void resumed(Session ssn) {} + public void message(Session ssn, MessageTransfer xfr) { String body = xfr.getBodyString(); diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/pubsub/TopicListener.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/pubsub/TopicListener.java index 5e6d3c6f69..dd9307ca84 100755 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/pubsub/TopicListener.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/pubsub/TopicListener.java @@ -40,6 +40,8 @@ public class TopicListener implements SessionListener public void opened(Session ssn) {} + public void resumed(Session ssn) {} + public void message(Session ssn, MessageTransfer xfr) { DeliveryProperties dp = xfr.getHeader().get(DeliveryProperties.class); diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java index 6c9fcc0f4c..5c48d73e43 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java @@ -268,6 +268,13 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect //Indicates whether persistent messages are synchronized private boolean _syncPersistence; + //Indicates whether we need to sync on every message ack + private boolean _syncAck; + + //Indicates the sync publish options (persistent|all) + //By default it's async publish + private String _syncPublish = ""; + /** * @param broker brokerdetails * @param username username @@ -348,25 +355,53 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect public AMQConnection(ConnectionURL connectionURL, SSLConfiguration sslConfig) throws AMQException { // set this connection maxPrefetch - if (connectionURL.getOption(ConnectionURL.AMQ_MAXPREFETCH) != null) + if (connectionURL.getOption(ConnectionURL.OPTIONS_MAXPREFETCH) != null) { - _maxPrefetch = Integer.parseInt(connectionURL.getOption(ConnectionURL.AMQ_MAXPREFETCH)); + _maxPrefetch = Integer.parseInt(connectionURL.getOption(ConnectionURL.OPTIONS_MAXPREFETCH)); } else { // use the defaul value set for all connections _maxPrefetch = Integer.parseInt(System.getProperties().getProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, - ClientProperties.MAX_PREFETCH_DEFAULT)); + ClientProperties.MAX_PREFETCH_DEFAULT)); } - if (connectionURL.getOption(ConnectionURL.AMQ_SYNC_PERSISTENCE) != null) + if (connectionURL.getOption(ConnectionURL.OPTIONS_SYNC_PERSISTENCE) != null) { - _syncPersistence = Boolean.parseBoolean(connectionURL.getOption(ConnectionURL.AMQ_SYNC_PERSISTENCE)); + _syncPersistence = + Boolean.parseBoolean(connectionURL.getOption(ConnectionURL.OPTIONS_SYNC_PERSISTENCE)); + _logger.warn("sync_persistence is a deprecated property, " + + "please use sync_publish={persistent|all} instead"); } else { // use the defaul value set for all connections _syncPersistence = Boolean.getBoolean(ClientProperties.SYNC_PERSISTENT_PROP_NAME); + if (_syncPersistence) + { + _logger.warn("sync_persistence is a deprecated property, " + + "please use sync_publish={persistent|all} instead"); + } + } + + if (connectionURL.getOption(ConnectionURL.OPTIONS_SYNC_ACK) != null) + { + _syncAck = Boolean.parseBoolean(connectionURL.getOption(ConnectionURL.OPTIONS_SYNC_ACK)); + } + else + { + // use the defaul value set for all connections + _syncAck = Boolean.getBoolean(ClientProperties.SYNC_ACK_PROP_NAME); + } + + if (connectionURL.getOption(ConnectionURL.OPTIONS_SYNC_PUBLISH) != null) + { + _syncPublish = connectionURL.getOption(ConnectionURL.OPTIONS_SYNC_PUBLISH); + } + else + { + // use the defaul value set for all connections + _syncPublish = System.getProperty((ClientProperties.SYNC_ACK_PROP_NAME),_syncPublish); } _failoverPolicy = new FailoverPolicy(connectionURL, this); @@ -1469,6 +1504,19 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect return _syncPersistence; } + /** + * Indicates whether we need to sync on every message ack + */ + public boolean getSyncAck() + { + return _syncAck; + } + + public String getSyncPublish() + { + return _syncPublish; + } + public void setIdleTimeout(long l) { _delegate.setIdleTimeout(l); diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java index 29f1aec2f5..c2fb05d94e 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java @@ -239,12 +239,6 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec { _conn.failoverPrep(); _qpidConnection.resume(); - - if (_conn.firePreResubscribe()) - { - _conn.resubscribeSessions(); - } - _conn.fireFailoverComplete(); return; } diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java index 08fd49286b..d96544adf8 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java @@ -22,14 +22,12 @@ package org.apache.qpid.client; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.qpid.AMQException; import javax.jms.IllegalStateException; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.Queue; import javax.jms.QueueBrowser; - import java.util.ArrayList; import java.util.Enumeration; import java.util.concurrent.atomic.AtomicBoolean; @@ -90,38 +88,11 @@ public class AMQQueueBrowser implements QueueBrowser { checkState(); final BasicMessageConsumer consumer = - (BasicMessageConsumer) _session.createBrowserConsumer(_queue, _messageSelector, false); + (BasicMessageConsumer) _session.createBrowserConsumer(_queue, _messageSelector, false); _consumers.add(consumer); - return new Enumeration() - { - - Message _nextMessage = consumer == null ? null : consumer.receive(1000); - - public boolean hasMoreElements() - { - _logger.info("QB:hasMoreElements:" + (_nextMessage != null)); - return (_nextMessage != null); - } - - public Object nextElement() - { - Message msg = _nextMessage; - try - { - _logger.info("QB:nextElement about to receive"); - _nextMessage = consumer.receive(1000); - _logger.info("QB:nextElement received:" + _nextMessage); - } - catch (JMSException e) - { - _logger.warn("Exception caught while queue browsing", e); - _nextMessage = null; - } - return msg; - } - }; + return new QueueBrowserEnumeration(consumer); } public void close() throws JMSException @@ -134,4 +105,39 @@ public class AMQQueueBrowser implements QueueBrowser _consumers.clear(); } + private class QueueBrowserEnumeration implements Enumeration + { + Message _nextMessage; + private BasicMessageConsumer _consumer; + + public QueueBrowserEnumeration(BasicMessageConsumer consumer) throws JMSException + { + _nextMessage = consumer == null ? null : consumer.receiveBrowse(); + _logger.info("QB:created with first element:" + _nextMessage); + _consumer = consumer; + } + + public boolean hasMoreElements() + { + _logger.info("QB:hasMoreElements:" + (_nextMessage != null)); + return (_nextMessage != null); + } + + public Object nextElement() + { + Message msg = _nextMessage; + try + { + _logger.info("QB:nextElement about to receive"); + _nextMessage = _consumer.receiveBrowse(); + _logger.info("QB:nextElement received:" + _nextMessage); + } + catch (JMSException e) + { + _logger.warn("Exception caught while queue browsing", e); + _nextMessage = null; + } + return msg; + } + } } diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java index 733bee2d81..9012632adf 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java @@ -574,13 +574,20 @@ public abstract class AMQSession(new FailoverProtectedOperation()*/ new FailoverNoopSupport(new FailoverProtectedOperation() { public Object execute() throws AMQException, FailoverException { - sendQueueBind(queueName, routingKey, arguments, exchangeName, destination); + sendQueueBind(queueName, routingKey, arguments, exchangeName, destination, nowait); return null; } }, _connection).execute(); @@ -595,7 +602,8 @@ public abstract class AMQSession(*/ @@ -2296,14 +2320,15 @@ public abstract class AMQSession 0) { messageAcknowledge - (unacked, _acknowledgeMode != org.apache.qpid.jms.Session.NO_ACKNOWLEDGE); + (unacked, _acknowledgeMode != org.apache.qpid.jms.Session.NO_ACKNOWLEDGE,setSyncBit); clearUnacked(); } } } void messageAcknowledge(RangeSet ranges, boolean accept) + { + messageAcknowledge(ranges,accept,false); + } + + void messageAcknowledge(RangeSet ranges, boolean accept,boolean setSyncBit) { Session ssn = getQpidSession(); for (Range range : ranges) @@ -257,7 +267,7 @@ public class AMQSession_0_10 extends AMQSession false - // We need to sync so that we get notify of an error. - getQpidSession().sync(); - getCurrentException(); + if (!nowait) + { + // We need to sync so that we get notify of an error. + getQpidSession().sync(); + getCurrentException(); + } return res; } @@ -609,7 +636,8 @@ public class AMQSession_0_10 extends AMQSession(*/ @@ -736,34 +780,11 @@ public class AMQSession_0_10 extends AMQSession extends Closeable implements Messa o = _synchronousQueue.take(); } return o; - } + } + + abstract Message receiveBrowse() throws JMSException; public Message receiveNoWait() throws JMSException { @@ -1037,23 +1039,6 @@ public abstract class BasicMessageConsumer extends Closeable implements Messa _synchronousQueue.clear(); } - public void start() - { - // do nothing as this is a 0_10 feature - } - - - public void stop() - { - // do nothing as this is a 0_10 feature - } - - public boolean isStrated() - { - // do nothing as this is a 0_10 feature - return false; - } - public AMQShortString getQueuename() { return _queuename; @@ -1070,10 +1055,13 @@ public abstract class BasicMessageConsumer extends Closeable implements Messa } /** to be called when a failover has occured */ - public void failedOver() + public void failedOverPre() { clearReceiveQueue(); // TGM FIXME: think this should just be removed // clearUnackedMessages(); } + + public void failedOverPost() {} + } diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java b/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java index 7d535643c0..8b17dcf91f 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java @@ -31,6 +31,7 @@ import org.apache.qpid.filter.JMSSelectorFilter; import javax.jms.InvalidSelectorException; import javax.jms.JMSException; +import javax.jms.Message; import javax.jms.MessageListener; import java.util.Iterator; import java.util.concurrent.atomic.AtomicBoolean; @@ -148,7 +149,8 @@ public class BasicMessageConsumer_0_10 extends BasicMessageConsumer brokerList = new ArrayList(); try { @@ -109,15 +133,22 @@ public class FailoverExchangeMethod extends FailoverRoundRobinServers implements for (String url:urls) { String[] tokens = url.split(":"); - if (tokens[0].equalsIgnoreCase(_orginalBrokerDetail.getTransport())) + if (tokens[0].equalsIgnoreCase(_originalBrokerDetail.getTransport())) { BrokerDetails broker = new AMQBrokerDetails(); broker.setTransport(tokens[0]); broker.setHost(tokens[1]); broker.setPort(Integer.parseInt(tokens[2])); - broker.setProperties(_orginalBrokerDetail.getProperties()); - broker.setSSLConfiguration(_orginalBrokerDetail.getSSLConfiguration()); + broker.setProperties(_originalBrokerDetail.getProperties()); + broker.setSSLConfiguration(_originalBrokerDetail.getSSLConfiguration()); brokerList.add(broker); + + if (currentBrokerIP.equals(broker.getHost()) && + _currentBrokerDetail.getPort() == broker.getPort()) + { + _currentBrokerIndex = brokerList.indexOf(broker); + } + break; } } @@ -132,13 +163,20 @@ public class FailoverExchangeMethod extends FailoverRoundRobinServers implements { _connectionDetails.setBrokerDetails(brokerList); } + + _logger.info("============================================================"); + _logger.info("Updated cluster membership details " + _connectionDetails); + _logger.info("============================================================"); } public void attainedConnection() { - super.attainedConnection(); try { + _failedAttemps = 0; + _logger.info("============================================================"); + _logger.info("Attained connection "); + _logger.info("============================================================"); subscribeForUpdates(); } catch (JMSException e) @@ -151,17 +189,92 @@ public class FailoverExchangeMethod extends FailoverRoundRobinServers implements { synchronized (_brokerListLock) { - return super.getCurrentBrokerDetails(); + return _connectionDetails.getBrokerDetails(_currentBrokerIndex); } - } - + } + public BrokerDetails getNextBrokerDetails() { synchronized(_brokerListLock) { - return super.getNextBrokerDetails(); + if (_currentBrokerIndex == (_connectionDetails.getBrokerCount() - 1)) + { + _currentBrokerIndex = 0; + } + else + { + _currentBrokerIndex++; + } + + BrokerDetails broker = _connectionDetails.getBrokerDetails(_currentBrokerIndex); + + // When the broker list is updated it will include the current broker as well + // There is no point trying it again, so trying the next one. + if (_currentBrokerDetail != null && + broker.getHost().equals(_currentBrokerDetail.getHost()) && + broker.getPort() == _currentBrokerDetail.getPort()) + { + return getNextBrokerDetails(); + } + + String delayStr = broker.getProperty(BrokerDetails.OPTIONS_CONNECT_DELAY); + if (delayStr != null) + { + Long delay = Long.parseLong(delayStr); + _logger.info("Delay between connect retries:" + delay); + try + { + Thread.sleep(delay); + } + catch (InterruptedException ie) + { + return null; + } + } + else + { + _logger.info("No delay between connect retries, use tcp://host:port?connectdelay='value' to enable."); + } + + _failedAttemps ++; + _currentBrokerDetail = broker; + return broker; } } + + public boolean failoverAllowed() + { + // We allow to Failover provided + // our broker list is not empty and + // we haven't gone through all of them + + boolean b = _connectionDetails.getBrokerCount() > 0 && + _failedAttemps <= _connectionDetails.getBrokerCount(); + + + _logger.info("============================================================"); + _logger.info(toString()); + _logger.info("FailoverAllowed " + b); + _logger.info("============================================================"); + + return b; + } + + public void reset() + { + _failedAttemps = 0; + } + + public void setBroker(BrokerDetails broker) + { + // not sure if this method is needed + } + + public void setRetries(int maxRetries) + { + // no max retries we keep trying as long + // as we get updates + } public String methodName() { @@ -172,7 +285,24 @@ public class FailoverExchangeMethod extends FailoverRoundRobinServers implements { StringBuffer sb = new StringBuffer(); sb.append("FailoverExchange:\n"); - sb.append(super.toString()); + sb.append("\n Current Broker Index:"); + sb.append(_currentBrokerIndex); + sb.append("\n Failed Attempts:"); + sb.append(_failedAttemps); + sb.append("\n Orignal broker details:"); + sb.append(_originalBrokerDetail).append("\n"); + sb.append("\n -------- Broker List -----------\n"); + for (int i = 0; i < _connectionDetails.getBrokerCount(); i++) + { + if (i == _currentBrokerIndex) + { + sb.append(">"); + } + + sb.append(_connectionDetails.getBrokerDetails(i)); + sb.append("\n"); + } + sb.append("--------------------------------\n"); return sb.toString(); } } diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverRoundRobinServers.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverRoundRobinServers.java index 7190344f59..c7d8c69fff 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverRoundRobinServers.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverRoundRobinServers.java @@ -30,7 +30,7 @@ public class FailoverRoundRobinServers implements FailoverMethod private static final Logger _logger = LoggerFactory.getLogger(FailoverRoundRobinServers.class); /** The default number of times to cycle through all servers */ - public static final int DEFAULT_CYCLE_RETRIES = 0; + public static final int DEFAULT_CYCLE_RETRIES = 1; /** The default number of times to retry each server */ public static final int DEFAULT_SERVER_RETRIES = 0; @@ -66,6 +66,8 @@ public class FailoverRoundRobinServers implements FailoverMethod String cycleRetries = _connectionDetails.getFailoverOption(ConnectionURL.OPTIONS_FAILOVER_CYCLE); + _cycleRetries = DEFAULT_CYCLE_RETRIES; + if (cycleRetries != null) { try @@ -74,7 +76,7 @@ public class FailoverRoundRobinServers implements FailoverMethod } catch (NumberFormatException nfe) { - _cycleRetries = DEFAULT_CYCLE_RETRIES; + _logger.warn("Cannot set cycle Retries, " + cycleRetries + " is not a number. Using default: " + DEFAULT_CYCLE_RETRIES); } } @@ -93,8 +95,8 @@ public class FailoverRoundRobinServers implements FailoverMethod public boolean failoverAllowed() { - return ((_currentCycleRetries < _cycleRetries) || (_currentServerRetry < _serverRetries) - || (_currentBrokerIndex < (_connectionDetails.getBrokerCount() - 1))); + return ((_currentCycleRetries < _cycleRetries) || (_currentServerRetry < _serverRetries)); + //|| (_currentBrokerIndex <= (_connectionDetails.getBrokerCount() - 1))); } public void attainedConnection() diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java index d05e90823c..7400b524fd 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java @@ -375,6 +375,19 @@ public class ConnectionURLTest extends TestCase assertTrue(connectionurl.getBrokerCount() == 1); } + public void testClientIDWithUnderscore() throws URLSyntaxException + { + String url = "amqp://user:pass@client_id/test?brokerlist='tcp://localhost:5672'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + assertTrue(connectionurl.getUsername().equals("user")); + assertTrue(connectionurl.getPassword().equals("pass")); + assertTrue(connectionurl.getVirtualHost().equals("/test")); + assertTrue(connectionurl.getClientName().equals("client_id")); + + assertTrue(connectionurl.getBrokerCount() == 1); + } public void testWrongOptionSeparatorInOptions() { diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java index a881f6a822..566a222897 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java @@ -44,7 +44,9 @@ public class TestAMQSession extends AMQSession channels = new HashMap(); private State state = NEW; - private Object lock = new Object(); + final private Object lock = new Object(); private long timeout = 60000; private ConnectionListener listener = new DefaultConnectionListener(); private ConnectionException error = null; diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/Echo.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/Echo.java index c1031c9a1c..0e969464ab 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/Echo.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/Echo.java @@ -37,6 +37,8 @@ public class Echo implements SessionListener public void opened(Session ssn) {} + public void resumed(Session ssn) {} + public void message(Session ssn, MessageTransfer xfr) { int id = xfr.getId(); diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java index 4079097f96..361db42498 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java @@ -53,13 +53,15 @@ public class Session extends SessionInvoker private static final Logger log = Logger.get(Session.class); - enum State { NEW, DETACHED, OPEN, CLOSING, CLOSED } + enum State { NEW, DETACHED, RESUMING, OPEN, CLOSING, CLOSED } class DefaultSessionListener implements SessionListener { public void opened(Session ssn) {} + public void resumed(Session ssn) {} + public void message(Session ssn, MessageTransfer xfr) { log.info("message: %s", xfr); @@ -107,6 +109,8 @@ public class Session extends SessionInvoker private volatile boolean flowControl = false; private Semaphore credit = new Semaphore(0); + private Thread resumer = null; + Session(Connection connection, Binary name, long expiry) { this.connection = connection; @@ -234,15 +238,21 @@ public class Session extends SessionInvoker for (int i = maxComplete + 1; lt(i, commandsOut); i++) { Method m = commands[mod(i, commands.length)]; - if (m != null) + if (m == null) { - sessionCommandPoint(m.getId(), 0); - send(m); + m = new ExecutionSync(); + m.setId(i); } + sessionCommandPoint(m.getId(), 0); + send(m); } sessionCommandPoint(commandsOut, 0); sessionFlush(COMPLETED); + resumer = Thread.currentThread(); + state = RESUMING; + listener.resumed(this); + resumer = null; } } @@ -387,7 +397,7 @@ public class Session extends SessionInvoker synchronized (commands) { - if (state == DETACHED) + if (state == DETACHED || state == CLOSING) { return; } @@ -494,15 +504,23 @@ public class Session extends SessionInvoker { if (state == DETACHED && m.isUnreliable()) { - return; + Thread current = Thread.currentThread(); + if (!current.equals(resumer)) + { + return; + } } if (state != OPEN && state != CLOSED) { - Waiter w = new Waiter(commands, timeout); - while (w.hasTime() && (state != OPEN && state != CLOSED)) + Thread current = Thread.currentThread(); + if (!current.equals(resumer)) { - w.await(); + Waiter w = new Waiter(commands, timeout); + while (w.hasTime() && (state != OPEN && state != CLOSED)) + { + w.await(); + } } } @@ -510,8 +528,24 @@ public class Session extends SessionInvoker { case OPEN: break; + case RESUMING: + Thread current = Thread.currentThread(); + if (!current.equals(resumer)) + { + throw new SessionException + ("timed out waiting for resume to finish"); + } + break; case CLOSED: - throw new SessionClosedException(); + ExecutionException exc = getException(); + if (exc != null) + { + throw new SessionException(exc); + } + else + { + throw new SessionClosedException(); + } default: throw new SessionException (String.format @@ -527,7 +561,7 @@ public class Session extends SessionInvoker Waiter w = new Waiter(commands, timeout); while (w.hasTime() && isFull(next)) { - if (state == OPEN) + if (state == OPEN || state == RESUMING) { try { @@ -560,7 +594,7 @@ public class Session extends SessionInvoker { sessionCommandPoint(0, 0); } - if (expiry > 0) + if (expiry > 0 && !m.isUnreliable()) { commands[mod(next, commands.length)] = m; commandBytes += m.getBodySize(); @@ -828,9 +862,9 @@ public class Session extends SessionInvoker { throw new SessionException("close() timed out"); } - - connection.removeSession(this); } + + connection.removeSession(this); } public void exception(Throwable t) @@ -842,7 +876,7 @@ public class Session extends SessionInvoker { synchronized (commands) { - if (expiry == 0) + if (expiry == 0 || getException() != null) { state = CLOSED; } diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/SessionListener.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/SessionListener.java index 63690177f9..eb650eb9ed 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/SessionListener.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/SessionListener.java @@ -31,6 +31,8 @@ public interface SessionListener void opened(Session session); + void resumed(Session session); + void message(Session ssn, MessageTransfer xfr); void exception(Session session, SessionException exception); diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/Sink.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/Sink.java index 622993effb..88870284f6 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/Sink.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/Sink.java @@ -87,6 +87,8 @@ public class Sink implements SessionListener public void opened(Session ssn) {} + public void resumed(Session ssn) {} + public void message(Session ssn, MessageTransfer xfr) { count++; diff --git a/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java index 3e13259ee3..e4bfb9c664 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java @@ -252,16 +252,16 @@ public class FileUtils { for (File subFile : file.listFiles()) { - success = delete(subFile, true) & success ; + success = delete(subFile, true) && success; } - return file.delete(); + return success && file.delete(); } return false; } - return success && file.delete(); + return file.delete(); } diff --git a/qpid/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java b/qpid/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java index dca6264367..8aa8c5f647 100644 --- a/qpid/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java +++ b/qpid/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java @@ -74,6 +74,8 @@ public class ConnectionTest extends TestCase implements SessionListener public void opened(Session ssn) {} + public void resumed(Session ssn) {} + public void message(final Session ssn, MessageTransfer xfr) { if (queue) @@ -122,6 +124,13 @@ public class ConnectionTest extends TestCase implements SessionListener { // do nothing } + else if (body.startsWith("EXCP")) + { + ExecutionException exc = new ExecutionException(); + exc.setDescription("intentional exception for testing"); + ssn.invoke(exc); + ssn.close(); + } else { throw new IllegalArgumentException @@ -137,10 +146,15 @@ public class ConnectionTest extends TestCase implements SessionListener public void closed(Session ssn) {} private void send(Session ssn, String msg) + { + send(ssn, msg, false); + } + + private void send(Session ssn, String msg, boolean sync) { ssn.messageTransfer ("xxx", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED, - null, msg); + null, msg, sync ? SYNC : NONE); } private Connection connect(final Condition closed) @@ -277,6 +291,7 @@ public class ConnectionTest extends TestCase implements SessionListener class TestSessionListener implements SessionListener { public void opened(Session s) {} + public void resumed(Session s) {} public void exception(Session s, SessionException e) {} public void message(Session s, MessageTransfer xfr) { @@ -391,4 +406,41 @@ public class ConnectionTest extends TestCase implements SessionListener conn.close(); } + public void testExecutionExceptionInvoke() throws Exception + { + startServer(); + + Connection conn = new Connection(); + conn.connect("localhost", port, null, "guest", "guest"); + Session ssn = conn.createSession(); + send(ssn, "EXCP 0"); + Thread.sleep(3000); + try + { + send(ssn, "SINK 1"); + } + catch (SessionException exc) + { + assertNotNull(exc.getException()); + } + } + + public void testExecutionExceptionSync() throws Exception + { + startServer(); + + Connection conn = new Connection(); + conn.connect("localhost", port, null, "guest", "guest"); + Session ssn = conn.createSession(); + send(ssn, "EXCP 0", true); + try + { + ssn.sync(); + } + catch (SessionException exc) + { + assertNotNull(exc.getException()); + } + } + } diff --git a/qpid/java/common/src/test/java/org/apache/qpid/util/FileUtilsTest.java b/qpid/java/common/src/test/java/org/apache/qpid/util/FileUtilsTest.java index fb367d042c..94e7e20a86 100644 --- a/qpid/java/common/src/test/java/org/apache/qpid/util/FileUtilsTest.java +++ b/qpid/java/common/src/test/java/org/apache/qpid/util/FileUtilsTest.java @@ -280,6 +280,30 @@ public class FileUtilsTest extends TestCase checkFileLists(filesBefore, filesAfter); } + public void testDeleteNonExistentFile() + { + File test = new File("FileUtilsTest-testDelete-"+System.currentTimeMillis()); + + assertTrue("File exists", !test.exists()); + assertFalse("File is a directory", test.isDirectory()); + + assertTrue("Delete Succeeded ", !FileUtils.delete(test, true)); + } + + public void testDeleteNull() + { + try + { + FileUtils.delete(null, true); + fail("Delete with null value should throw NPE."); + } + catch (NullPointerException npe) + { + // expected path + } + } + + /** * Given two lists of File arrays ensure they are the same length and all entries in Before are in After * diff --git a/qpid/java/cpp.cluster.testprofile b/qpid/java/cpp.cluster.testprofile index 1807ae098b..765eb714f3 100644 --- a/qpid/java/cpp.cluster.testprofile +++ b/qpid/java/cpp.cluster.testprofile @@ -3,3 +3,6 @@ broker=${project.root}/../cpp/src/qpidd --load-module ${project.root}/../cpp/src test.excludesfile=${project.root}/ExcludeList ${project.root}/XAExcludeList ${project.root}/010ExcludeList profile.clustered=true +profile.failoverMsgCount=10 +profile.failoverIterations=10 +profile.failoverRandomSeed=20080921 diff --git a/qpid/java/lib/org.apache.commons.codec_1.3.0.v20080530-1600.jar b/qpid/java/lib/org.apache.commons.codec_1.3.0.v20080530-1600.jar new file mode 100644 index 0000000000..d9b4c8ea1f Binary files /dev/null and b/qpid/java/lib/org.apache.commons.codec_1.3.0.v20080530-1600.jar differ diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/ECLIPSE.RSA b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/ECLIPSE.RSA new file mode 100644 index 0000000000..df6b24ad57 Binary files /dev/null and b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/ECLIPSE.RSA differ diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/ECLIPSE.SF b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/ECLIPSE.SF new file mode 100644 index 0000000000..4193e97338 --- /dev/null +++ b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/ECLIPSE.SF @@ -0,0 +1,17 @@ +Signature-Version: 1.0 +SHA1-Digest-Manifest: gnfArgp6eM77c1JxQF9X3q9/Hd8= +Created-By: 1.5.0 (IBM Corporation) +SHA1-Digest-Manifest-Main-Attributes: hR6QNnvCGlzBxiyTmh4DMZ03Yyg= + +Name: about.html +SHA1-Digest: xGcp/Hbq/ywyvVWkPzD/2vkIzdY= + +Name: eclipse_1115.so +SHA1-Digest: 33jSy/p2jY6bvgg4W0xBlxjxMWA= + +Name: META-INF/eclipse.inf +SHA1-Digest: SAqY+5ITAL0mkdYeijlSRhyIaZk= + +Name: launcher.gtk.linux.x86_64.properties +SHA1-Digest: Q2rsj7VmfkLLH24miqu0v+2sZjE= + diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/MANIFEST.MF b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..b790c0af9a --- /dev/null +++ b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-SymbolicName: org.eclipse.equinox.launcher.gtk.linux.x86_64;sin + gleton:=true +Bundle-ManifestVersion: 2 +Bundle-Localization: launcher.gtk.linux.x86_64 +Bundle-Name: %pluginName +Eclipse-PlatformFilter: (& (osgi.ws=gtk) (osgi.os=linux) (osgi.arch=x8 + 6_64)) +Bundle-Version: 1.0.101.R34x_v20080731 +Fragment-Host: org.eclipse.equinox.launcher;bundle-version="[1.0.0,1.1 + .0)" +Bundle-Vendor: %providerName + +Name: eclipse_1115.so +SHA1-Digest: l0VkVxLXANjcUEWTLRqXKUmIfn8= + +Name: about.html +SHA1-Digest: a9lDHrGuLPkvHBUhsqWU+V2mhPw= + +Name: META-INF/eclipse.inf +SHA1-Digest: KyT9FF7C7t86NoBoa2kZT3ZJBfw= + +Name: launcher.gtk.linux.x86_64.properties +SHA1-Digest: thXaNI0tmsHrCOYNbQBW2zzAh+Q= + diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/eclipse.inf b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/eclipse.inf new file mode 100644 index 0000000000..7864d3c4c3 --- /dev/null +++ b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/META-INF/eclipse.inf @@ -0,0 +1,3 @@ +#Processed using Jarprocessor +pack200.args = -E4 +pack200.conditioned = true diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/about.html b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/about.html new file mode 100644 index 0000000000..395df3ba90 --- /dev/null +++ b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

June 5, 2006

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). +Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor’s license +that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/eclipse_1115.so b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/eclipse_1115.so new file mode 100644 index 0000000000..8bf855533c Binary files /dev/null and b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/eclipse_1115.so differ diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/launcher.gtk.linux.x86_64.properties b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/launcher.gtk.linux.x86_64.properties new file mode 100644 index 0000000000..da448aadbb --- /dev/null +++ b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.101.R34x_v20080731/launcher.gtk.linux.x86_64.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2007 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +pluginName = Equinox Launcher Linux X86_64 Fragment +providerName = Eclipse.org diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/ECLIPSE.RSA b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/ECLIPSE.RSA new file mode 100644 index 0000000000..81599f2e21 Binary files /dev/null and b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/ECLIPSE.RSA differ diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/ECLIPSE.SF b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/ECLIPSE.SF new file mode 100644 index 0000000000..20fe507cdf --- /dev/null +++ b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/ECLIPSE.SF @@ -0,0 +1,17 @@ +Signature-Version: 1.0 +SHA1-Digest-Manifest: kR1kAxZlcW3W0rm/xjIZED9LrAo= +Created-By: 1.5.0 (IBM Corporation) +SHA1-Digest-Manifest-Main-Attributes: pqNWWWTyBz8hsANASpU3hoVl9kc= + +Name: about.html +SHA1-Digest: xGcp/Hbq/ywyvVWkPzD/2vkIzdY= + +Name: eclipse_1115.so +SHA1-Digest: o5PGzpcLRdWF5shzEwmVFCwZrb0= + +Name: META-INF/eclipse.inf +SHA1-Digest: SAqY+5ITAL0mkdYeijlSRhyIaZk= + +Name: launcher.gtk.solaris.sparc.properties +SHA1-Digest: gu+HrnaK+kn508ppLY/iXys12yA= + diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/MANIFEST.MF b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..f81e6141bb --- /dev/null +++ b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-SymbolicName: org.eclipse.equinox.launcher.gtk.solaris.sparc;si + ngleton:=true +Bundle-ManifestVersion: 2 +Bundle-Localization: launcher.gtk.solaris.sparc +Bundle-Name: %pluginName +Eclipse-PlatformFilter: (& (osgi.ws=gtk) (osgi.os=solaris) (osgi.arch= + sparc)) +Bundle-Version: 1.0.101.R34x_v20080731 +Fragment-Host: org.eclipse.equinox.launcher;bundle-version="[1.0.0,1.1 + .0)" +Bundle-Vendor: %providerName + +Name: eclipse_1115.so +SHA1-Digest: 5km5rPngvbWH3aWIYrl+xMejhCE= + +Name: about.html +SHA1-Digest: a9lDHrGuLPkvHBUhsqWU+V2mhPw= + +Name: META-INF/eclipse.inf +SHA1-Digest: KyT9FF7C7t86NoBoa2kZT3ZJBfw= + +Name: launcher.gtk.solaris.sparc.properties +SHA1-Digest: B/N7qN8v4Os5flFl4mE2UaqnMZs= + diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/eclipse.inf b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/eclipse.inf new file mode 100644 index 0000000000..7864d3c4c3 --- /dev/null +++ b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/META-INF/eclipse.inf @@ -0,0 +1,3 @@ +#Processed using Jarprocessor +pack200.args = -E4 +pack200.conditioned = true diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/about.html b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/about.html new file mode 100644 index 0000000000..395df3ba90 --- /dev/null +++ b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

June 5, 2006

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). +Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor’s license +that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/eclipse_1115.so b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/eclipse_1115.so new file mode 100644 index 0000000000..3d8beb88dd Binary files /dev/null and b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/eclipse_1115.so differ diff --git a/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/launcher.gtk.solaris.sparc.properties b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/launcher.gtk.solaris.sparc.properties new file mode 100644 index 0000000000..c3f2ae186e --- /dev/null +++ b/qpid/java/lib/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731/launcher.gtk.solaris.sparc.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2007 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +pluginName = Equinox Launcher Sparc Fragment +providerName = Eclipse.org diff --git a/qpid/java/lib/org.eclipse.swt.gtk.linux.x86_64_3.4.1.v3449c.jar b/qpid/java/lib/org.eclipse.swt.gtk.linux.x86_64_3.4.1.v3449c.jar new file mode 100644 index 0000000000..95909028d4 Binary files /dev/null and b/qpid/java/lib/org.eclipse.swt.gtk.linux.x86_64_3.4.1.v3449c.jar differ diff --git a/qpid/java/lib/org.eclipse.swt.gtk.solaris.sparc_3.4.1.v3449c.jar b/qpid/java/lib/org.eclipse.swt.gtk.solaris.sparc_3.4.1.v3449c.jar new file mode 100644 index 0000000000..d7143505a4 Binary files /dev/null and b/qpid/java/lib/org.eclipse.swt.gtk.solaris.sparc_3.4.1.v3449c.jar differ diff --git a/qpid/java/management/client/bin/qman-wsdm-start.cmd b/qpid/java/management/client/bin/qman-wsdm-start.cmd index 4e80177521..df30ce8617 100644 --- a/qpid/java/management/client/bin/qman-wsdm-start.cmd +++ b/qpid/java/management/client/bin/qman-wsdm-start.cmd @@ -58,7 +58,6 @@ SET CLASSPATH=%QMAN_HOME%\etc SET CLASSPATH=%CLASSPATH%;%QMAN_LIBS%\start.jar SET CLASSPATH=%CLASSPATH%;%QMAN_LIBS%\jetty-6.1.14.jar SET CLASSPATH=%CLASSPATH%;%QMAN_LIBS%\jetty-util-6.1.14.jar -SET CLASSPATH=%CLASSPATH%;%QMAN_LIBS%\jetty-util-6.1.14.jar SET CLASSPATH=%CLASSPATH%;%QMAN_LIBS%\geronimo-servlet_2.5_spec-1.2.jar SET CLASSPATH=%CLASSPATH%;%QMAN_LIBS%\slf4j-api-1.4.0.jar SET CLASSPATH=%CLASSPATH%;%QMAN_LIBS%\slf4j-log4j12-1.4.0.jar diff --git a/qpid/java/management/client/bin/qman-wsdm-start.sh b/qpid/java/management/client/bin/qman-wsdm-start.sh index 239d1bf2f0..39a4cba66e 100644 --- a/qpid/java/management/client/bin/qman-wsdm-start.sh +++ b/qpid/java/management/client/bin/qman-wsdm-start.sh @@ -58,7 +58,7 @@ ADMIN_KEY=gazzax QMAN_LIBS=$QMAN_HOME/lib JETTY_CONFIG_FILE=$QMAN_HOME/etc/jetty.xml -QMAN_CLASSPATH=$QMAN_HOME/etc:$QMAN_LIBS/start.jar:$QMAN_LIBS/jetty-6.1.14.jar:$QMAN_LIBS/jetty-util-6.1.14.jar:$QMAN_LIBS/jetty-util-6.1.14.jar:$QMAN_LIBS/geronimo-servlet_2.5_spec-1.2.jar:$QMAN_LIBS/slf4j-api-1.4.0.jar:$QMAN_LIBS/slf4j-log4j12-1.4.0.jar:$QMAN_LIBS/log4j-1.2.12.jar +QMAN_CLASSPATH=$QMAN_HOME/etc:$QMAN_LIBS/start.jar:$QMAN_LIBS/jetty-6.1.14.jar:$QMAN_LIBS/jetty-util-6.1.14.jar:$QMAN_LIBS/geronimo-servlet_2.5_spec-1.2.jar:$QMAN_LIBS/slf4j-api-1.4.0.jar:$QMAN_LIBS/slf4j-log4j12-1.4.0.jar:$QMAN_LIBS/log4j-1.2.12.jar echo "===============================================================================" echo"" diff --git a/qpid/java/management/client/build.xml b/qpid/java/management/client/build.xml index 6543a569ee..729c15e2a6 100644 --- a/qpid/java/management/client/build.xml +++ b/qpid/java/management/client/build.xml @@ -25,7 +25,6 @@ - @@ -49,7 +48,6 @@ - @@ -59,6 +57,8 @@ + + @@ -195,7 +195,7 @@ - + diff --git a/qpid/java/management/client/console/brokers_management.jsp b/qpid/java/management/client/console/brokers_management.jsp index ab9da15d29..449eabfcc1 100644 --- a/qpid/java/management/client/console/brokers_management.jsp +++ b/qpid/java/management/client/console/brokers_management.jsp @@ -97,7 +97,7 @@ Virtual Host : - + The virtual host name. diff --git a/qpid/java/management/client/console/fragments/menu.jsp b/qpid/java/management/client/console/fragments/menu.jsp index 5833f209ad..971123e996 100644 --- a/qpid/java/management/client/console/fragments/menu.jsp +++ b/qpid/java/management/client/console/fragments/menu.jsp @@ -3,8 +3,8 @@   > System Overview   > Brokers Management   > Resources Management -   > Subscriptions Management -   > System Health +   > Subscriptions Management +   > System Health   > Logging Configuration diff --git a/qpid/java/management/client/console/wsdl-viewer.xsl b/qpid/java/management/client/console/wsdl-viewer.xsl deleted file mode 100644 index c3c9767e10..0000000000 --- a/qpid/java/management/client/console/wsdl-viewer.xsl +++ /dev/null @@ -1,2523 +0,0 @@ - - - - - - - - - - - - - - - - - - - 3.1.01 - - - - - - - - - - - - - - - - 3 - Generated by wsdl-viewer.xsl - Port type - Interface - Source code - ... is recursive - src. - src.file. - op. - port. - iface. - - - - - - - - - - - - - - - - - -/** - wsdl-viewer.css -*/ - -/** -========================================= - Body -========================================= - -html { - background-color: #FFFFFF; -} - -body { - margin: 0; - padding: 0; - height: auto; - color: white; - background-color: #FFFFFF; - font: normal Tahoma; -} -*/ -#outer_box { - padding: 3px 3px 3px 194px; - width: 400px; -} - -#inner_box { - - background-color: white; - color: black; - font: normal Tahoma; - font-size : x-small; -} - -/** -========================================= - Fixed box with links -========================================= -*/ -#outer_links { - position: fixed; - left: 0px; - top: 0px; - margin: 3px; - padding: 1px; - z-index: 200; - width: 180px; - height: auto; - background-color: gainsboro; - padding-top: 2px; - border: 1px solid navy; -} - -* html #outer_links /* Override above rule for IE */ -{ - position: absolute; - width: 188px; - top: expression(offsetParent.scrollTop + 0); -} - -#links { - margin: 1px; - padding: 3px; - background-color: white; - height: 350px; - overflow: auto; - border: 1px solid navy; -} - -#links ul { - left: -999em; - list-style: none; - margin: 0; - padding: 0; - z-index: 100; -} - -#links li { - margin: 0; - padding: 2px 4px; - width: auto; - z-index: 100; -} - -#links ul li { - margin: 0; - padding: 2px 4px; - width: auto; - z-index: 100; -} - -#links a { - display: block; - padding: 0 2px; - color: blue; - width: auto; - border: 1px solid white; - text-decoration: none; - white-space: nowrap; -} - -#links a:hover { - color: white; - background-color: gray; - border: 1px solid gray; -} - - -/** -========================================= - Navigation tabs -========================================= -*/ - -#outer_nav { - background-color: yellow; - padding: 0; - margin: 0; -} - -#nav { - height: 100%; - width: auto; - margin: 0; - padding: 0; - background-color: gainsboro; - border-top: 1px solid gray; - border-bottom: 3px solid gray; - z-index: 100; - font: bold Tahoma; - letter-spacing: 2px; -} - -#nav ul { - background-color: gainsboro; - height: auto; - width: auto; - list-style: none; - margin: 0; - padding: 0; - z-index: 100; - - border: 1px solid silver; - border-top-color: black; - border-width: 1px 0 9px; -} - -#nav li { - display: inline; - padding: 0; - margin: 0; -} - -#nav a { - position: relative; - top: 3px; - float:left; - width:auto; - padding: 8px 10px 6px 10px; - margin: 3px 3px 0; - border: 1px solid gray; - border-width: 2px 2px 3px 2px; - - color: black; - background-color: silver; - text-decoration:none; - text-transform: uppercase; -} - -#nav a:hover { - margin-top: 1px; - padding-top: 9px; - padding-bottom: 7px; - color: blue; - background-color: gainsboro; -} - -#nav a.current:link, -#nav a.current:visited, -#nav a.current:hover { - background: white; - color: black; - text-shadow:none; - margin-top: 0; - padding-top: 11px; - padding-bottom: 9px; - border-bottom-width: 0; - border-color: #A5CE77; -} - -#nav a:active { - background-color: silver; - color: white; -} - - - -/** -========================================= - Content -========================================= -*/ -#header { - margin: 0; - padding: .5em 4em; - color: white; - background-color: #369; -} - -#content { - margin: 0; - padding: 0 2em .5em; -} - -#footer { - clear: both; - margin: 0; - padding: .5em 2em; - color: gray; - background-color: gainsboro; - font-size: 80%; - border-top: 1px dotted gray; - text-align: right -} - -.single_column { - padding: 10px 10px 10px 10px; - /*margin: 0px 33% 0px 0px; */ - margin: 3px 0; -} - -#flexi_column { - padding: 10px 10px 10px 10px; - /*margin: 0px 33% 0px 0px; */ - margin: 0px 212px 0px 0px; -} - -#fix_column { - float: right; - padding: 10px 10px 10px 10px; - margin: 0px; - width: 205px; - /*width: 30%; */ - voice-family: "\"}\""; - voice-family:inherit; - /* width: 30%; */ - width: 205px; -} -html>body #rightColumn { - width: 205px; /* ie5win fudge ends */ -} /* Opera5.02 shows a 2px gap between. N6.01Win sometimes does. - Depends on amount of fill and window size and wind direction. */ - -/** -========================================= - Label / value -========================================= -*/ - -.page { - border-bottom: 3px dotted navy; - margin: 0; - padding: 10px 0 20px 0; -} - -.value, .label { - margin: 0; - padding: 0; -} - -.label { - float: left; - width: 140px; - text-align: right; - font-weight: bold; - padding-bottom: .5em; - margin-right: 0; - color: darkblue; -} - -.value { - margin-left: 147px; - color: darkblue; - padding-bottom: .5em; -} - -strong, strong a { - color: darkblue; - font-weight: bold; - letter-spacing: 1px; - margin-left: 2px; -} - - -/** -========================================= - Links -========================================= -*/ - -a.local:link, -a.local:visited { - color: blue; - margin-left: 10px; - border-bottom: 1px dotted blue; - text-decoration: none; - font-style: italic; -} - -a.local:hover { - background-color: gainsboro; - color: darkblue; - padding-bottom: 1px; - border-bottom: 1px solid darkblue; -} - -a.target:link, -a.target:visited, -a.target:hover -{ - text-decoration: none; - background-color: transparent; - border-bottom-type: none; -} - -/** -========================================= - Box, Shadow -========================================= -*/ - -.box { - padding: 6px; - color: black; - background-color: gainsboro; - border: 1px solid gray; -} - -.shadow { - background: silver; - position: relative; - top: 5px; - left: 4px; -} - -.shadow div { - position: relative; - top: -5px; - left: -4px; -} - -/** -========================================= - Floatcontainer -========================================= -*/ - -.spacer -{ - display: block; - height: 0; - font-size: 0; - line-height: 0; - margin: 0; - padding: 0; - border-style: none; - clear: both; - visibility:hidden; -} - -.floatcontainer:after { - content: "."; - display: block; - height: 0; - font-size:0; - clear: both; - visibility:hidden; -} -.floatcontainer{ - display: inline-table; -} /* Mark Hadley's fix for IE Mac */ /* Hides from IE Mac \*/ * -html .floatcontainer { - height: 1%; -} -.floatcontainer{ - display:block; -} /* End Hack -*/ - -/** -========================================= - Source code -========================================= -*/ - -.indent { - margin: 2px 0 2px 20px; -} - -.xml-element, .xml-proc, .xml-comment { - margin: 2px 0; - padding: 2px 0 2px 0; -} - -.xml-element { - word-spacing: 3px; - color: red; - font-weight: bold; - font-style:normal; - border-left: 1px dotted silver; -} - -.xml-element div { - margin: 2px 0 2px 40px; -} - -.xml-att { - color: blue; - font-weight: bold; -} - -.xml-att-val { - color: blue; - font-weight: normal; -} - -.xml-proc { - color: darkred; - font-weight: normal; - font-style: italic; -} - -.xml-comment { - color: green; - font-weight: normal; - font-style: italic; -} - -.xml-text { - color: green; - font-weight: normal; - font-style: normal; -} - - -/** -========================================= - Heading -========================================= -*/ -h1, h2, h3 { - margin: 10px 10px 2px; - font-family: Tahoma; - font-weight: normal; - } - -h1 { - font-weight: bold; - letter-spacing: 3px; - font-size: 220%; - line-height: 100%; -} - -h2 { - font-weight: bold; - font-size: 175%; - line-height: 200%; -} - -h3 { - font-size: 150%; - line-height: 150%; - font-style: italic; -} - -/** -========================================= - Content formatting -========================================= -*/ -.port { - margin-bottom: 10px; - padding-bottom: 10px; - border-bottom: 1px dashed gray; -} - -.operation { - margin-bottom: 20px; - padding-bottom: 10px; - border-bottom: 1px dashed gray; -} - - -/* -------------------------------------------------------- - Printing -*/ - -/* -@media print -{ - #outer_links, #outer_nav { - display: none; - } -*/ - - #outer_box { - padding: 3px; - } -/* END print media definition -} -*/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Web Service Fragment - - - - - Syntax error by WSDL source rendering in element - - - - - - - - - - -
Description:
-
- -
-
-
- - - - - - - - - - - - - - - - - -
-
Target Namespace:
-
- -
- - -
-
- - - - - - - - - - - SOAP 1.1 - SOAP 1.2 - MIME - HTTP - Unknown - - - - - over HTTP - - - - -
Location:
-
- -
- -
Protocol:
-
- -
- - - - - - - - -
- -

Interface - - - - - - - - - - - - - -

- - - - - - -
Extends:
-
- -
-
- - - -
Operations:
-
- - -
    - - - -
-
-
- - - - - - - - - - SOAP - MIME - HTTP - unknown - - - - - - - - - - -

Port - - - - - - - - - - - - - -

- -
Location:
-
- -
- -
Protocol:
-
- -
- - - -
Operations:
-
- - -
    - - - -
-
-
- -
  • - - - - - - - - Detail - - - -
  • -
    - - - - -
    Default style:
    -
    - -
    -
    - - - - -
    Transport protocol:
    -
    - - SOAP over HTTP - - - - -
    -
    - - -
    Default method:
    -
    - -
    -
    -
    - - - - - - - - -

    - - - - - - - - - -

    -
    - -
      - - - -
    -
    - - -
  • - - operation - - - - - - - - -
    - - - -
    - - - - - - - - -
  • -
    - - - -
    - -
    - -
    - - - - - - - - - - - - -
    -
    -
    - -
    - - port - - -

    - - - - - - - - - -

    -
    -
      - - - -
    -
    -
    - - -
  • - - operation - - - - - - - - -
    - - - -
    - - -
    Description:
    -
    - -
    -
    - - - - -
    Style:
    -
    - -
    -
    - -
    Operation type:
    -
    - - - One-way. The endpoint receives a message. - - Request-response. The endpoint receives a message, and sends a correlated message. - - Solicit-response. The endpoint sends a message, and receives a correlated message. - - Notification. The endpoint sends a message. - unknown - -
    - - -
    SOAP action:
    -
    - -
    -
    - - -
    HTTP path:
    -
    - -
    -
    -
    - - - -
  • -
    - - - -
    - -
    - - - - - - - - - - - - - - - - - - - - - -
    - none -
    -
    -
    -
    -
    - - -
    - - - ( - - - - , use = - - - - - , part = - - - ) - - -
    - - -
    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - unknown - - - - - - - - - - - - - none - - -
    -
    - - - - - - - - - - - 1 - - - - - - - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      - - - -
    -
    - - - - - -
    -
    - - - - - - - - - - - - unknown type - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      - - - -
    -
    - - - - - disc - circle - square - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  • - - - - - - - - - - - - - anonymous - - - - - - - - - - - - - - - - -
  • -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - undefined - - - - - -
    - -
    -
    - - - - - - - - - optional - - - unbounded - - - nillable - - - - - - - - , - - - - , - - - - , - - - ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - type - - - - - - - undefined - - - - - - - - - - - - - - - - - - - - - - - undefined - - - - - - - - - with - - - - - - - - - ( - - ) - - - - - - - - - - - - - undefined - - - - - abstract - - - - - - - - - - - - - - - - - - - - - array of - - - - - - - - - - - - enum { - - } - - - - , - - ' - - ' - - - - - - - - - - - - - - -

    - -

    -
    - -

    - - - Included - Imported - - - - WSDL - Schema - - - - - -

    - -
    - -
    - - - - - - - -
    -
    -
    - -
    - - - - - - -
    -
    - - - / - - - - - - - - - / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - xmlns - : - - - - -
    -
    -
    -
    - - - - - xmlns - : - - = - - - - - - -
    - -
    - - - - - - -
    - <!-- - - --> - -
    -
    - -
    - <? - - - ?> - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - <xsl:value-of select="concat($html-title, ' - ', 'Generated by wsdl-viewer.xsl')"/> - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - - - - - -
    -
    - -
    - - - - - - - - - - - - - - -
    - -
    -
    - - - - - - -
    - - - - - - - - - - - - - - -
    -
    - - - - - - - - - - - - - - -
    - -

    - -

    -
    - - - - - - - - - - -
    -
    - - - - - - -
    - -

    Operations

    -
    -
      - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    -
    - - - - - - -
    - -

    WSDL source code

    -
    -
    -
    - <?xml version="1.0"?> -
    - -
    - - - -
    -
    - - - - - - - -
    - -

    About wsdl-viewer.xsl -

    -
    -
    -
    -
    -
    - -
    -
    -
    - -
    - - - -
    -
    -
    -
    - - -
    \ No newline at end of file diff --git a/qpid/java/management/client/console/wsdm_rmd_perspective.jsp b/qpid/java/management/client/console/wsdm_rmd_perspective.jsp index fc114a962d..fe70930627 100644 --- a/qpid/java/management/client/console/wsdm_rmd_perspective.jsp +++ b/qpid/java/management/client/console/wsdm_rmd_perspective.jsp @@ -18,7 +18,7 @@
    - +
    @@ -63,12 +63,8 @@ -
    - - ${wsdl} - - - +
    +
       
    diff --git a/qpid/java/management/client/console/wsdm_wsdl_perspective.jsp b/qpid/java/management/client/console/wsdm_wsdl_perspective.jsp index b725716fd8..3759459842 100644 --- a/qpid/java/management/client/console/wsdm_wsdl_perspective.jsp +++ b/qpid/java/management/client/console/wsdm_wsdl_perspective.jsp @@ -63,12 +63,8 @@ -
    - - ${wsdl} - - - +
    +
       
    diff --git a/qpid/java/management/client/src/example/PauseAndResumeSubscription.out.ok b/qpid/java/management/client/src/example/PauseAndResumeSubscription.out.ok new file mode 100644 index 0000000000..8a98e1d0b7 --- /dev/null +++ b/qpid/java/management/client/src/example/PauseAndResumeSubscription.out.ok @@ -0,0 +1,133 @@ +This example is demonstrating a WS-Notification scenario +when (for simplicity) QMan is at the same time consumer +and producer. + +Specifically the example shows how a requestor can create, +pause and resume a subscription. +Type enter to proceed... + +[CLIENT TRACE] SOAP envelope contents (outgoing): + + + + http://romagazzarini:8080/qman/services/adapter + http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest + uuid:485cc87c-660e-de43-e8fa-4ad5fffa95a6 + + http://www.w3.org/2005/08/addressing/role/anonymous + + + + + + http://romagazzarini:8080/qman/services/consumer + + + + + +[CLIENT TRACE] SOAP envelope contents (incoming): + + + + http://www.w3.org/2005/08/addressing/role/anonymous + http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeResponse + uuid:0ee610d1-e211-95c6-a498-e1084a610c44 + uuid:485cc87c-660e-de43-e8fa-4ad5fffa95a6 + + http://romagazzarini:8080/qman/services/adapter + + + + + + http://romagazzarini:8080/qman/services/SubscriptionManager + + 282f28e6-4396-4000-a19d-87a03978e8a0 + + + 2009-02-27T13:51:56+01:00 + + + + +[CLIENT TRACE] SOAP envelope contents (outgoing): + + + + http://romagazzarini:8080/qman/services/SubscriptionManager + http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/PauseSubscriptionRequest + uuid:35cc80af-84ac-2456-3e1f-edc2a7f60970 + + http://www.w3.org/2005/08/addressing/role/anonymous + + 282f28e6-4396-4000-a19d-87a03978e8a0 + + + + + + +[CLIENT TRACE] SOAP envelope contents (incoming): + + + + http://www.w3.org/2005/08/addressing/role/anonymous + http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/PauseSubscriptionResponse + uuid:bb53d38a-428c-3d90-cc45-29d5cb27a8df + uuid:35cc80af-84ac-2456-3e1f-edc2a7f60970 + + http://romagazzarini:8080/qman/services/SubscriptionManager + + 282f28e6-4396-4000-a19d-87a03978e8a0 + + + + + + + + +[CLIENT TRACE] SOAP envelope contents (outgoing): + + + + http://romagazzarini:8080/qman/services/SubscriptionManager + http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/ResumeSubscriptionRequest + uuid:bfb48615-905a-e472-a9ca-5483fa592f60 + + http://www.w3.org/2005/08/addressing/role/anonymous + + 282f28e6-4396-4000-a19d-87a03978e8a0 + + + + + + +[CLIENT TRACE] SOAP envelope contents (incoming): + + + + http://www.w3.org/2005/08/addressing/role/anonymous + http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/ResumeSubscriptionResponse + uuid:aab4cf18-3cc0-30c4-7036-009e26bb3213 + uuid:bfb48615-905a-e472-a9ca-5483fa592f60 + + http://romagazzarini:8080/qman/services/SubscriptionManager + + 282f28e6-4396-4000-a19d-87a03978e8a0 + + + + + + + + diff --git a/qpid/java/management/client/src/example/org/apache/qpid/management/example/ConsumerAndProducerExample.java b/qpid/java/management/client/src/example/org/apache/qpid/management/example/ConsumerAndProducerExample.java index 93e78707e9..42587d78ff 100644 --- a/qpid/java/management/client/src/example/org/apache/qpid/management/example/ConsumerAndProducerExample.java +++ b/qpid/java/management/client/src/example/org/apache/qpid/management/example/ConsumerAndProducerExample.java @@ -26,7 +26,9 @@ import java.util.Date; import org.apache.muse.util.xml.XPathUtils; import org.apache.muse.ws.addressing.EndpointReference; import org.apache.muse.ws.addressing.soap.SoapFault; +import org.apache.muse.ws.notification.impl.FilterCollection; import org.apache.muse.ws.notification.impl.MessagePatternFilter; +import org.apache.muse.ws.notification.impl.ProducerPropertiesFilter; import org.apache.muse.ws.notification.impl.TopicFilter; import org.apache.muse.ws.notification.remote.NotificationProducerClient; import org.apache.qpid.management.Names; @@ -65,11 +67,11 @@ public class ConsumerAndProducerExample extends AbstractQManExample void executeExample(String host, int port) throws Exception { // This is QMan... - URI producerURI = URI.create("http://"+host+":"+port+"/qman/services/consumer"); + URI producerURI = URI.create("http://"+host+":"+port+"/qman/services/adapter"); // ...and this is QMan too! Note that it has an hidden consumer capability that is used in // order to run successfully this example... - URI consumerURI = producerURI; + URI consumerURI = URI.create("http://"+host+":"+port+"/qman/services/consumer"); EndpointReference producerEPR = new EndpointReference(producerURI); EndpointReference consumerEPR = new EndpointReference(consumerURI); @@ -93,8 +95,11 @@ public class ConsumerAndProducerExample extends AbstractQManExample // Example 6: a MessageFilter is installed in order to listen only for connection events // (connections created or removed). The subscription will expire in 10 seconds. allMessagesWithMessageFilterAndTerminationTime(producerEPR,consumerEPR); + + // Example 7 : a subscription with more than one filter. + complexSubscription(producerEPR, consumerEPR); } - + /** * Makes a subscription on all topics / all messages without an expiry date. * @@ -223,6 +228,41 @@ public class ConsumerAndProducerExample extends AbstractQManExample new Date(System.currentTimeMillis() + 10000)); // Termination Time } + /** + * Makes a subscription on a specifc topic with an expiry date. + * Only messages published on the given topic will be delivered to the given consumer. + * The subscription will end after 10 seconds + * + * @param producer the producer endpoint reference. + * @param consumer the consumer endpoint reference . + * @throws SoapFault when the subscription cannot be made. + */ + private void complexSubscription(EndpointReference producer, EndpointReference consumer) throws SoapFault + { + NotificationProducerClient producerClient = new NotificationProducerClient(producer); + producerClient.setTrace(true); + + FilterCollection filter = new FilterCollection(); + + TopicFilter topicFilter = new TopicFilter(Names.EVENTS_LIFECYLE_TOPIC_NAME); + MessagePatternFilter messageFilter= new MessagePatternFilter( + "/wsnt:NotificationMessage/wsnt:Message/qman:LifeCycleEvent/qman:Resource/qman:Name/text()='connection'", // expression (XPath) + XPathUtils.NAMESPACE_URI); // Dialect : the only supported dialect is XPath 1.0 + + ProducerPropertiesFilter producerFilter = new ProducerPropertiesFilter( + "boolean(/*/MgtPubInterval > 100 and /*/MsgTotalEnqueues > 56272)", + XPathUtils.NAMESPACE_URI); + + filter.addFilter(topicFilter); + filter.addFilter(messageFilter); + filter.addFilter(producerFilter); + + producerClient.subscribe( + consumer, // Consumer Endpoint reference + filter, // Topic Filter + new Date(System.currentTimeMillis() + 10000)); // Termination Time + } + @Override void printOutExampleDescription() { @@ -245,4 +285,9 @@ public class ConsumerAndProducerExample extends AbstractQManExample System.out.println("A subscription with a termination time will have a predefined expiry"); System.out.println("date while if there's no termination the subscription will never expire."); } + + public static void main(String[] args) + { + new ConsumerAndProducerExample().execute(new String[]{"localhost","8080"}); + } } diff --git a/qpid/java/management/client/src/example/org/apache/qpid/management/example/PausableSubscriptionExample.java b/qpid/java/management/client/src/example/org/apache/qpid/management/example/PausableSubscriptionExample.java new file mode 100644 index 0000000000..01a27a16f9 --- /dev/null +++ b/qpid/java/management/client/src/example/org/apache/qpid/management/example/PausableSubscriptionExample.java @@ -0,0 +1,88 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.example; + +import java.net.URI; + +import org.apache.muse.ws.addressing.EndpointReference; +import org.apache.muse.ws.notification.remote.NotificationProducerClient; +import org.apache.muse.ws.notification.remote.SubscriptionClient; + +/** + * This example is demonstrating a WS-Notification scenario + * when (for simplicity) QMan is at the same time consumer + * and producer. + * + * Specifically the example shows how a requestor can create, pause and resume + * a subscription. + * + * @author Andrea Gazzarini + * + */ +public class PausableSubscriptionExample extends AbstractQManExample +{ + @Override + void executeExample(String host, int port) throws Exception + { + // This is QMan... + URI producerURI = URI.create("http://"+host+":"+port+"/qman/services/adapter"); + + // ...and this is QMan too! Note that it has an hidden consumer capability that is used in + // order to run successfully this example... + URI consumerURI = URI.create("http://"+host+":"+port+"/qman/services/consumer"); + + EndpointReference producerEPR = new EndpointReference(producerURI); + EndpointReference consumerEPR = new EndpointReference(consumerURI); + + NotificationProducerClient producerClient = new NotificationProducerClient(producerEPR); + producerClient.setTrace(true); + + // 1) Creates a subscription and gets the corresponding reference. + SubscriptionClient subscriptionClient = producerClient.subscribe( + consumerEPR, // Consumer Endpoint reference + null, // Filter, if null that means "all messages" + null); // Termination Time : if null the subscription will never expire. + subscriptionClient.setTrace(true); + + + // 2) Pauses the subscription. + subscriptionClient.pauseSubscription(); + + // 3) Resumes the subscription. + subscriptionClient.resumeSubscription(); + } + + @Override + void printOutExampleDescription() + { + System.out.println("This example is demonstrating a WS-Notification scenario "); + System.out.println("when (for simplicity) QMan is at the same time consumer "); + System.out.println("and producer."); + System.out.println(); + System.out.println("Specifically the example shows how a requestor can create,"); + System.out.println("pause and resume a subscription."); + } + + public static void main(String[] args) + { + new PausableSubscriptionExample().execute(new String[]{"romagazzarini","8080"}); + } +} diff --git a/qpid/java/management/client/src/main/java/muse.xml b/qpid/java/management/client/src/main/java/muse.xml index d2f499cef9..cf651c34ac 100644 --- a/qpid/java/management/client/src/main/java/muse.xml +++ b/qpid/java/management/client/src/main/java/muse.xml @@ -29,7 +29,7 @@ org.apache.qpid.management.wsdm.muse.serializer.DateSerializer - org.apache.muse.core.routing.SimpleResourceRouter + org.apache.muse.ws.resource.impl.WsResourceRouter log/muse.log SEVERE diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java index 3d208835f0..4f84128fb3 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java @@ -170,6 +170,6 @@ public interface Messages String QMAN_100037_INVOKE_OPERATION_FAILURE = " : Operation Invocation failure for operation."; String QMAN_100038_UNABLE_TO_SEND_WS_NOTIFICATION = " : Unable to send notification."; String QMAN_100039_UNABLE_TO_CONFIGURE_PROPERLY_WORKER_MANAGER = " : Unable to properly configure WorkManager. A malformed property (NaN) was given as input parameter."; - + String QMAN_100040_UNABLE_TO_LOCATE_WSRP_PROPERTIES = " : Unable to evaluate the WSRP XPath expression on resource WSDL."; } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java index 808cafb6a7..d3ce711d5d 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java @@ -45,7 +45,7 @@ public abstract class Names public static String CLASS = "class"; public static String EVENT = "event"; public static String OBJECT_ID="objectId"; - public static String BROKER_ID = "brokerID"; + public static String BROKER_ID = "brokerId"; public static String DOMAIN_NAME = "Q-MAN"; public static String ARG_COUNT_PARAM_NAME = "argCount"; @@ -86,7 +86,7 @@ public abstract class Names new StringBuilder() .append(DOMAIN_NAME) .append(':') - .append("Type=Service") + .append("Name=QMan,Type=Service") .toString()); } catch(Exception exception) { diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java deleted file mode 100644 index af6aaa36bf..0000000000 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.configuration; - -import org.apache.qpid.management.domain.model.AccessMode; - -/** - * Class used to encapsulate a mapping between an access mode and a code. - * - * @author Andrea Gazzarini - */ -class AccessModeMapping -{ - private final int _code; - private final AccessMode _accessMode; - - /** - * Builds a new access mode mapping with the given parameters. - * - * @param code the access code. - * @param accessMode the access mode. - */ - AccessModeMapping(int code, AccessMode accessMode) - { - this._code = code; - this._accessMode = accessMode; - } - - /** - * Returns the access mode of this mapping. - * - * @return the access mode of this mapping. - */ - AccessMode getAccessMode () - { - return _accessMode; - } - - /** - * Returns the code of this mapping. - * - * @return the code of this mapping. - */ - int getCode () - { - return _code; - } - - /** - * Returns a string representation of this mapping. - * The returned string is indicating the code and the corresponding access mode. - * - * @return a string representation of this mapping. - */ - @Override - public String toString () - { - return new StringBuilder() - .append("AccessMode mapping (") - .append(_code) - .append(',') - .append(_accessMode) - .append(')').toString(); - } -} diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java index c9d45c5023..51dc62f4fa 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java @@ -30,7 +30,16 @@ import org.apache.qpid.management.Messages; import org.apache.qpid.management.Names; import org.apache.qpid.management.domain.handler.base.IMessageHandler; import org.apache.qpid.management.domain.model.AccessMode; +import org.apache.qpid.management.domain.model.type.AbsTime; +import org.apache.qpid.management.domain.model.type.DeltaTime; +import org.apache.qpid.management.domain.model.type.ObjectReference; +import org.apache.qpid.management.domain.model.type.Str16; +import org.apache.qpid.management.domain.model.type.Str8; import org.apache.qpid.management.domain.model.type.Type; +import org.apache.qpid.management.domain.model.type.Uint16; +import org.apache.qpid.management.domain.model.type.Uint32; +import org.apache.qpid.management.domain.model.type.Uint64; +import org.apache.qpid.management.domain.model.type.Uint8; import org.apache.qpid.transport.DeliveryProperties; import org.apache.qpid.transport.Header; import org.apache.qpid.transport.MessageProperties; @@ -71,7 +80,12 @@ public final class Configuration private Configuration() { defineQueueNames(); + createHeaderForCommandMessages(); + + addAccessModeMappings(); + + addTypeMappings(); } void clean() @@ -90,9 +104,11 @@ public final class Configuration } /** - * Returns true if this configuration has at least one broker connection data. + * Returns true if this configuration has at least + * one broker configured. * - * @return true if this configuration has at least one broker connection data. + * @return true if this configuration has at least one + * broker configured. */ public boolean hasOneOrMoreBrokersDefined() { @@ -245,26 +261,46 @@ public final class Configuration /** * Adds a new type mapping to this configuration. * - * @param mapping the type mapping that will be added. + * @param code the code that will be associated with the declared type. + * @param type the type. + * @param vailidatorClassName the FQN of the validator class that will be + * associated with the given type. */ - void addTypeMapping(TypeMapping mapping) { - int code = mapping.getCode(); - Type type = mapping.getType(); - String validatorClassName = mapping.getValidatorClassName(); - _typeMappings.put(code, type); + void addTypeMapping(int code, Type type, String validatorClassName) { + _typeMappings.put(code, type); _validators.put(type, validatorClassName); - LOGGER.info(Messages.QMAN_000005_TYPE_MAPPING_CONFIGURED, code,type,validatorClassName); + LOGGER.info( + Messages.QMAN_000005_TYPE_MAPPING_CONFIGURED, + code, + type, + validatorClassName); } - + + + /** + * Adds a new type mapping to this configuration. + * + * @param code the code that will be associated with the declared type. + * @param type the type. + */ + void addTypeMapping(int code, Type type) { + _typeMappings.put(code, type); + + LOGGER.info( + Messages.QMAN_000005_TYPE_MAPPING_CONFIGURED, + code, + type, + "not configured for this type."); + } + /** * Adds a new access mode mapping to this configuration. * - * @param mapping the mapping that will be added. + * @param code the code that will be associated with the access mode, + * @param accessMode the accessMode. */ - void addAccessModeMapping(AccessModeMapping mapping){ - int code = mapping.getCode(); - AccessMode accessMode = mapping.getAccessMode(); + void addAccessModeMapping(int code, AccessMode accessMode){ _accessModes.put(code, accessMode); LOGGER.info(Messages.QMAN_000006_ACCESS_MODE_MAPPING_CONFIGURED, code,accessMode); @@ -420,4 +456,34 @@ public final class Configuration { this._keepAliveTime = keepAliveTime; } + + /** + * Configures access mode mappings. + * An access mode mapping is an association between a code and an access mode. + */ + private void addAccessModeMappings() { + addAccessModeMapping(1,AccessMode.RC); + addAccessModeMapping(2,AccessMode.RW); + addAccessModeMapping(3,AccessMode.RO); + } + + /** + * Configures type mappings. + * A type mapping is an association between a code and a management type. + */ + private void addTypeMappings() + { + addTypeMapping(1,new Uint8(),Names.NUMBER_VALIDATOR); + addTypeMapping(2,new Uint16(),Names.NUMBER_VALIDATOR); + addTypeMapping(3,new Uint32(),Names.NUMBER_VALIDATOR); + addTypeMapping(4,new Uint64(),Names.NUMBER_VALIDATOR); + addTypeMapping(6,new Str8(),Names.STRING_VALIDATOR); + addTypeMapping(7,new Str16(),Names.STRING_VALIDATOR); + addTypeMapping(8,new AbsTime()); + addTypeMapping(9,new DeltaTime()); + addTypeMapping(10,new ObjectReference()); + addTypeMapping(11,new org.apache.qpid.management.domain.model.type.Boolean()); + addTypeMapping(14,new org.apache.qpid.management.domain.model.type.Uuid()); + addTypeMapping(15,new org.apache.qpid.management.domain.model.type.Map()); + } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java index 1cde9d5f88..fe44c6aff7 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java @@ -38,16 +38,6 @@ import org.apache.qpid.management.domain.handler.impl.HeartBeatIndicationMessage import org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler; import org.apache.qpid.management.domain.handler.impl.MethodResponseMessageHandler; import org.apache.qpid.management.domain.handler.impl.SchemaResponseMessageHandler; -import org.apache.qpid.management.domain.model.AccessMode; -import org.apache.qpid.management.domain.model.type.AbsTime; -import org.apache.qpid.management.domain.model.type.DeltaTime; -import org.apache.qpid.management.domain.model.type.ObjectReference; -import org.apache.qpid.management.domain.model.type.Str16; -import org.apache.qpid.management.domain.model.type.Str8; -import org.apache.qpid.management.domain.model.type.Uint16; -import org.apache.qpid.management.domain.model.type.Uint32; -import org.apache.qpid.management.domain.model.type.Uint64; -import org.apache.qpid.management.domain.model.type.Uint8; import org.apache.qpid.transport.util.Logger; import org.xml.sax.Attributes; import org.xml.sax.InputSource; @@ -148,9 +138,6 @@ public class Configurator extends DefaultHandler } } - addTypeMappings(); - addAccessModeMappings(); - addMandatoryManagementMessageHandlers(); addMandatoryMethodReplyMessageHandlers(); } catch (Exception exception) @@ -209,38 +196,6 @@ public class Configurator extends DefaultHandler return data; } - /** - * Configures access mode mappings. - * An access mode mapping is an association between a code and an access mode. - */ - private void addAccessModeMappings() { - Configuration configuration = Configuration.getInstance(); - configuration.addAccessModeMapping(new AccessModeMapping(1,AccessMode.RC)); - configuration.addAccessModeMapping(new AccessModeMapping(2,AccessMode.RW)); - configuration.addAccessModeMapping(new AccessModeMapping(3,AccessMode.RO)); - } - - /** - * Configures type mappings. - * A type mapping is an association between a code and a management type. - */ - private void addTypeMappings() - { - Configuration configuration = Configuration.getInstance(); - configuration.addTypeMapping(new TypeMapping(1,new Uint8(),Names.NUMBER_VALIDATOR)); - configuration.addTypeMapping(new TypeMapping(2,new Uint16(),Names.NUMBER_VALIDATOR)); - configuration.addTypeMapping(new TypeMapping(3,new Uint32(),Names.NUMBER_VALIDATOR)); - configuration.addTypeMapping(new TypeMapping(4,new Uint64(),Names.NUMBER_VALIDATOR)); - configuration.addTypeMapping(new TypeMapping(6,new Str8(),Names.STRING_VALIDATOR)); - configuration.addTypeMapping(new TypeMapping(7,new Str16(),Names.STRING_VALIDATOR)); - configuration.addTypeMapping(new TypeMapping(8,new AbsTime())); - configuration.addTypeMapping(new TypeMapping(9,new DeltaTime())); - configuration.addTypeMapping(new TypeMapping(10,new ObjectReference())); - configuration.addTypeMapping(new TypeMapping(11,new org.apache.qpid.management.domain.model.type.Boolean())); - configuration.addTypeMapping(new TypeMapping(14,new org.apache.qpid.management.domain.model.type.Uuid())); - configuration.addTypeMapping(new TypeMapping(15,new org.apache.qpid.management.domain.model.type.Map())); - } - /** * Configures the mandatory management message handlers. */ diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java deleted file mode 100644 index 2c0a460c1a..0000000000 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.configuration; - -import org.apache.qpid.management.domain.model.type.Type; - -/** - * Type Mapping used for associating a code with a management type. - * - * @author Andrea Gazzarini - */ -class TypeMapping -{ - private final int _code; - private final Type _type; - private final String _validatorClass; - - /** - * Builds a new type mapping with the given parameters and no validator. - * - * @param code the code. - * @param type the management type. - */ - TypeMapping(int code, Type type) - { - this(code,type,null); - } - - /** - * Builds a new type mapping with the given parameters. - * - * @param code the code. - * @param type the management type. - * @param validatorClassName the class name of the validator to be used. - */ - TypeMapping(int code, Type type, String validatorClassName) - { - this._code = code; - this._type = type; - this._validatorClass = validatorClassName; - } - - /** - * Returns the code of this mapping. - * - * @return the code of this mapping. - */ - int getCode () - { - return _code; - } - - /** - * Returns the type for this mapping. - * - * @return the type for this mapping. - */ - Type getType () - { - return _type; - } - - /** - * Returns the validator class of this mapping. - * - * @return the validator class (as a string) of this mapping. - */ - public String getValidatorClassName() - { - return _validatorClass; - } -} diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java index 176cec451e..657d7e6210 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java @@ -54,11 +54,10 @@ public class JmxService */ public void registerQManService(QMan qman) throws MBeanException { - ObjectName name = createQManName(); - if (!_mxServer.isRegistered(name)) + if (!_mxServer.isRegistered(Names.QMAN_OBJECT_NAME)) { try { - _mxServer.registerMBean(qman, name); + _mxServer.registerMBean(qman, Names.QMAN_OBJECT_NAME); } catch (Exception exception) { throw new MBeanException(exception); } @@ -358,27 +357,6 @@ public class JmxService throw new RuntimeException(exception); } } - - /** - * Creates the QMan object name. - * - * @return the QMan object name. - */ - private ObjectName createQManName() - { - String asString = new StringBuilder() - .append(Names.DOMAIN_NAME) - .append(':') - .append("Type=Service") - .toString(); - try - { - return new ObjectName(asString); - } catch (MalformedObjectNameException exception) - { - throw new RuntimeException(exception); - } - } ObjectName createEntityDefinitionName(String packageName, String className, String type) { @@ -407,7 +385,7 @@ public class JmxService { if (!_mxServer.isRegistered(name)) _mxServer.registerMBean(entity, name); - _mxServer.addNotificationListener(name, createQManName(), null, null); + _mxServer.addNotificationListener(name, Names.QMAN_OBJECT_NAME, null, null); } catch(Exception exception) { throw new RuntimeException(exception); diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java index d124593472..c4c0ce5e74 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java @@ -26,6 +26,9 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import javax.management.Attribute; import javax.management.AttributeList; @@ -45,6 +48,7 @@ import org.apache.qpid.management.Names; import org.apache.qpid.management.configuration.BrokerAlreadyConnectedException; import org.apache.qpid.management.configuration.BrokerConnectionData; import org.apache.qpid.management.configuration.BrokerConnectionException; +import org.apache.qpid.management.configuration.Configuration; import org.apache.qpid.management.configuration.Configurator; import org.apache.qpid.management.domain.model.JmxService; import org.apache.qpid.transport.util.Logger; @@ -58,6 +62,7 @@ public class QMan extends NotificationBroadcasterSupport implements DynamicMBean private final List managementClients = new ArrayList(); private Configurator _configurator = new Configurator(); + private ThreadPoolExecutor _workManager; /** * Starts QMan. @@ -74,6 +79,8 @@ public class QMan extends NotificationBroadcasterSupport implements DynamicMBean _configurator.configure(); + configureWorkManager(); + LOGGER.info(Messages.QMAN_000019_QMAN_STARTED); } catch(Exception exception) { LOGGER.error(exception,Messages.QMAN_100018_UNABLE_TO_STARTUP_CORRECTLY ); @@ -143,6 +150,36 @@ public class QMan extends NotificationBroadcasterSupport implements DynamicMBean LOGGER.info(Messages.QMAN_000021_SHUT_DOWN); } + /** + * Creates a management client using the given data. + * + * @param brokerId the broker identifier. + * @param data the broker connection data. + */ + public void createManagementClient(UUID brokerId, BrokerConnectionData data) + { + try + { + ManagementClient client = new ManagementClient(brokerId,data); + client.estabilishFirstConnectionWithBroker(); + managementClients.add(client); + + LOGGER.info(Messages.QMAN_000004_MANAGEMENT_CLIENT_CONNECTED,brokerId); + } catch(StartupFailureException exception) { + LOGGER.error(exception, Messages.QMAN_100017_UNABLE_TO_CONNECT,brokerId,data); + } + } + + /** + * Returns the list of management clients currently handled by QMan. + * + * @return the list of management clients currently handled by QMan. + */ + public List getManagementClients() + { + return managementClients; + } + /** * Injects the configurator on this QMan instance. * That configutator later will be responsible to manage the configuration. @@ -330,13 +367,20 @@ public class QMan extends NotificationBroadcasterSupport implements DynamicMBean /** * Simply dispatches the incoming notification to registered listeners. + * Consider that the notification is sent asynchronously so the QMan current thread is not + * waiting for completion of receiver task. * * @param notification the incoming notification. * @param handback the context associated to this notification. */ - public void handleNotification(Notification notification, Object handback) + public void handleNotification(final Notification notification, Object handback) { - sendNotification(notification); + _workManager.execute(new Runnable(){ + public void run() + { + sendNotification(notification); + } + }); } /** @@ -352,33 +396,17 @@ public class QMan extends NotificationBroadcasterSupport implements DynamicMBean LOGGER.info(Messages.QMAN_000023_QMAN_REGISTERED_AS_MBEAN); } - /** - * Creates a management client using the given data. - * - * @param brokerId the broker identifier. - * @param data the broker connection data. - */ - public void createManagementClient(UUID brokerId, BrokerConnectionData data) - { - try - { - ManagementClient client = new ManagementClient(brokerId,data); - client.estabilishFirstConnectionWithBroker(); - managementClients.add(client); - - LOGGER.info(Messages.QMAN_000004_MANAGEMENT_CLIENT_CONNECTED,brokerId); - } catch(StartupFailureException exception) { - LOGGER.error(exception, Messages.QMAN_100017_UNABLE_TO_CONNECT,brokerId,data); - } - } - /** - * Returns the list of management clients currently handled by QMan. - * - * @return the list of management clients currently handled by QMan. + * Configures work manager component. */ - public List getManagementClients() - { - return managementClients; - } + private void configureWorkManager() + { + Configuration configuration = Configuration.getInstance(); + _workManager = new ThreadPoolExecutor( + configuration.getWorkerManagerPoolSize(), + configuration.getWorkerManagerMaxPoolSize(), + configuration.getWorkerManagerKeepAliveTime(), + TimeUnit.MILLISECONDS, + new ArrayBlockingQueue(30)); + } } diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java index a12993d40e..ee41beaf50 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java @@ -86,6 +86,8 @@ public class QpidService implements SessionListener public void opened(Session ssn) {} + public void resumed(Session ssn) {} + public void message(Session ssn, MessageTransfer xfr) { MessagePartListenerAdapter l = _listeners.get(xfr.getDestination()); diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokerModel.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokerModel.java index 03e772b9b1..09b7309b96 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokerModel.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokerModel.java @@ -30,12 +30,21 @@ import javax.management.ObjectName; import org.apache.qpid.management.Names; +/** + * Value Object encapsulating a broker management domain model. + * + * @author Andrea Gazzarini + */ public class BrokerModel { - private Map> objectsByType = new HashMap>(); - - private String id; + private Map> _objectsByType = new HashMap>(); + private String _id; + /** + * Adds a new object to this domain model. + * + * @param name the object name of the JMX entity. + */ void addObject(ObjectName name) { String packageName = name.getKeyProperty(Names.PACKAGE); @@ -44,37 +53,48 @@ public class BrokerModel { String fqn = packageName+"."+className; - List objects = objectsByType.get(fqn); + List objects = _objectsByType.get(fqn); if (objects == null) { objects = new ArrayList(); - objectsByType.put(fqn,objects); + _objectsByType.put(fqn,objects); } objects.add(name); } } + /** + * Gets the identifier of the owner of this model. + * + * @return the identifier of the owner of this model. + */ public String getId() { - return id; + return _id; } + /** + * Sets the identifier of the owner of this model. + * + * @param id the identifier of the owner of this model. + */ public void setId(String id) { - this.id = id; + this._id = id; } - public Set getCategoryNames(){ - return objectsByType.keySet(); + public Set getCategoryNames() + { + return _objectsByType.keySet(); } public List getCategory(String name) { - return objectsByType.get(name); + return _objectsByType.get(name); } public int getCategoryCount() { - return objectsByType.keySet().size(); + return _objectsByType.keySet().size(); } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokersManagementAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokersManagementAction.java index ae886767e2..509c86c08b 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokersManagementAction.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokersManagementAction.java @@ -42,9 +42,10 @@ import org.apache.qpid.management.domain.services.QMan; * This controller is responsible to : * *
      - *
    • prepare data for the page that is showing all connected brokers.
    • . - * connect QMan with a broker on demand. + *
    • prepare data for the page that is showing all connected brokers.
    • . + * connect QMan with a broker on demand. *
    + * * @author Andrea Gazzarini */ public class BrokersManagementAction extends HttpServlet @@ -54,6 +55,11 @@ public class BrokersManagementAction extends HttpServlet /** * Retrieves all connected brokers (their connection data) and prepare the model that * is then forwarded to the appropriate view page. + * + * @param request the http request. + * @param response the http response. + * @throws ServletException in case of failure while forwarding to the view component. + * @throws IOException in case of failure while forwarding to the view component. */ @SuppressWarnings("unchecked") @Override @@ -87,7 +93,13 @@ public class BrokersManagementAction extends HttpServlet } /** - * Connects QMan with a new broker. + * Connects QMan with a new broker and forwards to + * the brokers list view page. + * + * @param request the http request. + * @param response the http response. + * @throws ServletException in case of failure while forwarding to the view component. + * @throws IOException in case of failure while forwarding to the view component. */ @SuppressWarnings("unchecked") @Override @@ -123,28 +135,32 @@ public class BrokersManagementAction extends HttpServlet errors.add("Invalid value for \"virtualHost\" attribute. Must be not null."); } - try{ + try + { port = Integer.parseInt(portString); } catch(Exception exception) { errors.add("Invalid value for \"port\" attribute. Must be not null and must be a number."); } - try{ + try + { initialPoolCapacity = Integer.parseInt(initialCapacityString); } catch(Exception exception) { errors.add("Invalid value for \"Initial Pool Capacity\" attribute. Must be not null and must be a number."); } - try{ + try + { maxPoolCapacity = Integer.parseInt(maxCapacityString); } catch(Exception exception) { errors.add("Invalid value for \"Max Pool Capacity\" attribute. Must be not null and must be a number."); } - try{ + try + { maxWaitTimeout = Long.parseLong(maxWaitTimeoutString); } catch(Exception exception) { diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmPropertiesPerspectiveAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmPropertiesPerspectiveAction.java index de479a00d6..e3a8eb50d7 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmPropertiesPerspectiveAction.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmPropertiesPerspectiveAction.java @@ -43,15 +43,12 @@ import javax.xml.namespace.QName; import org.apache.muse.core.proxy.ProxyHandler; import org.apache.muse.core.proxy.ReflectionProxyHandler; import org.apache.muse.ws.addressing.EndpointReference; -import org.apache.muse.ws.resource.remote.WsResourceClient; import org.apache.qpid.management.Names; import org.w3c.dom.Element; public class WsdmPropertiesPerspectiveAction extends HttpServlet { private static final long serialVersionUID = -2411413147821629363L; - private static final Object [] WSDL_DIALECT = new Object[]{"http://schemas.xmlsoap.org/wsdl/"}; - private static final Object [] RMD_DIALECT = new Object[]{"http://docs.oasis-open.org/wsrf/rmd-1"}; private ProxyHandler proxyHandler; diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmRmdPerspectiveAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmRmdPerspectiveAction.java index bafdc06633..b4c488e97c 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmRmdPerspectiveAction.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmRmdPerspectiveAction.java @@ -35,6 +35,8 @@ import org.apache.muse.core.proxy.ProxyHandler; import org.apache.muse.core.proxy.ReflectionProxyHandler; import org.apache.muse.util.xml.XmlUtils; import org.apache.muse.ws.addressing.EndpointReference; +import org.apache.muse.ws.metadata.WsxConstants; +import org.apache.muse.ws.resource.metadata.WsrmdConstants; import org.apache.muse.ws.resource.remote.WsResourceClient; import org.apache.qpid.management.Names; import org.w3c.dom.Element; @@ -42,7 +44,7 @@ import org.w3c.dom.Element; public class WsdmRmdPerspectiveAction extends HttpServlet { private static final long serialVersionUID = -2411413147821629363L; - private static final Object [] DIALECT = new Object[]{"http://docs.oasis-open.org/wsrf/rmd-1"}; + private static final Object [] RMD_DIALECT = new Object[]{WsrmdConstants.NAMESPACE_URI}; private ProxyHandler proxyHandler; @@ -52,10 +54,14 @@ public class WsdmRmdPerspectiveAction extends HttpServlet public void init() throws ServletException { proxyHandler = new ReflectionProxyHandler(); - proxyHandler.setAction("http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata"); - proxyHandler.setRequestName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "GetMetadata", Names.PREFIX)); - proxyHandler.setRequestParameterNames(new QName[]{new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Dialect", Names.PREFIX)}); - proxyHandler.setResponseName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Metadata", Names.PREFIX)); + proxyHandler.setAction(WsxConstants.GET_METADATA_URI); + proxyHandler.setRequestName(WsxConstants.GET_METADATA_QNAME); + proxyHandler.setRequestParameterNames(new QName[]{ + new QName( + WsxConstants.NAMESPACE_URI, + WsxConstants.DIALECT, + WsxConstants.PREFIX)}); + proxyHandler.setResponseName(WsxConstants.METADATA_QNAME); proxyHandler.setReturnType(Element[].class); } @@ -65,29 +71,49 @@ public class WsdmRmdPerspectiveAction extends HttpServlet { try { -// String resourceId = request.getParameter("resourceId"); -// ObjectName objectName = new ObjectName(resourceId); -// -// String wsresourceid = objectName.getKeyProperty(Names.OBJECT_ID); -// EndpointReference resourceEndpointReference = new EndpointReference(getURI(request)); -// resourceEndpointReference.addParameter( -// Names.RESOURCE_ID_QNAME, -// wsresourceid); -// -// WsResourceClient resourceClient = new WsResourceClient(resourceEndpointReference); -// Element rmd = ((Element[])resourceClient.invoke(proxyHandler,DIALECT))[0]; -// -// String output = XmlUtils.toString(rmd); -// -// String [] keyProperties = objectName.getKeyPropertyListString().split(","); -// -// request.setAttribute("resourceId", objectName); -// request.setAttribute("nameAttributes",keyProperties); -// request.setAttribute("rmd",output); - RequestDispatcher dispatcher = request.getRequestDispatcher("/tbd.jsp"); + String resourceId = request.getParameter("resourceId"); + ObjectName objectName = new ObjectName(resourceId); + + String wsresourceid = objectName.getKeyProperty(Names.OBJECT_ID); + EndpointReference resourceEndpointReference = new EndpointReference(getURI(request)); + + resourceEndpointReference.addParameter( + Names.RESOURCE_ID_QNAME, + wsresourceid); + + WsResourceClient resourceClient = new WsResourceClient(resourceEndpointReference); + Element rmd = ((Element[])resourceClient.invoke(proxyHandler,RMD_DIALECT))[0]; + +// NodeList nodelist = wsdl.getChildNodes(); +// Element definitions = null; +// for (int i = 0; i < nodelist.getLength(); i++) +// { +// Node node = nodelist.item(i); +// switch (node.getNodeType()) +// { +// case Node.ELEMENT_NODE: +// { +// Element element = (Element) node; +// if (element.getNodeName().indexOf("definitions") != -1) +// { +// definitions = element; +// break; +// } +// } +// } +// } + + String output = XmlUtils.toString(rmd); + + String [] keyProperties = objectName.getKeyPropertyListString().split(","); + + request.setAttribute("resourceId", resourceId); + request.setAttribute("nameAttributes",keyProperties); + request.setAttribute("rmd",output); + RequestDispatcher dispatcher = request.getRequestDispatcher("/wsdm_rmd_perspective.jsp"); dispatcher.forward(request,response); } catch(Exception exception) - { + { request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below."); request.setAttribute("exception",exception); RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp"); diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmWsdlPerspectiveAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmWsdlPerspectiveAction.java index 9b47fe95b9..77a5237037 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmWsdlPerspectiveAction.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmWsdlPerspectiveAction.java @@ -35,6 +35,7 @@ import org.apache.muse.core.proxy.ProxyHandler; import org.apache.muse.core.proxy.ReflectionProxyHandler; import org.apache.muse.util.xml.XmlUtils; import org.apache.muse.ws.addressing.EndpointReference; +import org.apache.muse.ws.metadata.WsxConstants; import org.apache.muse.ws.resource.remote.WsResourceClient; import org.apache.qpid.management.Names; import org.w3c.dom.Element; @@ -44,7 +45,7 @@ import org.w3c.dom.NodeList; public class WsdmWsdlPerspectiveAction extends HttpServlet { private static final long serialVersionUID = -2411413147821629363L; - private static final Object [] WSDL_DIALECT = new Object[]{"http://schemas.xmlsoap.org/wsdl/"}; + private static final Object [] WSDL_DIALECT = new Object[]{WsxConstants.WSDL_DIALECT}; private ProxyHandler proxyHandler; @@ -54,10 +55,14 @@ public class WsdmWsdlPerspectiveAction extends HttpServlet public void init() throws ServletException { proxyHandler = new ReflectionProxyHandler(); - proxyHandler.setAction("http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata"); - proxyHandler.setRequestName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "GetMetadata", Names.PREFIX)); - proxyHandler.setRequestParameterNames(new QName[]{new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Dialect", Names.PREFIX)}); - proxyHandler.setResponseName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Metadata", Names.PREFIX)); + proxyHandler.setAction(WsxConstants.GET_METADATA_URI); + proxyHandler.setRequestName(WsxConstants.GET_METADATA_QNAME); + proxyHandler.setRequestParameterNames(new QName[]{ + new QName( + WsxConstants.NAMESPACE_URI, + WsxConstants.DIALECT, + WsxConstants.PREFIX)}); + proxyHandler.setResponseName(WsxConstants.METADATA_QNAME); proxyHandler.setReturnType(Element[].class); } @@ -72,6 +77,7 @@ public class WsdmWsdlPerspectiveAction extends HttpServlet String wsresourceid = objectName.getKeyProperty(Names.OBJECT_ID); EndpointReference resourceEndpointReference = new EndpointReference(getURI(request)); + resourceEndpointReference.addParameter( Names.RESOURCE_ID_QNAME, wsresourceid); diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/QEmuInitializer.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/QEmuInitializer.java index 545e587f79..47aa4ea681 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/QEmuInitializer.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/QEmuInitializer.java @@ -57,7 +57,9 @@ public class QEmuInitializer extends HttpServlet Names.QPID_EMULATOR_OBJECT_NAME); } catch(Exception exception) { - LOGGER.warn(exception,Messages.QMAN_300005_QEMU_INITIALIZATION_FAILURE); + LOGGER.warn( + exception, + Messages.QMAN_300005_QEMU_INITIALIZATION_FAILURE); throw new ServletException(exception); } } @@ -84,8 +86,8 @@ public class QEmuInitializer extends HttpServlet { try { - ManagementFactory.getPlatformMBeanServer() - .unregisterMBean(Names.QPID_EMULATOR_OBJECT_NAME); + ManagementFactory.getPlatformMBeanServer().unregisterMBean( + Names.QPID_EMULATOR_OBJECT_NAME); } catch (Exception exception) { } diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/Constants.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/Constants.java new file mode 100644 index 0000000000..59a5801505 --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/Constants.java @@ -0,0 +1,44 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.wsdm.capabilities; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; + +public interface Constants +{ + String WSRP_PROPERTIES_XPATH = "/wsdl:definitions/wsdl:types/xsd:schema[" + + "@targetNamespace='http://amqp.apache.org/qpid/management/qman']" + + "/xsd:element[@name='QManWsResourceProperties']/xsd:complexType/xsd:sequence"; + + String SERVICE_LOCATION_XPATH = "/wsdl:definitions/wsdl:service/wsdl:port/wsdl-soap:address/@location"; + String QMAN_SCHEMA_XPATH = "/wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://amqp.apache.org/qpid/management/qman']"; + + String MIN_OCCURS = "minOccurs"; + String REF_ATTRIBUTE = "ref"; + String NAME_ATTRIBUTE = "name"; + String TYPE_ATTRIBUTE ="type"; + + QName XSD_ELEMENT_QNAME = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI,"element","xsd"); + QName XSD_COMPLEX_TYPE_QNAME = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI,"complexType","xsd"); + QName XSD_SEQUENCE_QNAME = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI,"sequence","xsd"); + +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/ConsumerCapability.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/ConsumerCapability.java index dd5eb523c1..bde98092a0 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/ConsumerCapability.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/ConsumerCapability.java @@ -29,6 +29,8 @@ import org.apache.muse.ws.notification.WsnConstants; /** * WS-Notifications consumer capability. + * At the moment QMan is not a consumer of itself so this capability is here only + * for test purposes. * * @author Andrea Gazzarini */ diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/DummyCapabilityBuilder.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/DummyCapabilityBuilder.java index 0676b4ac49..370cf3086d 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/DummyCapabilityBuilder.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/DummyCapabilityBuilder.java @@ -29,32 +29,57 @@ import org.apache.muse.core.Environment; /** * Dummy capability builder used for avoid duplicated builds for the * same class. + * Basically it acts likes a Null Object when the target capability class has been + * already built. * * @author Andrea Gazzarini */ public class DummyCapabilityBuilder implements IArtifactBuilder { - - public void begin(ObjectName objectName) throws BuilderException + /** + * Director callback. + * Do nothing here (see class comments above.) + */ + public void begin(ObjectName objectName) { } - public void endAttributes() throws BuilderException + /** + * Director callback. + * Do nothing here (see class comments above.) + */ + public void endAttributes() { } - public void endOperations() throws BuilderException + /** + * Director callback. + * Do nothing here (see class comments above.) + */ + public void endOperations() { } - public void onAttribute(MBeanAttributeInfo attributeMetadata) throws BuilderException + /** + * Director callback. + * Do nothing here (see class comments above.) + */ + public void onAttribute(MBeanAttributeInfo attributeMetadata) { } - public void onOperation(MBeanOperationInfo operationMetadata) throws BuilderException + /** + * Director callback. + * Do nothing here (see class comments above.) + */ + public void onOperation(MBeanOperationInfo operationMetadata) { } + /** + * Director callback. + * Do nothing here (see class comments above.) + */ public void setEnvironment(Environment environment) { } diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java index 82d8e97d37..37ecc0c031 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java @@ -179,12 +179,8 @@ public abstract class MBeanCapability extends AbstractWsResourceCapability params, signature); - Result result = new Result( - output.getReturnCode(), - output.getStatusText(), - output.getOutputSection()); - - return result; + return new Result(output.getOutputSection()); + } catch (InstanceNotFoundException exception) { throw new EntityInstanceNotFoundFault( diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java index ea623138a4..ea67bdf9e1 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java @@ -178,6 +178,14 @@ public class MBeanCapabilityBuilder implements IArtifactBuilder{ } } + /** + * Director callback. + * All attributes have been notified. + * + * This builder is using this callback in order to create the initial + * properties QNames declaration. + * + */ public void endAttributes() throws BuilderException { _endAttributeHandler.endAttributes(); diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManMetadataExchangeCapability.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManMetadataExchangeCapability.java index 7e58992540..d6255d0bed 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManMetadataExchangeCapability.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManMetadataExchangeCapability.java @@ -21,6 +21,10 @@ package org.apache.qpid.management.wsdm.capabilities; import org.apache.muse.util.xml.XmlUtils; +import org.apache.muse.ws.metadata.WsxConstants; +import org.apache.muse.ws.resource.WsResource; +import org.apache.muse.ws.resource.metadata.MetadataDescriptor; +import org.apache.muse.ws.resource.metadata.WsrmdConstants; import org.apache.muse.ws.resource.metadata.ext.WsrfMetadataExchange; import org.apache.muse.ws.wsdl.WsdlUtils; import org.apache.qpid.management.wsdm.muse.resources.QManWsResource; @@ -60,4 +64,36 @@ public class QManMetadataExchangeCapability extends WsrfMetadataExchange return wsdl; } + + /** + * Returns the resource metadata descriptor associated with the owenr + * resource of thi capability. + * + * @return the resource metadata descriptor. + */ + protected Element getResourceMetadataDescriptor() + { + WsResource resource = (WsResource)getResource(); + MetadataDescriptor metadataDescriptor = resource.getPropertyCollection().getMetadata(); + return metadataDescriptor.toXML(); + } + + public Element[] getMetadata(String dialect) + { + if (dialect == null) + { + return new Element[]{ + getResourceMetadataDescriptor(), + getWSDL()}; + } else { + if (WsrmdConstants.NAMESPACE_URI.equals(dialect)) + { + return new Element[]{getResourceMetadataDescriptor()}; + } else if (WsxConstants.WSDL_DIALECT.equals(dialect)) + { + return new Element[]{getWSDL()}; + } + } + return super.getMetadata(dialect); + } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/Result.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/Result.java index b8e22b4bc7..a00d2665ae 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/Result.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/Result.java @@ -29,11 +29,9 @@ import java.util.*; * * @author Andrea Gazzarini */ -public class Result +public final class Result { - private long _statusCode; - private String _statusText; - private Map _outputParameters; + private final Map _outputParameters; /** * Builds a new result DTO with the given parameters. @@ -42,53 +40,11 @@ public class Result * @param statusText the status message. * @param outputParameters the output parameters. */ - public Result(long statusCode, String statusText,Map outputParameters) + public Result(Map outputParameters) { - this._statusCode = statusCode; - this._statusText = statusText; this._outputParameters = outputParameters; } - - /** - * Returns the status code. - * - * @return the status code. - */ - public long getStatusCode() - { - return _statusCode; - } - - /** - * Sets the status code. - * - * @param statusCode the status code. - */ - void setStatusCode(long statusCode) - { - this._statusCode = statusCode; - } - - /** - * Returns the status text. - * - * @return the status text. - */ - public String getStatusText() - { - return _statusText; - } - - /** - * Sets the status text. - * - * @param statusText the status text. - */ - void setStatusText(String statusText) - { - this._statusText = statusText; - } - + /** * Returns the output parameterss. * @@ -98,14 +54,4 @@ public class Result { return _outputParameters; } - - /** - * Sets the output parameters. - * - * @param outputParameters the output parameters. - */ - void setOutputParameters(Map outputParameters) - { - this._outputParameters = outputParameters; - } -} +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/RmdBuilder.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/RmdBuilder.java index 86aba0e5bb..c1678eb43f 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/RmdBuilder.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/RmdBuilder.java @@ -128,7 +128,8 @@ class RmdBuilder implements IArtifactBuilder */ public Element[] getResourceMetadataDescriptor() { - Element [] properties = _metadataDescriptor.toArray(new Element[0]); + Element [] properties = _metadataDescriptor.toArray( + new Element[_metadataDescriptor.size()]); return properties; } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WSDMArtifactsDirector.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WSDMArtifactsDirector.java index c9ffd5eac0..35a919c295 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WSDMArtifactsDirector.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WSDMArtifactsDirector.java @@ -35,7 +35,7 @@ import org.w3c.dom.Element; * * @author Andrea Gazzarini */ -class WSDMArtifactsDirector +final class WSDMArtifactsDirector { private final ObjectName _eventSourceObjectName; private final MBeanInfo _metadata; @@ -189,7 +189,8 @@ class WSDMArtifactsDirector * * @param resource the ws resource. */ - public void setResource(Resource resource) { + public void setResource(Resource resource) + { _wsdlBuilder.setWsdlPath(resource.getWsdlPath()); } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsArtifactsFactory.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsArtifactsFactory.java index 2a1bf059c3..94505d28f7 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsArtifactsFactory.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsArtifactsFactory.java @@ -105,13 +105,18 @@ class WsArtifactsFactory _cache.put(searchKey, result); - LOGGER.debug(Messages.QMAN_200040_WS_ARTIFACTS_CACHED,searchKey); + LOGGER.debug( + Messages.QMAN_200040_WS_ARTIFACTS_CACHED, + searchKey); } return result; } catch(Exception exception) { - throw new ArtifactsNotAvailableException(result,exception,objectName); + throw new ArtifactsNotAvailableException( + result, + exception, + objectName); } } diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java index 02b25eb02f..6bfccda1ce 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java @@ -23,20 +23,22 @@ package org.apache.qpid.management.wsdm.capabilities; import java.net.InetAddress; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import javax.management.MBeanAttributeInfo; import javax.management.MBeanOperationInfo; import javax.management.MBeanParameterInfo; import javax.management.ObjectName; -import javax.xml.XMLConstants; -import javax.xml.namespace.QName; +import javax.xml.transform.TransformerException; import org.apache.muse.core.Environment; +import org.apache.muse.core.serializer.SerializerRegistry; import org.apache.muse.util.ReflectUtils; import org.apache.muse.util.xml.XmlUtils; import org.apache.muse.ws.wsdl.WsdlUtils; import org.apache.qpid.management.Messages; import org.apache.qpid.management.Names; +import org.apache.qpid.management.wsdm.muse.engine.WSDMAdapterEnvironment; import org.apache.qpid.management.wsdm.muse.serializer.ObjectSerializer; import org.apache.qpid.qman.debug.WsdlDebugger; import org.apache.qpid.transport.util.Logger; @@ -49,126 +51,61 @@ import org.w3c.dom.Element; * * @author Andrea Gazzarini */ -class WsdlBuilder implements IArtifactBuilder { +class WsdlBuilder implements IArtifactBuilder,Constants { private final static Logger LOGGER = Logger.get(WsdlBuilder.class); - private Environment _environment; + private WSDMAdapterEnvironment _environment; private Document _document; private Element schema; - - private ObjectSerializer serializer = new ObjectSerializer(); - + private Element _wsrpProperties; + private ObjectSerializer _serializer; private ObjectName _objectName; - - private boolean mapTypeHasBeenDeclared; - private boolean uuidTypeHasBeenDeclared; private Map arrayTypesAlreadyDeclared = new HashMap(); + private Element _arrayComplexType; + private Element _nestedArrayType; + + /** + * For each attibute the corresponding xml type definition must be inserted on the QMan + * schema related section. + * After that, a reference to that definition must be declared on the wsrp element . + * + * @param attributeMetadata the attribute metadata. + * @throws BuilderException only if this builder wasn't able to get a reference (via XPath) + * to QMan schema section. + */ public void onAttribute(MBeanAttributeInfo attributeMetadata) throws BuilderException { try { - /* - - - - - - - - - - - - - - -*/ - schema.appendChild(defineSchemaFor(attributeMetadata.getType(), attributeMetadata.getName())); - Element wsrpProperties = (Element) XPathAPI.selectSingleNode( - _document, - "/wsdl:definitions/wsdl:types/xsd:schema[" + - "@targetNamespace='http://amqp.apache.org/qpid/management/qman']" + - "/xsd:element[@name='QManWsResourceProperties']/xsd:complexType/xsd:sequence"); + String attributeName = attributeMetadata.getName(); + schema.appendChild(defineSchemaFor(attributeMetadata.getType(), attributeName)); Element propertyRef= XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); + propertyRef.setAttribute(MIN_OCCURS, "0"); propertyRef.setAttribute( - "ref", - Names.PREFIX+":"+attributeMetadata.getName()); - propertyRef.setAttribute("minOccurs", "0"); - wsrpProperties.appendChild(propertyRef); - + REF_ATTRIBUTE, + Names.PREFIX+":"+attributeName); + + _wsrpProperties.appendChild(propertyRef); } catch(Exception exception) { throw new BuilderException(exception); } } - private final static QName XSD_ELEMENT_QNAME = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI,"element","xsd"); - private final static QName XSD_COMPLEX_TYPE_QNAME = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI,"complexType","xsd"); - private final static QName XSD_SEQUENCE_QNAME = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI,"sequence","xsd"); - @SuppressWarnings("unchecked") private Element defineSchemaFor(String type, String attributeName) throws Exception { - if (type.equals("java.util.Map")) + Element propertyDeclaration = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); + String xmlType = null; + if (type.equals(Map.class.getName())) { - if (!mapTypeHasBeenDeclared) - { - Element complexType = XmlUtils.createElement(_document, XSD_COMPLEX_TYPE_QNAME); - complexType.setAttribute("name","map"); - Element sequence = XmlUtils.createElement(_document, XSD_SEQUENCE_QNAME); - - Element entry = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); - entry.setAttribute("name", "entry"); - entry.setAttribute("minOccurs", "0"); - entry.setAttribute("maxOccurs", "unbounded"); - - Element complexType2 = XmlUtils.createElement(_document, XSD_COMPLEX_TYPE_QNAME); - Element sequence2 = XmlUtils.createElement(_document, XSD_SEQUENCE_QNAME); - - Element key = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); - key.setAttribute("name", "key"); - key.setAttribute("type", "xsd:string"); - - Element value = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); - value.setAttribute("name", "value"); - value.setAttribute("type", "xsd:anyType"); - - sequence2.appendChild(key); - sequence2.appendChild(value); - complexType2.appendChild(sequence2); - entry.appendChild(complexType2); - sequence.appendChild(entry); - complexType.appendChild(sequence); - schema.appendChild(complexType); - mapTypeHasBeenDeclared = true; - } - Element propertyDeclaration = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); - propertyDeclaration.setAttribute("name",attributeName); - propertyDeclaration.setAttribute("type", "qman:map"); - return propertyDeclaration; - - } else if ("java.util.UUID".equals(type)) - { - if (!uuidTypeHasBeenDeclared) - { - Element complexType = XmlUtils.createElement(_document, XSD_COMPLEX_TYPE_QNAME); - complexType.setAttribute("name", "uuid"); - Element sequence = XmlUtils.createElement(_document, XSD_SEQUENCE_QNAME); - Element uuid = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); - uuid.setAttribute("name", "uuid"); - uuid.setAttribute("type", "xsd:string"); - sequence.appendChild(uuid); - complexType.appendChild(sequence); - schema.appendChild(complexType); - uuidTypeHasBeenDeclared = true; - } - Element propertyDeclaration = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); - propertyDeclaration.setAttribute("name",attributeName); - propertyDeclaration.setAttribute("type", "qman:uuid"); - return propertyDeclaration; + xmlType="qman:map"; + } else if (UUID.class.getName().equals(type)) + { + xmlType = "qman:uuid"; } else if (type.startsWith("[")) { Class arrayClass = Class.forName(type); @@ -177,143 +114,40 @@ class WsdlBuilder implements IArtifactBuilder { arrayType = Character.toUpperCase(arrayType.charAt(0))+arrayType.substring(1); if (!arrayTypesAlreadyDeclared.containsKey(type)) { - Element complexType = XmlUtils.createElement(_document, XSD_COMPLEX_TYPE_QNAME); - complexType.setAttribute("name", "arrayOf"+arrayType); - Element sequence = XmlUtils.createElement(_document, XSD_SEQUENCE_QNAME); - Element entry = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); - entry.setAttribute("name", "entry"); - entry.setAttribute("type", serializer.getXmlType(clazz)); - sequence.appendChild(entry); - complexType.appendChild(sequence); - schema.appendChild(complexType); + _arrayComplexType.setAttribute(NAME_ATTRIBUTE, "arrayOf"+arrayType); + _nestedArrayType.setAttribute(TYPE_ATTRIBUTE, _serializer.getXmlType(clazz)); + schema.appendChild(_arrayComplexType); arrayTypesAlreadyDeclared.put(type, arrayType); } - Element propertyDeclaration = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); - propertyDeclaration.setAttribute("name",attributeName); - propertyDeclaration.setAttribute("type", "qman:arrayOf"+arrayTypesAlreadyDeclared.get(type)); - return propertyDeclaration; + xmlType = "qman:arrayOf"+arrayTypesAlreadyDeclared.get(type); } - else { - Element propertyDeclaration = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); - propertyDeclaration.setAttribute("name",attributeName); - propertyDeclaration.setAttribute("type", serializer.getXmlType(Class.forName(type))); - - return propertyDeclaration; + else + { + xmlType = _serializer.getXmlType(Class.forName(type)); } + propertyDeclaration.setAttribute(NAME_ATTRIBUTE,attributeName); + propertyDeclaration.setAttribute(TYPE_ATTRIBUTE, xmlType); + return propertyDeclaration; } - + + /** + * Initializes this builder. + * + * @param objectName the name of the current JMX entity. + * @throws BuilderException when it's not possible to proceed with the initialization. + */ public void begin(ObjectName objectName) throws BuilderException { this._objectName = objectName; - try - { - Attr location = (Attr) XPathAPI.selectSingleNode( - _document, - "/wsdl:definitions/wsdl:service/wsdl:port/wsdl-soap:address/@location"); - - StringBuilder builder = new StringBuilder("http://") - .append(InetAddress.getLocalHost().getHostName()) - .append(':') - .append(System.getProperty(Names.ADAPTER_PORT_PROPERTY_NAME,"8080")) - .append('/') - .append("qman") - .append('/') - .append("services/QManWsResource"); - location.setValue(builder.toString()); - } catch(Exception exception) - { - LOGGER.error( - exception, - Messages.QMAN_100026_SOAP_ADDRESS_REPLACEMENT_FAILURE); - throw new BuilderException(exception); - } - - try - { - schema = (Element) XPathAPI.selectSingleNode( - _document.getDocumentElement(), - "/wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://amqp.apache.org/qpid/management/qman']"); - } catch(Exception exception) - { - LOGGER.error( - exception, - Messages.QMAN_100034_WSDL_SCHEMA_SECTION_NOT_FOUND); - throw new BuilderException(exception); - } -/* - - - - - - - - - - - - - - - - - - - - - -*/ - Element complexTypeResult = _document.createElement("xsd:complexType"); - complexTypeResult.setAttribute("name", "result"); - Element sequence = _document.createElement("xsd:sequence"); - complexTypeResult.appendChild(sequence); - - Element statusCode = _document.createElement("xsd:element"); - statusCode.setAttribute("name", "statusCode"); - statusCode.setAttribute("type", "xsd:long"); - - Element statusText = _document.createElement("xsd:element"); - statusText.setAttribute("name", "statusText"); - statusText.setAttribute("type", "xsd:string"); - - sequence.appendChild(statusCode); - sequence.appendChild(statusText); - - Element outputParams = _document.createElement("xsd:complexType"); - outputParams.setAttribute("name", "outputParameters"); - sequence.appendChild(outputParams); - - Element complexTypeOutput = _document.createElement("xsd:complexType"); - Element outputSequence = _document.createElement("xsd:sequence"); + this._serializer = (ObjectSerializer) SerializerRegistry.getInstance().getSerializer(Object.class); - outputParams.appendChild(complexTypeOutput); - complexTypeOutput.appendChild(outputSequence); + createWsrpPropertiesElement(); - Element entry = _document.createElement("xsd:element"); - entry.setAttribute("maxOccurs", "unbounded"); - entry.setAttribute("minOccurs", "0"); - entry.setAttribute("name", "entry"); + createReusableArrayComplextType(); - outputSequence.appendChild(entry); + replaceDummyServiceLocationOnWsdl(); - Element entryComplexType = _document.createElement("xsd:complexType"); - Element entrySequence = _document.createElement("xsd:sequence"); - entryComplexType.appendChild(entrySequence); - entry.appendChild(entryComplexType); - - Element name = _document.createElement("xsd:name"); - name.setAttribute("name", "key"); - name.setAttribute("type", "xsd:string"); - - Element value = _document.createElement("xsd:element"); - value.setAttribute("name", "value"); - value.setAttribute("type", "xsd:anyType"); - - entrySequence.appendChild(name); - entrySequence.appendChild(value); - - schema.appendChild(complexTypeResult); + createSchemaElement(); } public void onOperation(MBeanOperationInfo operationMetadata) throws BuilderException @@ -350,9 +184,9 @@ class WsdlBuilder implements IArtifactBuilder { */ + try { - // // Element methodRequestElement= _document.createElement("xsd:element"); @@ -361,13 +195,13 @@ class WsdlBuilder implements IArtifactBuilder { methodRequestElement.setAttribute("type", "qman:"+methodNameRequest); // - Element methodResponseElement= _document.createElement("xsd:element"); +// Element methodResponseElement= _document.createElement("xsd:element"); String methodNameResponse= operationMetadata.getName()+"Response"; - methodResponseElement.setAttribute("name", methodNameResponse); - methodResponseElement.setAttribute("type", "qman:"+methodNameResponse); +// methodResponseElement.setAttribute("name", methodNameResponse); +// methodResponseElement.setAttribute("type", "qman:result");//+methodNameResponse); schema.appendChild(methodRequestElement); - schema.appendChild(methodResponseElement); +// schema.appendChild(methodResponseElement); /* @@ -391,19 +225,6 @@ class WsdlBuilder implements IArtifactBuilder { methodNameRequestComplexType.appendChild(methodNameRequestComplexTypeSequence); schema.appendChild(methodNameRequestComplexType); - Element methodNameResponseComplexType = _document.createElement("xsd:complexType"); - methodNameResponseComplexType.setAttribute("name", methodNameResponse); - - Element methodNameResponseSequence = _document.createElement("xsd:sequence"); - methodNameResponseComplexType.appendChild(methodNameResponseSequence); - - Element result = _document.createElement("xsd:element"); - result.setAttribute("name", "result"); - result.setAttribute("type", "qman:result"); - methodNameResponseSequence.appendChild(result); - - schema.appendChild(methodNameResponseComplexType); - /* @@ -428,7 +249,7 @@ class WsdlBuilder implements IArtifactBuilder { Element responseMessage = _document.createElement("wsdl:message"); responseMessage.setAttribute("name", responseMessageName); Element responsePart = _document.createElement("wsdl:part"); - responsePart.setAttribute("element", "qman:"+methodNameResponse); + responsePart.setAttribute("element", "qman:result");//+methodNameResponse); responsePart.setAttribute("name", methodNameResponse); responseMessage.appendChild(responsePart); @@ -506,29 +327,134 @@ class WsdlBuilder implements IArtifactBuilder { } } + /** + * Director callback : all attributes have been notified. + * Nothing to do here. + */ public void endAttributes() { // N.A. } + /** + * Director callback : all operations have been notified. + * Nothing to do here. + */ public void endOperations() { - + // N.A. } + /** + * Returns the WSDL built by this builder. + * + * @return the WSDL built by this builder. + */ public Document getWsdl() { WsdlDebugger.debug(_objectName,_document); return _document; } + /** + * Injects the application context environment + * on this builder. + * + * @param environment the application context environment. + */ public void setEnvironment(Environment environment) { - this._environment = environment; + this._environment = (WSDMAdapterEnvironment)environment; } + /** + * Injects the path of the wsdl document. + * + * @param wsdlPath the path of the wsdl document. + */ public void setWsdlPath(String wsdlPath) { _document = WsdlUtils.createWSDL(_environment, wsdlPath, true); } -} + + /** + * Create a reference to the WSRP properties element. + * + * @throws BuilderException in case of XPath evaluation problem. + */ + private void createWsrpPropertiesElement() throws BuilderException + { + try + { + _wsrpProperties = (Element) XPathAPI.selectSingleNode( + _document, + WSRP_PROPERTIES_XPATH); + } catch (TransformerException exception) + { + LOGGER.error(Messages.QMAN_100040_UNABLE_TO_LOCATE_WSRP_PROPERTIES); + throw new BuilderException(exception); + } + } + + /** + * Creates a template element that will be used for array + * type schema declaration(s). + */ + private void createReusableArrayComplextType() + { + _arrayComplexType = XmlUtils.createElement(_document, XSD_COMPLEX_TYPE_QNAME); + Element sequence = XmlUtils.createElement(_document, XSD_SEQUENCE_QNAME); + _nestedArrayType = XmlUtils.createElement(_document, XSD_ELEMENT_QNAME); + _nestedArrayType.setAttribute(NAME_ATTRIBUTE, "entry"); + sequence.appendChild(_nestedArrayType); + _arrayComplexType.appendChild(sequence); + } + + private void createSchemaElement() throws BuilderException + { + try + { + schema = (Element) XPathAPI.selectSingleNode( + _document.getDocumentElement(), + QMAN_SCHEMA_XPATH); + } catch(Exception exception) + { + LOGGER.error( + exception, + Messages.QMAN_100034_WSDL_SCHEMA_SECTION_NOT_FOUND); + throw new BuilderException(exception); + } + } + + /** + * The template WSDL contains a dummy URL as service location that + * needs to be replaced with the real service address. + * + * @throws BuilderException when replacement fails (XPath problem). + */ + private void replaceDummyServiceLocationOnWsdl() throws BuilderException + { + try + { + Attr location = (Attr) XPathAPI.selectSingleNode( + _document, + SERVICE_LOCATION_XPATH); + + StringBuilder builder = new StringBuilder("http://") + .append(InetAddress.getLocalHost().getHostName()) + .append(':') + .append(System.getProperty(Names.ADAPTER_PORT_PROPERTY_NAME,"8080")) + .append('/') + .append(_environment.getContextPath()) + .append('/') + .append("services/QManWsResource"); + location.setValue(builder.toString()); + } catch(Exception exception) + { + LOGGER.error( + exception, + Messages.QMAN_100026_SOAP_ADDRESS_REPLACEMENT_FAILURE); + throw new BuilderException(exception); + } + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/EntityInstanceNotFoundFault.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/EntityInstanceNotFoundFault.java index 25bb871e75..116d74727a 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/EntityInstanceNotFoundFault.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/EntityInstanceNotFoundFault.java @@ -50,6 +50,9 @@ public class EntityInstanceNotFoundFault extends QManFault */ public EntityInstanceNotFoundFault(EndpointReference endpointReference, ObjectName targetEntityName) { - super(endpointReference,EXCEPTION_QNAME, targetEntityName.getCanonicalName()); + super( + endpointReference, + EXCEPTION_QNAME, + targetEntityName.getCanonicalName()); } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ThreadSession.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ThreadSession.java index bc214b8b25..588879b951 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ThreadSession.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ThreadSession.java @@ -25,7 +25,6 @@ import javax.management.ObjectName; import org.w3c.dom.Document; import org.w3c.dom.Element; - /** * Thread-scoped session. * @@ -35,7 +34,8 @@ public class ThreadSession { private ObjectName _objectName; private Document _wsdl; - private Element [] additionalProperties; + private Element [] _wsrmdProperties; + /** * Empty constructor. */ @@ -90,7 +90,7 @@ public class ThreadSession */ public Element[] getResourceMetadataDescriptor() { - return additionalProperties; + return _wsrmdProperties; } /** @@ -100,6 +100,6 @@ public class ThreadSession */ public void setResourceMetadataDescriptor(Element[] rmd) { - this.additionalProperties = rmd; + this._wsrmdProperties = rmd; } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java index f47a587830..b5d978e0e5 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java @@ -64,6 +64,11 @@ public class WSDMAdapterEnvironment extends AbstractEnvironment return _realDirectory; } + /** + * Returns the default endpoint reference URI. + * + * @return the default endpoint reference URI. + */ public String getDefaultURIPrefix() { return new StringBuilder() @@ -79,4 +84,14 @@ public class WSDMAdapterEnvironment extends AbstractEnvironment .append("/services/") .toString(); } + + /** + * Returns the context path name of QMan application. + * + * @return the context path name of QMan application. + */ + public String getContextPath() + { + return _servletContext.getContextPath(); + } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/serializer/InvocationResultSerializer.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/serializer/InvocationResultSerializer.java index 0af570eacf..b819d52ad1 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/serializer/InvocationResultSerializer.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/serializer/InvocationResultSerializer.java @@ -38,8 +38,6 @@ import org.w3c.dom.Element; */ public class InvocationResultSerializer implements Serializer { - private Serializer _longSerializer = SerializerRegistry.getInstance().getSerializer(long.class); - private Serializer _stringSerializer = SerializerRegistry.getInstance().getSerializer(String.class); private Serializer _mapSerializer = SerializerRegistry.getInstance().getSerializer(Map.class); /** @@ -51,26 +49,8 @@ public class InvocationResultSerializer implements Serializer @SuppressWarnings("unchecked") public Object fromXML(Element elementData) throws SoapFault { - long statusCode = 0; - String statusText = null; - Map outputSection = null; - - Element[] elements = XmlUtils.getAllElements(elementData); - for (Element element : elements) - { - if ("statusCode".equals(element.getNodeName())) - { - statusCode = (Long) _longSerializer.fromXML(element); - } else if ("statusText".equals(element.getNodeName())) - { - statusText = (String) _stringSerializer.fromXML(element); - } else if ("outputParameters".equals(element.getNodeName())) - { - outputSection = (Map) _mapSerializer.fromXML(element); - } - } - - return new Result(statusCode,statusText,outputSection); + Element outputParameters = XmlUtils.getFirstElement(elementData); + return new Result((Map) _mapSerializer.fromXML(outputParameters)); } /** @@ -95,17 +75,11 @@ public class InvocationResultSerializer implements Serializer { Result result = (Result) obj; Element root = XmlUtils.createElement(qname); - Element statusCode = SerializerRegistry.getInstance().getSerializer(long.class).toXML(result.getStatusCode(), new QName("statusCode")); - Element statusText = SerializerRegistry.getInstance().getSerializer(String.class).toXML(result.getStatusText(), new QName("statusText")); - - root.appendChild(statusCode); - root.appendChild(statusText); if (result.getOutputParameters() != null) { Element outputSection = SerializerRegistry.getInstance().getSerializer(Map.class).toXML(result.getOutputParameters(), new QName("outputParameters")); root.appendChild(outputSection); } - return root; - + return root; } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/serializer/MapSerializer.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/serializer/MapSerializer.java index 1d0d02c669..07e1dfdc56 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/serializer/MapSerializer.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/serializer/MapSerializer.java @@ -62,25 +62,29 @@ public class MapSerializer implements Serializer public Object fromXML(Element xml) throws SoapFault { Map result = new HashMap(); - Element[] children = XmlUtils.getAllElements(xml); - Serializer objectDeserializer = SerializerRegistry.getInstance().getSerializer(Object.class); - for (Element entry : children) + if (xml != null) { - Element[] keysAndValues = XmlUtils.getAllElements(entry); - Object key = null; - Object value = null; - for (Element element : keysAndValues) + Element[] children = XmlUtils.getAllElements(xml); + Serializer objectDeserializer = SerializerRegistry.getInstance().getSerializer(Object.class); + + for (Element entry : children) { - if (Names.KEY.equals(element.getLocalName())) - { - key = _stringSerializer.fromXML(element); - } else if (Names.VALUE.equals(element.getLocalName())) + Element[] keysAndValues = XmlUtils.getAllElements(entry); + Object key = null; + Object value = null; + for (Element element : keysAndValues) { - value = objectDeserializer.fromXML(element); + if (Names.KEY.equals(element.getLocalName())) + { + key = _stringSerializer.fromXML(element); + } else if (Names.VALUE.equals(element.getLocalName())) + { + value = objectDeserializer.fromXML(element); + } } + result.put(key, value); } - result.put(key, value); } return result; } diff --git a/qpid/java/management/client/src/main/java/wsdl/QManWsResource.wsdl b/qpid/java/management/client/src/main/java/wsdl/QManWsResource.wsdl index 69647521ba..16169c9b78 100644 --- a/qpid/java/management/client/src/main/java/wsdl/QManWsResource.wsdl +++ b/qpid/java/management/client/src/main/java/wsdl/QManWsResource.wsdl @@ -93,7 +93,33 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/qpid/java/management/client/src/main/java/wsdl/WS-BaseNotification-1_3.wsdl b/qpid/java/management/client/src/main/java/wsdl/WS-BaseNotification-1_3.wsdl index 8764c18fc9..d53bf60f3a 100644 --- a/qpid/java/management/client/src/main/java/wsdl/WS-BaseNotification-1_3.wsdl +++ b/qpid/java/management/client/src/main/java/wsdl/WS-BaseNotification-1_3.wsdl @@ -424,23 +424,22 @@ This document and the information contained herein is provided on an "AS IS" bas - + - +--> - - + + - - + + - + diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/TestConstants.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/TestConstants.java index 12ba1fab73..9abcd08eef 100644 --- a/qpid/java/management/client/src/test/java/org/apache/qpid/management/TestConstants.java +++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/TestConstants.java @@ -63,5 +63,5 @@ public interface TestConstants int SAMPLE_ACCESS_CODE = 1; String YEARS = "years"; int SAMPLE_MIN_VALUE = 1; - int SAMPLE_MAX_VALUE = 120; + int SAMPLE_MAX_VALUE = 120; } \ No newline at end of file diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java index 8e9c3ccd6b..72bd45f70f 100644 --- a/qpid/java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java +++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java @@ -23,16 +23,13 @@ package org.apache.qpid.management.configuration; import java.util.Map; import java.util.UUID; +import junit.framework.TestCase; + import org.apache.qpid.management.TestConstants; import org.apache.qpid.management.domain.handler.base.IMessageHandler; import org.apache.qpid.management.domain.handler.impl.ConfigurationMessageHandler; import org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler; import org.apache.qpid.management.domain.handler.impl.SchemaResponseMessageHandler; -import org.apache.qpid.management.domain.model.AccessMode; -import org.apache.qpid.management.domain.model.type.Type; -import org.apache.qpid.management.domain.model.type.Uint8; - -import junit.framework.TestCase; /** * Test case for Configuration singleton. @@ -46,22 +43,7 @@ public class ConfigurationTest extends TestCase { assertSame(Configuration.getInstance(),Configuration.getInstance()); } - - /** - * Tests the execution of getType() method when a valid code is supplied. - * - *
    precondition : the requested type already exist on the configuration. - *
    postcondition : the requested type is returned and no exception is thrown. - */ - public void testGetTypeOk() throws UnknownTypeCodeException - { - TypeMapping mapping = new TypeMapping(TestConstants.VALID_CODE,new Uint8()); - Configuration.getInstance().addTypeMapping(mapping); - Type type = Configuration.getInstance().getType(TestConstants.VALID_CODE); - assertTrue(type instanceof Uint8); - } - /** * Tests the execution of getType() method when a unknown code is supplied. * @@ -79,22 +61,7 @@ public class ConfigurationTest extends TestCase assertEquals(TestConstants.VALID_CODE*10001,expected.getCode()); } } - - /** - * Tests the execution of getAccessMode() method when a valid code is supplied. - * - *
    precondition : the requested access mode already exist on the configuration. - *
    postcondition : the requested access mode is returned and no exception is thrown. - */ - public void testGetAccessModeOk() throws UnknownAccessCodeException - { - AccessModeMapping mapping = new AccessModeMapping(TestConstants.VALID_CODE,AccessMode.RW); - Configuration.getInstance().addAccessModeMapping(mapping); - AccessMode accessMode = Configuration.getInstance().getAccessMode(TestConstants.VALID_CODE); - - assertSame(AccessMode.RW,accessMode); - } - + /** * Tests the execution of getAccessMode() method when a unknown code is supplied. * diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/BaseWsDmAdapterTestCase.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/BaseWsDmAdapterTestCase.java new file mode 100644 index 0000000000..900d14c72e --- /dev/null +++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/BaseWsDmAdapterTestCase.java @@ -0,0 +1,143 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.wsdm; + +import java.lang.management.ManagementFactory; +import java.net.URI; +import java.util.UUID; + +import javax.management.MBeanInfo; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import junit.framework.TestCase; + +import org.apache.muse.ws.addressing.EndpointReference; +import org.apache.muse.ws.resource.remote.WsResourceClient; +import org.apache.muse.ws.resource.sg.remote.ServiceGroupClient; +import org.apache.qpid.management.Names; +import org.apache.qpid.management.Protocol; +import org.apache.qpid.management.TestConstants; + +/** + * Test case for WS-Resource lifecycle management. + * + * @author Andrea Gazzarini + */ +public abstract class BaseWsDmAdapterTestCase extends TestCase implements TestConstants{ + + protected MBeanServer _managementServer; + protected ObjectName _resourceObjectName; + + protected WsResourceClient _resourceClient; + protected MBeanInfo _mbeanInfo; + + /** + * Set up fixture for this test case. + * + * @throws Exception when the test case intialization fails. + */ + protected void setUp() throws Exception + { + _managementServer = ManagementFactory.getPlatformMBeanServer(); + + ServiceGroupClient serviceGroup = getServiceGroupClient(); + WsResourceClient [] members = serviceGroup.getMembers(); + + assertEquals( + "No resource has been yet created so how is " + + "it possible that service group children list is not empty?", + 0, + members.length); + + _managementServer.invoke( + Names.QPID_EMULATOR_OBJECT_NAME, + "createQueue", + new Object[]{_resourceObjectName = createResourceName()}, + new String[]{ObjectName.class.getName()}); + + members = serviceGroup.getMembers(); + assertEquals( + "One resource has just been created so " + + "I expect to find it on service group children list...", + 1, + members.length); + + _resourceClient = members[0]; + _mbeanInfo = _managementServer.getMBeanInfo(_resourceObjectName); + } + + /** + * Shutdown procedure for this test case. + * + * @throws Exception when either the server or some resource fails to shutdown. + */ + @Override + protected void tearDown() throws Exception + { + ServiceGroupClient serviceGroup = getServiceGroupClient(); + WsResourceClient [] members = serviceGroup.getMembers(); + + _managementServer.invoke( + Names.QPID_EMULATOR_OBJECT_NAME, + "unregister", + new Object[]{_resourceObjectName}, + new String[]{ObjectName.class.getName()}); + + members = serviceGroup.getMembers(); + + assertEquals( + "No resource has been yet created so how is it possible that service group children list is not empty?", + 0, + members.length); + } + + /** + * Creates a service group client reference. + * + * @return a service group client reference. + */ + private ServiceGroupClient getServiceGroupClient() + { + URI address = URI.create( + Protocol.DEFAULT_ENDPOINT_URI.replaceFirst("8080",System.getProperty(Names.ADAPTER_PORT_PROPERTY_NAME))); + return new ServiceGroupClient(new EndpointReference(address)); + } + + /** + * In order to test the behaviour of the WS-DM adapter, at + * least one resource must be created. This is the method that + * returns the name (ObjectName on JMX side, Resource-ID on WSDM side) + * of that resource + * + * @return the name of the MBean instance that will be created. + * @throws Exception when the name if malformed. Practically never. + */ + private ObjectName createResourceName() throws Exception + { + return new ObjectName( + "Q-MAN:objectId="+UUID.randomUUID()+ + ", brokerID="+UUID.randomUUID()+ + ",class=queue"+ + ",package=org.apache.qpid"+ + ",name="+System.currentTimeMillis()); + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetMultipleResourcePropertiesTestCase.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetMultipleResourcePropertiesTestCase.java new file mode 100644 index 0000000000..d59e7a39e5 --- /dev/null +++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetMultipleResourcePropertiesTestCase.java @@ -0,0 +1,125 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.wsdm; + +import java.util.Date; +import java.util.UUID; + +import javax.management.MBeanAttributeInfo; +import javax.xml.namespace.QName; + +import org.apache.muse.ws.addressing.soap.SoapFault; +import org.apache.muse.ws.resource.WsrfConstants; +import org.apache.qpid.management.Names; +import org.w3c.dom.Element; + +/** + * Test case for Web Service Resource Properties interfaces. + * Those interfaces are defined on http://docs.oasis-open.org/wsrf/wsrf-ws_resource_properties-1.2-spec-os.pdf + * (Web Services Resource Properties 1.2 - (WS-ResourceProperties). + * For a better explanation see chapter 5 of the specification above. + * + * @author Andrea Gazzarini + */ +public class GetMultipleResourcePropertiesTestCase extends BaseWsDmAdapterTestCase +{ + /** + * Tests the GetMultipleResourceProperties interface when the request contains + * an unknwon target resource. + * + *
    precondition : the GetMultipleResourceProperties request contains an unknwon resource. + *
    postcondition : a SoapFault is thrown and the corresponding detail contains an + * UnknownResourceFault element. + */ + public void testGetMultipleResourcePropertiesKO_WithUnknownResourceFault() throws Exception + { + try + { + _resourceClient.getEndpointReference().removeParameter(Names.RESOURCE_ID_QNAME); + _resourceClient.getEndpointReference().addParameter(Names.RESOURCE_ID_QNAME,"lablabalbal"); + + _resourceClient.getMultipleResourceProperties(new QName[]{}); + } catch(SoapFault expected) + { + assertEquals( + WsrfConstants.RESOURCE_UNKNOWN_QNAME.getLocalPart(), + expected.getDetail().getLocalName()); + } + } + + /** + * Test the WS-RP GetResourceProperties interface of the WS-DM adapter. + * + *
    precondition : a ws resource exists and is registered. + *
    postcondition : Properties are correctly returned according to WSRP interface and they (their value) + * are matching with corresponding MBean properties. + */ + public void testGetMultipleResourcePropertiesOK() throws Exception + { + MBeanAttributeInfo [] attributesMetadata = _mbeanInfo.getAttributes(); + QName[] names = new QName[attributesMetadata.length]; + + int index = 0; + for (MBeanAttributeInfo attributeMetadata : _mbeanInfo.getAttributes()) + { + QName qname = new QName(Names.NAMESPACE_URI,attributeMetadata.getName(),Names.PREFIX); + names[index++] = qname; + } + + Element[] properties =_resourceClient.getMultipleResourceProperties(names); + for (Element element : properties) + { + String name = element.getLocalName(); + Object value = _managementServer.getAttribute(_resourceObjectName, name); + if ("Name".equals(name)) + { + assertEquals( + value, + element.getTextContent()); + } else if ("Durable".equals(name)) + { + assertEquals( + value, + Boolean.valueOf(element.getTextContent())); + } else if ("ExpireTime".equals(name)) + { + assertEquals( + value, + new Date(Long.valueOf(element.getTextContent()))); + } else if ("MsgTotalEnqueues".equals(name)) + { + assertEquals( + value, + Long.valueOf(element.getTextContent())); + } else if ("ConsumerCount".equals(name)) + { + assertEquals( + value, + Integer.valueOf(element.getTextContent())); + }else if ("VhostRef".equals(name)) + { + assertEquals( + value, + UUID.fromString(element.getTextContent())); + } + } + } +} diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetResourcePropertiesTestCase.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetResourcePropertiesTestCase.java new file mode 100644 index 0000000000..e18e928cf4 --- /dev/null +++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetResourcePropertiesTestCase.java @@ -0,0 +1,105 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.wsdm; + +import java.lang.reflect.Array; + +import javax.management.MBeanAttributeInfo; +import javax.xml.namespace.QName; + +import org.apache.muse.ws.addressing.soap.SoapFault; +import org.apache.muse.ws.resource.WsrfConstants; +import org.apache.qpid.management.Names; + +/** + * Test case for Web Service Resource Properties interfaces. + * Those interfaces are defined on http://docs.oasis-open.org/wsrf/wsrf-ws_resource_properties-1.2-spec-os.pdf + * (Web Services Resource Properties 1.2 - (WS-ResourceProperties). + * For a better explanation see chapter 5 of the specification above. + * + * @author Andrea Gazzarini + */ +public class GetResourcePropertiesTestCase extends BaseWsDmAdapterTestCase +{ + + /** + * Test the WS-RP GetResourceProperty interface of the WS-DM adapter. + * + *
    precondition : a ws resource exists and is registered. + *
    postcondition : property values coming from WS-DM resource are the same of the JMX interface. + */ + public void testGetResourcePropertiesOK() throws Exception + { + MBeanAttributeInfo [] attributesMetadata = _mbeanInfo.getAttributes(); + for (MBeanAttributeInfo attributeMetadata : attributesMetadata) + { + String name = attributeMetadata.getName(); + Object propertyValues = _resourceClient.getPropertyAsObject( + new QName( + Names.NAMESPACE_URI, + name, + Names.PREFIX), + Class.forName(attributeMetadata.getType())); + + int length = Array.getLength(propertyValues); + if (length != 0) + { + Object propertyValue = Array.get(propertyValues, 0); + + assertEquals( + "Comparison failed for property "+name, + _managementServer.getAttribute(_resourceObjectName,name), + propertyValue); + } else { + assertNull( + String.format( + "\"%s\" property value shouldn't be null. Its value is %s", + name, + _managementServer.getAttribute(_resourceObjectName,name)), + _managementServer.getAttribute(_resourceObjectName,name)); + } + } + } + + /** + * Tests the GetMultipleResourceProperties interface when the request contains + * an unknwon target resource. + * + *
    precondition : the GetMultipleResourceProperties request contains an unknwon resource. + *
    postcondition : a SoapFault is thrown and the corresponding detail contains an + * UnknownResourceFault element. + */ + public void testGetResourcePropertiesKO_WithUnknownResourceFault() throws Exception + { + try + { + _resourceClient.getEndpointReference().removeParameter(Names.RESOURCE_ID_QNAME); + _resourceClient.getEndpointReference().addParameter(Names.RESOURCE_ID_QNAME,"lablabalbal"); + + _resourceClient.getResourceProperty(new QName("a","b","c")); + } catch(SoapFault expected) + { + assertEquals( + WsrfConstants.RESOURCE_UNKNOWN_QNAME.getLocalPart(), + expected.getDetail().getLocalName()); + } + } +} diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetResourcePropertyDocumentTestCase.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetResourcePropertyDocumentTestCase.java new file mode 100644 index 0000000000..862115f841 --- /dev/null +++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/GetResourcePropertyDocumentTestCase.java @@ -0,0 +1,134 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.wsdm; + +import javax.xml.namespace.QName; + +import org.apache.muse.util.xml.XmlUtils; +import org.apache.muse.ws.addressing.soap.SoapFault; +import org.apache.muse.ws.resource.WsrfConstants; +import org.apache.qpid.management.Names; +import org.w3c.dom.Element; + +/** + * Test case for Web Service Resource Properties interfaces. + * Those interfaces are defined on http://docs.oasis-open.org/wsrf/wsrf-ws_resource_properties-1.2-spec-os.pdf + * (Web Services Resource Properties 1.2 - (WS-ResourceProperties). + * For a better explanation see chapter 5 of the specification above. + * + * @author Andrea Gazzarini + */ +public class GetResourcePropertyDocumentTestCase extends BaseWsDmAdapterTestCase +{ + /** + * Tests the GetResourcePropertyDocument interface when the request contains + * an unknwon target resource. + * + *
    precondition : the GetResourcePropertyDocument contains an unknwon resource. + *
    postcondition : a SoapFault is thrown and the corresponding detail contains an + * UnknownResourceFault element. + */ + public void testGetResourcePropertyDocumentKO_WithUnknownResourceFault() throws Exception + { + try + { + _resourceClient.getEndpointReference().removeParameter(Names.RESOURCE_ID_QNAME); + _resourceClient.getEndpointReference().addParameter(Names.RESOURCE_ID_QNAME,"lablabalbal"); + _resourceClient.setTrace(true); + + _resourceClient.getResourcePropertyDocument(); + } catch(SoapFault expected) + { + assertEquals( + WsrfConstants.RESOURCE_UNKNOWN_QNAME.getLocalPart(), + expected.getDetail().getLocalName()); + } + } + + /** + * Tests the WS-RP PutResourcePropertyDocument interface of the WS-DM adapter. + * + *
    precondition : a ws resource exists and is registered. + *
    postcondition : A read / write property is correctly set according to WSRP interface. + */ + public void testGetAndPutResourcePropertyDocumentOK() throws Exception + { + String expectedMgmtPubIntervalValue = "4321"; + String propertyName = "MgmtPubInterval"; + + Element propertiesDocument = _resourceClient.getResourcePropertyDocument(); + Element [] properties = XmlUtils.getAllElements(propertiesDocument); + + for (Element element : properties) + { + if (propertyName.equals(element.getLocalName())) { + element.setTextContent(expectedMgmtPubIntervalValue); + } else { + propertiesDocument.removeChild(element); + } + } + + _resourceClient.putResourcePropertyDocument(propertiesDocument); + + Element newProperties = _resourceClient.getResourcePropertyDocument(); + + Element mgmtPubInterval = XmlUtils.getElement( + newProperties, new QName( + Names.NAMESPACE_URI, + propertyName, + Names.PREFIX)); + + assertEquals(expectedMgmtPubIntervalValue,mgmtPubInterval.getTextContent()); + } + + /** + * Tests the WS-RP PutResourcePropertyDocument interface of the WS-DM adapter. + * Specifically it tries to update the value of a read-only property. + * + *
    precondition : a ws resource exists, it is registered and has at least one read-only property. + *
    postcondition : An exception is thrown indicating the failure. + */ + public void testGetAndPutResourcePropertyDocumentKO_WithReadOnlyProperty() throws Exception + { + String propertyName = "Name"; + + Element propertiesDocument = _resourceClient.getResourcePropertyDocument(); + Element [] properties = XmlUtils.getAllElements(propertiesDocument); + + for (Element element : properties) + { + if (propertyName.equals(element.getLocalName())) { + element.setTextContent("ThisIsTheNewValueOfNameProperty"); + } else { + propertiesDocument.removeChild(element); + } + } + + try + { + _resourceClient.putResourcePropertyDocument(propertiesDocument); + fail("It's not possible to update the value of a read-only property."); + } catch (SoapFault expected) + { + + } + } +} diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/MetadataExchangeInterfaceTestCase.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/MetadataExchangeInterfaceTestCase.java new file mode 100644 index 0000000000..046f2226e6 --- /dev/null +++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/MetadataExchangeInterfaceTestCase.java @@ -0,0 +1,169 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.wsdm; + +import javax.xml.namespace.QName; + +import org.apache.muse.core.proxy.ProxyHandler; +import org.apache.muse.core.proxy.ReflectionProxyHandler; +import org.apache.muse.util.xml.XmlUtils; +import org.apache.muse.ws.addressing.soap.SoapFault; +import org.apache.muse.ws.metadata.WsxConstants; +import org.apache.muse.ws.resource.WsrfConstants; +import org.apache.muse.ws.resource.metadata.WsrmdConstants; +import org.apache.qpid.management.Names; +import org.w3c.dom.Element; + +/** + * Test case for QMan metadata exchange interface. + * + * @author Andrea Gazzarini + */ +public class MetadataExchangeInterfaceTestCase extends BaseWsDmAdapterTestCase +{ + /** + * Test the MetadataExchange interface when the corresponding + * request doesn't contain a dialect. According to WS-MetadataExchange specs this should be + * intended as a "give-me-all-metadata" for that resource. + * + *
    precondition : the GetMetadata request doesn't contain a dialect. + *
    postcondition : the whole metadata document is returned with all metadata . + * It will contain both WSDL and RMD. + */ + @SuppressWarnings("unchecked") + public void testGetMetadataOK_WithoutDialect() throws Exception + { + Element[] result = (Element[]) _resourceClient.invoke( + getProxyHandler(), + new Object[]{""}); + + assertEquals(2,result.length); + + Element rmdMetadataSection = result[0]; + Element wsdlMetadataSection = result[1]; + + Element rmd = XmlUtils.getFirstElement(rmdMetadataSection); + Element wsdl = XmlUtils.getFirstElement(wsdlMetadataSection); + + assertEquals("MetadataDescriptor",rmd.getLocalName()); + assertEquals("definitions",wsdl.getLocalName()); + } + + /** + * Test the MetadataExchange interface when the WSDL dialect is specified on the request. + * + *
    precondition : the GetMetadata request contains WSDL dialect. + *
    postcondition : the resource WSDL metadata document is returned. + */ + @SuppressWarnings("unchecked") + public void testGetMetadataOK_WithWSDLDialect() throws Exception + { + Element[] result = (Element[]) _resourceClient.invoke( + getProxyHandler(), + new Object[]{WsxConstants.WSDL_DIALECT}); + + assertEquals(1,result.length); + + Element wsdlMetadataSection = result[0]; + + Element wsdl = XmlUtils.getFirstElement(wsdlMetadataSection); + + assertEquals("definitions",wsdl.getLocalName()); + } + + /** + * Test the MetadataExchange interface when the RMD dialect is specified on the request. + * + *
    precondition : the GetMetadata request contains RMD dialect. + *
    postcondition : the RMD metadata document is returned. + */ + @SuppressWarnings("unchecked") + public void testGetMetadataOK_WithRMDDialect() throws Exception + { + Element[] result = (Element[]) _resourceClient.invoke( + getProxyHandler(), + new Object[]{WsrmdConstants.NAMESPACE_URI}); + + assertEquals(1,result.length); + + Element rmdMetadataSection = result[0]; + + Element wsdl = XmlUtils.getFirstElement(rmdMetadataSection); + + assertEquals("MetadataDescriptor",wsdl.getLocalName()); + } + + /** + * Test the MetadataExchange interface with an unknown metadata dialect. + * + *
    precondition : the GetMetadata request contains an unknown dialect. + *
    postcondition : the returned metadata section is empty. + */ + @SuppressWarnings("unchecked") + public void testGetMetadataKO_WithoutUnknownDialect() throws Exception + { + Element [] metadata = (Element[]) _resourceClient.invoke( + getProxyHandler(), + new Object[]{"HopeThisIsAnUnknownDialect"}); + + assertEquals(0,metadata.length); + } + + /** + * Test the MetadataExchange interface with an unknown metadata dialect. + * + *
    precondition : the GetMetadata request contains an unknown dialect. + *
    postcondition : the returned metadata section is empty. + */ + @SuppressWarnings("unchecked") + public void testGetMetadataKO_WithoutUnknownResourceFault() throws Exception + { + try + { + _resourceClient.getEndpointReference().removeParameter(Names.RESOURCE_ID_QNAME); + _resourceClient.getEndpointReference().addParameter(Names.RESOURCE_ID_QNAME,"lablabalbal"); + + _resourceClient.invoke(getProxyHandler(), new Object[]{""}); + } catch(SoapFault expected) + { + assertEquals( + WsrfConstants.RESOURCE_UNKNOWN_QNAME.getLocalPart(), + expected.getDetail().getLocalName()); + } + } + + /** + * Returns a proxy handler used for working with metadata exchange + * interface. + * + * @return a metadata proxy handler. + */ + private ProxyHandler getProxyHandler() + { + ProxyHandler getMetadataHandler = new ReflectionProxyHandler(); + getMetadataHandler.setAction("http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata"); + getMetadataHandler.setRequestName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "GetMetadata", "wsx")); + getMetadataHandler.setRequestParameterNames(new QName[]{new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Dialect", "wsx")}); + getMetadataHandler.setResponseName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Metadata", "wsx")); + getMetadataHandler.setReturnType(Element[].class); + return getMetadataHandler; + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/OperationInvocationInterfaceTestCase.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/OperationInvocationInterfaceTestCase.java new file mode 100644 index 0000000000..afc4a62085 --- /dev/null +++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/OperationInvocationInterfaceTestCase.java @@ -0,0 +1,580 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.wsdm; + +import java.lang.reflect.Array; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.xml.namespace.QName; + +import org.apache.muse.core.proxy.ProxyHandler; +import org.apache.muse.core.proxy.ReflectionProxyHandler; +import org.apache.muse.ws.addressing.soap.SoapFault; +import org.apache.qpid.management.Names; +import org.apache.qpid.management.wsdm.capabilities.Result; + +/** + * Test case for QMan operation invocation interface. + * + * @author Andrea Gazzarini + */ +public class OperationInvocationInterfaceTestCase extends BaseWsDmAdapterTestCase +{ + private Map _invocationHandlers = createInvocationHandlers(); + + /** + * Test operation invocation on WS-Resource. + * This method tests the exchange of a byte type array between requestor + * and service provider. + * + *
    precondition : a WS-Resource exists and is registered and the requested + * operation is available on that. + *
    postcondition : invocations are executed successfully, no exception is thrown + * and byte array are correctly returned. + */ + @SuppressWarnings("unchecked") + public void testOperationInvocationOK_withByteArray() throws Exception + { + byte [] expectedByteResult = {1,3,4,2,2,44,22,3,3,55,66}; + + Object result = _resourceClient.invoke( + _invocationHandlers.get("echoWithByteArray"), + new Object[]{expectedByteResult}); + + Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); + + Map out = (Map) getOutputParameters.invoke(result); + + assertEquals("Output parameters must be 1.",1,out.size()); + assertArrayEquals(expectedByteResult, out.get(byte[].class.getName())); + } + + /** + * Test a simple operation invocation on a WS-Resource. + * This method tests a simple operation without any input and output parameters. + * + *
    precondition : a ws resource exists and is registered and the requested operation + * is available on that. + *
    postcondition : invocations are executed successfully an no exception is thrown. + */ + @SuppressWarnings("unchecked") + public void testSimpleOperationInvocationOK() throws Exception + { + Object result = _resourceClient.invoke( + _invocationHandlers.get("voidWithoutArguments"), + null); + + assertNotNull(result); + } + + /** + * Test a the invocation on a WS-Resource with a method that throws an exception.. + * + *
    precondition : a ws resource exists and is registered and the requested + * operation is available on that. + *
    postcondition : an exception is thrown by the requested method. + */ + @SuppressWarnings("unchecked") + public void testInvocationException_OK() throws Exception + { + try + { + _resourceClient.invoke( + _invocationHandlers.get("throwsException"), + null); + fail("The requested operation has thrown an exception so a Soap Fault is expected..."); + } catch(SoapFault expected) + { + } + } + + /** + * Test operation invocation on WS-Resource. + * This method tests the exchange of UUID type between requestor and service provider. + * + *
    precondition : a WS-Resource exists and is registered and the requested operation + * is available on that. + *
    postcondition : invocations are executed successfully, no exception is thrown + * and parameters are correctly returned. + */ + @SuppressWarnings("unchecked") + public void testOperationInvocationOK_withUUID() throws Exception + { + UUID expectedUuid = UUID.randomUUID(); + + Object result = _resourceClient.invoke( + _invocationHandlers.get("echoWithUUID"), + new Object[]{expectedUuid}); + + Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); + + Map out = (Map) getOutputParameters.invoke(result); + + assertEquals("Output parameters must be 1.",1,out.size()); + assertEquals(expectedUuid, out.get("uuid")); + } + + /** + * Test operation invocation on WS-Resource. + * This method tests the exchange of Map type between requestor and service provider. + * For this test exchanged arrays contain : + * + *
    precondition : a ws resource exists and is registered and the requested + * operation is available on that. + *
    postcondition : invocations are executed successfully, no exception is + * thrown and parameters are correctly returned. + */ + @SuppressWarnings("unchecked") + public void testOperationInvocationOK_withMap() throws Exception + { + Map expectedMap = new HashMap(); + expectedMap.put("p1", new Long(1)); + expectedMap.put("p2", Boolean.TRUE); + expectedMap.put("p3", 1234d); + expectedMap.put("p4", 11.2f); + expectedMap.put("p5", 1272); + expectedMap.put("p6", (short)12); + expectedMap.put("p7", "aString"); + expectedMap.put("p8", "http://qpid.apache.org"); + expectedMap.put("p9", new Date(12383137128L)); + expectedMap.put("p10", new byte[]{1,2,2,3,3,4}); + + Object result = _resourceClient.invoke( + _invocationHandlers.get("echoWithMap"), + new Object[]{expectedMap}); + + Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); + + Map out = (Map) ((Map) getOutputParameters.invoke(result)).get("map"); + + assertEquals("Output parameters must be 10.",10,out.size()); + assertEquals(expectedMap.get("p1"),out.get("p1")); + assertEquals(expectedMap.get("p2"),out.get("p2")); + assertEquals(expectedMap.get("p3"),out.get("p3")); + assertEquals(expectedMap.get("p4"),out.get("p4")); + assertEquals(expectedMap.get("p5"),out.get("p5")); + assertEquals(expectedMap.get("p6"),out.get("p6")); + assertEquals(expectedMap.get("p7"),out.get("p7")); + assertEquals(expectedMap.get("p8"),out.get("p8")); + assertEquals(expectedMap.get("p9"),out.get("p9")); + assertTrue( Arrays.equals((byte[])expectedMap.get("p10"),(byte[])out.get("p10"))); + } + + /** + * Test operation invocation on WS-Resource. + * This method tests the exchange of simple types between requestor and + * service provider. + * + * With simple types we mean : + * + *
      + *
    • java.lang.Long / long (xsd:long) + *
    • java.lang.Integer / int (xsd:int / xsd:integer) + *
    • java.lang.Double/ double (xsd:double) + *
    • java.lang.Float / float (xsd:float) + *
    • java.lang.Short / short (xsd:short) + *
    • java.lang.Boolean / boolean (xsd:boolean) + *
    • java.lang.String (xsd:string) + *
    • java.net.URI (xsd:anyURI) + *
    • java.util.Date(xsd:dateTime) + *
    + * + *
    precondition : a ws resource exists and is registered and the requested operation is + * available on that. + *
    postcondition : invocations are executed successfully, no exception is thrown and + * parameters are correctly returned. + */ + @SuppressWarnings("unchecked") + public void testOperationInvocationOK_withSimpleTypes() throws Exception + { + Long expectedLongResult = new Long(1373); + Boolean expectedBooleanResult = Boolean.TRUE; + Double expectedDoubleResult = new Double(12763.44); + Float expectedFloatResult = new Float(2727.233f); + Integer expectedIntegerResult = new Integer(28292); + Short expectedShortResult = new Short((short)227); + String expectedStringResult = "expectedStringResult"; + URI expectedUriResult = URI.create("http://qpid.apache.org/"); + Date expectedDateResult = new Date(); + + Object result = _resourceClient.invoke( + _invocationHandlers.get("echoWithSimpleTypes"), + new Object[]{ + expectedLongResult, + expectedBooleanResult, + expectedDoubleResult, + expectedFloatResult, + expectedIntegerResult, + expectedShortResult, + expectedStringResult, + expectedUriResult, + expectedDateResult}); + + Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); + Map out = (Map) getOutputParameters.invoke(result); + + assertEquals("Output parameters must be 9.",9,out.size()); + assertTrue("Long output parameter not found on result object.",out.containsValue(expectedLongResult)); + assertTrue("Boolean output parameter not found on result object.",out.containsValue(expectedBooleanResult)); + assertTrue("Double output parameter not found on result object.",out.containsValue(expectedDoubleResult)); + assertTrue("Float output parameter not found on result object.",out.containsValue(expectedFloatResult)); + assertTrue("Integer output parameter not found on result object.",out.containsValue(expectedIntegerResult)); + assertTrue("Short output parameter not found on result object.",out.containsValue(expectedShortResult)); + assertTrue("String output parameter not found on result object.",out.containsValue(expectedStringResult)); + assertTrue("URI output parameter not found on result object.",out.containsValue(expectedUriResult)); + assertTrue("Date output parameter not found on result object.",out.containsValue(expectedDateResult)); + } + + /** + * Test operation invocation on WS-Resource. + * This method tests the exchange of arrays between requestor and service provider. + * For this test exchanged arrays contain : + * + *
      + *
    • java.lang.Long (xsd:long) + *
    • java.lang.Integer (xsd:int / xsd:integer) + *
    • java.lang.Double (xsd:double) + *
    • java.lang.Float (xsd:float) + *
    • java.lang.Short (xsd:short) + *
    • java.lang.Boolean (xsd:boolean) + *
    • java.lang.String (xsd:string) + *
    • java.net.URI (xsd:anyURI) + *
    • java.util.Date(xsd:dateTime) + *
    + * + *
    precondition : a ws resource exists and is registered and the requested operation is available on that. + *
    postcondition : invocations are executed successfully, no exception is thrown and parameters are correctly returned. + */ + @SuppressWarnings("unchecked") + public void testOperationInvocationOK_withWrapperArrays() throws Exception + { + Long [] expectedLongResult = {new Long(2),new Long(1),new Long(3),new Long(4)}; + Boolean [] expectedBooleanResult = { Boolean.TRUE,Boolean.FALSE,Boolean.FALSE}; + Double [] expectedDoubleResult = {12763.44d,2832.33d,2292.33d,22293.22d}; + Float [] expectedFloatResult = {2727.233f,1f,2f,4f,5.4f,33.2f}; + Integer [] expectedIntegerResult = {1,2,3,4,55,66,77,88,99}; + Short [] expectedShortResult = {(short)227,(short)23,(short)9}; + String [] expectedStringResult = {"s1","s2","s333","s4"}; + URI [] expectedUriResult = { + URI.create("http://qpid.apache.org/"), + URI.create("http://www.apache.org"), + URI.create("http://projects.apache.org")}; + + Date [] expectedDateResult = { + new Date(), + new Date(38211897), + new Date(903820382)}; + + Object result = _resourceClient.invoke( + _invocationHandlers.get("echoWithArrays"), + new Object[]{ + expectedLongResult, + expectedBooleanResult, + expectedDoubleResult, + expectedFloatResult, + expectedIntegerResult, + expectedShortResult, + expectedStringResult, + expectedUriResult, + expectedDateResult}); + + Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); + Map out = (Map) getOutputParameters.invoke(result); + + assertEquals("Output parameters must be 9.",9,out.size()); + assertTrue("Long array doesn't match.",Arrays.equals(expectedLongResult, (Long[])out.get(Long.class.getName()))); + assertTrue("Boolean array doesn't match.",Arrays.equals(expectedBooleanResult, (Boolean[])out.get(Boolean.class.getName()))); + assertTrue("Double array doesn't match.",Arrays.equals(expectedDoubleResult, (Double[])out.get(Double.class.getName()))); + assertTrue("Float array doesn't match.",Arrays.equals(expectedFloatResult, (Float[])out.get(Float.class.getName()))); + assertTrue("Integer array doesn't match.", Arrays.equals(expectedIntegerResult, (Integer[])out.get(Integer.class.getName()))); + assertTrue("Short array doesn't match.",Arrays.equals(expectedShortResult, (Short[])out.get(Short.class.getName()))); + assertTrue("String array doesn't match.",Arrays.equals(expectedStringResult, (String[])out.get(String.class.getName()))); + assertTrue("URI array doesn't match.",Arrays.equals(expectedUriResult, (URI[])out.get(URI.class.getName()))); + assertTrue("Date array doesn't match.",Arrays.equals(expectedDateResult, (Date[])out.get(Date.class.getName()))); + } + + /** + * Test operation invocation on WS-Resource. + * This method tests the exchange of primitive type arrays between requestor and service provider. + * NOte that even the sent array contain primtiive type QMan deals only with objects so in the result + * object you will find the corresponding wrapper types. + * + * For this test exchanged arrays contain : + * + *
      + *
    • java.lang.Long / long (xsd:long) + *
    • java.lang.Integer / int (xsd:int / xsd:integer) + *
    • java.lang.Double/ double (xsd:double) + *
    • java.lang.Float / float (xsd:float) + *
    • java.lang.Short / short (xsd:short) + *
    • java.lang.Boolean / boolean (xsd:boolean) + *
    + * + *
    precondition : a ws resource exists and is registered and the requested operation is available on that. + *
    postcondition : invocations are executed successfully, no exception is thrown and parameters are correctly returned. + */ + @SuppressWarnings("unchecked") + public void testOperationInvocationOK_withPrimitiveArrays() throws Exception + { + long [] expectedLongResult = {1L,2L,3L,4L}; + boolean [] expectedBooleanResult = { true,false,false}; + double [] expectedDoubleResult = {12763.44d,2832.33d,2292.33d,22293.22d}; + float [] expectedFloatResult = {2727.233f,1f,2f,4f,5.4f,33.2f}; + int [] expectedIntegerResult = {1,2,3,4,55,66,77,88,99}; + short [] expectedShortResult = {(short)227,(short)23,(short)9}; + + Object result = _resourceClient.invoke( + _invocationHandlers.get("echoWithSimpleTypeArrays"), + new Object[]{ + expectedLongResult, + expectedBooleanResult, + expectedDoubleResult, + expectedFloatResult, + expectedIntegerResult, + expectedShortResult}); + + Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); + Map out = (Map) getOutputParameters.invoke(result); + + assertEquals("Output parameters must be 6.",6,out.size()); + assertArrayEquals(expectedLongResult, out.get(long.class.getName())); + assertArrayEquals(expectedBooleanResult, out.get(boolean.class.getName())); + assertArrayEquals(expectedDoubleResult, out.get(double.class.getName())); + assertArrayEquals(expectedFloatResult, out.get(float.class.getName())); + assertArrayEquals(expectedIntegerResult, out.get(int.class.getName())); + assertArrayEquals(expectedShortResult, out.get(short.class.getName())); + } + + /** + * Internal method used for array comparison using reflection. + * + * @param expectedArray the expected array. + * @param resultArray the array that must match the expected one. + */ + private void assertArrayEquals(Object expectedArray, Object resultArray) + { + int expectedArrayLength = Array.getLength(expectedArray); + int resultArrayLength = Array.getLength(resultArray); + + assertEquals(expectedArrayLength,resultArrayLength); + + for (int index = 0; index < expectedArrayLength; index++) + { + Object expected = Array.get(expectedArray, index); + Object result = Array.get(resultArray, index); + + assertEquals(expected,result); + } + } + + private Map createInvocationHandlers() + { + Map handlers = new HashMap(); + + ProxyHandler handler = new ReflectionProxyHandler(); + handler.setAction(Names.NAMESPACE_URI+"/"+"voidWithoutArguments"); + handler.setRequestName( + new QName( + Names.NAMESPACE_URI, + "voidWithoutArgumentsRequest", + Names.PREFIX)); + handler.setRequestParameterNames(new QName[]{}); + handler.setResponseName( + new QName( + Names.NAMESPACE_URI, + "voidWithoutArgumentsResponse", + Names.PREFIX)); + handler.setReturnType(Result.class); + + ProxyHandler exceptionHandler = new ReflectionProxyHandler(); + exceptionHandler.setAction(Names.NAMESPACE_URI+"/"+"throwsException"); + exceptionHandler.setRequestName( + new QName( + Names.NAMESPACE_URI, + "throwsExceptionRequest", + Names.PREFIX)); + + exceptionHandler.setRequestParameterNames(new QName[]{}); + exceptionHandler.setResponseName( + new QName( + Names.NAMESPACE_URI, + "throwsExceptionResponse", + Names.PREFIX)); + + exceptionHandler.setReturnType(Result.class); + + ProxyHandler echoWithWrapperTypesHandler = new ReflectionProxyHandler(); + echoWithWrapperTypesHandler.setAction(Names.NAMESPACE_URI+"/"+"echoWithSimpleTypes"); + echoWithWrapperTypesHandler.setRequestName( + new QName( + Names.NAMESPACE_URI, + "echoWithSimpleTypesRequest", + Names.PREFIX)); + + echoWithWrapperTypesHandler.setRequestParameterNames(new QName[]{ + new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p2",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p3",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p4",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p5",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p6",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p7",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p8",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p9",Names.PREFIX), + }); + + echoWithWrapperTypesHandler.setResponseName( + new QName( + Names.NAMESPACE_URI, + "echoWithSimpleTypesResponse", + Names.PREFIX)); + + echoWithWrapperTypesHandler.setReturnType(Result.class); + + ProxyHandler echoWithArrayOfWrapperTypes = new ReflectionProxyHandler(); + echoWithArrayOfWrapperTypes.setAction(Names.NAMESPACE_URI+"/"+"echoWithArrays"); + echoWithArrayOfWrapperTypes.setRequestName( + new QName( + Names.NAMESPACE_URI, + "echoWithArraysRequest", + Names.PREFIX)); + + echoWithArrayOfWrapperTypes.setRequestParameterNames(new QName[]{ + new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p2",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p3",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p4",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p5",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p6",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p7",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p8",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p9",Names.PREFIX), + }); + + echoWithArrayOfWrapperTypes.setResponseName( + new QName( + Names.NAMESPACE_URI, + "echoWithArraysResponse", + Names.PREFIX)); + + echoWithArrayOfWrapperTypes.setReturnType(Result.class); + + ProxyHandler echoWithArrayOfPrimitiveTypes = new ReflectionProxyHandler(); + echoWithArrayOfPrimitiveTypes.setAction(Names.NAMESPACE_URI+"/"+"echoWithSimpleTypeArrays"); + echoWithArrayOfPrimitiveTypes.setRequestName( + new QName( + Names.NAMESPACE_URI, + "echoWithSimpleTypeArraysRequest", + Names.PREFIX)); + + echoWithArrayOfPrimitiveTypes.setRequestParameterNames(new QName[]{ + new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p2",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p3",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p4",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p5",Names.PREFIX), + new QName(Names.NAMESPACE_URI,"p6",Names.PREFIX)}); + + echoWithArrayOfPrimitiveTypes.setResponseName( + new QName( + Names.NAMESPACE_URI, + "echoWithSimpleTypeArraysResponse", + Names.PREFIX)); + + echoWithArrayOfPrimitiveTypes.setReturnType(Result.class); + + ProxyHandler echoWithByteArray = new EnhancedReflectionProxyHandler(); + echoWithByteArray.setAction(Names.NAMESPACE_URI+"/"+"echoWithByteArray"); + echoWithByteArray.setRequestName( + new QName( + Names.NAMESPACE_URI, + "echoWithByteArrayRequest", + Names.PREFIX)); + + echoWithByteArray.setRequestParameterNames( + new QName[]{ + new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX)}); + + echoWithByteArray.setResponseName( + new QName( + Names.NAMESPACE_URI, + "echoWithByteArrayResponse", + Names.PREFIX)); + + echoWithByteArray.setReturnType(Result.class); + + ProxyHandler echoWithUUID = new EnhancedReflectionProxyHandler(); + echoWithUUID.setAction(Names.NAMESPACE_URI+"/"+"echoWithUUID"); + echoWithUUID.setRequestName( + new QName( + Names.NAMESPACE_URI, + "echoWithUUIDRequest", + Names.PREFIX)); + + echoWithUUID.setRequestParameterNames( + new QName[]{ + new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX)}); + + echoWithUUID.setResponseName( + new QName( + Names.NAMESPACE_URI, + "echoWithUUIDResponse", + Names.PREFIX)); + + echoWithUUID.setReturnType(Result.class); + + ProxyHandler echoWithMap = new EnhancedReflectionProxyHandler(); + echoWithMap.setAction(Names.NAMESPACE_URI+"/"+"echoWithMap"); + echoWithMap.setRequestName( + new QName( + Names.NAMESPACE_URI, + "echoWithMapRequest", + Names.PREFIX)); + + echoWithMap.setRequestParameterNames( + new QName[]{ + new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX)}); + + echoWithMap.setResponseName( + new QName( + Names.NAMESPACE_URI, + "echoWithMapResponse", + Names.PREFIX)); + + echoWithMap.setReturnType(Result.class); + + handlers.put("voidWithoutArguments",handler); + handlers.put("echoWithSimpleTypes",echoWithWrapperTypesHandler); + handlers.put("echoWithArrays",echoWithArrayOfWrapperTypes); + handlers.put("echoWithSimpleTypeArrays", echoWithArrayOfPrimitiveTypes); + handlers.put("echoWithByteArray", echoWithByteArray); + handlers.put("echoWithUUID", echoWithUUID); + handlers.put("echoWithMap", echoWithMap); + handlers.put("throwsException",exceptionHandler); + return handlers; + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/SetResourcePropertiesTestCase.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/SetResourcePropertiesTestCase.java new file mode 100644 index 0000000000..87f8905e01 --- /dev/null +++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/SetResourcePropertiesTestCase.java @@ -0,0 +1,219 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.wsdm; + +import java.lang.reflect.Array; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.management.MBeanAttributeInfo; +import javax.xml.namespace.QName; + +import org.apache.muse.ws.addressing.soap.SoapFault; +import org.apache.muse.ws.resource.WsrfConstants; +import org.apache.qpid.management.Names; + +/** + * Test case for Set Resource Properties interfaces. + * + * @author Andrea Gazzarini + */ +public class SetResourcePropertiesTestCase extends BaseWsDmAdapterTestCase +{ + /** + * Test the WS-RP SetResourceProperty interface of the WS-DM adapter. + * + *
    precondition : a WS-Resource exists and is registered. + *
    postcondition : property values are correctly updated on the target WS-Resource.. + */ + public void testSetResourcePropertiesOK() throws Exception + { + Map sampleMap = new HashMap(); + sampleMap.put("Key1", "BLABALABLABALBAL"); + sampleMap.put("Key2", 182838484l); + sampleMap.put("Key3", -928376362); + sampleMap.put("Key4", 23762736276.33D); + sampleMap.put("Key4", 2327363.2F); + + Map sampleValues = new HashMap(); + sampleValues.put(String.class.getName(),"SAMPLE_STRING"); + sampleValues.put(UUID.class.getName(),UUID.randomUUID()); + sampleValues.put(Boolean.class.getName(),Boolean.FALSE); + sampleValues.put(Map.class.getName(),sampleMap); + sampleValues.put(Long.class.getName(),283781273L); + sampleValues.put(Integer.class.getName(),12727); + sampleValues.put(Short.class.getName(),new Short((short)22)); + sampleValues.put(Date.class.getName(),new Date()); + + MBeanAttributeInfo [] attributesMetadata = _mbeanInfo.getAttributes(); + boolean atLeastThereIsOneWritableProperty = false; + + for (MBeanAttributeInfo attributeMetadata : attributesMetadata) + { + String name = attributeMetadata.getName(); + + if (attributeMetadata.isWritable()) + { + atLeastThereIsOneWritableProperty = true; + Object sampleValue = sampleValues.get(attributeMetadata.getType()); + Object []values = new Object[]{sampleValue}; + + Object result = _managementServer.getAttribute(_resourceObjectName, name); + if (result == null) + { + _resourceClient.insertResourceProperty( + new QName( + Names.NAMESPACE_URI, + name, + Names.PREFIX), + values); + } else + { + _resourceClient.updateResourceProperty( + new QName( + Names.NAMESPACE_URI, + name, + Names.PREFIX), + values); + } + + Object propertyValues = _resourceClient.getPropertyAsObject( + new QName( + Names.NAMESPACE_URI, + name, + Names.PREFIX), + Class.forName(attributeMetadata.getType())); + int length = Array.getLength(propertyValues); + if (length != 0) + { + Object propertyValue = Array.get(propertyValues, 0); + + assertEquals( + "Comparison failed for property "+name, + sampleValue, + propertyValue); + } else { + assertNull( + String.format( + "\"%s\" property value shouldn't be null. Its value is %s", + name, + _managementServer.getAttribute(_resourceObjectName,name)), + sampleValue); + } + } + } + assertTrue( + "It's not possibile to run successfully this test case if " + + "the target WS-Resource has no at least one writable property", + atLeastThereIsOneWritableProperty); + } + + /** + * Test the WS-RP SetResourceProperty interface of the WS-DM adapter when the + * target property is null. + * According to WS-RP specs this operation is not allowed because in this case a SetResourceProperty with an "Insert" + * message should be sent in order to initialize the property. + * + *
    precondition : a ws resource exists and is registered. The value of the target property is null. + *
    postcondition : a Soap fault is received indicating the failuire. + */ + public void testSetResourcePropertiesKO() throws Exception + { + Object typePropertyValue = _managementServer.getAttribute(_resourceObjectName, "Type"); + assertNull(typePropertyValue); + + try + { + _resourceClient.updateResourceProperty( + new QName( + Names.NAMESPACE_URI, + "Type", + Names.PREFIX), + new Object[]{"sampleValue"}); + fail( + "If the property is null on the target ws resource, according " + + "to WS-RP specs, an update of its value is not possible."); + } catch(SoapFault expected) + { + + } + } + + /** + * Tests the SetResourceProperties (update) interface when the request contains + * an unknwon target resource. + * + *
    precondition : the SetResourceProperties contains an unknwon resource. + *
    postcondition : a SoapFault is thrown and the corresponding detail contains an + * UnknownResourceFault element. + */ + public void testUpdateResourcePropertiesKO_WithUnknownResourceFault() throws Exception + { + try + { + _resourceClient.getEndpointReference().removeParameter(Names.RESOURCE_ID_QNAME); + _resourceClient.getEndpointReference().addParameter(Names.RESOURCE_ID_QNAME,"lablabalbal"); + + _resourceClient.updateResourceProperty( + new QName( + Names.NAMESPACE_URI, + "Type", + Names.PREFIX), + new Object[]{"sampleValue"}); + } catch(SoapFault expected) + { + assertEquals( + WsrfConstants.RESOURCE_UNKNOWN_QNAME.getLocalPart(), + expected.getDetail().getLocalName()); + } + } + + /** + * Tests the SetResourceProperties (insert) interface when the request contains + * an unknwon target resource. + * + *
    precondition : the SetResourceProperties contains an unknwon resource. + *
    postcondition : a SoapFault is thrown and the corresponding detail contains an + * UnknownResourceFault element. + */ + public void testInsertResourcePropertiesKO_WithUnknownResourceFault() throws Exception + { + try + { + _resourceClient.getEndpointReference().removeParameter(Names.RESOURCE_ID_QNAME); + _resourceClient.getEndpointReference().addParameter(Names.RESOURCE_ID_QNAME,"lablabalbal"); + + _resourceClient.insertResourceProperty( + new QName( + Names.NAMESPACE_URI, + "Type", + Names.PREFIX), + new Object[]{"sampleValue"}); + } catch(SoapFault expected) + { + assertEquals( + WsrfConstants.RESOURCE_UNKNOWN_QNAME.getLocalPart(), + expected.getDetail().getLocalName()); + } + } +} diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java index 6644b5ae25..07395b3be9 100644 --- a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java +++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java @@ -21,36 +21,13 @@ package org.apache.qpid.management.wsdm; import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.lang.reflect.Array; -import java.lang.reflect.Method; import java.net.ServerSocket; -import java.net.URI; -import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import javax.management.MBeanAttributeInfo; -import javax.management.MBeanInfo; -import javax.management.MBeanServer; -import javax.management.ObjectName; -import javax.xml.namespace.QName; - -import junit.extensions.TestSetup; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.apache.muse.core.proxy.ProxyHandler; -import org.apache.muse.core.proxy.ReflectionProxyHandler; import org.apache.muse.core.serializer.SerializerRegistry; -import org.apache.muse.util.xml.XmlUtils; -import org.apache.muse.ws.addressing.EndpointReference; -import org.apache.muse.ws.addressing.soap.SoapFault; -import org.apache.muse.ws.resource.remote.WsResourceClient; -import org.apache.muse.ws.resource.sg.remote.ServiceGroupClient; import org.apache.qpid.management.Names; import org.apache.qpid.management.Protocol; import org.apache.qpid.management.wsdm.capabilities.Result; @@ -61,26 +38,14 @@ import org.apache.qpid.management.wsdm.muse.serializer.ObjectSerializer; import org.apache.qpid.management.wsdm.muse.serializer.UUIDSerializer; import org.mortbay.component.LifeCycle; import org.mortbay.component.LifeCycle.Listener; -import org.w3c.dom.Element; -/** - * Test case for WS-Resource lifecycle management. - * - * @author Andrea Gazzarini - */ -public class WsDmAdapterTest extends TestCase { - - private MBeanServer _managementServer; - private ObjectName _resourceObjectName; - - private WsResourceClient _resourceClient; - private MBeanInfo _mbeanInfo; - - private Map _invocationHandlers = createInvocationHandlers(); - final Long retCodeOk = new Long(0); +import junit.extensions.TestSetup; +import junit.framework.Test; +import junit.framework.TestSuite; + +public class WsDmAdapterTest +{ - private static ServerThread _server; - /** * Test case wide set up. * Provides Server startup & shutdown global procedure. @@ -102,6 +67,7 @@ public class WsDmAdapterTest extends TestCase { } }; + private ServerThread _server; /** * Builds a new test setup with for the given test. @@ -153,927 +119,30 @@ public class WsDmAdapterTest extends TestCase { }; /** - * Set up fixture for this test case. - * - * @throws Exception when the test case intialization fails. - */ - protected void setUp() throws Exception - { - _managementServer = ManagementFactory.getPlatformMBeanServer(); - - ServiceGroupClient serviceGroup = getServiceGroupClient(); - WsResourceClient [] members = serviceGroup.getMembers(); - - assertEquals( - "No resource has been yet created so how is " + - "it possible that service group children list is not empty?", - 0, - members.length); - - _managementServer.invoke( - Names.QPID_EMULATOR_OBJECT_NAME, - "createQueue", new Object[]{_resourceObjectName = createResourceName()}, - new String[]{ObjectName.class.getName()}); - - members = serviceGroup.getMembers(); - assertEquals( - "One resource has just been created so " + - "I expect to find it on service group children list...", - 1, - members.length); - - _resourceClient = members[0]; - _mbeanInfo = _managementServer.getMBeanInfo(_resourceObjectName); - } - - /** - * Shutdown procedure for this test case. - * - * @throws Exception when either the server or some resource fails to shutdown. - */ - @Override - protected void tearDown() throws Exception - { - ServiceGroupClient serviceGroup = getServiceGroupClient(); - WsResourceClient [] members = serviceGroup.getMembers(); - - _managementServer.invoke( - Names.QPID_EMULATOR_OBJECT_NAME, - "unregister", - new Object[]{_resourceObjectName}, - new String[]{ObjectName.class.getName()}); - - members = serviceGroup.getMembers(); - - assertEquals( - "No resource has been yet created so how is it possible that service group children list is not empty?", - 0, - members.length); - } - - /** - * Test the WS-RP GetResourceProperty interface of the WS-DM adapter. - * - *
    precondition : a ws resource exists and is registered. - *
    postcondition : property values coming from WS-DM resource are the same of the JMX interface. - */ - public void testGetResourcePropertiesOK() throws Exception - { - MBeanAttributeInfo [] attributesMetadata = _mbeanInfo.getAttributes(); - for (MBeanAttributeInfo attributeMetadata : attributesMetadata) - { - String name = attributeMetadata.getName(); - Object propertyValues = _resourceClient.getPropertyAsObject( - new QName( - Names.NAMESPACE_URI, - name, - Names.PREFIX), - Class.forName(attributeMetadata.getType())); - - int length = Array.getLength(propertyValues); - if (length != 0) - { - Object propertyValue = Array.get(propertyValues, 0); - - assertEquals( - "Comparison failed for property "+name, - _managementServer.getAttribute(_resourceObjectName,name), - propertyValue); - } else { - assertNull( - String.format( - "\"%s\" property value shouldn't be null. Its value is %s", - name, - _managementServer.getAttribute(_resourceObjectName,name)), - _managementServer.getAttribute(_resourceObjectName,name)); - } - } - } - - /** - * Test the WS-RP SetResourceProperty interface of the WS-DM adapter. + * Gets the test suite composition. * - *
    precondition : a WS-Resource exists and is registered. - *
    postcondition : property values are correctly updated on the target WS-Resource.. + * @return the test suite composition. */ - public void testSetResourcePropertiesOK() throws Exception + public static Test suite() { - Map sampleMap = new HashMap(); - sampleMap.put("Key1", "BLABALABLABALBAL"); - sampleMap.put("Key2", 182838484l); - sampleMap.put("Key3", -928376362); - sampleMap.put("Key4", 23762736276.33D); - sampleMap.put("Key4", 2327363.2F); - - Map sampleValues = new HashMap(); - sampleValues.put(String.class.getName(),"SAMPLE_STRING"); - sampleValues.put(UUID.class.getName(),UUID.randomUUID()); - sampleValues.put(Boolean.class.getName(),Boolean.FALSE); - sampleValues.put(Map.class.getName(),sampleMap); - sampleValues.put(Long.class.getName(),283781273L); - sampleValues.put(Integer.class.getName(),12727); - sampleValues.put(Short.class.getName(),new Short((short)22)); - sampleValues.put(Date.class.getName(),new Date()); - - MBeanAttributeInfo [] attributesMetadata = _mbeanInfo.getAttributes(); - boolean atLeastThereIsOneWritableProperty = false; - - for (MBeanAttributeInfo attributeMetadata : attributesMetadata) - { - String name = attributeMetadata.getName(); - - if (attributeMetadata.isWritable()) - { - atLeastThereIsOneWritableProperty = true; - Object sampleValue = sampleValues.get(attributeMetadata.getType()); - Object []values = new Object[]{sampleValue}; - - Object result = _managementServer.getAttribute(_resourceObjectName, name); - if (result == null) - { - _resourceClient.insertResourceProperty( - new QName( - Names.NAMESPACE_URI, - name, - Names.PREFIX), - values); - } else - { - _resourceClient.updateResourceProperty( - new QName( - Names.NAMESPACE_URI, - name, - Names.PREFIX), - values); - } - - Object propertyValues = _resourceClient.getPropertyAsObject( - new QName( - Names.NAMESPACE_URI, - name, - Names.PREFIX), - Class.forName(attributeMetadata.getType())); - int length = Array.getLength(propertyValues); - if (length != 0) - { - Object propertyValue = Array.get(propertyValues, 0); - - assertEquals( - "Comparison failed for property "+name, - sampleValue, - propertyValue); - } else { - assertNull( - String.format( - "\"%s\" property value shouldn't be null. Its value is %s", - name, - _managementServer.getAttribute(_resourceObjectName,name)), - sampleValue); - } - } - } - assertTrue( - "It's not possibile to run successfully this test case if " + - "the target WS-Resource has no at least one writable property", - atLeastThereIsOneWritableProperty); - } - - /** - * Test the WS-RP SetResourceProperty interface of the WS-DM adapter when the - * target property is null. - * According to WS-RP specs this operation is not allowed because in this case a SetResourceProperty with an "Insert" - * message should be sent in order to initialize the property. - * - *
    precondition : a ws resource exists and is registered. The value of the target property is null. - *
    postcondition : a Soap fault is received indicating the failuire. - */ - public void testSetResourcePropertiesKO() throws Exception - { - Object typePropertyValue = _managementServer.getAttribute(_resourceObjectName, "Type"); - assertNull(typePropertyValue); - - try - { - _resourceClient.updateResourceProperty( - new QName( - Names.NAMESPACE_URI, - "Type", - Names.PREFIX), - new Object[]{"sampleValue"}); - fail( - "If the property is null on the target ws resource, according " + - "to WS-RP specs, an update of its value is not possible."); - } catch(SoapFault expected) - { - - } - } - - /** - * Tests the WS-RP PutResourcePropertyDocument interface of the WS-DM adapter. - * - *
    precondition : a ws resource exists and is registered. - *
    postcondition : A read / write property is correctly set according to WSRP interface. - */ - public void testGetAndPutResourcePropertyDocumentOK() throws Exception - { - String expectedMgmtPubIntervalValue = "4321"; - String propertyName = "MgmtPubInterval"; - - Element propertiesDocument = _resourceClient.getResourcePropertyDocument(); - Element [] properties = XmlUtils.getAllElements(propertiesDocument); - - for (Element element : properties) - { - if (propertyName.equals(element.getLocalName())) { - element.setTextContent(expectedMgmtPubIntervalValue); - } else { - propertiesDocument.removeChild(element); - } - } - - _resourceClient.putResourcePropertyDocument(propertiesDocument); - - Element newProperties = _resourceClient.getResourcePropertyDocument(); - - Element mgmtPubInterval = XmlUtils.getElement( - newProperties, new QName( - Names.NAMESPACE_URI, - propertyName, - Names.PREFIX)); - - assertEquals(expectedMgmtPubIntervalValue,mgmtPubInterval.getTextContent()); - } - - /** - * Tests the WS-RP PutResourcePropertyDocument interface of the WS-DM adapter. - * Specifically it tries to update the value of a read-only property. - * - *
    precondition : a ws resource exists, it is registered and has at least one read-only property. - *
    postcondition : An exception is thrown indicating the failure. - */ - public void testGetAndPutResourcePropertyDocumentKO_WithReadOnlyProperty() throws Exception - { - String propertyName = "Name"; - - Element propertiesDocument = _resourceClient.getResourcePropertyDocument(); - Element [] properties = XmlUtils.getAllElements(propertiesDocument); - - for (Element element : properties) - { - if (propertyName.equals(element.getLocalName())) { - element.setTextContent("ThisIsTheNewValueOfNameProperty"); - } else { - propertiesDocument.removeChild(element); - } - } - - try - { - _resourceClient.putResourcePropertyDocument(propertiesDocument); - fail("It's not possible to update the value of a read-only property."); - } catch (SoapFault expected) - { - - } - } - - /** - * Test the WS-RP GetResourceProperties interface of the WS-DM adapter. - * - *
    precondition : a ws resource exists and is registered. - *
    postcondition : Properties are correctly returned according to WSRP interface and they (their value) - * are matching with corresponding MBean properties. - */ - public void testGetMultipleResourcePropertiesOK() throws Exception - { - MBeanAttributeInfo [] attributesMetadata = _mbeanInfo.getAttributes(); - QName[] names = new QName[attributesMetadata.length]; - - int index = 0; - for (MBeanAttributeInfo attributeMetadata : _mbeanInfo.getAttributes()) - { - QName qname = new QName(Names.NAMESPACE_URI,attributeMetadata.getName(),Names.PREFIX); - names[index++] = qname; - } - - Element[] properties =_resourceClient.getMultipleResourceProperties(names); - for (Element element : properties) - { - String name = element.getLocalName(); - Object value = _managementServer.getAttribute(_resourceObjectName, name); - if ("Name".equals(name)) - { - assertEquals( - value, - element.getTextContent()); - } else if ("Durable".equals(name)) - { - assertEquals( - value, - Boolean.valueOf(element.getTextContent())); - } else if ("ExpireTime".equals(name)) - { - assertEquals( - value, - new Date(Long.valueOf(element.getTextContent()))); - } else if ("MsgTotalEnqueues".equals(name)) - { - assertEquals( - value, - Long.valueOf(element.getTextContent())); - } else if ("ConsumerCount".equals(name)) - { - assertEquals( - value, - Integer.valueOf(element.getTextContent())); - }else if ("VhostRef".equals(name)) - { - assertEquals( - value, - UUID.fromString(element.getTextContent())); - } - } - } - - /** - * Test operation invocation on WS-Resource. - * This method tests the exchange of simple types between requestor and service provider. - * With simple types we mean : - * - *
      - *
    • java.lang.Long / long (xsd:long) - *
    • java.lang.Integer / int (xsd:int / xsd:integer) - *
    • java.lang.Double/ double (xsd:double) - *
    • java.lang.Float / float (xsd:float) - *
    • java.lang.Short / short (xsd:short) - *
    • java.lang.Boolean / boolean (xsd:boolean) - *
    • java.lang.String (xsd:string) - *
    • java.net.URI (xsd:anyURI) - *
    • java.util.Date(xsd:dateTime) - *
    - * - *
    precondition : a ws resource exists and is registered and the requested operation is available on that. - *
    postcondition : invocations are executed successfully, no exception is thrown and parameters are correctly returned. - */ - @SuppressWarnings("unchecked") - public void testOperationInvocationOK_withSimpleTypes() throws Exception - { - Long expectedLongResult = new Long(1373); - Boolean expectedBooleanResult = Boolean.TRUE; - Double expectedDoubleResult = new Double(12763.44); - Float expectedFloatResult = new Float(2727.233f); - Integer expectedIntegerResult = new Integer(28292); - Short expectedShortResult = new Short((short)227); - String expectedStringResult = "expectedStringResult"; - URI expectedUriResult = URI.create("http://qpid.apache.org/"); - Date expectedDateResult = new Date(); - - Object result = _resourceClient.invoke( - _invocationHandlers.get("echoWithSimpleTypes"), - new Object[]{ - expectedLongResult, - expectedBooleanResult, - expectedDoubleResult, - expectedFloatResult, - expectedIntegerResult, - expectedShortResult, - expectedStringResult, - expectedUriResult, - expectedDateResult}); - - Method getStatusCode = result.getClass().getMethod("getStatusCode"); - Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); - assertEquals(retCodeOk,getStatusCode.invoke(result)); - Map out = (Map) getOutputParameters.invoke(result); - - assertEquals("Output parameters must be 9.",9,out.size()); - assertTrue("Long output parameter not found on result object.",out.containsValue(expectedLongResult)); - assertTrue("Boolean output parameter not found on result object.",out.containsValue(expectedBooleanResult)); - assertTrue("Double output parameter not found on result object.",out.containsValue(expectedDoubleResult)); - assertTrue("Float output parameter not found on result object.",out.containsValue(expectedFloatResult)); - assertTrue("Integer output parameter not found on result object.",out.containsValue(expectedIntegerResult)); - assertTrue("Short output parameter not found on result object.",out.containsValue(expectedShortResult)); - assertTrue("String output parameter not found on result object.",out.containsValue(expectedStringResult)); - assertTrue("URI output parameter not found on result object.",out.containsValue(expectedUriResult)); - assertTrue("Date output parameter not found on result object.",out.containsValue(expectedDateResult)); - } - - /** - * Test operation invocation on WS-Resource. - * This method tests the exchange of arrays between requestor and service provider. - * For this test exchanged arrays contain : - * - *
      - *
    • java.lang.Long (xsd:long) - *
    • java.lang.Integer (xsd:int / xsd:integer) - *
    • java.lang.Double (xsd:double) - *
    • java.lang.Float (xsd:float) - *
    • java.lang.Short (xsd:short) - *
    • java.lang.Boolean (xsd:boolean) - *
    • java.lang.String (xsd:string) - *
    • java.net.URI (xsd:anyURI) - *
    • java.util.Date(xsd:dateTime) - *
    - * - *
    precondition : a ws resource exists and is registered and the requested operation is available on that. - *
    postcondition : invocations are executed successfully, no exception is thrown and parameters are correctly returned. - */ - @SuppressWarnings("unchecked") - public void testOperationInvocationOK_withWrapperArrays() throws Exception - { - Long [] expectedLongResult = {new Long(2),new Long(1),new Long(3),new Long(4)}; - Boolean [] expectedBooleanResult = { Boolean.TRUE,Boolean.FALSE,Boolean.FALSE}; - Double [] expectedDoubleResult = {12763.44d,2832.33d,2292.33d,22293.22d}; - Float [] expectedFloatResult = {2727.233f,1f,2f,4f,5.4f,33.2f}; - Integer [] expectedIntegerResult = {1,2,3,4,55,66,77,88,99}; - Short [] expectedShortResult = {(short)227,(short)23,(short)9}; - String [] expectedStringResult = {"s1","s2","s333","s4"}; - URI [] expectedUriResult = { - URI.create("http://qpid.apache.org/"), - URI.create("http://www.apache.org"), - URI.create("http://projects.apache.org")}; - - Date [] expectedDateResult = { - new Date(), - new Date(38211897), - new Date(903820382)}; - - Object result = _resourceClient.invoke( - _invocationHandlers.get("echoWithArrays"), - new Object[]{ - expectedLongResult, - expectedBooleanResult, - expectedDoubleResult, - expectedFloatResult, - expectedIntegerResult, - expectedShortResult, - expectedStringResult, - expectedUriResult, - expectedDateResult}); - - Method getStatusCode = result.getClass().getMethod("getStatusCode"); - Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); - assertEquals(retCodeOk,getStatusCode.invoke(result)); - Map out = (Map) getOutputParameters.invoke(result); - - assertEquals("Output parameters must be 9.",9,out.size()); - assertTrue("Long array doesn't match.",Arrays.equals(expectedLongResult, (Long[])out.get(Long.class.getName()))); - assertTrue("Boolean array doesn't match.",Arrays.equals(expectedBooleanResult, (Boolean[])out.get(Boolean.class.getName()))); - assertTrue("Double array doesn't match.",Arrays.equals(expectedDoubleResult, (Double[])out.get(Double.class.getName()))); - assertTrue("Float array doesn't match.",Arrays.equals(expectedFloatResult, (Float[])out.get(Float.class.getName()))); - assertTrue("Integer array doesn't match.", Arrays.equals(expectedIntegerResult, (Integer[])out.get(Integer.class.getName()))); - assertTrue("Short array doesn't match.",Arrays.equals(expectedShortResult, (Short[])out.get(Short.class.getName()))); - assertTrue("String array doesn't match.",Arrays.equals(expectedStringResult, (String[])out.get(String.class.getName()))); - assertTrue("URI array doesn't match.",Arrays.equals(expectedUriResult, (URI[])out.get(URI.class.getName()))); - assertTrue("Date array doesn't match.",Arrays.equals(expectedDateResult, (Date[])out.get(Date.class.getName()))); - } - - /** - * Test operation invocation on WS-Resource. - * This method tests the exchange of primitive type arrays between requestor and service provider. - * NOte that even the sent array contain primtiive type QMan deals only with objects so in the result - * object you will find the corresponding wrapper types. - * - * For this test exchanged arrays contain : - * - *
      - *
    • java.lang.Long / long (xsd:long) - *
    • java.lang.Integer / int (xsd:int / xsd:integer) - *
    • java.lang.Double/ double (xsd:double) - *
    • java.lang.Float / float (xsd:float) - *
    • java.lang.Short / short (xsd:short) - *
    • java.lang.Boolean / boolean (xsd:boolean) - *
    - * - *
    precondition : a ws resource exists and is registered and the requested operation is available on that. - *
    postcondition : invocations are executed successfully, no exception is thrown and parameters are correctly returned. - */ - @SuppressWarnings("unchecked") - public void testOperationInvocationOK_withPrimitiveArrays() throws Exception - { - long [] expectedLongResult = {1L,2L,3L,4L}; - boolean [] expectedBooleanResult = { true,false,false}; - double [] expectedDoubleResult = {12763.44d,2832.33d,2292.33d,22293.22d}; - float [] expectedFloatResult = {2727.233f,1f,2f,4f,5.4f,33.2f}; - int [] expectedIntegerResult = {1,2,3,4,55,66,77,88,99}; - short [] expectedShortResult = {(short)227,(short)23,(short)9}; - - Object result = _resourceClient.invoke( - _invocationHandlers.get("echoWithSimpleTypeArrays"), - new Object[]{ - expectedLongResult, - expectedBooleanResult, - expectedDoubleResult, - expectedFloatResult, - expectedIntegerResult, - expectedShortResult}); - - Method getStatusCode = result.getClass().getMethod("getStatusCode"); - Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); - assertEquals(retCodeOk,getStatusCode.invoke(result)); - Map out = (Map) getOutputParameters.invoke(result); - - assertEquals("Output parameters must be 6.",6,out.size()); - assertArrayEquals(expectedLongResult, out.get(long.class.getName())); - assertArrayEquals(expectedBooleanResult, out.get(boolean.class.getName())); - assertArrayEquals(expectedDoubleResult, out.get(double.class.getName())); - assertArrayEquals(expectedFloatResult, out.get(float.class.getName())); - assertArrayEquals(expectedIntegerResult, out.get(int.class.getName())); - assertArrayEquals(expectedShortResult, out.get(short.class.getName())); - } - - /** - * Test operation invocation on WS-Resource. - * This method tests the exchange of a byte type array between requestor and service provider. - * - *
    precondition : a WS-Resource exists and is registered and the requested operation is available on that. - *
    postcondition : invocations are executed successfully, no exception is thrown and byte array are correctly returned. - */ - @SuppressWarnings("unchecked") - public void testOperationInvocationOK_withByteArray() throws Exception - { - byte [] expectedByteResult = {1,3,4,2,2,44,22,3,3,55,66}; - - Object result = _resourceClient.invoke( - _invocationHandlers.get("echoWithByteArray"), - new Object[]{expectedByteResult}); - - Method getStatusCode = result.getClass().getMethod("getStatusCode"); - Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); - - assertEquals(retCodeOk,getStatusCode.invoke(result)); - Map out = (Map) getOutputParameters.invoke(result); - - assertEquals("Output parameters must be 1.",1,out.size()); - assertArrayEquals(expectedByteResult, out.get(byte[].class.getName())); - } - - /** - * Test a simple operation invocation on a WS-Resource. - * This method tests a simple operation without any input and output parameters. - * - *
    precondition : a ws resource exists and is registered and the requested operation is available on that. - *
    postcondition : invocations are executed successfully an no exception is thrown. - */ - @SuppressWarnings("unchecked") - public void testSimpleOperationInvocationOK() throws Exception - { - Object result = _resourceClient.invoke( - _invocationHandlers.get("voidWithoutArguments"), - null); - - Method getStatusCode = result.getClass().getMethod("getStatusCode"); - assertEquals( - "Something was wrong...expected return code is "+retCodeOk, - retCodeOk, - getStatusCode.invoke(result)); - } - - /** - * Test a the invocation on a WS-Resource with a method that throws an exception.. - * - *
    precondition : a ws resource exists and is registered and the requested operation is available on that. - *
    postcondition : an exception is thrown by the requested method. - */ - @SuppressWarnings("unchecked") - public void testInvocationException_OK() throws Exception - { - try - { - _resourceClient.invoke( - _invocationHandlers.get("throwsException"), - null); - fail("The requested operation has thrown an exception so a Soap Fault is expected..."); - } catch(SoapFault expected) - { - } - } - - /** - * Test operation invocation on WS-Resource. - * This method tests the exchange of UUID type between requestor and service provider. - * - *
    precondition : a WS-Resource exists and is registered and the requested operation is available on that. - *
    postcondition : invocations are executed successfully, no exception is thrown and parameters are correctly returned. - */ - @SuppressWarnings("unchecked") - public void testOperationInvocationOK_withUUID() throws Exception - { - UUID expectedUuid = UUID.randomUUID(); - - Object result = _resourceClient.invoke( - _invocationHandlers.get("echoWithUUID"), - new Object[]{expectedUuid}); - - Method getStatusCode = result.getClass().getMethod("getStatusCode"); - Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); - - assertEquals(retCodeOk,getStatusCode.invoke(result)); - Map out = (Map) getOutputParameters.invoke(result); - - assertEquals("Output parameters must be 1.",1,out.size()); - assertEquals(expectedUuid, out.get("uuid")); - } - - /** - * Test operation invocation on WS-Resource. - * This method tests the exchange of Map type between requestor and service provider. - * For this test exchanged arrays contain : - * - *
    precondition : a ws resource exists and is registered and the requested operation is available on that. - *
    postcondition : invocations are executed successfully, no exception is thrown and parameters are correctly returned. - */ - @SuppressWarnings("unchecked") - public void testOperationInvocationOK_withMap() throws Exception - { - Map expectedMap = new HashMap(); - expectedMap.put("p1", new Long(1)); - expectedMap.put("p2", Boolean.TRUE); - expectedMap.put("p3", 1234d); - expectedMap.put("p4", 11.2f); - expectedMap.put("p5", 1272); - expectedMap.put("p6", (short)12); - expectedMap.put("p7", "aString"); - expectedMap.put("p8", "http://qpid.apache.org"); - expectedMap.put("p9", new Date(12383137128L)); - expectedMap.put("p10", new byte[]{1,2,2,3,3,4}); - - Object result = _resourceClient.invoke( - _invocationHandlers.get("echoWithMap"), - new Object[]{expectedMap}); - - Method getStatusCode = result.getClass().getMethod("getStatusCode"); - Method getOutputParameters = result.getClass().getMethod("getOutputParameters"); - - assertEquals(retCodeOk,getStatusCode.invoke(result)); - Map out = (Map) ((Map) getOutputParameters.invoke(result)).get("map"); - - assertEquals("Output parameters must be 10.",10,out.size()); - assertEquals(expectedMap.get("p1"),out.get("p1")); - assertEquals(expectedMap.get("p2"),out.get("p2")); - assertEquals(expectedMap.get("p3"),out.get("p3")); - assertEquals(expectedMap.get("p4"),out.get("p4")); - assertEquals(expectedMap.get("p5"),out.get("p5")); - assertEquals(expectedMap.get("p6"),out.get("p6")); - assertEquals(expectedMap.get("p7"),out.get("p7")); - assertEquals(expectedMap.get("p8"),out.get("p8")); - assertEquals(expectedMap.get("p9"),out.get("p9")); - assertTrue( Arrays.equals((byte[])expectedMap.get("p10"),(byte[])out.get("p10"))); - } - - /** - * Main entry point for running this test case. - * - * @return the decorated test case. - */ - public static Test suite() { - TestSuite suite = new TestSuite("Test Suite for WS-DM Adapter"); - suite.addTestSuite(WsDmAdapterTest.class); + TestSuite suite = new TestSuite("Test suite for QMan WS-DM."); + suite.addTestSuite(MetadataExchangeInterfaceTestCase.class); + suite.addTestSuite(OperationInvocationInterfaceTestCase.class); + suite.addTestSuite(GetResourcePropertyDocumentTestCase.class); + suite.addTestSuite(SetResourcePropertiesTestCase.class); + suite.addTestSuite(GetMultipleResourcePropertiesTestCase.class); + suite.addTestSuite(GetResourcePropertiesTestCase.class); return new WsDmAdapterTestSetup(suite); } /** - * Creates a service group client reference. - * - * @return a service group client reference. - */ - private ServiceGroupClient getServiceGroupClient() - { - URI address = URI.create( - Protocol.DEFAULT_ENDPOINT_URI.replaceFirst("8080",System.getProperty(Names.ADAPTER_PORT_PROPERTY_NAME))); - return new ServiceGroupClient(new EndpointReference(address)); - } - - /** - * In order to test the behaviour of the WS-DM adapter, at - * least one resource must be created. This is the method that - * returns the name (ObjectName on JMX side, Resource-ID on WSDM side) - * of that resource - * - * @return the name of the MBean instance that will be created. - * @throws Exception when the name if malformed. Practically never. - */ - private ObjectName createResourceName() throws Exception - { - return new ObjectName( - "Q-MAN:objectId="+UUID.randomUUID()+ - ", brokerID="+UUID.randomUUID()+ - ",class=queue"+ - ",package=org.apache.qpid"+ - ",name="+System.currentTimeMillis()); - } - - private Map createInvocationHandlers() - { - Map handlers = new HashMap(); - - ProxyHandler handler = new ReflectionProxyHandler(); - handler.setAction(Names.NAMESPACE_URI+"/"+"voidWithoutArguments"); - handler.setRequestName( - new QName( - Names.NAMESPACE_URI, - "voidWithoutArgumentsRequest", - Names.PREFIX)); - handler.setRequestParameterNames(new QName[]{}); - handler.setResponseName( - new QName( - Names.NAMESPACE_URI, - "voidWithoutArgumentsResponse", - Names.PREFIX)); - handler.setReturnType(Result.class); - - ProxyHandler exceptionHandler = new ReflectionProxyHandler(); - exceptionHandler.setAction(Names.NAMESPACE_URI+"/"+"throwsException"); - exceptionHandler.setRequestName( - new QName( - Names.NAMESPACE_URI, - "throwsExceptionRequest", - Names.PREFIX)); - - exceptionHandler.setRequestParameterNames(new QName[]{}); - exceptionHandler.setResponseName( - new QName( - Names.NAMESPACE_URI, - "throwsExceptionResponse", - Names.PREFIX)); - - exceptionHandler.setReturnType(Result.class); - - ProxyHandler echoWithWrapperTypesHandler = new ReflectionProxyHandler(); - echoWithWrapperTypesHandler.setAction(Names.NAMESPACE_URI+"/"+"echoWithSimpleTypes"); - echoWithWrapperTypesHandler.setRequestName( - new QName( - Names.NAMESPACE_URI, - "echoWithSimpleTypesRequest", - Names.PREFIX)); - - echoWithWrapperTypesHandler.setRequestParameterNames(new QName[]{ - new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p2",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p3",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p4",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p5",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p6",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p7",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p8",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p9",Names.PREFIX), - }); - - echoWithWrapperTypesHandler.setResponseName( - new QName( - Names.NAMESPACE_URI, - "echoWithSimpleTypesResponse", - Names.PREFIX)); - - echoWithWrapperTypesHandler.setReturnType(Result.class); - - ProxyHandler echoWithArrayOfWrapperTypes = new ReflectionProxyHandler(); - echoWithArrayOfWrapperTypes.setAction(Names.NAMESPACE_URI+"/"+"echoWithArrays"); - echoWithArrayOfWrapperTypes.setRequestName( - new QName( - Names.NAMESPACE_URI, - "echoWithArraysRequest", - Names.PREFIX)); - - echoWithArrayOfWrapperTypes.setRequestParameterNames(new QName[]{ - new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p2",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p3",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p4",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p5",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p6",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p7",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p8",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p9",Names.PREFIX), - }); - - echoWithArrayOfWrapperTypes.setResponseName( - new QName( - Names.NAMESPACE_URI, - "echoWithArraysResponse", - Names.PREFIX)); - - echoWithArrayOfWrapperTypes.setReturnType(Result.class); - - ProxyHandler echoWithArrayOfPrimitiveTypes = new ReflectionProxyHandler(); - echoWithArrayOfPrimitiveTypes.setAction(Names.NAMESPACE_URI+"/"+"echoWithSimpleTypeArrays"); - echoWithArrayOfPrimitiveTypes.setRequestName( - new QName( - Names.NAMESPACE_URI, - "echoWithSimpleTypeArraysRequest", - Names.PREFIX)); - - echoWithArrayOfPrimitiveTypes.setRequestParameterNames(new QName[]{ - new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p2",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p3",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p4",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p5",Names.PREFIX), - new QName(Names.NAMESPACE_URI,"p6",Names.PREFIX)}); - - echoWithArrayOfPrimitiveTypes.setResponseName( - new QName( - Names.NAMESPACE_URI, - "echoWithSimpleTypeArraysResponse", - Names.PREFIX)); - - echoWithArrayOfPrimitiveTypes.setReturnType(Result.class); - - ProxyHandler echoWithByteArray = new EnhancedReflectionProxyHandler(); - echoWithByteArray.setAction(Names.NAMESPACE_URI+"/"+"echoWithByteArray"); - echoWithByteArray.setRequestName( - new QName( - Names.NAMESPACE_URI, - "echoWithByteArrayRequest", - Names.PREFIX)); - - echoWithByteArray.setRequestParameterNames( - new QName[]{ - new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX)}); - - echoWithByteArray.setResponseName( - new QName( - Names.NAMESPACE_URI, - "echoWithByteArrayResponse", - Names.PREFIX)); - - echoWithByteArray.setReturnType(Result.class); - - ProxyHandler echoWithUUID = new EnhancedReflectionProxyHandler(); - echoWithUUID.setAction(Names.NAMESPACE_URI+"/"+"echoWithUUID"); - echoWithUUID.setRequestName( - new QName( - Names.NAMESPACE_URI, - "echoWithUUIDRequest", - Names.PREFIX)); - - echoWithUUID.setRequestParameterNames( - new QName[]{ - new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX)}); - - echoWithUUID.setResponseName( - new QName( - Names.NAMESPACE_URI, - "echoWithUUIDResponse", - Names.PREFIX)); - - echoWithUUID.setReturnType(Result.class); - - ProxyHandler echoWithMap = new EnhancedReflectionProxyHandler(); - echoWithMap.setAction(Names.NAMESPACE_URI+"/"+"echoWithMap"); - echoWithMap.setRequestName( - new QName( - Names.NAMESPACE_URI, - "echoWithMapRequest", - Names.PREFIX)); - - echoWithMap.setRequestParameterNames( - new QName[]{ - new QName(Names.NAMESPACE_URI,"p1",Names.PREFIX)}); - - echoWithMap.setResponseName( - new QName( - Names.NAMESPACE_URI, - "echoWithMapResponse", - Names.PREFIX)); - - echoWithMap.setReturnType(Result.class); - - handlers.put("voidWithoutArguments",handler); - handlers.put("echoWithSimpleTypes",echoWithWrapperTypesHandler); - handlers.put("echoWithArrays",echoWithArrayOfWrapperTypes); - handlers.put("echoWithSimpleTypeArrays", echoWithArrayOfPrimitiveTypes); - handlers.put("echoWithByteArray", echoWithByteArray); - handlers.put("echoWithUUID", echoWithUUID); - handlers.put("echoWithMap", echoWithMap); - handlers.put("throwsException",exceptionHandler); - return handlers; - } - - /** - * Internal method used for array comparison using reflection. + * Finds a free port that will be used to run the embedded + * web server. * - * @param expectedArray the expected array. - * @param resultArray the array that must match the expected one. + * @return a free port that will be used to run the + * embedded web server. */ - private void assertArrayEquals(Object expectedArray, Object resultArray) - { - int expectedArrayLength = Array.getLength(expectedArray); - int resultArrayLength = Array.getLength(resultArray); - - assertEquals(expectedArrayLength,resultArrayLength); - - for (int index = 0; index < expectedArrayLength; index++) - { - Object expected = Array.get(expectedArray, index); - Object result = Array.get(resultArray, index); - - assertEquals(expected,result); - } - } - - public static int getFreePort() throws IOException { + private static int getFreePort() throws IOException { ServerSocket server = null; try { diff --git a/qpid/java/management/eclipse-plugin/META-INF/MANIFEST.MF b/qpid/java/management/eclipse-plugin/META-INF/MANIFEST.MF index 32d1b7a1b2..9b5a240bb6 100644 --- a/qpid/java/management/eclipse-plugin/META-INF/MANIFEST.MF +++ b/qpid/java/management/eclipse-plugin/META-INF/MANIFEST.MF @@ -10,8 +10,8 @@ Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.ui.forms, - jmxremote.sasl;resolution:=optional, - qpid-management-common + qpid-management-common, + org.apache.commons.codec;bundle-version="1.3.0" Eclipse-LazyStart: true Export-Package: org.apache.qpid.management.ui, org.apache.qpid.management.ui.actions, diff --git a/qpid/java/management/eclipse-plugin/build-release-linux-gtk-x86_64.properties b/qpid/java/management/eclipse-plugin/build-release-linux-gtk-x86_64.properties new file mode 100644 index 0000000000..f1c35c82e8 --- /dev/null +++ b/qpid/java/management/eclipse-plugin/build-release-linux-gtk-x86_64.properties @@ -0,0 +1,36 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# + +release.name=${module.namever}-linux-gtk-x86_64 + +release.subdir=${module.release.base}/${release.name} + +release.tar.gz=${module.release.base}/${release.name}.tar.gz + +qpidmc.ini=src/main/resources/linux-gtk-x86_64/qpidmc.ini + +qpidmc.executable=src/main/resources/linux-gtk-x86_64/qpidmc + +qpidmc.companion.library=src/main/resources/linux-gtk-x86_64/libcairo-swt.so + +rcp.libs=${management-eclipse-plugin-linux-gtk-x86_64.libs} + +rcp.configuration.dir=src/main/resources/linux-gtk-x86_64/Configuration diff --git a/qpid/java/management/eclipse-plugin/build-release-solaris-gtk-sparc.properties b/qpid/java/management/eclipse-plugin/build-release-solaris-gtk-sparc.properties new file mode 100644 index 0000000000..7d5b613e06 --- /dev/null +++ b/qpid/java/management/eclipse-plugin/build-release-solaris-gtk-sparc.properties @@ -0,0 +1,39 @@ +# +# +# 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. +# +# + +release.name=${module.namever}-solaris-gtk-sparc + +release.subdir=${module.release.base}/${release.name} + +release.tar.gz=${module.release.base}/${release.name}.tar.gz + +qpidmc.ini=src/main/resources/solaris-gtk-sparc/qpidmc.ini + +qpidmc.solaris.xpm.files=src/main/resources/solaris-gtk-sparc/Qpidmc.l.pm \ + src/main/resources/solaris-gtk-sparc/Qpidmc.m.pm \ + src/main/resources/solaris-gtk-sparc/Qpidmc.s.pm \ + src/main/resources/solaris-gtk-sparc/Qpidmc.t.pm + +qpidmc.executable=src/main/resources/solaris-gtk-sparc/qpidmc + +rcp.libs=${management-eclipse-plugin-solaris-gtk-sparc.libs} + +rcp.configuration.dir=src/main/resources/solaris-gtk-sparc/Configuration diff --git a/qpid/java/management/eclipse-plugin/build-release.xml b/qpid/java/management/eclipse-plugin/build-release.xml index b396974c9a..3cb1af194f 100644 --- a/qpid/java/management/eclipse-plugin/build-release.xml +++ b/qpid/java/management/eclipse-plugin/build-release.xml @@ -44,6 +44,9 @@ For linux libcairo-swt.so file: qpidmc.companion.library + + For solaris .xpm files: + qpidmc.solaris.xpm.files --> @@ -86,15 +89,22 @@ + + + + + + + + depends="release-bin-executable-companion-library, release-bin-executable-solaris-xpm-files"> - + diff --git a/qpid/java/management/eclipse-plugin/build.xml b/qpid/java/management/eclipse-plugin/build.xml index 4dd279f721..8513c6487d 100644 --- a/qpid/java/management/eclipse-plugin/build.xml +++ b/qpid/java/management/eclipse-plugin/build.xml @@ -70,6 +70,19 @@ + + + + + + + + + + + + + diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java index 5e05375e28..5a6b3f8856 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java @@ -28,12 +28,13 @@ package org.apache.qpid.management.ui; public class Constants { public final static String APPLICATION_NAME = "Qpid Management Console"; + public static final String DEFAULT_DOMAIN = "org.apache.qpid"; public final static String ACTION_REMOVE_MBEANNODE = "Remove from list"; public final static String VALUE = "value"; public final static String TYPE = "type"; + public final static String VERSION = "version"; public final static String NODE_TYPE_SERVER = "server"; - public final static String NODE_TYPE_DOMAIN = "domain"; public final static String NODE_TYPE_MBEANTYPE = "mbeantype"; // currently used only for virtual host instances, but will work as general also public final static String NODE_TYPE_TYPEINSTANCE = "mbeantype_instance"; @@ -80,8 +81,6 @@ public class Constants public final static String[] EXCHANGE_TYPE_VALUES = {"direct", "fanout", "headers", "topic"}; public final static String[] BOOLEAN_TYPE_VALUES = {"false", "true"}; public final static String[] ATTRIBUTE_TABLE_TITLES = {"Attribute Name", "Value"}; - public static final String[] CONNECTION_PROTOCOLS ={"RMI"}; - public static final String DEFAULT_PROTOCOL = CONNECTION_PROTOCOLS[0]; public final static String ACTION_ADDSERVER = "New Connection"; public final static String ACTION_RECONNECT = "Reconnect"; diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedBean.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedBean.java index 31825e925d..ae01f30f32 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedBean.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedBean.java @@ -20,13 +20,17 @@ */ package org.apache.qpid.management.ui; -import static org.apache.qpid.management.ui.Constants.*; +import static org.apache.qpid.management.ui.Constants.ADMIN_MBEAN_TYPE; +import static org.apache.qpid.management.ui.Constants.CONNECTION; +import static org.apache.qpid.management.ui.Constants.DEFAULT_VH; +import static org.apache.qpid.management.ui.Constants.EXCHANGE; +import static org.apache.qpid.management.ui.Constants.QUEUE; +import static org.apache.qpid.management.ui.Constants.VIRTUAL_HOST; + import java.util.HashMap; /** * Class representing a managed bean on the managed server - * @author Bhupendra Bhardwaj - * */ public abstract class ManagedBean extends ManagedObject { @@ -36,27 +40,50 @@ public abstract class ManagedBean extends ManagedObject private String _virtualHostName = null; private ManagedServer _server = null; private HashMap _properties = null; - + private int _version; + public String getProperty(String key) { - return (String)_properties.get(key); + return (String) _properties.get(key); } - + public HashMap getProperties() { return _properties; } + public void setProperties(HashMap properties) { this._properties = properties; setName(getProperty("name")); setType(getProperty("type")); + setVersion(getProperty("version")); _virtualHostName = getProperty(VIRTUAL_HOST); } + + public void setVersion(String version) + { + try + { + _version = Integer.parseInt(version); + } + catch (NumberFormatException nfe) + { + _version = 1; + } + + } + + public int getVersion() + { + return _version; + } + public String getDomain() { return _domain; } + public void setDomain(String domain) { this._domain = domain; @@ -66,65 +93,75 @@ public abstract class ManagedBean extends ManagedObject { return _server; } + public void setServer(ManagedServer server) { this._server = server; } + public String getType() { return _type; } + public void setType(String type) { this._type = type; } + public String getUniqueName() { return _uniqueName; } + public void setUniqueName(String uniqueName) { this._uniqueName = uniqueName; } - + public String getVirtualHostName() { // To make it work with the broker with no virtual host implementation return _virtualHostName == null ? DEFAULT_VH : _virtualHostName; } - + /** * Returns mbean instance name. MBeans which have only one instance, the type attribute will be returned + * * @return */ public String getInstanceName() { if (getName() != null) + { return getName(); + } else + { return getType(); + } } - + public boolean isQueue() { return _type.endsWith(QUEUE); } - + public boolean isConnection() { return _type.endsWith(CONNECTION); } - + public boolean isExchange() { return _type.endsWith(EXCHANGE); } - + public boolean isTempQueue() { return (isQueue() && getName().startsWith("tmp_")); } - + public boolean isAdmin() { return _type.endsWith(ADMIN_MBEAN_TYPE); diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedServer.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedServer.java index 480fdb429a..9ca8787bb5 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedServer.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedServer.java @@ -20,20 +20,16 @@ */ package org.apache.qpid.management.ui; -import static org.apache.qpid.management.ui.Constants.DEFAULT_PROTOCOL; /** * Class representing a server being managed eg. MBeanServer - * @author Bhupendra Bhardwaj */ public class ManagedServer extends ManagedObject { private String _host; private int _port; - private String _url; private String _domain; private String _user; private String _password; - private String _protocol = DEFAULT_PROTOCOL; public ManagedServer(String host, int port, String domain) { @@ -46,7 +42,6 @@ public class ManagedServer extends ManagedObject _host = host; _port = port; _domain = domain; - _url = getRMIURL(host, port); _user = user; _password = password; } @@ -65,17 +60,7 @@ public class ManagedServer extends ManagedObject { return _port; } - - public String getUrl() - { - return _url; - } - public String getProtocol() - { - return _protocol; - } - public String getPassword() { return _password; @@ -96,8 +81,4 @@ public class ManagedServer extends ManagedObject _user = user; } - private String getRMIURL(String host, int port) - { - return "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"; - } } diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java index ce7d8816ba..e487c02a67 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java @@ -35,7 +35,6 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -46,12 +45,9 @@ import org.eclipse.ui.IWorkbenchWindowActionDelegate; public class AddServer extends AbstractAction implements IWorkbenchWindowActionDelegate { - private static final String[] _domains ={"org.apache.qpid"}; - - private String _transport = DEFAULT_PROTOCOL; private String _host; private String _port; - private String _domain; + private String _domain = DEFAULT_DOMAIN; private String _user; private String _password; @@ -73,7 +69,7 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD { if (_addServer) { - getNavigationView().addNewServer(_transport, _host, Integer.parseInt(_port), _domain, _user, _password); + getNavigationView().addNewServer(_host, Integer.parseInt(_port), _domain, _user, _password); } } catch(InfoRequiredException ex) @@ -91,7 +87,6 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD _addServer = false; _host = null; _port = null; - _domain = null; _user = null; _password = null; } @@ -103,6 +98,8 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD */ private void createAddServerPopup() { + final Shell appShell = _window.getShell(); + Display display = Display.getCurrent(); final Shell shell = new Shell(display, SWT.BORDER | SWT.CLOSE); shell.setText(ACTION_ADDSERVER); @@ -112,21 +109,23 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD createWidgets(shell); shell.pack(); - //get current size dialog, and screen size - int displayWidth = display.getBounds().width; - int displayHeight = display.getBounds().height; + //get current size dialog, and application window size and location + int appWidth = appShell.getBounds().width; + int appHeight = appShell.getBounds().height; + int appLocX = appShell.getBounds().x; + int appLocY = appShell.getBounds().y; int currentShellWidth = shell.getSize().x; int currentShellHeight = shell.getSize().y; //default sizes for the dialog int minShellWidth = 425; - int minShellHeight= 290; + int minShellHeight= 265; //ensure this is large enough, increase it if its not int newShellWidth = currentShellWidth > minShellWidth ? currentShellWidth : minShellWidth; int newShellHeight = currentShellHeight > minShellHeight ? currentShellHeight : minShellHeight; - //set the final size and centre the dialog - shell.setBounds((displayWidth - newShellWidth)/2 , (displayHeight - newShellHeight)/2, newShellWidth, newShellHeight); + //set the final size and centre the dialog within the app window + shell.setBounds((appWidth - newShellWidth)/2 + appLocX, (appHeight - newShellHeight)/2 + appLocY, newShellWidth, newShellHeight); shell.open(); _window.getShell().setEnabled(false); @@ -189,17 +188,6 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD // Verify if the value entered is numeric textPort.addVerifyListener(new NumberVerifyListener()); - - Label domain = new Label(composite, SWT.NONE); - domain.setText("Domain"); - domain.setLayoutData(new GridData(SWT.TRAIL, SWT.TOP, false, false)); - - final Combo comboDomain = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); - comboDomain.setItems(_domains); - comboDomain.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); - comboDomain.select(0); - - Label user = new Label(composite, SWT.NONE); user.setText(USERNAME); user.setLayoutData(new GridData(SWT.TRAIL, SWT.TOP, false, false)); @@ -228,7 +216,7 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD if (event.character == SWT.ESC) { //Escape key acts as cancel on all widgets - shell.close(); + shell.dispose(); } } }); @@ -283,7 +271,6 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD return; } - _domain = comboDomain.getText(); _addServer = true; shell.dispose(); } @@ -314,7 +301,7 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD if (event.character == SWT.ESC) { //Escape key acts as cancel on all widgets - shell.close(); + shell.dispose(); } } }); diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java index ce9d80d49b..5eb9d9a168 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java @@ -99,6 +99,8 @@ public class ReconnectServer extends AbstractAction implements IWorkbenchWindowA // Create the login popup fot th user to enter usernaem and password private void createLoginPopup() { + final Shell appShell = _window.getShell(); + Display display = Display.getCurrent(); final Shell shell = new Shell(display, SWT.BORDER | SWT.CLOSE); shell.setText(_title); @@ -108,9 +110,11 @@ public class ReconnectServer extends AbstractAction implements IWorkbenchWindowA createWidgets(shell); shell.pack(); - //get current size dialog, and screen size - int displayWidth = display.getBounds().width; - int displayHeight = display.getBounds().height; + //get current size dialog, and application window size and location + int appWidth = appShell.getBounds().width; + int appHeight = appShell.getBounds().height; + int appLocX = appShell.getBounds().x; + int appLocY = appShell.getBounds().y; int currentShellWidth = shell.getSize().x; int currentShellHeight = shell.getSize().y; @@ -121,8 +125,8 @@ public class ReconnectServer extends AbstractAction implements IWorkbenchWindowA int newShellWidth = currentShellWidth > minShellWidth ? currentShellWidth : minShellWidth; int newShellHeight = currentShellHeight > minShellHeight ? currentShellHeight : minShellHeight; - //set the final size and centre the dialog - shell.setBounds((displayWidth - newShellWidth)/2 , (displayHeight - newShellHeight)/2, newShellWidth, newShellHeight); + //set the final size and centre the dialog within the app window + shell.setBounds((appWidth - newShellWidth)/2 + appLocX, (appHeight - newShellHeight)/2 + appLocY, newShellWidth, newShellHeight); shell.open(); _window.getShell().setEnabled(false); @@ -182,7 +186,7 @@ public class ReconnectServer extends AbstractAction implements IWorkbenchWindowA if (event.character == SWT.ESC) { //Escape key acts as cancel on all widgets - shell.close(); + shell.dispose(); } } }); @@ -248,7 +252,7 @@ public class ReconnectServer extends AbstractAction implements IWorkbenchWindowA if (event.character == SWT.ESC) { //Escape key acts as cancel on all widgets - shell.close(); + shell.dispose(); } } }); diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/ClientListener.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/ClientListener.java index 2be0ddbebf..c3348b32f0 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/ClientListener.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/ClientListener.java @@ -45,7 +45,6 @@ public class ClientListener implements NotificationListener { ObjectName objName = null; String type = notification.getType(); - MBeanUtility.printOutput(type + ":" + objName); if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(type)) { @@ -60,6 +59,7 @@ public class ClientListener implements NotificationListener else if (JMXConnectionNotification.FAILED.equals(type)) { ApplicationRegistry.serverConnectionClosed(server); + MBeanUtility.printOutput("Recieved notification from " + server.getName() + ": " + type ); } } diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/ClientNotificationListener.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/ClientNotificationListener.java index c6ecda4b4c..2af8e681ae 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/ClientNotificationListener.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/ClientNotificationListener.java @@ -35,7 +35,6 @@ public class ClientNotificationListener extends ClientListener public void handleNotification(Notification notification, Object handback) { ObjectName objName = (ObjectName)notification.getSource(); - //String type = notification.getType(); getServerRegistry().addNotification(objName, notification); } } diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java index 945c63f19a..cf3db26f4b 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java @@ -164,7 +164,6 @@ public class JMXServerRegistry extends ServerRegistry public void removeManagedObject(ManagedBean mbean) { - MBeanUtility.printOutput("Removing MBean:" + mbean.getUniqueName()); if (mbean.isQueue()) { diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java index 29d7b9c557..479f68de03 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java @@ -440,18 +440,6 @@ public class MBeanUtility return mbeans; } - /** - * Returns all the domains for the given server. This method can be removed as now this RCP is specific to - * Qpid and domain is also fixed - */ - public static List getAllDomains(ManagedServer server) throws Exception - { - JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(server); - MBeanServerConnection mbsc = serverRegistry.getServerConnection(); - String[] domains = mbsc.getDomains(); - return Arrays.asList(domains); - } - public static void printOutput(String statement) { if (ApplicationRegistry.debug) diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java index 5476c27871..3c8e52f1d2 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java @@ -30,6 +30,7 @@ import org.apache.qpid.management.ui.ServerRegistry; import org.apache.qpid.management.ui.exceptions.InfoRequiredException; import org.apache.qpid.management.ui.jmx.MBeanUtility; import org.apache.qpid.management.ui.model.AttributeData; +import org.apache.qpid.management.ui.model.NotificationInfoModel; import org.apache.qpid.management.ui.model.OperationData; import org.apache.qpid.management.ui.model.OperationDataModel; import org.eclipse.jface.viewers.ISelection; @@ -135,8 +136,7 @@ public class MBeanView extends ViewPart { try { - if (_selectedNode == null || NODE_TYPE_SERVER.equals(_selectedNode.getType()) || - NODE_TYPE_DOMAIN.equals(_selectedNode.getType()) ) + if (_selectedNode == null || NODE_TYPE_SERVER.equals(_selectedNode.getType())) { return; } @@ -176,8 +176,7 @@ public class MBeanView extends ViewPart */ private void setServer() { - if (NODE_TYPE_SERVER.equals(_selectedNode.getType()) || - NODE_TYPE_DOMAIN.equals(_selectedNode.getType()) ) + if (NODE_TYPE_SERVER.equals(_selectedNode.getType())) { _server = (ManagedServer)_selectedNode.getManagedObject(); _virtualHostName = null; @@ -359,6 +358,13 @@ public class MBeanView extends ViewPart private void createNotificationsTab(TabFolder tabFolder) { + NotificationInfoModel[] items = MBeanUtility.getNotificationInfo(_mbean); + if (items == null || items.length == 0) + { + //the mbean has no notifications to subscribe for, do not create the tab. + return; + } + NotificationsTabControl controller = new NotificationsTabControl(tabFolder); TabItem tab = new TabItem(tabFolder, SWT.NONE); diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java index ec8a612d41..fedb1c4bd0 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java @@ -130,16 +130,26 @@ public class NavigationView extends ViewPart { public void treeExpanded(TreeExpansionEvent event) { - _treeViewer.setExpandedState(event.getElement(), true); - // Following will cause the selection event to be sent, so commented - // _treeViewer.setSelection(new StructuredSelection(event.getElement())); - _treeViewer.refresh(); + getSite().getShell().getDisplay().asyncExec( + new Runnable() + { + public void run() + { + _treeViewer.refresh(); + } + }); } public void treeCollapsed(TreeExpansionEvent event) { - _treeViewer.setExpandedState(event.getElement(), false); - _treeViewer.refresh(); + getSite().getShell().getDisplay().asyncExec( + new Runnable() + { + public void run() + { + _treeViewer.refresh(); + } + }); } }); @@ -201,11 +211,11 @@ public class NavigationView extends ViewPart } /** - * Creates Qpid Server connection using JMX RMI protocol + * Creates Qpid Server connection * @param server * @throws Exception */ - private void createRMIServerConnection(ManagedServer server) throws Exception + private void createJMXServerConnection(ManagedServer server) throws Exception { // Currently Qpid Management Console only supports JMX MBeanServer ServerRegistry serverRegistry = new JMXServerRegistry(server); @@ -220,42 +230,32 @@ public class NavigationView extends ViewPart * @param domain * @throws Exception */ - public void addNewServer(String transportProtocol, String host, int port, String domain, String user, String pwd) + public void addNewServer(String host, int port, String domain, String user, String pwd) throws Exception { - String serverAddress = host + ":" + port; - String url = null; ManagedServer managedServer = new ManagedServer(host, port, domain, user, pwd); - if ("RMI".equals(transportProtocol)) + String server = managedServer.getName(); + List list = _serversRootNode.getChildren(); + for (TreeObject node : list) { - url = managedServer.getUrl(); - List list = _serversRootNode.getChildren(); - for (TreeObject node : list) + ManagedServer nodeServer = (ManagedServer)node.getManagedObject(); + if (server.equals(nodeServer.getName())) { - ManagedServer nodeServer = (ManagedServer)node.getManagedObject(); - if (url.equals(nodeServer.getUrl())) - { - // Server is already in the list of added servers, so now connect it. - // Set the server node as selected and then connect it. - _treeViewer.setSelection(new StructuredSelection(node)); - reconnect(user, pwd); + // Server is already in the list of added servers, so now connect it. + // Set the server node as selected and then connect it. + _treeViewer.setSelection(new StructuredSelection(node)); + reconnect(user, pwd); - return; - } + return; } - - // The server is not in the list of already added servers, so now connect and add it. - managedServer.setName(serverAddress); - createRMIServerConnection(managedServer); - } - else - { - throw new InfoRequiredException(transportProtocol + " transport is not supported"); } + // The server is not in the list of already added servers, so now connect and add it. + createJMXServerConnection(managedServer); + // Server connection is successful. Now add the server in the tree - TreeObject serverNode = new TreeObject(serverAddress, NODE_TYPE_SERVER); + TreeObject serverNode = new TreeObject(server, NODE_TYPE_SERVER); serverNode.setManagedObject(managedServer); _serversRootNode.addChild(serverNode); @@ -276,10 +276,12 @@ public class NavigationView extends ViewPart // Add the Queue/Exchanges/Connections from config file into the navigation tree addConfiguredItems(managedServer); + expandInitialMBeanView(serverNode); + _treeViewer.refresh(); // save server address in file - addServerInConfigFile(serverAddress); + addServerInConfigFile(server); } /** @@ -405,50 +407,33 @@ public class NavigationView extends ViewPart } } - /** - * Queries the qpid server for MBeans and populates the navigation view with all MBeans for - * the given server node. - * @param serverNode - */ - private void populateServer(TreeObject serverNode) throws Exception + //check if the MBeanInfo can be retrieved. + private boolean haveAccessPermission(ManagedBean mbean) { - ManagedServer server = (ManagedServer) serverNode.getManagedObject(); - String domain = server.getDomain(); - if (!domain.equals(ALL)) - { - TreeObject domainNode = new TreeObject(domain, NODE_TYPE_DOMAIN); - domainNode.setParent(serverNode); - - populateDomain(domainNode); + try + { + MBeanUtility.getMBeanInfo(mbean); } - else + catch(Exception ex) { - List domainList = new ArrayList(); - List domains = MBeanUtility.getAllDomains(server); - - for (String domainName : domains) - { - TreeObject domainNode = new TreeObject(domainName, NODE_TYPE_DOMAIN); - domainNode.setParent(serverNode); - - domainList.add(domainNode); - populateDomain(domainNode); - } + return false; } + + return true; } - + /** - * Queries the Qpid Server and populates the given domain node with all MBeans undser that domain. - * @param domain - * @throws IOException + * Queries the qpid server for MBeans and populates the navigation view with all MBeans for + * the given server node. + * @param serverNode * @throws Exception */ - private void populateDomain(TreeObject domain) throws IOException, Exception + private void populateServer(TreeObject serverNode) throws Exception { - ManagedServer server = (ManagedServer) domain.getParent().getManagedObject(); + ManagedServer server = (ManagedServer) serverNode.getManagedObject(); + String domain = server.getDomain(); - // Now populate the mbenas under those types - List mbeans = MBeanUtility.getManagedObjectsForDomain(server, domain.getName()); + List mbeans = MBeanUtility.getManagedObjectsForDomain(server, domain); for (ManagedBean mbean : mbeans) { mbean.setServer(server); @@ -459,13 +444,17 @@ public class NavigationView extends ViewPart // manually by selecting from MBeanView if (!(mbean.isConnection() || mbean.isExchange() || mbean.isQueue())) { - addManagedBean(domain, mbean); + //if we cant get the MBeanInfo then we cant display the mbean, so dont add it to the tree + if (haveAccessPermission(mbean)) + { + addManagedBean(serverNode, mbean); + } } } // To make it work with the broker without virtual host implementation. // This will add the default nodes to the domain node boolean hasVirtualHost = false; - for (TreeObject child : domain.getChildren()) + for (TreeObject child : serverNode.getChildren()) { if (child.getName().startsWith(VIRTUAL_HOST)) { @@ -475,7 +464,7 @@ public class NavigationView extends ViewPart } if (!hasVirtualHost){ - addDefaultNodes(domain); + addDefaultNodes(serverNode); } } @@ -540,15 +529,14 @@ public class NavigationView extends ViewPart } /** - * Adds the given MBean to the given domain node. Creates Notification node for the MBean. + * Adds the given MBean to the given domain node. * sample ObjectNames - * org.apache.qpid:type=VirtualHost.VirtualHostManager,VirtualHost=localhost * org.apache.qpid:type=VirtualHost.Queue,VirtualHost=test,name=ping_1 - * @param domain - * @param mbean - * @throws Exception + * @param parent parent tree node to add the mbean to + * @param mbean mbean to add */ - private void addManagedBean(TreeObject domain, ManagedBean mbean) // throws Exception + private void addManagedBean(TreeObject parent, ManagedBean mbean) { String name = mbean.getName(); // Split the mbean type into array of Strings, to create hierarchy @@ -558,7 +546,7 @@ public class NavigationView extends ViewPart // test->Queue->ping String[] types = mbean.getType().split("\\."); TreeObject typeNode = null; - TreeObject parentNode = domain; + TreeObject parentNode = parent; // Run this loop till all nodes(hierarchy) for this mbean are created. This loop only creates // all the required parent nodes for the mbean @@ -638,11 +626,6 @@ public class NavigationView extends ViewPart { addItemInConfigFile(mbeanNode); } - - // Add notification node - // TODO: show this only if the mbean sends any notification - //TreeObject notificationNode = new TreeObject(NOTIFICATION, NOTIFICATION); - //notificationNode.setParent(mbeanNode); } private TreeObject createTypeNode(TreeObject parent, String name) @@ -755,7 +738,7 @@ public class NavigationView extends ViewPart managedServer.setUser(user); managedServer.setPassword(password); - createRMIServerConnection(managedServer); + createJMXServerConnection(managedServer); // put the server in the managed server map _managedServerMap.put(managedServer, selectedNode); @@ -775,8 +758,31 @@ public class NavigationView extends ViewPart // Add the Queue/Exchanges/Connections from config file into the navigation tree addConfiguredItems(managedServer); + expandInitialMBeanView(selectedNode); + _treeViewer.refresh(); } + + private void expandInitialMBeanView(TreeObject serverNode) + { + if (serverNode.getChildren().size() == 0 ) + { + return; + } + else + { + _treeViewer.setExpandedState(serverNode , true); + } + + List children = serverNode.getChildren(); + for (TreeObject child : children) + { + if (child.getChildren().size() > 0) + { + _treeViewer.setExpandedState(child, true); + } + } + } /** * Adds the items(queues/exchanges/connectins) from config file to the server tree @@ -1157,25 +1163,12 @@ public class NavigationView extends ViewPart /** * Adds the mbean to the navigation tree - * @param mbean - * @throws Exception + * @param mbean mbean to add to the tree */ - public void addManagedBean(ManagedBean mbean) // throws Exception + public void addManagedBean(ManagedBean mbean) { TreeObject treeServerObject = _managedServerMap.get(mbean.getServer()); - List domains = treeServerObject.getChildren(); - TreeObject domain = null; - for (TreeObject child : domains) - { - if (child.getName().equals(mbean.getDomain())) - { - domain = child; - - break; - } - } - - addManagedBean(domain, mbean); + addManagedBean(treeServerObject, mbean); _treeViewer.refresh(); } @@ -1200,20 +1193,8 @@ public class NavigationView extends ViewPart for (ManagedBean mbean : removalList) { TreeObject treeServerObject = _managedServerMap.get(mbean.getServer()); - List domains = treeServerObject.getChildren(); - TreeObject domain = null; - for (TreeObject child : domains) - { - if (child.getName().equals(mbean.getDomain())) - { - domain = child; - - break; - } - } - removeManagedObject(domain, mbean); - // serverRegistry.removeManagedObject(mbean); + removeManagedObject(treeServerObject, mbean); } _treeViewer.refresh(); diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java index 36ad1b4fdc..11df1b6f00 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java @@ -33,8 +33,6 @@ import static org.apache.qpid.management.ui.Constants.*; import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.ManagedBean; -import org.apache.qpid.management.ui.ServerRegistry; -import org.apache.qpid.management.ui.jmx.JMXServerRegistry; import org.apache.qpid.management.ui.jmx.MBeanUtility; import org.apache.qpid.management.ui.model.OperationData; import org.apache.qpid.management.ui.model.ParameterData; @@ -69,8 +67,6 @@ import org.eclipse.ui.forms.widgets.FormToolkit; /** * Control class for the MBean operations tab. It creates the required widgets * for the selected MBean. - * @author Bhupendra Bhardwaj - * @author Robert Gemmell */ public class OperationTabControl extends TabControl { @@ -521,7 +517,7 @@ public class OperationTabControl extends TabControl private void populateResults(Object result) { Display display = Display.getCurrent(); - int width = 600; + int width = 610; int height = 400; Shell shell = ViewUtility.createPopupShell(RESULT, width, height); shell.setImage(ApplicationRegistry.getImage(CONSOLE_IMAGE)); @@ -605,23 +601,37 @@ public class OperationTabControl extends TabControl return; } - // customized for passwords - if (PASSWORD.equalsIgnoreCase(param.getName())) + //Custom handling for the PASSWORD field + if (param.getName().equalsIgnoreCase(PASSWORD)) { + //Convert the String value to a character array if that is what is required. if (param.getType().equals("[C")) { - try + // Retreive the mBean type and version. + // If we have a version 1 UserManagement class mbean then it expects the password + // to be sent as the hashed version. + if (_mbean.getType().equals("UserManagement") && _mbean.getVersion() == 1) { - param.setValue(ViewUtility.getHash((String)param.getValue())); + try + { + param.setValue(ViewUtility.getHash((String) param.getValue())); + } + catch (Exception hashException) + { + ViewUtility.popupErrorMessage(_form.getText(), + "Unable to calculate hash for Password:" + + hashException.getMessage()); + return; + } } - catch (Exception ex) + else { - MBeanUtility.handleException(_mbean, ex); - return; + param.setValue(((String) param.getValue()).toCharArray()); } } } // end of customization + } } @@ -725,7 +735,14 @@ public class OperationTabControl extends TabControl { boolean success = Boolean.parseBoolean(result.toString()); String message = success ? OPERATION_SUCCESSFUL : OPERATION_UNSUCCESSFUL; - ViewUtility.popupInfoMessage(title, message); + if(success) + { + ViewUtility.popupInfoMessage(title, message); + } + else + { + ViewUtility.popupErrorMessage(title, message); + } } else if (_opData.getParameters() != null && !_opData.getParameters().isEmpty()) { diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/QueueTypeTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/QueueTypeTabControl.java index 9fcf32abdd..6e37e96695 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/QueueTypeTabControl.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/QueueTypeTabControl.java @@ -271,12 +271,50 @@ public class QueueTypeTabControl extends MBeanTypeTabControl for (AttributeData data : list) { ManagedBean mbean = _queueDepthMap.get(data); - String value = data.getValue().toString(); - items[i++] = mbean.getName() + " (" + value + " KB)"; + items[i++] = mbean.getName() + " (" + getQueueDepthString(mbean, data) + ")"; } getListWidget().setItems(items); } + private String getQueueDepthString(ManagedBean mbean, AttributeData data) + { + if (mbean.getVersion() == 1) //mbean returns KB + { + Long value = (Long)data.getValue(); + + Double mb = 1024.0; + + if(value > mb) //MB + { + return String.format("%.3f", (Double)(value / mb)) + " MB"; + } + else //KB + { + return data.getValue().toString() + " KB"; + } + } + else //mbean returns Bytes + { + Long value = (Long)data.getValue(); + + double mb = 1024.0 * 1024.0; + double kb = 1024.0; + + if(value >= mb) //MB + { + return String.format("%.3f", (Double)(value / mb)) + " MB"; + } + else if (value >= kb) //KB + { + return String.format("%.3f", (Double)(value / kb)) + " KB"; + } + else //Bytes + { + return data.getValue().toString() + " Bytes"; + } + } + } + private void sortQueuesByConsumerCount() { java.util.List list = new ArrayList(_queueConsumerCountMap.keySet()); diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java index 5d6a03b238..16bae07e48 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java @@ -39,14 +39,15 @@ import javax.management.openmbean.OpenType; import javax.management.openmbean.TabularDataSupport; import javax.management.openmbean.TabularType; -import org.apache.qpid.management.ui.ApplicationWorkbenchAdvisor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.ErrorDialog; +import org.apache.commons.codec.binary.Hex; + import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -56,12 +57,12 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.widgets.FormToolkit; /** * Utility Class for displaying OpenMbean data types by creating required SWT widgets - * @author Bhupendra Bhardwaj */ public class ViewUtility { @@ -89,6 +90,10 @@ public class ViewUtility SUPPORTED_ARRAY_DATATYPES.add("java.util.Date"); } + private static final int DEFAULT_CONTENT_SIZE = 198; + static Button _firstButton, _nextButton, _previousButton, _lastButton; + static Text _hexNumTextToEnd, _hexNumTextToStart; + /** * Populates the composite with given openmbean data type (TabularType or CompositeType) * @param toolkit @@ -190,15 +195,15 @@ public class ViewUtility layoutData.widthHint = 80; firstRecordButton.setLayoutData(layoutData); - final Button nextRecordButton = toolkit.createButton(dataHolder, NEXT, SWT.PUSH); + final Button previousRecordButton = toolkit.createButton(dataHolder, PREV, SWT.PUSH); layoutData = new GridData (GridData.HORIZONTAL_ALIGN_END); layoutData.widthHint = 80; - nextRecordButton.setLayoutData(layoutData); + previousRecordButton.setLayoutData(layoutData); - final Button previousRecordButton = toolkit.createButton(dataHolder, PREV, SWT.PUSH); + final Button nextRecordButton = toolkit.createButton(dataHolder, NEXT, SWT.PUSH); layoutData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING); layoutData.widthHint = 80; - previousRecordButton.setLayoutData(layoutData); + nextRecordButton.setLayoutData(layoutData); final Button lastRecordButton = toolkit.createButton(dataHolder, LAST, SWT.PUSH); layoutData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING); @@ -352,7 +357,7 @@ public class ViewUtility } else { - setNotSupportedDataType(toolkit, compositeHolder); + handleBinaryMessageContent(toolkit, compositeHolder, data, itemName, encoding); } } // If array of any other supported type, show as a list of String array @@ -436,6 +441,321 @@ public class ViewUtility return messageBox.open(); } + /** + * Creates widgets for object messages and populates the content in hexadecimal format. + * @param toolkit + * @param compositeHolder + * @param data + * @param itemName + * @param encoding + */ + private static void handleBinaryMessageContent(FormToolkit toolkit, Composite compositeHolder, CompositeData data, String itemName, String encoding) + { + final String thisEncoding = encoding; + final Byte[] arrayItems = (Byte[]) data.get(itemName); + final byte[] byteArray = new byte[arrayItems.length]; + + for (int i = 0; i < arrayItems.length; i++) + { + byteArray[i] = arrayItems[i]; + } + + try + { + //create a new composite to contain the widgets required to display object messages. + final Composite localComposite = toolkit.createComposite(compositeHolder, SWT.NONE); + localComposite.setData("currentBytePos", 0); + localComposite.setData("startingBytePos", 0); + GridLayout layout = new GridLayout(2, true); + layout.marginWidth = 0; + layout.marginHeight = 0; + localComposite.setLayout(layout); + localComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + + int startContentSize = DEFAULT_CONTENT_SIZE; + + if (byteArray.length < DEFAULT_CONTENT_SIZE) + { + startContentSize = byteArray.length; + } + + //create a text to display the hexadecimal views of object messages, it takes more space than ascii view as + //a hex uses 2 chars and 1 space, while ascii only uses 1 char and 1 space. + final Text hexText = toolkit.createText(localComposite, + new String(displayByteFormat(localComposite, byteArray, startContentSize * 2, thisEncoding, "<<", true)), + SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + gridData.widthHint = 144; //set to 222 if not using any fonts + gridData.heightHint = 200; + hexText.setLayoutData(gridData); + + final Text asciiText = toolkit.createText(localComposite, + new String(displayByteFormat(localComposite, byteArray, startContentSize * 2, thisEncoding, "<<", false)), + SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER); + + + gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + gridData.widthHint = 52;//set to 98 if not using any fonts + gridData.heightHint = 200; + asciiText.setLayoutData(gridData); + + //use a monospaced font for a better layout + Font font = new Font(compositeHolder.getDisplay(), "Courier", 10, SWT.NORMAL); + hexText.setFont(font); + asciiText.setFont(font); + + final ScrollBar hexScrollBar = hexText.getVerticalBar(); + final ScrollBar asciiScrollBar = asciiText.getVerticalBar(); + + //create a sub composite to contain all the buttons + final Composite buttonComposite = toolkit.createComposite(localComposite, SWT.NONE); + layout = new GridLayout(7, false); + layout.marginWidth = 0; + buttonComposite.setLayout(layout); + buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1)); + + _firstButton = toolkit.createButton(buttonComposite, "<<", SWT.PUSH); + GridData layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _firstButton.setLayoutData(layoutData); + _firstButton.setToolTipText("See the first n bytes"); + + _previousButton = toolkit.createButton(buttonComposite, "<", SWT.PUSH); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _previousButton.setLayoutData(layoutData); + _previousButton.setToolTipText("See the previous n bytes"); + _previousButton.setEnabled(false); + + _hexNumTextToStart = toolkit.createText(buttonComposite, "0"); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _hexNumTextToStart.setLayoutData(layoutData); + _hexNumTextToStart.setEditable(false); + + final Text hexNumText = toolkit.createText(buttonComposite, "" + startContentSize); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + hexNumText.setLayoutData(layoutData); + + _hexNumTextToEnd = toolkit.createText(buttonComposite, "" + (byteArray.length - startContentSize)); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _hexNumTextToEnd.setLayoutData(layoutData); + _hexNumTextToEnd.setEditable(false); + + _nextButton = toolkit.createButton(buttonComposite, ">", SWT.PUSH); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _nextButton.setLayoutData(layoutData); + _nextButton.setToolTipText("See the next n bytes"); + _nextButton.setEnabled(true); + + _lastButton = toolkit.createButton(buttonComposite, ">>", SWT.PUSH); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _lastButton.setToolTipText("See the last n bytes"); + _lastButton.setLayoutData(layoutData); + + SelectionListener listener = new SelectionAdapter() + { + public void widgetSelected(SelectionEvent e) + { + if (e.widget instanceof Button) + { + String numOfBytes = hexNumText.getText(); + try + { + int n = Integer.parseInt(numOfBytes); + + //Reset range display if user requests a large value + if (n > byteArray.length) + { + n = (byteArray.length > DEFAULT_CONTENT_SIZE) ? DEFAULT_CONTENT_SIZE : byteArray.length; + hexNumText.setText("" + n); + } + + //rest if the user requests 0 + if (n < 1) + { + n = DEFAULT_CONTENT_SIZE; + hexNumText.setText("" + n); + } + + Button button = (Button) e.widget; + hexText.setText(displayByteFormat(localComposite, byteArray, n * 2, thisEncoding, + button.getText(), true)); + asciiText.setText(displayByteFormat(localComposite, byteArray, n * 2, thisEncoding, + button.getText(), false)); + } + catch (NumberFormatException exp) + { + popupErrorMessage("Error", "Please input the number of bytes you wish to look at"); + } + } + if (e.widget instanceof ScrollBar) + { + //synchronize the movements of the two scrollbars + ScrollBar sb = (ScrollBar) e.widget; + if (sb.getParent().equals(hexText)) + { + asciiScrollBar.setIncrement(sb.getIncrement()); + asciiScrollBar.setSelection(sb.getSelection()); + } + else if (sb.getParent().equals(asciiText)) + { + hexScrollBar.setSelection(sb.getSelection()); + hexScrollBar.setIncrement(sb.getIncrement()); + } + } + } + }; + localComposite.addControlListener(new ControlAdapter() + { + public void controlResized(ControlEvent e) + { + //if the control is resized, set different parameters to make a single line displays the same contents. + if (((GridLayout) localComposite.getLayout()).makeColumnsEqualWidth) + { + ((GridLayout) localComposite.getLayout()).makeColumnsEqualWidth = false; + ((GridLayout) localComposite.getLayout()).numColumns = 2; + ((GridData) hexText.getLayoutData()).horizontalSpan = 1; + ((GridData) hexText.getLayoutData()).widthHint = 144; + ((GridData) asciiText.getLayoutData()).horizontalSpan = 1; + ((GridData) asciiText.getLayoutData()).widthHint = 52; + ((GridData) buttonComposite.getLayoutData()).horizontalSpan = 2; + } + else + { + ((GridLayout) localComposite.getLayout()).makeColumnsEqualWidth = true; + ((GridLayout) localComposite.getLayout()).numColumns = 42; //set to 47 if not using any fonts + ((GridData) hexText.getLayoutData()).horizontalSpan = 25; // set to 30 if not using any fonts + ((GridData) asciiText.getLayoutData()).horizontalSpan = 17; // set to 17 if not using any fonts + ((GridData) buttonComposite.getLayoutData()).horizontalSpan = 42; + } + } + }); + + _firstButton.addSelectionListener(listener); + _previousButton.addSelectionListener(listener); + _nextButton.addSelectionListener(listener); + _lastButton.addSelectionListener(listener); + hexScrollBar.addSelectionListener(listener); + asciiScrollBar.addSelectionListener(listener); + //f.dispose(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + /** + * Format object messages to have a hexadecimal view and a ascii view. + * @param numOfBytes + * @param encoding + * @return + */ + private static String displayByteFormat(Composite localComposite, byte[] byteArray, int numOfBytes, + String encoding, String direction, boolean isHex) + { + final Hex hexeconder = new Hex(); + final byte[] encoded = hexeconder.encode(byteArray); + + int hexLength = byteArray.length * 2; + StringBuilder sb = new StringBuilder(); + int currentBytePos = (Integer) localComposite.getData("currentBytePos"); + int startingBytePos = (Integer) localComposite.getData("startingBytePos"); + + int strLength = 0; + int offset = 0; + String encStr; + if (isHex) + { + if (direction.equals("<<")) + { + strLength = (numOfBytes > hexLength) ? hexLength : numOfBytes; + offset = 0; + } + else if (direction.equals("<")) + { + strLength = (startingBytePos - numOfBytes < 0) ? startingBytePos : numOfBytes; + offset = (startingBytePos - numOfBytes < 0) ? 0 : startingBytePos - numOfBytes; + } + else if (direction.equals(">")) + { + strLength = (numOfBytes > (hexLength - currentBytePos)) ? hexLength - currentBytePos : numOfBytes; + offset = currentBytePos; + } + else if (direction.equals(">>")) + { + strLength = (numOfBytes > hexLength) ? hexLength : numOfBytes; + offset = (hexLength - numOfBytes > 0) ? hexLength - numOfBytes : 0; + } + else + { + strLength = hexLength; + offset = 0; + } + localComposite.setData("strLength", strLength); + localComposite.setData("currentBytePos", offset + strLength); + localComposite.setData("startingBytePos", offset); + + if (_lastButton != null && !_lastButton.isDisposed()) + { + //Set button state + _previousButton.setEnabled(offset != 0); + _nextButton.setEnabled(offset + strLength != hexLength); + + //set the text fields + _hexNumTextToStart.setText("" + offset / 2); + _hexNumTextToEnd.setText("" + (hexLength - (offset + strLength)) / 2); + } + } + + try + { + if (isHex) + { + encStr = new String(encoded, offset, strLength, encoding); + for (int c = 0; c < strLength; c++) + { + sb.append(encStr.charAt(c)); + if (c % 2 == 1) + { + sb.append(" "); + } + } + return sb.toString().toUpperCase(); + } + else + { + strLength = (Integer) localComposite.getData("strLength"); + sb = new StringBuilder(); + encStr = new String(byteArray, startingBytePos / 2, strLength / 2, encoding); + for (int c = 0; c < encStr.length(); c++) + { + char ch = encStr.charAt(c); + if (ch > 31 && ch < 127) + { + sb.append(ch); + } + else + { + sb.append("?"); + } + + sb.append(" "); + } + } + } + catch (UnsupportedEncodingException e) + { + e.printStackTrace(); + } + return sb.toString(); + } + public static int popupInfoMessage(String title, String message) { return showBox(title, message, SWT.ICON_INFORMATION | SWT.OK); @@ -448,7 +768,7 @@ public class ViewUtility public static int popupConfirmationMessage(String title, String message) { - return showBox(title, message,SWT.ICON_QUESTION | SWT.YES | SWT.NO | SWT.CANCEL); + return showBox(title, message,SWT.ICON_QUESTION | SWT.YES | SWT.NO); } diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86/Configuration/config.ini b/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86/Configuration/config.ini index be058e2ae5..dc15366740 100644 --- a/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86/Configuration/config.ini +++ b/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86/Configuration/config.ini @@ -45,4 +45,5 @@ org.eclipse.ui, \ org.eclipse.ui.forms, \ org.eclipse.ui.workbench, \ org.eclipse.equinox.launcher, \ -org.eclipse.equinox.launcher.gtk.linux.x86 +org.eclipse.equinox.launcher.gtk.linux.x86, \ +org.apache.commons.codec diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/Configuration/config.ini b/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/Configuration/config.ini new file mode 100644 index 0000000000..f437e830b5 --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/Configuration/config.ini @@ -0,0 +1,49 @@ +############################################################################### +# 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. +############################################################################### + +#Product Runtime Configuration File + +osgi.splashPath=platform:/base/plugins/org.apache.qpid.management.ui +eclipse.product=org.apache.qpid.management.ui.product +osgi.bundles.defaultStartLevel=4 +osgi.bundles=jmxremote.sasl, \ +qpid-management-common, \ +org.apache.qpid.management.ui, \ +com.ibm.icu, \ +org.eclipse.core.commands, \ +org.eclipse.core.contenttype, \ +org.eclipse.core.databinding, \ +org.eclipse.core.expressions, \ +org.eclipse.core.jobs, \ +org.eclipse.core.runtime@start, \ +org.eclipse.core.runtime.compatibility.registry, \ +org.eclipse.equinox.app,org.eclipse.equinox.common, \ +org.eclipse.equinox.preferences, \ +org.eclipse.equinox.registry, \ +org.eclipse.help, \ +org.eclipse.jface, \ +org.eclipse.jface.databinding, \ +org.eclipse.swt, \ +org.eclipse.swt.gtk.linux.x86_64, \ +org.eclipse.ui, \ +org.eclipse.ui.forms, \ +org.eclipse.ui.workbench, \ +org.eclipse.equinox.launcher, \ +org.eclipse.equinox.launcher.gtk.linux.x86_64, \ +org.apache.commons.codec diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/libcairo-swt.so b/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/libcairo-swt.so new file mode 100644 index 0000000000..5734427fb8 Binary files /dev/null and b/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/libcairo-swt.so differ diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/qpidmc b/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/qpidmc new file mode 100644 index 0000000000..ff1f3a7507 Binary files /dev/null and b/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/qpidmc differ diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/qpidmc.ini b/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/qpidmc.ini new file mode 100644 index 0000000000..19ceb6f717 --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/main/resources/linux-gtk-x86_64/qpidmc.ini @@ -0,0 +1,37 @@ +############################################################################### +# 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. +############################################################################### + +-vmargs +-Xms40m +-Xmx256m +-XX:MaxPermSize=256m +-Dosgi.requiredJavaVersion=1.5 +-Declipse.consoleLog=true + +#=============================================== +# SSL trust store configuration options. +#=============================================== + +# Uncomment lines below to specify custom truststore for server SSL +# certificate verification, eg when using self-signed server certs. +# +#-Djavax.net.ssl.trustStore= +#-Djavax.net.ssl.trustStorePassword= + + diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/macosx/Configuration/config.ini b/qpid/java/management/eclipse-plugin/src/main/resources/macosx/Configuration/config.ini index a7c671ce2d..3ac3aa20f3 100644 --- a/qpid/java/management/eclipse-plugin/src/main/resources/macosx/Configuration/config.ini +++ b/qpid/java/management/eclipse-plugin/src/main/resources/macosx/Configuration/config.ini @@ -45,4 +45,5 @@ org.eclipse.ui, \ org.eclipse.ui.forms, \ org.eclipse.ui.workbench, \ org.eclipse.equinox.launcher, \ -org.eclipse.equinox.launcher.carbon.macosx +org.eclipse.equinox.launcher.carbon.macosx, \ +org.apache.commons.codec diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/qpid-management-common-plugin/MANIFEST.MF b/qpid/java/management/eclipse-plugin/src/main/resources/qpid-management-common-plugin/MANIFEST.MF index 5ef0c78606..818daef003 100644 --- a/qpid/java/management/eclipse-plugin/src/main/resources/qpid-management-common-plugin/MANIFEST.MF +++ b/qpid/java/management/eclipse-plugin/src/main/resources/qpid-management-common-plugin/MANIFEST.MF @@ -8,4 +8,4 @@ Export-Package: org.apache.qpid.management.common, org.apache.qpid.management.common.sasl Bundle-Vendor: Bundle-Localization: plugin -Require-Bundle: jmxremote.sasl +Require-Bundle: jmxremote.sasl;resolution:=optional diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Configuration/config.ini b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Configuration/config.ini new file mode 100644 index 0000000000..a99a8b3f7d --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Configuration/config.ini @@ -0,0 +1,49 @@ +############################################################################### +# 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. +############################################################################### + +#Product Runtime Configuration File + +osgi.splashPath=platform:/base/plugins/org.apache.qpid.management.ui +eclipse.product=org.apache.qpid.management.ui.product +osgi.bundles.defaultStartLevel=4 +osgi.bundles=jmxremote.sasl, \ +qpid-management-common, \ +org.apache.qpid.management.ui, \ +com.ibm.icu, \ +org.eclipse.core.commands, \ +org.eclipse.core.contenttype, \ +org.eclipse.core.databinding, \ +org.eclipse.core.expressions, \ +org.eclipse.core.jobs, \ +org.eclipse.core.runtime@start, \ +org.eclipse.core.runtime.compatibility.registry, \ +org.eclipse.equinox.app,org.eclipse.equinox.common, \ +org.eclipse.equinox.preferences, \ +org.eclipse.equinox.registry, \ +org.eclipse.help, \ +org.eclipse.jface, \ +org.eclipse.jface.databinding, \ +org.eclipse.swt, \ +org.eclipse.swt.gtk.solaris.sparc, \ +org.eclipse.ui, \ +org.eclipse.ui.forms, \ +org.eclipse.ui.workbench, \ +org.eclipse.equinox.launcher, \ +org.eclipse.equinox.launcher.gtk.solaris.sparc, \ +org.apache.commons.codec diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.l.pm b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.l.pm new file mode 100644 index 0000000000..995d7c9bb0 --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.l.pm @@ -0,0 +1,311 @@ +/* XPM */ +static char *ProductIcon48[] = { +/* columns rows colors chars-per-pixel */ +"48 48 257 2", +" c black", +". c gray100", +"X c #69695A5AE8E8", +"o c #494949499191", +"O c #CECE9292BFBF", +"+ c #E7E7CACAE0E0", +"@ c #C8C88C8CBBBB", +"# c #C2C28A8ABABA", +"$ c #EAEAD7D7E8E8", +"% c #CFCFA9A9CCCC", +"& c #D9D9BCBCD8D8", +"* c #B6B68787B9B9", +"= c #C3C39999C7C7", +"- c #A7A77D7DB5B5", +"; c #BDBDA3A3CDCD", +": c #D8D8CACAE3E3", +"> c #A8A88D8DC4C4", +", c #92927575B2B2", +"< c #87876C6CAAAA", +"1 c #9A9A8383BABA", +"2 c #7B7B6363A3A3", +"3 c #666654549595", +"4 c #73735F5FADAD", +"5 c #626251519292", +"6 c #7F7F7272A7A7", +"7 c #6D6D5E5E9E9E", +"8 c #64645454A9A9", +"9 c #77776969B1B1", +"0 c #49493E3E8282", +"q c #7D7D7373B6B6", +"w c #5B5B4E4EADAD", +"e c #55554949BABA", +"r c #56564949BABA", +"t c #56564A4ABABA", +"y c #56564949B9B9", +"u c #55554949B8B8", +"i c #4F4F4444ACAC", +"p c #53534848B4B4", +"a c #53534848B3B3", +"s c #54544949B5B5", +"d c #52524747B0B0", +"f c #52524747AFAF", +"g c #54544949B3B3", +"h c #DEDEDCDCEEEE", +"j c #3E3E36369898", +"k c #43433B3B9F9F", +"l c #33332C2C7777", +"z c #42423A3A9C9C", +"x c #4A4A4040A8A8", +"c c #55554A4ABABA", +"v c #55554A4AB9B9", +"b c #54544949B7B7", +"n c #52524848B1B1", +"m c #51514747AEAE", +"M c #4E4E4545A9A9", +"N c #49494141A0A0", +"B c #52524848AFAF", +"V c #51514848AEAE", +"C c #50504747ACAC", +"Z c #4F4F4646AAAA", +"A c #51514848ADAD", +"S c #50504747ABAB", +"D c #50504848ACAC", +"F c #50504747A9A9", +"G c #4E4E4646A7A7", +"H c #4E4E4545A4A4", +"J c #4D4D4545A4A4", +"K c #4F4F4747A8A8", +"L c #4E4E4646A5A5", +"P c #4D4D4545A3A3", +"I c #3B3B35357D7D", +"U c #4E4E4646A3A3", +"Y c #55554D4D9F9F", +"T c #4A4A43438989", +"R c #51514B4B9090", +"E c #67676060A5A5", +"W c #1D1D18186A6A", +"Q c #272722227D7D", +"! c #282823237D7D", +"~ c #2B2B26268181", +"^ c #33332C2C8989", +"/ c #3B3B36368E8E", +"( c #454540409797", +") c #4D4D4646A4A4", +"_ c #4C4C4545A1A1", +"` c #4D4D4646A2A2", +"' c #4B4B4545A0A0", +"] c #4D4D4646A1A1", +"[ c #4C4C45459F9F", +"{ c #4B4B45459E9E", +"} c #4A4A44449C9C", +"| c #494944449898", +" . c #484843439696", +".. c #4A4A45459999", +"X. c #4F4F4A4AA0A0", +"o. c #68686363AAAA", +"O. c #21211D1D7676", +"+. c #242420207575", +"@. c #2D2D2A2A7F7F", +"#. c #2D2D2A2A7B7B", +"$. c #3D3D39398F8F", +"%. c #484844449696", +"&. c #474743439393", +"*. c #464643439191", +"=. c #454542428E8E", +"-. c #4D4D4A4A9C9C", +";. c #57575454A3A3", +":. c #5A5A58589797", +">. c #5F5F5D5D9999", +",. c #85858282C1C1", +"<. c #95959292C9C9", +"1. c #B8B8B6B6DCDC", +"2. c #070705055353", +"3. c #080807075555", +"4. c #0A0A09095757", +"5. c #0C0C0B0B5858", +"6. c #0F0F0D0D5C5C", +"7. c #10100F0F5C5C", +"8. c #131311116464", +"9. c #141413136060", +"0. c #141413135F5F", +"q. c #171715156767", +"w. c #161615156262", +"e. c #161615156161", +"r. c #181817176464", +"t. c #1A1A19196666", +"y. c #1C1C1A1A6464", +"u. c #1D1D1C1C6868", +"i. c #1F1F1E1E6A6A", +"p. c #222221216C6C", +"a. c #242423236F6F", +"s. c #272725257171", +"d. c #272726267272", +"f. c #272726267171", +"g. c #292928287474", +"h. c #2A2A29297474", +"j. c #2C2C2B2B7777", +"k. c #2F2F2E2E7C7C", +"l. c #2E2E2D2D7979", +"z. c #343433337E7E", +"x. c #393937378686", +"c. c #373736368181", +"v. c #3A3A39398484", +"b. c #3A3A39398383", +"n. c #3D3D3B3B8686", +"m. c #424241418C8C", +"M. c #424241418B8B", +"N. c #444442428B8B", +"B. c #434341418989", +"V. c #454544448E8E", +"C. c #454544448D8D", +"Z. c #424241418787", +"A. c #434342428888", +"S. c #444442428787", +"D. c #424241418585", +"F. c #414140408383", +"G. c #484847479090", +"H. c #434342428686", +"J. c #4A4A49499393", +"K. c #464645458A8A", +"L. c #4D4D4C4C9595", +"P. c #54545252A0A0", +"I. c #50504F4F9898", +"U. c #58585757A0A0", +"Y. c #525250509393", +"T. c #5B5B5959A2A2", +"R. c #585857579F9F", +"E. c #62626161A9A9", +"W. c #64646363ACAC", +"Q. c #6B6B6A6AB2B2", +"!. c #6B6B6A6AB1B1", +"~. c #75757474B8B8", +"^. c #7F7F7D7DBDBD", +"/. c #9C9C9B9BCFCF", +"(. c #0B0B0B0B5858", +"). c #0D0D0D0D5A5A", +"_. c #111111115E5E", +"`. c #131313136060", +"'. c #212121216D6D", +"]. c #242424246F6F", +"[. c #2B2B2C2C7777", +"{. c #2B2B2B2B7777", +"}. c #2C2C2C2C7777", +"|. c #2E2E2E2E7979", +" X c #313131317C7C", +".X c #313131317B7B", +"XX c #343434347E7E", +"oX c #3C3C3C3C8686", +"OX c #3F3F3F3F8989", +"+X c #414142428B8B", +"@X c #424242428B8B", +"#X c #474747479090", +"$X c #414141418484", +"%X c #404040408181", +"&X c #4A4A4A4A9494", +"*X c #4A4A4A4A9393", +"=X c #4D4D4D4D9696", +"-X c #4F4F4F4F9898", +";X c #505050509898", +":X c #525252529B9B", +">X c #555555559E9E", +",X c #555555559D9D", +".% + : vX1.1.cXmX/.dXaXaXsXpXiXQ.uXrXqX8X6X5XT.R.P.X.P ) H G K K S S S m o ", +"X D.$XD.D.D.D.D.S.6 & $ h bXvXvX1.xX/.kXfXaXsXpXiXQ.yXrXW.E.6X5X4XU.,X:XI.-.` L G G K F Z C C o ", +"X D.D.D.D.D.Z.H.6 & $ h h h bXvX1.cXmXkX,.dXpXiXQ.yXtXqXwX6X5XT.U.,X:XI.=X*X..` G K K Z S S m o ", +"X Z.D.Z.H.Z.Z.7 & $ h h nXh bXvX1.cXmXkX,.gXiXQ.uXrXW.E.6X5X4XU.,X:X-XL.J.#XV. .P G F S S C m o ", +"X Z.Z.Z.H.Z.R % + : bXh h h bXvX1.cX/.kXhX~.Q.yXrXqX9X6X5X4X2X,X:X;X=X*X#XV.M.OX( K Z S S C m o ", +"X Z.Z.Z.A.A.* & & vXvXbXbXbXvXvX1.xXlXjX^.pXuXrXeXwX6X5X4XU.,X:X-XL.*XG.V.@XOXoXb.( Z S C C V o ", +"X B.B.B.A.2 % % 1.1.vXvXvXvXvX1.cXzX<.,.gXiXrXW.E.6X5X4XU.,X:XI.=X*X#XV.@XOXn.b.c.x.N S S C m o ", +"X B.B.B.S.* % ; xX1.1.1.1.1.cXcXzXlXjX^.pXrXeX7X6X5X4XR.,X:X-XL.J.#XV.@XOXn.b.c.XX X$.S C C m o ", +"X N.N.N.2 O = /.mXxXcXcXcXcXxXzXlXjXhX~.uXeXE.6X5X4XU.,X:X-XL.J.#XV.M.OXn.v.c.z. X|.k.N D V f o ", +"X N.N.N.- @ > kX<././.mXzXzXlX<.jXhXgXuXeXE.6X5X4X1X,X:XI.L.*X#XV.m.OXn.b.c.z. Xl.j.g./ C m V o ", +"X N.N.R @ # ,.,.jXkXkX<.kXkXjX,.^.~.uXwXE.6X5X4X1X,X:XI.=XJ.#XC.M.OXn.v.c.z..X|.j.g.d.#.M m B o ", +"X =.M.< @ * fXfXhXhX,.,.,.hX^.gXpXuXqX9X6X5X4XU.,X:XI.L.*XG.V.+XOXn.b.c.z..X|.[.g.d.a.p.z V B o ", +"X =.N.- @ NXNXBXBXBXVXCXCXCXCXZXZXZXZXAXAXSXSXSXDXDXDXFXFXFXGXPXPXHXHXIXJXMXMXMXKXKXLXLXLXB d o ", +"X =.=.* @ 1 dXdXaXaXsXpXiX!.yXrXeXwX6X5X4XX:XI.L.*XG.V.m.OXoXv.c.z. X|.j.g.d.a.'.i.u.t.r.w.9.d n o ", +"X &.&.@ @ ~.sXpXiXQ.yXtXW.E.6X5X4X1X,X:XI.=X*X#XC.m.OXn.b.c.z. X|.[.g.f.a.p.i.u.t.r.w.9.0.n a o ", +"X &.&.@ @ NXNXBXBXVXVXVXCXCXCXZXZXZXZXAXAXSXSXSXDXDXDXFXFXGXGXPXPXHXIXIXJXMXMXKXKXKXLXLXLXn n o ", +"X %. .# @ q iXQ.yXrXW.0X6X5X4XU.>X:XI.L.*X#XV.@XOXn.b.c.XX.X|.{.g.f.].'.i.u.t.r.w.0._.7.W n a o ", +"X %. .* # , Q.yXtXeX7X6X5X4XU.,X:X-XL.*X#XV.@XOXn.b.c.XX Xl.{.g.d.a.p.i.u.t.r.e.0._.7.).+.a a o ", +"X | | - # NXNXNXBXVXVXCXCXCXCXZXZXZXAXAXAXAXSXSXDXDXDXFXFXGXGXPXPXHXHXIXJXMXMXMXKXKXLXLXLXa a o ", +"X | | < # - rXeX9X6X5X4XU.,X:X-XL.*X#XC.@XOXoXb.c.z. X|.j.h.s.a.'.i.u.t.r.w.9._.7.).5.4.j a p o ", +"X | } Y # * 9 8X6X5X4X3X,X:XI.=X*XG.V.@XOXn.v.c.XX X|.j.g.f.a.p.i.u.t.r.e.0._.7.).5.4.q.i g p o ", +"X } } | - # , 6X5X4XR.,X:XI.=X*XG.V.m.OXoXb.c.XX X|.j.g.f.a.p.i.u.t.r.e.9._.7.).5.4.3.~ a s s o ", +"X } } } 4 # - E 4XU.>X:X-X=XJ.#XV.M.OXoXb.c.XX X|.{.h.d.a.'.i.u.t.r.e.9._.7.).5.4.3.6.z p s s o ", +"X { { } } - # < U.,X:XI.=X*XG.V.+XOXoXb.c.z. X|.}.g.d.a.'.i.u.t.r.w.0._.7.).5.4.3.2.! g p s s o ", +"X [ { ' [ 4 * - E :X;XL.J.#XV.m.OXoXb.c.z..X|.j.h.f.a.'.i.u.t.r.w.9._.6.).(.4.3.2.8.k p s s s o ", +"X [ [ ' _ [ , * , ;XL.J.#XV.@XOXoXv.c.z..X|.{.g.f.a.p.i.u.t.r.w.`._.7.).(.4.3.2.2.^ s p s s s o ", +"X _ _ _ _ P ] - * 2 *X#XV.m.OXn.v.c.XX X|.j.h.f.a.p.i.u.t.r.w.`._.7.).(.4.3.2.2.Q p s s s b u o ", +"X ` ` ` ` ` ` 8 - - 7 V.@XOXoXv.c.XX.X|.j.g.d.a.'.i.u.t.r.w.0._.7.).5.4.3.2.2.O.x p s s s u u o ", +"X P P ) P U U ) 8 - - 7 OXn.v.c.XX X|.j.h.f.a.p.i.u.t.r.w.0._.7.).5.4.3.2.2.O.x s s s s b u u o ", +"X L L ) H ) L L L 8 1 - 7 b.c.z. X|.j.h.f.a.'.i.u.t.r.w.0._.7.).5.4.3.2.2.Q x p s s s b b u e o ", +"X L G L G G G G G G G , * 2 T .Xl.j.h.f.a.p.i.u.t.r.e.0._.7.).5.4.3.2.8.^ p p s s s s u u e e o ", +"X G G G G G G G K K M M 4 , , 3 I g.d.a.p.i.u.t.r.e.`._.7.).5.4.3.7.! k p s p s s s u u u e v o ", +"X K G K K K K K K Z Z M F F 4 , < 3 I p.i.u.t.r.w.9._.7.).5.4.W ~ z a p p s s b s u u u e e e o ", +"X F Z F F F F Z Z F F S S S S S w 9 < 2 5 0 l p.e.9.y.a.l ^ j i a p p p s s b b b u e v y r e o ", +"X S Z Z S Z S Z S S S S S C C C A m d V f m B m B d d n d a a a p s p s s b u u u u e v e r t o ", +"X S S S S S S S S S S C C C m m A V V B B B d d d n n a a a p p s p s s b u u u e e e c t r t o ", +"X C C C C C C C C m C A m A m f V f f B d d d n n n a a a a s s s s s u b u u u u v t t r t t o ", +"YXo o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o YX" +}; diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.m.pm b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.m.pm new file mode 100644 index 0000000000..e64aa0cc06 --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.m.pm @@ -0,0 +1,295 @@ +/* XPM */ +static char *ProductIcon32[] = { +/* columns rows colors chars-per-pixel */ +"32 32 257 2", +" c black", +". c gray100", +"X c #69695A5AE8E8", +"o c #494949499191", +"O c #E8E8CBCBE0E0", +"+ c #DDDDB3B3D2D2", +"@ c #F0F0DDDDEBEB", +"# c #CDCD9191BEBE", +"$ c #C8C88B8BBBBB", +"% c #CACA9898C2C2", +"& c #C3C38A8ABBBB", +"* c #BABA8787B9B9", +"= c #DCDCC4C4DEDE", +"- c #C5C5A3A3CACA", +"; c #ADAD8181B8B8", +": c #A3A37A7AB5B5", +"> c #E2E2D6D6E9E9", +", c #B3B39A9AC4C4", +"< c #EBEBE3E3F0F0", +"1 c #C9C9B6B6D6D6", +"2 c #96967676B8B8", +"3 c #8C8C7171ABAB", +"4 c #A4A49292BEBE", +"5 c #7D7D6565A6A6", +"6 c #83836D6DABAB", +"7 c #9A9A8787C2C2", +"8 c #7B7B6464B7B7", +"9 c #5E5E50509191", +"0 c #646457579A9A", +"q c #85857B7BBEBE", +"w c #7C7C7373B6B6", +"e c #62625353D5D5", +"r c #61615353D4D4", +"t c #60605252D1D1", +"y c #5F5F5252D0D0", +"u c #5F5F5151CFCF", +"i c #60605353D2D2", +"p c #5F5F5252CFCF", +"a c #5E5E5151CDCD", +"s c #5C5C4F4FC7C7", +"d c #5F5F5252CDCD", +"f c #5E5E5151CBCB", +"g c #5B5B4F4FC4C4", +"h c #5A5A4E4EC1C1", +"j c #71716969B0B0", +"k c #48483E3EADAD", +"l c #5D5D5151CDCD", +"z c #5C5C5050C9C9", +"x c #5D5D5151CBCB", +"c c #5C5C5050C7C7", +"v c #5B5B4F4FC6C6", +"b c #5B5B5050C6C6", +"n c #59594E4EC1C1", +"m c #58584D4DBFBF", +"M c #59594F4FC2C2", +"N c #5A5A4F4FC2C2", +"B c #58584D4DBCBC", +"V c #57574D4DBCBC", +"C c #59594E4EBEBE", +"Z c #58584E4EBDBD", +"A c #58584D4DBBBB", +"S c #57574D4DBABA", +"D c #56564D4DB9B9", +"F c #56564C4CB6B6", +"G c #55554C4CB6B6", +"H c #54544B4BB4B4", +"J c #54544B4BB1B1", +"K c #53534B4BB1B1", +"L c #52524A4AAEAE", +"P c #51514949ACAC", +"I c #51514949ABAB", +"U c #474741418787", +"Y c #32322C2C8F8F", +"T c #2B2B25257777", +"R c #36362F2F9696", +"E c #2B2B26266E6E", +"W c #4D4D4545ACAC", +"Q c #55554D4DB8B8", +"! c #54544C4CB4B4", +"~ c #54544C4CB3B3", +"^ c #51514A4AACAC", +"/ c #51514A4AABAB", +"( c #50504949A9A9", +") c #4F4F4949A6A6", +"_ c #4C4C4747A1A1", +"` c #4E4E4848A3A3", +"' c #4D4D4848A1A1", +"] c #4B4B46469C9C", +"[ c #4C4C47479E9E", +"{ c #51514C4CA6A6", +"} c #A9A9A6A6D5D5", +"| c #1E1E1A1A6666", +" . c #292925258181", +".. c #3D3D39399292", +"X. c #4A4A46469B9B", +"o. c #53534E4EABAB", +"O. c #494945459797", +"+. c #4A4A46469999", +"@. c #474744449494", +"#. c #484845459494", +"$. c #474744449292", +"%. c #464643439090", +"&. c #464642428D8D", +"*. c #54545050A9A9", +"=. c #474744448F8F", +"-. c #4C4C49499999", +";. c #57575454A6A6", +":. c #5B5B5757AAAA", +">. c #545451519B9B", +",. c #5A5A57579C9C", +"<. c #65656262A7A7", +"1. c #68686666A2A2", +"2. c #CACAC9C9E5E5", +"3. c #050504045151", +"4. c #080807075454", +"5. c #0A0A09095858", +"6. c #0C0C0A0A5858", +"7. c #10100E0E6262", +"8. c #0E0E0D0D5A5A", +"9. c #121211115D5D", +"0. c #131312125D5D", +"q. c #161615156161", +"w. c #171716166161", +"e. c #1A1A19196565", +"r. c #20201E1E7070", +"t. c #1E1E1D1D6969", +"y. c #2A2A29297676", +"u. c #2F2F2D2D7676", +"i. c #3A3A39398787", +"p. c #3A3A39398383", +"a. c #3F3F3E3E8888", +"s. c #414140408989", +"d. c #454543438D8D", +"f. c #444442428B8B", +"g. c #444443438C8C", +"h. c #434342428A8A", +"j. c #434341418888", +"k. c #434342428989", +"l. c #424241418787", +"z. c #434342428787", +"x. c #424241418585", +"c. c #41413F3F8181", +"v. c #414140408282", +"b. c #484846468D8D", +"n. c #494948489090", +"m. c #4B4B4A4A9191", +"M. c #4B4B49498E8E", +"N. c #525251519A9A", +"B. c #525251519999", +"V. c #565654549A9A", +"C. c #545453539494", +"Z. c #60605F5FA7A7", +"A. c #64646363ABAB", +"S. c #5A5A59599797", +"D. c #68686767ADAD", +"F. c #6C6C6B6BB2B2", +"G. c #5E5E5D5D9A9A", +"H. c #76767575BABA", +"J. c #78787777BBBB", +"K. c #76767474B5B5", +"L. c #7E7E7D7DBABA", +"P. c #A5A5A4A4D2D2", +"I. c #040404045252", +"U. c #070707075454", +"Y. c #070708085353", +"T. c #080808085454", +"R. c #0A0A0B0B5757", +"E. c #0E0E0E0E5A5A", +"W. c #111112125E5E", +"Q. c #111111115E5E", +"!. c #111111115D5D", +"~. c #111112125D5D", +"^. c #161616166868", +"/. c #151516166161", +"(. c #151515156161", +"). c #19191A1A6565", +"_. c #191919196565", +"`. c #1A1A1A1A6464", +"'. c #1D1D1E1E6969", +"]. c #1E1E1E1E6969", +"[. c #222222226D6D", +"{. c #272727277171", +"}. c #2B2B2C2C7676", +"|. c #2B2B2B2B7676", +" X c #2B2B2B2B7575", +".X c #303030307A7A", +"XX c #303030307979", +"oX c #353535357F7F", +"OX c #393939398383", +"+X c #3A3A3A3A8383", +"@X c #3F3F3F3F8787", +"#X c #434343438C8C", +"$X c #434344448C8C", +"%X c #424242428686", +"&X c #414141418484", +"*X c #484848489191", +"=X c #484849499090", +"-X c #4D4D4D4D9696", +";X c #515151519D9D", +":X c #4D4D4D4D9595", +">X c #515152529A9A", +",X c #515152529999", +".-.+.] [ _ ` ) ( ^ L K H G D V C h o ", +"X &Xv.&Xx.x.l.j.M.1.4 - - , 7 q J.H.K.j :.*.P L K H F S B C n o ", +"X x.&Xx.x.z.j.S., = = 1 } iXuXH.rXwXF.qX7XZ.;.o.J ! F S B m n o ", +"X x.l.z.%Xz.G.1 @ > 2.dXaXiXuXrXwXF.qX8X5X4X2X;X{ H F S V C n o ", +"X z.j.j.j.C.1 @ < gX2.fXaXpXuXwXeX9X7X5X4X2XN.:X*X_ D S Z m h o ", +"X k.k.h.b., O > gXgX2.dXaXiXyXF.D.A.Z.4X3X1X:Xn.g.a._ V B m N o ", +"X f.f.f.3 + = 2.2.2.fXsXpXhXtXD.8XZ.4X2X1X:X*X$X@Xp.i.W C n N o ", +"X d.&.%.% + 1 dXdXdXsXP.iXyXK.8X5X4X2X>X:X*Xg.a.+XoX.X..m n N o ", +"X %.=.5 % - P.} aXP.pXiXyXK.D.Z.4X3X1X-Xn.$X@X+XoX.X Xy.W h g o ", +"X $.$.: # PXIXGXGXLXJXFXFXSXvXAXcXZXxXVXCXzXzXBXMXkXmXnXjXh g o ", +"X #.@.* $ 7 yXuXyXtXL.K.D.6X4X2X1X:Xo g.a.OXoX.X|.{.[.t. .g v o ", +"X O.#.$ $ q H.rXwXF.0XA.6X4X2X1X:Xo $Xa.p.oX.X|.{.[.'.`.r.g b o ", +"X X.+.$ $ PXKXbXbXLXJXDXFXSXvXAXcXZXxXCXCXzXBXBXMXNXmXlXjXb c o ", +"X ] ] $ $ H.wXF.0X7X6X4X2XX:Xo #Xa.+XoXXX|.{.[.t._.q.~.E.R.4.5.k x a o ", +"X ( ( I ; * 6 2X>X:X=X$X@X+XoX.X|.{.[.t.e./.W.E.R.Y.3. .z a a o ", +"X I ^ / 8 * : 0 :X*X#X@X+XoX.X|.{.[.'._.(.~.E.R.T.3.7.k x a p o ", +"X L L L ^ 2 * 3 m.$Xa.p.oX.X}.{.[.t.).(.~.E.6.T.3.I.R x a a y o ", +"X J K K K K 2 * 5 s.OXoX.X}.{.[.'._.(.9.8.R.4.3.I.Y x l a p t o ", +"X ~ H H ! ! ! 2 ; 5 U XX}.{.[.].e.(.W.E.R.U.3.7.R x l u u y t o ", +"X G F G G G Q Q 8 : 3 9 u.[.]._./.Q.E.R.T.6. .k x a a u t t t o ", +"X D S D S D S S S V 8 2 6 9 c.E w.0.| T Y k z z a a p t t i r o ", +"X A V B V V V B B m m n n h h g g g c z z z l l d p y t i r r o ", +"X m C C C C C C C n n n M N g g b c z z x a a a u y t t r r e o ", +"X n n n n n h h h N N g g v b s z z z x a p p u t t r r r e e o ", +"YXo o o o o o o o o o o o o o o o o o o o o o o o o o o o o o YX" +}; diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.s.pm b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.s.pm new file mode 100644 index 0000000000..e2b9379f3a --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.s.pm @@ -0,0 +1,287 @@ +/* XPM */ +static char *ProductIcon24[] = { +/* columns rows colors chars-per-pixel */ +"24 24 257 2", +" c black", +". c gray100", +"X c #69695A5AE8E8", +"o c #494949499191", +"O c #F1F1DFDFECEC", +"+ c #D7D7ACACCDCD", +"@ c #DFDFBBBBD6D6", +"# c #E2E2C4C4DBDB", +"$ c #CECE9C9CC4C4", +"% c #C4C48B8BBABA", +"& c #C2C28A8ABABA", +"* c #C4C48E8EBCBC", +"= c #BFBF8A8AB9B9", +"- c #EBEBD9D9E9E9", +"; c #BFBF8888B9B9", +": c #D8D8B9B9D6D6", +"> c #B9B98686B9B9", +", c #B8B88989B9B9", +"< c #BBBB9393BFBF", +"1 c #A9A97B7BB2B2", +"2 c #E4E4D4D4E7E7", +"3 c #C6C6AFAFCECE", +"4 c #A6A68080B6B6", +"5 c #A2A27E7EB4B4", +"6 c #9E9E7E7EB1B1", +"7 c #ABAB9090BBBB", +"8 c #B7B7A0A0C5C5", +"9 c #9D9D7C7CB2B2", +"0 c #AAAA8B8BBEBE", +"q c #AAAA9090BCBC", +"w c #8C8C6B6BABAB", +"e c #90907070B1B1", +"r c #C4C4B3B3D7D7", +"t c #CDCDBFBFDDDD", +"y c #EAEAE4E4F1F1", +"u c #88886A6AADAD", +"i c #9E9E8585C1C1", +"p c #84846A6AAFAF", +"a c #81816B6BAAAA", +"s c #D7D7CFCFE6E6", +"d c #81816969B1B1", +"f c #78786363A5A5", +"g c #6E6E5D5D9C9C", +"h c #717160609D9D", +"j c #83837474AAAA", +"k c #6A6A5757A3A3", +"l c #6E6E5E5EA0A0", +"z c #5E5E50509292", +"x c #88887B7BBCBC", +"c c #68685858ABAB", +"v c #5A5A4D4DA2A2", +"b c #7D7D7373B4B4", +"n c #5A5A4E4EA6A6", +"m c #5F5F56569595", +"M c #56564A4ABBBB", +"N c #56564949B9B9", +"B c #55554949B8B8", +"V c #53534848B3B3", +"C c #54544949B4B4", +"Z c #52524747B0B0", +"A c #52524747AFAF", +"S c #5B5B53539393", +"D c #3E3E36369797", +"F c #49494040A6A6", +"G c #48484040A5A5", +"H c #55554A4ABABA", +"J c #54544949B7B7", +"K c #53534949B4B4", +"L c #51514747AFAF", +"P c #52524848B1B1", +"I c #51514848B0B0", +"U c #51514848AEAE", +"Y c #51514747ADAD", +"T c #51514848ADAD", +"R c #4F4F4747ABAB", +"E c #50504747ABAB", +"W c #50504646A9A9", +"Q c #4F4F4646A8A8", +"! c #4E4E4646A7A7", +"~ c #4E4E4545A4A4", +"^ c #4D4D4545A4A4", +"/ c #4E4E4646A5A5", +"( c #4D4D4545A1A1", +") c #3D3D36367E7E", +"_ c #4B4B44449C9C", +"` c #2A2A25257F7F", +"' c #3E3E37379898", +"] c #474740409C9C", +"[ c #4D4D4646A4A4", +"{ c #4C4C4545A2A2", +"} c #4D4D4646A2A2", +"| c #4D4D4646A1A1", +" . c #4B4B45459F9F", +".. c #4C4C45459F9F", +"X. c #4C4C46469F9F", +"o. c #4B4B45459D9D", +"O. c #494943439898", +"+. c #494944449A9A", +"@. c #4A4A45459A9A", +"#. c #494944449898", +"$. c #484843439696", +"%. c #494944449797", +"&. c #484843439595", +"*. c #51514C4CA1A1", +"=. c #6B6B6767AEAE", +"-. c #95959191C9C9", +";. c #23231F1F7676", +":. c #21211E1E7070", +">. c #292925257F7F", +",. c #252521217070", +"<. c #242421216D6D", +"1. c #2B2B27278080", +"2. c #393935358C8C", +"3. c #444440409494", +"4. c #3B3B38388282", +"5. c #474743439494", +"6. c #484844449595", +"7. c #474743439393", +"8. c #474744449393", +"9. c #464643439191", +"0. c #454542428F8F", +"q. c #4A4A47479898", +"w. c #464643438F8F", +"e. c #454542428D8D", +"r. c #444441418B8B", +"t. c #484844449191", +"y. c #444441418989", +"u. c #494946469090", +"i. c #4C4C48489393", +"p. c #51514E4E9E9E", +"a. c #73737070B6B6", +"s. c #77777474BBBB", +"d. c #A0A09E9ED1D1", +"f. c #D6D6D5D5EBEB", +"g. c #0E0E0D0D5A5A", +"h. c #11110F0F5E5E", +"j. c #121211115E5E", +"k. c #131312125F5F", +"l. c #171716166363", +"z. c #1D1D1B1B6868", +"x. c #1D1D1C1C6868", +"c. c #222221216E6E", +"v. c #222221216D6D", +"b. c #282827277474", +"n. c #282827277373", +"m. c #292928287373", +"M. c #2F2F2E2E7979", +"N. c #353534347F7F", +"B. c #363635358181", +"V. c #3C3C3B3B8585", +"C. c #424241418C8C", +"Z. c #424241418B8B", +"A. c #444442428B8B", +"S. c #434341418989", +"D. c #434342428989", +"F. c #424241418787", +"G. c #414140408484", +"H. c #474745458D8D", +"J. c #434342428787", +"K. c #424241418585", +"L. c #414140408282", +"P. c #494948489191", +"I. c #4F4F4E4E9797", +"U. c #59595757A6A6", +"Y. c #5F5F5D5DA4A4", +"T. c #6C6C6B6BB3B3", +"R. c #7C7C7B7BB9B9", +"E. c #A8A8A7A7D3D3", +"W. c #0D0D0D0D5A5A", +"Q. c #1F1F1F1F6C6C", +"!. c #222222226E6E", +"~. c #3B3B3B3B8585", +"^. c #414141418C8C", +"/. c #414141418B8B", +"(. c #424242428B8B", +"). c #484848489292", +"_. c #404040408181", +"`. c #4E4E4E4E9898", +"'. c #555555559E9E", +"]. c #555555559D9D", +"[. c #5B5B5B5BA3A3", +"{. c #5C5C5C5CA3A3", +"}. c #61616161A9A9", +"|. c #66666666AEAE", +" X c #66666666ADAD", +".X c #6B6B6B6BB2B2", +"XX c #70707070B7B7", +"oX c #6A6A6A6AADAD", +"OX c #74747474BBBB", +"+X c #89898989C2C2", +"@X c #90909090C8C8", +"#X c #8F8F8F8FC6C6", +"$X c #92929292C6C6", +"%X c #9F9F9F9FCFCF", +"&X c #A5A5A5A5D2D2", +"*X c #B5B5B5B5DBDB", +"=X c #B8B8B8B8DEDE", +"-X c #B7B7B7B7DCDC", +";X c #BBBBBBBBDEDE", +":X c #BDBDBDBDDFDF", +">X c #C9C9C9C9E5E5", +",X c #D1D1D1D1EAEA", +"X*X%X+X|.}.[.].I.P.^.~.B.] E Y o ", +"X e.u.q @ t :X-XE.$X 5 Y.].I.)./.~.N.M.b.v.x.l.k.h.' V C o ", +"X o.o.o.u , a I.).Z.V.N.M.n.c.z.l.j.W.` P V C o ", +"X .. .X.v e 4 l ^.V.N.M.m.!.x.l.j.g.;.F V C J o ", +"X ( | ( ( n p 9 g 4.M.n.c.x.l.j.h.>.G V K C J o ", +"X ~ [ [ ^ / / c d f z ) <.z.,.1.D P V C C B B o ", +"X ! Q ! Q Q Q Q W E E Y T A Z P V V K C J B B o ", +"X Q W Q W R W E E T T T L Z P V V K J J J B N o ", +"X R E E E E E Y Y U L Z P P P C V J J B B H M o ", +"YXo o o o o o o o o o o o o o o o o o o o o o YX" +}; diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.t.pm b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.t.pm new file mode 100644 index 0000000000..3f6b21f428 --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/Qpidmc.t.pm @@ -0,0 +1,279 @@ +/* XPM */ +static char *ProductIcon16[] = { +/* columns rows colors chars-per-pixel */ +"16 16 257 2", +" c black", +". c gray100", +"X c #E2E2C0C0D9D9", +"o c #EDEDD9D9E8E8", +"O c #D5D5ABABCDCD", +"+ c #E2E2C3C3DCDC", +"@ c #C5C58E8EBCBC", +"# c #D4D4ABABCDCD", +"$ c #CACA9F9FC6C6", +"% c #D6D6B4B4D3D3", +"& c #CACAA0A0C8C8", +"* c #C6C69D9DC6C6", +"= c #C5C59F9FC8C8", +"- c #CCCCACACCECE", +"; c #CCCCB0B0D3D3", +": c #A6A68383B3B3", +"> c #BABA9A9AC6C6", +", c #B7B79A9AC2C2", +"< c #E3E3D5D5E9E9", +"1 c #B0B08E8EC0C0", +"2 c #9F9F8080B8B8", +"3 c #AFAF9898C1C1", +"4 c #DBDBCFCFE5E5", +"5 c #96967878B2B2", +"6 c #9A9A7E7EBABA", +"7 c #8E8E7878AFAF", +"8 c #91917F7FBDBD", +"9 c #D3D3CCCCE4E4", +"0 c #535348488B8B", +"q c #69695A5AE8E8", +"w c #55554949B9B9", +"e c #55554949B8B8", +"r c #54544848B6B6", +"t c #53534848B4B4", +"y c #54544848B4B4", +"u c #53534848B3B3", +"i c #53534848B2B2", +"p c #52524747AFAF", +"a c #53534848B1B1", +"s c #54544949B8B8", +"d c #54544949B6B6", +"f c #52524848B3B3", +"g c #52524848B2B2", +"h c #53534949B3B3", +"j c #52524848B1B1", +"k c #52524848B0B0", +"l c #51514747AEAE", +"z c #52524848AFAF", +"x c #51514848AEAE", +"c c #51514747ADAD", +"v c #51514747ACAC", +"b c #4F4F4646AAAA", +"n c #51514848ADAD", +"m c #50504747ABAB", +"M c #50504747AAAA", +"N c #4F4F4646A8A8", +"B c #50504747A9A9", +"V c #4E4E4646A7A7", +"C c #4E4E4646A6A6", +"Z c #4F4F4646A6A6", +"A c #4F4F4747A7A7", +"S c #4D4D4545A3A3", +"D c #4D4D4545A2A2", +"F c #4C4C45459E9E", +"G c #74746E6EB3B3", +"H c #2E2E29298383", +"J c #383832329090", +"K c #464640409999", +"L c #4D4D4646A2A2", +"P c #4E4E4747A3A3", +"I c #4B4B45459F9F", +"U c #4B4B45459E9E", +"Y c #4C4C46469F9F", +"T c #4A4A44449B9B", +"R c #4A4A44449A9A", +"E c #494943439797", +"W c #494944449797", +"Q c #484843439494", +"! c #78787474B8B8", +"~ c #272724247878", +"^ c #2D2D2A2A7575", +"/ c #484844449797", +"( c #474743439393", +") c #454542429090", +"_ c #4B4B48489A9A", +"` c #464643438F8F", +"' c #464643438E8E", +"] c #454542428C8C", +"[ c #51514D4DA0A0", +"{ c #5C5C5959A5A5", +"} c #535350509090", +"| c #C8C8C7C7E3E3", +" . c #121211115D5D", +".. c #1A1A19196565", +"X. c #242422226D6D", +"o. c #3F3F3E3E8888", +"O. c #444442428D8D", +"+. c #444442428989", +"@. c #424241418787", +"#. c #454543438A8A", +"$. c #434342428888", +"%. c #424241418686", +"&. c #414140408484", +"*. c #414140408383", +"=. c #424240408383", +"-. c #414140408282", +";. c #474746468D8D", +":. c #464644448989", +">. c #525251519999", +",. c #64646363AAAA", +"<. c #61615F5FA2A2", +"1. c #6E6E6C6CB2B2", +"2. c #A5A5A4A4D3D3", +"3. c #B0B0AFAFD6D6", +"4. c #111112125D5D", +"5. c #19191A1A6565", +"6. c #1E1E1E1E6C6C", +"7. c #222222226D6D", +"8. c #2B2B2B2B7676", +"9. c #2B2B2B2B7575", +"0. c #2B2B2C2C7575", +"q. c #343435357F7F", +"w. c #343435357E7E", +"e. c #353535357F7F", +"r. c #3E3E3E3E8888", +"t. c #3E3E3E3E8787", +"y. c #414141418484", +"u. c #404040408282", +"i. c #484849499191", +"p. c #494949499191", +"a. c #484848489090", +"s. c #484849499090", +"d. c #404040408080", +"f. c #525252529A9A", +"g. c #525252529999", +"h. c #5B5B5B5BA3A3", +"j. c #5B5B5B5BA2A2", +"k. c #64646464ABAB", +"l. c #63636464AAAA", +"z. c #6B6B6C6CB2B2", +"x. c #72727373B9B9", +"c. c #71717171A4A4", +"v. c #78787878ABAB", +"b. c #7F7F7F7FB1B1", +"n. c #8C8C8C8CBEBE", +"m. c #A5A5A5A5D2D2", +"M. c #C9C9C9C9E5E5", +"N. c #85858686B7B7", +"B. c #91919292C4C4", +"V. c #71718989BCBC", +"C. c #73738B8BBEBE", +"Z. c #75758D8DC0C0", +"A. c #78789090C3C3", +"S. c #7A7A9292C5C5", +"D. c #71718A8ABDBD", +"F. c #76768E8EC0C0", +"G. c #78789090C2C2", +"H. c #7B7B9393C5C5", +"J. c #7D7D9595C7C7", +"K. c #80809999CACA", +"L. c #7E7E9696C7C7", +"P. c #83839B9BCDCD", +"I. c #83839B9BCCCC", +"U. c #86869E9ECFCF", +"Y. c #8888A1A1D1D1", +"T. c #8A8AA2A2D3D3", +"R. c #8989A1A1D1D1", +"E. c #8B8BA3A3D3D3", +"W. c gray100", +"Q. c black", +"!. c black", +"~. c black", +"^. c black", +"/. c black", +"(. c black", +"). c black", +"_. c black", +"`. c black", +"'. c black", +"]. c black", +"[. c black", +"{. c black", +"}. c black", +"|. c black", +" X c black", +".X c black", +"XX c black", +"oX c black", +"OX c black", +"+X c black", +"@X c black", +"#X c black", +"$X c black", +"%X c black", +"&X c black", +"*X c black", +"=X c black", +"-X c black", +";X c black", +":X c black", +">X c black", +",X c black", +"._ A m p.", +"q +.: X < M.m.z.l.j.g.s.r.K v p.", +"q ' $ + 9 | 3.B.n.N.b.v.c.<.n p.", +"q ` O T.Y.U.P.K.L.S.G.F.C.D.l p.", +"q ( # @ G k.h.g.i.t.e.9.7.6.z p.", +"q / * E.R.U.I.K.J.H.A.Z.C.V.a p.", +"q T 2 & 5 f.a.o.q.8.7...4.J u p.", +"q I Y 1 = 7 ;.w.0.7.5. .H f y p.", +"q L D P 6 > 3 0 ^ X.~ J i t d p.", +"q C C V A N M m n p k g y r e p.", +"q M b M m m c x p j h y d s w p.", +"YXp.p.p.p.p.p.p.p.p.p.p.p.p.p.YX" +}; diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/qpidmc b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/qpidmc new file mode 100755 index 0000000000..b88ff49e8e Binary files /dev/null and b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/qpidmc differ diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/qpidmc.ini b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/qpidmc.ini new file mode 100644 index 0000000000..cfa715e5a8 --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/main/resources/solaris-gtk-sparc/qpidmc.ini @@ -0,0 +1,40 @@ +############################################################################### +# 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. +############################################################################### +-startup +plugins/org.eclipse.equinox.launcher_1.0.101.R34x_v20080819.jar +--launcher.library +plugins/org.eclipse.equinox.launcher.gtk.solaris.sparc_1.0.101.R34x_v20080731 +-vmargs +-Xms40m +-Xmx256m +-XX:MaxPermSize=256m +-Dosgi.requiredJavaVersion=1.5 +-Declipse.consoleLog=true + +#=============================================== +# SSL trust store configuration options. +#=============================================== + +# Uncomment lines below to specify custom truststore for server SSL +# certificate verification, eg when using self-signed server certs. +# +#-Djavax.net.ssl.trustStore= +#-Djavax.net.ssl.trustStorePassword= + + diff --git a/qpid/java/management/eclipse-plugin/src/main/resources/win32-win32-x86/Configuration/config.ini b/qpid/java/management/eclipse-plugin/src/main/resources/win32-win32-x86/Configuration/config.ini index d00d756706..a61bea2fa8 100644 --- a/qpid/java/management/eclipse-plugin/src/main/resources/win32-win32-x86/Configuration/config.ini +++ b/qpid/java/management/eclipse-plugin/src/main/resources/win32-win32-x86/Configuration/config.ini @@ -45,4 +45,5 @@ org.eclipse.ui, \ org.eclipse.ui.forms, \ org.eclipse.ui.workbench, \ org.eclipse.equinox.launcher, \ -org.eclipse.equinox.launcher.win32.win32.x86 +org.eclipse.equinox.launcher.win32.win32.x86, \ +org.apache.commons.codec diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/client/MessageListenerTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/client/MessageListenerTest.java index 4c1d5ee9c1..ffec6c7a29 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/client/MessageListenerTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/client/MessageListenerTest.java @@ -106,6 +106,14 @@ public class MessageListenerTest extends QpidTestCase implements MessageListener } } + public void testSynchronousRecieveNoWait() throws Exception + { + for (int msg = 0; msg < MSG_COUNT; msg++) + { + assertTrue(_consumer.receiveNoWait() != null); + } + } + public void testAsynchronousRecieve() throws Exception { _consumer.setMessageListener(this); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/QueueCreateTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/QueueCreateTest.java new file mode 100644 index 0000000000..dd9b35c475 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/QueueCreateTest.java @@ -0,0 +1,179 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.queue; + +import org.apache.qpid.AMQException; +import org.apache.qpid.client.AMQSession; +import org.apache.qpid.client.failover.FailoverException; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.test.utils.QpidTestCase; + +import javax.jms.Connection; +import javax.jms.JMSException; +import javax.jms.Session; +import javax.naming.NamingException; +import java.util.HashMap; +import java.util.Map; + +/** The purpose of this set of tests is to ensure */ +public class QueueCreateTest extends QpidTestCase +{ + private Connection _connection; + private AMQSession _session; + private int _queueCount = 0; + + public void setUp() throws Exception + { + _connection = getConnection(); + + _session = (AMQSession) _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + } + + private void testQueueWithArguments(Map arguments) throws AMQException + { + _session.createQueue(new AMQShortString(this.getName() + (_queueCount++)), false, false, false, arguments); + } + + public void testCreateNoArguments() throws AMQException, FailoverException + { + Map arguments = null; + testQueueWithArguments(arguments); + } + + public void testCreatePriorityInt() throws AMQException, FailoverException + { + Map arguments = new HashMap(); + + //Ensure we can call createQueue with a priority int value + arguments.put(AMQQueueFactory.X_QPID_PRIORITIES.toString(), 7); + testQueueWithArguments(arguments); + } + + /** + * @link https://issues.apache.org/jira/browse/QPID-1715, QPID-1716 + * + * @throws AMQException + * @throws FailoverException + */ + public void testCreatePriorityString() throws AMQException, FailoverException + { + Map arguments = new HashMap(); + + //Ensure we can call createQueue with a priority value that is not an int + arguments.put(AMQQueueFactory.X_QPID_PRIORITIES.toString(), "seven"); + try + { + + testQueueWithArguments(arguments); + fail("Invalid Property value still succeeds."); + } + catch (Exception e) + { + assertTrue("Incorrect error message thrown:" + e.getMessage(), + e.getMessage().startsWith("Queue create request with non integer value for :x-qpid-priorities=seven")); + } + } + + public void testCreateFlowToDiskValid() throws AMQException, FailoverException + { + Map arguments = new HashMap(); + + //Ensure we can call createQueue with a priority int value + arguments.put(AMQQueueFactory.QPID_POLICY_TYPE.toString(), AMQQueueFactory.QPID_FLOW_TO_DISK); + arguments.put(AMQQueueFactory.QPID_MAX_SIZE.toString(), 100); + testQueueWithArguments(arguments); + } + + /** + * @link https://issues.apache.org/jira/browse/QPID-1715, QPID-1716 + * @throws AMQException + * @throws FailoverException + */ + public void testCreateFlowToDiskValidNoSize() throws AMQException, FailoverException + { + Map arguments = new HashMap(); + + //Ensure we can call createQueue with a priority int value + arguments.put(AMQQueueFactory.QPID_POLICY_TYPE.toString(), AMQQueueFactory.QPID_FLOW_TO_DISK); + try + { + testQueueWithArguments(arguments); + } + catch (AMQException e) + { + assertTrue("Incorrect Error throw:" + e.getMessage() + + ":expecting:Queue create request with no qpid.max_size value", + e.getMessage().contains("Queue create request with no qpid.max_size value")); + } + } + + /** + * @link https://issues.apache.org/jira/browse/QPID-1715, QPID-1716 + * @throws AMQException + * @throws FailoverException + */ + public void testCreateFlowToDiskInvalid() throws AMQException, FailoverException + { + Map arguments = new HashMap(); + + arguments.put(AMQQueueFactory.QPID_POLICY_TYPE.toString(), "infinite"); + try + { + testQueueWithArguments(arguments); + fail("Invalid Property value still succeeds."); + } + catch (Exception e) + { + //Check error is correct + assertTrue("Incorrect error message thrown:" + e.getMessage(), + e.getMessage().startsWith("Queue create request with unknown Policy Type:infinite")); + } + + } + + /** + * @link https://issues.apache.org/jira/browse/QPID-1715, QPID-1716 + * @throws AMQException + * @throws FailoverException + */ + public void testCreateFlowToDiskInvalidSize() throws AMQException, FailoverException + { + Map arguments = new HashMap(); + + arguments.put(AMQQueueFactory.QPID_POLICY_TYPE.toString(), AMQQueueFactory.QPID_FLOW_TO_DISK); + arguments.put(AMQQueueFactory.QPID_MAX_SIZE.toString(), -1); + try + { + testQueueWithArguments(arguments); + fail("Invalid Property value still succeeds."); + } + catch (Exception e) + { + //Check error is correct + assertTrue("Incorrect error message thrown:" + e.getMessage(), + e.getMessage().startsWith("Queue create request with negative size:-1")); + } + + } + + +} diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowsingFlowToDiskTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowsingFlowToDiskTest.java new file mode 100644 index 0000000000..02965b5ab7 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowsingFlowToDiskTest.java @@ -0,0 +1,69 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.test.client; + +import org.apache.qpid.AMQException; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.client.AMQSession; +import org.apache.qpid.server.queue.AMQQueueFactory; + +import javax.jms.JMSException; +import javax.jms.Connection; +import javax.jms.Session; +import java.util.Map; +import java.util.HashMap; + +public class QueueBrowsingFlowToDiskTest extends QueueBrowserAutoAckTest +{ + @Override + protected void sendMessages(Connection producerConnection, int messageSendCount) throws JMSException + { + try + { + setupFlowToDisk(producerConnection, messageSendCount , this.getName()); + } + catch (AMQException e) + { + fail("Unable to setup Flow to disk:"+e.getMessage()); + } + + super.sendMessages(producerConnection,messageSendCount); + } + + private void setupFlowToDisk(Connection producerConnection, int messages, String name) + throws AMQException, JMSException + { + Map arguments = new HashMap(); + + //Ensure we can call createQueue with a priority int value + arguments.put(AMQQueueFactory.QPID_POLICY_TYPE.toString(), AMQQueueFactory.QPID_FLOW_TO_DISK); + // each message in the QBAAT is around 9-10 bytes each so only give space for half + arguments.put(AMQQueueFactory.QPID_MAX_SIZE.toString(), 5 * messages); + + //Create the FlowToDisk Queue + ((AMQSession) producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE)). + createQueue(new AMQShortString(name), false, false, false, arguments); + + // Get a JMS reference to the new queue + _queue = _clientSession.createQueue(name); + } + +} diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java index 3a1fb50725..b7ae911a49 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java @@ -21,36 +21,37 @@ package org.apache.qpid.test.client.failover; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQConnectionFactory; -import org.apache.qpid.client.AMQConnectionURL; -import org.apache.qpid.client.transport.TransportConnection; -import org.apache.qpid.jms.ConnectionListener; -import org.apache.qpid.jms.ConnectionURL; -import org.apache.qpid.jms.BrokerDetails; -import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.test.utils.FailoverBaseCase; -import org.apache.log4j.Logger; +import java.util.Random; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import javax.jms.Connection; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageProducer; +import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.jms.Queue; import javax.naming.NamingException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; + +import org.apache.log4j.Logger; +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.client.AMQSession_0_10; +import org.apache.qpid.jms.BrokerDetails; +import org.apache.qpid.jms.ConnectionListener; +import org.apache.qpid.jms.ConnectionURL; +import org.apache.qpid.test.utils.FailoverBaseCase; public class FailoverTest extends FailoverBaseCase implements ConnectionListener { private static final Logger _logger = Logger.getLogger(FailoverTest.class); private static final String QUEUE = "queue"; - private static final int NUM_MESSAGES = 10; - private Connection connnection; + private static final int DEFAULT_NUM_MESSAGES = 10; + private static final int DEFAULT_SEED = 20080921; + protected int numMessages = 0; + protected Connection connection; private Session producerSession; private Queue queue; private MessageProducer producer; @@ -61,26 +62,32 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener private CountDownLatch failoverComplete; private static final long DEFAULT_FAILOVER_TIME = 10000L; private boolean CLUSTERED = Boolean.getBoolean("profile.clustered"); - + private int seed; + private Random rand; + @Override protected void setUp() throws Exception { super.setUp(); - - connnection = getConnection(); - ((AMQConnection) connnection).setConnectionListener(this); - connnection.start(); + + numMessages = Integer.getInteger("profile.failoverMsgCount",DEFAULT_NUM_MESSAGES); + seed = Integer.getInteger("profile.failoverRandomSeed",DEFAULT_SEED); + rand = new Random(seed); + + connection = getConnection(); + ((AMQConnection) connection).setConnectionListener(this); + connection.start(); failoverComplete = new CountDownLatch(1); } - private void init(boolean transacted, int mode) throws JMSException, NamingException + protected void init(boolean transacted, int mode) throws JMSException, NamingException { queue = (Queue) getInitialContext().lookup(QUEUE); - consumerSession = connnection.createSession(transacted, mode); + consumerSession = connection.createSession(transacted, mode); consumer = consumerSession.createConsumer(queue); - producerSession = connnection.createSession(transacted, mode); + producerSession = connection.createSession(transacted, mode); producer = producerSession.createProducer(queue); } @@ -89,7 +96,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener { try { - connnection.close(); + connection.close(); } catch (Exception e) { @@ -99,26 +106,46 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener super.tearDown(); } - private void consumeMessages(int toConsume, boolean transacted) throws JMSException + private void consumeMessages(int startIndex,int endIndex, boolean transacted) throws JMSException { Message msg; - for (int i = 0; i < toConsume; i++) + _logger.debug("**************** Receive (Start: " + startIndex + ", End:" + endIndex + ")***********************"); + + for (int i = startIndex; i < endIndex; i++) { - msg = consumer.receive(1000); + msg = consumer.receive(1000); assertNotNull("Message " + i + " was null!", msg); - assertEquals("message " + i, ((TextMessage) msg).getText()); + + _logger.debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); + _logger.debug("Received : " + ((TextMessage) msg).getText()); + _logger.debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); + + assertEquals("Invalid message order","message " + i, ((TextMessage) msg).getText()); + } - if (transacted) { + _logger.debug("***********************************************************"); + + if (transacted) + { consumerSession.commit(); } } - private void sendMessages(int totalMessages, boolean transacted) throws JMSException + private void sendMessages(int startIndex,int endIndex, boolean transacted) throws JMSException { - for (int i = 0; i < totalMessages; i++) - { + _logger.debug("**************** Send (Start: " + startIndex + ", End:" + endIndex + ")***********************"); + + for (int i = startIndex; i < endIndex; i++) + { producer.send(producerSession.createTextMessage("message " + i)); + + _logger.debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); + _logger.debug("Sending message"+i); + _logger.debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); } + + _logger.debug("***********************************************************"); + if (transacted) { producerSession.commit(); @@ -127,47 +154,93 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener public void testP2PFailover() throws Exception { - testP2PFailover(NUM_MESSAGES, true, false); + testP2PFailover(numMessages, true,true, false); } - public void testP2PFailoverWithMessagesLeft() throws Exception + public void testP2PFailoverWithMessagesLeftToConsumeAndProduce() throws Exception { - testP2PFailover(NUM_MESSAGES, false, false); + if (CLUSTERED) + { + testP2PFailover(numMessages, false,false, false); + } } - + + public void testP2PFailoverWithMessagesLeftToConsume() throws Exception + { + if (CLUSTERED) + { + testP2PFailover(numMessages, false,true, false); + } + } + public void testP2PFailoverTransacted() throws Exception { - testP2PFailover(NUM_MESSAGES, true, false); + testP2PFailover(numMessages, true,true, false); } - private void testP2PFailover(int totalMessages, boolean consumeAll, boolean transacted) throws JMSException, NamingException + public void testP2PFailoverTransactedWithMessagesLeftToConsumeAndProduce() throws Exception { - Message msg = null; + // Currently the cluster does not support transactions that span a failover + if (CLUSTERED) + { + testP2PFailover(numMessages, false,false, false); + } + } + + private void testP2PFailover(int totalMessages, boolean consumeAll, boolean produceAll , boolean transacted) throws JMSException, NamingException + { init(transacted, Session.AUTO_ACKNOWLEDGE); - sendMessages(totalMessages, transacted); + runP2PFailover(totalMessages,consumeAll, produceAll , transacted); + } + + protected void runP2PFailover(int totalMessages, boolean consumeAll, boolean produceAll , boolean transacted) throws JMSException, NamingException + { + Message msg = null; + int toProduce = totalMessages; + + _logger.debug("==================================================================="); + _logger.debug("Total messages used for the test " + totalMessages + " messages"); + _logger.debug("==================================================================="); + + if (!produceAll) + { + toProduce = totalMessages - rand.nextInt(totalMessages); + } + + _logger.debug("=================="); + _logger.debug("Sending " + toProduce + " messages"); + _logger.debug("=================="); + + sendMessages(0,toProduce, transacted); // Consume some messages - int toConsume = totalMessages; + int toConsume = toProduce; if (!consumeAll) { - toConsume = totalMessages / 2; + toConsume = toProduce - rand.nextInt(toProduce); } + + consumeMessages(0,toConsume, transacted); - consumeMessages(toConsume, transacted); - + _logger.debug("=================="); + _logger.debug("Consuming " + toConsume + " messages"); + _logger.debug("=================="); + _logger.info("Failing over"); causeFailure(DEFAULT_FAILOVER_TIME); - if (!CLUSTERED) - { - msg = consumer.receive(500); - assertNull("Should not have received message from new broker!", msg); - } - - // Check that messages still sent / received - sendMessages(totalMessages, transacted); - consumeMessages(totalMessages, transacted); + // Check that you produce and consume the rest of messages. + _logger.debug("=================="); + _logger.debug("Sending " + (totalMessages-toProduce) + " messages"); + _logger.debug("=================="); + + sendMessages(toProduce,totalMessages, transacted); + consumeMessages(toConsume,totalMessages, transacted); + + _logger.debug("=================="); + _logger.debug("Consuming " + (totalMessages-toConsume) + " messages"); + _logger.debug("=================="); } private void causeFailure(long delay) @@ -188,11 +261,11 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener //evil ignore IE. } } - + public void testClientAckFailover() throws Exception { init(false, Session.CLIENT_ACKNOWLEDGE); - sendMessages(1, false); + sendMessages(0,1, false); Message msg = consumer.receive(); assertNotNull("Expected msgs not received", msg); @@ -208,7 +281,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener failure = e; } assertNotNull("Exception should be thrown", failure); - } + } /** * The client used to have a fixed timeout of 4 minutes after which failover would no longer work. @@ -216,6 +289,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener * * @throws Exception if something unexpected occurs in the test. */ + public void test4MinuteFailover() throws Exception { ConnectionURL connectionURL = getConnectionFactory().getConnectionURL(); @@ -228,12 +302,12 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener details.setProperty(BrokerDetails.OPTIONS_RETRY, String.valueOf(RETRIES)); details.setProperty(BrokerDetails.OPTIONS_CONNECT_DELAY, String.valueOf(DELAY)); - connnection = new AMQConnection(connectionURL, null); + connection = new AMQConnection(connectionURL, null); - ((AMQConnection) connnection).setConnectionListener(this); + ((AMQConnection) connection).setConnectionListener(this); //Start the connection - connnection.start(); + connection.start(); long FAILOVER_DELAY = (RETRIES * DELAY); @@ -247,6 +321,51 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener assertTrue("Failover did not take long enough", System.nanoTime() > failTime); } + + /** + * The idea is to run a failover test in a loop by failing over + * to the other broker each time. + */ + public void testFailoverInALoop() throws Exception + { + if (!CLUSTERED) + { + return; + } + + int iterations = Integer.getInteger("profile.failoverIterations",0); + boolean b = true; + int failingPort = getFailingPort(); + init(false, Session.AUTO_ACKNOWLEDGE); + for (int i=0; i < iterations; i++) + { + _logger.debug("==================================================================="); + _logger.debug("Failover In a loop : iteration number " + i); + _logger.debug("==================================================================="); + + runP2PFailover(numMessages, false,false, false); + startBroker(failingPort); + if (b) + { + failingPort = getFailingPort()-1; + b = false; + } + else + { + failingPort = getFailingPort()+1; + b = true; + } + setFailingPort(failingPort); + } + //To prevent any failover logic being initiaed when we shutdown the brokers. + connection.close(); + + // Shutdown the brokers + stopBroker(getFailingPort()); + stopBroker(b?getFailingPort()+1 : getFailingPort()-1); + + } + public void bytesSent(long count) { } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/ObjectMessageTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/ObjectMessageTest.java new file mode 100644 index 0000000000..001a40988b --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/ObjectMessageTest.java @@ -0,0 +1,136 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.test.client.message; + +import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.test.utils.QpidTestCase; + +import javax.jms.Connection; +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.ObjectMessage; +import javax.jms.Queue; +import javax.jms.Session; +import java.util.UUID; + +public class ObjectMessageTest extends QpidTestCase +{ + private Connection _connection; + private Session _session; + MessageConsumer _consumer; + MessageProducer _producer; + + public void setUp() throws Exception + { + super.setUp(); + + //Create Connection + _connection = getConnection(); + + //Create Queue + Queue queue = new AMQQueue("amq.direct", "queue"); + + //Create Session + _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + //Create Consumer + _consumer = _session.createConsumer(queue); + + //Create Producer + _producer = _session.createProducer(queue); + + _connection.start(); + } + + public void tearDown() throws Exception + { + //clean up + _connection.close(); + + super.tearDown(); + } + + public void testGetAndSend() throws JMSException + { + //Create Sample Message using UUIDs + UUID test = UUID.randomUUID(); + + ObjectMessage testMessage = _session.createObjectMessage(test); + + Object o = testMessage.getObject(); + + assertNotNull("Object was null", o); + + sendAndTest(testMessage, test); + } + + public void testSend() throws JMSException + { + //Create Sample Message using UUIDs + UUID test = UUID.randomUUID(); + + ObjectMessage testMessage = _session.createObjectMessage(test); + + sendAndTest(testMessage, test); + } + + public void testTostringAndSend() throws JMSException + { + //Create Sample Message using UUIDs + UUID test = UUID.randomUUID(); + + ObjectMessage testMessage = _session.createObjectMessage(test); + + assertNotNull("Object was null", testMessage.toString()); + + sendAndTest(testMessage, test); + } + + public void testSendNull() throws JMSException + { + + ObjectMessage testMessage = _session.createObjectMessage(null); + + assertNotNull("Object was null", testMessage.toString()); + + sendAndTest(testMessage, null); + } + + //***************** Helpers + + private void sendAndTest(ObjectMessage message, Object sent) throws JMSException + { + _producer.send(message); + + ObjectMessage receivedMessage = (ObjectMessage) _consumer.receive(1000); + + assertNotNull("Message was not received.", receivedMessage); + + UUID result = (UUID) receivedMessage.getObject(); + + assertEquals("First read: UUIDs were not equal", sent, result); + + result = (UUID) receivedMessage.getObject(); + + assertEquals("Second read: UUIDs were not equal", sent, result); + } +} diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java index 2a44c444e0..b185ec60a2 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java @@ -20,30 +20,34 @@ */ package org.apache.qpid.test.utils; -import org.apache.qpid.client.transport.TransportConnection; -import org.apache.qpid.server.registry.ApplicationRegistry; - import javax.jms.Connection; public class FailoverBaseCase extends QpidTestCase { - protected int FAILING_VM_PORT = 2; - protected int FAILING_PORT = 5673; + public static int FAILING_VM_PORT = 2; + public static int FAILING_PORT = 5673; + protected int failingPort; + private boolean failedOver = false; - private int getFailingPort() + public FailoverBaseCase() { if (_broker.equals(VM)) { - return FAILING_VM_PORT; + failingPort = FAILING_VM_PORT; } else { - return FAILING_PORT; + failingPort = FAILING_PORT; } } + + protected int getFailingPort() + { + return failingPort; + } protected void setUp() throws java.lang.Exception { @@ -67,10 +71,16 @@ public class FailoverBaseCase extends QpidTestCase public void tearDown() throws Exception { - if (!failedOver) + int port; + if (_broker.equals(VM)) { - stopBroker(getFailingPort()); + port = FAILING_VM_PORT; } + else + { + port = FAILING_PORT; + } + stopBroker(port); super.tearDown(); } @@ -90,4 +100,9 @@ public class FailoverBaseCase extends QpidTestCase throw new RuntimeException(e); } } + + protected void setFailingPort(int p) + { + failingPort = p; + } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java index eddd9ed538..00c1da69e9 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java @@ -229,11 +229,13 @@ public class QpidTestCase extends TestCase private LineNumberReader in; private String ready; private CountDownLatch latch; + private boolean seenReady; public Piper(InputStream in, String ready) { this.in = new LineNumberReader(new InputStreamReader(in)); this.ready = ready; + this.seenReady = false; if (this.ready != null && !this.ready.equals("")) { this.latch = new CountDownLatch(1); @@ -257,7 +259,8 @@ public class QpidTestCase extends TestCase } else { - return latch.await(timeout, unit); + latch.await(timeout, unit); + return seenReady; } } @@ -271,6 +274,7 @@ public class QpidTestCase extends TestCase System.out.println(line); if (latch != null && line.contains(ready)) { + seenReady = true; latch.countDown(); } } diff --git a/qpid/java/test-provider.properties b/qpid/java/test-provider.properties index 8066256f4f..5e2ab9c9cf 100644 --- a/qpid/java/test-provider.properties +++ b/qpid/java/test-provider.properties @@ -23,7 +23,7 @@ connectionfactory.default = amqp://username:password@clientid/test?brokerlist='t connectionfactory.default.vm = amqp://username:password@clientid/test?brokerlist='vm://:1' connectionfactory.ssl = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5671?ssl='true'' -connectionfactory.failover = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5673;tcp://localhost:5672' +connectionfactory.failover = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5673;tcp://localhost:5672'&sync_ack='true'&sync_publish='all'&failover='roundrobin?cyclecount='20'' connectionfactory.failover.vm = amqp://username:password@clientid/test?brokerlist='vm://:2;vm://:1' connectionfactory.connection1 = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5672' connectionfactory.connection2 = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5673' diff --git a/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java b/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java index 4bba7b113d..9770adceb0 100644 --- a/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java +++ b/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java @@ -696,6 +696,8 @@ public class QpidBench public void opened(org.apache.qpid.transport.Session ssn) {} + public void resumed(org.apache.qpid.transport.Session ssn) {} + public void exception(org.apache.qpid.transport.Session ssn, SessionException exc) { diff --git a/qpid/python/commands/qpid-cluster b/qpid/python/commands/qpid-cluster index 2928ba65ea..4bc40e5abc 100755 --- a/qpid/python/commands/qpid-cluster +++ b/qpid/python/commands/qpid-cluster @@ -56,6 +56,9 @@ def Usage (): class IpAddr: def __init__(self, text): + if text.find("@") != -1: + tokens = text.split("@") + text = tokens[1] if text.find(":") != -1: tokens = text.split(":") text = tokens[0] diff --git a/qpid/python/commands/qpid-config b/qpid/python/commands/qpid-config index a7d537edb5..4a6129a153 100755 --- a/qpid/python/commands/qpid-config +++ b/qpid/python/commands/qpid-config @@ -211,7 +211,7 @@ class BrokerManager: if POLICY_TYPE in args: print "--limit-policy=%s" % args[POLICY_TYPE].replace("_", "-"), if LVQ in args and args[LVQ] == 1: print "--order lvq", if LVQNB in args and args[LVQNB] == 1: print "--order lvq-no-browse", - if QUEUE_EVENT_GENERATION in args: print "--generate-queue-events=%d" % args[GENERATE_QUEUE_EVENTS], + if QUEUE_EVENT_GENERATION in args: print "--generate-queue-events=%d" % args[QUEUE_EVENT_GENERATION], print def QueueListRecurse (self, filter): diff --git a/qpid/python/commands/qpid-stat b/qpid/python/commands/qpid-stat new file mode 100755 index 0000000000..9d41f4e966 --- /dev/null +++ b/qpid/python/commands/qpid-stat @@ -0,0 +1,449 @@ +#!/usr/bin/env python + +# +# 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. +# + +import os +import getopt +import sys +import locale +import socket +import re +from qmf.console import Session, Console +from qpid.disp import Display, Header, Sorter + +_host = "localhost" +_top = False +_types = "" +_limit = 50 +_increasing = False +_sortcol = None +pattern = re.compile("^\\d+\\.\\d+\\.\\d+\\.\\d+:\\d+$") + +def Usage (): + print "Usage: qpid-stat [OPTIONS] [broker-addr]" + print + print " broker-addr is in the form: [username/password@] hostname | ip-address [:]" + print " ex: localhost, 10.1.1.7:10000, broker-host:10000, guest/guest@localhost" + print +# print "General Options:" +# print " -n [--numeric] Don't resolve names" +# print " -t [--top] Repeatedly display top items" +# print + print "Display Options:" + print + print " -b Show Brokers" + print " -c Show Connections" +# print " -s Show Sessions" + print " -e Show Exchanges" + print " -q Show Queues" + print + print " -S [--sort-by] COLNAME Sort by column name" + print " -I [--increasing] Sort by increasing value (default = decreasing)" + print " -L [--limit] NUM Limit output to NUM rows (default = 50)" + print + sys.exit (1) + +class IpAddr: + def __init__(self, text): + if text.find("@") != -1: + tokens = text.split("@") + text = tokens[1] + if text.find(":") != -1: + tokens = text.split(":") + text = tokens[0] + self.port = int(tokens[1]) + else: + self.port = 5672 + self.dottedQuad = socket.gethostbyname(text) + nums = self.dottedQuad.split(".") + self.addr = (int(nums[0]) << 24) + (int(nums[1]) << 16) + (int(nums[2]) << 8) + int(nums[3]) + + def bestAddr(self, addrPortList): + bestDiff = 0xFFFFFFFF + bestAddr = None + for addrPort in addrPortList: + diff = IpAddr(addrPort[0]).addr ^ self.addr + if diff < bestDiff: + bestDiff = diff + bestAddr = addrPort + return bestAddr + +class Broker(object): + def __init__(self, qmf, broker): + self.broker = broker + bobj = qmf.getObjects(_class="broker", _package="org.apache.qpid.broker", _broker=broker)[0] + self.currentTime = bobj.getTimestamps()[0] + try: + self.uptime = bobj.uptime + except: + self.uptime = 0 + self.connections = {} + self.sessions = {} + self.exchanges = {} + self.queues = {} + package = "org.apache.qpid.broker" + + list = qmf.getObjects(_class="connection", _package=package, _broker=broker) + for conn in list: + if pattern.match(conn.address): + self.connections[conn.getObjectId()] = conn + + list = qmf.getObjects(_class="session", _package=package, _broker=broker) + for sess in list: + if sess.connectionRef in self.connections: + self.sessions[sess.getObjectId()] = sess + + list = qmf.getObjects(_class="exchange", _package=package, _broker=broker) + for exchange in list: + self.exchanges[exchange.getObjectId()] = exchange + + list = qmf.getObjects(_class="queue", _package=package, _broker=broker) + for queue in list: + self.queues[queue.getObjectId()] = queue + + def getName(self): + return self.broker.getUrl() + + def getCurrentTime(self): + return self.currentTime + + def getUptime(self): + return self.uptime + +class BrokerManager(Console): + def __init__(self): + self.brokerName = None + self.qmf = None + self.broker = None + self.brokers = [] + self.cluster = None + + def SetBroker(self, brokerUrl): + self.url = brokerUrl + self.qmf = Session() + self.broker = self.qmf.addBroker(brokerUrl) + agents = self.qmf.getAgents() + for a in agents: + if a.getAgentBank() == 0: + self.brokerAgent = a + + def Disconnect(self): + if self.broker: + self.qmf.delBroker(self.broker) + + def _getCluster(self): + packages = self.qmf.getPackages() + if "org.apache.qpid.cluster" not in packages: + return None + + clusters = self.qmf.getObjects(_class="cluster", _agent=self.brokerAgent) + if len(clusters) == 0: + print "Clustering is installed but not enabled on the broker." + return None + + self.cluster = clusters[0] + + def _getHostList(self, urlList): + hosts = [] + hostAddr = IpAddr(_host) + for url in urlList: + if url.find("amqp:") != 0: + raise Exception("Invalid URL 1") + url = url[5:] + addrs = str(url).split(",") + addrList = [] + for addr in addrs: + tokens = addr.split(":") + if len(tokens) != 3: + raise Exception("Invalid URL 2") + addrList.append((tokens[1], tokens[2])) + + # Find the address in the list that is most likely to be in the same subnet as the address + # with which we made the original QMF connection. This increases the probability that we will + # be able to reach the cluster member. + + best = hostAddr.bestAddr(addrList) + bestUrl = best[0] + ":" + best[1] + hosts.append(bestUrl) + return hosts + + def displaySubs(self, subs, indent, broker=None, conn=None, sess=None, exchange=None, queue=None): + if len(subs) == 0: + return + this = subs[0] + remaining = subs[1:] + newindent = indent + " " + if this == 'b': + pass + elif this == 'c': + if broker: + for oid in broker.connections: + iconn = broker.connections[oid] + self.printConnSub(indent, broker.getName(), iconn) + self.displaySubs(remaining, newindent, broker=broker, conn=iconn, + sess=sess, exchange=exchange, queue=queue) + elif this == 's': + pass + elif this == 'e': + pass + elif this == 'q': + pass + print + + def displayBroker(self, subs): + disp = Display(prefix=" ") + heads = [] + heads.append(Header('broker')) + heads.append(Header('cluster')) + heads.append(Header('uptime', Header.DURATION)) + heads.append(Header('conn', Header.KMG)) + heads.append(Header('sess', Header.KMG)) + heads.append(Header('exch', Header.KMG)) + heads.append(Header('queue', Header.KMG)) + rows = [] + for broker in self.brokers: + if self.cluster: + ctext = "%s(%s)" % (self.cluster.clusterName, self.cluster.status) + else: + ctext = "" + row = (broker.getName(), ctext, broker.getUptime(), + len(broker.connections), len(broker.sessions), + len(broker.exchanges), len(broker.queues)) + rows.append(row) + title = "Brokers" + if _sortcol: + sorter = Sorter(heads, rows, _sortcol, _limit, _increasing) + dispRows = sorter.getSorted() + else: + dispRows = rows + disp.formattedTable(title, heads, dispRows) + + def displayConn(self, subs): + disp = Display(prefix=" ") + heads = [] + if self.cluster: + heads.append(Header('broker')) + heads.append(Header('client-addr')) + heads.append(Header('cproc')) + heads.append(Header('cpid')) + heads.append(Header('auth')) + heads.append(Header('connected', Header.DURATION)) + heads.append(Header('idle', Header.DURATION)) + heads.append(Header('msgIn', Header.KMG)) + heads.append(Header('msgOut', Header.KMG)) + rows = [] + for broker in self.brokers: + for oid in broker.connections: + conn = broker.connections[oid] + row = [] + if self.cluster: + row.append(broker.getName()) + row.append(conn.address) + row.append(conn.remoteProcessName) + row.append(conn.remotePid) + row.append(conn.authIdentity) + row.append(broker.getCurrentTime() - conn.getTimestamps()[1]) + idle = broker.getCurrentTime() - conn.getTimestamps()[0] + row.append(broker.getCurrentTime() - conn.getTimestamps()[0]) + row.append(conn.framesFromClient) + row.append(conn.framesToClient) + rows.append(row) + title = "Connections" + if self.cluster: + title += " for cluster '%s'" % self.cluster.clusterName + if _sortcol: + sorter = Sorter(heads, rows, _sortcol, _limit, _increasing) + dispRows = sorter.getSorted() + else: + dispRows = rows + disp.formattedTable(title, heads, dispRows) + + def displaySession(self, subs): + disp = Display(prefix=" ") + + def displayExchange(self, subs): + disp = Display(prefix=" ") + heads = [] + if self.cluster: + heads.append(Header('broker')) + heads.append(Header("exchange")) + heads.append(Header("type")) + heads.append(Header("dur", Header.Y)) + heads.append(Header("bind", Header.KMG)) + heads.append(Header("msgIn", Header.KMG)) + heads.append(Header("msgOut", Header.KMG)) + heads.append(Header("msgDrop", Header.KMG)) + heads.append(Header("byteIn", Header.KMG)) + heads.append(Header("byteOut", Header.KMG)) + heads.append(Header("byteDrop", Header.KMG)) + rows = [] + for broker in self.brokers: + for oid in broker.exchanges: + ex = broker.exchanges[oid] + row = [] + if self.cluster: + row.append(broker.getName()) + row.append(ex.name) + row.append(ex.type) + row.append(ex.durable) + row.append(ex.bindingCount) + row.append(ex.msgReceives) + row.append(ex.msgRoutes) + row.append(ex.msgDrops) + row.append(ex.byteReceives) + row.append(ex.byteRoutes) + row.append(ex.byteDrops) + rows.append(row) + title = "Exchanges" + if self.cluster: + title += " for cluster '%s'" % self.cluster.clusterName + if _sortcol: + sorter = Sorter(heads, rows, _sortcol, _limit, _increasing) + dispRows = sorter.getSorted() + else: + dispRows = rows + disp.formattedTable(title, heads, dispRows) + + def displayQueue(self, subs): + disp = Display(prefix=" ") + heads = [] + if self.cluster: + heads.append(Header('broker')) + heads.append(Header("queue")) + heads.append(Header("dur", Header.Y)) + heads.append(Header("autoDel", Header.Y)) + heads.append(Header("excl", Header.Y)) + heads.append(Header("msg", Header.KMG)) + heads.append(Header("msgIn", Header.KMG)) + heads.append(Header("msgOut", Header.KMG)) + heads.append(Header("bytes", Header.KMG)) + heads.append(Header("bytesIn", Header.KMG)) + heads.append(Header("bytesOut", Header.KMG)) + heads.append(Header("cons", Header.KMG)) + heads.append(Header("bind", Header.KMG)) + rows = [] + for broker in self.brokers: + for oid in broker.queues: + q = broker.queues[oid] + row = [] + if self.cluster: + row.append(broker.getName()) + row.append(q.name) + row.append(q.durable) + row.append(q.autoDelete) + row.append(q.exclusive) + row.append(q.msgDepth) + row.append(q.msgTotalEnqueues) + row.append(q.msgTotalDequeues) + row.append(q.byteDepth) + row.append(q.byteTotalEnqueues) + row.append(q.byteTotalDequeues) + row.append(q.consumerCount) + row.append(q.bindingCount) + rows.append(row) + title = "Queues" + if self.cluster: + title += " for cluster '%s'" % self.cluster.clusterName + if _sortcol: + sorter = Sorter(heads, rows, _sortcol, _limit, _increasing) + dispRows = sorter.getSorted() + else: + dispRows = rows + disp.formattedTable(title, heads, dispRows) + + def displayMain(self, main, subs): + if main == 'b': self.displayBroker(subs) + elif main == 'c': self.displayConn(subs) + elif main == 's': self.displaySession(subs) + elif main == 'e': self.displayExchange(subs) + elif main == 'q': self.displayQueue(subs) + + def display(self): + self._getCluster() + if self.cluster: + memberList = self.cluster.members.split(";") + hostList = self._getHostList(memberList) + self.qmf.delBroker(self.broker) + self.broker = None + for host in hostList: + b = self.qmf.addBroker(host) + self.brokers.append(Broker(self.qmf, b)) + else: + self.brokers.append(Broker(self.qmf, self.broker)) + + self.displayMain(_types[0], _types[1:]) + + +## +## Main Program +## + +try: + longOpts = ("top", "numeric", "sort-by=", "limit=", "increasing") + (optlist, encArgs) = getopt.gnu_getopt(sys.argv[1:], "bceqS:L:I", longOpts) +except: + Usage() + +try: + encoding = locale.getpreferredencoding() + cargs = [a.decode(encoding) for a in encArgs] +except: + cargs = encArgs + +for opt in optlist: + if opt[0] == "-t" or opt[0] == "--top": + _top = True + elif opt[0] == "-n" or opt[0] == "--numeric": + _numeric = True + elif opt[0] == "-S" or opt[0] == "--sort-by": + _sortcol = opt[1] + elif opt[0] == "-I" or opt[0] == "--increasing": + _increasing = True + elif opt[0] == "-L" or opt[0] == "--limit": + _limit = int(opt[1]) + elif len(opt[0]) == 2: + char = opt[0][1] + if "bcseq".find(char) != -1: + _types += char + else: + Usage() + else: + Usage() + +if len(_types) == 0: + Usage() + +nargs = len(cargs) +bm = BrokerManager() + +if nargs == 1: + _host = cargs[0] + +try: + bm.SetBroker(_host) + bm.display() +except KeyboardInterrupt: + print +except Exception,e: + print "Failed:", e.args + #raise # TODO: Remove before flight + sys.exit(1) + +bm.Disconnect() diff --git a/qpid/python/qmf/console.py b/qpid/python/qmf/console.py index 39ef157f82..541ba8724f 100644 --- a/qpid/python/qmf/console.py +++ b/qpid/python/qmf/console.py @@ -28,7 +28,7 @@ import re from qpid.peer import Closed from qpid.session import SessionDetached from qpid.connection import Connection, ConnectionFailed -from qpid.datatypes import UUID, uuid4, Message, RangedSet +from qpid.datatypes import Message, RangedSet from qpid.util import connect, ssl, URL from qpid.codec010 import StringCodec as Codec from threading import Lock, Condition, Thread @@ -415,7 +415,7 @@ class Session: self.console.brokerDisconnected(broker) def _handleBrokerResp(self, broker, codec, seq): - broker.brokerId = UUID(codec.read_uuid()) + broker.brokerId = codec.read_uuid() if self.console != None: self.console.brokerInfo(broker) @@ -616,7 +616,7 @@ class Session: elif typecode == 11: data = codec.read_uint8() != 0 # BOOL elif typecode == 12: data = codec.read_float() # FLOAT elif typecode == 13: data = codec.read_double() # DOUBLE - elif typecode == 14: data = UUID(codec.read_uuid()) # UUID + elif typecode == 14: data = codec.read_uuid() # UUID elif typecode == 15: data = codec.read_map() # FTABLE elif typecode == 16: data = codec.read_int8() # S8 elif typecode == 17: data = codec.read_int16() # S16 diff --git a/qpid/python/qpid/codec010.py b/qpid/python/qpid/codec010.py index f34025ef17..f07362c38d 100644 --- a/qpid/python/qpid/codec010.py +++ b/qpid/python/qpid/codec010.py @@ -19,7 +19,7 @@ import datetime from packer import Packer -from datatypes import serial, timestamp, RangedSet, Struct +from datatypes import serial, timestamp, RangedSet, Struct, UUID class CodecException(Exception): pass @@ -118,6 +118,8 @@ class Codec(Packer): def read_vbin8(self): return self.read(self.read_uint8()) def write_vbin8(self, b): + if isinstance(b, buffer): + b = str(b) self.write_uint8(len(b)) self.write(b) @@ -131,10 +133,17 @@ class Codec(Packer): def write_str16(self, s): self.write_vbin16(s.encode("utf8")) + def read_str16_latin(self): + return self.read_vbin16().decode("iso-8859-15") + def write_str16_latin(self, s): + self.write_vbin16(s.encode("iso-8859-15")) + def read_vbin16(self): return self.read(self.read_uint16()) def write_vbin16(self, b): + if isinstance(b, buffer): + b = str(b) self.write_uint16(len(b)) self.write(b) @@ -158,6 +167,8 @@ class Codec(Packer): def read_vbin32(self): return self.read(self.read_uint32()) def write_vbin32(self, b): + if isinstance(b, buffer): + b = str(b) self.write_uint32(len(b)) self.write(b) @@ -166,7 +177,7 @@ class Codec(Packer): if m is not None: sc.write_uint32(len(m)) for k, v in m.items(): - type = self.spec.encoding(v.__class__) + type = self.spec.encoding(v) if type == None: raise CodecException("no encoding for %s" % v.__class__) sc.write_str8(k) @@ -191,9 +202,9 @@ class Codec(Packer): sc = StringCodec(self.spec) if a is not None: if len(a) > 0: - type = self.spec.encoding(a[0].__class__) + type = self.spec.encoding(a[0]) else: - type = self.spec.encoding(None.__class__) + type = self.spec.encoding(None) sc.write_uint8(type.code) sc.write_uint32(len(a)) for o in a: @@ -216,7 +227,7 @@ class Codec(Packer): if l is not None: sc.write_uint32(len(l)) for o in l: - type = self.spec.encoding(o.__class__) + type = self.spec.encoding(o) sc.write_uint8(type.code) type.encode(sc, o) self.write_vbin32(sc.encoded) @@ -273,9 +284,11 @@ class Codec(Packer): getattr(self, attr)(n) def read_uuid(self): - return self.unpack("16s") + return UUID(self.unpack("16s")) def write_uuid(self, s): + if isinstance(s, UUID): + s = s.bytes self.pack("16s", s) def read_bin128(self): diff --git a/qpid/python/qpid/datatypes.py b/qpid/python/qpid/datatypes.py index eb1f86b0b0..532995e051 100644 --- a/qpid/python/qpid/datatypes.py +++ b/qpid/python/qpid/datatypes.py @@ -289,7 +289,8 @@ class UUID: def __cmp__(self, other): if isinstance(other, UUID): return cmp(self.bytes, other.bytes) - raise NotImplemented() + else: + return -1 def __str__(self): return "%08x-%04x-%04x-%04x-%04x%08x" % struct.unpack("!LHHHHL", self.bytes) diff --git a/qpid/python/qpid/disp.py b/qpid/python/qpid/disp.py index e46cb33c60..1b315c9d98 100644 --- a/qpid/python/qpid/disp.py +++ b/qpid/python/qpid/disp.py @@ -21,16 +21,115 @@ from time import strftime, gmtime +class Header: + """ """ + NONE = 1 + KMG = 2 + YN = 3 + Y = 4 + TIME_LONG = 5 + TIME_SHORT = 6 + DURATION = 7 + + def __init__(self, text, format=NONE): + self.text = text + self.format = format + + def __repr__(self): + return self.text + + def __str__(self): + return self.text + + def formatted(self, value): + try: + if value == None: + return '' + if self.format == Header.NONE: + return value + if self.format == Header.KMG: + return self.num(value) + if self.format == Header.YN: + if value: + return 'Y' + return 'N' + if self.format == Header.Y: + if value: + return 'Y' + return '' + if self.format == Header.TIME_LONG: + return strftime("%c", gmtime(value / 1000000000)) + if self.format == Header.TIME_SHORT: + return strftime("%X", gmtime(value / 1000000000)) + if self.format == Header.DURATION: + if value < 0: value = 0 + sec = value / 1000000000 + min = sec / 60 + hour = min / 60 + day = hour / 24 + result = "" + if day > 0: + result = "%dd " % day + if hour > 0 or result != "": + result += "%dh " % (hour % 24) + if min > 0 or result != "": + result += "%dm " % (min % 60) + result += "%ds" % (sec % 60) + return result + except: + return "?" + + def numCell(self, value, tag): + fp = float(value) / 1000. + if fp < 10.0: + return "%1.2f%c" % (fp, tag) + if fp < 100.0: + return "%2.1f%c" % (fp, tag) + return "%4d%c" % (value / 1000, tag) + + def num(self, value): + if value < 1000: + return "%4d" % value + if value < 1000000: + return self.numCell(value, 'k') + value /= 1000 + if value < 1000000: + return self.numCell(value, 'm') + value /= 1000 + return self.numCell(value, 'g') + + class Display: """ Display formatting for QPID Management CLI """ - def __init__ (self): - self.tableSpacing = 2 - self.tablePrefix = " " + def __init__(self, spacing=2, prefix=" "): + self.tableSpacing = spacing + self.tablePrefix = prefix self.timestampFormat = "%X" - def table (self, title, heads, rows): - """ Print a formatted table with autosized columns """ + def formattedTable(self, title, heads, rows): + fRows = [] + for row in rows: + fRow = [] + col = 0 + for cell in row: + fRow.append(heads[col].formatted(cell)) + col += 1 + fRows.append(fRow) + headtext = [] + for head in heads: + headtext.append(head.text) + self.table(title, headtext, fRows) + + def table(self, title, heads, rows): + """ Print a table with autosized columns """ + + # Pad the rows to the number of heads + for row in rows: + diff = len(heads) - len(row) + for idx in range(diff): + row.append("") + print title if len (rows) == 0: return @@ -77,3 +176,59 @@ class Display: def timestamp (self, nsec): """ Format a nanosecond-since-the-epoch timestamp for printing """ return strftime (self.timestampFormat, gmtime (nsec / 1000000000)) + + def duration(self, nsec): + if nsec < 0: nsec = 0 + sec = nsec / 1000000000 + min = sec / 60 + hour = min / 60 + day = hour / 24 + result = "" + if day > 0: + result = "%dd " % day + if hour > 0 or result != "": + result += "%dh " % (hour % 24) + if min > 0 or result != "": + result += "%dm " % (min % 60) + result += "%ds" % (sec % 60) + return result + +class Sortable: + """ """ + def __init__(self, row, sortIndex): + self.row = row + self.sortIndex = sortIndex + if sortIndex >= len(row): + raise Exception("sort index exceeds row boundary") + + def __cmp__(self, other): + return cmp(self.row[self.sortIndex], other.row[self.sortIndex]) + + def getRow(self): + return self.row + +class Sorter: + """ """ + def __init__(self, heads, rows, sortCol, limit=0, inc=True): + col = 0 + for head in heads: + if head.text == sortCol: + break + col += 1 + if col == len(heads): + raise Exception("sortCol '%s', not found in headers" % sortCol) + + list = [] + for row in rows: + list.append(Sortable(row, col)) + list.sort(reverse=not inc) + count = 0 + self.sorted = [] + for row in list: + self.sorted.append(row.getRow()) + count += 1 + if count == limit: + break + + def getSorted(self): + return self.sorted diff --git a/qpid/python/qpid/managementdata.py b/qpid/python/qpid/managementdata.py index 2fe85dbdf3..e1fd8d54eb 100644 --- a/qpid/python/qpid/managementdata.py +++ b/qpid/python/qpid/managementdata.py @@ -263,7 +263,7 @@ class ManagementData: else: return "True" elif typecode == 14: - return "%08x-%04x-%04x-%04x-%04x%08x" % struct.unpack ("!LHHHHL", value) + return str (value) elif typecode == 15: return str (value) return "*type-error*" diff --git a/qpid/python/qpid/spec010.py b/qpid/python/qpid/spec010.py index cbc85a5e8b..13a64d7db6 100644 --- a/qpid/python/qpid/spec010.py +++ b/qpid/python/qpid/spec010.py @@ -467,19 +467,31 @@ class Exception(Named, Node): node.exceptions.append(self) Node.register(self) +def direct(t): + return lambda x: t + +def map_str(s): + for c in s: + if ord(c) >= 0x80: + return "vbin16" + return "str16" + class Spec(Node): ENCODINGS = { - basestring: "vbin16", - int: "int64", - long: "int64", - float: "float", - None.__class__: "void", - list: "list", - tuple: "list", - dict: "map", - datatypes.timestamp: "datetime", - datetime.datetime: "datetime" + unicode: direct("str16"), + str: map_str, + buffer: direct("vbin32"), + int: direct("int64"), + long: direct("int64"), + float: direct("float"), + None.__class__: direct("void"), + list: direct("list"), + tuple: direct("list"), + dict: direct("map"), + datatypes.timestamp: direct("datetime"), + datetime.datetime: direct("datetime"), + datatypes.UUID: direct("uuid") } def __init__(self, major, minor, port, children): @@ -500,11 +512,14 @@ class Spec(Node): self.structs_by_name = {} self.enums = {} - def encoding(self, klass): + def encoding(self, obj): + return self._encoding(obj.__class__, obj) + + def _encoding(self, klass, obj): if Spec.ENCODINGS.has_key(klass): - return self.named[Spec.ENCODINGS[klass]] + return self.named[Spec.ENCODINGS[klass](obj)] for base in klass.__bases__: - result = self.encoding(base) + result = self._encoding(base, obj) if result != None: return result diff --git a/qpid/python/tests/codec010.py b/qpid/python/tests/codec010.py index 1912eac591..a1f89dc3f4 100644 --- a/qpid/python/tests/codec010.py +++ b/qpid/python/tests/codec010.py @@ -23,7 +23,7 @@ from unittest import TestCase from qpid.spec010 import load from qpid.codec010 import StringCodec from qpid.testlib import testrunner -from qpid.datatypes import timestamp +from qpid.datatypes import timestamp, uuid4 class CodecTest(TestCase): @@ -42,6 +42,17 @@ class CodecTest(TestCase): def testMapString(self): self.check("map", {"string": "this is a test"}) + def testMapUnicode(self): + self.check("map", {"unicode": u"this is a unicode test"}) + + def testMapBinary(self): + self.check("map", {"binary": "\x7f\xb4R^\xe5\xf0:\x89\x96E1\xf6\xfe\xb9\x1b\xf5"}) + + def testMapBuffer(self): + s = "\x7f\xb4R^\xe5\xf0:\x89\x96E1\xf6\xfe\xb9\x1b\xf5" + dec = self.check("map", {"buffer": buffer(s)}, False) + assert dec["buffer"] == s + def testMapInt(self): self.check("map", {"int": 3}) @@ -68,14 +79,20 @@ class CodecTest(TestCase): def testMapList(self): self.check("map", {"list": [1, "two", 3.0, -4]}) + def testMapUUID(self): + self.check("map", {"uuid": uuid4()}) + def testMapAll(self): decoded = self.check("map", {"string": "this is a test", + "unicode": u"this is a unicode test", + "binary": "\x7f\xb4R^\xe5\xf0:\x89\x96E1\xf6\xfe\xb9\x1b\xf5", "int": 3, "long": 2**32, "timestamp": timestamp(0), "none": None, "map": {"string": "nested map"}, - "list": [1, "two", 3.0, -4]}) + "list": [1, "two", 3.0, -4], + "uuid": uuid4()}) assert isinstance(decoded["timestamp"], timestamp) def testMapEmpty(self): diff --git a/qpid/python/tests_0-10/message.py b/qpid/python/tests_0-10/message.py index cbcef5602f..f2e2dc88ee 100644 --- a/qpid/python/tests_0-10/message.py +++ b/qpid/python/tests_0-10/message.py @@ -462,6 +462,42 @@ class MessageTests(TestBase010): self.assertDataEquals(session, q.get(timeout = 1), "abcdefgh") self.assertEmpty(q) + def test_window_flush_ack_flow(self): + """ + Test basic window based flow control with unit = bytes + """ + #declare an exclusive queue + ssn = self.session + ssn.queue_declare(queue = "q", exclusive=True, auto_delete=True) + #create consumer + ssn.message_subscribe(queue = "q", destination = "c", + accept_mode=ssn.accept_mode.explicit) + ssn.message_set_flow_mode(flow_mode = ssn.flow_mode.window, destination = "c") + + #send message A + ssn.message_transfer(message=Message(ssn.delivery_properties(routing_key="q"), "A")) + + for unit in ssn.credit_unit.values(): + ssn.message_flow("c", unit, 0xFFFFFFFFL) + + q = ssn.incoming("c") + msgA = q.get(timeout=10) + + ssn.message_flush(destination="c") + + # XXX + ssn.receiver._completed.add(msgA.id) + ssn.channel.session_completed(ssn.receiver._completed) + ssn.message_accept(RangedSet(msgA.id)) + + for unit in ssn.credit_unit.values(): + ssn.message_flow("c", unit, 0xFFFFFFFFL) + + #send message B + ssn.message_transfer(message=Message(ssn.delivery_properties(routing_key="q"), "B")) + + msgB = q.get(timeout=10) + def test_subscribe_not_acquired(self): """ Test the not-acquired modes works as expected for a simple case diff --git a/qpid/ruby/Makefile b/qpid/ruby/Makefile new file mode 100644 index 0000000000..9cac3207c0 --- /dev/null +++ b/qpid/ruby/Makefile @@ -0,0 +1,47 @@ +# +# 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. +# + +SASL_DIR = ext/sasl +SASL_MODULE = $(SASL_DIR)/sasl.so +RUBY_LIB = lib +SPEC_CACHE_SCRIPT = sc.rb + +.PHONY: spec_cache all clean distclean + +all : build + +$(SASL_MODULE) : $(SASL_DIR)/sasl.c + cd $(SASL_DIR); ruby extconf.rb + $(MAKE) -C $(SASL_DIR) + +spec_cache : + echo "require 'qpid'" > $(SPEC_CACHE_SCRIPT) + echo "Qpid::Spec010::load()" >> $(SPEC_CACHE_SCRIPT) + ruby -I $(RUBY_LIB) -I $(SASL_DIR) $(SPEC_CACHE_SCRIPT) + rm $(SPEC_CACHE_SCRIPT) + +build: $(SASL_MODULE) spec_cache + +clean: + cd $(SASL_DIR); make clean + +distclean: + cd $(SASL_DIR); make distclean + rm -rf $(RUBY_LIB)/qpid/spec_cache + diff --git a/qpid/specs/management-schema.xml b/qpid/specs/management-schema.xml index 67c90a1fbe..bc38350a45 100644 --- a/qpid/specs/management-schema.xml +++ b/qpid/specs/management-schema.xml @@ -70,6 +70,7 @@ + -- cgit v1.2.1