From bfa255f4fd7a67f1433b424913515633d7e58c2f Mon Sep 17 00:00:00 2001 From: Arnaud Simon Date: Thu, 9 Oct 2008 15:09:08 +0000 Subject: QPID-1335: moved Qman into java/management/client git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@703177 13f79535-47bb-0310-9956-ffa450edef68 --- java/build.deps | 4 +- .../java/org/apache/qpid/management/Constants.java | 32 - .../java/org/apache/qpid/management/Names.java | 52 -- .../java/org/apache/qpid/management/Protocol.java | 34 - .../java/org/apache/qpid/management/config.xml | 106 --- .../configuration/AccessModeMapping.java | 94 --- .../configuration/AccessModeMappingParser.java | 74 -- .../configuration/BrokerConnectionData.java | 211 ----- .../configuration/BrokerConnectionDataParser.java | 133 ---- .../management/configuration/Configuration.java | 343 --------- .../configuration/ConfigurationException.java | 41 - .../management/configuration/Configurator.java | 145 ---- .../qpid/management/configuration/IParser.java | 44 -- .../ManagementQueueMessageListenerParser.java | 72 -- .../configuration/MessageHandlerMapping.java | 72 -- .../MethodReplyQueueMessageListenerParser.java | 72 -- .../management/configuration/QpidDatasource.java | 276 ------- .../apache/qpid/management/configuration/Tag.java | 42 - .../qpid/management/configuration/TypeMapping.java | 103 --- .../configuration/TypeMappingParser.java | 77 -- .../configuration/UnknownAccessCodeException.java | 53 -- .../configuration/UnknownBrokerException.java | 43 -- .../configuration/UnknownTypeCodeException.java | 53 -- .../domain/handler/base/BaseMessageHandler.java | 54 -- .../base/ContentIndicationMessageHandler.java | 116 --- .../domain/handler/base/IMessageHandler.java | 52 -- .../handler/impl/ConfigurationMessageHandler.java | 58 -- .../impl/InstrumentationMessageHandler.java | 58 -- .../impl/MethodOrEventDataTransferObject.java | 68 -- .../handler/impl/MethodResponseMessageHandler.java | 41 - .../handler/impl/SchemaResponseMessageHandler.java | 162 ---- .../qpid/management/domain/model/AccessMode.java | 33 - .../qpid/management/domain/model/Direction.java | 33 - .../qpid/management/domain/model/DomainModel.java | 174 ----- .../qpid/management/domain/model/IValidator.java | 38 - .../qpid/management/domain/model/JmxService.java | 158 ---- .../model/MissingFeatureAttributesException.java | 35 - .../qpid/management/domain/model/QpidArgument.java | 77 -- .../management/domain/model/QpidAttribute.java | 104 --- .../qpid/management/domain/model/QpidClass.java | 855 --------------------- .../qpid/management/domain/model/QpidEvent.java | 26 - .../qpid/management/domain/model/QpidFeature.java | 88 --- .../domain/model/QpidFeatureBuilder.java | 444 ----------- .../qpid/management/domain/model/QpidMethod.java | 103 --- .../qpid/management/domain/model/QpidPackage.java | 227 ------ .../qpid/management/domain/model/QpidProperty.java | 295 ------- .../management/domain/model/QpidStatistic.java | 34 - .../model/UnableToBuildFeatureException.java | 51 -- .../domain/model/ValidationException.java | 105 --- .../qpid/management/domain/model/type/AbsTime.java | 44 -- .../qpid/management/domain/model/type/Binary.java | 129 ---- .../qpid/management/domain/model/type/Boolean.java | 44 -- .../management/domain/model/type/DeltaTime.java | 44 -- .../qpid/management/domain/model/type/Map.java | 44 -- .../domain/model/type/ObjectReference.java | 44 -- .../qpid/management/domain/model/type/Str16.java | 44 -- .../qpid/management/domain/model/type/Str8.java | 44 -- .../qpid/management/domain/model/type/Type.java | 95 --- .../qpid/management/domain/model/type/Uint16.java | 44 -- .../qpid/management/domain/model/type/Uint32.java | 44 -- .../qpid/management/domain/model/type/Uint64.java | 44 -- .../qpid/management/domain/model/type/Uint8.java | 44 -- .../qpid/management/domain/model/type/Uuid.java | 46 -- .../domain/services/BrokerMessageListener.java | 181 ----- .../domain/services/ManagementClient.java | 256 ------ .../qpid/management/domain/services/QMan.java | 103 --- .../management/domain/services/QpidService.java | 270 ------- .../domain/services/StartupFailureException.java | 42 - .../org/apache/qpid/management/TestConstants.java | 48 -- .../configuration/AccessModeMappingTest.java | 107 --- .../configuration/ConfigurationTest.java | 237 ------ .../management/configuration/ConfiguratorTest.java | 112 --- .../configuration/MappingParsersTest.java | 201 ----- .../management/configuration/StubConfigurator.java | 56 -- .../management/configuration/TypeMappingTest.java | 117 --- .../base/ContentIndicationMessageHandlerTest.java | 120 --- .../domain/model/BaseDomainModelTestCase.java | 44 -- .../model/BaseQpidFeatureBuilderTestCase.java | 102 --- .../management/domain/model/DomainModelTest.java | 56 -- .../domain/model/OptionalPropertiesTest.java | 187 ----- .../domain/model/QpidMethodBuilderTest.java | 166 ---- .../domain/model/QpidNumberPropertyTest.java | 167 ---- .../management/domain/model/QpidPackageTest.java | 54 -- .../domain/model/QpidPropertyBuilderTest.java | 271 ------- .../domain/model/QpidStatisticBuilderTest.java | 159 ---- .../domain/model/QpidStringPropertyTest.java | 123 --- .../management/domain/model/type/BinaryTest.java | 59 -- .../java/org/apache/qpid/management/Constants.java | 32 + .../java/org/apache/qpid/management/Names.java | 52 ++ .../java/org/apache/qpid/management/Protocol.java | 34 + .../java/org/apache/qpid/management/config.xml | 106 +++ .../configuration/AccessModeMapping.java | 94 +++ .../configuration/AccessModeMappingParser.java | 74 ++ .../configuration/BrokerConnectionData.java | 211 +++++ .../configuration/BrokerConnectionDataParser.java | 133 ++++ .../management/configuration/Configuration.java | 343 +++++++++ .../configuration/ConfigurationException.java | 41 + .../management/configuration/Configurator.java | 145 ++++ .../qpid/management/configuration/IParser.java | 44 ++ .../ManagementQueueMessageListenerParser.java | 72 ++ .../configuration/MessageHandlerMapping.java | 72 ++ .../MethodReplyQueueMessageListenerParser.java | 72 ++ .../management/configuration/QpidDatasource.java | 276 +++++++ .../apache/qpid/management/configuration/Tag.java | 42 + .../qpid/management/configuration/TypeMapping.java | 103 +++ .../configuration/TypeMappingParser.java | 77 ++ .../configuration/UnknownAccessCodeException.java | 53 ++ .../configuration/UnknownBrokerException.java | 43 ++ .../configuration/UnknownTypeCodeException.java | 53 ++ .../domain/handler/base/BaseMessageHandler.java | 54 ++ .../base/ContentIndicationMessageHandler.java | 116 +++ .../domain/handler/base/IMessageHandler.java | 52 ++ .../handler/impl/ConfigurationMessageHandler.java | 58 ++ .../impl/InstrumentationMessageHandler.java | 58 ++ .../impl/MethodOrEventDataTransferObject.java | 68 ++ .../handler/impl/MethodResponseMessageHandler.java | 41 + .../handler/impl/SchemaResponseMessageHandler.java | 162 ++++ .../qpid/management/domain/model/AccessMode.java | 33 + .../qpid/management/domain/model/Direction.java | 33 + .../qpid/management/domain/model/DomainModel.java | 174 +++++ .../qpid/management/domain/model/IValidator.java | 38 + .../qpid/management/domain/model/JmxService.java | 158 ++++ .../model/MissingFeatureAttributesException.java | 35 + .../qpid/management/domain/model/QpidArgument.java | 77 ++ .../management/domain/model/QpidAttribute.java | 104 +++ .../qpid/management/domain/model/QpidClass.java | 855 +++++++++++++++++++++ .../qpid/management/domain/model/QpidEvent.java | 26 + .../qpid/management/domain/model/QpidFeature.java | 88 +++ .../domain/model/QpidFeatureBuilder.java | 444 +++++++++++ .../qpid/management/domain/model/QpidMethod.java | 103 +++ .../qpid/management/domain/model/QpidPackage.java | 227 ++++++ .../qpid/management/domain/model/QpidProperty.java | 295 +++++++ .../management/domain/model/QpidStatistic.java | 34 + .../model/UnableToBuildFeatureException.java | 51 ++ .../domain/model/ValidationException.java | 105 +++ .../qpid/management/domain/model/type/AbsTime.java | 44 ++ .../qpid/management/domain/model/type/Binary.java | 129 ++++ .../qpid/management/domain/model/type/Boolean.java | 44 ++ .../management/domain/model/type/DeltaTime.java | 44 ++ .../qpid/management/domain/model/type/Map.java | 44 ++ .../domain/model/type/ObjectReference.java | 44 ++ .../qpid/management/domain/model/type/Str16.java | 44 ++ .../qpid/management/domain/model/type/Str8.java | 44 ++ .../qpid/management/domain/model/type/Type.java | 95 +++ .../qpid/management/domain/model/type/Uint16.java | 44 ++ .../qpid/management/domain/model/type/Uint32.java | 44 ++ .../qpid/management/domain/model/type/Uint64.java | 44 ++ .../qpid/management/domain/model/type/Uint8.java | 44 ++ .../qpid/management/domain/model/type/Uuid.java | 46 ++ .../domain/services/BrokerMessageListener.java | 181 +++++ .../domain/services/ManagementClient.java | 256 ++++++ .../qpid/management/domain/services/QMan.java | 103 +++ .../management/domain/services/QpidService.java | 270 +++++++ .../domain/services/StartupFailureException.java | 42 + .../org/apache/qpid/management/TestConstants.java | 48 ++ .../configuration/AccessModeMappingTest.java | 107 +++ .../configuration/ConfigurationTest.java | 237 ++++++ .../management/configuration/ConfiguratorTest.java | 112 +++ .../configuration/MappingParsersTest.java | 201 +++++ .../management/configuration/StubConfigurator.java | 56 ++ .../management/configuration/TypeMappingTest.java | 117 +++ .../base/ContentIndicationMessageHandlerTest.java | 120 +++ .../domain/model/BaseDomainModelTestCase.java | 44 ++ .../model/BaseQpidFeatureBuilderTestCase.java | 102 +++ .../management/domain/model/DomainModelTest.java | 56 ++ .../domain/model/OptionalPropertiesTest.java | 187 +++++ .../domain/model/QpidMethodBuilderTest.java | 166 ++++ .../domain/model/QpidNumberPropertyTest.java | 167 ++++ .../management/domain/model/QpidPackageTest.java | 54 ++ .../domain/model/QpidPropertyBuilderTest.java | 271 +++++++ .../domain/model/QpidStatisticBuilderTest.java | 159 ++++ .../domain/model/QpidStringPropertyTest.java | 123 +++ .../management/domain/model/type/BinaryTest.java | 59 ++ 173 files changed, 9655 insertions(+), 9655 deletions(-) delete mode 100644 java/client/src/main/java/org/apache/qpid/management/Constants.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/Names.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/Protocol.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/config.xml delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMappingParser.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionDataParser.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/ConfigurationException.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/IParser.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/ManagementQueueMessageListenerParser.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/MessageHandlerMapping.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/MethodReplyQueueMessageListenerParser.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/QpidDatasource.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/Tag.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/TypeMappingParser.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/UnknownAccessCodeException.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/UnknownBrokerException.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/configuration/UnknownTypeCodeException.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/handler/base/BaseMessageHandler.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandler.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/handler/base/IMessageHandler.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/ConfigurationMessageHandler.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InstrumentationMessageHandler.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodOrEventDataTransferObject.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodResponseMessageHandler.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/SchemaResponseMessageHandler.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/AccessMode.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/Direction.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/DomainModel.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/IValidator.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/MissingFeatureAttributesException.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/QpidArgument.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/QpidAttribute.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/QpidClass.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/QpidEvent.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeature.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeatureBuilder.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/QpidMethod.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/QpidProperty.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/QpidStatistic.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/UnableToBuildFeatureException.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/ValidationException.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/AbsTime.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Boolean.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/DeltaTime.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Map.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/ObjectReference.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Str16.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Str8.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint16.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint32.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint64.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint8.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uuid.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/services/BrokerMessageListener.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java delete mode 100644 java/client/src/main/java/org/apache/qpid/management/domain/services/StartupFailureException.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/TestConstants.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPropertyBuilderTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/QpidStatisticBuilderTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/QpidStringPropertyTest.java delete mode 100644 java/client/src/test/java/org/apache/qpid/management/domain/model/type/BinaryTest.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/Constants.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/Names.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/Protocol.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/config.xml create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMappingParser.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionDataParser.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/ConfigurationException.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/IParser.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/ManagementQueueMessageListenerParser.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/MessageHandlerMapping.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/MethodReplyQueueMessageListenerParser.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/QpidDatasource.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/Tag.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMappingParser.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownAccessCodeException.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownBrokerException.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownTypeCodeException.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/BaseMessageHandler.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandler.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/IMessageHandler.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/ConfigurationMessageHandler.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InstrumentationMessageHandler.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodOrEventDataTransferObject.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodResponseMessageHandler.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/SchemaResponseMessageHandler.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/AccessMode.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/Direction.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/DomainModel.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/IValidator.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/MissingFeatureAttributesException.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidArgument.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidAttribute.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidClass.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidEvent.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeature.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeatureBuilder.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidMethod.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidProperty.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidStatistic.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/UnableToBuildFeatureException.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/ValidationException.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/AbsTime.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Boolean.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/DeltaTime.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Map.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/ObjectReference.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Str16.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Str8.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint16.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint32.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint64.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint8.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uuid.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/services/BrokerMessageListener.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java create mode 100644 java/management/client/src/main/java/org/apache/qpid/management/domain/services/StartupFailureException.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/TestConstants.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidPropertyBuilderTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidStatisticBuilderTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidStringPropertyTest.java create mode 100644 java/management/client/src/test/java/org/apache/qpid/management/domain/model/type/BinaryTest.java (limited to 'java') diff --git a/java/build.deps b/java/build.deps index 20ceda21f6..8db5fbcf7e 100644 --- a/java/build.deps +++ b/java/build.deps @@ -23,14 +23,14 @@ xalan=lib/xalan-2.7.0.jar osgi-core=lib/org.osgi.core-1.0.0.jar felix-framework=lib/org.apache.felix.framework-1.0.0.jar -commons-pool-libs=lib/commons-pool-1.4.jar + felix.libs=${osgi-core} ${felix-framework} common.libs=${slf4j-api} ${backport-util-concurrent} ${mina-core} \ ${mina-filter-ssl} ${commons-codec} ${commons-lang} ${commons-collections} \ ${commons-configuration} -client.libs=${common.libs} ${geronimo-jms} ${commons-pool-libs} +client.libs=${common.libs} ${geronimo-jms} tools.libs=${client.libs} broker.libs=${common.libs} ${commons-cli} ${commons-logging} ${log4j} \ ${slf4j-log4j} ${xalan} ${felix.libs} ${build.lib}/${project.name}-common-${project.version}.jar diff --git a/java/client/src/main/java/org/apache/qpid/management/Constants.java b/java/client/src/main/java/org/apache/qpid/management/Constants.java deleted file mode 100644 index 7be1bda776..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/Constants.java +++ /dev/null @@ -1,32 +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; - -/** - * Enumeration of literal values used to avoid code duplication. - * - * @author Andrea Gazzarini - */ -public interface Constants -{ - /** No expiration (used for timeout) */ - long NO_EXPIRATION = 0; -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/Names.java b/java/client/src/main/java/org/apache/qpid/management/Names.java deleted file mode 100644 index dde7715509..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/Names.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management; - -/** - * Enumeration of literal strings to avoid code duplication. - * - * @author Andrea Gazzarini - */ -public interface Names -{ - /** Name of the qpid management exchange. */ - String MANAGEMENT_EXCHANGE = "qpid.management"; - String MANAGEMENT_ROUTING_KEY = "console.#"; - - String MANAGEMENT_QUEUE_PREFIX = "management."; - String METHOD_REPLY_QUEUE_PREFIX = "reply."; - - String AMQ_DIRECT_QUEUE = "amq.direct"; - String AGENT_ROUTING_KEY = "agent.1.0"; - - String BROKER_ROUTING_KEY = "broker"; - - // Attributes - String PACKAGE = "package"; - String CLASS = "class"; - String OBJECT_ID="objectID"; - String BROKER_ID = "brokerID"; - String DOMAIN_NAME = "Q-MAN"; - - String CONFIGURATION_FILE_NAME = "/org/apache/qpid/management/config.xml"; - - String ARG_COUNT_PARAM_NAME = "argCount"; -} diff --git a/java/client/src/main/java/org/apache/qpid/management/Protocol.java b/java/client/src/main/java/org/apache/qpid/management/Protocol.java deleted file mode 100644 index 185f417448..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/Protocol.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management; - -/** - * Protocol defined constants. - * - * @author Andrea Gazzarini - */ -public interface Protocol -{ - String MAGIC_NUMBER = "AM2"; - - byte [] METHOD_REQUEST_FIRST_FOUR_BYTES = (MAGIC_NUMBER+"M").getBytes(); - byte [] SCHEMA_REQUEST_FIRST_FOUR_BYTES = (MAGIC_NUMBER+"S").getBytes(); -} diff --git a/java/client/src/main/java/org/apache/qpid/management/config.xml b/java/client/src/main/java/org/apache/qpid/management/config.xml deleted file mode 100644 index 590e33a0f7..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/config.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - i - org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler - - - c - org.apache.qpid.management.domain.handler.impl.ConfigurationMessageHandler - - - - - m - org.apache.qpid.management.domain.handler.impl.MethodResponseMessageHandler - - - s - org.apache.qpid.management.domain.handler.impl.SchemaResponseMessageHandler - - - - - - 1 - org.apache.qpid.management.domain.model.type.Uint8 - org.apache.qpid.management.domain.model.QpidProperty$NumberValidator - - - 2 - org.apache.qpid.management.domain.model.type.Uint16 - org.apache.qpid.management.domain.model.QpidProperty$NumberValidator - - - 3 - org.apache.qpid.management.domain.model.type.Uint32 - org.apache.qpid.management.domain.model.QpidProperty$NumberValidator - - - 4 - org.apache.qpid.management.domain.model.type.Uint64 - org.apache.qpid.management.domain.model.QpidProperty$NumberValidator - - - 6 - org.apache.qpid.management.domain.model.type.Str8 - org.apache.qpid.management.domain.model.QpidProperty$StringValidator - - - 7 - org.apache.qpid.management.domain.model.type.Str16 - org.apache.qpid.management.domain.model.QpidProperty$StringValidator - - - 8 - org.apache.qpid.management.domain.model.type.AbsTime - - - 9 - org.apache.qpid.management.domain.model.type.DeltaTime - - - 10 - org.apache.qpid.management.domain.model.type.ObjectReference - - - 11 - org.apache.qpid.management.domain.model.type.Boolean - - - 14 - org.apache.qpid.management.domain.model.type.Uuid - - - 15 - org.apache.qpid.management.domain.model.type.Map - - - - - 1 - RC - - - 2 - RW - - - 3 - RO - - - - - localhost - 5672 - test - guest - guest - 4 - 4 - -1 - - - diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java b/java/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java deleted file mode 100644 index 899462a648..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.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 int _code; - private AccessMode _accessMode; - - /** - * Sets the code for this mapping. - * Note that the given string must be a valid number (integer). - * - * @param codeAsString the code value as a string. - * @throws NumberFormatException when the given string is not a number. - */ - void setCode(String codeAsString) { - this._code = Integer.parseInt(codeAsString); - } - - /** - * Returns the access mode of this mapping. - * - * @return the access mode of this mapping. - */ - AccessMode getAccessMode () - { - return _accessMode; - } - - /** - * Sets the access mode for this mapping. - * Note that the given string must correspond to a valid access mode value (RW,RC, RO). - * - * @param accessModeAsString acces mode as a string. - * @throws IllegalArgumentException when the given string is not a valid access code. - */ - void setAccessMode (String accessModeAsString) - { - this._accessMode = AccessMode.valueOf(accessModeAsString); - } - - /** - * 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(); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMappingParser.java b/java/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMappingParser.java deleted file mode 100644 index d9dcbd12d3..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMappingParser.java +++ /dev/null @@ -1,74 +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; - -/** - * Parser used for building access mode mappings. - * For each access-mode-mappings/mapping element found in the configuration file, a new access mode mapping - * is built and injected into the configuration. - * - * - 1 - RC - - * - * @author Andrea Gazzarini - */ -class AccessModeMappingParser implements IParser -{ - private AccessModeMapping _mapping = new AccessModeMapping(); - private String _currentValue; - - /** - * Callback : the given value is the text content of the current node. - */ - public void setCurrrentAttributeValue (String value) - { - this._currentValue = value; - } - - /** - * Callback: each time the end of an element is reached this method is called. - * It's here that the built mapping is injected into the configuration. - */ - public void setCurrentAttributeName (String name) - { - switch (Tag.get(name)) - { - case CODE: - { - _mapping.setCode(_currentValue); - break; - } - case VALUE : - { - _mapping.setAccessMode(_currentValue); - break; - } - case MAPPING: - { - Configuration.getInstance().addAccessModeMapping(_mapping); - _mapping = new AccessModeMapping(); - break; - } - } - } -} diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java b/java/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java deleted file mode 100644 index 74e89ef19d..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java +++ /dev/null @@ -1,211 +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; - -/** - * Value object which is holding connection data for a specific broker. - * - * @author Andrea Gazzarini - */ -public class BrokerConnectionData -{ - private String _host; - private int _port; - private String _virtualHost; - private String _username; - private String _password; - private int _maxPoolCapacity; - private int _initialPoolCapacity; - private long _maxWaitTimeout; - - /** - * Builds a new empty broker connection data object. - */ - BrokerConnectionData() - { - } - - /** - * Sets the value of host property for this connection data. - * - * @param host the host name. - */ - void setHost (String host) - { - this._host = host; - } - - /** - * Sets the value of port property for this connection data. - * - * @param port the port. - */ - void setPort (String port) - { - this._port = Integer.parseInt(port); - } - - /** - * Sets the value of virtual host property for this connection data. - * - * @param virtualHost the virtual host. - */ - void setVirtualHost (String virtualHost) - { - this._virtualHost = virtualHost; - } - - /** - * Sets the value of username property for this connection data. - * - * @param username the username. - */ - void setUsername(String username) - { - this._username = username; - } - - /** - * Sets the value of password property for this connection data. - * - * @param password the password. - */ - void setPassword(String password) - { - this._password = password; - } - - /** - * Returns the value of the host property. - * - * @return the value of the host property. - */ - public String getHost () - { - return _host; - } - - /** - * Returns the value of the port property. - * - * @return the value of the port property. - */ - public int getPort () - { - return _port; - } - - /** - * Returns the value of the virtual host property. - * - * @return the value of the virtual host property. - */ - public String getVirtualHost () - { - return _virtualHost; - } - - /** - * Returns the value of the username property. - * - * @return the value of the username property. - */ - public String getUsername () - { - return _username; - } - - /** - * Returns the value of the password property. - * - * @return the value of the password property. - */ - public String getPassword () - { - return _password; - } - - // sofia:5663@pippo/sung1 - @Override - public String toString () - { - return new StringBuilder() - .append(_host) - .append(':') - .append(_port) - .append('@') - .append(_virtualHost) - .toString(); - } - - /** - * Sets the max number of allowed connections that can be opened. - * - * @param value the max number of allowed connections that can be opened. - * @throws NumberFormatException if the given value is not a valid integer. - */ - public void setMaxPoolCapacity (String value) - { - _maxPoolCapacity = Integer.parseInt(value); - } - - /** - * Sets the max wait timeout for retrieving an available connections from the pool. - * - * @param value the max wait timeout for retrieving an available connections from the pool.. - * @throws NumberFormatException if the given value is not a valid long. - */ - public void setMaxWaitTimeout (String value) - { - this._maxWaitTimeout = Long.parseLong(value); - } - - /** - * Returns the max number of allowed connections that can be opened. - * - * @return the max number of allowed connections that can be opened. - */ - public int getMaxPoolCapacity () - { - return _maxPoolCapacity; - } - - /** - * Returns the max wait timeout for retrieving an available connections from the pool. - * - * @return the max wait timeout for retrieving an available connections from the pool. - */ - public long getMaxWaitTimeout () - { - return _maxWaitTimeout; - } - - public void setInitialPoolCapacity (String value) - { - _initialPoolCapacity = Integer.parseInt(value); - } - - public int getInitialPoolCapacity () - { - return _initialPoolCapacity; - } - -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionDataParser.java b/java/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionDataParser.java deleted file mode 100644 index d76baed07f..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionDataParser.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.configuration; - -import java.util.UUID; - -import org.apache.qpid.transport.util.Logger; - -/** - * Parser used for building access mode mappings. - * For each access-mode-mappings/mapping element found in the configuration file, a new access mode mapping - * is built and injected into the bridge configuration. - * - * - 192.168.61.130 - 5673 - test - andrea - andrea - - * - * @author Andrea Gazzarini - */ -class BrokerConnectionDataParser implements IParser -{ - private final static Logger LOGGER = Logger.get(Configuration.class); - private BrokerConnectionData _connectionData = new BrokerConnectionData(); - private String _currentValue; - - /** - * Callback : the given value is the text content of the current node. - */ - public void setCurrrentAttributeValue (String value) - { - this._currentValue = value; - } - - /** - * Callback: each time the end of an element is reached this method is called. - * It's here that the built mapping is injected into the configuration. - * - 192.168.61.130 - 5673 - test - andrea - andrea - - */ - public void setCurrentAttributeName (String name) - { - switch (Tag.get(name)) - { - case HOST: - { - _connectionData.setHost(_currentValue); - break; - } - case PORT : - { - _connectionData.setPort(_currentValue); - break; - } - case VIRTUAL_HOST: - { - _connectionData.setVirtualHost(_currentValue); - break; - } - case USER : - { - _connectionData.setUsername(_currentValue); - break; - } - case MAX_POOL_CAPACITY: - { - _connectionData.setMaxPoolCapacity (_currentValue); - break; - } - case INITIAL_POOL_CAPACITY: - { - _connectionData.setInitialPoolCapacity(_currentValue); - break; - } - case MAX_WAIT_TIMEOUT: - { - _connectionData.setMaxWaitTimeout(_currentValue); - break; - } - case PASSWORD: - { - _connectionData.setPassword(_currentValue); - break; - } - case BROKER: - { - try - { - Configuration.getInstance().addBrokerConnectionData(getUUId(),_connectionData); - } catch(Exception exception) - { - LOGGER.error(exception, "Unable to connect with broker located on %s and. Hence this broker will be ignored.", _connectionData); - } - _connectionData = new BrokerConnectionData(); - break; - } - } - } - - /** - * Gets an uuid in order to associate current connection data with a broker. - * @return - */ - UUID getUUId(){ - return UUID.randomUUID(); - } -} diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java b/java/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java deleted file mode 100644 index cd39d330bb..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java +++ /dev/null @@ -1,343 +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 java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.Map.Entry; - -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.Type; -import org.apache.qpid.transport.DeliveryProperties; -import org.apache.qpid.transport.Header; -import org.apache.qpid.transport.MessageProperties; -import org.apache.qpid.transport.ReplyTo; -import org.apache.qpid.transport.util.Logger; - -/** - * Qpid Management bridge configuration. - * Basically iy is a singleton that is holding all the configurtion data loaded at startup. - * - * @author Andrea Gazzarini - */ -public final class Configuration -{ - private final static Logger LOGGER = Logger.get(Configuration.class); - private static Configuration INSTANCE = new Configuration(); - - Map _typeMappings = new HashMap(); - Map _accessModes = new HashMap(); - Map _validators = new HashMap(); - - Map _brokerConnectionInfos = new HashMap(); - - Map _managementQueueHandlers = new HashMap(); - Map _methodReplyQueueHandlers = new HashMap(); - - private String _managementQueueName; - private String _methodReplyQueueName; - - private Header _headerForCommandMessages; - - // Private constructor. - private Configuration() - { - defineQueueNames(); - createHeaderForCommandMessages(); - } - - /** - * Returns the singleton instance. - * - * @return the singleton instance. - */ - public static Configuration getInstance () - { - return INSTANCE; - } - - /** - * Returns the type associated to the given code. - * - * @param code the code used as search criteria. - * @return the type associated to the given code. - * @throws UnknownTypeCodeException when the given code is not associated to any type. - */ - public Type getType(int code) throws UnknownTypeCodeException - { - Type result = _typeMappings.get(code); - if (result == null) - { - throw new UnknownTypeCodeException(code); - } - return result; - } - - /** - * Returns the access mode associated to the given code. - * - * @param code the code used as search criteria. - * @return the access mode associated to the given code. - * @throws UnknownAccessCodeException when the given code is not associated to any access mode. - */ - public AccessMode getAccessMode(int code) throws UnknownAccessCodeException - { - AccessMode result = _accessModes.get(code); - if (result == null) - { - throw new UnknownAccessCodeException(code); - } - return result; - } - - /** - * Returns the validator class name associated to the given type. - * - * @param type the type. - * @return the validator class name associated to the given type. - */ - public String getValidatorClassName (Type type) - { - return _validators.get(type); - } - - /** - * Gets from this configuration the list of known broker (I mean, only their connection data). - * - * @return the list of known broker - */ - public Set> getConnectionInfos(){ - return _brokerConnectionInfos.entrySet(); - } - - /** - * Gets from this configuration the connection data of the broker associated with the given id. - * - * @param brokerId the broker identifier. - * @return the connection data of the broker associated with the given id. - * @throws UnknownBrokerException when the given id is not associated with any broker. - */ - public BrokerConnectionData getBrokerConnectionData (UUID brokerId) throws UnknownBrokerException - { - BrokerConnectionData connectionData = _brokerConnectionInfos.get(brokerId); - if (connectionData == null) - { - throw new UnknownBrokerException(brokerId); - } - return _brokerConnectionInfos.get(brokerId); - } - - /** - * Returns the name of the management queue. - * - * @return the name of the management queue. - */ - public String getManagementQueueName() { - return _managementQueueName; - } - - /** - * Returns the name of the method-reply queue. - * - * @return the name of the method-reply queue. - */ - public String getMethodReplyQueueName() { - return _methodReplyQueueName; - } - - /** - * Returns a map containing all the configured management message handlers. - * A management message handler it is a basically a processor for a management queue incoming message associated - * with a specific opcode. - * - * @return a map containing all the configured management message handlers. - */ - public Map getManagementQueueHandlers() - { - Map result = new HashMap(); - - for (Entry entry : _managementQueueHandlers.entrySet()) - { - Character opcode = entry.getKey(); - String className = entry.getValue(); - try - { - result.put(opcode, (IMessageHandler)Class.forName(className).newInstance()); - } catch(Exception exception) - { - LOGGER.error( - exception, - " : Management Message Handler configured for opcode %s is not available and therefore will be discarded.", - opcode); - } - } - return result; - } - - /** - * Returns a map containing all the configured method-reply message handlers. - * A management message handler it is a basically a processor for a method-reply queue incoming message associated - * with a specific opcode. - * - * @return a map containing all the configured method-reply message handlers. - */ - public Map getMethodReplyQueueHandlers() - { - Map result = new HashMap(); - - for (Entry entry : _methodReplyQueueHandlers.entrySet()) - { - Character opcode = entry.getKey(); - String className = entry.getValue(); - try - { - result.put(opcode, (IMessageHandler)Class.forName(className).newInstance()); - } catch(Exception exception) - { - LOGGER.error( - exception, - " :Method-Reply Message Handler configured for opcode %s is not available and therefore will be discarded.", - opcode); - } - } - return result; - } - - /** - * Returns the message header used for sending command message on management queue. - * - * @return the message header used for sending command message on management queue. - */ - public Header getCommandMessageHeader () - { - return _headerForCommandMessages; - } - - /** - * Adds a new type mapping to this configuration. - * - * @param mapping the type mapping that will be added. - */ - void addTypeMapping(TypeMapping mapping) { - int code = mapping.getCode(); - Type type = mapping.getType(); - String validatorClassName = mapping.getValidatorClassName(); - _typeMappings.put(code, type); - _validators.put(type, validatorClassName); - - LOGGER.info(" : Type mapping : code = %s associated to %s (validator class is %s)", code,type,validatorClassName); - } - - /** - * Adds a new access mode mapping to this configuration. - * - * @param mapping the mapping that will be added. - */ - void addAccessModeMapping(AccessModeMapping mapping){ - int code = mapping.getCode(); - AccessMode accessMode = mapping.getAccessMode(); - _accessModes.put(code, accessMode); - - LOGGER.info(" : Access Mode mapping : code = %s associated to %s", code,accessMode); - } - - /** - * Adds a new management message handler to this configuration. - * The incoming mapping object will contains an opcode and the class (as a string) of the message handler that will be used - * for processing incoming messages with that opcode. - * - * @param mapping the message handler mapping. - */ - void addManagementMessageHandlerMapping (MessageHandlerMapping mapping) - { - Character opcode = mapping.getOpcode(); - String handlerClass = mapping.getMessageHandlerClass(); - _managementQueueHandlers.put(opcode, handlerClass); - - LOGGER.info(" : Management Queue Message Handler Mapping : opcode = %s associated with %s", opcode,handlerClass); - } - - /** - * Adds a new method-reply message handler to this configuration. - * The incoming mapping object will contains an opcode and the class (as a string) of the message handler that will be used - * for processing incoming messages with that opcode. - * - * @param mapping the message handler mapping. - */ - void addMethodReplyMessageHandlerMapping (MessageHandlerMapping mapping) - { - Character opcode = mapping.getOpcode(); - String handlerClass = mapping.getMessageHandlerClass(); - _methodReplyQueueHandlers.put(opcode, handlerClass); - - LOGGER.info(" : Method-Reply Queue Message Handler Mapping : opcode = %s associated with %s", opcode,handlerClass); - } - - /** - * Adds to this configuration a new broker connection data. - * - * @param brokerId the broker identifier. - * @param connectionData the connection data. - * @throws Exception - */ - void addBrokerConnectionData (UUID brokerId, BrokerConnectionData connectionData) throws Exception - { - QpidDatasource.getInstance().addConnectionPool(brokerId, connectionData); - _brokerConnectionInfos.put(brokerId,connectionData); - LOGGER.info(" : Broker Configuration %s: %s",brokerId,connectionData); - } - - /** - * Header for command messages is created once because it only contains static values. - */ - private void createHeaderForCommandMessages () - { - MessageProperties messageProperties = new MessageProperties(); - - ReplyTo replyTo=new ReplyTo(); - replyTo.setRoutingKey(_methodReplyQueueName); - messageProperties.setReplyTo(replyTo); - - DeliveryProperties deliveryProperties = new DeliveryProperties(); - deliveryProperties.setRoutingKey(Names.AGENT_ROUTING_KEY); - - _headerForCommandMessages = new Header(deliveryProperties, messageProperties); - } - - /** - * Creates the name of the queues used by this service. - * This is done because if a broker should be managed by one or more management client, then each of them - * must have its own channels to communicate with. - */ - private void defineQueueNames() - { - UUID uuid = UUID.randomUUID(); - _managementQueueName = Names.MANAGEMENT_QUEUE_PREFIX+uuid; - _methodReplyQueueName = Names.METHOD_REPLY_QUEUE_PREFIX+uuid; - - LOGGER.debug(" : Management queue name : %s",_managementQueueName); - LOGGER.debug(" : Method-reply queue name : %s",_methodReplyQueueName); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/ConfigurationException.java b/java/client/src/main/java/org/apache/qpid/management/configuration/ConfigurationException.java deleted file mode 100644 index 0ddbb3e1d8..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/ConfigurationException.java +++ /dev/null @@ -1,41 +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; - -/** - * Thrown when a problem is encountered during building the configuration. - * - * @author Andrea Gazzarini - */ -public class ConfigurationException extends Exception -{ - private static final long serialVersionUID = 8238481177714286259L; - - /** - * Builds a new ConfigurationException with the given cause. - * - * @param exception the exception cause. - */ - public ConfigurationException(Exception exception) - { - super(exception); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java b/java/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java deleted file mode 100644 index fb33622f4d..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.configuration; - -import java.io.BufferedReader; -import java.io.InputStreamReader; - -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.apache.qpid.management.Names; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * Director used for coordinating the build process of configuration. - * This is the only component which has a read-write permission on Configuration object. - * - * @author Andrea Gazzarini - */ -public class Configurator extends DefaultHandler -{ - /** - * Default (empty) parser used when there's no need to process data (non relevant elements). - */ - final static IParser DEFAULT_PARSER = new IParser() { - - public void setCurrrentAttributeValue (String value) - { - } - - public void setCurrentAttributeName (String name) - { - } - }; - - IParser _typeMappingParser = new TypeMappingParser(); - IParser _accessModeMappingParser = new AccessModeMappingParser(); - IParser _brokerConfigurationParser = new BrokerConnectionDataParser(); - IParser _managementQueueHandlerParser = new ManagementQueueMessageListenerParser(); - IParser _methodReplyQueueHandlerParser = new MethodReplyQueueMessageListenerParser(); - - IParser _currentParser = DEFAULT_PARSER; - - /** - * Delegates the processing to the current parser. - */ - @Override - public void characters (char[] ch, int start, int length) throws SAXException - { - String value = new String(ch,start,length).trim(); - if (value.length() != 0) { - _currentParser.setCurrrentAttributeValue(value); - } - } - - /** - * Here is defined what parser needs to be used for processing the current data. - */ - @Override - public void startElement (String uri, String localName, String name, Attributes attributes) throws SAXException - { - switch(Tag.get(name)) { - case TYPE_MAPPINGS : { - _currentParser = _typeMappingParser; - break; - } - case ACCESS_MODE_MAPPINGS: - { - _currentParser = _accessModeMappingParser; - break; - } - case BROKERS: - { - _currentParser = _brokerConfigurationParser; - break; - } - case MANAGEMENT_QUEUE: - { - _currentParser = _managementQueueHandlerParser; - break; - } - case METHOD_REPLY_QUEUE: - { - _currentParser = _methodReplyQueueHandlerParser; - break; - } - } - } - - @Override - public void endElement (String uri, String localName, String name) throws SAXException - { - _currentParser.setCurrentAttributeName(name); - } - - /** - * Builds whole configuration. - * - * @throws ConfigurationException when the build fails. - */ - public void configure() throws ConfigurationException - { - try - { - SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); - BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(getConfigurationFileName()),"UTF8")); - InputSource source = new InputSource(reader); - parser.parse(source, this); - } catch (Exception exception) - { - throw new ConfigurationException(exception); - } - } - - /** - * Returns the name of the configuration file. - * - * @return the name of the configuration file. - */ - String getConfigurationFileName() - { - return Names.CONFIGURATION_FILE_NAME; - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/IParser.java b/java/client/src/main/java/org/apache/qpid/management/configuration/IParser.java deleted file mode 100644 index a221686765..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/IParser.java +++ /dev/null @@ -1,44 +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; - -/** - * Interface definition for configuration parser - * Concrete implementors are responsible for parsing a specific XML part of configuration data. - * - * @author Andrea Gazzarini - */ -interface IParser -{ - /** - * Main director callback : Sets the name of the current attribute. - * - * @param name the name of the current attribute. - */ - void setCurrentAttributeName(String name); - - /** - * Main director callback : sets the value of the current attribute. - * - * @param value the value of the current attribute. - */ - void setCurrrentAttributeValue(String value); -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/ManagementQueueMessageListenerParser.java b/java/client/src/main/java/org/apache/qpid/management/configuration/ManagementQueueMessageListenerParser.java deleted file mode 100644 index f31cd832cc..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/ManagementQueueMessageListenerParser.java +++ /dev/null @@ -1,72 +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; - -/** - * Parser used for building mapping between a management queue message listeners and an opcode. - * - * - i - org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler - - - * @author Andrea Gazzarini - */ -class ManagementQueueMessageListenerParser implements IParser -{ - private MessageHandlerMapping _mapping = new MessageHandlerMapping(); - private String _currentValue; - - /** - * Callback : the given value is the text content of the current node. - */ - public void setCurrrentAttributeValue (String value) - { - this._currentValue = value; - } - - /** - * Callback: each time the end of an element is reached this method is called. - * It's here that the built mapping is injected into the configuration. - */ - public void setCurrentAttributeName (String name) - { - switch (Tag.get(name)) - { - case OPCODE: - { - _mapping.setOpcode(_currentValue); - break; - } - case CLASS_NAME: - { - _mapping.setMessageHandlerClass(_currentValue); - break; - } - case HANDLER: - { - Configuration.getInstance().addManagementMessageHandlerMapping(_mapping); - _mapping = new MessageHandlerMapping(); - break; - } - } - } -} diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/MessageHandlerMapping.java b/java/client/src/main/java/org/apache/qpid/management/configuration/MessageHandlerMapping.java deleted file mode 100644 index 7ce3baae49..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/MessageHandlerMapping.java +++ /dev/null @@ -1,72 +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; - -/** - * Message Handler mapping used for associating an opcode with a message handler. - * - * @author Andrea Gazzarini - */ -class MessageHandlerMapping -{ - private Character _opcode; - private String _handlerClass; - - /** - * Returns the opcode of this mapping. - * - * @return the code of this mapping. - */ - Character getOpcode () - { - return _opcode; - } - - /** - * Sets the opcode for this mapping. - * - * @param codeAsString the opcode as a string. - */ - void setOpcode (String codeAsString) - { - this._opcode = codeAsString.charAt(0); - } - - /** - * Returns the message handler for this mapping. - * - * @return the message handler for this mapping. - */ - String getMessageHandlerClass() - { - return _handlerClass; - } - - /** - * Sets the message handler of this mapping. - * - * @param handlerClass the handler class as a string. - */ - void setMessageHandlerClass(String handlerClass) - { - this._handlerClass = handlerClass; - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/MethodReplyQueueMessageListenerParser.java b/java/client/src/main/java/org/apache/qpid/management/configuration/MethodReplyQueueMessageListenerParser.java deleted file mode 100644 index a466b50658..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/MethodReplyQueueMessageListenerParser.java +++ /dev/null @@ -1,72 +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; - -/** - * Parser used for building mappings between method-reply queue message listeners and an opcode. - * - * - i - org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler - - * - * @author Andrea Gazzarini - */ -class MethodReplyQueueMessageListenerParser implements IParser -{ - private MessageHandlerMapping _mapping = new MessageHandlerMapping(); - private String _currentValue; - - /** - * Callback : the given value is the text content of the current node. - */ - public void setCurrrentAttributeValue (String value) - { - this._currentValue = value; - } - - /** - * Callback: each time the end of an element is reached this method is called. - * It's here that the built mapping is injected into the configuration. - */ - public void setCurrentAttributeName (String name) - { - switch (Tag.get(name)) - { - case OPCODE: - { - _mapping.setOpcode(_currentValue); - break; - } - case CLASS_NAME: - { - _mapping.setMessageHandlerClass(_currentValue); - break; - } - case HANDLER: - { - Configuration.getInstance().addMethodReplyMessageHandlerMapping(_mapping); - _mapping = new MessageHandlerMapping(); - break; - } - } - } -} diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/QpidDatasource.java b/java/client/src/main/java/org/apache/qpid/management/configuration/QpidDatasource.java deleted file mode 100644 index f4428cb1e2..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/QpidDatasource.java +++ /dev/null @@ -1,276 +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 java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.pool.BasePoolableObjectFactory; -import org.apache.commons.pool.ObjectPool; -import org.apache.commons.pool.impl.GenericObjectPool; -import org.apache.commons.pool.impl.GenericObjectPoolFactory; -import org.apache.qpid.ErrorCode; -import org.apache.qpid.QpidException; -import org.apache.qpid.nclient.Client; -import org.apache.qpid.nclient.ClosedListener; -import org.apache.qpid.nclient.Connection; -import org.apache.qpid.nclient.DtxSession; -import org.apache.qpid.nclient.Session; -import org.apache.qpid.transport.util.Logger; - -/** - * Qpid datasource. - * Basically it is a connection pool manager used for optimizing broker connections usage. - * - * @author Andrea Gazzarini - */ -public final class QpidDatasource -{ - private final static Logger LOGGER = Logger.get(QpidDatasource.class); - - /** - * A connection decorator used for adding pool interaction behaviour to an existing connection. - * - * @author Andrea Gazzarini - */ - public class ConnectionDecorator implements Connection,ClosedListener - { - private final Connection _decoratee; - private final UUID _brokerId; - private boolean _valid; - - /** - * Builds a new decorator with the given connection. - * - * @param brokerId the broker identifier. - * @param decoratee the underlying connection. - */ - private ConnectionDecorator(UUID brokerId, Connection decoratee) - { - this._decoratee = decoratee; - this._brokerId = brokerId; - _decoratee.setClosedListener(this); - _valid = true; - } - - /** - * Returns true if the underlying connection is still valid and can be used. - * - * @return true if the underlying connection is still valid and can be used. - */ - boolean isValid() - { - return _valid; - } - - /** - * Returns the connection to the pool. That is, marks this connections as available. - * After that, this connection will be available for further operations. - */ - public void close () throws QpidException - { - try - { - pools.get(_brokerId).returnObject(this); - LOGGER.debug(" : Connection %s returned to the pool.", this); - } catch (Exception exception) - { - throw new QpidException("Error while closing connection.",ErrorCode.CONNECTION_ERROR,exception); - } - } - - /** - * Do nothing : underlying connection is already connected. - */ - public void connect (String host, int port, String virtualHost, String username, String password) - throws QpidException - { - // DO NOTHING : DECORATEE CONNECTION IS ALREADY CONNECTED. - } - - /** - * Do nothing : underlying connection is already connected. - */ - public void connect (String url) throws QpidException - { - // DO NOTHING : DECORATEE CONNECTION IS ALREADY CONNECTED. - } - - /** - * @see Connection#createDTXSession(int) - */ - public DtxSession createDTXSession (int expiryInSeconds) - { - return _decoratee.createDTXSession(expiryInSeconds); - } - - /** - * @see Connection#createSession(long) - */ - public Session createSession (long expiryInSeconds) - { - return _decoratee.createSession(expiryInSeconds); - } - - /** - * Do nothing : closed listener has been already injected. - */ - public void setClosedListener (ClosedListener exceptionListner) - { - } - - /** - * Callback method used for error notifications while underlying connection is closing. - */ - public void onClosed (ErrorCode errorCode, String reason, Throwable t) - { - _valid = false; - LOGGER.error(t," : Error on closing connection. Reason is : %s, error code is %s",reason,errorCode.getCode()); - } - }; - - /** - * This is the connection factory, that is, the factory used to manage the lifecycle (create, validate & destroy) of - * the broker connection(s). - * - * @author Andrea Gazzarini - */ - class QpidConnectionFactory extends BasePoolableObjectFactory - { - private final BrokerConnectionData _connectionData; - private final UUID _brokerId; - - /** - * Builds a new connection factory with the given parameters. - * - * @param brokerId the broker identifier. - * @param connectionData the connecton data. - */ - private QpidConnectionFactory(UUID brokerId, BrokerConnectionData connectionData) - { - this._connectionData = connectionData; - this._brokerId = brokerId; - } - - /** - * Creates a new underlying connection. - */ - @Override - public Connection makeObject () throws Exception - { - Connection connection = Client.createConnection(); - connection.connect( - _connectionData.getHost(), - _connectionData.getPort(), - _connectionData.getVirtualHost(), - _connectionData.getUsername(), - _connectionData.getPassword()); - return new ConnectionDecorator(_brokerId,connection); - } - - /** - * Validates the underlying connection. - */ - @Override - public boolean validateObject (Object obj) - { - ConnectionDecorator connection = (ConnectionDecorator) obj; - boolean isValid = connection.isValid(); - LOGGER.debug(" : Test connection on reserve. Is valid? %s",isValid); - return isValid; - } - - /** - * Closes the underlying connection. - */ - @Override - public void destroyObject (Object obj) throws Exception - { - try - { - ConnectionDecorator connection = (ConnectionDecorator) obj; - connection._decoratee.close(); - LOGGER.debug(" : Connection has been destroyed."); - } catch (Exception e) - { - LOGGER.debug(e, " : Unable to destroy a connection object"); - } - } - } - - // Singleton instance. - private static QpidDatasource instance = new QpidDatasource(); - - // Each entry contains a connection pool for a specific broker. - private Map pools = new HashMap(); - - // Private constructor. - private QpidDatasource() - { - } - - /** - * Gets an available connection from the pool of the given broker. - * - * @param brokerId the broker identifier. - * @return a valid connection to the broker associated with the given identifier. - */ - public Connection getConnection(UUID brokerId) throws Exception - { - return (Connection) pools.get(brokerId).borrowObject(); - } - - /** - * Entry point method for retrieving the singleton instance of this datasource. - * - * @return the qpid datasource singleton instance. - */ - public static QpidDatasource getInstance() - { - return instance; - } - - /** - * Adds a connection pool to this datasource. - * - * @param brokerId the broker identifier that will be associated with the new connection pool. - * @param connectionData the broker connection data. - * @throws Exception when the pool cannot be created. - */ - void addConnectionPool(UUID brokerId,BrokerConnectionData connectionData) throws Exception { - GenericObjectPoolFactory factory = new GenericObjectPoolFactory( - new QpidConnectionFactory(brokerId,connectionData), - connectionData.getMaxPoolCapacity(), - GenericObjectPool.WHEN_EXHAUSTED_BLOCK, - connectionData.getMaxWaitTimeout(),-1, - true, - false); - ObjectPool pool = factory.createPool(); - - for (int i = 0; i < connectionData.getInitialPoolCapacity(); i++) - { - pool.returnObject(pool.borrowObject()); - } - - pools.put(brokerId,pool); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/Tag.java b/java/client/src/main/java/org/apache/qpid/management/configuration/Tag.java deleted file mode 100644 index 9b3a4a3f6f..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/Tag.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.apache.qpid.management.configuration; - -/** - * Configuration Tag catalogue. - * - * @author Andrea Gazzarini - */ -public enum Tag { - HANDLER { @Override public String toString() { return "handler"; }}, - MAPPING { @Override public String toString() { return "mapping"; }}, - CODE { @Override public String toString() { return "code"; }}, - CLASS_NAME { @Override public String toString() { return "class-name"; }}, - TYPE_MAPPINGS { @Override public String toString() { return "type-mappings"; }}, - ACCESS_MODE_MAPPINGS { @Override public String toString() { return "access-mode-mappings"; }}, - VALUE { @Override public String toString() { return "value"; }}, - CONFIGURATION { @Override public String toString() { return "configuration"; }}, - MESSAGE_HANDLERS { @Override public String toString() { return "message-handlers"; }}, - OPCODE { @Override public String toString() { return "opcode"; }}, - VALIDATOR_CLASS_NAME { @Override public String toString() { return "validator-class-name"; }}, - BROKER { @Override public String toString() { return "broker"; }}, - HOST { @Override public String toString() { return "host"; }}, - PORT { @Override public String toString() { return "port"; }}, - MAX_POOL_CAPACITY { @Override public String toString() { return "max-pool-capacity"; }}, - MAX_WAIT_TIMEOUT { @Override public String toString() { return "max-wait-timeout"; }}, - INITIAL_POOL_CAPACITY { @Override public String toString() { return "initial-pool-capacity"; }}, - VIRTUAL_HOST { @Override public String toString() { return "virtual-host"; }}, - USER { @Override public String toString() { return "user"; }}, - PASSWORD { @Override public String toString() { return "password"; }}, - BROKERS { @Override public String toString() { return "brokers"; }}, - MANAGEMENT_QUEUE { @Override public String toString() { return "management-queue"; }}, - METHOD_REPLY_QUEUE { @Override public String toString() { return "method-reply-queue"; }}; - - /** - * Returns the enum entry associated to the given tag name. - * - * @param name the name of tag. - * @return the enum entry associated to the given tag name. - */ - public static Tag get(String name) { - return valueOf(name.replaceAll("-", "_").toUpperCase()); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java b/java/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java deleted file mode 100644 index 714c8eb6f5..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java +++ /dev/null @@ -1,103 +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 int _code; - private Type _type; - private String _validatorClass; - - /** - * Returns the code of this mapping. - * - * @return the code of this mapping. - */ - int getCode () - { - return _code; - } - - /** - * Sets the code for this mapping. - * Note that the given string must be a valid number (integer). - * - * @param codeAsString the code as a string. - * @throws NumberFormatException when the given string is not a valid number. - */ - void setCode (String codeAsString) - { - this._code = Integer.parseInt(codeAsString); - } - - /** - * Returns the type for this mapping. - * - * @return the type for this mapping. - */ - Type getType () - { - return _type; - } - - /** - * Sets the type of this mapping. - * - * @param typeClass the type class as a string. - * @throw IllegalArgumentException when it's not possible to load the given class. - */ - void setType (String typeClass) - { - try - { - this._type = (Type) Class.forName(typeClass).newInstance(); - } catch (Exception exception) - { - throw new IllegalArgumentException(exception); - } - } - - /** - * Sets the validator class that will be used for validation. - * - * @param className the fully qualified name of the validation class. - */ - public void setValidatorClassName (String className) - { - this._validatorClass = className; - } - - /** - * Returns the validator class of this mapping. - * - * @return the validator class (as a string) of this mapping. - */ - public String getValidatorClassName() - { - return _validatorClass; - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/TypeMappingParser.java b/java/client/src/main/java/org/apache/qpid/management/configuration/TypeMappingParser.java deleted file mode 100644 index 40b9cf84ca..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/TypeMappingParser.java +++ /dev/null @@ -1,77 +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; - -/** - * Parser used for building type mappings. - * For each type-mappings/mapping element found in the configuration file, a new type mapping is built and injected into - * the bridge configuration. - * - * - 1 - org.apache.qpid.management.domain.model.type.Uint8 - org.apache.qpid.management.domain.model.QpidProperty$NumberValidator - - * - * @author Andrea Gazzarini - */ -class TypeMappingParser implements IParser -{ - private TypeMapping _mapping = new TypeMapping(); - private String _currentValue; - - /** - * Callback : the given value is the text content of the current node. - */ - public void setCurrrentAttributeValue (String value) - { - this._currentValue = value; - } - - /** - * Callback: each time the end of an element is reached this method is called. - * It's here that the built mapping is injected into the configuration. - */ - public void setCurrentAttributeName (String name) - { - switch (Tag.get(name)) - { - case CODE: - { - _mapping.setCode(_currentValue); - break; - } - case CLASS_NAME : { - _mapping.setType(_currentValue); - break; - } - case VALIDATOR_CLASS_NAME : { - _mapping.setValidatorClassName(_currentValue); - break; - } - case MAPPING : { - Configuration.getInstance().addTypeMapping(_mapping); - _mapping = new TypeMapping(); - break; - } - } - } -} diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/UnknownAccessCodeException.java b/java/client/src/main/java/org/apache/qpid/management/configuration/UnknownAccessCodeException.java deleted file mode 100644 index b7f1c0a7ec..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/UnknownAccessCodeException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.configuration; - -/** - * Thrown when no access mode is found in configuration associated to the given code. - * - * @author Andrea Gazzarini - */ -public class UnknownAccessCodeException extends Exception -{ - private static final long serialVersionUID = 2350963503092509119L; - private final int _code; - - /** - * Builds a new UnknownAccessCodeException with the given code. - * - * @param code the access code. - */ - UnknownAccessCodeException(int code) - { - super(String.valueOf(code)); - this._code = code; - } - - /** - * Returns the unknown code. - * - * @return the unknown code. - */ - public int getCode () - { - return _code; - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/UnknownBrokerException.java b/java/client/src/main/java/org/apache/qpid/management/configuration/UnknownBrokerException.java deleted file mode 100644 index 5b08e09c24..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/UnknownBrokerException.java +++ /dev/null @@ -1,43 +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 java.util.UUID; - -/** - * Thrown when someone requests connection data for an unknown broker. - * - * @author Andrea Gazzarini - */ -public class UnknownBrokerException extends Exception -{ - private static final long serialVersionUID = 4965395428832158924L; - - /** - * Builds a new UnknownBrokerException with the given broker id. - * - * @param brokerId the broker identifier. - */ - UnknownBrokerException(UUID brokerId) - { - super(String.valueOf(brokerId)); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/configuration/UnknownTypeCodeException.java b/java/client/src/main/java/org/apache/qpid/management/configuration/UnknownTypeCodeException.java deleted file mode 100644 index 57005d21e5..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/configuration/UnknownTypeCodeException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.configuration; - -/** - * Thrown when no type is found in configuration associated to the given code. - * - * @author Andrea Gazzarini - */ -public class UnknownTypeCodeException extends Exception -{ - private static final long serialVersionUID = 5440934037645111591L; - private int _code; - - /** - * Builds a new UnknownTypeCodeException with the given code. - * - * @param code the access code. - */ - UnknownTypeCodeException(int code) - { - super(String.valueOf(code)); - this._code = code; - } - - /** - * Returns the unknown code. - * - * @return the unknown code. - */ - public int getCode () - { - return _code; - } -} diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/handler/base/BaseMessageHandler.java b/java/client/src/main/java/org/apache/qpid/management/domain/handler/base/BaseMessageHandler.java deleted file mode 100644 index 798e835ff4..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/handler/base/BaseMessageHandler.java +++ /dev/null @@ -1,54 +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.domain.handler.base; - -import org.apache.qpid.management.domain.model.DomainModel; -import org.apache.qpid.transport.util.Logger; - -/** - * Base class for all message handlers. - * A message handler is an handler for a specific type of message. - * Message type is defined by the opcode. - * - * @author Andrea Gazzarini - */ -public abstract class BaseMessageHandler implements IMessageHandler -{ - /** - * Logger used for logging. - */ - protected final Logger _logger = Logger.get(getClass()); - - /** - * Managed broker domain model. - */ - protected DomainModel _domainModel; - - /** - * Sets the broker domain model. - * - * @param domainModel the broker domain model. - */ - public void setDomainModel(DomainModel domainModel) - { - this._domainModel = domainModel; - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandler.java b/java/client/src/main/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandler.java deleted file mode 100644 index 21a3281fa9..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandler.java +++ /dev/null @@ -1,116 +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.domain.handler.base; - -import org.apache.qpid.management.domain.model.type.Binary; -import org.apache.qpid.transport.codec.ManagementDecoder; - -/** - * Base class for content indication message handlers. - * - * @author Andrea Gazzarini - */ -public abstract class ContentIndicationMessageHandler extends BaseMessageHandler -{ - /** - * Processes the income message. - * - * @param decoder the decoder used to parse the message. - * @param sequenceNumber the sequence number of the message. - */ - public final void process (ManagementDecoder decoder, int sequenceNumber) - { - String packageName = decoder.readStr8(); - String className = decoder.readStr8(); - Binary classHash = new Binary(decoder.readBin128()); - - long timeStampOfCurrentSample = decoder.readDatetime(); - long timeObjectWasCreated = decoder.readDatetime(); - long timeObjectWasDeleted = decoder.readDatetime(); - - - - Binary objectId = new Binary(decoder.readBin128()); - - if (objectHasBeenRemoved(timeObjectWasDeleted, timeStampOfCurrentSample)) - { - removeObjectInstance(packageName,className,classHash,objectId); - } else - { - updateDomainModel( - packageName, - className, - classHash, - objectId, - timeStampOfCurrentSample, - timeObjectWasCreated, - timeObjectWasDeleted, - decoder.readReaminingBytes()); - } - } - - /** - * Removes an object instance from the domain model. - * - * @param packageName the package name. - * @param className the class name. - * @param classHash the class hash. - * @param objectId the object identifier. - */ - void removeObjectInstance(String packageName, String className,Binary classHash, Binary objectId) - { - _domainModel.removeObjectInstance(packageName,className,classHash,objectId); - } - - /** - * Checks if the timestamps contained in the message indicate that the object has been removed. - * - * @param deletionTimestamp time object was deleted. - * @param now timestamp of the current message. - * @return true if the object has been removed, false otherwise. - */ - boolean objectHasBeenRemoved(long deletionTimestamp, long now) { - return (deletionTimestamp != 0) && (now > deletionTimestamp); - } - - /** - * Updates domain model with the incoming data. - * This is a template method that each concrete subclass must implement in order to update the domain model - * with the incoming data. - * - * @param packageName the name of the package. - * @param className the name of the class. - * @param objectId the object identifier. - * @param timeStampOfCurrentSample timestamp of current sample. - * @param timeObjectWasCreated time object was created. - * @param timeObjectWasDeleted time object was deleted. - * @param contentData object instance incoming data. - */ - protected abstract void updateDomainModel( - String packageName, - String className, - Binary classHash, - Binary objectId, - long timeStampOfCurrentSample, - long timeObjectWasCreated, - long timeObjectWasDeleted, - byte []contentData ); -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/handler/base/IMessageHandler.java b/java/client/src/main/java/org/apache/qpid/management/domain/handler/base/IMessageHandler.java deleted file mode 100644 index b945a29117..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/handler/base/IMessageHandler.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.domain.handler.base; - -import org.apache.qpid.management.domain.model.DomainModel; -import org.apache.qpid.transport.codec.ManagementDecoder; - -/** - * Interface definition for a processor able to deal with a specific message. - * The concrete implementor must define what has to be done with the supplied (incoming) stream and the sequence - * number. - * - * @author Andrea Gazzarini. - */ -public interface IMessageHandler -{ - /** - * Processes the (incoming) stream message. - * Note that the main controller (the component that is controlling this handler) has already read the magic number and - * the sequence number so here concrete implementors must start from that point (that is, just after the sequence - * number). - * - * @param decoder the stream decoder. - * @param sequenceNumber the sequence number of the message. - */ - void process (ManagementDecoder decoder, int sequenceNumber); - - /** - * Injects the domain model into this handler. - * - * @param domainModel the domain model. - */ - void setDomainModel(DomainModel domainModel); -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/ConfigurationMessageHandler.java b/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/ConfigurationMessageHandler.java deleted file mode 100644 index a5f8c238a7..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/ConfigurationMessageHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.domain.handler.impl; - -import org.apache.qpid.management.domain.handler.base.ContentIndicationMessageHandler; -import org.apache.qpid.management.domain.model.type.Binary; - -/** - * Schema Response message handler. - * This handler is responsible to process 'c'(opcode) messages sent by the management broker. - * - * @author Andrea Gazzarini - */ -public class ConfigurationMessageHandler extends ContentIndicationMessageHandler -{ - /** - * Broker domain model is going to be updated with incoming configuration data. - * - * @param packageName the name of the package. - * @param className the name of the class. - * @param objectId the object identifier. - * @param timeStampOfCurrentSample the timestamp of incoming data. - * @param timeObjectWasCreated time object was created. - * @param timeObjectWasDeleted time object was deleted. - */ - @Override - protected void updateDomainModel ( - String packageName, - String className, - Binary classHash, - Binary objectId, - long timeStampOfCurrentSample, - long timeObjectWasCreated, - long timeObjectWasDeleted, - byte[] contentData) - { - // TODO : deal with timestamps, too - _domainModel.addConfigurationRawData(packageName,className,classHash,objectId,contentData); - } - } \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InstrumentationMessageHandler.java b/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InstrumentationMessageHandler.java deleted file mode 100644 index ee6d1f0092..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InstrumentationMessageHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.domain.handler.impl; - -import org.apache.qpid.management.domain.handler.base.ContentIndicationMessageHandler; -import org.apache.qpid.management.domain.model.type.Binary; - -/** - * Schema Response message handler. - * This handler is responsible to process 'i'(opcode) messages sent by the management broker. - * - * @author Andrea Gazzarini - */ -public class InstrumentationMessageHandler extends ContentIndicationMessageHandler -{ - /** - * Broker domain model is going to be updated with incoming instrumentation data. - * - * @param packageName the name of the package. - * @param className the name of the class. - * @param objectId the object identifier. - * @param timeStampOfCurrentSample the timestamp of incoming data. - * @param timeObjectWasCreated time object was created. - * @param timeObjectWasDeleted time object was deleted. - */ - @Override - protected void updateDomainModel ( - String packageName, - String className, - Binary classHash, - Binary objectId, - long timeStampOfCurrentSample, - long timeObjectWasCreated, - long timeObjectWasDeleted, - byte[] contentData) - { - // TODO : deal with timestamps, too - _domainModel.addInstrumentationRawData(packageName,className,classHash,objectId,contentData); - } - } \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodOrEventDataTransferObject.java b/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodOrEventDataTransferObject.java deleted file mode 100644 index bc6a77d804..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodOrEventDataTransferObject.java +++ /dev/null @@ -1,68 +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.domain.handler.impl; - -import java.util.List; -import java.util.Map; - -/** - * Simple transfer object used for holding method / event definition data. - * - * @author Andrea Gazzarini - */ -public class MethodOrEventDataTransferObject -{ - private final Map _definition; - private List> _argumentDefinitions; - - /** - * Builds a new trasfer object with the given parameters. - * - * @param definition the method definition. - * @param argumentDefinitions the arguments definitions. - */ - public MethodOrEventDataTransferObject( - Map definition, - List> argumentDefinitions) - { - this._definition = definition; - this._argumentDefinitions = argumentDefinitions; - } - - /** - * Returns the method definition. - * - * @return the method definition. - */ - public Map getDefinition() { - return _definition; - } - - /** - * Returns the arguemnts definitions. - * - * @return the arguemnts definitions. - */ - public List> getArgumentsDefinitions() - { - return _argumentDefinitions; - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodResponseMessageHandler.java b/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodResponseMessageHandler.java deleted file mode 100644 index 24db2e963d..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodResponseMessageHandler.java +++ /dev/null @@ -1,41 +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.domain.handler.impl; - -import org.apache.qpid.management.domain.handler.base.BaseMessageHandler; -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.util.Logger; - -public class MethodResponseMessageHandler extends BaseMessageHandler -{ - private final static Logger LOGGER = Logger.get(MethodResponseMessageHandler.class); - - public void process (ManagementDecoder decoder, int sequenceNumber) - { - LOGGER.debug(" : Incoming method response message."); - - long statusCode = decoder.readUint32(); - String statusText = decoder.readStr8(); - - LOGGER.debug(" : Status code : %s", statusCode); - LOGGER.debug(" : Status text : %s", statusText); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/SchemaResponseMessageHandler.java b/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/SchemaResponseMessageHandler.java deleted file mode 100644 index 497e264581..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/handler/impl/SchemaResponseMessageHandler.java +++ /dev/null @@ -1,162 +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.domain.handler.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.qpid.management.Names; -import org.apache.qpid.management.domain.handler.base.BaseMessageHandler; -import org.apache.qpid.management.domain.model.type.Binary; -import org.apache.qpid.transport.codec.ManagementDecoder; - -/** - * Schema Response message handler. - * This handler is responsible to process 'S'(opcode) messages sent by the management broker containing the full - * schema details for a class. - * - * @author Andrea Gazzarini - */ -public class SchemaResponseMessageHandler extends BaseMessageHandler -{ - /** - * Processes an incoming schema response. - * This will be used for building the corresponding class definition. - * - * @param decoder the decoder used for parsing the incoming stream. - * @param sequenceNumber the sequence number of the incoming message. - */ - public void process (ManagementDecoder decoder, int sequenceNumber) - { - try - { - int classKind = decoder.readUint8(); - if (classKind != 1) { - return; - } - String packageName = decoder.readStr8(); - String className = decoder.readStr8(); - - Binary schemaHash = new Binary(decoder.readBin128()); - - int howManyProperties = decoder.readUint16(); - int howManyStatistics = decoder.readUint16(); - int howManyMethods = decoder.readUint16(); - int howManyEvents = 0; - - // FIXME : Divide between schema error and raw data conversion error!!!! - _domainModel.addSchema( - packageName, - className, - schemaHash, - getProperties(decoder, howManyProperties), - getStatistics(decoder, howManyStatistics), - getMethods(decoder, howManyMethods), - getEvents(decoder, howManyEvents)); - } catch(Exception exception) - { - _logger.error(exception," : Q-Man was unable to process the schema response message."); - } - } - - /** - * Reads from the incoming message stream the properties definitions. - * - * @param decoder the decoder used for decode incoming data. - * @param howManyProperties the number of properties to read. - * @return a list of maps. Each map contains a property definition. - */ - List> getProperties(ManagementDecoder decoder,int howManyProperties) - { - List> result = new ArrayList>(howManyProperties); - for (int i = 0; i < howManyProperties; i++ ) - { - result.add(decoder.readMap()); - } - return result; - } - - /** - * Reads the statistics definitions from the incoming message stream. - * - * @param decoder the decoder used for decode incoming data. - * @param howManyProperties the number of statistics to read. - * @return a list of maps. Each map contains a statistic definition. - */ - List> getStatistics(ManagementDecoder decoder,int howManyStatistics) - { - List> result = new ArrayList>(howManyStatistics); - for (int i = 0; i < howManyStatistics; i++ ) - { - result.add(decoder.readMap()); - } - return result; - } - - /** - * Reads the methods definitions from the incoming message stream. - * - * @param decoder the decoder used for decode incoming data. - * @param howManyMethods the number of methods to read. - * @return a list method definitions. - */ - List getMethods(ManagementDecoder decoder, int howManyMethods) - { - List result = new ArrayList(howManyMethods); - for (int i = 0; i < howManyMethods; i++) - { - Map method = decoder.readMap(); - int howManyArguments = (Integer) method.get(Names.ARG_COUNT_PARAM_NAME); - - List> arguments = new ArrayList>(howManyArguments); - for (int argIndex = 0; argIndex < howManyArguments; argIndex++){ - arguments.add(decoder.readMap()); - } - result.add(new MethodOrEventDataTransferObject(method,arguments)); - } - return result; - } - - /** - * Reads the events definitions from the incoming message stream. - * - * @param decoder the decoder used for decode incoming data. - * @param howManyEvents the number of events to read. - * @return a list event definitions. - */ - List getEvents(ManagementDecoder decoder, int howManyEvents) - { - List result = new ArrayList(howManyEvents); - for (int i = 0; i < howManyEvents; i++) - { - Map method = decoder.readMap(); - int howManyArguments = (Integer) method.get(Names.ARG_COUNT_PARAM_NAME); - - List> arguments = new ArrayList>(howManyArguments); - for (int argIndex = 0; argIndex < howManyArguments; argIndex++){ - arguments.add(decoder.readMap()); - } - result.add(new MethodOrEventDataTransferObject(method,arguments)); - } - return result; - } - } diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/AccessMode.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/AccessMode.java deleted file mode 100644 index 6d1426c122..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/AccessMode.java +++ /dev/null @@ -1,33 +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.domain.model; - -/** - * Enumeration for Access modes. - * - * @author Andrea Gazzarini - */ -public enum AccessMode -{ - RC { @Override public String toString() { return "Read-Create"; }}, - RO { @Override public String toString() { return "Read-Only"; }}, - RW { @Override public String toString() { return "Read-Write"; }} -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/Direction.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/Direction.java deleted file mode 100644 index 8166c35eb6..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/Direction.java +++ /dev/null @@ -1,33 +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.domain.model; - -/** - * Enumeration of allowed method argument direction codes. - * - * @author Andrea Gazzarini - */ -public enum Direction -{ - I{ @Override public String toString() { return "Input"; }}, - O{ @Override public String toString() { return "Output"; }}, - IO{ @Override public String toString() { return "Input-Output"; }}; -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/DomainModel.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/DomainModel.java deleted file mode 100644 index b24228d122..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/DomainModel.java +++ /dev/null @@ -1,174 +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.domain.model; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; -import org.apache.qpid.management.domain.model.type.Binary; - -/** - * Broker domain model. - * This is the local representation of a remote broker domain model. - * - * @author Andrea Gazzarini - */ -public class DomainModel -{ - private final UUID _id; - - /** Here the known packages of the remote broker are stored. */ - Map _packages = new HashMap(); - - /** - * Builds a new domain model with the given broker identifier. - * - * @param brokerId the broker identifier. - */ - public DomainModel(UUID brokerId) - { - this._id = brokerId; - } - - /** - * Returns the identifier of the broker associated with this domain model. - * - * @return the identifier of the broker associated with this domain model. - */ - public UUID getBrokerId() - { - return _id; - } - - /** - * Adds the specified schema to this domain model. - * - * @param packageName the package name. - * @param className the class name. - * @param classHash the class schema hash. - * @param properties the class properties. - * @param statistics the class statistics. - * @param methods the class methods. - * @param events the class events. - * @throws UnableToBuildFeatureException - */ - public void addSchema( - String packageName, - String className, - Binary classHash, - List> properties, - List> statistics, - List methods, - List events) throws UnableToBuildFeatureException - { - QpidPackage qpidPackage = getPackageByName(packageName); - qpidPackage.addClassDefinition(className,classHash,properties,statistics,methods, events); - } - - /** - * Gets the package with the specified name. - * Note that if the package doesn't exist a new one will be created and returned. - * - * @param packageName the name of the package. - * @return the package. - */ - QpidPackage getPackageByName (String packageName) - { - QpidPackage qpidPackage = _packages.get(packageName); - if (qpidPackage == null) - { - qpidPackage = new QpidPackage(packageName,this); - _packages.put(packageName, qpidPackage); - } - return qpidPackage; - } - - /** - * Returns true if a package with the specified name already exists on this domain model. - * - * @param packageName the name of the package. - * @return true if the package exists, false otherwise. - */ - boolean containsPackage (String packageName) - { - return _packages.containsKey(packageName); - } - - /** - * Adds the given instrumentation data (raw format) to this domain model. - * Note that this data is belonging to a specific object instance. - * - * @param packageName the name of the ower package. - * @param className the name of the owner class. - * @param classHash the schema hash for this class. - * @param objectId the object instance identifier. - * @param rawData the instrumentation data. - */ - public void addInstrumentationRawData (String packageName, String className,Binary classHash, Binary objectId, byte[] rawData) - { - QpidPackage qpidPackage = getPackageByName(packageName); - qpidPackage.setObjectInstanceInstrumentationRawData(className,classHash,objectId,rawData); - } - - /** - * Adds the given configuration data (raw format) to this domain model. - * Note that this data is belonging to a specific object instance. - * - * @param packageName the name of the ower package. - * @param className the name of the owner class. - * @param classHash the schema hash for this class. - * @param objectId the object instance identifier. - * @param rawData the configuration data. - */ - public void addConfigurationRawData (String packageName, String className, Binary classHash,Binary objectId, byte[] rawData) - { - QpidPackage qpidPackage = getPackageByName(packageName); - qpidPackage.setObjectInstanceConfigurationRawData(className,classHash,objectId,rawData); - } - - /** - * Removes the object instance associated to the given parameters. - * - * @param packageName the owner package. - * @param className the class definition of the object instance. - * @param classHash the class hash - * @param objectId the object identifier. - */ - public void removeObjectInstance (String packageName, String className, Binary classHash, Binary objectId) - { - QpidPackage qpidPackage = getPackageByName(packageName); - qpidPackage.removeObjectInstance(className, classHash, objectId); - } - - /** - * Releases all the resources kept by domain model entitiies. - */ - public void releaseResources() - { - for (QpidPackage qpidPackage : _packages.values()) - { - qpidPackage.releaseResources(); - } - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/IValidator.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/IValidator.java deleted file mode 100644 index 1ede559145..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/IValidator.java +++ /dev/null @@ -1,38 +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.domain.model; - -/** - * Interface definition for attribute validators. - * - * @author Andrea Gazzarini - */ -interface IValidator -{ - /** - * Validates the given value according to the rules definied by this validator. - * - * @param value the value be checked. - * - * @throws ValidationException when the value is violating validator's rules. - */ - void validate(Object value) throws ValidationException; -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java deleted file mode 100644 index 9ca6ba0e7c..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java +++ /dev/null @@ -1,158 +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.domain.model; - -import java.lang.management.ManagementFactory; -import java.util.UUID; - -import javax.management.MBeanServer; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; - -import org.apache.qpid.management.Names; -import org.apache.qpid.management.domain.model.QpidClass.QpidManagedObject; -import org.apache.qpid.management.domain.model.type.Binary; -import org.apache.qpid.transport.util.Logger; - -/** - * A simple facade used to perform operations on Mbean server. - * - * @author Andrea Gazzarini - */ -class JmxService -{ - private final static Logger LOGGER = Logger.get(JmxService.class); - private MBeanServer _mxServer = ManagementFactory.getPlatformMBeanServer(); - - - /** - * Registers a pre-existing object instance as an MBean with the MBean - * server. - * - * @param instance the object instance. - * @param brokerId the broker identifier. - * @param packageName the name of the package containing this instance. - * @param className the name of the owner class of this instance. - * @param objectId the object instance identifier. - */ - void registerObjectInstance( - QpidManagedObject instance, - UUID brokerId, - String packageName, - String className, - Binary objectId) - { - ObjectName name = createObjectName(brokerId, packageName, className, objectId); - if (!_mxServer.isRegistered(name)) - { - try - { - _mxServer.registerMBean(instance, name); - - LOGGER.debug( - " : Object instance %s::%s::%s:%s successfully registered with MBean Server with name %s", - brokerId, - packageName, - className, - objectId, - name); - } catch (Exception exception) - { - throw new RuntimeException(exception); - } - } - } - - /** - * Removes / unregisters a managed object instance from the MBean Server. - * - * @param brokerId the broker identifier. - * @param packageName the name of the package containing this instance. - * @param className the name of the owner class of this instance. - * @param objectId the object instance identifier. - */ - void unregisterObjectInstance( - UUID brokerId, - String packageName, - String className, - Binary objectId) - { - ObjectName name = createObjectName(brokerId, packageName, className, objectId); - if (_mxServer.isRegistered(name)) - { - try - { - _mxServer.unregisterMBean(name); - - LOGGER.debug( - " : Object instance %s::%s::%s:%s successfully unregistered from MBean Server. " + - "Name was %s", - brokerId, - packageName, - className, - objectId, - name); - } catch (Exception exception) - { - LOGGER.error(exception," : Unable to unregister object instance %s.",name); - } - } - } - - /** - * Factory method for ObjectNames. - * - * @param brokerId the broker identifier. - * @param packageName the name of the package containing this instance. - * @param className the name of the owner class of this instance. - * @param objectId the object instance identifier. - * @return the object name built according to the given parameters. - */ - private ObjectName createObjectName(UUID brokerId, String packageName, String className, Binary objectId) - { - String asString = new StringBuilder() - .append(Names.DOMAIN_NAME) - .append(':') - .append(Names.BROKER_ID) - .append('=') - .append(brokerId) - .append(',') - .append(Names.PACKAGE) - .append('=') - .append(packageName) - .append(',') - .append(Names.CLASS) - .append('=') - .append(className) - .append(',') - .append(Names.OBJECT_ID) - .append('=') - .append(objectId) - .toString(); - try - { - return new ObjectName(asString); - } catch (MalformedObjectNameException exception) - { - throw new RuntimeException(exception); - } - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/MissingFeatureAttributesException.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/MissingFeatureAttributesException.java deleted file mode 100644 index 160054059b..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/MissingFeatureAttributesException.java +++ /dev/null @@ -1,35 +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.domain.model; - -import java.util.List; - -import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute; - -public class MissingFeatureAttributesException extends UnableToBuildFeatureException -{ - private static final long serialVersionUID = 671471705085787235L; - - public MissingFeatureAttributesException(List missingAttributeList) - { - super(String.valueOf(missingAttributeList)); - } -} diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidArgument.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidArgument.java deleted file mode 100644 index e38ad4cee0..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidArgument.java +++ /dev/null @@ -1,77 +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.domain.model; - -import org.apache.qpid.transport.codec.ManagementEncoder; -import org.apache.qpid.transport.util.Logger; - -class QpidArgument extends QpidProperty -{ - private final static Logger LOGGER = Logger.get(QpidArgument.class); - - private Object _defaultValue; - - private Direction _direction; - - public void setDirection(String code) - { - this._direction = Direction.valueOf(code); - } - - public Direction getDirection() - { - return _direction; - } - - public void setDefaultValue(Object defaultValue) - { - this._defaultValue = defaultValue; - } - - public Object getDefaultValue() - { - return _defaultValue; - } - - public boolean isInput(){ - return _direction != Direction.O; - } - - @Override - public String toString () - { - return new StringBuilder() - .append(getJavaType().getName()) - .append(' ') - .append(_name) - .append("(") - .append(_direction) - .append(")") - .toString(); - } - - public void validateAndEncode (Object value,ManagementEncoder encoder) throws ValidationException - { - validate(value); - _type.encode(value, encoder); - LOGGER.debug("Encoded value %S for argument %s. Type is %s",value,_name,_type); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidAttribute.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidAttribute.java deleted file mode 100644 index d0bc470de9..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidAttribute.java +++ /dev/null @@ -1,104 +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.domain.model; - -import org.apache.qpid.management.domain.model.type.Type; -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.util.Logger; - -/** - * Layer supertype for qpid properties and statistics. - * - * @author Andrea Gazzarini - */ -class QpidAttribute extends QpidFeature -{ - private final static Logger LOGGER = Logger.get(QpidAttribute.class); - - /** feature type */ - protected Type _type; - - /** feature unit */ - protected String _unit; - - /** - * Returns the units used for numeric values (i.e. seconds, bytes, etc.) - * - * @return the units used for numeric values (i.e. seconds, bytes, etc.) - */ - String getUnit () - { - return _unit; - } - - /** - * Sets the unit for this property. - * - * @param unit the unit of this property. - */ - void setUnit (String unit) - { - this._unit = unit; - LOGGER.debug("Unit : %s", unit); - } - - /** - * Returns the java type (class) of this feature. - * - * @return the java type (class) of this feature. - */ - Class getJavaType () - { - return _type.getJavaType(); - } - - /** - * Sets the type of this feature. - * - * @param type the type of this feature. - */ - void setType (Type type) - { - this._type = type; - } - - /** - * Gets the value of this feature according to its type definition. - * - * @param decoder the decoder used to extract the value. - * @return the value of this feature according to its type definition - */ - Object decodeValue(ManagementDecoder decoder) - { - try { - return _type.decode(decoder); - } catch(RuntimeException exception) { - LOGGER.error(exception,"Unable to decode value for attribute %s",this); - throw exception; - } - } - - @Override - public String toString () - { - return super.toString()+",type="+_type; - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidClass.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidClass.java deleted file mode 100644 index 262e17db9a..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidClass.java +++ /dev/null @@ -1,855 +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.domain.model; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.management.Attribute; -import javax.management.AttributeList; -import javax.management.AttributeNotFoundException; -import javax.management.DynamicMBean; -import javax.management.InvalidAttributeValueException; -import javax.management.MBeanAttributeInfo; -import javax.management.MBeanException; -import javax.management.MBeanInfo; -import javax.management.MBeanOperationInfo; -import javax.management.MBeanRegistration; -import javax.management.MBeanServer; -import javax.management.ObjectName; -import javax.management.ReflectionException; -import javax.management.RuntimeOperationsException; - -import org.apache.qpid.management.Protocol; -import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; -import org.apache.qpid.management.domain.model.type.Binary; -import org.apache.qpid.management.domain.services.QpidService; -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; -import org.apache.qpid.transport.util.Logger; - -/** - * Qpid Class definition. - * A type definition for a manageable object. - * This class is also responsible to manage incoming obejct instance data (configuration & instrumentation). - * How can we handle data before schema is injected into this class? simply we must retain that data in raw format. - * This class has 2 states : - * 1) first state is when schema is not yet injected. In this case the incoming object data is retained as is (in raw format); - * 2) second state is when schema is injected. In this case each injection of data will result in an update / create / delete of - * the corresponding object instance. In addition, the first time the state change, the old retained raw data is cnverted in - * object instance(s). - * - * @author Andrea Gazzarini - */ -class QpidClass -{ - /** - * State interface for this class definition. - * Each state is responsible to handle the injection of the object data. - * - * @author Andrea Gazzarini - */ - interface State - { - /** - * Adds configuration data for the object instance associated to the given object identifier. - * - * @param objectId the object identifier. - * @param rawData the raw configuration data. - */ - void addInstrumentationData (Binary objectId, byte[] rawData); - - /** - * Adds instrumentation data for the object instance associated to the given object identifier. - * - * @param objectId the object identifier. - * @param rawData the raw instrumentation data. - */ - void addConfigurationData (Binary objectId, byte[] rawData); - - /** - * Inject the schema into this class definition. - * - * @param propertyDefinitions - * @param statisticDefinitions - * @param methodDefinitions - * @param eventDefinitions - * @throws UnableToBuildFeatureException when it's not possibile to parse schema and build the class definition. - */ - public void setSchema ( - List> propertyDefinitions, - List> statisticDefinitions, - List methodDefinitions, - List eventDefinitions) throws UnableToBuildFeatureException; - }; - - /** - * This is the initial state of every qpid class. - * The class definition instance is created but its schema has not been injected. - * Incoming configuration & instrumentation data will be stored in raw format because we don't know how to - * parse it until the schema arrives. - * In addition, this state is responsible (when data arrives) to request its schema. - */ - final State _schemaNotRequested = new State() { - - /** - * Stores the incoming data in raw format and request the schema for this class. - * After that a transition to the next state is made. - * - * @param objectId the object instance identifier. - * @param rawData incoming configuration data. - */ - public synchronized void addConfigurationData (Binary objectId, byte[] rawData) - { - schemaRequest(); - QpidManagedObject instance = getObjectInstance(objectId,false); - instance._rawConfigurationData.add(rawData); - _state = _schemaRequestedButNotYetInjected; - } - - /** - * Stores the incoming data in raw format and request the schema for this class. - * After that a transition to the next state is made. - * - * @param objectId the object instance identifier. - * @param rawData incoming instrumentation data. - */ - public synchronized void addInstrumentationData (Binary objectId, byte[] rawData) - { - schemaRequest(); - QpidManagedObject instance = getObjectInstance(objectId,false); - instance._rawConfigurationData.add(rawData); - _state = _schemaRequestedButNotYetInjected; - } - - /** - * This method only throws an illegal state exception because when a schema arrives - * this state is no longer valid. - */ - public void setSchema ( - List> propertyDefinitions, - List> statisticDefinitions, - List methodDefinitions, - List eventDefinitions) throws UnableToBuildFeatureException - { - throw new IllegalStateException("When a schema arrives it's not possible for this class to be in this state."); - } - }; - - /** - * This is the first state of this class definition : the schema is not yet injected so each injection of object data will be - * retained in raw format. - */ - final State _schemaRequestedButNotYetInjected = new State() - { - /** - * Stores the incoming data in raw format. - * - * @param objectId the object instance identifier. - * @param rawData incoming configuration data. - */ - public void addConfigurationData (Binary objectId, byte[] rawData) - { - QpidManagedObject instance = getObjectInstance(objectId,false); - instance._rawConfigurationData.add(rawData); - } - - /** - * Stores the incoming data in raw format. - * - * @param objectId the object instance identifier. - * @param rawData incoming instrumentation data. - */ - public void addInstrumentationData (Binary objectId, byte[] rawData) - { - QpidManagedObject instance = getObjectInstance(objectId,false); - instance._rawInstrumentationData.add(rawData); - } - - /** - * When a schema is injected into this defintiion the following should happen : - * 1) the incoming schema is parsed and the class definition is built; - * 2) the retained raw data is converted into object instance(s) - * 3) the internal state of this class changes; - * - * If someting is wrong during that process the schema is not built and the state don't change. - */ - public synchronized void setSchema ( - List> propertyDefinitions, - List> statisticDefinitions, - List methodDefinitions, - List eventDefinitions) throws UnableToBuildFeatureException - { - - MBeanAttributeInfo [] attributesMetadata = new MBeanAttributeInfo[propertyDefinitions.size()+statisticDefinitions.size()]; - MBeanOperationInfo [] operationsMetadata = new MBeanOperationInfo[methodDefinitions.size()]; - - buildAttributes(propertyDefinitions,statisticDefinitions,attributesMetadata); - buildMethods(methodDefinitions,operationsMetadata); - buildEvents(eventDefinitions); - - _metadata = new MBeanInfo(_name,_name,attributesMetadata,null,operationsMetadata,null); - - // Converting stored object instances into JMX MBean and removing raw instance data. - for (Entry instanceEntry : _objectInstances.entrySet()) - { - Binary objectId = instanceEntry.getKey(); - QpidManagedObject instance = instanceEntry.getValue(); - - for (Iterator iterator = instance._rawInstrumentationData.iterator(); iterator.hasNext();) - { - updateInstanceWithInstrumentationData(instance,iterator.next()); - iterator.remove(); - } - - for (Iterator iterator = instance._rawConfigurationData.iterator(); iterator.hasNext();) - { - updateInstanceWithConfigurationData(instance, iterator.next()); - iterator.remove(); - } - - JMX_SERVICE.registerObjectInstance(instance,_parent.getOwnerId(),_parent.getName(),_name,objectId); - } - _state = _schemaInjected; - } - }; - - /** - * After a schema is built into this definition this is the current state of the class. - */ - final State _schemaInjected = new State() - { - /** - * Updates the configuration state of the object instance associates with the given object identifier. - * - * @param objectId the object identifier. - * @param rawData the configuration data (raw format). - */ - public void addConfigurationData (Binary objectId, byte[] rawData) - { - QpidManagedObject instance = getObjectInstance(objectId,true); - updateInstanceWithConfigurationData(instance, rawData); - } - - /** - * Updates the instrumentation state of the object instance associates with the given object identifier. - * - * @param objectId the object identifier. - * @param rawData the instrumentation data (raw format). - */ - public void addInstrumentationData (Binary objectId, byte[] rawData) - { - QpidManagedObject instance = getObjectInstance(objectId,true); - updateInstanceWithInstrumentationData(instance, rawData); - } - - /** - * Never called when the class definition has this state. - */ - public void setSchema ( - List> propertyDefinitions, - List> statisticDefinitions, - List methodDefinitions, - List eventDefinitions) throws UnableToBuildFeatureException - { - throw new IllegalStateException("When a schema arrives it's not possible for this class to be in this state."); - } - }; - - /** - * MBean used for representing remote broker object instances. - * This is the core component of the QMan domain model - * - * @author Andrea Gazzarini - */ - class QpidManagedObject implements DynamicMBean,MBeanRegistration - { - // After this mbean is registered with the MBean server this collection holds the mbean attributes - private Map _attributes = new HashMap(); - private Binary _objectId; - - // Arrays used for storing raw data before this mbean is registered to mbean server. - List _rawInstrumentationData = new ArrayList(); - List _rawConfigurationData = new ArrayList(); - - /** - * Builds a new managed object with the given object identifier. - * - * @param objectId the object identifier. - */ - QpidManagedObject(Binary objectId) - { - this._objectId = objectId; - } - - /** - * Creates or replace the given attribute. - * Note that this is not part of the management interface of this object instance and therefore will be accessible only - * from within this class. - * It is used to update directly the object attributes. - * - * @param attributeName the name of the attribute. - * @param property newValue the new value of the attribute. - */ - void createOrReplaceAttributeValue(String attributeName, Object newValue) - { - _attributes.put(attributeName, newValue); - } - - /** - * Returns the value of the given attribute.s - * - * @throws AttributeNotFoundException when no attribute is found with the given name. - */ - public Object getAttribute (String attributeName) throws AttributeNotFoundException, MBeanException, ReflectionException - { - if (attributeName == null) - { - throw new RuntimeOperationsException(new IllegalArgumentException("attribute name must not be null")); - } - - if (_properties.containsKey(attributeName) || _statistics.containsKey(attributeName)) - { - return _attributes.get(attributeName); - } else - { - throw new AttributeNotFoundException(attributeName); - } - } - - /** - * Get the values of several attributes of the Dynamic MBean. - * - * @param attributes A list of the attributes to be retrieved. - * - * @return The list of attributes retrieved. - */ - public AttributeList getAttributes (String[] attributes) - { - if (attributes == null) - { - throw new RuntimeOperationsException(new IllegalArgumentException("attributes array must not be null")); - } - - AttributeList result = new AttributeList(attributes.length); - for (int i = 0; i < attributes.length; i++) - { - String attributeName = attributes[i]; - try - { - result.add(new Attribute(attributeName,getAttribute(attributeName))); - } catch(Exception exception) - { - // Already logged. - } - } - return result; - } - - /** - * Returns metadata for this object instance. - */ - // Developer Note : note that this metadata is a member of the outer class definition : in that way we create - // that metadata only once and then it will be shared between all object instances (it's a readonly object) - public MBeanInfo getMBeanInfo () - { - return _metadata; - } - - /** - * Executes an operation on this object instance. - * - * @param actionName the name of the method. - * @param params the method parameters - * @param signature the method signature. - */ - public Object invoke (String actionName, Object[] params, String[] signature) throws MBeanException,ReflectionException - { - // TODO : Overloaded methods - QpidMethod method = _methods.get(actionName); - if (method != null) - { - try - { - methodRequest(_objectId, method, params); - return null; - } catch (ValidationException exception) - { - throw new MBeanException(exception); - } - } else { - throw new ReflectionException(new NoSuchMethodException(actionName)); - } - } - - /** - * Sets the value of the given attribute on this object instance. - * - * @param attribute contains the new value of the attribute. - * @throws AttributeNotFoundException when the given attribute is not found on this object instance. - * @throws InvalidAttributeValueException when the given value is violating one attribute invariant. - */ - public void setAttribute (Attribute attribute) throws AttributeNotFoundException, - InvalidAttributeValueException, MBeanException, ReflectionException - { - QpidProperty property = _properties.get(attribute.getName()); - try - { - property.validate(attribute.getValue()); - } catch(ValidationException exception) - { - throw new InvalidAttributeValueException(exception.getMessage()); - } - throw new RuntimeException("Not yet implemented."); - } - - /** - * Sets the values of several attributes of this MBean. - * - * @param attributes a list of attributes: The identification of the attributes to be set and the values they are to be set to. - * @return The list of attributes that were set, with their new values. - */ - public AttributeList setAttributes (AttributeList attributes) - { - throw new RuntimeException("Not yet implemented."); - } - - /** - * MBean server callback after deregistration. - */ - public void postDeregister () - { - } - - /** - * After the object is registered the raw data is set to null. - * This is done because we no longer need this data : it has already been - * injected into this object instance. - * - * @param registrationDone a flag indicating if the instance has been registered to mbean server. - */ - public void postRegister (Boolean registrationDone) - { - if (registrationDone) - { - _rawConfigurationData = null; - _rawInstrumentationData = null; - } - } - - /** - * MBean server callback before deregistration. - */ - public void preDeregister () throws Exception - { - } - - /** - * MBean server callback before registration. - */ - public ObjectName preRegister (MBeanServer server, ObjectName name) throws Exception - { - return name; - } - } - - private final static Logger LOGGER = Logger.get(QpidClass.class); - private final static JmxService JMX_SERVICE = new JmxService(); - - private final String _name; - private final Binary _hash; - - private final QpidPackage _parent; - - Map _properties = new HashMap(); - Map _statistics = new HashMap(); - private Map _methods = new HashMap(); - - private List _schemaOrderedProperties = new ArrayList(); - private List _schemaOrderedStatistics= new ArrayList(); - private MBeanInfo _metadata; - - private final QpidService _service; - - private int _howManyPresenceBitMasks; - - Map _objectInstances = new HashMap(); - State _state = _schemaNotRequested;; - - /** - * Builds a new class with the given name and package as parent. - * - * @param className the name of the class. - * @param hash the class schema hash. - * @param parentPackage the parent of this class. - */ - QpidClass(String className, Binary hash, QpidPackage parentPackage) - { - this._name = className; - this._parent = parentPackage; - this._hash = hash; - this._service = new QpidService(_parent.getOwnerId()); - LOGGER.debug( - " : Class definition has been built (without schema) for %s::%s.%s", - _parent.getOwnerId(), - _parent.getName(), - _name); - } - - /** - * Adds the configuration data for the object instance associated to the given object identifier. - * - * @param objectId the object identifier. - * @param rawData the raw configuration data. - */ - void addInstrumentationData (Binary objectId, byte[] rawData) - { - LOGGER.debug(" : Incoming instrumentation data for %s::%s.%s.%s", - _parent.getOwnerId(), - _parent.getName(), - _name, - objectId); - _state.addInstrumentationData(objectId, rawData); - } - - /** - * Adds the instrumentation data for the object instance associated to the given object identifier. - * - * @param objectId the object identifier. - * @param rawData the raw instrumentation data. - */ - void addConfigurationData (Binary objectId, byte[] rawData) - { - LOGGER.debug(" : Incoming configuration data for %s::%s.%s.%s", - _parent.getOwnerId(), - _parent.getName(), - _name, - objectId); - _state.addConfigurationData(objectId, rawData); - } - - /** - * Sets the schema for this class definition. - * A schema is basically a metadata description of all properties, statistics, methods and events of this class. - * - * @param propertyDefinitions properties metadata. - * @param statisticDefinitions statistics metadata. - * @param methodDefinitions methods metadata. - * @param eventDefinitions events metadata. - * @throws UnableToBuildFeatureException when some error occurs while parsing the incoming schema. - */ - void setSchema ( - List> propertyDefinitions, - List> statisticDefinitions, - List methodDefinitions, - List eventDefinitions) throws UnableToBuildFeatureException - { - LOGGER.info(" : Incoming schema for %s::%s.%s",_parent.getOwnerId(),_parent.getName(),_name); - _state.setSchema(propertyDefinitions, statisticDefinitions, methodDefinitions, eventDefinitions); - } - - /** - * Internal method used for building attributes definitions. - * - * @param props the map contained in the properties schema. - * @param stats the map contained in the statistics schema. - * @param attributes the management metadata for attributes. - * @throws UnableToBuildFeatureException when it's not possibile to build one attribute definition. - */ - void buildAttributes ( - List> props, - List> stats, - MBeanAttributeInfo[] attributes) throws UnableToBuildFeatureException - { - int index = 0; - int howManyOptionalProperties = 0; - - for (Map propertyDefinition : props) - { - QpidFeatureBuilder builder = QpidFeatureBuilder.createPropertyBuilder(propertyDefinition); - builder.build(); - - QpidProperty property = (QpidProperty) builder.getQpidFeature(); - - howManyOptionalProperties += (property.isOptional()) ? 1 : 0; - - _properties.put(property.getName(),property); - _schemaOrderedProperties.add(property); - attributes[index++]=(MBeanAttributeInfo) builder.getManagementFeature(); - - LOGGER.debug( - " : Property definition for %s::%s.%s has been built.", - _parent.getName(), - _name, - property); - } - - _howManyPresenceBitMasks = (int)Math.ceil((double)howManyOptionalProperties / 8); - - LOGGER.debug( - " : Class %s::%s.%s has %s optional properties.", - _parent.getOwnerId(), - _parent.getName(), - _name, - _howManyPresenceBitMasks); - - for (Map statisticDefinition : stats) - { - QpidFeatureBuilder builder = QpidFeatureBuilder.createStatisticBuilder(statisticDefinition); - builder.build(); - QpidStatistic statistic = (QpidStatistic) builder.getQpidFeature(); - - _statistics.put(statistic.getName(),statistic); - _schemaOrderedStatistics.add(statistic); - attributes[index++]=(MBeanAttributeInfo) builder.getManagementFeature(); - - LOGGER.debug( - " : Statistic definition for %s::%s.%s has been built.", - _parent.getName(), - _name, - statistic); - } - } - - /** - * Returns the object instance associated to the given identifier. - * Note that if the identifier is not associated to any obejct instance, a new one will be created. - * - * @param objectId the object identifier. - * @param registration a flag indicating whenever the (new ) instance must be registered with MBean server. - * @return the object instance associated to the given identifier. - */ - QpidManagedObject getObjectInstance(Binary objectId, boolean registration) - { - QpidManagedObject objectInstance = _objectInstances.get(objectId); - if (objectInstance == null) - { - objectInstance = new QpidManagedObject(objectId); - _objectInstances.put(objectId, objectInstance); - if (registration) - { - JMX_SERVICE.registerObjectInstance(objectInstance,_parent.getOwnerId(),_parent.getName(),_name,objectId); - } - } - return objectInstance; - } - - /** - * Internal method used for building event statistics defintions. - * - * @param definitions the properties map contained in the incoming schema. - * @throws UnableToBuildFeatureException when it's not possibile to build one or more definitions. - */ - void buildEvents (List eventDefinitions) - { - // TODO - } - - /** - * Internal method used for building method defintiions. - * - * @param definitions the properties map contained in the incoming schema. - * @param operationsMetadata - * @throws UnableToBuildFeatureException when it's not possibile to build one or more definitions. - */ - void buildMethods (List definitions, MBeanOperationInfo[] operationsMetadata) throws UnableToBuildFeatureException - { - int index = 0; - for (MethodOrEventDataTransferObject definition: definitions) - { - QpidFeatureBuilder builder = QpidFeatureBuilder.createMethodBuilder(definition); - builder.build(); - operationsMetadata [index++]= (MBeanOperationInfo) builder.getManagementFeature(); - QpidMethod method = (QpidMethod) builder.getQpidFeature(); - _methods.put(method.getName(),method); - } - } - - private void schemaRequest() - { - ByteBuffer buffer = ByteBuffer.allocate(100); - ManagementEncoder encoder = new ManagementEncoder(buffer); - buffer.put(Protocol.SCHEMA_REQUEST_FIRST_FOUR_BYTES); - - // TODO - encoder.writeSequenceNo(1000); - encoder.writeStr8(_parent.getName()); - encoder.writeStr8(_name); - _hash.encode(encoder); - buffer.rewind(); - try - { - _service.connect(); - _service.sendCommandMessage(buffer); - _service.sync(); - } catch (Exception exception) - { - exception.printStackTrace(); - // TODO - // Log.logSchemaRequestNotSent(exception, - // _parent.getOwnerId(),_parent.getName(), _name); - } finally - { - _service.close(); - } - } - - /** - * Header (opcode='M') - * ObjectId of target object (128 bits) - * Package name (str8) - * Class name (str8) - * Class hash (bin128) - * Method name (str8) [as defined in the schema] - * Now encode all input ("I") and i/o (IO) arguments in the order in which they are defined in the schema. - * (i.e. make one pass over the argument list and encode arguments that are either input or inptu/output). - - * @param objectId - * @param method - * @param parameters - * @throws ValidationException - */ - private void methodRequest(Binary objectId,QpidMethod method,Object [] parameters) throws ValidationException - { - ByteBuffer buffer = ByteBuffer.allocate(1000); - ManagementEncoder encoder = new ManagementEncoder(buffer); - buffer.put(Protocol.METHOD_REQUEST_FIRST_FOUR_BYTES); - encoder.writeSequenceNo(0); - objectId.encode(encoder); - encoder.writeStr8(_parent.getName()); - encoder.writeStr8(_name); - _hash.encode(encoder); - encoder.writeStr8(method.getName()); - method.encodeParameters(parameters,encoder); - - buffer.rewind(); - try - { - _service.connect(); - _service.sendCommandMessage(buffer); - //_service.sync(); - } catch (Exception exception) - { - exception.printStackTrace(); - // TODO - // Log.logSchemaRequestNotSent(exception, - // _parent.getOwnerId(),_parent.getName(), _name); - } finally - { - _service.close(); - } - } - - /** - * Updates the given obejct instance with the given incoming configuration data. - * - * @param instance the managed object instance. - * @param rawData the incoming configuration data which contains new values for instance properties. - */ - private void updateInstanceWithConfigurationData(QpidManagedObject instance,byte [] rawData) - { - ManagementDecoder decoder = new ManagementDecoder(); - decoder.init(ByteBuffer.wrap(rawData)); - - byte [] presenceBitMasks = decoder.readBytes(_howManyPresenceBitMasks); - for (QpidProperty property : _schemaOrderedProperties) - { - try { - Object value = property.decodeValue(decoder,presenceBitMasks); - instance.createOrReplaceAttributeValue(property.getName(),value); - } catch(Exception ignore) { - LOGGER.error("Unable to decode value for %s::%s::%s", _parent.getName(),_name,property.getName()); - } - } - } - - /** - * Updates the given object instance with the given incoming instrumentation data. - * - * @param instance the managed object instance. - * @param rawData the incoming instrumentation data which contains new values for instance properties. - */ - private void updateInstanceWithInstrumentationData(QpidManagedObject instance,byte [] rawData) - { - ManagementDecoder decoder = new ManagementDecoder(); - decoder.init(ByteBuffer.wrap(rawData)); - - for (QpidStatistic statistic : _schemaOrderedStatistics) - { - try { - Object value = statistic.decodeValue(decoder); - instance.createOrReplaceAttributeValue(statistic.getName(),value); - } catch(Exception ignore) { - LOGGER.error("Unable to decode value for %s::%s::%s", _parent.getName(),_name,statistic.getName()); - } - } - } - - @Override - public String toString () - { - return new StringBuilder() - .append(_parent.getOwnerId()) - .append("::") - .append(_parent.getName()) - .append("::") - .append(_name) - .toString(); - } - - /** - * Removes the object instance associated to the given identifier. - * - * @param objectId the object identifier. - */ - void removeObjectInstance (Binary objectId) - { - QpidManagedObject toBeRemoved = _objectInstances.remove(objectId); - if (toBeRemoved != null) - { - JMX_SERVICE.unregisterObjectInstance(_parent.getOwnerId(),_parent.getName(),_name,toBeRemoved._objectId); - } - } - - /** - * Deregisters all the object instances and release all previously acquired resources. - */ - void releaseResources () - { - for (Iterator iterator = _objectInstances.keySet().iterator(); iterator.hasNext();) - { - Binary objectId = iterator.next(); - JMX_SERVICE.unregisterObjectInstance(_parent.getOwnerId(),_parent.getName(),_name,objectId); - iterator.remove(); - LOGGER.debug( - "%s.%s.%s object instance has been removed from broker %s", - _parent.getName(), - _name,objectId, - _parent.getOwnerId()); - } - _service.close(); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidEvent.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidEvent.java deleted file mode 100644 index 200791bb93..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidEvent.java +++ /dev/null @@ -1,26 +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.domain.model; - -class QpidEvent extends QpidFeature -{ - // NOT YET IMPLEMENTED -} diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeature.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeature.java deleted file mode 100644 index 5fccb0a858..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeature.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.domain.model; - -/** - * Layer Supertype for all qpid management features. - * - * @author Andrea Gazzarini - */ -abstract class QpidFeature -{ - /** The name of the feature. */ - protected String _name; - - /** - * The description of the feature. - */ - protected String _description; - - /** - * Returns the description of this feature. - * - * @return the description of this feature. - */ - String getDescription () - { - return _description; - } - - /** - * Sets the description for this feature. - * - * @param description the description for this feature. - */ - void setDescription (String description) - { - this._description = description; - } - - /** - * Returns the name of the feature. - * - * @return the name of the feature. - */ - String getName () - { - return _name; - } - - /** - * Sets the name for this feature. - * - * @param name the name of this feature. - */ - void setName (String name) - { - this._name = name; - } - - /** - * Returns the name of the feature. - * - * @return the name of the feature. - */ - @Override - public String toString () - { - return _name; - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeatureBuilder.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeatureBuilder.java deleted file mode 100644 index 4bac16452c..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeatureBuilder.java +++ /dev/null @@ -1,444 +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.domain.model; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.management.MBeanAttributeInfo; -import javax.management.MBeanFeatureInfo; -import javax.management.MBeanOperationInfo; -import javax.management.MBeanParameterInfo; - -import org.apache.qpid.management.configuration.Configuration; -import org.apache.qpid.management.configuration.UnknownTypeCodeException; -import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; - -/** - * A builder used to parse incoming schema message and therefore to build a feature (property, statistic, method, event) - * definition. - * In order to set up the correct state for this builder, clients must create an instance of this class - * The product of the builder will be a QpidFeature and a JMX Managemtn feature used for describing that feature in a - * JMX environment. So, for example, for building a property definition client code should be : - * - *
- QpidFeatureBuilder builder = QpidFeature.createPropertyBuilder(...); - *
- builder.build(); - *
- QpidProperty property = (QpidProperty) builder.getQpidFeature(); - *
- MBeanAttributeInfo managementAttributeInfo = (MBeanAttributeInfo)builder.getManagementFeature(); - * - *
N.B.: a builder instance is not supposed to be reused. One instance for one feature! - * - * @author Andrea Gazzarini - */ -class QpidFeatureBuilder -{ - - static enum Attribute { - name,type,access,index,optional,unit,min,max,maxlen,desc,dir,argCount; - }; - - private List _mandatoryAttributes = new ArrayList(); - - /** - * Builder state for this class. - * Each concrete implementor is a builder for a specific feature. - * using the appropriate factory method. - * - * @author Andrea Gazzarini - */ - interface State { - void build() throws UnableToBuildFeatureException; - } - - /** - * Builder used for building property definition. - */ - final State _propertyBuilder = new State() { - - /** - * Builds a property definition as well a management attribute feature. - */ - public void build () throws UnableToBuildFeatureException - { - QpidProperty property = new QpidProperty(); - try { - int optionalIndex = 0; - for (Entry propertyAttribute : _featureDefinition.entrySet()) - { - Attribute attribute = Attribute.valueOf(propertyAttribute.getKey()); - switch(attribute) - { - case name : - { - property.setName(String.valueOf(propertyAttribute.getValue())); - break; - } - case access : - { - int code = (Integer)propertyAttribute.getValue(); - property.setAccessMode(Configuration.getInstance().getAccessMode(code)); - break; - } - case unit : - { - property.setUnit(String.valueOf(propertyAttribute.getValue())); - break; - } - case min : - { - property.setMinValue((Integer)propertyAttribute.getValue()); - break; - } - case max : - { - property.setMaxValue((Integer)propertyAttribute.getValue()); - break; - } - case maxlen : - { - property.setMaxLength((Integer)propertyAttribute.getValue()); - break; - } - case desc : - { - property.setDescription(String.valueOf(propertyAttribute.getValue())); - break; - } - case type : - { - int code = (Integer) propertyAttribute.getValue(); - property.setType(Configuration.getInstance().getType(code)); - break; - } - case index : - { - break; - } - case optional : - { - int code = (Integer) propertyAttribute.getValue(); - if (code == 1) - { - property.markAsOptional(optionalIndex); - optionalIndex++; - } - break; - } - } - _mandatoryAttributes.remove(attribute); - } - } catch(Exception exception) - { - throw new UnableToBuildFeatureException(exception,property.getName()); - } - - if (!_mandatoryAttributes.isEmpty()) - { - throw new MissingFeatureAttributesException(_mandatoryAttributes); - } - - _managementFeatureInfo = new MBeanAttributeInfo( - property.getName(), - property.getJavaType().getName(), - property.getDescription(), - true, - property.getAccessMode()==AccessMode.RW, - false); - _qpidFeature = property; - } - }; - - final State _statisticBuilder = new State() - { - public void build () throws UnableToBuildFeatureException - { - QpidStatistic statistic = new QpidStatistic(); - try - { - for (Entry statisticAttribute : _featureDefinition.entrySet()) - { - Attribute attribute = Attribute.valueOf(statisticAttribute.getKey()); - switch(attribute) - { - case name : - { - statistic.setName(String.valueOf(statisticAttribute.getValue())); - break; - } - case unit : - { - statistic.setUnit(String.valueOf(statisticAttribute.getValue())); - break; - } - case desc : - { - statistic.setDescription(String.valueOf(statisticAttribute.getValue())); - break; - } - case type : - { - int code = (Integer) statisticAttribute.getValue(); - statistic.setType(Configuration.getInstance().getType(code)); - break; - } - } - _mandatoryAttributes.remove(attribute); - } - } catch(Exception exception) - { - throw new UnableToBuildFeatureException(exception,statistic.getName()); - } - - if (!_mandatoryAttributes.isEmpty()) - { - throw new MissingFeatureAttributesException(_mandatoryAttributes); - } - - _managementFeatureInfo = new MBeanAttributeInfo( - statistic.getName(), - statistic.getJavaType().getName(), - statistic.getDescription(), - true, - false, - false); - _qpidFeature = statistic; - } - }; - - /** - * Builder used for building a statistic definition. - */ - final State _argumentBuilder = new State() - { - /** - * Builds a property definition as well a management attribute feature. - */ - public void build () throws UnableToBuildFeatureException - { - QpidArgument argument = new QpidArgument(); - for (Entry argumentAttribute : _featureDefinition.entrySet()) - { - String key = argumentAttribute.getKey(); - if ("default".equals(key)) - { - argument.setDefaultValue(argumentAttribute.getValue()); - } else { - Attribute attribute = Attribute.valueOf(key); - switch (attribute) - { - case name : - { - argument.setName((String)argumentAttribute.getValue()); - break; - } - case desc : - { - argument.setDescription((String)argumentAttribute.getValue()); - break; - } - case type : - { - try - { - argument.setType(Configuration.getInstance().getType((Integer)argumentAttribute.getValue())); - break; - } catch(UnknownTypeCodeException exception) - { - throw new UnableToBuildFeatureException(exception,argument.getName()); - } - } - case dir : - { - argument.setDirection((String)argumentAttribute.getValue()); - break; - } - case unit : - { - argument.setUnit((String)argumentAttribute.getValue()); - break; - - } - } - } - } - - if (!_mandatoryAttributes.isEmpty()) - { - throw new MissingFeatureAttributesException(_mandatoryAttributes); - } - - _qpidFeature = argument; - _managementFeatureInfo = new MBeanParameterInfo( - argument.getName(), - argument.getJavaType().getName(), - argument.getDescription()); - } - }; - - final State _methodBuilder = new State() - { - public void build () throws UnableToBuildFeatureException - { - Map definition = _methodOrEventDefinition.getDefinition(); - String name = (String)definition.get(Attribute.name.name()); - if (name == null) - { - throw new MissingFeatureAttributesException(_mandatoryAttributes); - } - - QpidMethod method = new QpidMethod((String)definition.get("name"),(String) definition.get("desc")); - - List> args = _methodOrEventDefinition.getArgumentsDefinitions(); - - List signature = new LinkedList(); - - for (Map argumentDefinition : args) - { - QpidFeatureBuilder builder = QpidFeatureBuilder.createArgumentBuilder(argumentDefinition); - builder.build(); - - QpidArgument argument = (QpidArgument) builder.getQpidFeature(); - method.addArgument(argument); - if (argument.isInput()) - { - signature.add((MBeanParameterInfo) builder.getManagementFeature()); - } - } - - _qpidFeature = method; - _managementFeatureInfo = new MBeanOperationInfo( - method.getName(), - method.getDescription(), - (MBeanParameterInfo[])signature.toArray(new MBeanParameterInfo[signature.size()]), - void.class.getName(), - MBeanOperationInfo.ACTION); - } - }; - - final State _eventBuilder = new State() - { - public void build () throws UnableToBuildFeatureException - { - } - }; - - private MBeanFeatureInfo _managementFeatureInfo; - private QpidFeature _qpidFeature; - private final Map _featureDefinition; - private final MethodOrEventDataTransferObject _methodOrEventDefinition; - private State _state; - - static QpidFeatureBuilder createPropertyBuilder(Map propertyDefinition) - { - QpidFeatureBuilder result = new QpidFeatureBuilder(propertyDefinition); - result._state = result._propertyBuilder; - result._mandatoryAttributes.add(Attribute.name); - result._mandatoryAttributes.add(Attribute.access); - result._mandatoryAttributes.add(Attribute.type); - result._mandatoryAttributes.add(Attribute.optional); - result._mandatoryAttributes.add(Attribute.index); - return result; - } - - static QpidFeatureBuilder createStatisticBuilder(Map statisticDefinition) - { - QpidFeatureBuilder result = new QpidFeatureBuilder(statisticDefinition); - result._state = result._statisticBuilder; - result._mandatoryAttributes.add(Attribute.name); - result._mandatoryAttributes.add(Attribute.type); - return result; - } - - static QpidFeatureBuilder createEventBuilder(Map eventDefinition) - { - QpidFeatureBuilder result = new QpidFeatureBuilder(eventDefinition); - result._state = result._eventBuilder; - return result; - } - - static QpidFeatureBuilder createMethodBuilder(MethodOrEventDataTransferObject methodDefinition) - { - QpidFeatureBuilder result = new QpidFeatureBuilder(methodDefinition); - result._state = result._methodBuilder; - result._mandatoryAttributes.add(Attribute.name); - return result; - } - - private static QpidFeatureBuilder createArgumentBuilder(Map argumentDefinition) - { - QpidFeatureBuilder result = new QpidFeatureBuilder(argumentDefinition); - result._state = result._argumentBuilder; - return result; - } - - - /** - * Builds new builder with the given data. - * This constructor is used for building properties, statistics and arguments. - * - * @param definition the feature definition data. - */ - private QpidFeatureBuilder(Map definition) - { - this._featureDefinition = definition; - this._methodOrEventDefinition = null; - } - - /** - * Builds new builder with the given data. - * This constructor is used for building properties, statistics and arguments. - * - * @param definition the feature definition data. - */ - private QpidFeatureBuilder(MethodOrEventDataTransferObject definition) - { - this._featureDefinition = null; - this._methodOrEventDefinition = definition; - } - - /** - * Returns the just built qpid feature. - * - * @return the qpid feature. - */ - QpidFeature getQpidFeature() - { - return _qpidFeature; - } - - /** - * Return the jmx metadata for the built feature. - * - * @return the jmx metadata for the built feature. - */ - MBeanFeatureInfo getManagementFeature() - { - return _managementFeatureInfo; - } - - void build() throws UnableToBuildFeatureException - { - _state.build(); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidMethod.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidMethod.java deleted file mode 100644 index 4d4918e45f..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidMethod.java +++ /dev/null @@ -1,103 +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.domain.model; - -import java.util.LinkedList; -import java.util.List; - -import org.apache.qpid.transport.codec.ManagementEncoder; - -/** - * Qpid method definition. - * An entity describing an invocation that can be made on a managed object instance. - * - * @author Andrea Gazzarini - */ -class QpidMethod extends QpidFeature -{ - /** Argument list */ - List arguments = new LinkedList(); - - /** - * Builds a new qpid method definition with the given name and description. - * - * @param name the method name. - * @param description the method description. - */ - QpidMethod(String name, String description) - { - this._name = name; - this._description = description; - } - - /** - * Adds an argument to this method. - * - * @param argument the new argument to be added. - */ - void addArgument(QpidArgument argument) - { - arguments.add(argument); - } - - /** - * Returns a string representation of this method. - * The result format is (argType1 argName1 (Direction), argType2 argName2 (Direction), etc...) - * - * @return a string representation of this method. - */ - @Override - public String toString () - { - StringBuilder builder = new StringBuilder() - .append(_name) - .append('('); - - for (QpidArgument argument : arguments) - { - builder.append(argument).append(','); - } - - builder.append(')'); - return builder.toString(); - } - - /** - * Encodes the given parameter values according to this method arguments definitions. - * Also provide a validation of the given values according to the invariants defined for each argument. - * Note that only Input/Output and Output parameters are encoded. - * - * @param parameters the parameters values. - * @param encoder the encoder used for encoding. - * @throws ValidationException when one of the given values is violating an argument invariant. - */ - void encodeParameters (Object[] parameters, ManagementEncoder encoder) throws ValidationException - { - int index = 0; - for (QpidArgument argument : arguments) - { - if (argument.getDirection() != Direction.O) - { - argument.validateAndEncode(parameters[index++],encoder); - } - } - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java deleted file mode 100644 index 524121afe5..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java +++ /dev/null @@ -1,227 +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.domain.model; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; -import org.apache.qpid.management.domain.model.type.Binary; - -/** - * Qpid package definition. - * A grouping of class definitions that are related to a single software component. - * The package concept is used to extend the management schema beyond just the QPID software components. - * The name is prefixed with "Qpid" for avoiding name conficts with java.lang.Package. - * - * @author Andrea Gazzarini - */ -final class QpidPackage -{ - /** - * Qpid class identity. - * Each qpid class is uniquely identifier by its name and schema-hash. - * The schema hash is an MD5 checksum of the schema for a class. - * It is there so we can support the case where two different versions of the same class are present at the same time. - * - * @author Andrea Gazzarini - */ - class QpidClassIdentity { - final String name; - final Binary hash; - - /** - * Builds a new class identity with the given name and hash. - * - * @param name the class name. - * @param hash is an MD5 checksum of the schema of this outer class. - */ - QpidClassIdentity(String name,Binary hash) { - this.name = name; - this.hash = hash; - } - - @Override - public int hashCode () - { - return name.hashCode()+hash.hashCode(); - } - - @Override - public boolean equals (Object obj) - { - QpidClassIdentity identity = (QpidClassIdentity) obj; - return name.equals(identity.name) && hash.equals(identity.hash); - } - } - - private String _name; - private DomainModel _parent; - private Map _classes = new HashMap(); - - /** - * Builds a new package with the supplied name. - * - * @param name the name of the package. - */ - QpidPackage(String name, DomainModel parent) - { - this._name = name; - this._parent = parent; - } - - /** - * Returns the identifier of the broker which contains this package. - * @return - */ - UUID getOwnerId() - { - return _parent.getBrokerId(); - } - - /** - * Returns the name of this package. - * - * @return the name of this package. - */ - String getName () - { - return _name; - } - - /** - * Adds a class definition to this package. - * The class will be added only if its definition doesn't already exists. - * - * @param className the name of the class. - * @param classHash the class schema hash. - * @param properties the properties of the class. - * @param statistics the statistics of the class. - * @param methods the methods of the class. - * @param events the events of the class. - * - * @throws UnableToBuildFeatureException when the class definition cannot be built due to a feature build failure. - */ - void addClassDefinition ( - String className, - Binary classHash, - List> properties, - List> statistics, - List methods, - List events) throws UnableToBuildFeatureException - { - getQpidClass(className,classHash,true).setSchema(properties,statistics,methods, events); - } - - /** - * Returns true if this package contains the given class definition. - * - * @param className the name of the class. - * @return true if this package contains the class definition, false otherwise. - */ - boolean alreadyContainsClassDefinition (String className, Binary hash) - { - return _classes.containsKey(new QpidClassIdentity(className,hash)); - } - - /** - * Injects into a class the given object instance instrumentation data. - * - * @param className the of the class the injected object data belongs to. - * @param objectId the object identifier. - * @param rawData the instrumentation data (in raw format). - */ - void setObjectInstanceInstrumentationRawData (String className, Binary classHash,Binary objectId, byte[] rawData) - { - getQpidClass(className, classHash,true).addInstrumentationData(objectId,rawData); - } - - /** - * Injects into a class the given object instance configuration data. - * - * @param className the of the class the injected object data belongs to. - * @param objectId the object identifier. - * @param rawData the configuration data (in raw format). - */ - void setObjectInstanceConfigurationRawData (String className,Binary classHash, Binary objectId, byte[] rawData) - { - getQpidClass(className,classHash,true).addConfigurationData(objectId,rawData); - } - - /** - * Returns the definition of the class with given name. - * - * @param className the name of the class. - * @param hash the class hash. - * @param store a flag indicating if a just created class must be stored or not. - * @return the definition of the class with given name. - */ - QpidClass getQpidClass(String className, Binary hash, boolean store) - { - QpidClassIdentity identity = new QpidClassIdentity(className,hash); - QpidClass classDefinition = _classes.get(identity); - if (classDefinition == null) - { - classDefinition = new QpidClass(className, hash,this); - if (store) - { - _classes.put(identity,classDefinition); - } - } - return classDefinition; - } - - /** - * Returns a string representation of this class. - * That is, this method returns the simple name (not FQN) of this class. - */ - @Override - public String toString () - { - return _name; - } - - /** - * Removes the object instance associated to the given parameters. - * - * @param className the class definition of the object instance. - * @param classHash the class hash - * @param objectId the object identifier. - */ - void removeObjectInstance (String className, Binary classHash, Binary objectId) - { - QpidClass qpidClass = getQpidClass(className,classHash,false); - qpidClass.removeObjectInstance(objectId); - } - - /** - * Releases all previously acquired resources of this package. - */ - void releaseResources () - { - for (QpidClass qpidClass : _classes.values()) - { - qpidClass.releaseResources(); - } - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidProperty.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidProperty.java deleted file mode 100644 index 8b2544af1c..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidProperty.java +++ /dev/null @@ -1,295 +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.domain.model; - -import java.lang.reflect.Constructor; - -import org.apache.qpid.management.configuration.Configuration; -import org.apache.qpid.management.domain.model.type.Type; -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.util.Logger; - -/** - * Qpid property definition. - * - * @author Andrea Gazzarini - */ -class QpidProperty extends QpidAttribute -{ - private final static Logger LOGGER = Logger.get(QpidProperty.class); - - private final static int [] MASKS = {1,2,4,8,16,32,64,128}; - - /** - * Decoder interface used for decoding incomng values for this property. - * - * @author Andrea Gazzarini - */ - interface Decoder - { - Object decodeValue(ManagementDecoder decoder,byte [] presenceBitMasks); - } - - /** - * Decoder used for decoding incoming values for this optional property. - */ - final Decoder _optionalPropertyDecoder = new Decoder() { - - public Object decodeValue (ManagementDecoder decoder, byte[] presenceBitMasks) - { - return ((presenceBitMasks[_optionalIndex/8] & MASKS[_maskIndex]) != 0) - ? QpidProperty.this.decodeValue(decoder) - : null; - } - }; - - /** - * Decoder used for decoding incoming values for this mandatory property. - */ - final Decoder _mandatoryPropertyDecoder = new Decoder() { - - public Object decodeValue (ManagementDecoder decoder, byte[] presenceBitMasks) - { - return QpidProperty.this.decodeValue(decoder); - } - }; - - - /** - * Null object used to perform a dummy validation. - * This is the default validator installed at creation time. - */ - final static IValidator EMPTY_VALIDATOR = new IValidator() - { - public void validate (Object value) throws ValidationException - { - // Nothing to do here. - } - }; - - /** - * Validator responsible for validating strings. - * At the moment the only constraint that should be applied to a string feature is the "max length" - */ - class StringValidator implements IValidator - { - public void validate (Object value) throws ValidationException - { - if ((_maxLength != Integer.MIN_VALUE) && (value != null)){ - int length = value.toString().length(); - if (length > _maxLength) { - throw new ValidationException( - ValidationException.MAX_LENGTH, - _maxLength, - _name, - length); - } - } - } - }; - - /** - * Validator responsible for validating numbers. - */ - class NumberValidator implements IValidator - { - public void validate (Object value) throws ValidationException - { - if (value != null) { - double numericValue = ((Number)value).doubleValue(); - if (_minValue != Integer.MIN_VALUE && numericValue < _minValue) { - throw new ValidationException( - ValidationException.MIN_VALUE, - _minValue, - _name, - numericValue); - } - - if (_maxValue != Integer.MIN_VALUE && numericValue > _maxValue) { - throw new ValidationException( - ValidationException.MAX_VALUE, - _maxValue, - _name, - numericValue); - } - } - } - }; - - private AccessMode _accessMode; - private int _minValue = Integer.MIN_VALUE; - private int _maxValue = Integer.MIN_VALUE; - private int _maxLength = Integer.MIN_VALUE; - - private int _optionalIndex; - private int _maskIndex; - - Decoder _decoder = _mandatoryPropertyDecoder; - - private IValidator _validator = EMPTY_VALIDATOR; - - /** - * Validates the given value according to the current validator. - * It delegates the validation to the current installed validator. - * - * @param value the value of this qpid property. - * @throws ValidationException when the given value is violating the current validator constraints. - */ - void validate(Object value) throws ValidationException { - _validator.validate(value); - } - - /** - * Sets the type of this property. - * In addition this method tries to detect if a validator has been associated with the type. - * If no validator is found then the default validator will be used; that is : no validator will be performed on this - * property. - * - * @param type the type of this property. - */ - void setType (Type type) - { - super.setType(type); - try { - Class validatorClass = Class.forName(Configuration.getInstance().getValidatorClassName(type)); - Constructor validatorConstructor = validatorClass.getDeclaredConstructor(QpidProperty.class); - _validator = (IValidator) validatorConstructor.newInstance(this); - LOGGER.debug("Validator %s for type %s successfully installed." ,validatorClass.getName(), type); - } catch(Exception exception) { - _validator = EMPTY_VALIDATOR; - LOGGER.debug("No validator was found for type %s. The default (empty) validator will be used." , type); - } - } - - /** - * Gets the value of this property according to its type definition. - * - * @param decoder the decoder used to extract the value. - * @return the value of this feature according to its type definition - */ - Object decodeValue(ManagementDecoder decoder,byte [] presenceBitMasks) - { - return _decoder.decodeValue(decoder, presenceBitMasks); - } - - /** - * Sets access mode for this property. - * - * @param accessMode the access mode for this property. - */ - void setAccessMode (AccessMode accessMode) - { - this._accessMode = accessMode; - } - - /** - * Gets the minimum allowed value for this property. - * - * @return the minimum allowed value for this property. - */ - int getMinValue () - { - return _minValue; - } - - /** - * Sets the minimum allowed value for this property. - * - * @param minValue the minimum allowed value for this property. - */ - void setMinValue (int minValue) - { - this._minValue = minValue; - } - - /** - * Gets the maximum allowed value for this property. - * - * @return the maximum allowed value for this property. - */ - int getMaxValue () - { - return _maxValue; - } - - /** - * Sets the masimum allowed value for this property. - * - * @param maxValue the maximum allowed value for this property. - */ - void setMaxValue (int maxValue) - { - this._maxValue = maxValue; - } - - /** - * Gets the max length value for this property. - * - * @return the max length value for this property. - */ - int getMaxLength () - { - return _maxLength; - } - - /** - * Sets the max length value for this property. - * - * @param maxLength the max length value for this property. - */ - void setMaxLength (int maxLength) - { - this._maxLength = maxLength; - } - - /** - * Gets the description of this property. - * - * @return the description of this property. - */ - AccessMode getAccessMode () - { - return _accessMode; - } - - /** - * Marks this property as optional. - * - * @param optional the optional attribute value for this property. - * @param index the index of this optional property - */ - void markAsOptional (int index) - { - this._optionalIndex = index; - this._maskIndex = (_optionalIndex >= 8) ? _optionalIndex-8 : _optionalIndex; - _decoder = _optionalPropertyDecoder; - } - - /** - * Returns true if this property is marked as optional. - * - * @return true if this property is marked as optional, false otherwise. - */ - boolean isOptional () - { - return _decoder == _optionalPropertyDecoder; - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidStatistic.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidStatistic.java deleted file mode 100644 index 37a652c098..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/QpidStatistic.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.domain.model; - -/** - * Qpid statistic definition. - * - * A statistic is a typed member of a class which represents an instrumentation attribute of the class. - * Statistics are always read-only in nature and tend to change rapidly. - * - * @author Andrea Gazzarini - */ -class QpidStatistic extends QpidAttribute -{ - // EMPTY CLASS : Statistic metadata are all defined in superclasses. -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/UnableToBuildFeatureException.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/UnableToBuildFeatureException.java deleted file mode 100644 index 59721240d0..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/UnableToBuildFeatureException.java +++ /dev/null @@ -1,51 +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.domain.model; - -/** - * Thrown when a feature (property, statistic, method or event) definition cannot be built due to schema parsing errors. - * - * @author Andrea Gazzarini - */ -public class UnableToBuildFeatureException extends Exception -{ - private static final long serialVersionUID = 5180111828887602836L; - - /** - * Builds a new UnableToBuildFeatureException with the specified cause. - * - * @param exception the exception cause. - */ - UnableToBuildFeatureException(Exception exception, String featureName) - { - super( (featureName != null) ? featureName : "Not available" ,exception); - } - - /** - * Builds a new UnableToBuildFeatureException with the specified message. - * - * @param message the detail message. - */ - UnableToBuildFeatureException(String message) - { - super(message); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/ValidationException.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/ValidationException.java deleted file mode 100644 index 3b117e5b9d..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/ValidationException.java +++ /dev/null @@ -1,105 +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.domain.model; - -/** - * Thrown when an attempt is made in order to update / change the state of an object and a constraint on that state - * is violated. - * - * @author Andrea Gazzarini - */ -public class ValidationException extends Exception -{ - private static final long serialVersionUID = -5218828669655586205L; - - public final static String MAX_LENGTH = "Max Length"; - public final static String MAX_VALUE = "Max Value"; - public final static String MIN_VALUE = "Min Value"; - - private final String _featureName; - private final Object _featureValue; - - private final Number _constraintValue; - private final String _constraintName; - - /** - * Builds a new validation exception with the specified parameters. - * - * @param constraintName the name of the violated constraint. - * @param constraintValue the value of the violated constraint. - * @param featureName the name of the violating feature. - * @param featureValue the value of the violating feature. - */ - ValidationException(String constraintName,Number constraintValue, String featureName,Object featureValue) - { - super(String.format( - "Property constraint violation : " + - "%s allowed for property %s is %s but received value was %s", - constraintName, - featureName, - constraintValue, - featureValue)); - this._constraintName = constraintName; - this._constraintValue = constraintValue; - this._featureName = featureName; - this._featureValue = featureValue; - } - - /** - * Returns the value of the violating feature. - * - * @return the value of the violating feature. - */ - public Object getFeatureValue () - { - return _featureValue; - } - - /** - * Returns the name of the violating feature. - * - * @return the name of the violating feature. - */ - public String getFeatureName() - { - return _featureName; - } - - /** - * Returns the value of the violated constraint. - * - * @return the value of the violated constraint. - */ - public Number getConstraintValue () - { - return _constraintValue; - } - - /** - * Returns the name of the violated constraint. - * - * @return the name of the violated constraint. - */ - public String getConstraintName () - { - return _constraintName; - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/AbsTime.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/AbsTime.java deleted file mode 100644 index 27bfa62e2b..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/AbsTime.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class AbsTime extends Type -{ - public AbsTime() - { - super(Long.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return decoder.readUint64(); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeUint64((Long)value); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java deleted file mode 100644 index d6d25534d8..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java +++ /dev/null @@ -1,129 +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.domain.model.type; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.UUID; - -import org.apache.qpid.transport.codec.ManagementEncoder; - -/** - * It is a simple wrapper for a byte array (for example a 128bin). - * It is used to let QMan deal with an object instead of an array. - * - * @author Andrea Gazzarini - */ -public final class Binary implements Serializable -{ - private static final long serialVersionUID = -6865585077320637567L; - - // instance identifider. - private final UUID uuid; - - // Marker internal (empty) interface - private interface State extends Serializable{} - - /** - * Internal state of this object used to denote the situation when the hashcode() method has never been called. - * After the hashcode has been computed this class switches the state of the outer object to the next state. - */ - State hashCodeNotYetComputed = new State() - { - private static final long serialVersionUID = 221632033761266959L; - - @Override - public int hashCode () - { - hashCode = Arrays.hashCode(bytes); - state = hashCodeAlreadyComputed; - return hashCode; - } - }; - - /** - * Internal state of this object used to denote the situation where the hashcode() method has already been computed. - * Simply it returns the just computed value for the hashcode. - */ - State hashCodeAlreadyComputed = new State() - { - private static final long serialVersionUID = 221632033761266959L; - - @Override - public int hashCode () - { - return hashCode; - } - }; - - private final byte [] bytes; - private int hashCode; - - /** Current state (hashcode computation). */ - State state = hashCodeNotYetComputed; - - /** - * Builds a new binary with the given byte array. - * - * @param bytes the wrapped data. - */ - public Binary(byte [] bytes) - { - this.bytes = bytes; - uuid = UUID.randomUUID(); - } - - @Override - public int hashCode () - { - return state.hashCode(); - } - - @Override - public boolean equals (Object obj) - { - try - { - Binary binary = (Binary)obj; - return Arrays.equals(bytes, binary.bytes); - } catch (Exception exception) - { - return false; - } - } - - /** - * Encodes the content (wrapped byte array) of this instance using the given encoder. - * - * @param encoder the encoder used to encode instance content. - */ - public void encode(ManagementEncoder encoder) - { - encoder.writeBin128(bytes); - } - - // TODO - @Override - public String toString () - { - return uuid.toString(); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Boolean.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Boolean.java deleted file mode 100644 index 89867bd4c4..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Boolean.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class Boolean extends Type -{ - public Boolean() - { - super(java.lang.Boolean.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return (decoder.readUint8() == 1); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeUint8( ((java.lang.Boolean)value) ? (short)1 : (short)0); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/DeltaTime.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/DeltaTime.java deleted file mode 100644 index 85724f34c8..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/DeltaTime.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class DeltaTime extends Type -{ - public DeltaTime() - { - super(Long.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return decoder.readUint64(); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeUint64((Long)value); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Map.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Map.java deleted file mode 100644 index f7d6101d3f..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Map.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class Map extends Type -{ - public Map() - { - super(java.util.Map.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return decoder.readMap(); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeMap((java.util.Map)value); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/ObjectReference.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/ObjectReference.java deleted file mode 100644 index 784571e0c0..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/ObjectReference.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class ObjectReference extends Type -{ - public ObjectReference() - { - super(byte[].class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return decoder.readBin128(); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - ((Binary)value).encode(encoder); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Str16.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Str16.java deleted file mode 100644 index 7ab1c667f0..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Str16.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class Str16 extends Type -{ - public Str16() - { - super(String.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return decoder.readStr16(); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeStr16((String)value); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Str8.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Str8.java deleted file mode 100644 index f8f48bc8ec..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Str8.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class Str8 extends Type -{ - public Str8() - { - super(String.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return decoder.readStr8(); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeStr8((String)value); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java deleted file mode 100644 index 786f8d9957..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java +++ /dev/null @@ -1,95 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -/** - * Layer supertype for all management "types". - * - * @author Andrea Gazzarini - */ -public abstract class Type -{ - /** Java representation of this type. */ - protected final Class javaType; - - /** - * Builds a new management type wiich wraps the given java type. - * - * @param javaType the java type. - */ - Type(Class javaType) - { - this.javaType = javaType; - } - - /** - * Returns the wrapped java type. - * - * @return the wrapped java type. - */ - public Class getJavaType () - { - return javaType; - } - - /** - * Each concrete subclass must define here how to decode incoming data according. - * - * @param decoder the decoder used to extract data. - * @return the "typed" value. - * - */ - public abstract Object decode(ManagementDecoder decoder); - - /** - * Returns a string representation of this type. - * - * @return a string representation of this type. - */ - @Override - public String toString () - { - return new StringBuilder(getClass().getName()) - .append(" (wraps ") - .append(javaType.getName()) - .append(')').toString(); - } - - /** - * Identity for types is based on wrapped java type identity. - */ - @Override - public boolean equals (Object obj) - { - return getClass() == obj.getClass(); - } - - @Override - public int hashCode () - { - return getClass().hashCode(); - } - - public abstract void encode (Object value, ManagementEncoder encoder); -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint16.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint16.java deleted file mode 100644 index 31aeab954d..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint16.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class Uint16 extends Type -{ - public Uint16() - { - super(Integer.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return new Integer(decoder.readUint16()); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeUint16((Integer)value); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint32.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint32.java deleted file mode 100644 index deb9772953..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint32.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class Uint32 extends Type -{ - public Uint32() - { - super(Long.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return new Long(decoder.readUint32()); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeUint32((Integer)value); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint64.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint64.java deleted file mode 100644 index 9d414cf225..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint64.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class Uint64 extends Type -{ - public Uint64() - { - super(Long.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return new Long(decoder.readUint64()); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeUint64((Integer)value); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint8.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint8.java deleted file mode 100644 index 681537c48f..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint8.java +++ /dev/null @@ -1,44 +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.domain.model.type; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class Uint8 extends Type -{ - public Uint8() - { - super(Short.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return new Short(decoder.readUint8()); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeUint8((Short)value); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uuid.java b/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uuid.java deleted file mode 100644 index 74e0337173..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/model/type/Uuid.java +++ /dev/null @@ -1,46 +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.domain.model.type; - -import java.util.UUID; - -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -public class Uuid extends Type -{ - public Uuid() - { - super(UUID.class); - } - - @Override - public Object decode (ManagementDecoder decoder) - { - return decoder.readUuid(); - } - - @Override - public void encode (Object value, ManagementEncoder encoder) - { - encoder.writeUuid((UUID)value); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/services/BrokerMessageListener.java b/java/client/src/main/java/org/apache/qpid/management/domain/services/BrokerMessageListener.java deleted file mode 100644 index d5fdce09fc..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/services/BrokerMessageListener.java +++ /dev/null @@ -1,181 +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.domain.services; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.qpid.api.Message; -import org.apache.qpid.management.Protocol; -import org.apache.qpid.management.domain.handler.base.IMessageHandler; -import org.apache.qpid.management.domain.model.DomainModel; -import org.apache.qpid.nclient.util.MessageListener; -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.util.Logger; - -/** - * Message listener used for processing incoming messages. - * So it is installed as a consumer on a specific channel and when a new message arrives: - * - * 1) Performs a sanity check on the message (magic number, sequence number) - * 2) Extracts the opcode and looks for one message handler associated with that opcode. - * 3) If a message handler is found the delegates the message processing; otherwise a log message is written to indicate - * that the message will be skipped. - * - * @author Andrea Gazzarini - */ -class BrokerMessageListener implements MessageListener -{ - private final static Logger LOGGER = Logger.get(BrokerMessageListener.class); - - private static class Log - { - // Debugs the content of the incoming message. - static void debugIncomingMessage(ByteBuffer message) - { - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug( - " : New incoming message has been received. Message content : %s", - Arrays.toString(message.array())); - } - } - - // Debugs all the configured handlers. - static void debugConfiguredHandlers (Map _handlers) - { - if (LOGGER.isDebugEnabled()) - { - for (Entry entry : _handlers.entrySet()) - { - LOGGER.debug(" : \"%s\" opcode is associated to handler %s",entry.getKey(),entry.getValue()); - } - } - } - } - - Map _handlers = new HashMap(); - private DomainModel _domainModel; - - /** - * Builds a new message listener with the given broker domain model. - * - * @param model the managed broker domain model. - */ - BrokerMessageListener(DomainModel model) - { - this._domainModel = model; - } - - /** - * When a new message arrives this method is called. - * 1) Performs a sanity check on the message (magic number, sequence number) - * 2) Extracts the opcode and looks for one message handler associated with that opcode. - * 3) If a message handler is found the delegates the message processing; otherwise a log message is written to indicate - * that the message will be skipped. - * - * @param message the incoming message. - */ - public void onMessage (Message message) - { - try - { - ByteBuffer buffer = message.readData(); - - // TODO : Should be better...! - String magicNumber = new String(new byte[] {buffer.get(),buffer.get(),buffer.get()}); - if (!Protocol.MAGIC_NUMBER.equals(magicNumber)) - { - LOGGER.error( - " : Message processing failure : incoming message contains a bad magic number (%s) " + - "and therefore will be discaded.", - magicNumber); - return; - } - - char opcode = (char)buffer.get(); - - IMessageHandler handler = _handlers.get(opcode); - if (handler != null) - { - ManagementDecoder decoder = new ManagementDecoder(); - decoder.init(buffer); - - LOGGER.debug( - " : Incoming message with \"%s\" as opcode will be forwarded to %s for processing.", - opcode, - handler); - - handler.process(decoder,decoder.readSequenceNo()); - } else - { - LOGGER.warn( - " : No handler has been configured for processing messages with \"%s\" as opcode. " + - "This message will be discarded.", - opcode); - - Log.debugConfiguredHandlers(_handlers); - } - } catch(IOException exception) - { - LOGGER.error( - exception, - " : Message I/O failure : unable to read byte message content and therefore it will be discarded."); - } catch(Exception exception) - { - LOGGER.error( - exception, - " : Message processing failure : unknown exception; see logs for more details."); - } - } - - /** - * Configures a new handler with this listener. - * After that, each time a message arrives with the specified opcode, this handler will be responsible for - * processing. - * Note that calling this method will switch this listener to a WORKING state. - * - * @param opcode the operation code. - * @param handler the message handler. - */ - void setHandlers(Map handlers) - { - for (Entry entry : handlers.entrySet()) - { - char opcode = entry.getKey(); - IMessageHandler handler = entry.getValue(); - try - { - handler.setDomainModel(_domainModel); - _handlers.put(opcode, handler); - } catch(Exception exception) { - LOGGER.error( - exception, - " : Message handler configured for opcode %s thrown an exception in initialization and therefore will be discarded.", - opcode); - } - } - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java b/java/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java deleted file mode 100644 index b2f1b19a6c..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java +++ /dev/null @@ -1,256 +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.domain.services; - -import java.util.UUID; - -import org.apache.qpid.QpidException; -import org.apache.qpid.management.Names; -import org.apache.qpid.management.configuration.BrokerConnectionData; -import org.apache.qpid.management.configuration.Configuration; -import org.apache.qpid.management.domain.model.DomainModel; -import org.apache.qpid.transport.util.Logger; - -/** - * This is the Object representation of a management client. - * According to specification : "A software component that is separate from the messaging broker, connected to the - * management broker via an AMQP connection, which allows any software component to be managed remotely by QPID." - * - * @author Andrea Gazzarini - */ -final class ManagementClient -{ - private final static Logger LOGGER = Logger.get(ManagementClient.class); - - private final String _managementQueueName; - private final String _methodReplyQueueName; - - private DomainModel _domainModel; - private QpidService _service; - - /** - * Builds a new ManagementClient with the given identifier and connection data. - * - * @param brokerId the broker identifier. - * @param connectionData the broker connection data (host, port, etc...) - */ - ManagementClient(UUID brokerId,BrokerConnectionData connectionData) - { - _service = new QpidService(brokerId); - _domainModel = new DomainModel(brokerId); - _managementQueueName = Configuration.getInstance().getManagementQueueName(); - _methodReplyQueueName = Configuration.getInstance().getMethodReplyQueueName(); - } - - /** - * Establishing initial communication Between Client and Broker. - * According to specification : - * "Communication is established between the management client and management agent using normal AMQP procedures. - * The client creates a connection to the broker and then establishes a session with its corresponding channel. - * Two private queues are then declared. - * A management queue is declared and bound to the qpid.management exchange with "mgmt.#" as routing key; in that - * way all management-related messages sent to the exchange will be received by this client. - * When a client successfully binds to the qpid.management exchange, the management agent schedules a schema - * broadcast to be sent to the exchange. - * The agent will publish, via the exchange, a description of the schema for all manageable objects in its control. That - * schema is therefore received by this service and it will be part of service's domain model." - * - * @throws StartupFailureException when this management client cannot perform startup operations due to an error. - */ - void estabilishFirstConnectionWithBroker() throws StartupFailureException{ - try { - connectWithBroker(); - - createAndBindMethodReplyQueue(); - createAndBindManagementQueue(); - - registerConsumerOnManagementQueue(); - registerConsumerOnMethodReplyQueue(); - - synchronize(); - } catch(Exception exception) - { - try { - _service.close(); - } catch(Exception ignore) - { - } - throw new StartupFailureException(exception); - } - } - - /** - * Shutdown procedure for this management client. - */ - void shutdown () - { - LOGGER.info( - " : The shutdown sequence has been initiated for management client connected with broker %s", - _domainModel.getBrokerId()); - - removeMethodReplyConsumer(); - destroyAndUnbingMethodReplyQueue(); - - removeManagementConsumer(); - destroyAndUnbingManagementQueue(); - - _domainModel.releaseResources(); - - _service.close(); - - LOGGER.info( - " : Management client connected with broker %s shut down successfully.", - _domainModel.getBrokerId()); - } - - /** - * Registers a consumer (that is, a listener) on the method-reply queue. - */ - private void registerConsumerOnMethodReplyQueue () - { - BrokerMessageListener methodReplyChannelListener = new BrokerMessageListener(_domainModel); - methodReplyChannelListener.setHandlers(Configuration.getInstance().getMethodReplyQueueHandlers()); - _service.createSubscription(_methodReplyQueueName, _methodReplyQueueName, methodReplyChannelListener); - - LOGGER.info( - " : Method-reply queue consumer has been successfully installed and bound on broker %s.", - _domainModel.getBrokerId()); - } - - /** - * Registers a consumer (listener) on the management queue. - */ - private void registerConsumerOnManagementQueue () throws QpidException - { - BrokerMessageListener managementChannelListener = new BrokerMessageListener(_domainModel); - managementChannelListener.setHandlers(Configuration.getInstance().getManagementQueueHandlers()); - _service.createSubscription(_managementQueueName, _managementQueueName, managementChannelListener); - - LOGGER.info( - " : Management queue consumer has been successfully installed and bound on broker %s.", - _domainModel.getBrokerId()); - } - - /** - * Declares a management queue and bound it to the "qpid.management" exchange with "mgmt.#" as routing key; - */ - private void createAndBindManagementQueue () - { - _service.declareQueue(_managementQueueName); - _service.declareBinding( - _managementQueueName, - Names.MANAGEMENT_EXCHANGE, - Names.MANAGEMENT_ROUTING_KEY); - - LOGGER.info( - " : Management queue with name %s has been successfully declared and bound on broker %s.", - _managementQueueName, - _domainModel.getBrokerId()); - } - - /** - * Declares a private queue for receiving method replies (after method invocations). - * This queue is bound to the amq.direct exchange using a routing key equal to the name of the queue. - */ - private void createAndBindMethodReplyQueue () - { - _service.declareQueue(_methodReplyQueueName); - _service.declareBinding(_methodReplyQueueName, Names.AMQ_DIRECT_QUEUE, _methodReplyQueueName); - - LOGGER.info( - " : Method-reply queue with name %s has been successfully declared and bound on broker %s.", - _methodReplyQueueName, - _domainModel.getBrokerId()); - } - - /** - * Removes the method-reply queue consumer. - */ - private void removeMethodReplyConsumer() - { - _service.removeSubscription(_methodReplyQueueName); - - LOGGER.info( - " : Consumer %s has been removed from broker %s.", - _methodReplyQueueName, - _domainModel.getBrokerId()); - } - - /** - * Unbind the method reply queue and after that destroy it from remote broker. - */ - private void destroyAndUnbingMethodReplyQueue() - { - _service.declareUnbinding(_methodReplyQueueName, Names.AMQ_DIRECT_QUEUE, _methodReplyQueueName); - _service.deleteQueue(_methodReplyQueueName); - - LOGGER.info( - " : Queue %s has been removed from broker %s.", - _methodReplyQueueName, - _domainModel.getBrokerId()); - } - - /** - * Removes the management queue consumer. - */ - private void removeManagementConsumer() - { - _service.removeSubscription(_managementQueueName); - - LOGGER.info( - " : Consumer %s has been removed from broker %s.", - _managementQueueName, - _domainModel.getBrokerId()); - } - - /** - * Unbind the management queue and after that destroy it from remote broker. - */ - private void destroyAndUnbingManagementQueue() - { - _service.declareUnbinding(_managementQueueName, Names.MANAGEMENT_EXCHANGE, Names.MANAGEMENT_ROUTING_KEY); - _service.deleteQueue(_managementQueueName); - - LOGGER.info( - " : Queue %s has been removed from broker %s.", - _managementQueueName, - _domainModel.getBrokerId()); - } - - /** - * Connects this client with the broker. - * - * @throws QpidException when it's not possibile to connect with the broker. - */ - private void connectWithBroker() throws Exception - { - _service.connect(); - } - - /** - * All the Management client commands are asynchronous. - * Synchronous behavior is achieved through invoking the sync method. - */ - private void synchronize() - { - _service.sync(); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java b/java/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java deleted file mode 100644 index 00dbec261d..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java +++ /dev/null @@ -1,103 +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.domain.services; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.Map.Entry; - -import org.apache.qpid.management.configuration.BrokerConnectionData; -import org.apache.qpid.management.configuration.Configuration; -import org.apache.qpid.management.configuration.ConfigurationException; -import org.apache.qpid.management.configuration.Configurator; -import org.apache.qpid.transport.util.Logger; - -/** - * Main entry point for starting Q-Man application. - * - * @author Andrea Gazzarini - */ -public class QMan -{ - private final static Logger LOGGER = Logger.get(QMan.class); - private final static List managementClients = new ArrayList(); - - /** - * Main method used for starting Q-Man. - * - * @param args the command line arguments. - */ - public static void main (String[] args) throws IOException - { - // SHUTDOWN HOOK - Runtime.getRuntime().addShutdownHook(new Thread(){ - @Override - public void run () - { - LOGGER.info(" : Shutting down Q-Man..."); - for (ManagementClient client : managementClients) - { - client.shutdown(); - } - LOGGER.info(" : Q-Man shut down."); - } - }); - - LOGGER.info(" : Starting Q-Man..."); - LOGGER.info(" : Reading Q-Man configuration..."); - - Configurator configurator = new Configurator(); - try - { - configurator.configure(); - LOGGER.info(" : Creating management client(s)..."); - for (Entry entry : Configuration.getInstance().getConnectionInfos()) - { - UUID brokerId = entry.getKey(); - BrokerConnectionData data = entry.getValue(); - try - { - ManagementClient client = new ManagementClient(brokerId,data); - managementClients.add(client); - client.estabilishFirstConnectionWithBroker(); - - LOGGER.info(" : Management client for broker %s successfully connected.",brokerId); - } catch(StartupFailureException exception) { - LOGGER.error(exception, ": Cannot connect to broker %s on %s:%s",brokerId,data.getHost(),data.getPort()); - } - } - LOGGER.info(" : Q-Man open for e-business."); - - // TODO : console enhancement (i.e. : connect another broker) - System.out.println("Type \"q\" to quit."); - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - while ( !"q".equals(reader.readLine()) ){ - } - } catch(ConfigurationException exception) { - LOGGER.error(exception, " : Q-Man was unable to startup correctly : a configuration error occurred."); - System.exit(1); - } - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java b/java/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java deleted file mode 100644 index 92689eba52..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java +++ /dev/null @@ -1,270 +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.domain.services; - -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.UUID; - -import org.apache.qpid.QpidException; -import org.apache.qpid.management.Constants; -import org.apache.qpid.management.Names; -import org.apache.qpid.management.configuration.Configuration; -import org.apache.qpid.management.configuration.QpidDatasource; -import org.apache.qpid.nclient.Connection; -import org.apache.qpid.nclient.Session; -import org.apache.qpid.nclient.util.MessageListener; -import org.apache.qpid.nclient.util.MessagePartListenerAdapter; -import org.apache.qpid.transport.MessageAcceptMode; -import org.apache.qpid.transport.MessageAcquireMode; -import org.apache.qpid.transport.MessageCreditUnit; -import org.apache.qpid.transport.Option; -import org.apache.qpid.transport.util.Logger; - -/** - * Qpid Broker facade. - * - * @author Andrea Gazzarini - */ -public class QpidService -{ - private final static Logger LOGGER = Logger.get(QpidService.class); - - // Inner static class used for logging and avoid conditional logic (isDebugEnabled()) duplication. - private static class Log - { - /** - * Logs the content f the message. - * This will be written on log only if DEBUG level is enabled. - * - * @param messageContent the raw content of the message. - */ - static void logMessageContent(byte [] messageContent) - { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug( - " : Message has been sent to management exchange. Message content : %s", - Arrays.toString(messageContent)); - } - } - - /** - * Logs the content f the message. - * This will be written on log only if DEBUG level is enabled. - * - * @param messageContent the raw content of the message. - */ - static void logMessageContent(ByteBuffer messageContent) - { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug( - " : Message has been sent to management exchange."); - } - } - } - - private UUID _brokerId; - private Connection _connection; - private Session _session; - - /** - * Builds a new service with the given connection data. - * - * @param connectionData the connection data of the broker. - */ - public QpidService(UUID brokerId) - { - this._brokerId = brokerId; - } - - /** - * Estabilishes a connection with the broker. - * - * @throws QpidException in case of connection failure. - */ - public void connect() throws Exception - { - _connection = QpidDatasource.getInstance().getConnection(_brokerId); - _session = _connection.createSession(Constants.NO_EXPIRATION); - } - - /** - * All the previously entered outstanding commands are asynchronous. - * Synchronous behavior is achieved through invoking this method. - */ - public void sync() - { - _session.sync(); - } - - /** - * Closes communication with broker. - */ - public void close() - { - try - { - _session.close(); - _session = null; - } catch (Exception e) - { - } - try - { - _connection.close(); - _connection = null; - } catch (Exception e) - { - } - } - - /** - * Associate a message listener with a destination therefore creating a new subscription. - * - * @param queueName The name of the queue that the subscriber is receiving messages from. - * @param destinationName the name of the destination, or delivery tag, for the subscriber. - * @param listener the listener for this destination. - * - * @see Session#messageSubscribe(String, String, short, short, org.apache.qpid.nclient.MessagePartListener, java.util.Map, org.apache.qpid.transport.Option...) - */ - public void createSubscription(String queueName, String destinationName,MessageListener listener) - { - _session.messageSubscribe( - queueName, - destinationName, - Session.TRANSFER_CONFIRM_MODE_NOT_REQUIRED, - Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE, - new MessagePartListenerAdapter(listener), null); - - _session.messageFlow(destinationName, MessageCreditUnit.BYTE, Session.MESSAGE_FLOW_MAX_BYTES); - _session.messageFlow(destinationName, MessageCreditUnit.MESSAGE, Integer.MAX_VALUE); - - LOGGER.debug( - " : New subscription between queue %s and destination %s has been declared.", - queueName, - destinationName); - } - - /** - * Removes a previously declared consumer from the broker. - * - * @param destinationName the name of the destination, or delivery tag, for the subscriber. - * @see Session#messageCancel(String, Option...) - */ - public void removeSubscription(String destinationName) - { - _session.messageCancel(destinationName); - LOGGER.debug( - " : Subscription named %s has been removed from remote broker.", - destinationName); - } - - /** - * Declares a queue on the broker with the given name. - * - * @param queueName the name of the declared queue. - * @see Session#queueDeclare(String, String, java.util.Map, Option...) - */ - public void declareQueue(String queueName) - { - _session.queueDeclare(queueName, null, null); - LOGGER.debug(" : New queue with name %s has been declared.",queueName); - } - - /** - * Removes the queue with the given name from the broker. - * - * @param queueName the name of the queue. - * @see Session#queueDelete(String, Option...) - */ - public void deleteQueue(String queueName) - { - _session.queueDelete(queueName); - LOGGER.debug(" : Queue with name %s has been removed.",queueName); - } - - /** - * Binds (on the broker) a queue with an exchange. - * - * @param queueName the name of the queue to bind. - * @param exchangeName the exchange name. - * @param routingKey the routing key used for the binding. - * @see Session#exchangeBind(String, String, String, java.util.Map, Option...) - */ - public void declareBinding(String queueName, String exchangeName, String routingKey) - { - _session.exchangeBind(queueName, exchangeName, routingKey, null); - LOGGER.debug( - " : New binding with %s as routing key has been declared between queue %s and exchange %s.", - routingKey,queueName, - exchangeName); - } - - /** - * Removes a previously declare binding between an exchange and a queue. - * - * @param queueName the name of the queue. - * @param exchangeName the name of the exchange. - * @param routingKey the routing key used for binding. - */ - public void declareUnbinding(String queueName, String exchangeName, String routingKey) - { - _session.exchangeUnbind(queueName, exchangeName, routingKey); - LOGGER.debug( - " : Binding with %s as routing key has been removed between queue %s and exchange %s.", - routingKey,queueName, - exchangeName); - } - - /** - * Sends a command message with the given data on the management queue. - * - * @param messageData the command message content. - */ - public void sendCommandMessage(byte [] messageData) - { - _session.messageTransfer( - Names.MANAGEMENT_EXCHANGE, - MessageAcceptMode.EXPLICIT, - MessageAcquireMode.PRE_ACQUIRED, - Configuration.getInstance().getCommandMessageHeader(), - messageData); - - Log.logMessageContent (messageData); - } - - /** - * Sends a command message with the given data on the management queue. - * - * @param messageData the command message content. - */ - public void sendCommandMessage(ByteBuffer messageData) - { - _session.messageTransfer( - Names.MANAGEMENT_EXCHANGE, - MessageAcceptMode.EXPLICIT, - MessageAcquireMode.PRE_ACQUIRED, - Configuration.getInstance().getCommandMessageHeader(), - messageData); - - Log.logMessageContent (messageData); - } -} \ No newline at end of file diff --git a/java/client/src/main/java/org/apache/qpid/management/domain/services/StartupFailureException.java b/java/client/src/main/java/org/apache/qpid/management/domain/services/StartupFailureException.java deleted file mode 100644 index 9da8832624..0000000000 --- a/java/client/src/main/java/org/apache/qpid/management/domain/services/StartupFailureException.java +++ /dev/null @@ -1,42 +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.domain.services; - -/** - * Thrown in case of service startup failure. - * For example the configuration file couldn't be read because is not well-formed. - * - * @author Andrea Gazzarini. - */ -public class StartupFailureException extends Exception -{ - private static final long serialVersionUID = -4102037574602857703L; - - /** - * Builds a new StartupFailureException with the given exception. - * - * @param exception the exception cause. - */ - public StartupFailureException(Exception exception) - { - super(exception); - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/TestConstants.java b/java/client/src/test/java/org/apache/qpid/management/TestConstants.java deleted file mode 100644 index 1ed938d9fd..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/TestConstants.java +++ /dev/null @@ -1,48 +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; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.management.domain.model.DomainModel; -import org.apache.qpid.management.domain.model.type.Binary; - -public interface TestConstants -{ - String QPID_PACKAGE_NAME = "qpid"; - String EXCHANGE_CLASS_NAME = "exchange"; - Binary HASH = new Binary(new byte []{1,2,3,4,5,6,7,8,9}); - int VALID_CODE = 1; - - - UUID BROKER_ID = UUID.randomUUID(); - Binary OBJECT_ID = new Binary(new byte []{1,2,3,2,1,1,2,3}); - - DomainModel DOMAIN_MODEL = new DomainModel(BROKER_ID); - - List> EMPTY_PROPERTIES_SCHEMA = new LinkedList>(); - List> EMPTY_STATISTICS_SCHEMA = new LinkedList>(); - List> EMPTY_METHODS_SCHEMA = new LinkedList>(); - List> EMPTY_EVENTS_SCHEMA = new LinkedList>(); -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java b/java/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java deleted file mode 100644 index 4c53c3d428..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.configuration; - -import org.apache.qpid.management.TestConstants; -import org.apache.qpid.management.domain.model.AccessMode; - -import junit.framework.TestCase; - -/** - * Test case for AccessMode mapping. - * - * @author Andrea Gazzarini - */ -public class AccessModeMappingTest extends TestCase -{ - private AccessModeMapping _mapping; - - /** - * Set up fixture for this test case. - */ - @Override - protected void setUp () throws Exception - { - _mapping = new AccessModeMapping(); - } - - /** - * Tests the execution of the setCode method when a valid code is given. - * - *
precondition : given code is a valid number. - *
postcondition : no exception is thrown and the mapping contained the requested code. - */ - public void testSetCodeOK() - { - _mapping.setCode(String.valueOf(TestConstants.VALID_CODE)); - assertEquals(TestConstants.VALID_CODE,_mapping.getCode()); - } - - /** - * Tests the execution of the setCode method when an invalid code is given. - * - *
precondition : given code is an invalid number. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testSetCodeKO_withInvalidNumber () - { - try { - _mapping.setCode(String.valueOf(TestConstants.VALID_CODE)+"a"); - fail("The given string is not a number and therefore an exception must be thrown."); - } catch(NumberFormatException expected) { - - } - } - - /** - * Tests the execution of the setAccessMode method when a valid access code is given. - * - *
precondition : given code is valid (i.e. RW, RC or RO). - *
postcondition : no exception is thrown and the mapping contained the requested access mode. - */ - public void testSetAccessModeOK() - { - _mapping.setAccessMode("RW"); - assertEquals(AccessMode.RW,_mapping.getAccessMode()); - - _mapping.setAccessMode("RC"); - assertEquals(AccessMode.RC,_mapping.getAccessMode()); - - _mapping.setAccessMode("RO"); - assertEquals(AccessMode.RO,_mapping.getAccessMode()); - } - - /** - * Tests the execution of the setAccessMode method when an unknown code is given. - * - *
precondition : given code is an unknown code. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testSetAccessModeKO () - { - try { - _mapping.setAccessMode(AccessMode.RW.toString()+"X"); - fail("The given string is not a string representation of a valid access mode."); - } catch(IllegalArgumentException expected) { - - } - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java b/java/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java deleted file mode 100644 index c948db59bf..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java +++ /dev/null @@ -1,237 +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 java.util.Map; -import java.util.UUID; - -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. - * - * @author Andrea Gazzarini - */ -public class ConfigurationTest extends TestCase -{ - /** - * Tests the singleton behaviour of the configuration object. - */ - public void testSingleton() - { - 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(); - mapping.setCode(String.valueOf(TestConstants.VALID_CODE)); - mapping.setType(Uint8.class.getName()); - 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. - * - *
precondition : the requested type doesn't exist on the configuration. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testGetTypeKO() - { - try - { - Configuration.getInstance().getType(TestConstants.VALID_CODE+1); - fail("If an unknwon code is supplied an exception must be thrown."); - } catch (UnknownTypeCodeException expected) - { - assertEquals(TestConstants.VALID_CODE+1,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 - { - String accessModeAsString = "RW"; - - AccessModeMapping mapping = new AccessModeMapping(); - mapping.setCode(String.valueOf(TestConstants.VALID_CODE)); - mapping.setAccessMode(accessModeAsString); - 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. - * - *
precondition : the requested access mode doesn't exist on the configuration. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testGetAccessModeKO() - { - try - { - Configuration.getInstance().getAccessMode(TestConstants.VALID_CODE+1); - fail("If an unknwon code is supplied an exception must be thrown."); - } catch (UnknownAccessCodeException expected) - { - assertEquals(TestConstants.VALID_CODE+1,expected.getCode()); - } - } - - /** - * Tests the execution of the getBrokerConnectionData when a valid broker id is supplied. - * - *
precondition : on configuration a connection data is stored and associated with the supplied id. - *
postcondition : the requested connection data is returned and no exception is thrown. - */ - public void testGetBrokerConnectionDataOK() throws Exception - { - BrokerConnectionData connectionData = new BrokerConnectionData(); - connectionData.setHost("host"); - connectionData.setPort("7001"); - connectionData.setInitialPoolCapacity("0"); - connectionData.setMaxPoolCapacity("10"); - connectionData.setMaxWaitTimeout("1"); - Configuration.getInstance().addBrokerConnectionData(TestConstants.BROKER_ID, connectionData); - - BrokerConnectionData result = Configuration.getInstance().getBrokerConnectionData(TestConstants.BROKER_ID); - assertSame(connectionData, result); - } - - /** - * Tests the execution of the getBrokerConnectionData when a unknown broker id is supplied. - * - *
precondition : on configuration there's no connection data associated with the supplied id. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testGetBrokerConnectionDataKO_withUnknownBrokerId() - { - UUID brokerId = UUID.randomUUID(); - try - { - Configuration.getInstance().getBrokerConnectionData(brokerId); - fail("If an unknown broker id is supplied then an exception must be thrown."); - } catch(UnknownBrokerException expected) - { - assertEquals(brokerId.toString(),expected.getMessage()); - } - } - - /** - * Tests the execution of the getBrokerConnectionData when a null id is supplied. - * - *
precondition : a null broker is given. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testGetBrokerConnectionDataKO_withNullBrokerId() - { - try - { - Configuration.getInstance().getBrokerConnectionData(null); - fail("If a null broker id is supplied then an exception must be thrown."); - } catch(UnknownBrokerException expected) - { - } - } - - /** - * Tests the behaviour of the getManagementQueueHandlers() method. - * - *
precondition: 2 management handlers are in stored configuration - *
postcondition : 2 management handlers are returned. - */ - public void testGetManagementQueueHandlersOk() - { - String i = "i"; - String c = "c"; - - String instrMessageHandlerClassName = InstrumentationMessageHandler.class.getName(); - String configMessageHandlerClassName = ConfigurationMessageHandler.class.getName(); - - MessageHandlerMapping instrMapping = new MessageHandlerMapping(); - MessageHandlerMapping configMapping = new MessageHandlerMapping(); - - instrMapping.setOpcode(i); - instrMapping.setMessageHandlerClass(instrMessageHandlerClassName); - - configMapping.setOpcode(c); - configMapping.setMessageHandlerClass(configMessageHandlerClassName); - - Configuration.getInstance().addManagementMessageHandlerMapping(instrMapping); - Configuration.getInstance().addManagementMessageHandlerMapping(configMapping); - - Map handlerMappings = Configuration.getInstance().getManagementQueueHandlers(); - - assertEquals(2,handlerMappings.size()); - assertEquals(instrMessageHandlerClassName,handlerMappings.get(instrMapping.getOpcode()).getClass().getName()); - assertEquals(configMessageHandlerClassName,handlerMappings.get(configMapping.getOpcode()).getClass().getName()); - } - - /** - * Tests the behaviour of the getManagementQueueHandlers() method. - * - *
precondition: 2 management handlers are in stored configuration - *
postcondition : 2 management handlers are returned. - */ - public void testGetMethodReplyQueueHandlersOk() - { - String s = "s"; - - String schemaMessageHandlerClassName = SchemaResponseMessageHandler.class.getName(); - - MessageHandlerMapping schemaMapping = new MessageHandlerMapping(); - - schemaMapping.setOpcode(s); - schemaMapping.setMessageHandlerClass(schemaMessageHandlerClassName); - - Configuration.getInstance().addMethodReplyMessageHandlerMapping(schemaMapping); - - Map handlerMappings = Configuration.getInstance().getMethodReplyQueueHandlers(); - - assertEquals(schemaMessageHandlerClassName,handlerMappings.get(schemaMapping.getOpcode()).getClass().getName()); - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java b/java/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java deleted file mode 100644 index c3fa0c13f3..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.configuration; - -import org.xml.sax.SAXException; - -import junit.framework.TestCase; - -/** - * Test case for configurator. - * - * @author Andrea Gazzarini - * - */ -public class ConfiguratorTest extends TestCase -{ - - /** - * Tests the execution of the configure() method when a inexistent configuration file is used. - * - *
precondition : the configuration file doesn't exist. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testConfigureKO_WithConfigFileNotFound() - { - Configurator configurator = getConfiguratorWithDatafileInjected("pippo/pluto/paperino.xml"); - try { - configurator.configure(); - fail("If there's no configuration file the configuration cannot be built."); - } catch(ConfigurationException expected) { - - } - } - - /** - * Tests the execution of the configure() method when configuration file is null. - * - *
precondition : the configuration file is null. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testConfigureKO_WithNullConfig() - { - Configurator configurator = getConfiguratorWithDatafileInjected(null); - try { - configurator.configure(); - fail("If there's no configuration file the configuration cannot be built."); - } catch(ConfigurationException expected) { - - } - } - - /** - * Tests the changes of the configurator internal state while configuration file is parsed. - * - *
precondition: N.A. - *
postcondition: N.A. - */ - public void testDirectorParsing() throws SAXException{ - Configurator configurator = new Configurator(); - - assertSame(Configurator.DEFAULT_PARSER,configurator._currentParser); - - configurator.startElement(null, null, Tag.TYPE_MAPPINGS.toString(), null); - assertSame(configurator._typeMappingParser,configurator._currentParser); - - configurator.startElement(null, null, Tag.ACCESS_MODE_MAPPINGS.toString(), null); - assertSame(configurator._accessModeMappingParser,configurator._currentParser); - - configurator.startElement(null, null, Tag.BROKERS.toString(), null); - assertSame(configurator._brokerConfigurationParser,configurator._currentParser); - - configurator.startElement(null, null, Tag.MANAGEMENT_QUEUE.toString(), null); - assertSame(configurator._managementQueueHandlerParser,configurator._currentParser); - - configurator.startElement(null, null, Tag.METHOD_REPLY_QUEUE.toString(), null); - assertSame(configurator._methodReplyQueueHandlerParser,configurator._currentParser); - } - /** - * Create a stub configurator which returns the given datafile path. - * - * @param filename the configuration file to be injected. - * @return a configurator which returns the given datafile path. - */ - private Configurator getConfiguratorWithDatafileInjected(final String filename) { - return new Configurator() - { - @Override - String getConfigurationFileName () - { - return filename; - } - }; - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java b/java/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java deleted file mode 100644 index 9755c62991..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java +++ /dev/null @@ -1,201 +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 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; - -/** - * Test case for mapping parsers. - * - * @author Andrea Gazzarini. - */ -public class MappingParsersTest extends TestCase -{ - /** - * Tests the execution of the access mode mapping parser. - * - *
precondition: An access mode mapping is built by the parser; - *
postcondition: the corresponding access mode is available on the configuration. - */ - public void testAccessModeMappingParser() throws UnknownAccessCodeException - { - AccessModeMappingParser parser = new AccessModeMappingParser(); - parser.setCurrrentAttributeValue(String.valueOf(TestConstants.VALID_CODE)); - parser.setCurrentAttributeName(Tag.CODE.toString()); - parser.setCurrrentAttributeValue("RW"); - parser.setCurrentAttributeName(Tag.VALUE.toString()); - parser.setCurrentAttributeName(Tag.MAPPING.toString()); - - AccessMode result = Configuration.getInstance().getAccessMode(TestConstants.VALID_CODE); - assertEquals(AccessMode.RW,result); - } - - /** - * Tests the execution of the broker connection data mapping parser. - * - *
precondition: A broker connection datamapping is built by the parser; - *
postcondition: the corresponding connection data is available on the configuration. - */ - public void testBrokerConnectionDataParser() throws UnknownBrokerException - { - String host = "127.0.0.1"; - String port = "7001"; - String virtualHost = "test"; - String username = "username_guest"; - String password ="password_guest"; - - BrokerConnectionDataParser parser = new BrokerConnectionDataParser() - { - @Override - UUID getUUId () - { - return TestConstants.BROKER_ID; - } - }; - - parser.setCurrrentAttributeValue(host); - parser.setCurrentAttributeName(Tag.HOST.toString()); - parser.setCurrrentAttributeValue(port); - parser.setCurrentAttributeName(Tag.PORT.toString()); - parser.setCurrrentAttributeValue(virtualHost); - parser.setCurrentAttributeName(Tag.VIRTUAL_HOST.toString()); - parser.setCurrrentAttributeValue(username); - parser.setCurrentAttributeName(Tag.USER.toString()); - parser.setCurrrentAttributeValue(password); - parser.setCurrentAttributeName(Tag.PASSWORD.toString()); - parser.setCurrentAttributeName(Tag.BROKER.toString()); - - BrokerConnectionData result = Configuration.getInstance().getBrokerConnectionData(TestConstants.BROKER_ID); - - assertEquals(host,result.getHost()); - assertEquals(Integer.parseInt(port),result.getPort()); - assertEquals(virtualHost,result.getVirtualHost()); - assertEquals(username,result.getUsername()); - assertEquals(password,result.getPassword()); - } - - /** - * Tests the execution of the management queue handler mapping parser. - * - *
precondition: Two managenent queue handlers mapping are built by the parser; - *
postcondition: the corresponding management handlers are available on the configuration. - */ - public void testManagementQueueMessageListenerParser() - { - String instrOpcode = "i"; - String configOpCode = "c"; - - ManagementQueueMessageListenerParser parser = new ManagementQueueMessageListenerParser(); - - parser.setCurrrentAttributeValue(instrOpcode); - parser.setCurrentAttributeName(Tag.OPCODE.toString()); - parser.setCurrrentAttributeValue(InstrumentationMessageHandler.class.getName()); - parser.setCurrentAttributeName(Tag.CLASS_NAME.toString()); - parser.setCurrentAttributeName(Tag.HANDLER.toString()); - - parser.setCurrrentAttributeValue(configOpCode); - parser.setCurrentAttributeName(Tag.OPCODE.toString()); - parser.setCurrrentAttributeValue(ConfigurationMessageHandler.class.getName()); - parser.setCurrentAttributeName(Tag.CLASS_NAME.toString()); - parser.setCurrentAttributeName(Tag.HANDLER.toString()); - - - Map result = Configuration.getInstance().getManagementQueueHandlers(); - - assertEquals(2,result.size()); - - assertEquals(InstrumentationMessageHandler.class,result.get(instrOpcode.charAt(0)).getClass()); - assertEquals(ConfigurationMessageHandler.class,result.get(configOpCode.charAt(0)).getClass()); - } - - /** - * Tests the execution of the method-reply queue handler mapping parser. - * - *
precondition: two method-reply queue handler mappings are built by the parser; - *
postcondition: the corresponding method-reply handlers are available on the configuration. - */ - public void testMethodReplyQueueMessageListenerParser() - { - String schemaOpcode = "s"; - String configOpCode = "c"; - - MethodReplyQueueMessageListenerParser parser = new MethodReplyQueueMessageListenerParser(); - - parser.setCurrrentAttributeValue(schemaOpcode); - parser.setCurrentAttributeName(Tag.OPCODE.toString()); - parser.setCurrrentAttributeValue(SchemaResponseMessageHandler.class.getName()); - parser.setCurrentAttributeName(Tag.CLASS_NAME.toString()); - parser.setCurrentAttributeName(Tag.HANDLER.toString()); - - parser.setCurrrentAttributeValue(configOpCode); - parser.setCurrentAttributeName(Tag.OPCODE.toString()); - parser.setCurrrentAttributeValue(ConfigurationMessageHandler.class.getName()); - parser.setCurrentAttributeName(Tag.CLASS_NAME.toString()); - parser.setCurrentAttributeName(Tag.HANDLER.toString()); - - Map result = Configuration.getInstance().getMethodReplyQueueHandlers(); - - assertEquals(2,result.size()); - - assertEquals(SchemaResponseMessageHandler.class,result.get(schemaOpcode.charAt(0)).getClass()); - assertEquals(ConfigurationMessageHandler.class,result.get(configOpCode.charAt(0)).getClass()); - } - - /** - * Tests the execution of the type mapping parser. - * - *
precondition: two type mappings are built by the parser; - *
postcondition: the corresponding types are available on the configuration. - */ - public void testMappingParser() throws NumberFormatException, UnknownTypeCodeException - { - TypeMappingParser parser = new TypeMappingParser(); - - String className = Uint8.class.getName(); - String validatorClassName = "a.b.c.Validator"; - - parser.setCurrrentAttributeValue(String.valueOf(TestConstants.VALID_CODE)); - parser.setCurrentAttributeName(Tag.CODE.toString()); - parser.setCurrrentAttributeValue(className); - parser.setCurrentAttributeName(Tag.CLASS_NAME.toString()); - parser.setCurrrentAttributeValue(validatorClassName); - parser.setCurrentAttributeName(Tag.VALIDATOR_CLASS_NAME.toString()); - parser.setCurrentAttributeName(Tag.MAPPING.toString()); - - Type type =Configuration.getInstance().getType(TestConstants.VALID_CODE); - String vClassName = Configuration.getInstance().getValidatorClassName(type); - - assertEquals(Uint8.class, type.getClass()); - assertEquals(validatorClassName,vClassName); - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java b/java/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java deleted file mode 100644 index 6d92e3b6f8..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java +++ /dev/null @@ -1,56 +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.Str8; - -public class StubConfigurator extends Configurator -{ - /** - * Builds whole configuration. - * - * @throws ConfigurationException when the build fails. - */ - public void configure() throws ConfigurationException - { - addAccessModeMapping("1", "RW"); - addAccessModeMapping("2", "RO"); - addAccessModeMapping("3", "RC"); - - addTypeMapping("1", Str8.class.getName()); - } - - public void addTypeMapping(String code,String clazzName) - { - TypeMapping mapping = new TypeMapping(); - mapping.setCode(code); - mapping.setType(clazzName); - Configuration.getInstance().addTypeMapping(mapping); - } - - public void addAccessModeMapping(String code, String value) - { - AccessModeMapping mapping = new AccessModeMapping(); - mapping.setCode(code);; - mapping.setAccessMode(value); - Configuration.getInstance().addAccessModeMapping(mapping); - } -} diff --git a/java/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java b/java/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java deleted file mode 100644 index bf44608c0e..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.configuration; - -import org.apache.qpid.management.TestConstants; -import org.apache.qpid.management.domain.model.type.Uint8; - -import junit.framework.TestCase; - -/** - * Test case for type mapping. - * - * @author Andrea Gazzarini - */ -public class TypeMappingTest extends TestCase -{ - private TypeMapping _mapping; - - @Override - protected void setUp () throws Exception - { - _mapping = new TypeMapping(); - } - - /** - * Tests the execution of the setCode method when a valid code is given. - * - *
precondition : given code is a valid number. - *
postcondition : no exception is thrown and the mapping contained the requested code. - */ - public void testSetCodeOK() - { - _mapping.setCode(String.valueOf(TestConstants.VALID_CODE)); - assertEquals(TestConstants.VALID_CODE,_mapping.getCode()); - } - - /** - * Tests the execution of the setCode method when an invalid code is given. - * - *
precondition : given code is an invalid number. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testSetCodeKO_withInvalidNumber () - { - try { - _mapping.setCode(String.valueOf(TestConstants.VALID_CODE)+"a"); - fail("The given string is not a number and therefore an exception must be thrown."); - } catch(NumberFormatException expected) - { - - } - } - - /** - * Tests the execution of the setType() method when a valid type class is given. - * - *
precondition : a valid class type is supplied. - *
postcondition : no exception is thrown and the mapping contains the previously associated type. - */ - public void testSetTypeOK() - { - _mapping.setType(Uint8.class.getName()); - assertTrue(_mapping.getType() instanceof Uint8); - } - - /** - * Tests the execution of the setType() method when a invalid type class is given. - * - *
precondition : an invalid class type is supplied. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testSetTypeKO_withTypeClassNotFound() - { - try - { - _mapping.setType(Uint8.class.getName()+"a"); - fail("If the supplied class doesn't exist an exception must be thrown."); - } catch(IllegalArgumentException expected) { - assertTrue(expected.getCause() instanceof ClassNotFoundException); - } - } - - /** - * Tests the execution of the setType() method when a invalid type class is given. - * - *
precondition : an invalid class type is supplied (is not a Type). - *
postcondition : an exception is thrown indicating the failure. - */ - public void testSetTypeKO_withInvalidType() - { - try - { - _mapping.setType(String.class.getName()); - fail("If the supplied class is not a Type an exception must be thrown."); - } catch(IllegalArgumentException expected) { - assertTrue(expected.getCause() instanceof ClassCastException); - } - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java b/java/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java deleted file mode 100644 index 6be4484f5c..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java +++ /dev/null @@ -1,120 +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.domain.handler.base; - -import java.nio.ByteBuffer; - -import org.apache.qpid.management.TestConstants; -import org.apache.qpid.management.domain.model.type.Binary; -import org.apache.qpid.transport.codec.ManagementDecoder; -import org.apache.qpid.transport.codec.ManagementEncoder; - -import junit.framework.TestCase; - -/** - * Test case for Content indication message handler (base class). - * - * @author Andrea Gazzarini - */ -public class ContentIndicationMessageHandlerTest extends TestCase -{ - /** - * Tests the execution of the process method when the message is processed correctly. - */ - public void testProcessOk() { - final String expectedPackageName = "org.apache.qpid.broker"; - final String expectedClassName ="connection"; - final long expectedMessageTimestamp = System.currentTimeMillis(); - final long expectedCreationTime = expectedMessageTimestamp - 1000; - final long expectedDeletionTime = 0; - final Binary expectedClassHash = new Binary(new byte[]{9,9,9,9,8,8,8,8,7,7,7,7,6,6,6,6}); - final Binary expectedObjectId = new Binary(new byte[]{1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16}); - final Binary expectedBody = new Binary(new byte[]{1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4}); - - ContentIndicationMessageHandler mockHandler = new ContentIndicationMessageHandler() - { - @Override - protected void updateDomainModel (String packageName, String className, Binary classHash, Binary objectId, - long timeStampOfCurrentSample, long timeObjectWasCreated, long timeObjectWasDeleted, byte[] contentData) - { - assertEquals(expectedPackageName,packageName); - assertEquals(expectedClassName,className); - assertEquals(expectedClassHash,classHash); - assertEquals(expectedMessageTimestamp,timeStampOfCurrentSample); - assertEquals(expectedCreationTime,timeObjectWasCreated); - assertEquals(expectedDeletionTime,timeObjectWasDeleted); - assertEquals(expectedObjectId,objectId); - assertEquals(expectedBody,new Binary(contentData)); - } - - @Override - void removeObjectInstance (String packageName, String className, Binary classHash, Binary objectId) - { - fail("The object shouldn't be deleted because deletion time was set to 0!"); - } - }; - mockHandler.setDomainModel(TestConstants.DOMAIN_MODEL); - - ByteBuffer buffer = ByteBuffer.allocate(1000); - ManagementEncoder encoder = new ManagementEncoder(buffer); - - encoder.writeStr8(expectedPackageName); - encoder.writeStr8(expectedClassName); - expectedClassHash.encode(encoder); - encoder.writeDatetime(expectedMessageTimestamp); - encoder.writeDatetime(expectedCreationTime); - encoder.writeDatetime(expectedDeletionTime); - expectedObjectId.encode(encoder); - expectedBody.encode(encoder); - - buffer.flip(); - ManagementDecoder decoder = new ManagementDecoder(); - decoder.init(buffer); - - mockHandler.process(decoder, 1); - } - - /** - * Tests the behaviour of the objectHasBeenRemoved method(). - */ - public void testObjectHasBeenRemoved() - { - ContentIndicationMessageHandler mockHandler = new ContentIndicationMessageHandler() - { - @Override - protected void updateDomainModel (String packageName, String className, Binary classHash, Binary objectId, - long timeStampOfCurrentSample, long timeObjectWasCreated, long timeObjectWasDeleted, byte[] contentData) - { - } - }; - - long deletionTimestamp = 0; - long now = System.currentTimeMillis(); - - assertFalse(mockHandler.objectHasBeenRemoved(deletionTimestamp, now)); - - deletionTimestamp = now + 1000; - assertFalse(mockHandler.objectHasBeenRemoved(deletionTimestamp, now)); - - deletionTimestamp = now - 1000; - assertTrue(mockHandler.objectHasBeenRemoved(deletionTimestamp, now)); - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java deleted file mode 100644 index 0c67811621..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java +++ /dev/null @@ -1,44 +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.domain.model; - -import org.apache.qpid.management.configuration.Configurator; - -import junit.framework.TestCase;; - -/** - * Layer supertype for all domain model related test cases. - * - * @author Andrea Gazzarini - */ -public class BaseDomainModelTestCase extends TestCase -{ - /** - * Set up fixture for this test case. - * In order to execute tests on domain model we need to build the configuration. - */ - @Override - protected void setUp () throws Exception - { - Configurator configurator = new Configurator(); - configurator.configure(); - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java deleted file mode 100644 index 43793e588a..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java +++ /dev/null @@ -1,102 +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.domain.model; - -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.desc; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.name; - -import java.util.HashMap; -import java.util.Map; - -import junit.framework.TestCase; - -import org.apache.qpid.management.configuration.StubConfigurator; -import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute; -import org.apache.qpid.management.domain.model.type.Uint16; - -/** - * Layer supertype for feature builder test cases. - * - * @author Andrea Gazzarini - */ -public abstract class BaseQpidFeatureBuilderTestCase extends TestCase -{ - protected final static String NAME = "aName"; - - protected final static String DESCRIPTION = "A description."; - protected Integer _type; - - protected Map _featureDefinition; - protected QpidFeatureBuilder _builder; - - protected StubConfigurator configurator; - - /** - * Set up fixture for all concrete builder test cases. - */ - @Override - protected void setUp () throws Exception - { - _type = 1; - configurator = new StubConfigurator(); - configurator.addTypeMapping(_type.toString(),Uint16.class.getName()); - - _featureDefinition = new HashMap(); - _featureDefinition.put(name.name(),NAME); - _featureDefinition.put(desc.name(), DESCRIPTION); - } - - // Internal test used to avoid code duplication. - protected void internalTestForMissingMandatoryAttribute(Attribute ...toBeRemoved) - { - try - { - for (Attribute attribute : toBeRemoved) - { - _featureDefinition.remove(attribute.name()); - } - _builder.build(); - fail("If a mandatory attribute is missing an exception must be thrown!"); - } catch (UnableToBuildFeatureException expected) - { - assertTrue(expected instanceof MissingFeatureAttributesException); - for (Attribute attribute : toBeRemoved) - { - assertTrue(expected.getMessage().contains(attribute.name())); - } - } - } - - // Internal test used to avoid code duplication. - protected void internalTestForMissingOptionalAttribute(Attribute ...toBeRemoved) throws UnableToBuildFeatureException - { - for (Attribute attribute : toBeRemoved) - { - _featureDefinition.remove(attribute.name()); - } - _builder.build(); - - assertNotNull(_builder.getQpidFeature()); - assertNotNull(_builder.getManagementFeature()); - } - - -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java deleted file mode 100644 index 185302c182..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java +++ /dev/null @@ -1,56 +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.domain.model; - -import java.util.UUID; - -import org.apache.qpid.management.TestConstants; - -/** - * Test case for domain model entity. - * - * @author Andrea Gazzarini - */ -public class DomainModelTest extends BaseDomainModelTestCase -{ - private DomainModel _model; - - @Override - protected void setUp () throws Exception - { - super.setUp(); - _model = new DomainModel(UUID.randomUUID()); - } - - /** - * Tests the execution of the getPackage() method. - */ - public void testGetPackage() - { - assertFalse(_model.containsPackage(TestConstants.QPID_PACKAGE_NAME)); - - QpidPackage qpidPackage = _model.getPackageByName(TestConstants.QPID_PACKAGE_NAME); - assertEquals(TestConstants.QPID_PACKAGE_NAME,qpidPackage.getName()); - - QpidPackage theSameAsPreviousOne = _model.getPackageByName(TestConstants.QPID_PACKAGE_NAME); - assertSame(qpidPackage, theSameAsPreviousOne); - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java deleted file mode 100644 index a4e1e24ff3..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java +++ /dev/null @@ -1,187 +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.domain.model; - -import java.nio.ByteBuffer; -import java.util.LinkedList; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.qpid.management.domain.model.type.Uint64; -import org.apache.qpid.transport.codec.ManagementDecoder; - -public class OptionalPropertiesTest extends TestCase -{ - public void testDecoderStateChange() - { - QpidProperty property = new QpidProperty(); - assertSame( - "Default decoder for properties is the one for mandatory properties.", - property._mandatoryPropertyDecoder, - property._decoder); - - property.markAsOptional(1); - assertSame( - "After a property has been marked as optional the corresponding decoder must be installed.", - property._optionalPropertyDecoder, - property._decoder); - } - - /** - * Tests the execution of the decode() method when the current property is optional but in the presence bitmask - * there's no the corresponding bit set. - * - *
precondition : property is optional and corresponding presence bit is not set. - *
postcondition : result must be null. - */ - public void testDecodeValueWithOptionalPropertyAndMissingValue() - { - byte [] presenceBytes = {2}; - - QpidProperty property = new QpidProperty(); - - // We don't need a decoder so in order to be sure that it won't be invoked set it to null. - ManagementDecoder nullDecoder = null; - - for (int i = 0; i < 8; i++) - { - // Property number 1 is declaring a value so skip it! - if (i != 1) - { - property.markAsOptional(i); - assertNull(property.decodeValue(nullDecoder, presenceBytes)); - } - } - } - - /** - * Tests the execution of the decode() method when the current property is optional but in the presence bitmask - * there's no the corresponding bit set. - * - *
precondition : property is optional and corresponding presence bit is not set. - *
postcondition : result must be null. - */ - public void testDecodeValueWithOptionalPropertyAndDeclaredValue() - { - byte [] presenceBytes = {4}; - Long _44 = new Long(44); - - QpidProperty property = new QpidProperty(); - property.setType(new Uint64()); - property.markAsOptional(2); - - ByteBuffer buffer = ByteBuffer.allocate(8); - buffer.putLong(_44); - buffer.rewind(); - ManagementDecoder decoder = new ManagementDecoder(); - - decoder.init(buffer); - assertEquals(_44,property.decodeValue(decoder, presenceBytes)); - } - - /** - * Tests the execution of the decode() method with a real scenario where there are mandatory and optional - * properties. - */ - public void testDecodeValueWithOptionalAndMandatoryProperties() - { - // With this bitset : - // - // 1th opt property is null; - // 2th opt property is null; - // 3th opt property is not null; - // 4th opt property is null; - // 5th opt propertyis null; - // 6th opt property is null; - // 7th opt property is null; - // 8th opt property is not null; - byte [] presenceBytes = {4,1}; - - List properties = new LinkedList(); - - properties.add(createProperty(false, -1)); - properties.add(createProperty(false, -1)); - properties.add(createProperty(true, 0)); - properties.add(createProperty(false, -1)); - properties.add(createProperty(false, -1)); - properties.add(createProperty(true, 1)); - properties.add(createProperty(false, -1)); - properties.add(createProperty(false, -1)); - properties.add(createProperty(true, 2)); - properties.add(createProperty(true, 3)); - properties.add(createProperty(true, 4)); - properties.add(createProperty(true, 5)); - properties.add(createProperty(true, 6)); - properties.add(createProperty(true, 7)); - properties.add(createProperty(false, -1)); - properties.add(createProperty(true, 8)); - - Long expectedResults [] = { - 1L, // p1 - 22L, // p2 - null, // p3 - 232L, // p4 - 211L, // p5 - null, // p6 - 232L, // p7 - 211L, // p8 - 999L, // p9 - null, // p10 - null, // p11 - null, // p12 - null, // p13 - null, // p14 - 626L, // p15 - 969L // p16 - }; - - - ByteBuffer buffer = ByteBuffer.allocate(expectedResults.length * 8); - for (Long expected : expectedResults) - { - if (expected != null) - { - buffer.putLong(expected); - } - } - buffer.rewind(); - ManagementDecoder decoder = new ManagementDecoder(); - - decoder.init(buffer); - int index = 0; - for (QpidProperty property : properties) - { - assertEquals(expectedResults[index++],property.decodeValue(decoder, presenceBytes)); - } - } - - private QpidProperty createProperty(boolean isOptional, int optionalIndex) - { - QpidProperty property = new QpidProperty(); - property.setType(new Uint64()); - if (isOptional) - { - property.markAsOptional(optionalIndex); - } - return property; - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java deleted file mode 100644 index 6032721d1b..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java +++ /dev/null @@ -1,166 +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.domain.model; - -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.dir; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.name; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.type; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.unit; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.management.MBeanOperationInfo; - -import org.apache.qpid.management.Names; -import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; -import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute; -import org.apache.qpid.transport.codec.ManagementEncoder; - -/** - * Test case for Qpid Statistic builder. - * - * @author Andrea Gazzarini - */ -public class QpidMethodBuilderTest extends BaseQpidFeatureBuilderTestCase -{ - private final static Integer ARG_COUNT = 3; - private MethodOrEventDataTransferObject _methodDefinition; - - private List> _argumentsDefinitons = new ArrayList>(); - - @Override - protected void setUp () throws Exception - { - super.setUp(); - _featureDefinition.put(Names.ARG_COUNT_PARAM_NAME, ARG_COUNT); - - Map arg1 = new HashMap(); - arg1.put(name.name(), "arg1"); - arg1.put(type.name(),_type); - arg1.put(dir.name(),Direction.I.name()); - arg1.put(unit.name(), "bytes"); - - Map arg2 = new HashMap(); - arg2.put(name.name(), "arg2"); - arg2.put(type.name(),_type); - arg2.put(dir.name(),Direction.O.name()); - arg2.put(unit.name(), "bytes"); - - Map arg3 = new HashMap(); - arg3.put(name.name(), "arg3"); - arg3.put(type.name(),_type); - arg3.put(dir.name(),Direction.IO.name()); - arg3.put(unit.name(), "bytes"); - - /* - dir yes no yes Direction code for method arguments - unit yes yes yes Units for numeric values (i.e. seconds, bytes, etc.) - min yes no yes Minimum value for numerics - max yes no yes Maximum value for numerics - maxlen yes no yes Maximum length for strings - desc yes yes yes Description of the argument - default yes no yes Default value for the argument - */ - _argumentsDefinitons.add(arg1); - _argumentsDefinitons.add(arg2); - - _methodDefinition = new MethodOrEventDataTransferObject(_featureDefinition,_argumentsDefinitons); - _builder = QpidFeatureBuilder.createMethodBuilder(_methodDefinition); - } - - /** - * Tests the build process for a statistic when the definition map doesn't contains type attribute. - * - *
precondition: definition map doesn't contains type attribute. - *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the - * missing attribute. - */ - public void testMethodBuilderKO_WithMissingName() - { - internalTestForMissingMandatoryAttribute(Attribute.name); - } - - /** - * Tests the build process for a statistic when the definition map doesn't contain type, name, index & optional attributes. - * - *
precondition: definition map doesn't contain type, name, index & optional attributes. - *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the - * missing attributes. - */ - public void testMethodBuilderOK_WithMissingUnit() throws UnableToBuildFeatureException - { - internalTestForMissingOptionalAttribute(Attribute.unit); - } - - /** - * Tests the build process for a statistic when the definition map doesn't unit attribute. - * Note that this attribute is optional and therefore the build must succeed. - * - *
precondition: definition map doesn't contain unit attribute. - *
postcondition : no exception is thrown and the statistic is built. - */ - public void testMethodBuilderOK_WithMissingDescription() throws UnableToBuildFeatureException - { - internalTestForMissingOptionalAttribute(Attribute.desc); - } - - /** - * Tests the build process for a statistic when the definition map contains valid values. - * - *
precondition : the statistic definiton map contains valid values. - *
postcondition : no exception is thrown and the statistisc is built as expected. - */ - public void testMethodBuilderOK() throws UnableToBuildFeatureException - { - _builder.build(); - - QpidMethod method = (QpidMethod) _builder.getQpidFeature(); - MBeanOperationInfo info = (MBeanOperationInfo) _builder.getManagementFeature(); - - assertEquals(NAME,method.getName()); - - assertEquals(DESCRIPTION,method.getDescription()); - - assertEquals(method.getDescription(),info.getDescription()); - assertEquals(method.getName(),info.getName()); - } - - public void testEncodeParameters() throws ValidationException, UnableToBuildFeatureException { - _builder.build(); - - Object [] parameters = new Object[]{new Integer(1), new Integer(2),new Integer(3)}; - - ManagementEncoder encoder = new ManagementEncoder(ByteBuffer.allocate(1)){ - @Override - public void writeUint16 (int s) - { - assertTrue(s == 1 || s == 2); - } - }; - - QpidMethod method = (QpidMethod) _builder.getQpidFeature(); - method.encodeParameters(parameters, encoder); - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java deleted file mode 100644 index 2611923f71..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.management.domain.model; - -import org.apache.qpid.management.domain.model.type.Uint64; - -public class QpidNumberPropertyTest extends BaseDomainModelTestCase -{ - private QpidProperty _property; - private Long _value = 55432L; - - @Override - protected void setUp () throws Exception - { - super.setUp(); - _property = new QpidProperty(); - _property.setName("average"); - _property.setAccessMode(AccessMode.RW); - _property.setType(new Uint64()); - } - - /** - * Tests the validation of a qpid property when the type is a number and no constraint has been set. - * - *
precondition : property type is a string, no constraint has been set. - *
postcondition : no exception is thrown and the validation succeeds. - */ - public void testValidationWithoutConstraints() { - try - { - _property.validate(_value); - } catch (ValidationException notExpected) - { - fail("If no constraint has been set on this property why the validation is failing?"); - } - } - - /** - * Tests the validation of a qpid property when the type is a number and a max value constraint has been set. - * - *
precondition : property type is a number, max value has been set and property value is greater than max value. - *
postcondition : an exception is thrown indicating the validation failure. - */ - public void testValidationKO_withMaxValue() { - int maxValue = (int)(_value-1); - _property.setMaxValue(maxValue); - - try - { - _property.validate(_value); - fail("The given value is violating the installed constraint so an exception must be thrown."); - } catch (ValidationException expected) - { - assertEquals(ValidationException.MAX_VALUE,expected.getConstraintName()); - assertEquals(maxValue,expected.getConstraintValue()); - assertEquals((double)_value,expected.getFeatureValue()); - assertEquals(_property.getName(),expected.getFeatureName()); - } - } - - /** - * Tests the validation of a qpid property when the type is a number and a min value constraint has been set. - * - *
precondition : property type is a number, min value has been set and property value is lesser than min value. - *
postcondition : an exception is thrown indicating the validation failure. - */ - public void testValidationKO_withMinValue() { - int minValue = (int)(_value+1); - _property.setMinValue(minValue); - - try - { - _property.validate(_value); - fail("The given value is violating the installed constraint so an exception must be thrown."); - } catch (ValidationException expected) - { - assertEquals(ValidationException.MIN_VALUE,expected.getConstraintName()); - assertEquals(minValue,expected.getConstraintValue()); - assertEquals((double)_value,expected.getFeatureValue()); - assertEquals(_property.getName(),expected.getFeatureName()); - } - } - - - /** - * Tests the validation of a qpid property when the number is a string and the property value is null. - * - *
precondition : property type is a number and property value is null.. - *
postcondition : no exception is thrown. That is : the validation succeeds. - */ - public void testValidationOK_withNullValue() { - try - { - _property.validate(null); - } catch (ValidationException notExpected) - { - fail("No constraint has been violated so validate() shouldn't raise an exception."); - } - - _property.setMinValue(1); - _property.setMaxValue(10); - - try - { - _property.validate(null); - } catch (ValidationException notExpected) - { - fail("No constraint has been violated so validate() shouldn't raise an exception."); - } - } - - /** - * Tests the validation of a qpid property when the type is a number and a max / min constraints have been set. - * - *
precondition : property type is a number, max / min constraint have been set and property value is wrong. - *
postcondition : an exception is thrown indicating the validation failure. - */ - public void testValidationOK_withMinAndMaxConstraint() { - int minValue = (int)(_value+1); - int maxValue = (int)(_value-1); - _property.setMinValue(minValue); - _property.setMaxValue(maxValue); - - try - { - _property.validate(_value); - fail("The given value is violating the installed constraint so an exception must be thrown."); - } catch (ValidationException expected) - { - assertEquals(ValidationException.MIN_VALUE,expected.getConstraintName()); - assertEquals(minValue,expected.getConstraintValue()); - assertEquals((double)_value,expected.getFeatureValue()); - assertEquals(_property.getName(),expected.getFeatureName()); - } - - _property.setMinValue(0); - try - { - _property.validate(_value); - fail("The given value is violating the installed constraint so an exception must be thrown."); - } catch (ValidationException expected) - { - assertEquals(ValidationException.MAX_VALUE,expected.getConstraintName()); - assertEquals(maxValue,expected.getConstraintValue()); - assertEquals((double)_value,expected.getFeatureValue()); - assertEquals(_property.getName(),expected.getFeatureName()); - } - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java deleted file mode 100644 index 530b526bec..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java +++ /dev/null @@ -1,54 +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.domain.model; - -import org.apache.qpid.management.TestConstants; - -/** - * Test case for Qpid package entity. - * - * @author Andrea Gazzarini - */ -public class QpidPackageTest extends BaseDomainModelTestCase -{ - private QpidPackage _qpidPackage; - - @Override - protected void setUp () throws Exception - { - super.setUp(); - _qpidPackage = new QpidPackage(TestConstants.QPID_PACKAGE_NAME, TestConstants.DOMAIN_MODEL); - } - - /** - * Tests the association of a new class with a qpid package. - * - *
precondition : the package is not associated with any class. - *
postcondition : the package is now associated with the given class. - */ - public void testAddClass() throws UnableToBuildFeatureException { - assertFalse(_qpidPackage.alreadyContainsClassDefinition(TestConstants.EXCHANGE_CLASS_NAME, TestConstants.HASH)); - - _qpidPackage.getQpidClass(TestConstants.EXCHANGE_CLASS_NAME, TestConstants.HASH, true); - - assertTrue(_qpidPackage.alreadyContainsClassDefinition(TestConstants.EXCHANGE_CLASS_NAME, TestConstants.HASH)); - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPropertyBuilderTest.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPropertyBuilderTest.java deleted file mode 100644 index 4ac399def0..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPropertyBuilderTest.java +++ /dev/null @@ -1,271 +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.domain.model; - -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.access; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.index; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.max; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.min; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.optional; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.type; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.unit; - -import javax.management.MBeanAttributeInfo; - -import org.apache.qpid.management.configuration.UnknownTypeCodeException; -import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute; - -/** - * Test case for Qpid Property builder. - * - * @author Andrea Gazzarini - */ -public class QpidPropertyBuilderTest extends BaseQpidFeatureBuilderTestCase -{ - private final static Integer MIN = 0; - private final static Integer MAX = 120; - private final static String UNIT = "bytes"; - - private Integer _access; - - @Override - protected void setUp () throws Exception - { - super.setUp(); - - _access = 1; - configurator.addAccessModeMapping(_access.toString(), AccessMode.RW.name()); - - _featureDefinition.put(access.name(), _access); - _featureDefinition.put(unit.name(),UNIT); - _featureDefinition.put(min.name(), MIN); - _featureDefinition.put(max.name(),MAX); - - _featureDefinition.put(type.name(), _type); - _featureDefinition.put(optional.name(),0); - _featureDefinition.put(index.name(), 0); - - _builder = QpidFeatureBuilder.createPropertyBuilder(_featureDefinition); - } - - /** - * Tests the build process for a statistic when the definition map contains an unknown type code. - * - *
precondition : the statistic definiton map contains an unknown type code. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testStatisticBuilderKO_WithUnknownType() - { - int unknownTypeCode =999; - try - { - _featureDefinition.put(type.name(), unknownTypeCode); - _builder.build(); - fail("An unknown type code should raise an exception to indicate a failure."); - } catch (UnableToBuildFeatureException expected) - { - assertEquals(unknownTypeCode,((UnknownTypeCodeException)expected.getCause()).getCode()); - } - } - - /** - * Tests the build process for a statistic when the definition map contains a null value for a metadata attribute. - * - *
precondition : the statistic definiton map contains a null value for a metadata attribute. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testMethodBuilderKO_WithNullMetadataValue() - { - try - { - _featureDefinition.put(type.name(), null); - _builder.build(); - fail("An null value for a metadata attribute should raise an exception to indicate a failure."); - } catch (UnableToBuildFeatureException expected) - { - assertTrue(expected.getCause() instanceof NullPointerException); - } - } - - /** - * Tests the build process for a property when the definition map contains an invalid metadata type. - * - *
precondition : the property definiton map contains a wrong type for a metadata attribute. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testPropertyBuilderKO_WithClassCastException() - { - try - { - _featureDefinition.put(access.name(), new String("a")); - _builder.build(); - fail("A wrong metadata attribute type should raise an exception to indicate a failure."); - } catch (UnableToBuildFeatureException expected) - { - assertTrue(expected.getCause() instanceof ClassCastException); - } - } - - /** - * Tests the build process for a property when the definition map contains an unknown type code. - * - *
precondition : the property definiton map contains an unknown type code. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testPropertyBuilderKO_WithUnknownType() - { - int unknownTypeCode = 999; - try - { - _featureDefinition.put(type.name(), unknownTypeCode); - _builder.build(); - fail("An unknown type code should raise an exception to indicate a failure."); - } catch (UnableToBuildFeatureException expected) - { - assertEquals(unknownTypeCode,((UnknownTypeCodeException)expected.getCause()).getCode()); - } - } - - /** - * Tests the build process for a property when the definition map doesn't contains type attribute. - * - *
precondition: definition map doesn't contains type attribute. - *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the - * missing attribute. - */ - public void testPropertyBuilderKO_WithMissingType() - { - internalTestForMissingMandatoryAttribute(Attribute.type); - } - - /** - * Tests the build process for a property when the definition map doesn't contain type & name attributes. - * - *
precondition: definition map doesn't contain type & name attributes. - *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the - * missing attributes. - */ - public void testPropertyBuilderKO_WithMissingTypeAndName() - { - internalTestForMissingMandatoryAttribute(Attribute.type, Attribute.name); - } - - /** - * Tests the build process for a property when the definition map doesn't contain type & name & index attributes. - * - *
precondition: definition map doesn't contain type & name & index attributes. - *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the - * missing attributes. - */ - public void testPropertyBuilderKO_WithMissingTypeAndNameAndIndex() - { - internalTestForMissingMandatoryAttribute(Attribute.type, Attribute.name,Attribute.index); - } - - /** - * Tests the build process for a property when the definition map doesn't contain type, name, index & optional attributes. - * - *
precondition: definition map doesn't contain type, name, index & optional attributes. - *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the - * missing attributes. - */ - public void testPropertyBuilderKO_WithMissingTypeAndNameAndIndexAndOptional() - { - internalTestForMissingMandatoryAttribute(Attribute.type, Attribute.name,Attribute.index,Attribute.optional); - } - - /** - * Tests the build process for a property when the definition map doesn't contain type, name, index, optional and access - * attributes. - * - *
precondition: definition map doesn't contain type, name, index, optional and access attributes. - *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the - * missing attributes. - */ - public void testPropertyBuilderKO_WithMissingTypeAndNameAndIndexAndOptionalAndAccess() - { - internalTestForMissingMandatoryAttribute(Attribute.type, Attribute.name,Attribute.index,Attribute.optional,Attribute.access); - } - - /** - * Tests the build process for a property when the definition map doesn't unit attribute. - * Note that this attribute is optional and therefore the build must succeed. - * - *
precondition: definition map doesn't contain unit attribute. - *
postcondition : no exception is thrown and the property is built. - */ - public void testBuilderOK_WithMissingUnit() throws UnableToBuildFeatureException - { - internalTestForMissingOptionalAttribute(Attribute.unit); - } - - /** - * Tests the build process for a property when the definition map doesn't min and max attributes. - * Note that those attributes are optional and therefore the build must succeed. - * - *
precondition: definition map doesn't contain min and max attributes. - *
postcondition : no exception is thrown and the property is built. - */ - public void testBuilderOK_WithMissingMinAndMax() throws UnableToBuildFeatureException - { - internalTestForMissingOptionalAttribute(Attribute.min,Attribute.max); - } - - /** - * Tests the build process for a property when the definition map doesn't description attribute. - * Note that this attribute is optional and therefore the build must succeed. - * - *
precondition: definition map doesn't contain description attribute. - *
postcondition : no exception is thrown and the property is built. - */ - public void testBuilderOK_WithMissingDescription() throws UnableToBuildFeatureException - { - internalTestForMissingOptionalAttribute(Attribute.desc); - } - - /** - * Tests the build process for a property when the definition map contains valid values. - * - *
precondition : the property definiton map contains valid values. - *
postcondition : no exception is thrown and the property is built as expected. - */ - public void testPropertyBuilderOK() throws UnableToBuildFeatureException - { - _builder.build(); - - QpidProperty property = (QpidProperty) _builder.getQpidFeature(); - MBeanAttributeInfo info = (MBeanAttributeInfo) _builder.getManagementFeature(); - - assertEquals(NAME,property.getName()); - assertEquals(AccessMode.RW,property.getAccessMode()); - assertEquals(UNIT,property.getUnit()); - assertEquals(MIN.intValue(),property.getMinValue()); - assertEquals(MAX.intValue(),property.getMaxValue()); - assertEquals(Integer.MIN_VALUE,property.getMaxLength()); - assertEquals(DESCRIPTION,property.getDescription()); - assertEquals(Integer.class,property.getJavaType()); - assertFalse(property.isOptional()); - - assertEquals(property.getDescription(),info.getDescription()); - assertEquals(property.getName(),info.getName()); - assertEquals(property.getJavaType().getName(),info.getType()); - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidStatisticBuilderTest.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidStatisticBuilderTest.java deleted file mode 100644 index 7f4cf72895..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidStatisticBuilderTest.java +++ /dev/null @@ -1,159 +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.domain.model; - -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.type; -import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.unit; - -import javax.management.MBeanAttributeInfo; - -import org.apache.qpid.management.configuration.UnknownTypeCodeException; -import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute; - -/** - * Test case for Qpid Statistic builder. - * - * @author Andrea Gazzarini - */ -public class QpidStatisticBuilderTest extends BaseQpidFeatureBuilderTestCase -{ - private final static String UNIT = "bytes"; - - @Override - protected void setUp () throws Exception - { - super.setUp(); - _featureDefinition.put(unit.name(),UNIT); - _featureDefinition.put(type.name(), _type); - - _builder = QpidFeatureBuilder.createStatisticBuilder(_featureDefinition); - } - - /** - * Tests the build process for a statistic when the definition map contains an unknown type code. - * - *
precondition : the statistic definiton map contains an unknown type code. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testStatisticBuilderKO_WithUnknownType() - { - int unknownTypeCode = 999; - try - { - _featureDefinition.put(type.name(), unknownTypeCode); - _builder.build(); - fail("An unknown type code should raise an exception to indicate a failure."); - } catch (UnableToBuildFeatureException expected) - { - assertEquals(unknownTypeCode,((UnknownTypeCodeException)expected.getCause()).getCode()); - } - } - - /** - * Tests the build process for a statistic when the definition map contains a null value for a metadata attribute. - * - *
precondition : the statistic definiton map contains a null value for a metadata attribute. - *
postcondition : an exception is thrown indicating the failure. - */ - public void testMethodBuilderKO_WithNullMetadataValue() - { - try - { - _featureDefinition.put(type.name(), null); - _builder.build(); - fail("An null value for a metadata attribute should raise an exception to indicate a failure."); - } catch (UnableToBuildFeatureException expected) - { - assertTrue(expected.getCause() instanceof NullPointerException); - } - } - - /** - * Tests the build process for a statistic when the definition map doesn't contains type attribute. - * - *
precondition: definition map doesn't contains type attribute. - *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the - * missing attribute. - */ - public void testStatisticBuilderKO_WithMissingType() - { - internalTestForMissingMandatoryAttribute(Attribute.type); - } - - /** - * Tests the build process for a statistic when the definition map doesn't contain type & name attributes. - * - *
precondition: definition map doesn't contain type & name attributes. - *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the - * missing attributes. - */ - public void testStatisticBuilderKO_WithMissingTypeAndName() - { - internalTestForMissingMandatoryAttribute(Attribute.type, Attribute.name); - } - - /** - * Tests the build process for a statistic when the definition map doesn't contain type, name, index & optional attributes. - * - *
precondition: definition map doesn't contain type, name, index & optional attributes. - *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the - * missing attributes. - */ - public void testStatisticBuilderOK_WithMissingUnit() throws UnableToBuildFeatureException - { - internalTestForMissingOptionalAttribute(Attribute.unit); - } - - /** - * Tests the build process for a statistic when the definition map doesn't unit attribute. - * Note that this attribute is optional and therefore the build must succeed. - * - *
precondition: definition map doesn't contain unit attribute. - *
postcondition : no exception is thrown and the statistic is built. - */ - public void testBuilderOK_WithMissingDescription() throws UnableToBuildFeatureException - { - internalTestForMissingOptionalAttribute(Attribute.desc); - } - - /** - * Tests the build process for a statistic when the definition map contains valid values. - * - *
precondition : the statistic definiton map contains valid values. - *
postcondition : no exception is thrown and the statistisc is built as expected. - */ - public void testStatisticBuilderOK() throws UnableToBuildFeatureException - { - _builder.build(); - - QpidStatistic statistic= (QpidStatistic) _builder.getQpidFeature(); - MBeanAttributeInfo info = (MBeanAttributeInfo) _builder.getManagementFeature(); - - assertEquals(NAME,statistic.getName()); - assertEquals(UNIT,statistic.getUnit()); - assertEquals(DESCRIPTION,statistic.getDescription()); - assertEquals(Integer.class,statistic.getJavaType()); - - assertEquals(statistic.getDescription(),info.getDescription()); - assertEquals(statistic.getName(),info.getName()); - assertEquals(statistic.getJavaType().getName(),info.getType()); - } -} \ No newline at end of file diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidStringPropertyTest.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidStringPropertyTest.java deleted file mode 100644 index 263e4209a6..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidStringPropertyTest.java +++ /dev/null @@ -1,123 +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.domain.model; - -import org.apache.qpid.management.domain.model.type.Str16; - -public class QpidStringPropertyTest extends BaseDomainModelTestCase -{ - private QpidProperty _property; - private final String _5LettersString = "12345"; - - @Override - protected void setUp () throws Exception - { - super.setUp(); - _property = new QpidProperty(); - _property.setName("name"); - _property.setAccessMode(AccessMode.RW); - _property.setType(new Str16()); - } - - /** - * Tests the validation of a qpid property when the type is a string and a max length constraint hasn't been set. - * - *
precondition : property type is a string, max length hasn't been set. - *
postcondition : no exception is thrown. That is : the validation succeeds. - */ - public void testValidationWithoutMaxLength() { - try - { - _property.validate(_5LettersString); - } catch (ValidationException notExpected) - { - fail("No max length has been set on property so validation must succeed."); - } - } - - /** - * Tests the validation of a qpid property when the type is a string and a max length constraint has been set. - * - *
precondition : property type is a string, max length has been set and property value is longer than max length. - *
postcondition : an exception is thrown indicating the validation failure. - */ - public void testValidationKO_withMaxLength() { - int maxLength = 2; - _property.setMaxLength(maxLength); - - try - { - _property.validate(_5LettersString); - fail("No max length has been set on property so validation must proceed."); - } catch (ValidationException expected) - { - assertEquals(ValidationException.MAX_LENGTH,expected.getConstraintName()); - assertEquals(maxLength,expected.getConstraintValue()); - assertEquals(_5LettersString.length(),expected.getFeatureValue()); - assertEquals(_property.getName(),expected.getFeatureName()); - } - } - - /** - * Tests the validation of a qpid property when the type is a string and the property value is null. - * - *
precondition : property type is a string and property value is null.. - *
postcondition : no exception is thrown. That is : the validation succeeds. - */ - public void testValidationOK_withNullValue() { - try - { - _property.validate(null); - } catch (ValidationException notExpected) - { - fail("No constraint has been violated so validate() shouldn't raise an exception."); - } - - _property.setMaxLength(1); - - try - { - _property.validate(null); - } catch (ValidationException notExpected) - { - fail("No constraint has been violated so validate() shouldn't raise an exception."); - } - } - - /** - * Tests the validation of a qpid property when the type is a string and a max length constraint has been set. - * - *
precondition : property type is a string, max length has been set and property value is not violating that. - *
postcondition : no exception is thrown. That is : the validation succeeds. - */ - public void testValidationOK_withMaxLength() { - int maxLength = (_5LettersString.length()+1); - _property.setMaxLength(maxLength); - - try - { - _property.validate(_5LettersString); - } catch (ValidationException notExpected) - { - fail("No constraint has been violated so validate() shouldn't raise an exception."); - } - } -} diff --git a/java/client/src/test/java/org/apache/qpid/management/domain/model/type/BinaryTest.java b/java/client/src/test/java/org/apache/qpid/management/domain/model/type/BinaryTest.java deleted file mode 100644 index 6636c08710..0000000000 --- a/java/client/src/test/java/org/apache/qpid/management/domain/model/type/BinaryTest.java +++ /dev/null @@ -1,59 +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.domain.model.type; - -import junit.framework.TestCase; - -/** - * Test case for "Binary" type. - * - * @author Andrea Gazzarini - */ -public class BinaryTest extends TestCase -{ - /** - * Tests the lazy & once hash code computation behaviour of the binary type. - */ - public void testHashCodeComputation(){ - Binary binary = new Binary(new byte[]{1,2,3,4,5,6,7,6,3,3}); - assertSame(binary.state,binary.hashCodeNotYetComputed); - - int firstResult = binary.hashCode(); - assertSame(binary.state,binary.hashCodeAlreadyComputed); - - int secondResult = binary.hashCode(); - assertSame(binary.state,binary.hashCodeAlreadyComputed); - assertEquals(firstResult,secondResult); - } - - /** - * Tests the equals() method of the binary class. - * Two binary must be equals only if they contain the same array (that is, two arrays with the same size & content) - */ - public void testIdentity() { - Binary binary = new Binary(new byte[]{1,2,3,4,5,6,7,6,3,3}); - Binary theSame= new Binary(new byte[]{1,2,3,4,5,6,7,6,3,3}); - Binary aDifferentOne = new Binary(new byte[]{4,2,3,3,4,4,5,3,3,2}); - - assertTrue(binary.equals(theSame)); - assertFalse(binary.equals(aDifferentOne)); - } -} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/Constants.java b/java/management/client/src/main/java/org/apache/qpid/management/Constants.java new file mode 100644 index 0000000000..7be1bda776 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/Constants.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.management; + +/** + * Enumeration of literal values used to avoid code duplication. + * + * @author Andrea Gazzarini + */ +public interface Constants +{ + /** No expiration (used for timeout) */ + long NO_EXPIRATION = 0; +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/Names.java b/java/management/client/src/main/java/org/apache/qpid/management/Names.java new file mode 100644 index 0000000000..dde7715509 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/Names.java @@ -0,0 +1,52 @@ +/* + * + * 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; + +/** + * Enumeration of literal strings to avoid code duplication. + * + * @author Andrea Gazzarini + */ +public interface Names +{ + /** Name of the qpid management exchange. */ + String MANAGEMENT_EXCHANGE = "qpid.management"; + String MANAGEMENT_ROUTING_KEY = "console.#"; + + String MANAGEMENT_QUEUE_PREFIX = "management."; + String METHOD_REPLY_QUEUE_PREFIX = "reply."; + + String AMQ_DIRECT_QUEUE = "amq.direct"; + String AGENT_ROUTING_KEY = "agent.1.0"; + + String BROKER_ROUTING_KEY = "broker"; + + // Attributes + String PACKAGE = "package"; + String CLASS = "class"; + String OBJECT_ID="objectID"; + String BROKER_ID = "brokerID"; + String DOMAIN_NAME = "Q-MAN"; + + String CONFIGURATION_FILE_NAME = "/org/apache/qpid/management/config.xml"; + + String ARG_COUNT_PARAM_NAME = "argCount"; +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/Protocol.java b/java/management/client/src/main/java/org/apache/qpid/management/Protocol.java new file mode 100644 index 0000000000..185f417448 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/Protocol.java @@ -0,0 +1,34 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management; + +/** + * Protocol defined constants. + * + * @author Andrea Gazzarini + */ +public interface Protocol +{ + String MAGIC_NUMBER = "AM2"; + + byte [] METHOD_REQUEST_FIRST_FOUR_BYTES = (MAGIC_NUMBER+"M").getBytes(); + byte [] SCHEMA_REQUEST_FIRST_FOUR_BYTES = (MAGIC_NUMBER+"S").getBytes(); +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/config.xml b/java/management/client/src/main/java/org/apache/qpid/management/config.xml new file mode 100644 index 0000000000..590e33a0f7 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/config.xml @@ -0,0 +1,106 @@ + + + + + i + org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler + + + c + org.apache.qpid.management.domain.handler.impl.ConfigurationMessageHandler + + + + + m + org.apache.qpid.management.domain.handler.impl.MethodResponseMessageHandler + + + s + org.apache.qpid.management.domain.handler.impl.SchemaResponseMessageHandler + + + + + + 1 + org.apache.qpid.management.domain.model.type.Uint8 + org.apache.qpid.management.domain.model.QpidProperty$NumberValidator + + + 2 + org.apache.qpid.management.domain.model.type.Uint16 + org.apache.qpid.management.domain.model.QpidProperty$NumberValidator + + + 3 + org.apache.qpid.management.domain.model.type.Uint32 + org.apache.qpid.management.domain.model.QpidProperty$NumberValidator + + + 4 + org.apache.qpid.management.domain.model.type.Uint64 + org.apache.qpid.management.domain.model.QpidProperty$NumberValidator + + + 6 + org.apache.qpid.management.domain.model.type.Str8 + org.apache.qpid.management.domain.model.QpidProperty$StringValidator + + + 7 + org.apache.qpid.management.domain.model.type.Str16 + org.apache.qpid.management.domain.model.QpidProperty$StringValidator + + + 8 + org.apache.qpid.management.domain.model.type.AbsTime + + + 9 + org.apache.qpid.management.domain.model.type.DeltaTime + + + 10 + org.apache.qpid.management.domain.model.type.ObjectReference + + + 11 + org.apache.qpid.management.domain.model.type.Boolean + + + 14 + org.apache.qpid.management.domain.model.type.Uuid + + + 15 + org.apache.qpid.management.domain.model.type.Map + + + + + 1 + RC + + + 2 + RW + + + 3 + RO + + + + + localhost + 5672 + test + guest + guest + 4 + 4 + -1 + + + diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java new file mode 100644 index 0000000000..899462a648 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMapping.java @@ -0,0 +1,94 @@ +/* + * + * 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 int _code; + private AccessMode _accessMode; + + /** + * Sets the code for this mapping. + * Note that the given string must be a valid number (integer). + * + * @param codeAsString the code value as a string. + * @throws NumberFormatException when the given string is not a number. + */ + void setCode(String codeAsString) { + this._code = Integer.parseInt(codeAsString); + } + + /** + * Returns the access mode of this mapping. + * + * @return the access mode of this mapping. + */ + AccessMode getAccessMode () + { + return _accessMode; + } + + /** + * Sets the access mode for this mapping. + * Note that the given string must correspond to a valid access mode value (RW,RC, RO). + * + * @param accessModeAsString acces mode as a string. + * @throws IllegalArgumentException when the given string is not a valid access code. + */ + void setAccessMode (String accessModeAsString) + { + this._accessMode = AccessMode.valueOf(accessModeAsString); + } + + /** + * 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(); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMappingParser.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMappingParser.java new file mode 100644 index 0000000000..d9dcbd12d3 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/AccessModeMappingParser.java @@ -0,0 +1,74 @@ +/* + * + * 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; + +/** + * Parser used for building access mode mappings. + * For each access-mode-mappings/mapping element found in the configuration file, a new access mode mapping + * is built and injected into the configuration. + * + * + 1 + RC + + * + * @author Andrea Gazzarini + */ +class AccessModeMappingParser implements IParser +{ + private AccessModeMapping _mapping = new AccessModeMapping(); + private String _currentValue; + + /** + * Callback : the given value is the text content of the current node. + */ + public void setCurrrentAttributeValue (String value) + { + this._currentValue = value; + } + + /** + * Callback: each time the end of an element is reached this method is called. + * It's here that the built mapping is injected into the configuration. + */ + public void setCurrentAttributeName (String name) + { + switch (Tag.get(name)) + { + case CODE: + { + _mapping.setCode(_currentValue); + break; + } + case VALUE : + { + _mapping.setAccessMode(_currentValue); + break; + } + case MAPPING: + { + Configuration.getInstance().addAccessModeMapping(_mapping); + _mapping = new AccessModeMapping(); + break; + } + } + } +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java new file mode 100644 index 0000000000..74e89ef19d --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java @@ -0,0 +1,211 @@ +/* + * + * 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; + +/** + * Value object which is holding connection data for a specific broker. + * + * @author Andrea Gazzarini + */ +public class BrokerConnectionData +{ + private String _host; + private int _port; + private String _virtualHost; + private String _username; + private String _password; + private int _maxPoolCapacity; + private int _initialPoolCapacity; + private long _maxWaitTimeout; + + /** + * Builds a new empty broker connection data object. + */ + BrokerConnectionData() + { + } + + /** + * Sets the value of host property for this connection data. + * + * @param host the host name. + */ + void setHost (String host) + { + this._host = host; + } + + /** + * Sets the value of port property for this connection data. + * + * @param port the port. + */ + void setPort (String port) + { + this._port = Integer.parseInt(port); + } + + /** + * Sets the value of virtual host property for this connection data. + * + * @param virtualHost the virtual host. + */ + void setVirtualHost (String virtualHost) + { + this._virtualHost = virtualHost; + } + + /** + * Sets the value of username property for this connection data. + * + * @param username the username. + */ + void setUsername(String username) + { + this._username = username; + } + + /** + * Sets the value of password property for this connection data. + * + * @param password the password. + */ + void setPassword(String password) + { + this._password = password; + } + + /** + * Returns the value of the host property. + * + * @return the value of the host property. + */ + public String getHost () + { + return _host; + } + + /** + * Returns the value of the port property. + * + * @return the value of the port property. + */ + public int getPort () + { + return _port; + } + + /** + * Returns the value of the virtual host property. + * + * @return the value of the virtual host property. + */ + public String getVirtualHost () + { + return _virtualHost; + } + + /** + * Returns the value of the username property. + * + * @return the value of the username property. + */ + public String getUsername () + { + return _username; + } + + /** + * Returns the value of the password property. + * + * @return the value of the password property. + */ + public String getPassword () + { + return _password; + } + + // sofia:5663@pippo/sung1 + @Override + public String toString () + { + return new StringBuilder() + .append(_host) + .append(':') + .append(_port) + .append('@') + .append(_virtualHost) + .toString(); + } + + /** + * Sets the max number of allowed connections that can be opened. + * + * @param value the max number of allowed connections that can be opened. + * @throws NumberFormatException if the given value is not a valid integer. + */ + public void setMaxPoolCapacity (String value) + { + _maxPoolCapacity = Integer.parseInt(value); + } + + /** + * Sets the max wait timeout for retrieving an available connections from the pool. + * + * @param value the max wait timeout for retrieving an available connections from the pool.. + * @throws NumberFormatException if the given value is not a valid long. + */ + public void setMaxWaitTimeout (String value) + { + this._maxWaitTimeout = Long.parseLong(value); + } + + /** + * Returns the max number of allowed connections that can be opened. + * + * @return the max number of allowed connections that can be opened. + */ + public int getMaxPoolCapacity () + { + return _maxPoolCapacity; + } + + /** + * Returns the max wait timeout for retrieving an available connections from the pool. + * + * @return the max wait timeout for retrieving an available connections from the pool. + */ + public long getMaxWaitTimeout () + { + return _maxWaitTimeout; + } + + public void setInitialPoolCapacity (String value) + { + _initialPoolCapacity = Integer.parseInt(value); + } + + public int getInitialPoolCapacity () + { + return _initialPoolCapacity; + } + +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionDataParser.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionDataParser.java new file mode 100644 index 0000000000..d76baed07f --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionDataParser.java @@ -0,0 +1,133 @@ +/* + * + * 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 java.util.UUID; + +import org.apache.qpid.transport.util.Logger; + +/** + * Parser used for building access mode mappings. + * For each access-mode-mappings/mapping element found in the configuration file, a new access mode mapping + * is built and injected into the bridge configuration. + * + * + 192.168.61.130 + 5673 + test + andrea + andrea + + * + * @author Andrea Gazzarini + */ +class BrokerConnectionDataParser implements IParser +{ + private final static Logger LOGGER = Logger.get(Configuration.class); + private BrokerConnectionData _connectionData = new BrokerConnectionData(); + private String _currentValue; + + /** + * Callback : the given value is the text content of the current node. + */ + public void setCurrrentAttributeValue (String value) + { + this._currentValue = value; + } + + /** + * Callback: each time the end of an element is reached this method is called. + * It's here that the built mapping is injected into the configuration. + * + 192.168.61.130 + 5673 + test + andrea + andrea + + */ + public void setCurrentAttributeName (String name) + { + switch (Tag.get(name)) + { + case HOST: + { + _connectionData.setHost(_currentValue); + break; + } + case PORT : + { + _connectionData.setPort(_currentValue); + break; + } + case VIRTUAL_HOST: + { + _connectionData.setVirtualHost(_currentValue); + break; + } + case USER : + { + _connectionData.setUsername(_currentValue); + break; + } + case MAX_POOL_CAPACITY: + { + _connectionData.setMaxPoolCapacity (_currentValue); + break; + } + case INITIAL_POOL_CAPACITY: + { + _connectionData.setInitialPoolCapacity(_currentValue); + break; + } + case MAX_WAIT_TIMEOUT: + { + _connectionData.setMaxWaitTimeout(_currentValue); + break; + } + case PASSWORD: + { + _connectionData.setPassword(_currentValue); + break; + } + case BROKER: + { + try + { + Configuration.getInstance().addBrokerConnectionData(getUUId(),_connectionData); + } catch(Exception exception) + { + LOGGER.error(exception, "Unable to connect with broker located on %s and. Hence this broker will be ignored.", _connectionData); + } + _connectionData = new BrokerConnectionData(); + break; + } + } + } + + /** + * Gets an uuid in order to associate current connection data with a broker. + * @return + */ + UUID getUUId(){ + return UUID.randomUUID(); + } +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java new file mode 100644 index 0000000000..cd39d330bb --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java @@ -0,0 +1,343 @@ +/* + * + * 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 java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.Map.Entry; + +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.Type; +import org.apache.qpid.transport.DeliveryProperties; +import org.apache.qpid.transport.Header; +import org.apache.qpid.transport.MessageProperties; +import org.apache.qpid.transport.ReplyTo; +import org.apache.qpid.transport.util.Logger; + +/** + * Qpid Management bridge configuration. + * Basically iy is a singleton that is holding all the configurtion data loaded at startup. + * + * @author Andrea Gazzarini + */ +public final class Configuration +{ + private final static Logger LOGGER = Logger.get(Configuration.class); + private static Configuration INSTANCE = new Configuration(); + + Map _typeMappings = new HashMap(); + Map _accessModes = new HashMap(); + Map _validators = new HashMap(); + + Map _brokerConnectionInfos = new HashMap(); + + Map _managementQueueHandlers = new HashMap(); + Map _methodReplyQueueHandlers = new HashMap(); + + private String _managementQueueName; + private String _methodReplyQueueName; + + private Header _headerForCommandMessages; + + // Private constructor. + private Configuration() + { + defineQueueNames(); + createHeaderForCommandMessages(); + } + + /** + * Returns the singleton instance. + * + * @return the singleton instance. + */ + public static Configuration getInstance () + { + return INSTANCE; + } + + /** + * Returns the type associated to the given code. + * + * @param code the code used as search criteria. + * @return the type associated to the given code. + * @throws UnknownTypeCodeException when the given code is not associated to any type. + */ + public Type getType(int code) throws UnknownTypeCodeException + { + Type result = _typeMappings.get(code); + if (result == null) + { + throw new UnknownTypeCodeException(code); + } + return result; + } + + /** + * Returns the access mode associated to the given code. + * + * @param code the code used as search criteria. + * @return the access mode associated to the given code. + * @throws UnknownAccessCodeException when the given code is not associated to any access mode. + */ + public AccessMode getAccessMode(int code) throws UnknownAccessCodeException + { + AccessMode result = _accessModes.get(code); + if (result == null) + { + throw new UnknownAccessCodeException(code); + } + return result; + } + + /** + * Returns the validator class name associated to the given type. + * + * @param type the type. + * @return the validator class name associated to the given type. + */ + public String getValidatorClassName (Type type) + { + return _validators.get(type); + } + + /** + * Gets from this configuration the list of known broker (I mean, only their connection data). + * + * @return the list of known broker + */ + public Set> getConnectionInfos(){ + return _brokerConnectionInfos.entrySet(); + } + + /** + * Gets from this configuration the connection data of the broker associated with the given id. + * + * @param brokerId the broker identifier. + * @return the connection data of the broker associated with the given id. + * @throws UnknownBrokerException when the given id is not associated with any broker. + */ + public BrokerConnectionData getBrokerConnectionData (UUID brokerId) throws UnknownBrokerException + { + BrokerConnectionData connectionData = _brokerConnectionInfos.get(brokerId); + if (connectionData == null) + { + throw new UnknownBrokerException(brokerId); + } + return _brokerConnectionInfos.get(brokerId); + } + + /** + * Returns the name of the management queue. + * + * @return the name of the management queue. + */ + public String getManagementQueueName() { + return _managementQueueName; + } + + /** + * Returns the name of the method-reply queue. + * + * @return the name of the method-reply queue. + */ + public String getMethodReplyQueueName() { + return _methodReplyQueueName; + } + + /** + * Returns a map containing all the configured management message handlers. + * A management message handler it is a basically a processor for a management queue incoming message associated + * with a specific opcode. + * + * @return a map containing all the configured management message handlers. + */ + public Map getManagementQueueHandlers() + { + Map result = new HashMap(); + + for (Entry entry : _managementQueueHandlers.entrySet()) + { + Character opcode = entry.getKey(); + String className = entry.getValue(); + try + { + result.put(opcode, (IMessageHandler)Class.forName(className).newInstance()); + } catch(Exception exception) + { + LOGGER.error( + exception, + " : Management Message Handler configured for opcode %s is not available and therefore will be discarded.", + opcode); + } + } + return result; + } + + /** + * Returns a map containing all the configured method-reply message handlers. + * A management message handler it is a basically a processor for a method-reply queue incoming message associated + * with a specific opcode. + * + * @return a map containing all the configured method-reply message handlers. + */ + public Map getMethodReplyQueueHandlers() + { + Map result = new HashMap(); + + for (Entry entry : _methodReplyQueueHandlers.entrySet()) + { + Character opcode = entry.getKey(); + String className = entry.getValue(); + try + { + result.put(opcode, (IMessageHandler)Class.forName(className).newInstance()); + } catch(Exception exception) + { + LOGGER.error( + exception, + " :Method-Reply Message Handler configured for opcode %s is not available and therefore will be discarded.", + opcode); + } + } + return result; + } + + /** + * Returns the message header used for sending command message on management queue. + * + * @return the message header used for sending command message on management queue. + */ + public Header getCommandMessageHeader () + { + return _headerForCommandMessages; + } + + /** + * Adds a new type mapping to this configuration. + * + * @param mapping the type mapping that will be added. + */ + void addTypeMapping(TypeMapping mapping) { + int code = mapping.getCode(); + Type type = mapping.getType(); + String validatorClassName = mapping.getValidatorClassName(); + _typeMappings.put(code, type); + _validators.put(type, validatorClassName); + + LOGGER.info(" : Type mapping : code = %s associated to %s (validator class is %s)", code,type,validatorClassName); + } + + /** + * Adds a new access mode mapping to this configuration. + * + * @param mapping the mapping that will be added. + */ + void addAccessModeMapping(AccessModeMapping mapping){ + int code = mapping.getCode(); + AccessMode accessMode = mapping.getAccessMode(); + _accessModes.put(code, accessMode); + + LOGGER.info(" : Access Mode mapping : code = %s associated to %s", code,accessMode); + } + + /** + * Adds a new management message handler to this configuration. + * The incoming mapping object will contains an opcode and the class (as a string) of the message handler that will be used + * for processing incoming messages with that opcode. + * + * @param mapping the message handler mapping. + */ + void addManagementMessageHandlerMapping (MessageHandlerMapping mapping) + { + Character opcode = mapping.getOpcode(); + String handlerClass = mapping.getMessageHandlerClass(); + _managementQueueHandlers.put(opcode, handlerClass); + + LOGGER.info(" : Management Queue Message Handler Mapping : opcode = %s associated with %s", opcode,handlerClass); + } + + /** + * Adds a new method-reply message handler to this configuration. + * The incoming mapping object will contains an opcode and the class (as a string) of the message handler that will be used + * for processing incoming messages with that opcode. + * + * @param mapping the message handler mapping. + */ + void addMethodReplyMessageHandlerMapping (MessageHandlerMapping mapping) + { + Character opcode = mapping.getOpcode(); + String handlerClass = mapping.getMessageHandlerClass(); + _methodReplyQueueHandlers.put(opcode, handlerClass); + + LOGGER.info(" : Method-Reply Queue Message Handler Mapping : opcode = %s associated with %s", opcode,handlerClass); + } + + /** + * Adds to this configuration a new broker connection data. + * + * @param brokerId the broker identifier. + * @param connectionData the connection data. + * @throws Exception + */ + void addBrokerConnectionData (UUID brokerId, BrokerConnectionData connectionData) throws Exception + { + QpidDatasource.getInstance().addConnectionPool(brokerId, connectionData); + _brokerConnectionInfos.put(brokerId,connectionData); + LOGGER.info(" : Broker Configuration %s: %s",brokerId,connectionData); + } + + /** + * Header for command messages is created once because it only contains static values. + */ + private void createHeaderForCommandMessages () + { + MessageProperties messageProperties = new MessageProperties(); + + ReplyTo replyTo=new ReplyTo(); + replyTo.setRoutingKey(_methodReplyQueueName); + messageProperties.setReplyTo(replyTo); + + DeliveryProperties deliveryProperties = new DeliveryProperties(); + deliveryProperties.setRoutingKey(Names.AGENT_ROUTING_KEY); + + _headerForCommandMessages = new Header(deliveryProperties, messageProperties); + } + + /** + * Creates the name of the queues used by this service. + * This is done because if a broker should be managed by one or more management client, then each of them + * must have its own channels to communicate with. + */ + private void defineQueueNames() + { + UUID uuid = UUID.randomUUID(); + _managementQueueName = Names.MANAGEMENT_QUEUE_PREFIX+uuid; + _methodReplyQueueName = Names.METHOD_REPLY_QUEUE_PREFIX+uuid; + + LOGGER.debug(" : Management queue name : %s",_managementQueueName); + LOGGER.debug(" : Method-reply queue name : %s",_methodReplyQueueName); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/ConfigurationException.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/ConfigurationException.java new file mode 100644 index 0000000000..0ddbb3e1d8 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/ConfigurationException.java @@ -0,0 +1,41 @@ +/* + * + * 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; + +/** + * Thrown when a problem is encountered during building the configuration. + * + * @author Andrea Gazzarini + */ +public class ConfigurationException extends Exception +{ + private static final long serialVersionUID = 8238481177714286259L; + + /** + * Builds a new ConfigurationException with the given cause. + * + * @param exception the exception cause. + */ + public ConfigurationException(Exception exception) + { + super(exception); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java new file mode 100644 index 0000000000..fb33622f4d --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configurator.java @@ -0,0 +1,145 @@ +/* + * + * 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 java.io.BufferedReader; +import java.io.InputStreamReader; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.apache.qpid.management.Names; +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * Director used for coordinating the build process of configuration. + * This is the only component which has a read-write permission on Configuration object. + * + * @author Andrea Gazzarini + */ +public class Configurator extends DefaultHandler +{ + /** + * Default (empty) parser used when there's no need to process data (non relevant elements). + */ + final static IParser DEFAULT_PARSER = new IParser() { + + public void setCurrrentAttributeValue (String value) + { + } + + public void setCurrentAttributeName (String name) + { + } + }; + + IParser _typeMappingParser = new TypeMappingParser(); + IParser _accessModeMappingParser = new AccessModeMappingParser(); + IParser _brokerConfigurationParser = new BrokerConnectionDataParser(); + IParser _managementQueueHandlerParser = new ManagementQueueMessageListenerParser(); + IParser _methodReplyQueueHandlerParser = new MethodReplyQueueMessageListenerParser(); + + IParser _currentParser = DEFAULT_PARSER; + + /** + * Delegates the processing to the current parser. + */ + @Override + public void characters (char[] ch, int start, int length) throws SAXException + { + String value = new String(ch,start,length).trim(); + if (value.length() != 0) { + _currentParser.setCurrrentAttributeValue(value); + } + } + + /** + * Here is defined what parser needs to be used for processing the current data. + */ + @Override + public void startElement (String uri, String localName, String name, Attributes attributes) throws SAXException + { + switch(Tag.get(name)) { + case TYPE_MAPPINGS : { + _currentParser = _typeMappingParser; + break; + } + case ACCESS_MODE_MAPPINGS: + { + _currentParser = _accessModeMappingParser; + break; + } + case BROKERS: + { + _currentParser = _brokerConfigurationParser; + break; + } + case MANAGEMENT_QUEUE: + { + _currentParser = _managementQueueHandlerParser; + break; + } + case METHOD_REPLY_QUEUE: + { + _currentParser = _methodReplyQueueHandlerParser; + break; + } + } + } + + @Override + public void endElement (String uri, String localName, String name) throws SAXException + { + _currentParser.setCurrentAttributeName(name); + } + + /** + * Builds whole configuration. + * + * @throws ConfigurationException when the build fails. + */ + public void configure() throws ConfigurationException + { + try + { + SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); + BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(getConfigurationFileName()),"UTF8")); + InputSource source = new InputSource(reader); + parser.parse(source, this); + } catch (Exception exception) + { + throw new ConfigurationException(exception); + } + } + + /** + * Returns the name of the configuration file. + * + * @return the name of the configuration file. + */ + String getConfigurationFileName() + { + return Names.CONFIGURATION_FILE_NAME; + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/IParser.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/IParser.java new file mode 100644 index 0000000000..a221686765 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/IParser.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.configuration; + +/** + * Interface definition for configuration parser + * Concrete implementors are responsible for parsing a specific XML part of configuration data. + * + * @author Andrea Gazzarini + */ +interface IParser +{ + /** + * Main director callback : Sets the name of the current attribute. + * + * @param name the name of the current attribute. + */ + void setCurrentAttributeName(String name); + + /** + * Main director callback : sets the value of the current attribute. + * + * @param value the value of the current attribute. + */ + void setCurrrentAttributeValue(String value); +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/ManagementQueueMessageListenerParser.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/ManagementQueueMessageListenerParser.java new file mode 100644 index 0000000000..f31cd832cc --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/ManagementQueueMessageListenerParser.java @@ -0,0 +1,72 @@ +/* + * + * 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; + +/** + * Parser used for building mapping between a management queue message listeners and an opcode. + * + * + i + org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler + + + * @author Andrea Gazzarini + */ +class ManagementQueueMessageListenerParser implements IParser +{ + private MessageHandlerMapping _mapping = new MessageHandlerMapping(); + private String _currentValue; + + /** + * Callback : the given value is the text content of the current node. + */ + public void setCurrrentAttributeValue (String value) + { + this._currentValue = value; + } + + /** + * Callback: each time the end of an element is reached this method is called. + * It's here that the built mapping is injected into the configuration. + */ + public void setCurrentAttributeName (String name) + { + switch (Tag.get(name)) + { + case OPCODE: + { + _mapping.setOpcode(_currentValue); + break; + } + case CLASS_NAME: + { + _mapping.setMessageHandlerClass(_currentValue); + break; + } + case HANDLER: + { + Configuration.getInstance().addManagementMessageHandlerMapping(_mapping); + _mapping = new MessageHandlerMapping(); + break; + } + } + } +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/MessageHandlerMapping.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/MessageHandlerMapping.java new file mode 100644 index 0000000000..7ce3baae49 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/MessageHandlerMapping.java @@ -0,0 +1,72 @@ +/* + * + * 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; + +/** + * Message Handler mapping used for associating an opcode with a message handler. + * + * @author Andrea Gazzarini + */ +class MessageHandlerMapping +{ + private Character _opcode; + private String _handlerClass; + + /** + * Returns the opcode of this mapping. + * + * @return the code of this mapping. + */ + Character getOpcode () + { + return _opcode; + } + + /** + * Sets the opcode for this mapping. + * + * @param codeAsString the opcode as a string. + */ + void setOpcode (String codeAsString) + { + this._opcode = codeAsString.charAt(0); + } + + /** + * Returns the message handler for this mapping. + * + * @return the message handler for this mapping. + */ + String getMessageHandlerClass() + { + return _handlerClass; + } + + /** + * Sets the message handler of this mapping. + * + * @param handlerClass the handler class as a string. + */ + void setMessageHandlerClass(String handlerClass) + { + this._handlerClass = handlerClass; + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/MethodReplyQueueMessageListenerParser.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/MethodReplyQueueMessageListenerParser.java new file mode 100644 index 0000000000..a466b50658 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/MethodReplyQueueMessageListenerParser.java @@ -0,0 +1,72 @@ +/* + * + * 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; + +/** + * Parser used for building mappings between method-reply queue message listeners and an opcode. + * + * + i + org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler + + * + * @author Andrea Gazzarini + */ +class MethodReplyQueueMessageListenerParser implements IParser +{ + private MessageHandlerMapping _mapping = new MessageHandlerMapping(); + private String _currentValue; + + /** + * Callback : the given value is the text content of the current node. + */ + public void setCurrrentAttributeValue (String value) + { + this._currentValue = value; + } + + /** + * Callback: each time the end of an element is reached this method is called. + * It's here that the built mapping is injected into the configuration. + */ + public void setCurrentAttributeName (String name) + { + switch (Tag.get(name)) + { + case OPCODE: + { + _mapping.setOpcode(_currentValue); + break; + } + case CLASS_NAME: + { + _mapping.setMessageHandlerClass(_currentValue); + break; + } + case HANDLER: + { + Configuration.getInstance().addMethodReplyMessageHandlerMapping(_mapping); + _mapping = new MessageHandlerMapping(); + break; + } + } + } +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/QpidDatasource.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/QpidDatasource.java new file mode 100644 index 0000000000..f4428cb1e2 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/QpidDatasource.java @@ -0,0 +1,276 @@ +/* + * + * 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 java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.pool.BasePoolableObjectFactory; +import org.apache.commons.pool.ObjectPool; +import org.apache.commons.pool.impl.GenericObjectPool; +import org.apache.commons.pool.impl.GenericObjectPoolFactory; +import org.apache.qpid.ErrorCode; +import org.apache.qpid.QpidException; +import org.apache.qpid.nclient.Client; +import org.apache.qpid.nclient.ClosedListener; +import org.apache.qpid.nclient.Connection; +import org.apache.qpid.nclient.DtxSession; +import org.apache.qpid.nclient.Session; +import org.apache.qpid.transport.util.Logger; + +/** + * Qpid datasource. + * Basically it is a connection pool manager used for optimizing broker connections usage. + * + * @author Andrea Gazzarini + */ +public final class QpidDatasource +{ + private final static Logger LOGGER = Logger.get(QpidDatasource.class); + + /** + * A connection decorator used for adding pool interaction behaviour to an existing connection. + * + * @author Andrea Gazzarini + */ + public class ConnectionDecorator implements Connection,ClosedListener + { + private final Connection _decoratee; + private final UUID _brokerId; + private boolean _valid; + + /** + * Builds a new decorator with the given connection. + * + * @param brokerId the broker identifier. + * @param decoratee the underlying connection. + */ + private ConnectionDecorator(UUID brokerId, Connection decoratee) + { + this._decoratee = decoratee; + this._brokerId = brokerId; + _decoratee.setClosedListener(this); + _valid = true; + } + + /** + * Returns true if the underlying connection is still valid and can be used. + * + * @return true if the underlying connection is still valid and can be used. + */ + boolean isValid() + { + return _valid; + } + + /** + * Returns the connection to the pool. That is, marks this connections as available. + * After that, this connection will be available for further operations. + */ + public void close () throws QpidException + { + try + { + pools.get(_brokerId).returnObject(this); + LOGGER.debug(" : Connection %s returned to the pool.", this); + } catch (Exception exception) + { + throw new QpidException("Error while closing connection.",ErrorCode.CONNECTION_ERROR,exception); + } + } + + /** + * Do nothing : underlying connection is already connected. + */ + public void connect (String host, int port, String virtualHost, String username, String password) + throws QpidException + { + // DO NOTHING : DECORATEE CONNECTION IS ALREADY CONNECTED. + } + + /** + * Do nothing : underlying connection is already connected. + */ + public void connect (String url) throws QpidException + { + // DO NOTHING : DECORATEE CONNECTION IS ALREADY CONNECTED. + } + + /** + * @see Connection#createDTXSession(int) + */ + public DtxSession createDTXSession (int expiryInSeconds) + { + return _decoratee.createDTXSession(expiryInSeconds); + } + + /** + * @see Connection#createSession(long) + */ + public Session createSession (long expiryInSeconds) + { + return _decoratee.createSession(expiryInSeconds); + } + + /** + * Do nothing : closed listener has been already injected. + */ + public void setClosedListener (ClosedListener exceptionListner) + { + } + + /** + * Callback method used for error notifications while underlying connection is closing. + */ + public void onClosed (ErrorCode errorCode, String reason, Throwable t) + { + _valid = false; + LOGGER.error(t," : Error on closing connection. Reason is : %s, error code is %s",reason,errorCode.getCode()); + } + }; + + /** + * This is the connection factory, that is, the factory used to manage the lifecycle (create, validate & destroy) of + * the broker connection(s). + * + * @author Andrea Gazzarini + */ + class QpidConnectionFactory extends BasePoolableObjectFactory + { + private final BrokerConnectionData _connectionData; + private final UUID _brokerId; + + /** + * Builds a new connection factory with the given parameters. + * + * @param brokerId the broker identifier. + * @param connectionData the connecton data. + */ + private QpidConnectionFactory(UUID brokerId, BrokerConnectionData connectionData) + { + this._connectionData = connectionData; + this._brokerId = brokerId; + } + + /** + * Creates a new underlying connection. + */ + @Override + public Connection makeObject () throws Exception + { + Connection connection = Client.createConnection(); + connection.connect( + _connectionData.getHost(), + _connectionData.getPort(), + _connectionData.getVirtualHost(), + _connectionData.getUsername(), + _connectionData.getPassword()); + return new ConnectionDecorator(_brokerId,connection); + } + + /** + * Validates the underlying connection. + */ + @Override + public boolean validateObject (Object obj) + { + ConnectionDecorator connection = (ConnectionDecorator) obj; + boolean isValid = connection.isValid(); + LOGGER.debug(" : Test connection on reserve. Is valid? %s",isValid); + return isValid; + } + + /** + * Closes the underlying connection. + */ + @Override + public void destroyObject (Object obj) throws Exception + { + try + { + ConnectionDecorator connection = (ConnectionDecorator) obj; + connection._decoratee.close(); + LOGGER.debug(" : Connection has been destroyed."); + } catch (Exception e) + { + LOGGER.debug(e, " : Unable to destroy a connection object"); + } + } + } + + // Singleton instance. + private static QpidDatasource instance = new QpidDatasource(); + + // Each entry contains a connection pool for a specific broker. + private Map pools = new HashMap(); + + // Private constructor. + private QpidDatasource() + { + } + + /** + * Gets an available connection from the pool of the given broker. + * + * @param brokerId the broker identifier. + * @return a valid connection to the broker associated with the given identifier. + */ + public Connection getConnection(UUID brokerId) throws Exception + { + return (Connection) pools.get(brokerId).borrowObject(); + } + + /** + * Entry point method for retrieving the singleton instance of this datasource. + * + * @return the qpid datasource singleton instance. + */ + public static QpidDatasource getInstance() + { + return instance; + } + + /** + * Adds a connection pool to this datasource. + * + * @param brokerId the broker identifier that will be associated with the new connection pool. + * @param connectionData the broker connection data. + * @throws Exception when the pool cannot be created. + */ + void addConnectionPool(UUID brokerId,BrokerConnectionData connectionData) throws Exception { + GenericObjectPoolFactory factory = new GenericObjectPoolFactory( + new QpidConnectionFactory(brokerId,connectionData), + connectionData.getMaxPoolCapacity(), + GenericObjectPool.WHEN_EXHAUSTED_BLOCK, + connectionData.getMaxWaitTimeout(),-1, + true, + false); + ObjectPool pool = factory.createPool(); + + for (int i = 0; i < connectionData.getInitialPoolCapacity(); i++) + { + pool.returnObject(pool.borrowObject()); + } + + pools.put(brokerId,pool); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/Tag.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/Tag.java new file mode 100644 index 0000000000..9b3a4a3f6f --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/Tag.java @@ -0,0 +1,42 @@ +package org.apache.qpid.management.configuration; + +/** + * Configuration Tag catalogue. + * + * @author Andrea Gazzarini + */ +public enum Tag { + HANDLER { @Override public String toString() { return "handler"; }}, + MAPPING { @Override public String toString() { return "mapping"; }}, + CODE { @Override public String toString() { return "code"; }}, + CLASS_NAME { @Override public String toString() { return "class-name"; }}, + TYPE_MAPPINGS { @Override public String toString() { return "type-mappings"; }}, + ACCESS_MODE_MAPPINGS { @Override public String toString() { return "access-mode-mappings"; }}, + VALUE { @Override public String toString() { return "value"; }}, + CONFIGURATION { @Override public String toString() { return "configuration"; }}, + MESSAGE_HANDLERS { @Override public String toString() { return "message-handlers"; }}, + OPCODE { @Override public String toString() { return "opcode"; }}, + VALIDATOR_CLASS_NAME { @Override public String toString() { return "validator-class-name"; }}, + BROKER { @Override public String toString() { return "broker"; }}, + HOST { @Override public String toString() { return "host"; }}, + PORT { @Override public String toString() { return "port"; }}, + MAX_POOL_CAPACITY { @Override public String toString() { return "max-pool-capacity"; }}, + MAX_WAIT_TIMEOUT { @Override public String toString() { return "max-wait-timeout"; }}, + INITIAL_POOL_CAPACITY { @Override public String toString() { return "initial-pool-capacity"; }}, + VIRTUAL_HOST { @Override public String toString() { return "virtual-host"; }}, + USER { @Override public String toString() { return "user"; }}, + PASSWORD { @Override public String toString() { return "password"; }}, + BROKERS { @Override public String toString() { return "brokers"; }}, + MANAGEMENT_QUEUE { @Override public String toString() { return "management-queue"; }}, + METHOD_REPLY_QUEUE { @Override public String toString() { return "method-reply-queue"; }}; + + /** + * Returns the enum entry associated to the given tag name. + * + * @param name the name of tag. + * @return the enum entry associated to the given tag name. + */ + public static Tag get(String name) { + return valueOf(name.replaceAll("-", "_").toUpperCase()); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java new file mode 100644 index 0000000000..714c8eb6f5 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMapping.java @@ -0,0 +1,103 @@ +/* + * + * 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 int _code; + private Type _type; + private String _validatorClass; + + /** + * Returns the code of this mapping. + * + * @return the code of this mapping. + */ + int getCode () + { + return _code; + } + + /** + * Sets the code for this mapping. + * Note that the given string must be a valid number (integer). + * + * @param codeAsString the code as a string. + * @throws NumberFormatException when the given string is not a valid number. + */ + void setCode (String codeAsString) + { + this._code = Integer.parseInt(codeAsString); + } + + /** + * Returns the type for this mapping. + * + * @return the type for this mapping. + */ + Type getType () + { + return _type; + } + + /** + * Sets the type of this mapping. + * + * @param typeClass the type class as a string. + * @throw IllegalArgumentException when it's not possible to load the given class. + */ + void setType (String typeClass) + { + try + { + this._type = (Type) Class.forName(typeClass).newInstance(); + } catch (Exception exception) + { + throw new IllegalArgumentException(exception); + } + } + + /** + * Sets the validator class that will be used for validation. + * + * @param className the fully qualified name of the validation class. + */ + public void setValidatorClassName (String className) + { + this._validatorClass = className; + } + + /** + * Returns the validator class of this mapping. + * + * @return the validator class (as a string) of this mapping. + */ + public String getValidatorClassName() + { + return _validatorClass; + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMappingParser.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMappingParser.java new file mode 100644 index 0000000000..40b9cf84ca --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/TypeMappingParser.java @@ -0,0 +1,77 @@ +/* + * + * 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; + +/** + * Parser used for building type mappings. + * For each type-mappings/mapping element found in the configuration file, a new type mapping is built and injected into + * the bridge configuration. + * + * + 1 + org.apache.qpid.management.domain.model.type.Uint8 + org.apache.qpid.management.domain.model.QpidProperty$NumberValidator + + * + * @author Andrea Gazzarini + */ +class TypeMappingParser implements IParser +{ + private TypeMapping _mapping = new TypeMapping(); + private String _currentValue; + + /** + * Callback : the given value is the text content of the current node. + */ + public void setCurrrentAttributeValue (String value) + { + this._currentValue = value; + } + + /** + * Callback: each time the end of an element is reached this method is called. + * It's here that the built mapping is injected into the configuration. + */ + public void setCurrentAttributeName (String name) + { + switch (Tag.get(name)) + { + case CODE: + { + _mapping.setCode(_currentValue); + break; + } + case CLASS_NAME : { + _mapping.setType(_currentValue); + break; + } + case VALIDATOR_CLASS_NAME : { + _mapping.setValidatorClassName(_currentValue); + break; + } + case MAPPING : { + Configuration.getInstance().addTypeMapping(_mapping); + _mapping = new TypeMapping(); + break; + } + } + } +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownAccessCodeException.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownAccessCodeException.java new file mode 100644 index 0000000000..b7f1c0a7ec --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownAccessCodeException.java @@ -0,0 +1,53 @@ +/* + * + * 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; + +/** + * Thrown when no access mode is found in configuration associated to the given code. + * + * @author Andrea Gazzarini + */ +public class UnknownAccessCodeException extends Exception +{ + private static final long serialVersionUID = 2350963503092509119L; + private final int _code; + + /** + * Builds a new UnknownAccessCodeException with the given code. + * + * @param code the access code. + */ + UnknownAccessCodeException(int code) + { + super(String.valueOf(code)); + this._code = code; + } + + /** + * Returns the unknown code. + * + * @return the unknown code. + */ + public int getCode () + { + return _code; + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownBrokerException.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownBrokerException.java new file mode 100644 index 0000000000..5b08e09c24 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownBrokerException.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.management.configuration; + +import java.util.UUID; + +/** + * Thrown when someone requests connection data for an unknown broker. + * + * @author Andrea Gazzarini + */ +public class UnknownBrokerException extends Exception +{ + private static final long serialVersionUID = 4965395428832158924L; + + /** + * Builds a new UnknownBrokerException with the given broker id. + * + * @param brokerId the broker identifier. + */ + UnknownBrokerException(UUID brokerId) + { + super(String.valueOf(brokerId)); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownTypeCodeException.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownTypeCodeException.java new file mode 100644 index 0000000000..57005d21e5 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/UnknownTypeCodeException.java @@ -0,0 +1,53 @@ +/* + * + * 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; + +/** + * Thrown when no type is found in configuration associated to the given code. + * + * @author Andrea Gazzarini + */ +public class UnknownTypeCodeException extends Exception +{ + private static final long serialVersionUID = 5440934037645111591L; + private int _code; + + /** + * Builds a new UnknownTypeCodeException with the given code. + * + * @param code the access code. + */ + UnknownTypeCodeException(int code) + { + super(String.valueOf(code)); + this._code = code; + } + + /** + * Returns the unknown code. + * + * @return the unknown code. + */ + public int getCode () + { + return _code; + } +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/BaseMessageHandler.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/BaseMessageHandler.java new file mode 100644 index 0000000000..798e835ff4 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/BaseMessageHandler.java @@ -0,0 +1,54 @@ +/* + * + * 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.domain.handler.base; + +import org.apache.qpid.management.domain.model.DomainModel; +import org.apache.qpid.transport.util.Logger; + +/** + * Base class for all message handlers. + * A message handler is an handler for a specific type of message. + * Message type is defined by the opcode. + * + * @author Andrea Gazzarini + */ +public abstract class BaseMessageHandler implements IMessageHandler +{ + /** + * Logger used for logging. + */ + protected final Logger _logger = Logger.get(getClass()); + + /** + * Managed broker domain model. + */ + protected DomainModel _domainModel; + + /** + * Sets the broker domain model. + * + * @param domainModel the broker domain model. + */ + public void setDomainModel(DomainModel domainModel) + { + this._domainModel = domainModel; + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandler.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandler.java new file mode 100644 index 0000000000..21a3281fa9 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandler.java @@ -0,0 +1,116 @@ +/* + * + * 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.domain.handler.base; + +import org.apache.qpid.management.domain.model.type.Binary; +import org.apache.qpid.transport.codec.ManagementDecoder; + +/** + * Base class for content indication message handlers. + * + * @author Andrea Gazzarini + */ +public abstract class ContentIndicationMessageHandler extends BaseMessageHandler +{ + /** + * Processes the income message. + * + * @param decoder the decoder used to parse the message. + * @param sequenceNumber the sequence number of the message. + */ + public final void process (ManagementDecoder decoder, int sequenceNumber) + { + String packageName = decoder.readStr8(); + String className = decoder.readStr8(); + Binary classHash = new Binary(decoder.readBin128()); + + long timeStampOfCurrentSample = decoder.readDatetime(); + long timeObjectWasCreated = decoder.readDatetime(); + long timeObjectWasDeleted = decoder.readDatetime(); + + + + Binary objectId = new Binary(decoder.readBin128()); + + if (objectHasBeenRemoved(timeObjectWasDeleted, timeStampOfCurrentSample)) + { + removeObjectInstance(packageName,className,classHash,objectId); + } else + { + updateDomainModel( + packageName, + className, + classHash, + objectId, + timeStampOfCurrentSample, + timeObjectWasCreated, + timeObjectWasDeleted, + decoder.readReaminingBytes()); + } + } + + /** + * Removes an object instance from the domain model. + * + * @param packageName the package name. + * @param className the class name. + * @param classHash the class hash. + * @param objectId the object identifier. + */ + void removeObjectInstance(String packageName, String className,Binary classHash, Binary objectId) + { + _domainModel.removeObjectInstance(packageName,className,classHash,objectId); + } + + /** + * Checks if the timestamps contained in the message indicate that the object has been removed. + * + * @param deletionTimestamp time object was deleted. + * @param now timestamp of the current message. + * @return true if the object has been removed, false otherwise. + */ + boolean objectHasBeenRemoved(long deletionTimestamp, long now) { + return (deletionTimestamp != 0) && (now > deletionTimestamp); + } + + /** + * Updates domain model with the incoming data. + * This is a template method that each concrete subclass must implement in order to update the domain model + * with the incoming data. + * + * @param packageName the name of the package. + * @param className the name of the class. + * @param objectId the object identifier. + * @param timeStampOfCurrentSample timestamp of current sample. + * @param timeObjectWasCreated time object was created. + * @param timeObjectWasDeleted time object was deleted. + * @param contentData object instance incoming data. + */ + protected abstract void updateDomainModel( + String packageName, + String className, + Binary classHash, + Binary objectId, + long timeStampOfCurrentSample, + long timeObjectWasCreated, + long timeObjectWasDeleted, + byte []contentData ); +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/IMessageHandler.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/IMessageHandler.java new file mode 100644 index 0000000000..b945a29117 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/base/IMessageHandler.java @@ -0,0 +1,52 @@ +/* + * + * 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.domain.handler.base; + +import org.apache.qpid.management.domain.model.DomainModel; +import org.apache.qpid.transport.codec.ManagementDecoder; + +/** + * Interface definition for a processor able to deal with a specific message. + * The concrete implementor must define what has to be done with the supplied (incoming) stream and the sequence + * number. + * + * @author Andrea Gazzarini. + */ +public interface IMessageHandler +{ + /** + * Processes the (incoming) stream message. + * Note that the main controller (the component that is controlling this handler) has already read the magic number and + * the sequence number so here concrete implementors must start from that point (that is, just after the sequence + * number). + * + * @param decoder the stream decoder. + * @param sequenceNumber the sequence number of the message. + */ + void process (ManagementDecoder decoder, int sequenceNumber); + + /** + * Injects the domain model into this handler. + * + * @param domainModel the domain model. + */ + void setDomainModel(DomainModel domainModel); +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/ConfigurationMessageHandler.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/ConfigurationMessageHandler.java new file mode 100644 index 0000000000..a5f8c238a7 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/ConfigurationMessageHandler.java @@ -0,0 +1,58 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.domain.handler.impl; + +import org.apache.qpid.management.domain.handler.base.ContentIndicationMessageHandler; +import org.apache.qpid.management.domain.model.type.Binary; + +/** + * Schema Response message handler. + * This handler is responsible to process 'c'(opcode) messages sent by the management broker. + * + * @author Andrea Gazzarini + */ +public class ConfigurationMessageHandler extends ContentIndicationMessageHandler +{ + /** + * Broker domain model is going to be updated with incoming configuration data. + * + * @param packageName the name of the package. + * @param className the name of the class. + * @param objectId the object identifier. + * @param timeStampOfCurrentSample the timestamp of incoming data. + * @param timeObjectWasCreated time object was created. + * @param timeObjectWasDeleted time object was deleted. + */ + @Override + protected void updateDomainModel ( + String packageName, + String className, + Binary classHash, + Binary objectId, + long timeStampOfCurrentSample, + long timeObjectWasCreated, + long timeObjectWasDeleted, + byte[] contentData) + { + // TODO : deal with timestamps, too + _domainModel.addConfigurationRawData(packageName,className,classHash,objectId,contentData); + } + } \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InstrumentationMessageHandler.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InstrumentationMessageHandler.java new file mode 100644 index 0000000000..ee6d1f0092 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InstrumentationMessageHandler.java @@ -0,0 +1,58 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.domain.handler.impl; + +import org.apache.qpid.management.domain.handler.base.ContentIndicationMessageHandler; +import org.apache.qpid.management.domain.model.type.Binary; + +/** + * Schema Response message handler. + * This handler is responsible to process 'i'(opcode) messages sent by the management broker. + * + * @author Andrea Gazzarini + */ +public class InstrumentationMessageHandler extends ContentIndicationMessageHandler +{ + /** + * Broker domain model is going to be updated with incoming instrumentation data. + * + * @param packageName the name of the package. + * @param className the name of the class. + * @param objectId the object identifier. + * @param timeStampOfCurrentSample the timestamp of incoming data. + * @param timeObjectWasCreated time object was created. + * @param timeObjectWasDeleted time object was deleted. + */ + @Override + protected void updateDomainModel ( + String packageName, + String className, + Binary classHash, + Binary objectId, + long timeStampOfCurrentSample, + long timeObjectWasCreated, + long timeObjectWasDeleted, + byte[] contentData) + { + // TODO : deal with timestamps, too + _domainModel.addInstrumentationRawData(packageName,className,classHash,objectId,contentData); + } + } \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodOrEventDataTransferObject.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodOrEventDataTransferObject.java new file mode 100644 index 0000000000..bc6a77d804 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodOrEventDataTransferObject.java @@ -0,0 +1,68 @@ +/* + * + * 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.domain.handler.impl; + +import java.util.List; +import java.util.Map; + +/** + * Simple transfer object used for holding method / event definition data. + * + * @author Andrea Gazzarini + */ +public class MethodOrEventDataTransferObject +{ + private final Map _definition; + private List> _argumentDefinitions; + + /** + * Builds a new trasfer object with the given parameters. + * + * @param definition the method definition. + * @param argumentDefinitions the arguments definitions. + */ + public MethodOrEventDataTransferObject( + Map definition, + List> argumentDefinitions) + { + this._definition = definition; + this._argumentDefinitions = argumentDefinitions; + } + + /** + * Returns the method definition. + * + * @return the method definition. + */ + public Map getDefinition() { + return _definition; + } + + /** + * Returns the arguemnts definitions. + * + * @return the arguemnts definitions. + */ + public List> getArgumentsDefinitions() + { + return _argumentDefinitions; + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodResponseMessageHandler.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodResponseMessageHandler.java new file mode 100644 index 0000000000..24db2e963d --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/MethodResponseMessageHandler.java @@ -0,0 +1,41 @@ +/* + * + * 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.domain.handler.impl; + +import org.apache.qpid.management.domain.handler.base.BaseMessageHandler; +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.util.Logger; + +public class MethodResponseMessageHandler extends BaseMessageHandler +{ + private final static Logger LOGGER = Logger.get(MethodResponseMessageHandler.class); + + public void process (ManagementDecoder decoder, int sequenceNumber) + { + LOGGER.debug(" : Incoming method response message."); + + long statusCode = decoder.readUint32(); + String statusText = decoder.readStr8(); + + LOGGER.debug(" : Status code : %s", statusCode); + LOGGER.debug(" : Status text : %s", statusText); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/SchemaResponseMessageHandler.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/SchemaResponseMessageHandler.java new file mode 100644 index 0000000000..497e264581 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/SchemaResponseMessageHandler.java @@ -0,0 +1,162 @@ +/* + * + * 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.domain.handler.impl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.qpid.management.Names; +import org.apache.qpid.management.domain.handler.base.BaseMessageHandler; +import org.apache.qpid.management.domain.model.type.Binary; +import org.apache.qpid.transport.codec.ManagementDecoder; + +/** + * Schema Response message handler. + * This handler is responsible to process 'S'(opcode) messages sent by the management broker containing the full + * schema details for a class. + * + * @author Andrea Gazzarini + */ +public class SchemaResponseMessageHandler extends BaseMessageHandler +{ + /** + * Processes an incoming schema response. + * This will be used for building the corresponding class definition. + * + * @param decoder the decoder used for parsing the incoming stream. + * @param sequenceNumber the sequence number of the incoming message. + */ + public void process (ManagementDecoder decoder, int sequenceNumber) + { + try + { + int classKind = decoder.readUint8(); + if (classKind != 1) { + return; + } + String packageName = decoder.readStr8(); + String className = decoder.readStr8(); + + Binary schemaHash = new Binary(decoder.readBin128()); + + int howManyProperties = decoder.readUint16(); + int howManyStatistics = decoder.readUint16(); + int howManyMethods = decoder.readUint16(); + int howManyEvents = 0; + + // FIXME : Divide between schema error and raw data conversion error!!!! + _domainModel.addSchema( + packageName, + className, + schemaHash, + getProperties(decoder, howManyProperties), + getStatistics(decoder, howManyStatistics), + getMethods(decoder, howManyMethods), + getEvents(decoder, howManyEvents)); + } catch(Exception exception) + { + _logger.error(exception," : Q-Man was unable to process the schema response message."); + } + } + + /** + * Reads from the incoming message stream the properties definitions. + * + * @param decoder the decoder used for decode incoming data. + * @param howManyProperties the number of properties to read. + * @return a list of maps. Each map contains a property definition. + */ + List> getProperties(ManagementDecoder decoder,int howManyProperties) + { + List> result = new ArrayList>(howManyProperties); + for (int i = 0; i < howManyProperties; i++ ) + { + result.add(decoder.readMap()); + } + return result; + } + + /** + * Reads the statistics definitions from the incoming message stream. + * + * @param decoder the decoder used for decode incoming data. + * @param howManyProperties the number of statistics to read. + * @return a list of maps. Each map contains a statistic definition. + */ + List> getStatistics(ManagementDecoder decoder,int howManyStatistics) + { + List> result = new ArrayList>(howManyStatistics); + for (int i = 0; i < howManyStatistics; i++ ) + { + result.add(decoder.readMap()); + } + return result; + } + + /** + * Reads the methods definitions from the incoming message stream. + * + * @param decoder the decoder used for decode incoming data. + * @param howManyMethods the number of methods to read. + * @return a list method definitions. + */ + List getMethods(ManagementDecoder decoder, int howManyMethods) + { + List result = new ArrayList(howManyMethods); + for (int i = 0; i < howManyMethods; i++) + { + Map method = decoder.readMap(); + int howManyArguments = (Integer) method.get(Names.ARG_COUNT_PARAM_NAME); + + List> arguments = new ArrayList>(howManyArguments); + for (int argIndex = 0; argIndex < howManyArguments; argIndex++){ + arguments.add(decoder.readMap()); + } + result.add(new MethodOrEventDataTransferObject(method,arguments)); + } + return result; + } + + /** + * Reads the events definitions from the incoming message stream. + * + * @param decoder the decoder used for decode incoming data. + * @param howManyEvents the number of events to read. + * @return a list event definitions. + */ + List getEvents(ManagementDecoder decoder, int howManyEvents) + { + List result = new ArrayList(howManyEvents); + for (int i = 0; i < howManyEvents; i++) + { + Map method = decoder.readMap(); + int howManyArguments = (Integer) method.get(Names.ARG_COUNT_PARAM_NAME); + + List> arguments = new ArrayList>(howManyArguments); + for (int argIndex = 0; argIndex < howManyArguments; argIndex++){ + arguments.add(decoder.readMap()); + } + result.add(new MethodOrEventDataTransferObject(method,arguments)); + } + return result; + } + } diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/AccessMode.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/AccessMode.java new file mode 100644 index 0000000000..6d1426c122 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/AccessMode.java @@ -0,0 +1,33 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.domain.model; + +/** + * Enumeration for Access modes. + * + * @author Andrea Gazzarini + */ +public enum AccessMode +{ + RC { @Override public String toString() { return "Read-Create"; }}, + RO { @Override public String toString() { return "Read-Only"; }}, + RW { @Override public String toString() { return "Read-Write"; }} +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/Direction.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/Direction.java new file mode 100644 index 0000000000..8166c35eb6 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/Direction.java @@ -0,0 +1,33 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.domain.model; + +/** + * Enumeration of allowed method argument direction codes. + * + * @author Andrea Gazzarini + */ +public enum Direction +{ + I{ @Override public String toString() { return "Input"; }}, + O{ @Override public String toString() { return "Output"; }}, + IO{ @Override public String toString() { return "Input-Output"; }}; +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/DomainModel.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/DomainModel.java new file mode 100644 index 0000000000..b24228d122 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/DomainModel.java @@ -0,0 +1,174 @@ +/* + * + * 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.domain.model; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; +import org.apache.qpid.management.domain.model.type.Binary; + +/** + * Broker domain model. + * This is the local representation of a remote broker domain model. + * + * @author Andrea Gazzarini + */ +public class DomainModel +{ + private final UUID _id; + + /** Here the known packages of the remote broker are stored. */ + Map _packages = new HashMap(); + + /** + * Builds a new domain model with the given broker identifier. + * + * @param brokerId the broker identifier. + */ + public DomainModel(UUID brokerId) + { + this._id = brokerId; + } + + /** + * Returns the identifier of the broker associated with this domain model. + * + * @return the identifier of the broker associated with this domain model. + */ + public UUID getBrokerId() + { + return _id; + } + + /** + * Adds the specified schema to this domain model. + * + * @param packageName the package name. + * @param className the class name. + * @param classHash the class schema hash. + * @param properties the class properties. + * @param statistics the class statistics. + * @param methods the class methods. + * @param events the class events. + * @throws UnableToBuildFeatureException + */ + public void addSchema( + String packageName, + String className, + Binary classHash, + List> properties, + List> statistics, + List methods, + List events) throws UnableToBuildFeatureException + { + QpidPackage qpidPackage = getPackageByName(packageName); + qpidPackage.addClassDefinition(className,classHash,properties,statistics,methods, events); + } + + /** + * Gets the package with the specified name. + * Note that if the package doesn't exist a new one will be created and returned. + * + * @param packageName the name of the package. + * @return the package. + */ + QpidPackage getPackageByName (String packageName) + { + QpidPackage qpidPackage = _packages.get(packageName); + if (qpidPackage == null) + { + qpidPackage = new QpidPackage(packageName,this); + _packages.put(packageName, qpidPackage); + } + return qpidPackage; + } + + /** + * Returns true if a package with the specified name already exists on this domain model. + * + * @param packageName the name of the package. + * @return true if the package exists, false otherwise. + */ + boolean containsPackage (String packageName) + { + return _packages.containsKey(packageName); + } + + /** + * Adds the given instrumentation data (raw format) to this domain model. + * Note that this data is belonging to a specific object instance. + * + * @param packageName the name of the ower package. + * @param className the name of the owner class. + * @param classHash the schema hash for this class. + * @param objectId the object instance identifier. + * @param rawData the instrumentation data. + */ + public void addInstrumentationRawData (String packageName, String className,Binary classHash, Binary objectId, byte[] rawData) + { + QpidPackage qpidPackage = getPackageByName(packageName); + qpidPackage.setObjectInstanceInstrumentationRawData(className,classHash,objectId,rawData); + } + + /** + * Adds the given configuration data (raw format) to this domain model. + * Note that this data is belonging to a specific object instance. + * + * @param packageName the name of the ower package. + * @param className the name of the owner class. + * @param classHash the schema hash for this class. + * @param objectId the object instance identifier. + * @param rawData the configuration data. + */ + public void addConfigurationRawData (String packageName, String className, Binary classHash,Binary objectId, byte[] rawData) + { + QpidPackage qpidPackage = getPackageByName(packageName); + qpidPackage.setObjectInstanceConfigurationRawData(className,classHash,objectId,rawData); + } + + /** + * Removes the object instance associated to the given parameters. + * + * @param packageName the owner package. + * @param className the class definition of the object instance. + * @param classHash the class hash + * @param objectId the object identifier. + */ + public void removeObjectInstance (String packageName, String className, Binary classHash, Binary objectId) + { + QpidPackage qpidPackage = getPackageByName(packageName); + qpidPackage.removeObjectInstance(className, classHash, objectId); + } + + /** + * Releases all the resources kept by domain model entitiies. + */ + public void releaseResources() + { + for (QpidPackage qpidPackage : _packages.values()) + { + qpidPackage.releaseResources(); + } + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/IValidator.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/IValidator.java new file mode 100644 index 0000000000..1ede559145 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/IValidator.java @@ -0,0 +1,38 @@ +/* + * + * 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.domain.model; + +/** + * Interface definition for attribute validators. + * + * @author Andrea Gazzarini + */ +interface IValidator +{ + /** + * Validates the given value according to the rules definied by this validator. + * + * @param value the value be checked. + * + * @throws ValidationException when the value is violating validator's rules. + */ + void validate(Object value) throws ValidationException; +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java new file mode 100644 index 0000000000..9ca6ba0e7c --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/JmxService.java @@ -0,0 +1,158 @@ +/* + * + * 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.domain.model; + +import java.lang.management.ManagementFactory; +import java.util.UUID; + +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + +import org.apache.qpid.management.Names; +import org.apache.qpid.management.domain.model.QpidClass.QpidManagedObject; +import org.apache.qpid.management.domain.model.type.Binary; +import org.apache.qpid.transport.util.Logger; + +/** + * A simple facade used to perform operations on Mbean server. + * + * @author Andrea Gazzarini + */ +class JmxService +{ + private final static Logger LOGGER = Logger.get(JmxService.class); + private MBeanServer _mxServer = ManagementFactory.getPlatformMBeanServer(); + + + /** + * Registers a pre-existing object instance as an MBean with the MBean + * server. + * + * @param instance the object instance. + * @param brokerId the broker identifier. + * @param packageName the name of the package containing this instance. + * @param className the name of the owner class of this instance. + * @param objectId the object instance identifier. + */ + void registerObjectInstance( + QpidManagedObject instance, + UUID brokerId, + String packageName, + String className, + Binary objectId) + { + ObjectName name = createObjectName(brokerId, packageName, className, objectId); + if (!_mxServer.isRegistered(name)) + { + try + { + _mxServer.registerMBean(instance, name); + + LOGGER.debug( + " : Object instance %s::%s::%s:%s successfully registered with MBean Server with name %s", + brokerId, + packageName, + className, + objectId, + name); + } catch (Exception exception) + { + throw new RuntimeException(exception); + } + } + } + + /** + * Removes / unregisters a managed object instance from the MBean Server. + * + * @param brokerId the broker identifier. + * @param packageName the name of the package containing this instance. + * @param className the name of the owner class of this instance. + * @param objectId the object instance identifier. + */ + void unregisterObjectInstance( + UUID brokerId, + String packageName, + String className, + Binary objectId) + { + ObjectName name = createObjectName(brokerId, packageName, className, objectId); + if (_mxServer.isRegistered(name)) + { + try + { + _mxServer.unregisterMBean(name); + + LOGGER.debug( + " : Object instance %s::%s::%s:%s successfully unregistered from MBean Server. " + + "Name was %s", + brokerId, + packageName, + className, + objectId, + name); + } catch (Exception exception) + { + LOGGER.error(exception," : Unable to unregister object instance %s.",name); + } + } + } + + /** + * Factory method for ObjectNames. + * + * @param brokerId the broker identifier. + * @param packageName the name of the package containing this instance. + * @param className the name of the owner class of this instance. + * @param objectId the object instance identifier. + * @return the object name built according to the given parameters. + */ + private ObjectName createObjectName(UUID brokerId, String packageName, String className, Binary objectId) + { + String asString = new StringBuilder() + .append(Names.DOMAIN_NAME) + .append(':') + .append(Names.BROKER_ID) + .append('=') + .append(brokerId) + .append(',') + .append(Names.PACKAGE) + .append('=') + .append(packageName) + .append(',') + .append(Names.CLASS) + .append('=') + .append(className) + .append(',') + .append(Names.OBJECT_ID) + .append('=') + .append(objectId) + .toString(); + try + { + return new ObjectName(asString); + } catch (MalformedObjectNameException exception) + { + throw new RuntimeException(exception); + } + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/MissingFeatureAttributesException.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/MissingFeatureAttributesException.java new file mode 100644 index 0000000000..160054059b --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/MissingFeatureAttributesException.java @@ -0,0 +1,35 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.domain.model; + +import java.util.List; + +import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute; + +public class MissingFeatureAttributesException extends UnableToBuildFeatureException +{ + private static final long serialVersionUID = 671471705085787235L; + + public MissingFeatureAttributesException(List missingAttributeList) + { + super(String.valueOf(missingAttributeList)); + } +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidArgument.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidArgument.java new file mode 100644 index 0000000000..e38ad4cee0 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidArgument.java @@ -0,0 +1,77 @@ +/* + * + * 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.domain.model; + +import org.apache.qpid.transport.codec.ManagementEncoder; +import org.apache.qpid.transport.util.Logger; + +class QpidArgument extends QpidProperty +{ + private final static Logger LOGGER = Logger.get(QpidArgument.class); + + private Object _defaultValue; + + private Direction _direction; + + public void setDirection(String code) + { + this._direction = Direction.valueOf(code); + } + + public Direction getDirection() + { + return _direction; + } + + public void setDefaultValue(Object defaultValue) + { + this._defaultValue = defaultValue; + } + + public Object getDefaultValue() + { + return _defaultValue; + } + + public boolean isInput(){ + return _direction != Direction.O; + } + + @Override + public String toString () + { + return new StringBuilder() + .append(getJavaType().getName()) + .append(' ') + .append(_name) + .append("(") + .append(_direction) + .append(")") + .toString(); + } + + public void validateAndEncode (Object value,ManagementEncoder encoder) throws ValidationException + { + validate(value); + _type.encode(value, encoder); + LOGGER.debug("Encoded value %S for argument %s. Type is %s",value,_name,_type); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidAttribute.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidAttribute.java new file mode 100644 index 0000000000..d0bc470de9 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidAttribute.java @@ -0,0 +1,104 @@ +/* + * + * 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.domain.model; + +import org.apache.qpid.management.domain.model.type.Type; +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.util.Logger; + +/** + * Layer supertype for qpid properties and statistics. + * + * @author Andrea Gazzarini + */ +class QpidAttribute extends QpidFeature +{ + private final static Logger LOGGER = Logger.get(QpidAttribute.class); + + /** feature type */ + protected Type _type; + + /** feature unit */ + protected String _unit; + + /** + * Returns the units used for numeric values (i.e. seconds, bytes, etc.) + * + * @return the units used for numeric values (i.e. seconds, bytes, etc.) + */ + String getUnit () + { + return _unit; + } + + /** + * Sets the unit for this property. + * + * @param unit the unit of this property. + */ + void setUnit (String unit) + { + this._unit = unit; + LOGGER.debug("Unit : %s", unit); + } + + /** + * Returns the java type (class) of this feature. + * + * @return the java type (class) of this feature. + */ + Class getJavaType () + { + return _type.getJavaType(); + } + + /** + * Sets the type of this feature. + * + * @param type the type of this feature. + */ + void setType (Type type) + { + this._type = type; + } + + /** + * Gets the value of this feature according to its type definition. + * + * @param decoder the decoder used to extract the value. + * @return the value of this feature according to its type definition + */ + Object decodeValue(ManagementDecoder decoder) + { + try { + return _type.decode(decoder); + } catch(RuntimeException exception) { + LOGGER.error(exception,"Unable to decode value for attribute %s",this); + throw exception; + } + } + + @Override + public String toString () + { + return super.toString()+",type="+_type; + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidClass.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidClass.java new file mode 100644 index 0000000000..262e17db9a --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidClass.java @@ -0,0 +1,855 @@ +/* + * + * 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.domain.model; + +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.management.Attribute; +import javax.management.AttributeList; +import javax.management.AttributeNotFoundException; +import javax.management.DynamicMBean; +import javax.management.InvalidAttributeValueException; +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanException; +import javax.management.MBeanInfo; +import javax.management.MBeanOperationInfo; +import javax.management.MBeanRegistration; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.RuntimeOperationsException; + +import org.apache.qpid.management.Protocol; +import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; +import org.apache.qpid.management.domain.model.type.Binary; +import org.apache.qpid.management.domain.services.QpidService; +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; +import org.apache.qpid.transport.util.Logger; + +/** + * Qpid Class definition. + * A type definition for a manageable object. + * This class is also responsible to manage incoming obejct instance data (configuration & instrumentation). + * How can we handle data before schema is injected into this class? simply we must retain that data in raw format. + * This class has 2 states : + * 1) first state is when schema is not yet injected. In this case the incoming object data is retained as is (in raw format); + * 2) second state is when schema is injected. In this case each injection of data will result in an update / create / delete of + * the corresponding object instance. In addition, the first time the state change, the old retained raw data is cnverted in + * object instance(s). + * + * @author Andrea Gazzarini + */ +class QpidClass +{ + /** + * State interface for this class definition. + * Each state is responsible to handle the injection of the object data. + * + * @author Andrea Gazzarini + */ + interface State + { + /** + * Adds configuration data for the object instance associated to the given object identifier. + * + * @param objectId the object identifier. + * @param rawData the raw configuration data. + */ + void addInstrumentationData (Binary objectId, byte[] rawData); + + /** + * Adds instrumentation data for the object instance associated to the given object identifier. + * + * @param objectId the object identifier. + * @param rawData the raw instrumentation data. + */ + void addConfigurationData (Binary objectId, byte[] rawData); + + /** + * Inject the schema into this class definition. + * + * @param propertyDefinitions + * @param statisticDefinitions + * @param methodDefinitions + * @param eventDefinitions + * @throws UnableToBuildFeatureException when it's not possibile to parse schema and build the class definition. + */ + public void setSchema ( + List> propertyDefinitions, + List> statisticDefinitions, + List methodDefinitions, + List eventDefinitions) throws UnableToBuildFeatureException; + }; + + /** + * This is the initial state of every qpid class. + * The class definition instance is created but its schema has not been injected. + * Incoming configuration & instrumentation data will be stored in raw format because we don't know how to + * parse it until the schema arrives. + * In addition, this state is responsible (when data arrives) to request its schema. + */ + final State _schemaNotRequested = new State() { + + /** + * Stores the incoming data in raw format and request the schema for this class. + * After that a transition to the next state is made. + * + * @param objectId the object instance identifier. + * @param rawData incoming configuration data. + */ + public synchronized void addConfigurationData (Binary objectId, byte[] rawData) + { + schemaRequest(); + QpidManagedObject instance = getObjectInstance(objectId,false); + instance._rawConfigurationData.add(rawData); + _state = _schemaRequestedButNotYetInjected; + } + + /** + * Stores the incoming data in raw format and request the schema for this class. + * After that a transition to the next state is made. + * + * @param objectId the object instance identifier. + * @param rawData incoming instrumentation data. + */ + public synchronized void addInstrumentationData (Binary objectId, byte[] rawData) + { + schemaRequest(); + QpidManagedObject instance = getObjectInstance(objectId,false); + instance._rawConfigurationData.add(rawData); + _state = _schemaRequestedButNotYetInjected; + } + + /** + * This method only throws an illegal state exception because when a schema arrives + * this state is no longer valid. + */ + public void setSchema ( + List> propertyDefinitions, + List> statisticDefinitions, + List methodDefinitions, + List eventDefinitions) throws UnableToBuildFeatureException + { + throw new IllegalStateException("When a schema arrives it's not possible for this class to be in this state."); + } + }; + + /** + * This is the first state of this class definition : the schema is not yet injected so each injection of object data will be + * retained in raw format. + */ + final State _schemaRequestedButNotYetInjected = new State() + { + /** + * Stores the incoming data in raw format. + * + * @param objectId the object instance identifier. + * @param rawData incoming configuration data. + */ + public void addConfigurationData (Binary objectId, byte[] rawData) + { + QpidManagedObject instance = getObjectInstance(objectId,false); + instance._rawConfigurationData.add(rawData); + } + + /** + * Stores the incoming data in raw format. + * + * @param objectId the object instance identifier. + * @param rawData incoming instrumentation data. + */ + public void addInstrumentationData (Binary objectId, byte[] rawData) + { + QpidManagedObject instance = getObjectInstance(objectId,false); + instance._rawInstrumentationData.add(rawData); + } + + /** + * When a schema is injected into this defintiion the following should happen : + * 1) the incoming schema is parsed and the class definition is built; + * 2) the retained raw data is converted into object instance(s) + * 3) the internal state of this class changes; + * + * If someting is wrong during that process the schema is not built and the state don't change. + */ + public synchronized void setSchema ( + List> propertyDefinitions, + List> statisticDefinitions, + List methodDefinitions, + List eventDefinitions) throws UnableToBuildFeatureException + { + + MBeanAttributeInfo [] attributesMetadata = new MBeanAttributeInfo[propertyDefinitions.size()+statisticDefinitions.size()]; + MBeanOperationInfo [] operationsMetadata = new MBeanOperationInfo[methodDefinitions.size()]; + + buildAttributes(propertyDefinitions,statisticDefinitions,attributesMetadata); + buildMethods(methodDefinitions,operationsMetadata); + buildEvents(eventDefinitions); + + _metadata = new MBeanInfo(_name,_name,attributesMetadata,null,operationsMetadata,null); + + // Converting stored object instances into JMX MBean and removing raw instance data. + for (Entry instanceEntry : _objectInstances.entrySet()) + { + Binary objectId = instanceEntry.getKey(); + QpidManagedObject instance = instanceEntry.getValue(); + + for (Iterator iterator = instance._rawInstrumentationData.iterator(); iterator.hasNext();) + { + updateInstanceWithInstrumentationData(instance,iterator.next()); + iterator.remove(); + } + + for (Iterator iterator = instance._rawConfigurationData.iterator(); iterator.hasNext();) + { + updateInstanceWithConfigurationData(instance, iterator.next()); + iterator.remove(); + } + + JMX_SERVICE.registerObjectInstance(instance,_parent.getOwnerId(),_parent.getName(),_name,objectId); + } + _state = _schemaInjected; + } + }; + + /** + * After a schema is built into this definition this is the current state of the class. + */ + final State _schemaInjected = new State() + { + /** + * Updates the configuration state of the object instance associates with the given object identifier. + * + * @param objectId the object identifier. + * @param rawData the configuration data (raw format). + */ + public void addConfigurationData (Binary objectId, byte[] rawData) + { + QpidManagedObject instance = getObjectInstance(objectId,true); + updateInstanceWithConfigurationData(instance, rawData); + } + + /** + * Updates the instrumentation state of the object instance associates with the given object identifier. + * + * @param objectId the object identifier. + * @param rawData the instrumentation data (raw format). + */ + public void addInstrumentationData (Binary objectId, byte[] rawData) + { + QpidManagedObject instance = getObjectInstance(objectId,true); + updateInstanceWithInstrumentationData(instance, rawData); + } + + /** + * Never called when the class definition has this state. + */ + public void setSchema ( + List> propertyDefinitions, + List> statisticDefinitions, + List methodDefinitions, + List eventDefinitions) throws UnableToBuildFeatureException + { + throw new IllegalStateException("When a schema arrives it's not possible for this class to be in this state."); + } + }; + + /** + * MBean used for representing remote broker object instances. + * This is the core component of the QMan domain model + * + * @author Andrea Gazzarini + */ + class QpidManagedObject implements DynamicMBean,MBeanRegistration + { + // After this mbean is registered with the MBean server this collection holds the mbean attributes + private Map _attributes = new HashMap(); + private Binary _objectId; + + // Arrays used for storing raw data before this mbean is registered to mbean server. + List _rawInstrumentationData = new ArrayList(); + List _rawConfigurationData = new ArrayList(); + + /** + * Builds a new managed object with the given object identifier. + * + * @param objectId the object identifier. + */ + QpidManagedObject(Binary objectId) + { + this._objectId = objectId; + } + + /** + * Creates or replace the given attribute. + * Note that this is not part of the management interface of this object instance and therefore will be accessible only + * from within this class. + * It is used to update directly the object attributes. + * + * @param attributeName the name of the attribute. + * @param property newValue the new value of the attribute. + */ + void createOrReplaceAttributeValue(String attributeName, Object newValue) + { + _attributes.put(attributeName, newValue); + } + + /** + * Returns the value of the given attribute.s + * + * @throws AttributeNotFoundException when no attribute is found with the given name. + */ + public Object getAttribute (String attributeName) throws AttributeNotFoundException, MBeanException, ReflectionException + { + if (attributeName == null) + { + throw new RuntimeOperationsException(new IllegalArgumentException("attribute name must not be null")); + } + + if (_properties.containsKey(attributeName) || _statistics.containsKey(attributeName)) + { + return _attributes.get(attributeName); + } else + { + throw new AttributeNotFoundException(attributeName); + } + } + + /** + * Get the values of several attributes of the Dynamic MBean. + * + * @param attributes A list of the attributes to be retrieved. + * + * @return The list of attributes retrieved. + */ + public AttributeList getAttributes (String[] attributes) + { + if (attributes == null) + { + throw new RuntimeOperationsException(new IllegalArgumentException("attributes array must not be null")); + } + + AttributeList result = new AttributeList(attributes.length); + for (int i = 0; i < attributes.length; i++) + { + String attributeName = attributes[i]; + try + { + result.add(new Attribute(attributeName,getAttribute(attributeName))); + } catch(Exception exception) + { + // Already logged. + } + } + return result; + } + + /** + * Returns metadata for this object instance. + */ + // Developer Note : note that this metadata is a member of the outer class definition : in that way we create + // that metadata only once and then it will be shared between all object instances (it's a readonly object) + public MBeanInfo getMBeanInfo () + { + return _metadata; + } + + /** + * Executes an operation on this object instance. + * + * @param actionName the name of the method. + * @param params the method parameters + * @param signature the method signature. + */ + public Object invoke (String actionName, Object[] params, String[] signature) throws MBeanException,ReflectionException + { + // TODO : Overloaded methods + QpidMethod method = _methods.get(actionName); + if (method != null) + { + try + { + methodRequest(_objectId, method, params); + return null; + } catch (ValidationException exception) + { + throw new MBeanException(exception); + } + } else { + throw new ReflectionException(new NoSuchMethodException(actionName)); + } + } + + /** + * Sets the value of the given attribute on this object instance. + * + * @param attribute contains the new value of the attribute. + * @throws AttributeNotFoundException when the given attribute is not found on this object instance. + * @throws InvalidAttributeValueException when the given value is violating one attribute invariant. + */ + public void setAttribute (Attribute attribute) throws AttributeNotFoundException, + InvalidAttributeValueException, MBeanException, ReflectionException + { + QpidProperty property = _properties.get(attribute.getName()); + try + { + property.validate(attribute.getValue()); + } catch(ValidationException exception) + { + throw new InvalidAttributeValueException(exception.getMessage()); + } + throw new RuntimeException("Not yet implemented."); + } + + /** + * Sets the values of several attributes of this MBean. + * + * @param attributes a list of attributes: The identification of the attributes to be set and the values they are to be set to. + * @return The list of attributes that were set, with their new values. + */ + public AttributeList setAttributes (AttributeList attributes) + { + throw new RuntimeException("Not yet implemented."); + } + + /** + * MBean server callback after deregistration. + */ + public void postDeregister () + { + } + + /** + * After the object is registered the raw data is set to null. + * This is done because we no longer need this data : it has already been + * injected into this object instance. + * + * @param registrationDone a flag indicating if the instance has been registered to mbean server. + */ + public void postRegister (Boolean registrationDone) + { + if (registrationDone) + { + _rawConfigurationData = null; + _rawInstrumentationData = null; + } + } + + /** + * MBean server callback before deregistration. + */ + public void preDeregister () throws Exception + { + } + + /** + * MBean server callback before registration. + */ + public ObjectName preRegister (MBeanServer server, ObjectName name) throws Exception + { + return name; + } + } + + private final static Logger LOGGER = Logger.get(QpidClass.class); + private final static JmxService JMX_SERVICE = new JmxService(); + + private final String _name; + private final Binary _hash; + + private final QpidPackage _parent; + + Map _properties = new HashMap(); + Map _statistics = new HashMap(); + private Map _methods = new HashMap(); + + private List _schemaOrderedProperties = new ArrayList(); + private List _schemaOrderedStatistics= new ArrayList(); + private MBeanInfo _metadata; + + private final QpidService _service; + + private int _howManyPresenceBitMasks; + + Map _objectInstances = new HashMap(); + State _state = _schemaNotRequested;; + + /** + * Builds a new class with the given name and package as parent. + * + * @param className the name of the class. + * @param hash the class schema hash. + * @param parentPackage the parent of this class. + */ + QpidClass(String className, Binary hash, QpidPackage parentPackage) + { + this._name = className; + this._parent = parentPackage; + this._hash = hash; + this._service = new QpidService(_parent.getOwnerId()); + LOGGER.debug( + " : Class definition has been built (without schema) for %s::%s.%s", + _parent.getOwnerId(), + _parent.getName(), + _name); + } + + /** + * Adds the configuration data for the object instance associated to the given object identifier. + * + * @param objectId the object identifier. + * @param rawData the raw configuration data. + */ + void addInstrumentationData (Binary objectId, byte[] rawData) + { + LOGGER.debug(" : Incoming instrumentation data for %s::%s.%s.%s", + _parent.getOwnerId(), + _parent.getName(), + _name, + objectId); + _state.addInstrumentationData(objectId, rawData); + } + + /** + * Adds the instrumentation data for the object instance associated to the given object identifier. + * + * @param objectId the object identifier. + * @param rawData the raw instrumentation data. + */ + void addConfigurationData (Binary objectId, byte[] rawData) + { + LOGGER.debug(" : Incoming configuration data for %s::%s.%s.%s", + _parent.getOwnerId(), + _parent.getName(), + _name, + objectId); + _state.addConfigurationData(objectId, rawData); + } + + /** + * Sets the schema for this class definition. + * A schema is basically a metadata description of all properties, statistics, methods and events of this class. + * + * @param propertyDefinitions properties metadata. + * @param statisticDefinitions statistics metadata. + * @param methodDefinitions methods metadata. + * @param eventDefinitions events metadata. + * @throws UnableToBuildFeatureException when some error occurs while parsing the incoming schema. + */ + void setSchema ( + List> propertyDefinitions, + List> statisticDefinitions, + List methodDefinitions, + List eventDefinitions) throws UnableToBuildFeatureException + { + LOGGER.info(" : Incoming schema for %s::%s.%s",_parent.getOwnerId(),_parent.getName(),_name); + _state.setSchema(propertyDefinitions, statisticDefinitions, methodDefinitions, eventDefinitions); + } + + /** + * Internal method used for building attributes definitions. + * + * @param props the map contained in the properties schema. + * @param stats the map contained in the statistics schema. + * @param attributes the management metadata for attributes. + * @throws UnableToBuildFeatureException when it's not possibile to build one attribute definition. + */ + void buildAttributes ( + List> props, + List> stats, + MBeanAttributeInfo[] attributes) throws UnableToBuildFeatureException + { + int index = 0; + int howManyOptionalProperties = 0; + + for (Map propertyDefinition : props) + { + QpidFeatureBuilder builder = QpidFeatureBuilder.createPropertyBuilder(propertyDefinition); + builder.build(); + + QpidProperty property = (QpidProperty) builder.getQpidFeature(); + + howManyOptionalProperties += (property.isOptional()) ? 1 : 0; + + _properties.put(property.getName(),property); + _schemaOrderedProperties.add(property); + attributes[index++]=(MBeanAttributeInfo) builder.getManagementFeature(); + + LOGGER.debug( + " : Property definition for %s::%s.%s has been built.", + _parent.getName(), + _name, + property); + } + + _howManyPresenceBitMasks = (int)Math.ceil((double)howManyOptionalProperties / 8); + + LOGGER.debug( + " : Class %s::%s.%s has %s optional properties.", + _parent.getOwnerId(), + _parent.getName(), + _name, + _howManyPresenceBitMasks); + + for (Map statisticDefinition : stats) + { + QpidFeatureBuilder builder = QpidFeatureBuilder.createStatisticBuilder(statisticDefinition); + builder.build(); + QpidStatistic statistic = (QpidStatistic) builder.getQpidFeature(); + + _statistics.put(statistic.getName(),statistic); + _schemaOrderedStatistics.add(statistic); + attributes[index++]=(MBeanAttributeInfo) builder.getManagementFeature(); + + LOGGER.debug( + " : Statistic definition for %s::%s.%s has been built.", + _parent.getName(), + _name, + statistic); + } + } + + /** + * Returns the object instance associated to the given identifier. + * Note that if the identifier is not associated to any obejct instance, a new one will be created. + * + * @param objectId the object identifier. + * @param registration a flag indicating whenever the (new ) instance must be registered with MBean server. + * @return the object instance associated to the given identifier. + */ + QpidManagedObject getObjectInstance(Binary objectId, boolean registration) + { + QpidManagedObject objectInstance = _objectInstances.get(objectId); + if (objectInstance == null) + { + objectInstance = new QpidManagedObject(objectId); + _objectInstances.put(objectId, objectInstance); + if (registration) + { + JMX_SERVICE.registerObjectInstance(objectInstance,_parent.getOwnerId(),_parent.getName(),_name,objectId); + } + } + return objectInstance; + } + + /** + * Internal method used for building event statistics defintions. + * + * @param definitions the properties map contained in the incoming schema. + * @throws UnableToBuildFeatureException when it's not possibile to build one or more definitions. + */ + void buildEvents (List eventDefinitions) + { + // TODO + } + + /** + * Internal method used for building method defintiions. + * + * @param definitions the properties map contained in the incoming schema. + * @param operationsMetadata + * @throws UnableToBuildFeatureException when it's not possibile to build one or more definitions. + */ + void buildMethods (List definitions, MBeanOperationInfo[] operationsMetadata) throws UnableToBuildFeatureException + { + int index = 0; + for (MethodOrEventDataTransferObject definition: definitions) + { + QpidFeatureBuilder builder = QpidFeatureBuilder.createMethodBuilder(definition); + builder.build(); + operationsMetadata [index++]= (MBeanOperationInfo) builder.getManagementFeature(); + QpidMethod method = (QpidMethod) builder.getQpidFeature(); + _methods.put(method.getName(),method); + } + } + + private void schemaRequest() + { + ByteBuffer buffer = ByteBuffer.allocate(100); + ManagementEncoder encoder = new ManagementEncoder(buffer); + buffer.put(Protocol.SCHEMA_REQUEST_FIRST_FOUR_BYTES); + + // TODO + encoder.writeSequenceNo(1000); + encoder.writeStr8(_parent.getName()); + encoder.writeStr8(_name); + _hash.encode(encoder); + buffer.rewind(); + try + { + _service.connect(); + _service.sendCommandMessage(buffer); + _service.sync(); + } catch (Exception exception) + { + exception.printStackTrace(); + // TODO + // Log.logSchemaRequestNotSent(exception, + // _parent.getOwnerId(),_parent.getName(), _name); + } finally + { + _service.close(); + } + } + + /** + * Header (opcode='M') + * ObjectId of target object (128 bits) + * Package name (str8) + * Class name (str8) + * Class hash (bin128) + * Method name (str8) [as defined in the schema] + * Now encode all input ("I") and i/o (IO) arguments in the order in which they are defined in the schema. + * (i.e. make one pass over the argument list and encode arguments that are either input or inptu/output). + + * @param objectId + * @param method + * @param parameters + * @throws ValidationException + */ + private void methodRequest(Binary objectId,QpidMethod method,Object [] parameters) throws ValidationException + { + ByteBuffer buffer = ByteBuffer.allocate(1000); + ManagementEncoder encoder = new ManagementEncoder(buffer); + buffer.put(Protocol.METHOD_REQUEST_FIRST_FOUR_BYTES); + encoder.writeSequenceNo(0); + objectId.encode(encoder); + encoder.writeStr8(_parent.getName()); + encoder.writeStr8(_name); + _hash.encode(encoder); + encoder.writeStr8(method.getName()); + method.encodeParameters(parameters,encoder); + + buffer.rewind(); + try + { + _service.connect(); + _service.sendCommandMessage(buffer); + //_service.sync(); + } catch (Exception exception) + { + exception.printStackTrace(); + // TODO + // Log.logSchemaRequestNotSent(exception, + // _parent.getOwnerId(),_parent.getName(), _name); + } finally + { + _service.close(); + } + } + + /** + * Updates the given obejct instance with the given incoming configuration data. + * + * @param instance the managed object instance. + * @param rawData the incoming configuration data which contains new values for instance properties. + */ + private void updateInstanceWithConfigurationData(QpidManagedObject instance,byte [] rawData) + { + ManagementDecoder decoder = new ManagementDecoder(); + decoder.init(ByteBuffer.wrap(rawData)); + + byte [] presenceBitMasks = decoder.readBytes(_howManyPresenceBitMasks); + for (QpidProperty property : _schemaOrderedProperties) + { + try { + Object value = property.decodeValue(decoder,presenceBitMasks); + instance.createOrReplaceAttributeValue(property.getName(),value); + } catch(Exception ignore) { + LOGGER.error("Unable to decode value for %s::%s::%s", _parent.getName(),_name,property.getName()); + } + } + } + + /** + * Updates the given object instance with the given incoming instrumentation data. + * + * @param instance the managed object instance. + * @param rawData the incoming instrumentation data which contains new values for instance properties. + */ + private void updateInstanceWithInstrumentationData(QpidManagedObject instance,byte [] rawData) + { + ManagementDecoder decoder = new ManagementDecoder(); + decoder.init(ByteBuffer.wrap(rawData)); + + for (QpidStatistic statistic : _schemaOrderedStatistics) + { + try { + Object value = statistic.decodeValue(decoder); + instance.createOrReplaceAttributeValue(statistic.getName(),value); + } catch(Exception ignore) { + LOGGER.error("Unable to decode value for %s::%s::%s", _parent.getName(),_name,statistic.getName()); + } + } + } + + @Override + public String toString () + { + return new StringBuilder() + .append(_parent.getOwnerId()) + .append("::") + .append(_parent.getName()) + .append("::") + .append(_name) + .toString(); + } + + /** + * Removes the object instance associated to the given identifier. + * + * @param objectId the object identifier. + */ + void removeObjectInstance (Binary objectId) + { + QpidManagedObject toBeRemoved = _objectInstances.remove(objectId); + if (toBeRemoved != null) + { + JMX_SERVICE.unregisterObjectInstance(_parent.getOwnerId(),_parent.getName(),_name,toBeRemoved._objectId); + } + } + + /** + * Deregisters all the object instances and release all previously acquired resources. + */ + void releaseResources () + { + for (Iterator iterator = _objectInstances.keySet().iterator(); iterator.hasNext();) + { + Binary objectId = iterator.next(); + JMX_SERVICE.unregisterObjectInstance(_parent.getOwnerId(),_parent.getName(),_name,objectId); + iterator.remove(); + LOGGER.debug( + "%s.%s.%s object instance has been removed from broker %s", + _parent.getName(), + _name,objectId, + _parent.getOwnerId()); + } + _service.close(); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidEvent.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidEvent.java new file mode 100644 index 0000000000..200791bb93 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidEvent.java @@ -0,0 +1,26 @@ +/* + * + * 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.domain.model; + +class QpidEvent extends QpidFeature +{ + // NOT YET IMPLEMENTED +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeature.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeature.java new file mode 100644 index 0000000000..5fccb0a858 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeature.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.domain.model; + +/** + * Layer Supertype for all qpid management features. + * + * @author Andrea Gazzarini + */ +abstract class QpidFeature +{ + /** The name of the feature. */ + protected String _name; + + /** + * The description of the feature. + */ + protected String _description; + + /** + * Returns the description of this feature. + * + * @return the description of this feature. + */ + String getDescription () + { + return _description; + } + + /** + * Sets the description for this feature. + * + * @param description the description for this feature. + */ + void setDescription (String description) + { + this._description = description; + } + + /** + * Returns the name of the feature. + * + * @return the name of the feature. + */ + String getName () + { + return _name; + } + + /** + * Sets the name for this feature. + * + * @param name the name of this feature. + */ + void setName (String name) + { + this._name = name; + } + + /** + * Returns the name of the feature. + * + * @return the name of the feature. + */ + @Override + public String toString () + { + return _name; + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeatureBuilder.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeatureBuilder.java new file mode 100644 index 0000000000..4bac16452c --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidFeatureBuilder.java @@ -0,0 +1,444 @@ +/* + * + * 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.domain.model; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanFeatureInfo; +import javax.management.MBeanOperationInfo; +import javax.management.MBeanParameterInfo; + +import org.apache.qpid.management.configuration.Configuration; +import org.apache.qpid.management.configuration.UnknownTypeCodeException; +import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; + +/** + * A builder used to parse incoming schema message and therefore to build a feature (property, statistic, method, event) + * definition. + * In order to set up the correct state for this builder, clients must create an instance of this class + * The product of the builder will be a QpidFeature and a JMX Managemtn feature used for describing that feature in a + * JMX environment. So, for example, for building a property definition client code should be : + * + *
- QpidFeatureBuilder builder = QpidFeature.createPropertyBuilder(...); + *
- builder.build(); + *
- QpidProperty property = (QpidProperty) builder.getQpidFeature(); + *
- MBeanAttributeInfo managementAttributeInfo = (MBeanAttributeInfo)builder.getManagementFeature(); + * + *
N.B.: a builder instance is not supposed to be reused. One instance for one feature! + * + * @author Andrea Gazzarini + */ +class QpidFeatureBuilder +{ + + static enum Attribute { + name,type,access,index,optional,unit,min,max,maxlen,desc,dir,argCount; + }; + + private List _mandatoryAttributes = new ArrayList(); + + /** + * Builder state for this class. + * Each concrete implementor is a builder for a specific feature. + * using the appropriate factory method. + * + * @author Andrea Gazzarini + */ + interface State { + void build() throws UnableToBuildFeatureException; + } + + /** + * Builder used for building property definition. + */ + final State _propertyBuilder = new State() { + + /** + * Builds a property definition as well a management attribute feature. + */ + public void build () throws UnableToBuildFeatureException + { + QpidProperty property = new QpidProperty(); + try { + int optionalIndex = 0; + for (Entry propertyAttribute : _featureDefinition.entrySet()) + { + Attribute attribute = Attribute.valueOf(propertyAttribute.getKey()); + switch(attribute) + { + case name : + { + property.setName(String.valueOf(propertyAttribute.getValue())); + break; + } + case access : + { + int code = (Integer)propertyAttribute.getValue(); + property.setAccessMode(Configuration.getInstance().getAccessMode(code)); + break; + } + case unit : + { + property.setUnit(String.valueOf(propertyAttribute.getValue())); + break; + } + case min : + { + property.setMinValue((Integer)propertyAttribute.getValue()); + break; + } + case max : + { + property.setMaxValue((Integer)propertyAttribute.getValue()); + break; + } + case maxlen : + { + property.setMaxLength((Integer)propertyAttribute.getValue()); + break; + } + case desc : + { + property.setDescription(String.valueOf(propertyAttribute.getValue())); + break; + } + case type : + { + int code = (Integer) propertyAttribute.getValue(); + property.setType(Configuration.getInstance().getType(code)); + break; + } + case index : + { + break; + } + case optional : + { + int code = (Integer) propertyAttribute.getValue(); + if (code == 1) + { + property.markAsOptional(optionalIndex); + optionalIndex++; + } + break; + } + } + _mandatoryAttributes.remove(attribute); + } + } catch(Exception exception) + { + throw new UnableToBuildFeatureException(exception,property.getName()); + } + + if (!_mandatoryAttributes.isEmpty()) + { + throw new MissingFeatureAttributesException(_mandatoryAttributes); + } + + _managementFeatureInfo = new MBeanAttributeInfo( + property.getName(), + property.getJavaType().getName(), + property.getDescription(), + true, + property.getAccessMode()==AccessMode.RW, + false); + _qpidFeature = property; + } + }; + + final State _statisticBuilder = new State() + { + public void build () throws UnableToBuildFeatureException + { + QpidStatistic statistic = new QpidStatistic(); + try + { + for (Entry statisticAttribute : _featureDefinition.entrySet()) + { + Attribute attribute = Attribute.valueOf(statisticAttribute.getKey()); + switch(attribute) + { + case name : + { + statistic.setName(String.valueOf(statisticAttribute.getValue())); + break; + } + case unit : + { + statistic.setUnit(String.valueOf(statisticAttribute.getValue())); + break; + } + case desc : + { + statistic.setDescription(String.valueOf(statisticAttribute.getValue())); + break; + } + case type : + { + int code = (Integer) statisticAttribute.getValue(); + statistic.setType(Configuration.getInstance().getType(code)); + break; + } + } + _mandatoryAttributes.remove(attribute); + } + } catch(Exception exception) + { + throw new UnableToBuildFeatureException(exception,statistic.getName()); + } + + if (!_mandatoryAttributes.isEmpty()) + { + throw new MissingFeatureAttributesException(_mandatoryAttributes); + } + + _managementFeatureInfo = new MBeanAttributeInfo( + statistic.getName(), + statistic.getJavaType().getName(), + statistic.getDescription(), + true, + false, + false); + _qpidFeature = statistic; + } + }; + + /** + * Builder used for building a statistic definition. + */ + final State _argumentBuilder = new State() + { + /** + * Builds a property definition as well a management attribute feature. + */ + public void build () throws UnableToBuildFeatureException + { + QpidArgument argument = new QpidArgument(); + for (Entry argumentAttribute : _featureDefinition.entrySet()) + { + String key = argumentAttribute.getKey(); + if ("default".equals(key)) + { + argument.setDefaultValue(argumentAttribute.getValue()); + } else { + Attribute attribute = Attribute.valueOf(key); + switch (attribute) + { + case name : + { + argument.setName((String)argumentAttribute.getValue()); + break; + } + case desc : + { + argument.setDescription((String)argumentAttribute.getValue()); + break; + } + case type : + { + try + { + argument.setType(Configuration.getInstance().getType((Integer)argumentAttribute.getValue())); + break; + } catch(UnknownTypeCodeException exception) + { + throw new UnableToBuildFeatureException(exception,argument.getName()); + } + } + case dir : + { + argument.setDirection((String)argumentAttribute.getValue()); + break; + } + case unit : + { + argument.setUnit((String)argumentAttribute.getValue()); + break; + + } + } + } + } + + if (!_mandatoryAttributes.isEmpty()) + { + throw new MissingFeatureAttributesException(_mandatoryAttributes); + } + + _qpidFeature = argument; + _managementFeatureInfo = new MBeanParameterInfo( + argument.getName(), + argument.getJavaType().getName(), + argument.getDescription()); + } + }; + + final State _methodBuilder = new State() + { + public void build () throws UnableToBuildFeatureException + { + Map definition = _methodOrEventDefinition.getDefinition(); + String name = (String)definition.get(Attribute.name.name()); + if (name == null) + { + throw new MissingFeatureAttributesException(_mandatoryAttributes); + } + + QpidMethod method = new QpidMethod((String)definition.get("name"),(String) definition.get("desc")); + + List> args = _methodOrEventDefinition.getArgumentsDefinitions(); + + List signature = new LinkedList(); + + for (Map argumentDefinition : args) + { + QpidFeatureBuilder builder = QpidFeatureBuilder.createArgumentBuilder(argumentDefinition); + builder.build(); + + QpidArgument argument = (QpidArgument) builder.getQpidFeature(); + method.addArgument(argument); + if (argument.isInput()) + { + signature.add((MBeanParameterInfo) builder.getManagementFeature()); + } + } + + _qpidFeature = method; + _managementFeatureInfo = new MBeanOperationInfo( + method.getName(), + method.getDescription(), + (MBeanParameterInfo[])signature.toArray(new MBeanParameterInfo[signature.size()]), + void.class.getName(), + MBeanOperationInfo.ACTION); + } + }; + + final State _eventBuilder = new State() + { + public void build () throws UnableToBuildFeatureException + { + } + }; + + private MBeanFeatureInfo _managementFeatureInfo; + private QpidFeature _qpidFeature; + private final Map _featureDefinition; + private final MethodOrEventDataTransferObject _methodOrEventDefinition; + private State _state; + + static QpidFeatureBuilder createPropertyBuilder(Map propertyDefinition) + { + QpidFeatureBuilder result = new QpidFeatureBuilder(propertyDefinition); + result._state = result._propertyBuilder; + result._mandatoryAttributes.add(Attribute.name); + result._mandatoryAttributes.add(Attribute.access); + result._mandatoryAttributes.add(Attribute.type); + result._mandatoryAttributes.add(Attribute.optional); + result._mandatoryAttributes.add(Attribute.index); + return result; + } + + static QpidFeatureBuilder createStatisticBuilder(Map statisticDefinition) + { + QpidFeatureBuilder result = new QpidFeatureBuilder(statisticDefinition); + result._state = result._statisticBuilder; + result._mandatoryAttributes.add(Attribute.name); + result._mandatoryAttributes.add(Attribute.type); + return result; + } + + static QpidFeatureBuilder createEventBuilder(Map eventDefinition) + { + QpidFeatureBuilder result = new QpidFeatureBuilder(eventDefinition); + result._state = result._eventBuilder; + return result; + } + + static QpidFeatureBuilder createMethodBuilder(MethodOrEventDataTransferObject methodDefinition) + { + QpidFeatureBuilder result = new QpidFeatureBuilder(methodDefinition); + result._state = result._methodBuilder; + result._mandatoryAttributes.add(Attribute.name); + return result; + } + + private static QpidFeatureBuilder createArgumentBuilder(Map argumentDefinition) + { + QpidFeatureBuilder result = new QpidFeatureBuilder(argumentDefinition); + result._state = result._argumentBuilder; + return result; + } + + + /** + * Builds new builder with the given data. + * This constructor is used for building properties, statistics and arguments. + * + * @param definition the feature definition data. + */ + private QpidFeatureBuilder(Map definition) + { + this._featureDefinition = definition; + this._methodOrEventDefinition = null; + } + + /** + * Builds new builder with the given data. + * This constructor is used for building properties, statistics and arguments. + * + * @param definition the feature definition data. + */ + private QpidFeatureBuilder(MethodOrEventDataTransferObject definition) + { + this._featureDefinition = null; + this._methodOrEventDefinition = definition; + } + + /** + * Returns the just built qpid feature. + * + * @return the qpid feature. + */ + QpidFeature getQpidFeature() + { + return _qpidFeature; + } + + /** + * Return the jmx metadata for the built feature. + * + * @return the jmx metadata for the built feature. + */ + MBeanFeatureInfo getManagementFeature() + { + return _managementFeatureInfo; + } + + void build() throws UnableToBuildFeatureException + { + _state.build(); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidMethod.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidMethod.java new file mode 100644 index 0000000000..4d4918e45f --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidMethod.java @@ -0,0 +1,103 @@ +/* + * + * 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.domain.model; + +import java.util.LinkedList; +import java.util.List; + +import org.apache.qpid.transport.codec.ManagementEncoder; + +/** + * Qpid method definition. + * An entity describing an invocation that can be made on a managed object instance. + * + * @author Andrea Gazzarini + */ +class QpidMethod extends QpidFeature +{ + /** Argument list */ + List arguments = new LinkedList(); + + /** + * Builds a new qpid method definition with the given name and description. + * + * @param name the method name. + * @param description the method description. + */ + QpidMethod(String name, String description) + { + this._name = name; + this._description = description; + } + + /** + * Adds an argument to this method. + * + * @param argument the new argument to be added. + */ + void addArgument(QpidArgument argument) + { + arguments.add(argument); + } + + /** + * Returns a string representation of this method. + * The result format is (argType1 argName1 (Direction), argType2 argName2 (Direction), etc...) + * + * @return a string representation of this method. + */ + @Override + public String toString () + { + StringBuilder builder = new StringBuilder() + .append(_name) + .append('('); + + for (QpidArgument argument : arguments) + { + builder.append(argument).append(','); + } + + builder.append(')'); + return builder.toString(); + } + + /** + * Encodes the given parameter values according to this method arguments definitions. + * Also provide a validation of the given values according to the invariants defined for each argument. + * Note that only Input/Output and Output parameters are encoded. + * + * @param parameters the parameters values. + * @param encoder the encoder used for encoding. + * @throws ValidationException when one of the given values is violating an argument invariant. + */ + void encodeParameters (Object[] parameters, ManagementEncoder encoder) throws ValidationException + { + int index = 0; + for (QpidArgument argument : arguments) + { + if (argument.getDirection() != Direction.O) + { + argument.validateAndEncode(parameters[index++],encoder); + } + } + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java new file mode 100644 index 0000000000..524121afe5 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java @@ -0,0 +1,227 @@ +/* + * + * 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.domain.model; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; +import org.apache.qpid.management.domain.model.type.Binary; + +/** + * Qpid package definition. + * A grouping of class definitions that are related to a single software component. + * The package concept is used to extend the management schema beyond just the QPID software components. + * The name is prefixed with "Qpid" for avoiding name conficts with java.lang.Package. + * + * @author Andrea Gazzarini + */ +final class QpidPackage +{ + /** + * Qpid class identity. + * Each qpid class is uniquely identifier by its name and schema-hash. + * The schema hash is an MD5 checksum of the schema for a class. + * It is there so we can support the case where two different versions of the same class are present at the same time. + * + * @author Andrea Gazzarini + */ + class QpidClassIdentity { + final String name; + final Binary hash; + + /** + * Builds a new class identity with the given name and hash. + * + * @param name the class name. + * @param hash is an MD5 checksum of the schema of this outer class. + */ + QpidClassIdentity(String name,Binary hash) { + this.name = name; + this.hash = hash; + } + + @Override + public int hashCode () + { + return name.hashCode()+hash.hashCode(); + } + + @Override + public boolean equals (Object obj) + { + QpidClassIdentity identity = (QpidClassIdentity) obj; + return name.equals(identity.name) && hash.equals(identity.hash); + } + } + + private String _name; + private DomainModel _parent; + private Map _classes = new HashMap(); + + /** + * Builds a new package with the supplied name. + * + * @param name the name of the package. + */ + QpidPackage(String name, DomainModel parent) + { + this._name = name; + this._parent = parent; + } + + /** + * Returns the identifier of the broker which contains this package. + * @return + */ + UUID getOwnerId() + { + return _parent.getBrokerId(); + } + + /** + * Returns the name of this package. + * + * @return the name of this package. + */ + String getName () + { + return _name; + } + + /** + * Adds a class definition to this package. + * The class will be added only if its definition doesn't already exists. + * + * @param className the name of the class. + * @param classHash the class schema hash. + * @param properties the properties of the class. + * @param statistics the statistics of the class. + * @param methods the methods of the class. + * @param events the events of the class. + * + * @throws UnableToBuildFeatureException when the class definition cannot be built due to a feature build failure. + */ + void addClassDefinition ( + String className, + Binary classHash, + List> properties, + List> statistics, + List methods, + List events) throws UnableToBuildFeatureException + { + getQpidClass(className,classHash,true).setSchema(properties,statistics,methods, events); + } + + /** + * Returns true if this package contains the given class definition. + * + * @param className the name of the class. + * @return true if this package contains the class definition, false otherwise. + */ + boolean alreadyContainsClassDefinition (String className, Binary hash) + { + return _classes.containsKey(new QpidClassIdentity(className,hash)); + } + + /** + * Injects into a class the given object instance instrumentation data. + * + * @param className the of the class the injected object data belongs to. + * @param objectId the object identifier. + * @param rawData the instrumentation data (in raw format). + */ + void setObjectInstanceInstrumentationRawData (String className, Binary classHash,Binary objectId, byte[] rawData) + { + getQpidClass(className, classHash,true).addInstrumentationData(objectId,rawData); + } + + /** + * Injects into a class the given object instance configuration data. + * + * @param className the of the class the injected object data belongs to. + * @param objectId the object identifier. + * @param rawData the configuration data (in raw format). + */ + void setObjectInstanceConfigurationRawData (String className,Binary classHash, Binary objectId, byte[] rawData) + { + getQpidClass(className,classHash,true).addConfigurationData(objectId,rawData); + } + + /** + * Returns the definition of the class with given name. + * + * @param className the name of the class. + * @param hash the class hash. + * @param store a flag indicating if a just created class must be stored or not. + * @return the definition of the class with given name. + */ + QpidClass getQpidClass(String className, Binary hash, boolean store) + { + QpidClassIdentity identity = new QpidClassIdentity(className,hash); + QpidClass classDefinition = _classes.get(identity); + if (classDefinition == null) + { + classDefinition = new QpidClass(className, hash,this); + if (store) + { + _classes.put(identity,classDefinition); + } + } + return classDefinition; + } + + /** + * Returns a string representation of this class. + * That is, this method returns the simple name (not FQN) of this class. + */ + @Override + public String toString () + { + return _name; + } + + /** + * Removes the object instance associated to the given parameters. + * + * @param className the class definition of the object instance. + * @param classHash the class hash + * @param objectId the object identifier. + */ + void removeObjectInstance (String className, Binary classHash, Binary objectId) + { + QpidClass qpidClass = getQpidClass(className,classHash,false); + qpidClass.removeObjectInstance(objectId); + } + + /** + * Releases all previously acquired resources of this package. + */ + void releaseResources () + { + for (QpidClass qpidClass : _classes.values()) + { + qpidClass.releaseResources(); + } + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidProperty.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidProperty.java new file mode 100644 index 0000000000..8b2544af1c --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidProperty.java @@ -0,0 +1,295 @@ +/* + * + * 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.domain.model; + +import java.lang.reflect.Constructor; + +import org.apache.qpid.management.configuration.Configuration; +import org.apache.qpid.management.domain.model.type.Type; +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.util.Logger; + +/** + * Qpid property definition. + * + * @author Andrea Gazzarini + */ +class QpidProperty extends QpidAttribute +{ + private final static Logger LOGGER = Logger.get(QpidProperty.class); + + private final static int [] MASKS = {1,2,4,8,16,32,64,128}; + + /** + * Decoder interface used for decoding incomng values for this property. + * + * @author Andrea Gazzarini + */ + interface Decoder + { + Object decodeValue(ManagementDecoder decoder,byte [] presenceBitMasks); + } + + /** + * Decoder used for decoding incoming values for this optional property. + */ + final Decoder _optionalPropertyDecoder = new Decoder() { + + public Object decodeValue (ManagementDecoder decoder, byte[] presenceBitMasks) + { + return ((presenceBitMasks[_optionalIndex/8] & MASKS[_maskIndex]) != 0) + ? QpidProperty.this.decodeValue(decoder) + : null; + } + }; + + /** + * Decoder used for decoding incoming values for this mandatory property. + */ + final Decoder _mandatoryPropertyDecoder = new Decoder() { + + public Object decodeValue (ManagementDecoder decoder, byte[] presenceBitMasks) + { + return QpidProperty.this.decodeValue(decoder); + } + }; + + + /** + * Null object used to perform a dummy validation. + * This is the default validator installed at creation time. + */ + final static IValidator EMPTY_VALIDATOR = new IValidator() + { + public void validate (Object value) throws ValidationException + { + // Nothing to do here. + } + }; + + /** + * Validator responsible for validating strings. + * At the moment the only constraint that should be applied to a string feature is the "max length" + */ + class StringValidator implements IValidator + { + public void validate (Object value) throws ValidationException + { + if ((_maxLength != Integer.MIN_VALUE) && (value != null)){ + int length = value.toString().length(); + if (length > _maxLength) { + throw new ValidationException( + ValidationException.MAX_LENGTH, + _maxLength, + _name, + length); + } + } + } + }; + + /** + * Validator responsible for validating numbers. + */ + class NumberValidator implements IValidator + { + public void validate (Object value) throws ValidationException + { + if (value != null) { + double numericValue = ((Number)value).doubleValue(); + if (_minValue != Integer.MIN_VALUE && numericValue < _minValue) { + throw new ValidationException( + ValidationException.MIN_VALUE, + _minValue, + _name, + numericValue); + } + + if (_maxValue != Integer.MIN_VALUE && numericValue > _maxValue) { + throw new ValidationException( + ValidationException.MAX_VALUE, + _maxValue, + _name, + numericValue); + } + } + } + }; + + private AccessMode _accessMode; + private int _minValue = Integer.MIN_VALUE; + private int _maxValue = Integer.MIN_VALUE; + private int _maxLength = Integer.MIN_VALUE; + + private int _optionalIndex; + private int _maskIndex; + + Decoder _decoder = _mandatoryPropertyDecoder; + + private IValidator _validator = EMPTY_VALIDATOR; + + /** + * Validates the given value according to the current validator. + * It delegates the validation to the current installed validator. + * + * @param value the value of this qpid property. + * @throws ValidationException when the given value is violating the current validator constraints. + */ + void validate(Object value) throws ValidationException { + _validator.validate(value); + } + + /** + * Sets the type of this property. + * In addition this method tries to detect if a validator has been associated with the type. + * If no validator is found then the default validator will be used; that is : no validator will be performed on this + * property. + * + * @param type the type of this property. + */ + void setType (Type type) + { + super.setType(type); + try { + Class validatorClass = Class.forName(Configuration.getInstance().getValidatorClassName(type)); + Constructor validatorConstructor = validatorClass.getDeclaredConstructor(QpidProperty.class); + _validator = (IValidator) validatorConstructor.newInstance(this); + LOGGER.debug("Validator %s for type %s successfully installed." ,validatorClass.getName(), type); + } catch(Exception exception) { + _validator = EMPTY_VALIDATOR; + LOGGER.debug("No validator was found for type %s. The default (empty) validator will be used." , type); + } + } + + /** + * Gets the value of this property according to its type definition. + * + * @param decoder the decoder used to extract the value. + * @return the value of this feature according to its type definition + */ + Object decodeValue(ManagementDecoder decoder,byte [] presenceBitMasks) + { + return _decoder.decodeValue(decoder, presenceBitMasks); + } + + /** + * Sets access mode for this property. + * + * @param accessMode the access mode for this property. + */ + void setAccessMode (AccessMode accessMode) + { + this._accessMode = accessMode; + } + + /** + * Gets the minimum allowed value for this property. + * + * @return the minimum allowed value for this property. + */ + int getMinValue () + { + return _minValue; + } + + /** + * Sets the minimum allowed value for this property. + * + * @param minValue the minimum allowed value for this property. + */ + void setMinValue (int minValue) + { + this._minValue = minValue; + } + + /** + * Gets the maximum allowed value for this property. + * + * @return the maximum allowed value for this property. + */ + int getMaxValue () + { + return _maxValue; + } + + /** + * Sets the masimum allowed value for this property. + * + * @param maxValue the maximum allowed value for this property. + */ + void setMaxValue (int maxValue) + { + this._maxValue = maxValue; + } + + /** + * Gets the max length value for this property. + * + * @return the max length value for this property. + */ + int getMaxLength () + { + return _maxLength; + } + + /** + * Sets the max length value for this property. + * + * @param maxLength the max length value for this property. + */ + void setMaxLength (int maxLength) + { + this._maxLength = maxLength; + } + + /** + * Gets the description of this property. + * + * @return the description of this property. + */ + AccessMode getAccessMode () + { + return _accessMode; + } + + /** + * Marks this property as optional. + * + * @param optional the optional attribute value for this property. + * @param index the index of this optional property + */ + void markAsOptional (int index) + { + this._optionalIndex = index; + this._maskIndex = (_optionalIndex >= 8) ? _optionalIndex-8 : _optionalIndex; + _decoder = _optionalPropertyDecoder; + } + + /** + * Returns true if this property is marked as optional. + * + * @return true if this property is marked as optional, false otherwise. + */ + boolean isOptional () + { + return _decoder == _optionalPropertyDecoder; + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidStatistic.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidStatistic.java new file mode 100644 index 0000000000..37a652c098 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidStatistic.java @@ -0,0 +1,34 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.domain.model; + +/** + * Qpid statistic definition. + * + * A statistic is a typed member of a class which represents an instrumentation attribute of the class. + * Statistics are always read-only in nature and tend to change rapidly. + * + * @author Andrea Gazzarini + */ +class QpidStatistic extends QpidAttribute +{ + // EMPTY CLASS : Statistic metadata are all defined in superclasses. +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/UnableToBuildFeatureException.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/UnableToBuildFeatureException.java new file mode 100644 index 0000000000..59721240d0 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/UnableToBuildFeatureException.java @@ -0,0 +1,51 @@ +/* + * + * 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.domain.model; + +/** + * Thrown when a feature (property, statistic, method or event) definition cannot be built due to schema parsing errors. + * + * @author Andrea Gazzarini + */ +public class UnableToBuildFeatureException extends Exception +{ + private static final long serialVersionUID = 5180111828887602836L; + + /** + * Builds a new UnableToBuildFeatureException with the specified cause. + * + * @param exception the exception cause. + */ + UnableToBuildFeatureException(Exception exception, String featureName) + { + super( (featureName != null) ? featureName : "Not available" ,exception); + } + + /** + * Builds a new UnableToBuildFeatureException with the specified message. + * + * @param message the detail message. + */ + UnableToBuildFeatureException(String message) + { + super(message); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/ValidationException.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/ValidationException.java new file mode 100644 index 0000000000..3b117e5b9d --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/ValidationException.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.domain.model; + +/** + * Thrown when an attempt is made in order to update / change the state of an object and a constraint on that state + * is violated. + * + * @author Andrea Gazzarini + */ +public class ValidationException extends Exception +{ + private static final long serialVersionUID = -5218828669655586205L; + + public final static String MAX_LENGTH = "Max Length"; + public final static String MAX_VALUE = "Max Value"; + public final static String MIN_VALUE = "Min Value"; + + private final String _featureName; + private final Object _featureValue; + + private final Number _constraintValue; + private final String _constraintName; + + /** + * Builds a new validation exception with the specified parameters. + * + * @param constraintName the name of the violated constraint. + * @param constraintValue the value of the violated constraint. + * @param featureName the name of the violating feature. + * @param featureValue the value of the violating feature. + */ + ValidationException(String constraintName,Number constraintValue, String featureName,Object featureValue) + { + super(String.format( + "Property constraint violation : " + + "%s allowed for property %s is %s but received value was %s", + constraintName, + featureName, + constraintValue, + featureValue)); + this._constraintName = constraintName; + this._constraintValue = constraintValue; + this._featureName = featureName; + this._featureValue = featureValue; + } + + /** + * Returns the value of the violating feature. + * + * @return the value of the violating feature. + */ + public Object getFeatureValue () + { + return _featureValue; + } + + /** + * Returns the name of the violating feature. + * + * @return the name of the violating feature. + */ + public String getFeatureName() + { + return _featureName; + } + + /** + * Returns the value of the violated constraint. + * + * @return the value of the violated constraint. + */ + public Number getConstraintValue () + { + return _constraintValue; + } + + /** + * Returns the name of the violated constraint. + * + * @return the name of the violated constraint. + */ + public String getConstraintName () + { + return _constraintName; + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/AbsTime.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/AbsTime.java new file mode 100644 index 0000000000..27bfa62e2b --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/AbsTime.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class AbsTime extends Type +{ + public AbsTime() + { + super(Long.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return decoder.readUint64(); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeUint64((Long)value); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java new file mode 100644 index 0000000000..d6d25534d8 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java @@ -0,0 +1,129 @@ +/* + * + * 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.domain.model.type; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.UUID; + +import org.apache.qpid.transport.codec.ManagementEncoder; + +/** + * It is a simple wrapper for a byte array (for example a 128bin). + * It is used to let QMan deal with an object instead of an array. + * + * @author Andrea Gazzarini + */ +public final class Binary implements Serializable +{ + private static final long serialVersionUID = -6865585077320637567L; + + // instance identifider. + private final UUID uuid; + + // Marker internal (empty) interface + private interface State extends Serializable{} + + /** + * Internal state of this object used to denote the situation when the hashcode() method has never been called. + * After the hashcode has been computed this class switches the state of the outer object to the next state. + */ + State hashCodeNotYetComputed = new State() + { + private static final long serialVersionUID = 221632033761266959L; + + @Override + public int hashCode () + { + hashCode = Arrays.hashCode(bytes); + state = hashCodeAlreadyComputed; + return hashCode; + } + }; + + /** + * Internal state of this object used to denote the situation where the hashcode() method has already been computed. + * Simply it returns the just computed value for the hashcode. + */ + State hashCodeAlreadyComputed = new State() + { + private static final long serialVersionUID = 221632033761266959L; + + @Override + public int hashCode () + { + return hashCode; + } + }; + + private final byte [] bytes; + private int hashCode; + + /** Current state (hashcode computation). */ + State state = hashCodeNotYetComputed; + + /** + * Builds a new binary with the given byte array. + * + * @param bytes the wrapped data. + */ + public Binary(byte [] bytes) + { + this.bytes = bytes; + uuid = UUID.randomUUID(); + } + + @Override + public int hashCode () + { + return state.hashCode(); + } + + @Override + public boolean equals (Object obj) + { + try + { + Binary binary = (Binary)obj; + return Arrays.equals(bytes, binary.bytes); + } catch (Exception exception) + { + return false; + } + } + + /** + * Encodes the content (wrapped byte array) of this instance using the given encoder. + * + * @param encoder the encoder used to encode instance content. + */ + public void encode(ManagementEncoder encoder) + { + encoder.writeBin128(bytes); + } + + // TODO + @Override + public String toString () + { + return uuid.toString(); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Boolean.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Boolean.java new file mode 100644 index 0000000000..89867bd4c4 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Boolean.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class Boolean extends Type +{ + public Boolean() + { + super(java.lang.Boolean.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return (decoder.readUint8() == 1); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeUint8( ((java.lang.Boolean)value) ? (short)1 : (short)0); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/DeltaTime.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/DeltaTime.java new file mode 100644 index 0000000000..85724f34c8 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/DeltaTime.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class DeltaTime extends Type +{ + public DeltaTime() + { + super(Long.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return decoder.readUint64(); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeUint64((Long)value); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Map.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Map.java new file mode 100644 index 0000000000..f7d6101d3f --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Map.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class Map extends Type +{ + public Map() + { + super(java.util.Map.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return decoder.readMap(); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeMap((java.util.Map)value); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/ObjectReference.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/ObjectReference.java new file mode 100644 index 0000000000..784571e0c0 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/ObjectReference.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class ObjectReference extends Type +{ + public ObjectReference() + { + super(byte[].class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return decoder.readBin128(); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + ((Binary)value).encode(encoder); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Str16.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Str16.java new file mode 100644 index 0000000000..7ab1c667f0 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Str16.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class Str16 extends Type +{ + public Str16() + { + super(String.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return decoder.readStr16(); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeStr16((String)value); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Str8.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Str8.java new file mode 100644 index 0000000000..f8f48bc8ec --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Str8.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class Str8 extends Type +{ + public Str8() + { + super(String.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return decoder.readStr8(); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeStr8((String)value); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java new file mode 100644 index 0000000000..786f8d9957 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java @@ -0,0 +1,95 @@ +/* + * + * 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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +/** + * Layer supertype for all management "types". + * + * @author Andrea Gazzarini + */ +public abstract class Type +{ + /** Java representation of this type. */ + protected final Class javaType; + + /** + * Builds a new management type wiich wraps the given java type. + * + * @param javaType the java type. + */ + Type(Class javaType) + { + this.javaType = javaType; + } + + /** + * Returns the wrapped java type. + * + * @return the wrapped java type. + */ + public Class getJavaType () + { + return javaType; + } + + /** + * Each concrete subclass must define here how to decode incoming data according. + * + * @param decoder the decoder used to extract data. + * @return the "typed" value. + * + */ + public abstract Object decode(ManagementDecoder decoder); + + /** + * Returns a string representation of this type. + * + * @return a string representation of this type. + */ + @Override + public String toString () + { + return new StringBuilder(getClass().getName()) + .append(" (wraps ") + .append(javaType.getName()) + .append(')').toString(); + } + + /** + * Identity for types is based on wrapped java type identity. + */ + @Override + public boolean equals (Object obj) + { + return getClass() == obj.getClass(); + } + + @Override + public int hashCode () + { + return getClass().hashCode(); + } + + public abstract void encode (Object value, ManagementEncoder encoder); +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint16.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint16.java new file mode 100644 index 0000000000..31aeab954d --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint16.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class Uint16 extends Type +{ + public Uint16() + { + super(Integer.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return new Integer(decoder.readUint16()); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeUint16((Integer)value); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint32.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint32.java new file mode 100644 index 0000000000..deb9772953 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint32.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class Uint32 extends Type +{ + public Uint32() + { + super(Long.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return new Long(decoder.readUint32()); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeUint32((Integer)value); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint64.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint64.java new file mode 100644 index 0000000000..9d414cf225 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint64.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class Uint64 extends Type +{ + public Uint64() + { + super(Long.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return new Long(decoder.readUint64()); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeUint64((Integer)value); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint8.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint8.java new file mode 100644 index 0000000000..681537c48f --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uint8.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.domain.model.type; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class Uint8 extends Type +{ + public Uint8() + { + super(Short.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return new Short(decoder.readUint8()); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeUint8((Short)value); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uuid.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uuid.java new file mode 100644 index 0000000000..74e0337173 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Uuid.java @@ -0,0 +1,46 @@ +/* + * + * 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.domain.model.type; + +import java.util.UUID; + +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +public class Uuid extends Type +{ + public Uuid() + { + super(UUID.class); + } + + @Override + public Object decode (ManagementDecoder decoder) + { + return decoder.readUuid(); + } + + @Override + public void encode (Object value, ManagementEncoder encoder) + { + encoder.writeUuid((UUID)value); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/services/BrokerMessageListener.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/BrokerMessageListener.java new file mode 100644 index 0000000000..d5fdce09fc --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/BrokerMessageListener.java @@ -0,0 +1,181 @@ +/* + * + * 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.domain.services; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.qpid.api.Message; +import org.apache.qpid.management.Protocol; +import org.apache.qpid.management.domain.handler.base.IMessageHandler; +import org.apache.qpid.management.domain.model.DomainModel; +import org.apache.qpid.nclient.util.MessageListener; +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.util.Logger; + +/** + * Message listener used for processing incoming messages. + * So it is installed as a consumer on a specific channel and when a new message arrives: + * + * 1) Performs a sanity check on the message (magic number, sequence number) + * 2) Extracts the opcode and looks for one message handler associated with that opcode. + * 3) If a message handler is found the delegates the message processing; otherwise a log message is written to indicate + * that the message will be skipped. + * + * @author Andrea Gazzarini + */ +class BrokerMessageListener implements MessageListener +{ + private final static Logger LOGGER = Logger.get(BrokerMessageListener.class); + + private static class Log + { + // Debugs the content of the incoming message. + static void debugIncomingMessage(ByteBuffer message) + { + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug( + " : New incoming message has been received. Message content : %s", + Arrays.toString(message.array())); + } + } + + // Debugs all the configured handlers. + static void debugConfiguredHandlers (Map _handlers) + { + if (LOGGER.isDebugEnabled()) + { + for (Entry entry : _handlers.entrySet()) + { + LOGGER.debug(" : \"%s\" opcode is associated to handler %s",entry.getKey(),entry.getValue()); + } + } + } + } + + Map _handlers = new HashMap(); + private DomainModel _domainModel; + + /** + * Builds a new message listener with the given broker domain model. + * + * @param model the managed broker domain model. + */ + BrokerMessageListener(DomainModel model) + { + this._domainModel = model; + } + + /** + * When a new message arrives this method is called. + * 1) Performs a sanity check on the message (magic number, sequence number) + * 2) Extracts the opcode and looks for one message handler associated with that opcode. + * 3) If a message handler is found the delegates the message processing; otherwise a log message is written to indicate + * that the message will be skipped. + * + * @param message the incoming message. + */ + public void onMessage (Message message) + { + try + { + ByteBuffer buffer = message.readData(); + + // TODO : Should be better...! + String magicNumber = new String(new byte[] {buffer.get(),buffer.get(),buffer.get()}); + if (!Protocol.MAGIC_NUMBER.equals(magicNumber)) + { + LOGGER.error( + " : Message processing failure : incoming message contains a bad magic number (%s) " + + "and therefore will be discaded.", + magicNumber); + return; + } + + char opcode = (char)buffer.get(); + + IMessageHandler handler = _handlers.get(opcode); + if (handler != null) + { + ManagementDecoder decoder = new ManagementDecoder(); + decoder.init(buffer); + + LOGGER.debug( + " : Incoming message with \"%s\" as opcode will be forwarded to %s for processing.", + opcode, + handler); + + handler.process(decoder,decoder.readSequenceNo()); + } else + { + LOGGER.warn( + " : No handler has been configured for processing messages with \"%s\" as opcode. " + + "This message will be discarded.", + opcode); + + Log.debugConfiguredHandlers(_handlers); + } + } catch(IOException exception) + { + LOGGER.error( + exception, + " : Message I/O failure : unable to read byte message content and therefore it will be discarded."); + } catch(Exception exception) + { + LOGGER.error( + exception, + " : Message processing failure : unknown exception; see logs for more details."); + } + } + + /** + * Configures a new handler with this listener. + * After that, each time a message arrives with the specified opcode, this handler will be responsible for + * processing. + * Note that calling this method will switch this listener to a WORKING state. + * + * @param opcode the operation code. + * @param handler the message handler. + */ + void setHandlers(Map handlers) + { + for (Entry entry : handlers.entrySet()) + { + char opcode = entry.getKey(); + IMessageHandler handler = entry.getValue(); + try + { + handler.setDomainModel(_domainModel); + _handlers.put(opcode, handler); + } catch(Exception exception) { + LOGGER.error( + exception, + " : Message handler configured for opcode %s thrown an exception in initialization and therefore will be discarded.", + opcode); + } + } + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java new file mode 100644 index 0000000000..b2f1b19a6c --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java @@ -0,0 +1,256 @@ +/* + * + * 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.domain.services; + +import java.util.UUID; + +import org.apache.qpid.QpidException; +import org.apache.qpid.management.Names; +import org.apache.qpid.management.configuration.BrokerConnectionData; +import org.apache.qpid.management.configuration.Configuration; +import org.apache.qpid.management.domain.model.DomainModel; +import org.apache.qpid.transport.util.Logger; + +/** + * This is the Object representation of a management client. + * According to specification : "A software component that is separate from the messaging broker, connected to the + * management broker via an AMQP connection, which allows any software component to be managed remotely by QPID." + * + * @author Andrea Gazzarini + */ +final class ManagementClient +{ + private final static Logger LOGGER = Logger.get(ManagementClient.class); + + private final String _managementQueueName; + private final String _methodReplyQueueName; + + private DomainModel _domainModel; + private QpidService _service; + + /** + * Builds a new ManagementClient with the given identifier and connection data. + * + * @param brokerId the broker identifier. + * @param connectionData the broker connection data (host, port, etc...) + */ + ManagementClient(UUID brokerId,BrokerConnectionData connectionData) + { + _service = new QpidService(brokerId); + _domainModel = new DomainModel(brokerId); + _managementQueueName = Configuration.getInstance().getManagementQueueName(); + _methodReplyQueueName = Configuration.getInstance().getMethodReplyQueueName(); + } + + /** + * Establishing initial communication Between Client and Broker. + * According to specification : + * "Communication is established between the management client and management agent using normal AMQP procedures. + * The client creates a connection to the broker and then establishes a session with its corresponding channel. + * Two private queues are then declared. + * A management queue is declared and bound to the qpid.management exchange with "mgmt.#" as routing key; in that + * way all management-related messages sent to the exchange will be received by this client. + * When a client successfully binds to the qpid.management exchange, the management agent schedules a schema + * broadcast to be sent to the exchange. + * The agent will publish, via the exchange, a description of the schema for all manageable objects in its control. That + * schema is therefore received by this service and it will be part of service's domain model." + * + * @throws StartupFailureException when this management client cannot perform startup operations due to an error. + */ + void estabilishFirstConnectionWithBroker() throws StartupFailureException{ + try { + connectWithBroker(); + + createAndBindMethodReplyQueue(); + createAndBindManagementQueue(); + + registerConsumerOnManagementQueue(); + registerConsumerOnMethodReplyQueue(); + + synchronize(); + } catch(Exception exception) + { + try { + _service.close(); + } catch(Exception ignore) + { + } + throw new StartupFailureException(exception); + } + } + + /** + * Shutdown procedure for this management client. + */ + void shutdown () + { + LOGGER.info( + " : The shutdown sequence has been initiated for management client connected with broker %s", + _domainModel.getBrokerId()); + + removeMethodReplyConsumer(); + destroyAndUnbingMethodReplyQueue(); + + removeManagementConsumer(); + destroyAndUnbingManagementQueue(); + + _domainModel.releaseResources(); + + _service.close(); + + LOGGER.info( + " : Management client connected with broker %s shut down successfully.", + _domainModel.getBrokerId()); + } + + /** + * Registers a consumer (that is, a listener) on the method-reply queue. + */ + private void registerConsumerOnMethodReplyQueue () + { + BrokerMessageListener methodReplyChannelListener = new BrokerMessageListener(_domainModel); + methodReplyChannelListener.setHandlers(Configuration.getInstance().getMethodReplyQueueHandlers()); + _service.createSubscription(_methodReplyQueueName, _methodReplyQueueName, methodReplyChannelListener); + + LOGGER.info( + " : Method-reply queue consumer has been successfully installed and bound on broker %s.", + _domainModel.getBrokerId()); + } + + /** + * Registers a consumer (listener) on the management queue. + */ + private void registerConsumerOnManagementQueue () throws QpidException + { + BrokerMessageListener managementChannelListener = new BrokerMessageListener(_domainModel); + managementChannelListener.setHandlers(Configuration.getInstance().getManagementQueueHandlers()); + _service.createSubscription(_managementQueueName, _managementQueueName, managementChannelListener); + + LOGGER.info( + " : Management queue consumer has been successfully installed and bound on broker %s.", + _domainModel.getBrokerId()); + } + + /** + * Declares a management queue and bound it to the "qpid.management" exchange with "mgmt.#" as routing key; + */ + private void createAndBindManagementQueue () + { + _service.declareQueue(_managementQueueName); + _service.declareBinding( + _managementQueueName, + Names.MANAGEMENT_EXCHANGE, + Names.MANAGEMENT_ROUTING_KEY); + + LOGGER.info( + " : Management queue with name %s has been successfully declared and bound on broker %s.", + _managementQueueName, + _domainModel.getBrokerId()); + } + + /** + * Declares a private queue for receiving method replies (after method invocations). + * This queue is bound to the amq.direct exchange using a routing key equal to the name of the queue. + */ + private void createAndBindMethodReplyQueue () + { + _service.declareQueue(_methodReplyQueueName); + _service.declareBinding(_methodReplyQueueName, Names.AMQ_DIRECT_QUEUE, _methodReplyQueueName); + + LOGGER.info( + " : Method-reply queue with name %s has been successfully declared and bound on broker %s.", + _methodReplyQueueName, + _domainModel.getBrokerId()); + } + + /** + * Removes the method-reply queue consumer. + */ + private void removeMethodReplyConsumer() + { + _service.removeSubscription(_methodReplyQueueName); + + LOGGER.info( + " : Consumer %s has been removed from broker %s.", + _methodReplyQueueName, + _domainModel.getBrokerId()); + } + + /** + * Unbind the method reply queue and after that destroy it from remote broker. + */ + private void destroyAndUnbingMethodReplyQueue() + { + _service.declareUnbinding(_methodReplyQueueName, Names.AMQ_DIRECT_QUEUE, _methodReplyQueueName); + _service.deleteQueue(_methodReplyQueueName); + + LOGGER.info( + " : Queue %s has been removed from broker %s.", + _methodReplyQueueName, + _domainModel.getBrokerId()); + } + + /** + * Removes the management queue consumer. + */ + private void removeManagementConsumer() + { + _service.removeSubscription(_managementQueueName); + + LOGGER.info( + " : Consumer %s has been removed from broker %s.", + _managementQueueName, + _domainModel.getBrokerId()); + } + + /** + * Unbind the management queue and after that destroy it from remote broker. + */ + private void destroyAndUnbingManagementQueue() + { + _service.declareUnbinding(_managementQueueName, Names.MANAGEMENT_EXCHANGE, Names.MANAGEMENT_ROUTING_KEY); + _service.deleteQueue(_managementQueueName); + + LOGGER.info( + " : Queue %s has been removed from broker %s.", + _managementQueueName, + _domainModel.getBrokerId()); + } + + /** + * Connects this client with the broker. + * + * @throws QpidException when it's not possibile to connect with the broker. + */ + private void connectWithBroker() throws Exception + { + _service.connect(); + } + + /** + * All the Management client commands are asynchronous. + * Synchronous behavior is achieved through invoking the sync method. + */ + private void synchronize() + { + _service.sync(); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java new file mode 100644 index 0000000000..00dbec261d --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java @@ -0,0 +1,103 @@ +/* + * + * 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.domain.services; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.Map.Entry; + +import org.apache.qpid.management.configuration.BrokerConnectionData; +import org.apache.qpid.management.configuration.Configuration; +import org.apache.qpid.management.configuration.ConfigurationException; +import org.apache.qpid.management.configuration.Configurator; +import org.apache.qpid.transport.util.Logger; + +/** + * Main entry point for starting Q-Man application. + * + * @author Andrea Gazzarini + */ +public class QMan +{ + private final static Logger LOGGER = Logger.get(QMan.class); + private final static List managementClients = new ArrayList(); + + /** + * Main method used for starting Q-Man. + * + * @param args the command line arguments. + */ + public static void main (String[] args) throws IOException + { + // SHUTDOWN HOOK + Runtime.getRuntime().addShutdownHook(new Thread(){ + @Override + public void run () + { + LOGGER.info(" : Shutting down Q-Man..."); + for (ManagementClient client : managementClients) + { + client.shutdown(); + } + LOGGER.info(" : Q-Man shut down."); + } + }); + + LOGGER.info(" : Starting Q-Man..."); + LOGGER.info(" : Reading Q-Man configuration..."); + + Configurator configurator = new Configurator(); + try + { + configurator.configure(); + LOGGER.info(" : Creating management client(s)..."); + for (Entry entry : Configuration.getInstance().getConnectionInfos()) + { + UUID brokerId = entry.getKey(); + BrokerConnectionData data = entry.getValue(); + try + { + ManagementClient client = new ManagementClient(brokerId,data); + managementClients.add(client); + client.estabilishFirstConnectionWithBroker(); + + LOGGER.info(" : Management client for broker %s successfully connected.",brokerId); + } catch(StartupFailureException exception) { + LOGGER.error(exception, ": Cannot connect to broker %s on %s:%s",brokerId,data.getHost(),data.getPort()); + } + } + LOGGER.info(" : Q-Man open for e-business."); + + // TODO : console enhancement (i.e. : connect another broker) + System.out.println("Type \"q\" to quit."); + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + while ( !"q".equals(reader.readLine()) ){ + } + } catch(ConfigurationException exception) { + LOGGER.error(exception, " : Q-Man was unable to startup correctly : a configuration error occurred."); + System.exit(1); + } + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java new file mode 100644 index 0000000000..92689eba52 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QpidService.java @@ -0,0 +1,270 @@ +/* + * + * 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.domain.services; + +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.UUID; + +import org.apache.qpid.QpidException; +import org.apache.qpid.management.Constants; +import org.apache.qpid.management.Names; +import org.apache.qpid.management.configuration.Configuration; +import org.apache.qpid.management.configuration.QpidDatasource; +import org.apache.qpid.nclient.Connection; +import org.apache.qpid.nclient.Session; +import org.apache.qpid.nclient.util.MessageListener; +import org.apache.qpid.nclient.util.MessagePartListenerAdapter; +import org.apache.qpid.transport.MessageAcceptMode; +import org.apache.qpid.transport.MessageAcquireMode; +import org.apache.qpid.transport.MessageCreditUnit; +import org.apache.qpid.transport.Option; +import org.apache.qpid.transport.util.Logger; + +/** + * Qpid Broker facade. + * + * @author Andrea Gazzarini + */ +public class QpidService +{ + private final static Logger LOGGER = Logger.get(QpidService.class); + + // Inner static class used for logging and avoid conditional logic (isDebugEnabled()) duplication. + private static class Log + { + /** + * Logs the content f the message. + * This will be written on log only if DEBUG level is enabled. + * + * @param messageContent the raw content of the message. + */ + static void logMessageContent(byte [] messageContent) + { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + " : Message has been sent to management exchange. Message content : %s", + Arrays.toString(messageContent)); + } + } + + /** + * Logs the content f the message. + * This will be written on log only if DEBUG level is enabled. + * + * @param messageContent the raw content of the message. + */ + static void logMessageContent(ByteBuffer messageContent) + { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + " : Message has been sent to management exchange."); + } + } + } + + private UUID _brokerId; + private Connection _connection; + private Session _session; + + /** + * Builds a new service with the given connection data. + * + * @param connectionData the connection data of the broker. + */ + public QpidService(UUID brokerId) + { + this._brokerId = brokerId; + } + + /** + * Estabilishes a connection with the broker. + * + * @throws QpidException in case of connection failure. + */ + public void connect() throws Exception + { + _connection = QpidDatasource.getInstance().getConnection(_brokerId); + _session = _connection.createSession(Constants.NO_EXPIRATION); + } + + /** + * All the previously entered outstanding commands are asynchronous. + * Synchronous behavior is achieved through invoking this method. + */ + public void sync() + { + _session.sync(); + } + + /** + * Closes communication with broker. + */ + public void close() + { + try + { + _session.close(); + _session = null; + } catch (Exception e) + { + } + try + { + _connection.close(); + _connection = null; + } catch (Exception e) + { + } + } + + /** + * Associate a message listener with a destination therefore creating a new subscription. + * + * @param queueName The name of the queue that the subscriber is receiving messages from. + * @param destinationName the name of the destination, or delivery tag, for the subscriber. + * @param listener the listener for this destination. + * + * @see Session#messageSubscribe(String, String, short, short, org.apache.qpid.nclient.MessagePartListener, java.util.Map, org.apache.qpid.transport.Option...) + */ + public void createSubscription(String queueName, String destinationName,MessageListener listener) + { + _session.messageSubscribe( + queueName, + destinationName, + Session.TRANSFER_CONFIRM_MODE_NOT_REQUIRED, + Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE, + new MessagePartListenerAdapter(listener), null); + + _session.messageFlow(destinationName, MessageCreditUnit.BYTE, Session.MESSAGE_FLOW_MAX_BYTES); + _session.messageFlow(destinationName, MessageCreditUnit.MESSAGE, Integer.MAX_VALUE); + + LOGGER.debug( + " : New subscription between queue %s and destination %s has been declared.", + queueName, + destinationName); + } + + /** + * Removes a previously declared consumer from the broker. + * + * @param destinationName the name of the destination, or delivery tag, for the subscriber. + * @see Session#messageCancel(String, Option...) + */ + public void removeSubscription(String destinationName) + { + _session.messageCancel(destinationName); + LOGGER.debug( + " : Subscription named %s has been removed from remote broker.", + destinationName); + } + + /** + * Declares a queue on the broker with the given name. + * + * @param queueName the name of the declared queue. + * @see Session#queueDeclare(String, String, java.util.Map, Option...) + */ + public void declareQueue(String queueName) + { + _session.queueDeclare(queueName, null, null); + LOGGER.debug(" : New queue with name %s has been declared.",queueName); + } + + /** + * Removes the queue with the given name from the broker. + * + * @param queueName the name of the queue. + * @see Session#queueDelete(String, Option...) + */ + public void deleteQueue(String queueName) + { + _session.queueDelete(queueName); + LOGGER.debug(" : Queue with name %s has been removed.",queueName); + } + + /** + * Binds (on the broker) a queue with an exchange. + * + * @param queueName the name of the queue to bind. + * @param exchangeName the exchange name. + * @param routingKey the routing key used for the binding. + * @see Session#exchangeBind(String, String, String, java.util.Map, Option...) + */ + public void declareBinding(String queueName, String exchangeName, String routingKey) + { + _session.exchangeBind(queueName, exchangeName, routingKey, null); + LOGGER.debug( + " : New binding with %s as routing key has been declared between queue %s and exchange %s.", + routingKey,queueName, + exchangeName); + } + + /** + * Removes a previously declare binding between an exchange and a queue. + * + * @param queueName the name of the queue. + * @param exchangeName the name of the exchange. + * @param routingKey the routing key used for binding. + */ + public void declareUnbinding(String queueName, String exchangeName, String routingKey) + { + _session.exchangeUnbind(queueName, exchangeName, routingKey); + LOGGER.debug( + " : Binding with %s as routing key has been removed between queue %s and exchange %s.", + routingKey,queueName, + exchangeName); + } + + /** + * Sends a command message with the given data on the management queue. + * + * @param messageData the command message content. + */ + public void sendCommandMessage(byte [] messageData) + { + _session.messageTransfer( + Names.MANAGEMENT_EXCHANGE, + MessageAcceptMode.EXPLICIT, + MessageAcquireMode.PRE_ACQUIRED, + Configuration.getInstance().getCommandMessageHeader(), + messageData); + + Log.logMessageContent (messageData); + } + + /** + * Sends a command message with the given data on the management queue. + * + * @param messageData the command message content. + */ + public void sendCommandMessage(ByteBuffer messageData) + { + _session.messageTransfer( + Names.MANAGEMENT_EXCHANGE, + MessageAcceptMode.EXPLICIT, + MessageAcquireMode.PRE_ACQUIRED, + Configuration.getInstance().getCommandMessageHeader(), + messageData); + + Log.logMessageContent (messageData); + } +} \ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/services/StartupFailureException.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/StartupFailureException.java new file mode 100644 index 0000000000..9da8832624 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/StartupFailureException.java @@ -0,0 +1,42 @@ +/* + * + * 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.domain.services; + +/** + * Thrown in case of service startup failure. + * For example the configuration file couldn't be read because is not well-formed. + * + * @author Andrea Gazzarini. + */ +public class StartupFailureException extends Exception +{ + private static final long serialVersionUID = -4102037574602857703L; + + /** + * Builds a new StartupFailureException with the given exception. + * + * @param exception the exception cause. + */ + public StartupFailureException(Exception exception) + { + super(exception); + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/TestConstants.java b/java/management/client/src/test/java/org/apache/qpid/management/TestConstants.java new file mode 100644 index 0000000000..1ed938d9fd --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/TestConstants.java @@ -0,0 +1,48 @@ +/* + * + * 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; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.qpid.management.domain.model.DomainModel; +import org.apache.qpid.management.domain.model.type.Binary; + +public interface TestConstants +{ + String QPID_PACKAGE_NAME = "qpid"; + String EXCHANGE_CLASS_NAME = "exchange"; + Binary HASH = new Binary(new byte []{1,2,3,4,5,6,7,8,9}); + int VALID_CODE = 1; + + + UUID BROKER_ID = UUID.randomUUID(); + Binary OBJECT_ID = new Binary(new byte []{1,2,3,2,1,1,2,3}); + + DomainModel DOMAIN_MODEL = new DomainModel(BROKER_ID); + + List> EMPTY_PROPERTIES_SCHEMA = new LinkedList>(); + List> EMPTY_STATISTICS_SCHEMA = new LinkedList>(); + List> EMPTY_METHODS_SCHEMA = new LinkedList>(); + List> EMPTY_EVENTS_SCHEMA = new LinkedList>(); +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java b/java/management/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java new file mode 100644 index 0000000000..4c53c3d428 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java @@ -0,0 +1,107 @@ +/* + * + * 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.TestConstants; +import org.apache.qpid.management.domain.model.AccessMode; + +import junit.framework.TestCase; + +/** + * Test case for AccessMode mapping. + * + * @author Andrea Gazzarini + */ +public class AccessModeMappingTest extends TestCase +{ + private AccessModeMapping _mapping; + + /** + * Set up fixture for this test case. + */ + @Override + protected void setUp () throws Exception + { + _mapping = new AccessModeMapping(); + } + + /** + * Tests the execution of the setCode method when a valid code is given. + * + *
precondition : given code is a valid number. + *
postcondition : no exception is thrown and the mapping contained the requested code. + */ + public void testSetCodeOK() + { + _mapping.setCode(String.valueOf(TestConstants.VALID_CODE)); + assertEquals(TestConstants.VALID_CODE,_mapping.getCode()); + } + + /** + * Tests the execution of the setCode method when an invalid code is given. + * + *
precondition : given code is an invalid number. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testSetCodeKO_withInvalidNumber () + { + try { + _mapping.setCode(String.valueOf(TestConstants.VALID_CODE)+"a"); + fail("The given string is not a number and therefore an exception must be thrown."); + } catch(NumberFormatException expected) { + + } + } + + /** + * Tests the execution of the setAccessMode method when a valid access code is given. + * + *
precondition : given code is valid (i.e. RW, RC or RO). + *
postcondition : no exception is thrown and the mapping contained the requested access mode. + */ + public void testSetAccessModeOK() + { + _mapping.setAccessMode("RW"); + assertEquals(AccessMode.RW,_mapping.getAccessMode()); + + _mapping.setAccessMode("RC"); + assertEquals(AccessMode.RC,_mapping.getAccessMode()); + + _mapping.setAccessMode("RO"); + assertEquals(AccessMode.RO,_mapping.getAccessMode()); + } + + /** + * Tests the execution of the setAccessMode method when an unknown code is given. + * + *
precondition : given code is an unknown code. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testSetAccessModeKO () + { + try { + _mapping.setAccessMode(AccessMode.RW.toString()+"X"); + fail("The given string is not a string representation of a valid access mode."); + } catch(IllegalArgumentException expected) { + + } + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java b/java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java new file mode 100644 index 0000000000..c948db59bf --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java @@ -0,0 +1,237 @@ +/* + * + * 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 java.util.Map; +import java.util.UUID; + +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. + * + * @author Andrea Gazzarini + */ +public class ConfigurationTest extends TestCase +{ + /** + * Tests the singleton behaviour of the configuration object. + */ + public void testSingleton() + { + 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(); + mapping.setCode(String.valueOf(TestConstants.VALID_CODE)); + mapping.setType(Uint8.class.getName()); + 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. + * + *
precondition : the requested type doesn't exist on the configuration. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testGetTypeKO() + { + try + { + Configuration.getInstance().getType(TestConstants.VALID_CODE+1); + fail("If an unknwon code is supplied an exception must be thrown."); + } catch (UnknownTypeCodeException expected) + { + assertEquals(TestConstants.VALID_CODE+1,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 + { + String accessModeAsString = "RW"; + + AccessModeMapping mapping = new AccessModeMapping(); + mapping.setCode(String.valueOf(TestConstants.VALID_CODE)); + mapping.setAccessMode(accessModeAsString); + 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. + * + *
precondition : the requested access mode doesn't exist on the configuration. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testGetAccessModeKO() + { + try + { + Configuration.getInstance().getAccessMode(TestConstants.VALID_CODE+1); + fail("If an unknwon code is supplied an exception must be thrown."); + } catch (UnknownAccessCodeException expected) + { + assertEquals(TestConstants.VALID_CODE+1,expected.getCode()); + } + } + + /** + * Tests the execution of the getBrokerConnectionData when a valid broker id is supplied. + * + *
precondition : on configuration a connection data is stored and associated with the supplied id. + *
postcondition : the requested connection data is returned and no exception is thrown. + */ + public void testGetBrokerConnectionDataOK() throws Exception + { + BrokerConnectionData connectionData = new BrokerConnectionData(); + connectionData.setHost("host"); + connectionData.setPort("7001"); + connectionData.setInitialPoolCapacity("0"); + connectionData.setMaxPoolCapacity("10"); + connectionData.setMaxWaitTimeout("1"); + Configuration.getInstance().addBrokerConnectionData(TestConstants.BROKER_ID, connectionData); + + BrokerConnectionData result = Configuration.getInstance().getBrokerConnectionData(TestConstants.BROKER_ID); + assertSame(connectionData, result); + } + + /** + * Tests the execution of the getBrokerConnectionData when a unknown broker id is supplied. + * + *
precondition : on configuration there's no connection data associated with the supplied id. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testGetBrokerConnectionDataKO_withUnknownBrokerId() + { + UUID brokerId = UUID.randomUUID(); + try + { + Configuration.getInstance().getBrokerConnectionData(brokerId); + fail("If an unknown broker id is supplied then an exception must be thrown."); + } catch(UnknownBrokerException expected) + { + assertEquals(brokerId.toString(),expected.getMessage()); + } + } + + /** + * Tests the execution of the getBrokerConnectionData when a null id is supplied. + * + *
precondition : a null broker is given. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testGetBrokerConnectionDataKO_withNullBrokerId() + { + try + { + Configuration.getInstance().getBrokerConnectionData(null); + fail("If a null broker id is supplied then an exception must be thrown."); + } catch(UnknownBrokerException expected) + { + } + } + + /** + * Tests the behaviour of the getManagementQueueHandlers() method. + * + *
precondition: 2 management handlers are in stored configuration + *
postcondition : 2 management handlers are returned. + */ + public void testGetManagementQueueHandlersOk() + { + String i = "i"; + String c = "c"; + + String instrMessageHandlerClassName = InstrumentationMessageHandler.class.getName(); + String configMessageHandlerClassName = ConfigurationMessageHandler.class.getName(); + + MessageHandlerMapping instrMapping = new MessageHandlerMapping(); + MessageHandlerMapping configMapping = new MessageHandlerMapping(); + + instrMapping.setOpcode(i); + instrMapping.setMessageHandlerClass(instrMessageHandlerClassName); + + configMapping.setOpcode(c); + configMapping.setMessageHandlerClass(configMessageHandlerClassName); + + Configuration.getInstance().addManagementMessageHandlerMapping(instrMapping); + Configuration.getInstance().addManagementMessageHandlerMapping(configMapping); + + Map handlerMappings = Configuration.getInstance().getManagementQueueHandlers(); + + assertEquals(2,handlerMappings.size()); + assertEquals(instrMessageHandlerClassName,handlerMappings.get(instrMapping.getOpcode()).getClass().getName()); + assertEquals(configMessageHandlerClassName,handlerMappings.get(configMapping.getOpcode()).getClass().getName()); + } + + /** + * Tests the behaviour of the getManagementQueueHandlers() method. + * + *
precondition: 2 management handlers are in stored configuration + *
postcondition : 2 management handlers are returned. + */ + public void testGetMethodReplyQueueHandlersOk() + { + String s = "s"; + + String schemaMessageHandlerClassName = SchemaResponseMessageHandler.class.getName(); + + MessageHandlerMapping schemaMapping = new MessageHandlerMapping(); + + schemaMapping.setOpcode(s); + schemaMapping.setMessageHandlerClass(schemaMessageHandlerClassName); + + Configuration.getInstance().addMethodReplyMessageHandlerMapping(schemaMapping); + + Map handlerMappings = Configuration.getInstance().getMethodReplyQueueHandlers(); + + assertEquals(schemaMessageHandlerClassName,handlerMappings.get(schemaMapping.getOpcode()).getClass().getName()); + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java b/java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java new file mode 100644 index 0000000000..c3fa0c13f3 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java @@ -0,0 +1,112 @@ +/* + * + * 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.xml.sax.SAXException; + +import junit.framework.TestCase; + +/** + * Test case for configurator. + * + * @author Andrea Gazzarini + * + */ +public class ConfiguratorTest extends TestCase +{ + + /** + * Tests the execution of the configure() method when a inexistent configuration file is used. + * + *
precondition : the configuration file doesn't exist. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testConfigureKO_WithConfigFileNotFound() + { + Configurator configurator = getConfiguratorWithDatafileInjected("pippo/pluto/paperino.xml"); + try { + configurator.configure(); + fail("If there's no configuration file the configuration cannot be built."); + } catch(ConfigurationException expected) { + + } + } + + /** + * Tests the execution of the configure() method when configuration file is null. + * + *
precondition : the configuration file is null. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testConfigureKO_WithNullConfig() + { + Configurator configurator = getConfiguratorWithDatafileInjected(null); + try { + configurator.configure(); + fail("If there's no configuration file the configuration cannot be built."); + } catch(ConfigurationException expected) { + + } + } + + /** + * Tests the changes of the configurator internal state while configuration file is parsed. + * + *
precondition: N.A. + *
postcondition: N.A. + */ + public void testDirectorParsing() throws SAXException{ + Configurator configurator = new Configurator(); + + assertSame(Configurator.DEFAULT_PARSER,configurator._currentParser); + + configurator.startElement(null, null, Tag.TYPE_MAPPINGS.toString(), null); + assertSame(configurator._typeMappingParser,configurator._currentParser); + + configurator.startElement(null, null, Tag.ACCESS_MODE_MAPPINGS.toString(), null); + assertSame(configurator._accessModeMappingParser,configurator._currentParser); + + configurator.startElement(null, null, Tag.BROKERS.toString(), null); + assertSame(configurator._brokerConfigurationParser,configurator._currentParser); + + configurator.startElement(null, null, Tag.MANAGEMENT_QUEUE.toString(), null); + assertSame(configurator._managementQueueHandlerParser,configurator._currentParser); + + configurator.startElement(null, null, Tag.METHOD_REPLY_QUEUE.toString(), null); + assertSame(configurator._methodReplyQueueHandlerParser,configurator._currentParser); + } + /** + * Create a stub configurator which returns the given datafile path. + * + * @param filename the configuration file to be injected. + * @return a configurator which returns the given datafile path. + */ + private Configurator getConfiguratorWithDatafileInjected(final String filename) { + return new Configurator() + { + @Override + String getConfigurationFileName () + { + return filename; + } + }; + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java b/java/management/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java new file mode 100644 index 0000000000..9755c62991 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java @@ -0,0 +1,201 @@ +/* + * + * 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 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; + +/** + * Test case for mapping parsers. + * + * @author Andrea Gazzarini. + */ +public class MappingParsersTest extends TestCase +{ + /** + * Tests the execution of the access mode mapping parser. + * + *
precondition: An access mode mapping is built by the parser; + *
postcondition: the corresponding access mode is available on the configuration. + */ + public void testAccessModeMappingParser() throws UnknownAccessCodeException + { + AccessModeMappingParser parser = new AccessModeMappingParser(); + parser.setCurrrentAttributeValue(String.valueOf(TestConstants.VALID_CODE)); + parser.setCurrentAttributeName(Tag.CODE.toString()); + parser.setCurrrentAttributeValue("RW"); + parser.setCurrentAttributeName(Tag.VALUE.toString()); + parser.setCurrentAttributeName(Tag.MAPPING.toString()); + + AccessMode result = Configuration.getInstance().getAccessMode(TestConstants.VALID_CODE); + assertEquals(AccessMode.RW,result); + } + + /** + * Tests the execution of the broker connection data mapping parser. + * + *
precondition: A broker connection datamapping is built by the parser; + *
postcondition: the corresponding connection data is available on the configuration. + */ + public void testBrokerConnectionDataParser() throws UnknownBrokerException + { + String host = "127.0.0.1"; + String port = "7001"; + String virtualHost = "test"; + String username = "username_guest"; + String password ="password_guest"; + + BrokerConnectionDataParser parser = new BrokerConnectionDataParser() + { + @Override + UUID getUUId () + { + return TestConstants.BROKER_ID; + } + }; + + parser.setCurrrentAttributeValue(host); + parser.setCurrentAttributeName(Tag.HOST.toString()); + parser.setCurrrentAttributeValue(port); + parser.setCurrentAttributeName(Tag.PORT.toString()); + parser.setCurrrentAttributeValue(virtualHost); + parser.setCurrentAttributeName(Tag.VIRTUAL_HOST.toString()); + parser.setCurrrentAttributeValue(username); + parser.setCurrentAttributeName(Tag.USER.toString()); + parser.setCurrrentAttributeValue(password); + parser.setCurrentAttributeName(Tag.PASSWORD.toString()); + parser.setCurrentAttributeName(Tag.BROKER.toString()); + + BrokerConnectionData result = Configuration.getInstance().getBrokerConnectionData(TestConstants.BROKER_ID); + + assertEquals(host,result.getHost()); + assertEquals(Integer.parseInt(port),result.getPort()); + assertEquals(virtualHost,result.getVirtualHost()); + assertEquals(username,result.getUsername()); + assertEquals(password,result.getPassword()); + } + + /** + * Tests the execution of the management queue handler mapping parser. + * + *
precondition: Two managenent queue handlers mapping are built by the parser; + *
postcondition: the corresponding management handlers are available on the configuration. + */ + public void testManagementQueueMessageListenerParser() + { + String instrOpcode = "i"; + String configOpCode = "c"; + + ManagementQueueMessageListenerParser parser = new ManagementQueueMessageListenerParser(); + + parser.setCurrrentAttributeValue(instrOpcode); + parser.setCurrentAttributeName(Tag.OPCODE.toString()); + parser.setCurrrentAttributeValue(InstrumentationMessageHandler.class.getName()); + parser.setCurrentAttributeName(Tag.CLASS_NAME.toString()); + parser.setCurrentAttributeName(Tag.HANDLER.toString()); + + parser.setCurrrentAttributeValue(configOpCode); + parser.setCurrentAttributeName(Tag.OPCODE.toString()); + parser.setCurrrentAttributeValue(ConfigurationMessageHandler.class.getName()); + parser.setCurrentAttributeName(Tag.CLASS_NAME.toString()); + parser.setCurrentAttributeName(Tag.HANDLER.toString()); + + + Map result = Configuration.getInstance().getManagementQueueHandlers(); + + assertEquals(2,result.size()); + + assertEquals(InstrumentationMessageHandler.class,result.get(instrOpcode.charAt(0)).getClass()); + assertEquals(ConfigurationMessageHandler.class,result.get(configOpCode.charAt(0)).getClass()); + } + + /** + * Tests the execution of the method-reply queue handler mapping parser. + * + *
precondition: two method-reply queue handler mappings are built by the parser; + *
postcondition: the corresponding method-reply handlers are available on the configuration. + */ + public void testMethodReplyQueueMessageListenerParser() + { + String schemaOpcode = "s"; + String configOpCode = "c"; + + MethodReplyQueueMessageListenerParser parser = new MethodReplyQueueMessageListenerParser(); + + parser.setCurrrentAttributeValue(schemaOpcode); + parser.setCurrentAttributeName(Tag.OPCODE.toString()); + parser.setCurrrentAttributeValue(SchemaResponseMessageHandler.class.getName()); + parser.setCurrentAttributeName(Tag.CLASS_NAME.toString()); + parser.setCurrentAttributeName(Tag.HANDLER.toString()); + + parser.setCurrrentAttributeValue(configOpCode); + parser.setCurrentAttributeName(Tag.OPCODE.toString()); + parser.setCurrrentAttributeValue(ConfigurationMessageHandler.class.getName()); + parser.setCurrentAttributeName(Tag.CLASS_NAME.toString()); + parser.setCurrentAttributeName(Tag.HANDLER.toString()); + + Map result = Configuration.getInstance().getMethodReplyQueueHandlers(); + + assertEquals(2,result.size()); + + assertEquals(SchemaResponseMessageHandler.class,result.get(schemaOpcode.charAt(0)).getClass()); + assertEquals(ConfigurationMessageHandler.class,result.get(configOpCode.charAt(0)).getClass()); + } + + /** + * Tests the execution of the type mapping parser. + * + *
precondition: two type mappings are built by the parser; + *
postcondition: the corresponding types are available on the configuration. + */ + public void testMappingParser() throws NumberFormatException, UnknownTypeCodeException + { + TypeMappingParser parser = new TypeMappingParser(); + + String className = Uint8.class.getName(); + String validatorClassName = "a.b.c.Validator"; + + parser.setCurrrentAttributeValue(String.valueOf(TestConstants.VALID_CODE)); + parser.setCurrentAttributeName(Tag.CODE.toString()); + parser.setCurrrentAttributeValue(className); + parser.setCurrentAttributeName(Tag.CLASS_NAME.toString()); + parser.setCurrrentAttributeValue(validatorClassName); + parser.setCurrentAttributeName(Tag.VALIDATOR_CLASS_NAME.toString()); + parser.setCurrentAttributeName(Tag.MAPPING.toString()); + + Type type =Configuration.getInstance().getType(TestConstants.VALID_CODE); + String vClassName = Configuration.getInstance().getValidatorClassName(type); + + assertEquals(Uint8.class, type.getClass()); + assertEquals(validatorClassName,vClassName); + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java b/java/management/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java new file mode 100644 index 0000000000..6d92e3b6f8 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java @@ -0,0 +1,56 @@ +/* + * + * 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.Str8; + +public class StubConfigurator extends Configurator +{ + /** + * Builds whole configuration. + * + * @throws ConfigurationException when the build fails. + */ + public void configure() throws ConfigurationException + { + addAccessModeMapping("1", "RW"); + addAccessModeMapping("2", "RO"); + addAccessModeMapping("3", "RC"); + + addTypeMapping("1", Str8.class.getName()); + } + + public void addTypeMapping(String code,String clazzName) + { + TypeMapping mapping = new TypeMapping(); + mapping.setCode(code); + mapping.setType(clazzName); + Configuration.getInstance().addTypeMapping(mapping); + } + + public void addAccessModeMapping(String code, String value) + { + AccessModeMapping mapping = new AccessModeMapping(); + mapping.setCode(code);; + mapping.setAccessMode(value); + Configuration.getInstance().addAccessModeMapping(mapping); + } +} diff --git a/java/management/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java b/java/management/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java new file mode 100644 index 0000000000..bf44608c0e --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java @@ -0,0 +1,117 @@ +/* + * + * 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.TestConstants; +import org.apache.qpid.management.domain.model.type.Uint8; + +import junit.framework.TestCase; + +/** + * Test case for type mapping. + * + * @author Andrea Gazzarini + */ +public class TypeMappingTest extends TestCase +{ + private TypeMapping _mapping; + + @Override + protected void setUp () throws Exception + { + _mapping = new TypeMapping(); + } + + /** + * Tests the execution of the setCode method when a valid code is given. + * + *
precondition : given code is a valid number. + *
postcondition : no exception is thrown and the mapping contained the requested code. + */ + public void testSetCodeOK() + { + _mapping.setCode(String.valueOf(TestConstants.VALID_CODE)); + assertEquals(TestConstants.VALID_CODE,_mapping.getCode()); + } + + /** + * Tests the execution of the setCode method when an invalid code is given. + * + *
precondition : given code is an invalid number. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testSetCodeKO_withInvalidNumber () + { + try { + _mapping.setCode(String.valueOf(TestConstants.VALID_CODE)+"a"); + fail("The given string is not a number and therefore an exception must be thrown."); + } catch(NumberFormatException expected) + { + + } + } + + /** + * Tests the execution of the setType() method when a valid type class is given. + * + *
precondition : a valid class type is supplied. + *
postcondition : no exception is thrown and the mapping contains the previously associated type. + */ + public void testSetTypeOK() + { + _mapping.setType(Uint8.class.getName()); + assertTrue(_mapping.getType() instanceof Uint8); + } + + /** + * Tests the execution of the setType() method when a invalid type class is given. + * + *
precondition : an invalid class type is supplied. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testSetTypeKO_withTypeClassNotFound() + { + try + { + _mapping.setType(Uint8.class.getName()+"a"); + fail("If the supplied class doesn't exist an exception must be thrown."); + } catch(IllegalArgumentException expected) { + assertTrue(expected.getCause() instanceof ClassNotFoundException); + } + } + + /** + * Tests the execution of the setType() method when a invalid type class is given. + * + *
precondition : an invalid class type is supplied (is not a Type). + *
postcondition : an exception is thrown indicating the failure. + */ + public void testSetTypeKO_withInvalidType() + { + try + { + _mapping.setType(String.class.getName()); + fail("If the supplied class is not a Type an exception must be thrown."); + } catch(IllegalArgumentException expected) { + assertTrue(expected.getCause() instanceof ClassCastException); + } + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java new file mode 100644 index 0000000000..6be4484f5c --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java @@ -0,0 +1,120 @@ +/* + * + * 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.domain.handler.base; + +import java.nio.ByteBuffer; + +import org.apache.qpid.management.TestConstants; +import org.apache.qpid.management.domain.model.type.Binary; +import org.apache.qpid.transport.codec.ManagementDecoder; +import org.apache.qpid.transport.codec.ManagementEncoder; + +import junit.framework.TestCase; + +/** + * Test case for Content indication message handler (base class). + * + * @author Andrea Gazzarini + */ +public class ContentIndicationMessageHandlerTest extends TestCase +{ + /** + * Tests the execution of the process method when the message is processed correctly. + */ + public void testProcessOk() { + final String expectedPackageName = "org.apache.qpid.broker"; + final String expectedClassName ="connection"; + final long expectedMessageTimestamp = System.currentTimeMillis(); + final long expectedCreationTime = expectedMessageTimestamp - 1000; + final long expectedDeletionTime = 0; + final Binary expectedClassHash = new Binary(new byte[]{9,9,9,9,8,8,8,8,7,7,7,7,6,6,6,6}); + final Binary expectedObjectId = new Binary(new byte[]{1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16}); + final Binary expectedBody = new Binary(new byte[]{1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4}); + + ContentIndicationMessageHandler mockHandler = new ContentIndicationMessageHandler() + { + @Override + protected void updateDomainModel (String packageName, String className, Binary classHash, Binary objectId, + long timeStampOfCurrentSample, long timeObjectWasCreated, long timeObjectWasDeleted, byte[] contentData) + { + assertEquals(expectedPackageName,packageName); + assertEquals(expectedClassName,className); + assertEquals(expectedClassHash,classHash); + assertEquals(expectedMessageTimestamp,timeStampOfCurrentSample); + assertEquals(expectedCreationTime,timeObjectWasCreated); + assertEquals(expectedDeletionTime,timeObjectWasDeleted); + assertEquals(expectedObjectId,objectId); + assertEquals(expectedBody,new Binary(contentData)); + } + + @Override + void removeObjectInstance (String packageName, String className, Binary classHash, Binary objectId) + { + fail("The object shouldn't be deleted because deletion time was set to 0!"); + } + }; + mockHandler.setDomainModel(TestConstants.DOMAIN_MODEL); + + ByteBuffer buffer = ByteBuffer.allocate(1000); + ManagementEncoder encoder = new ManagementEncoder(buffer); + + encoder.writeStr8(expectedPackageName); + encoder.writeStr8(expectedClassName); + expectedClassHash.encode(encoder); + encoder.writeDatetime(expectedMessageTimestamp); + encoder.writeDatetime(expectedCreationTime); + encoder.writeDatetime(expectedDeletionTime); + expectedObjectId.encode(encoder); + expectedBody.encode(encoder); + + buffer.flip(); + ManagementDecoder decoder = new ManagementDecoder(); + decoder.init(buffer); + + mockHandler.process(decoder, 1); + } + + /** + * Tests the behaviour of the objectHasBeenRemoved method(). + */ + public void testObjectHasBeenRemoved() + { + ContentIndicationMessageHandler mockHandler = new ContentIndicationMessageHandler() + { + @Override + protected void updateDomainModel (String packageName, String className, Binary classHash, Binary objectId, + long timeStampOfCurrentSample, long timeObjectWasCreated, long timeObjectWasDeleted, byte[] contentData) + { + } + }; + + long deletionTimestamp = 0; + long now = System.currentTimeMillis(); + + assertFalse(mockHandler.objectHasBeenRemoved(deletionTimestamp, now)); + + deletionTimestamp = now + 1000; + assertFalse(mockHandler.objectHasBeenRemoved(deletionTimestamp, now)); + + deletionTimestamp = now - 1000; + assertTrue(mockHandler.objectHasBeenRemoved(deletionTimestamp, now)); + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java new file mode 100644 index 0000000000..0c67811621 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.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.domain.model; + +import org.apache.qpid.management.configuration.Configurator; + +import junit.framework.TestCase;; + +/** + * Layer supertype for all domain model related test cases. + * + * @author Andrea Gazzarini + */ +public class BaseDomainModelTestCase extends TestCase +{ + /** + * Set up fixture for this test case. + * In order to execute tests on domain model we need to build the configuration. + */ + @Override + protected void setUp () throws Exception + { + Configurator configurator = new Configurator(); + configurator.configure(); + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java new file mode 100644 index 0000000000..43793e588a --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java @@ -0,0 +1,102 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.management.domain.model; + +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.desc; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.name; + +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.qpid.management.configuration.StubConfigurator; +import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute; +import org.apache.qpid.management.domain.model.type.Uint16; + +/** + * Layer supertype for feature builder test cases. + * + * @author Andrea Gazzarini + */ +public abstract class BaseQpidFeatureBuilderTestCase extends TestCase +{ + protected final static String NAME = "aName"; + + protected final static String DESCRIPTION = "A description."; + protected Integer _type; + + protected Map _featureDefinition; + protected QpidFeatureBuilder _builder; + + protected StubConfigurator configurator; + + /** + * Set up fixture for all concrete builder test cases. + */ + @Override + protected void setUp () throws Exception + { + _type = 1; + configurator = new StubConfigurator(); + configurator.addTypeMapping(_type.toString(),Uint16.class.getName()); + + _featureDefinition = new HashMap(); + _featureDefinition.put(name.name(),NAME); + _featureDefinition.put(desc.name(), DESCRIPTION); + } + + // Internal test used to avoid code duplication. + protected void internalTestForMissingMandatoryAttribute(Attribute ...toBeRemoved) + { + try + { + for (Attribute attribute : toBeRemoved) + { + _featureDefinition.remove(attribute.name()); + } + _builder.build(); + fail("If a mandatory attribute is missing an exception must be thrown!"); + } catch (UnableToBuildFeatureException expected) + { + assertTrue(expected instanceof MissingFeatureAttributesException); + for (Attribute attribute : toBeRemoved) + { + assertTrue(expected.getMessage().contains(attribute.name())); + } + } + } + + // Internal test used to avoid code duplication. + protected void internalTestForMissingOptionalAttribute(Attribute ...toBeRemoved) throws UnableToBuildFeatureException + { + for (Attribute attribute : toBeRemoved) + { + _featureDefinition.remove(attribute.name()); + } + _builder.build(); + + assertNotNull(_builder.getQpidFeature()); + assertNotNull(_builder.getManagementFeature()); + } + + +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java new file mode 100644 index 0000000000..185302c182 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java @@ -0,0 +1,56 @@ +/* + * + * 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.domain.model; + +import java.util.UUID; + +import org.apache.qpid.management.TestConstants; + +/** + * Test case for domain model entity. + * + * @author Andrea Gazzarini + */ +public class DomainModelTest extends BaseDomainModelTestCase +{ + private DomainModel _model; + + @Override + protected void setUp () throws Exception + { + super.setUp(); + _model = new DomainModel(UUID.randomUUID()); + } + + /** + * Tests the execution of the getPackage() method. + */ + public void testGetPackage() + { + assertFalse(_model.containsPackage(TestConstants.QPID_PACKAGE_NAME)); + + QpidPackage qpidPackage = _model.getPackageByName(TestConstants.QPID_PACKAGE_NAME); + assertEquals(TestConstants.QPID_PACKAGE_NAME,qpidPackage.getName()); + + QpidPackage theSameAsPreviousOne = _model.getPackageByName(TestConstants.QPID_PACKAGE_NAME); + assertSame(qpidPackage, theSameAsPreviousOne); + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java new file mode 100644 index 0000000000..a4e1e24ff3 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java @@ -0,0 +1,187 @@ +/* + * + * 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.domain.model; + +import java.nio.ByteBuffer; +import java.util.LinkedList; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.qpid.management.domain.model.type.Uint64; +import org.apache.qpid.transport.codec.ManagementDecoder; + +public class OptionalPropertiesTest extends TestCase +{ + public void testDecoderStateChange() + { + QpidProperty property = new QpidProperty(); + assertSame( + "Default decoder for properties is the one for mandatory properties.", + property._mandatoryPropertyDecoder, + property._decoder); + + property.markAsOptional(1); + assertSame( + "After a property has been marked as optional the corresponding decoder must be installed.", + property._optionalPropertyDecoder, + property._decoder); + } + + /** + * Tests the execution of the decode() method when the current property is optional but in the presence bitmask + * there's no the corresponding bit set. + * + *
precondition : property is optional and corresponding presence bit is not set. + *
postcondition : result must be null. + */ + public void testDecodeValueWithOptionalPropertyAndMissingValue() + { + byte [] presenceBytes = {2}; + + QpidProperty property = new QpidProperty(); + + // We don't need a decoder so in order to be sure that it won't be invoked set it to null. + ManagementDecoder nullDecoder = null; + + for (int i = 0; i < 8; i++) + { + // Property number 1 is declaring a value so skip it! + if (i != 1) + { + property.markAsOptional(i); + assertNull(property.decodeValue(nullDecoder, presenceBytes)); + } + } + } + + /** + * Tests the execution of the decode() method when the current property is optional but in the presence bitmask + * there's no the corresponding bit set. + * + *
precondition : property is optional and corresponding presence bit is not set. + *
postcondition : result must be null. + */ + public void testDecodeValueWithOptionalPropertyAndDeclaredValue() + { + byte [] presenceBytes = {4}; + Long _44 = new Long(44); + + QpidProperty property = new QpidProperty(); + property.setType(new Uint64()); + property.markAsOptional(2); + + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.putLong(_44); + buffer.rewind(); + ManagementDecoder decoder = new ManagementDecoder(); + + decoder.init(buffer); + assertEquals(_44,property.decodeValue(decoder, presenceBytes)); + } + + /** + * Tests the execution of the decode() method with a real scenario where there are mandatory and optional + * properties. + */ + public void testDecodeValueWithOptionalAndMandatoryProperties() + { + // With this bitset : + // + // 1th opt property is null; + // 2th opt property is null; + // 3th opt property is not null; + // 4th opt property is null; + // 5th opt propertyis null; + // 6th opt property is null; + // 7th opt property is null; + // 8th opt property is not null; + byte [] presenceBytes = {4,1}; + + List properties = new LinkedList(); + + properties.add(createProperty(false, -1)); + properties.add(createProperty(false, -1)); + properties.add(createProperty(true, 0)); + properties.add(createProperty(false, -1)); + properties.add(createProperty(false, -1)); + properties.add(createProperty(true, 1)); + properties.add(createProperty(false, -1)); + properties.add(createProperty(false, -1)); + properties.add(createProperty(true, 2)); + properties.add(createProperty(true, 3)); + properties.add(createProperty(true, 4)); + properties.add(createProperty(true, 5)); + properties.add(createProperty(true, 6)); + properties.add(createProperty(true, 7)); + properties.add(createProperty(false, -1)); + properties.add(createProperty(true, 8)); + + Long expectedResults [] = { + 1L, // p1 + 22L, // p2 + null, // p3 + 232L, // p4 + 211L, // p5 + null, // p6 + 232L, // p7 + 211L, // p8 + 999L, // p9 + null, // p10 + null, // p11 + null, // p12 + null, // p13 + null, // p14 + 626L, // p15 + 969L // p16 + }; + + + ByteBuffer buffer = ByteBuffer.allocate(expectedResults.length * 8); + for (Long expected : expectedResults) + { + if (expected != null) + { + buffer.putLong(expected); + } + } + buffer.rewind(); + ManagementDecoder decoder = new ManagementDecoder(); + + decoder.init(buffer); + int index = 0; + for (QpidProperty property : properties) + { + assertEquals(expectedResults[index++],property.decodeValue(decoder, presenceBytes)); + } + } + + private QpidProperty createProperty(boolean isOptional, int optionalIndex) + { + QpidProperty property = new QpidProperty(); + property.setType(new Uint64()); + if (isOptional) + { + property.markAsOptional(optionalIndex); + } + return property; + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java new file mode 100644 index 0000000000..6032721d1b --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.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.management.domain.model; + +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.dir; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.name; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.type; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.unit; + +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.management.MBeanOperationInfo; + +import org.apache.qpid.management.Names; +import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; +import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute; +import org.apache.qpid.transport.codec.ManagementEncoder; + +/** + * Test case for Qpid Statistic builder. + * + * @author Andrea Gazzarini + */ +public class QpidMethodBuilderTest extends BaseQpidFeatureBuilderTestCase +{ + private final static Integer ARG_COUNT = 3; + private MethodOrEventDataTransferObject _methodDefinition; + + private List> _argumentsDefinitons = new ArrayList>(); + + @Override + protected void setUp () throws Exception + { + super.setUp(); + _featureDefinition.put(Names.ARG_COUNT_PARAM_NAME, ARG_COUNT); + + Map arg1 = new HashMap(); + arg1.put(name.name(), "arg1"); + arg1.put(type.name(),_type); + arg1.put(dir.name(),Direction.I.name()); + arg1.put(unit.name(), "bytes"); + + Map arg2 = new HashMap(); + arg2.put(name.name(), "arg2"); + arg2.put(type.name(),_type); + arg2.put(dir.name(),Direction.O.name()); + arg2.put(unit.name(), "bytes"); + + Map arg3 = new HashMap(); + arg3.put(name.name(), "arg3"); + arg3.put(type.name(),_type); + arg3.put(dir.name(),Direction.IO.name()); + arg3.put(unit.name(), "bytes"); + + /* + dir yes no yes Direction code for method arguments + unit yes yes yes Units for numeric values (i.e. seconds, bytes, etc.) + min yes no yes Minimum value for numerics + max yes no yes Maximum value for numerics + maxlen yes no yes Maximum length for strings + desc yes yes yes Description of the argument + default yes no yes Default value for the argument + */ + _argumentsDefinitons.add(arg1); + _argumentsDefinitons.add(arg2); + + _methodDefinition = new MethodOrEventDataTransferObject(_featureDefinition,_argumentsDefinitons); + _builder = QpidFeatureBuilder.createMethodBuilder(_methodDefinition); + } + + /** + * Tests the build process for a statistic when the definition map doesn't contains type attribute. + * + *
precondition: definition map doesn't contains type attribute. + *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the + * missing attribute. + */ + public void testMethodBuilderKO_WithMissingName() + { + internalTestForMissingMandatoryAttribute(Attribute.name); + } + + /** + * Tests the build process for a statistic when the definition map doesn't contain type, name, index & optional attributes. + * + *
precondition: definition map doesn't contain type, name, index & optional attributes. + *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the + * missing attributes. + */ + public void testMethodBuilderOK_WithMissingUnit() throws UnableToBuildFeatureException + { + internalTestForMissingOptionalAttribute(Attribute.unit); + } + + /** + * Tests the build process for a statistic when the definition map doesn't unit attribute. + * Note that this attribute is optional and therefore the build must succeed. + * + *
precondition: definition map doesn't contain unit attribute. + *
postcondition : no exception is thrown and the statistic is built. + */ + public void testMethodBuilderOK_WithMissingDescription() throws UnableToBuildFeatureException + { + internalTestForMissingOptionalAttribute(Attribute.desc); + } + + /** + * Tests the build process for a statistic when the definition map contains valid values. + * + *
precondition : the statistic definiton map contains valid values. + *
postcondition : no exception is thrown and the statistisc is built as expected. + */ + public void testMethodBuilderOK() throws UnableToBuildFeatureException + { + _builder.build(); + + QpidMethod method = (QpidMethod) _builder.getQpidFeature(); + MBeanOperationInfo info = (MBeanOperationInfo) _builder.getManagementFeature(); + + assertEquals(NAME,method.getName()); + + assertEquals(DESCRIPTION,method.getDescription()); + + assertEquals(method.getDescription(),info.getDescription()); + assertEquals(method.getName(),info.getName()); + } + + public void testEncodeParameters() throws ValidationException, UnableToBuildFeatureException { + _builder.build(); + + Object [] parameters = new Object[]{new Integer(1), new Integer(2),new Integer(3)}; + + ManagementEncoder encoder = new ManagementEncoder(ByteBuffer.allocate(1)){ + @Override + public void writeUint16 (int s) + { + assertTrue(s == 1 || s == 2); + } + }; + + QpidMethod method = (QpidMethod) _builder.getQpidFeature(); + method.encodeParameters(parameters, encoder); + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java new file mode 100644 index 0000000000..2611923f71 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java @@ -0,0 +1,167 @@ +/* + * + * 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.domain.model; + +import org.apache.qpid.management.domain.model.type.Uint64; + +public class QpidNumberPropertyTest extends BaseDomainModelTestCase +{ + private QpidProperty _property; + private Long _value = 55432L; + + @Override + protected void setUp () throws Exception + { + super.setUp(); + _property = new QpidProperty(); + _property.setName("average"); + _property.setAccessMode(AccessMode.RW); + _property.setType(new Uint64()); + } + + /** + * Tests the validation of a qpid property when the type is a number and no constraint has been set. + * + *
precondition : property type is a string, no constraint has been set. + *
postcondition : no exception is thrown and the validation succeeds. + */ + public void testValidationWithoutConstraints() { + try + { + _property.validate(_value); + } catch (ValidationException notExpected) + { + fail("If no constraint has been set on this property why the validation is failing?"); + } + } + + /** + * Tests the validation of a qpid property when the type is a number and a max value constraint has been set. + * + *
precondition : property type is a number, max value has been set and property value is greater than max value. + *
postcondition : an exception is thrown indicating the validation failure. + */ + public void testValidationKO_withMaxValue() { + int maxValue = (int)(_value-1); + _property.setMaxValue(maxValue); + + try + { + _property.validate(_value); + fail("The given value is violating the installed constraint so an exception must be thrown."); + } catch (ValidationException expected) + { + assertEquals(ValidationException.MAX_VALUE,expected.getConstraintName()); + assertEquals(maxValue,expected.getConstraintValue()); + assertEquals((double)_value,expected.getFeatureValue()); + assertEquals(_property.getName(),expected.getFeatureName()); + } + } + + /** + * Tests the validation of a qpid property when the type is a number and a min value constraint has been set. + * + *
precondition : property type is a number, min value has been set and property value is lesser than min value. + *
postcondition : an exception is thrown indicating the validation failure. + */ + public void testValidationKO_withMinValue() { + int minValue = (int)(_value+1); + _property.setMinValue(minValue); + + try + { + _property.validate(_value); + fail("The given value is violating the installed constraint so an exception must be thrown."); + } catch (ValidationException expected) + { + assertEquals(ValidationException.MIN_VALUE,expected.getConstraintName()); + assertEquals(minValue,expected.getConstraintValue()); + assertEquals((double)_value,expected.getFeatureValue()); + assertEquals(_property.getName(),expected.getFeatureName()); + } + } + + + /** + * Tests the validation of a qpid property when the number is a string and the property value is null. + * + *
precondition : property type is a number and property value is null.. + *
postcondition : no exception is thrown. That is : the validation succeeds. + */ + public void testValidationOK_withNullValue() { + try + { + _property.validate(null); + } catch (ValidationException notExpected) + { + fail("No constraint has been violated so validate() shouldn't raise an exception."); + } + + _property.setMinValue(1); + _property.setMaxValue(10); + + try + { + _property.validate(null); + } catch (ValidationException notExpected) + { + fail("No constraint has been violated so validate() shouldn't raise an exception."); + } + } + + /** + * Tests the validation of a qpid property when the type is a number and a max / min constraints have been set. + * + *
precondition : property type is a number, max / min constraint have been set and property value is wrong. + *
postcondition : an exception is thrown indicating the validation failure. + */ + public void testValidationOK_withMinAndMaxConstraint() { + int minValue = (int)(_value+1); + int maxValue = (int)(_value-1); + _property.setMinValue(minValue); + _property.setMaxValue(maxValue); + + try + { + _property.validate(_value); + fail("The given value is violating the installed constraint so an exception must be thrown."); + } catch (ValidationException expected) + { + assertEquals(ValidationException.MIN_VALUE,expected.getConstraintName()); + assertEquals(minValue,expected.getConstraintValue()); + assertEquals((double)_value,expected.getFeatureValue()); + assertEquals(_property.getName(),expected.getFeatureName()); + } + + _property.setMinValue(0); + try + { + _property.validate(_value); + fail("The given value is violating the installed constraint so an exception must be thrown."); + } catch (ValidationException expected) + { + assertEquals(ValidationException.MAX_VALUE,expected.getConstraintName()); + assertEquals(maxValue,expected.getConstraintValue()); + assertEquals((double)_value,expected.getFeatureValue()); + assertEquals(_property.getName(),expected.getFeatureName()); + } + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java new file mode 100644 index 0000000000..530b526bec --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java @@ -0,0 +1,54 @@ +/* + * + * 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.domain.model; + +import org.apache.qpid.management.TestConstants; + +/** + * Test case for Qpid package entity. + * + * @author Andrea Gazzarini + */ +public class QpidPackageTest extends BaseDomainModelTestCase +{ + private QpidPackage _qpidPackage; + + @Override + protected void setUp () throws Exception + { + super.setUp(); + _qpidPackage = new QpidPackage(TestConstants.QPID_PACKAGE_NAME, TestConstants.DOMAIN_MODEL); + } + + /** + * Tests the association of a new class with a qpid package. + * + *
precondition : the package is not associated with any class. + *
postcondition : the package is now associated with the given class. + */ + public void testAddClass() throws UnableToBuildFeatureException { + assertFalse(_qpidPackage.alreadyContainsClassDefinition(TestConstants.EXCHANGE_CLASS_NAME, TestConstants.HASH)); + + _qpidPackage.getQpidClass(TestConstants.EXCHANGE_CLASS_NAME, TestConstants.HASH, true); + + assertTrue(_qpidPackage.alreadyContainsClassDefinition(TestConstants.EXCHANGE_CLASS_NAME, TestConstants.HASH)); + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidPropertyBuilderTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidPropertyBuilderTest.java new file mode 100644 index 0000000000..4ac399def0 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidPropertyBuilderTest.java @@ -0,0 +1,271 @@ +/* + * + * 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.domain.model; + +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.access; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.index; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.max; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.min; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.optional; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.type; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.unit; + +import javax.management.MBeanAttributeInfo; + +import org.apache.qpid.management.configuration.UnknownTypeCodeException; +import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute; + +/** + * Test case for Qpid Property builder. + * + * @author Andrea Gazzarini + */ +public class QpidPropertyBuilderTest extends BaseQpidFeatureBuilderTestCase +{ + private final static Integer MIN = 0; + private final static Integer MAX = 120; + private final static String UNIT = "bytes"; + + private Integer _access; + + @Override + protected void setUp () throws Exception + { + super.setUp(); + + _access = 1; + configurator.addAccessModeMapping(_access.toString(), AccessMode.RW.name()); + + _featureDefinition.put(access.name(), _access); + _featureDefinition.put(unit.name(),UNIT); + _featureDefinition.put(min.name(), MIN); + _featureDefinition.put(max.name(),MAX); + + _featureDefinition.put(type.name(), _type); + _featureDefinition.put(optional.name(),0); + _featureDefinition.put(index.name(), 0); + + _builder = QpidFeatureBuilder.createPropertyBuilder(_featureDefinition); + } + + /** + * Tests the build process for a statistic when the definition map contains an unknown type code. + * + *
precondition : the statistic definiton map contains an unknown type code. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testStatisticBuilderKO_WithUnknownType() + { + int unknownTypeCode =999; + try + { + _featureDefinition.put(type.name(), unknownTypeCode); + _builder.build(); + fail("An unknown type code should raise an exception to indicate a failure."); + } catch (UnableToBuildFeatureException expected) + { + assertEquals(unknownTypeCode,((UnknownTypeCodeException)expected.getCause()).getCode()); + } + } + + /** + * Tests the build process for a statistic when the definition map contains a null value for a metadata attribute. + * + *
precondition : the statistic definiton map contains a null value for a metadata attribute. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testMethodBuilderKO_WithNullMetadataValue() + { + try + { + _featureDefinition.put(type.name(), null); + _builder.build(); + fail("An null value for a metadata attribute should raise an exception to indicate a failure."); + } catch (UnableToBuildFeatureException expected) + { + assertTrue(expected.getCause() instanceof NullPointerException); + } + } + + /** + * Tests the build process for a property when the definition map contains an invalid metadata type. + * + *
precondition : the property definiton map contains a wrong type for a metadata attribute. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testPropertyBuilderKO_WithClassCastException() + { + try + { + _featureDefinition.put(access.name(), new String("a")); + _builder.build(); + fail("A wrong metadata attribute type should raise an exception to indicate a failure."); + } catch (UnableToBuildFeatureException expected) + { + assertTrue(expected.getCause() instanceof ClassCastException); + } + } + + /** + * Tests the build process for a property when the definition map contains an unknown type code. + * + *
precondition : the property definiton map contains an unknown type code. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testPropertyBuilderKO_WithUnknownType() + { + int unknownTypeCode = 999; + try + { + _featureDefinition.put(type.name(), unknownTypeCode); + _builder.build(); + fail("An unknown type code should raise an exception to indicate a failure."); + } catch (UnableToBuildFeatureException expected) + { + assertEquals(unknownTypeCode,((UnknownTypeCodeException)expected.getCause()).getCode()); + } + } + + /** + * Tests the build process for a property when the definition map doesn't contains type attribute. + * + *
precondition: definition map doesn't contains type attribute. + *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the + * missing attribute. + */ + public void testPropertyBuilderKO_WithMissingType() + { + internalTestForMissingMandatoryAttribute(Attribute.type); + } + + /** + * Tests the build process for a property when the definition map doesn't contain type & name attributes. + * + *
precondition: definition map doesn't contain type & name attributes. + *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the + * missing attributes. + */ + public void testPropertyBuilderKO_WithMissingTypeAndName() + { + internalTestForMissingMandatoryAttribute(Attribute.type, Attribute.name); + } + + /** + * Tests the build process for a property when the definition map doesn't contain type & name & index attributes. + * + *
precondition: definition map doesn't contain type & name & index attributes. + *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the + * missing attributes. + */ + public void testPropertyBuilderKO_WithMissingTypeAndNameAndIndex() + { + internalTestForMissingMandatoryAttribute(Attribute.type, Attribute.name,Attribute.index); + } + + /** + * Tests the build process for a property when the definition map doesn't contain type, name, index & optional attributes. + * + *
precondition: definition map doesn't contain type, name, index & optional attributes. + *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the + * missing attributes. + */ + public void testPropertyBuilderKO_WithMissingTypeAndNameAndIndexAndOptional() + { + internalTestForMissingMandatoryAttribute(Attribute.type, Attribute.name,Attribute.index,Attribute.optional); + } + + /** + * Tests the build process for a property when the definition map doesn't contain type, name, index, optional and access + * attributes. + * + *
precondition: definition map doesn't contain type, name, index, optional and access attributes. + *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the + * missing attributes. + */ + public void testPropertyBuilderKO_WithMissingTypeAndNameAndIndexAndOptionalAndAccess() + { + internalTestForMissingMandatoryAttribute(Attribute.type, Attribute.name,Attribute.index,Attribute.optional,Attribute.access); + } + + /** + * Tests the build process for a property when the definition map doesn't unit attribute. + * Note that this attribute is optional and therefore the build must succeed. + * + *
precondition: definition map doesn't contain unit attribute. + *
postcondition : no exception is thrown and the property is built. + */ + public void testBuilderOK_WithMissingUnit() throws UnableToBuildFeatureException + { + internalTestForMissingOptionalAttribute(Attribute.unit); + } + + /** + * Tests the build process for a property when the definition map doesn't min and max attributes. + * Note that those attributes are optional and therefore the build must succeed. + * + *
precondition: definition map doesn't contain min and max attributes. + *
postcondition : no exception is thrown and the property is built. + */ + public void testBuilderOK_WithMissingMinAndMax() throws UnableToBuildFeatureException + { + internalTestForMissingOptionalAttribute(Attribute.min,Attribute.max); + } + + /** + * Tests the build process for a property when the definition map doesn't description attribute. + * Note that this attribute is optional and therefore the build must succeed. + * + *
precondition: definition map doesn't contain description attribute. + *
postcondition : no exception is thrown and the property is built. + */ + public void testBuilderOK_WithMissingDescription() throws UnableToBuildFeatureException + { + internalTestForMissingOptionalAttribute(Attribute.desc); + } + + /** + * Tests the build process for a property when the definition map contains valid values. + * + *
precondition : the property definiton map contains valid values. + *
postcondition : no exception is thrown and the property is built as expected. + */ + public void testPropertyBuilderOK() throws UnableToBuildFeatureException + { + _builder.build(); + + QpidProperty property = (QpidProperty) _builder.getQpidFeature(); + MBeanAttributeInfo info = (MBeanAttributeInfo) _builder.getManagementFeature(); + + assertEquals(NAME,property.getName()); + assertEquals(AccessMode.RW,property.getAccessMode()); + assertEquals(UNIT,property.getUnit()); + assertEquals(MIN.intValue(),property.getMinValue()); + assertEquals(MAX.intValue(),property.getMaxValue()); + assertEquals(Integer.MIN_VALUE,property.getMaxLength()); + assertEquals(DESCRIPTION,property.getDescription()); + assertEquals(Integer.class,property.getJavaType()); + assertFalse(property.isOptional()); + + assertEquals(property.getDescription(),info.getDescription()); + assertEquals(property.getName(),info.getName()); + assertEquals(property.getJavaType().getName(),info.getType()); + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidStatisticBuilderTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidStatisticBuilderTest.java new file mode 100644 index 0000000000..7f4cf72895 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidStatisticBuilderTest.java @@ -0,0 +1,159 @@ +/* + * + * 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.domain.model; + +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.type; +import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.unit; + +import javax.management.MBeanAttributeInfo; + +import org.apache.qpid.management.configuration.UnknownTypeCodeException; +import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute; + +/** + * Test case for Qpid Statistic builder. + * + * @author Andrea Gazzarini + */ +public class QpidStatisticBuilderTest extends BaseQpidFeatureBuilderTestCase +{ + private final static String UNIT = "bytes"; + + @Override + protected void setUp () throws Exception + { + super.setUp(); + _featureDefinition.put(unit.name(),UNIT); + _featureDefinition.put(type.name(), _type); + + _builder = QpidFeatureBuilder.createStatisticBuilder(_featureDefinition); + } + + /** + * Tests the build process for a statistic when the definition map contains an unknown type code. + * + *
precondition : the statistic definiton map contains an unknown type code. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testStatisticBuilderKO_WithUnknownType() + { + int unknownTypeCode = 999; + try + { + _featureDefinition.put(type.name(), unknownTypeCode); + _builder.build(); + fail("An unknown type code should raise an exception to indicate a failure."); + } catch (UnableToBuildFeatureException expected) + { + assertEquals(unknownTypeCode,((UnknownTypeCodeException)expected.getCause()).getCode()); + } + } + + /** + * Tests the build process for a statistic when the definition map contains a null value for a metadata attribute. + * + *
precondition : the statistic definiton map contains a null value for a metadata attribute. + *
postcondition : an exception is thrown indicating the failure. + */ + public void testMethodBuilderKO_WithNullMetadataValue() + { + try + { + _featureDefinition.put(type.name(), null); + _builder.build(); + fail("An null value for a metadata attribute should raise an exception to indicate a failure."); + } catch (UnableToBuildFeatureException expected) + { + assertTrue(expected.getCause() instanceof NullPointerException); + } + } + + /** + * Tests the build process for a statistic when the definition map doesn't contains type attribute. + * + *
precondition: definition map doesn't contains type attribute. + *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the + * missing attribute. + */ + public void testStatisticBuilderKO_WithMissingType() + { + internalTestForMissingMandatoryAttribute(Attribute.type); + } + + /** + * Tests the build process for a statistic when the definition map doesn't contain type & name attributes. + * + *
precondition: definition map doesn't contain type & name attributes. + *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the + * missing attributes. + */ + public void testStatisticBuilderKO_WithMissingTypeAndName() + { + internalTestForMissingMandatoryAttribute(Attribute.type, Attribute.name); + } + + /** + * Tests the build process for a statistic when the definition map doesn't contain type, name, index & optional attributes. + * + *
precondition: definition map doesn't contain type, name, index & optional attributes. + *
postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the + * missing attributes. + */ + public void testStatisticBuilderOK_WithMissingUnit() throws UnableToBuildFeatureException + { + internalTestForMissingOptionalAttribute(Attribute.unit); + } + + /** + * Tests the build process for a statistic when the definition map doesn't unit attribute. + * Note that this attribute is optional and therefore the build must succeed. + * + *
precondition: definition map doesn't contain unit attribute. + *
postcondition : no exception is thrown and the statistic is built. + */ + public void testBuilderOK_WithMissingDescription() throws UnableToBuildFeatureException + { + internalTestForMissingOptionalAttribute(Attribute.desc); + } + + /** + * Tests the build process for a statistic when the definition map contains valid values. + * + *
precondition : the statistic definiton map contains valid values. + *
postcondition : no exception is thrown and the statistisc is built as expected. + */ + public void testStatisticBuilderOK() throws UnableToBuildFeatureException + { + _builder.build(); + + QpidStatistic statistic= (QpidStatistic) _builder.getQpidFeature(); + MBeanAttributeInfo info = (MBeanAttributeInfo) _builder.getManagementFeature(); + + assertEquals(NAME,statistic.getName()); + assertEquals(UNIT,statistic.getUnit()); + assertEquals(DESCRIPTION,statistic.getDescription()); + assertEquals(Integer.class,statistic.getJavaType()); + + assertEquals(statistic.getDescription(),info.getDescription()); + assertEquals(statistic.getName(),info.getName()); + assertEquals(statistic.getJavaType().getName(),info.getType()); + } +} \ No newline at end of file diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidStringPropertyTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidStringPropertyTest.java new file mode 100644 index 0000000000..263e4209a6 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidStringPropertyTest.java @@ -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. + * + */ +package org.apache.qpid.management.domain.model; + +import org.apache.qpid.management.domain.model.type.Str16; + +public class QpidStringPropertyTest extends BaseDomainModelTestCase +{ + private QpidProperty _property; + private final String _5LettersString = "12345"; + + @Override + protected void setUp () throws Exception + { + super.setUp(); + _property = new QpidProperty(); + _property.setName("name"); + _property.setAccessMode(AccessMode.RW); + _property.setType(new Str16()); + } + + /** + * Tests the validation of a qpid property when the type is a string and a max length constraint hasn't been set. + * + *
precondition : property type is a string, max length hasn't been set. + *
postcondition : no exception is thrown. That is : the validation succeeds. + */ + public void testValidationWithoutMaxLength() { + try + { + _property.validate(_5LettersString); + } catch (ValidationException notExpected) + { + fail("No max length has been set on property so validation must succeed."); + } + } + + /** + * Tests the validation of a qpid property when the type is a string and a max length constraint has been set. + * + *
precondition : property type is a string, max length has been set and property value is longer than max length. + *
postcondition : an exception is thrown indicating the validation failure. + */ + public void testValidationKO_withMaxLength() { + int maxLength = 2; + _property.setMaxLength(maxLength); + + try + { + _property.validate(_5LettersString); + fail("No max length has been set on property so validation must proceed."); + } catch (ValidationException expected) + { + assertEquals(ValidationException.MAX_LENGTH,expected.getConstraintName()); + assertEquals(maxLength,expected.getConstraintValue()); + assertEquals(_5LettersString.length(),expected.getFeatureValue()); + assertEquals(_property.getName(),expected.getFeatureName()); + } + } + + /** + * Tests the validation of a qpid property when the type is a string and the property value is null. + * + *
precondition : property type is a string and property value is null.. + *
postcondition : no exception is thrown. That is : the validation succeeds. + */ + public void testValidationOK_withNullValue() { + try + { + _property.validate(null); + } catch (ValidationException notExpected) + { + fail("No constraint has been violated so validate() shouldn't raise an exception."); + } + + _property.setMaxLength(1); + + try + { + _property.validate(null); + } catch (ValidationException notExpected) + { + fail("No constraint has been violated so validate() shouldn't raise an exception."); + } + } + + /** + * Tests the validation of a qpid property when the type is a string and a max length constraint has been set. + * + *
precondition : property type is a string, max length has been set and property value is not violating that. + *
postcondition : no exception is thrown. That is : the validation succeeds. + */ + public void testValidationOK_withMaxLength() { + int maxLength = (_5LettersString.length()+1); + _property.setMaxLength(maxLength); + + try + { + _property.validate(_5LettersString); + } catch (ValidationException notExpected) + { + fail("No constraint has been violated so validate() shouldn't raise an exception."); + } + } +} diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/type/BinaryTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/type/BinaryTest.java new file mode 100644 index 0000000000..6636c08710 --- /dev/null +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/type/BinaryTest.java @@ -0,0 +1,59 @@ +/* + * + * 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.domain.model.type; + +import junit.framework.TestCase; + +/** + * Test case for "Binary" type. + * + * @author Andrea Gazzarini + */ +public class BinaryTest extends TestCase +{ + /** + * Tests the lazy & once hash code computation behaviour of the binary type. + */ + public void testHashCodeComputation(){ + Binary binary = new Binary(new byte[]{1,2,3,4,5,6,7,6,3,3}); + assertSame(binary.state,binary.hashCodeNotYetComputed); + + int firstResult = binary.hashCode(); + assertSame(binary.state,binary.hashCodeAlreadyComputed); + + int secondResult = binary.hashCode(); + assertSame(binary.state,binary.hashCodeAlreadyComputed); + assertEquals(firstResult,secondResult); + } + + /** + * Tests the equals() method of the binary class. + * Two binary must be equals only if they contain the same array (that is, two arrays with the same size & content) + */ + public void testIdentity() { + Binary binary = new Binary(new byte[]{1,2,3,4,5,6,7,6,3,3}); + Binary theSame= new Binary(new byte[]{1,2,3,4,5,6,7,6,3,3}); + Binary aDifferentOne = new Binary(new byte[]{4,2,3,3,4,4,5,3,3,2}); + + assertTrue(binary.equals(theSame)); + assertFalse(binary.equals(aDifferentOne)); + } +} \ No newline at end of file -- cgit v1.2.1