diff options
author | Arnaud Simon <arnaudsimon@apache.org> | 2008-10-31 10:04:12 +0000 |
---|---|---|
committer | Arnaud Simon <arnaudsimon@apache.org> | 2008-10-31 10:04:12 +0000 |
commit | f6af982851f804589793fd05207ee11eaa8ae984 (patch) | |
tree | f6d0c379b9625cbc7a00e7800031e47053c0b7b8 | |
parent | c8561c785bb6ff3b1f8e5902c2ffdba3eaa46de7 (diff) | |
download | qpid-python-f6af982851f804589793fd05207ee11eaa8ae984.tar.gz |
QPID-1411: Applied Andrea's patch; added config file sample
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@709374 13f79535-47bb-0310-9956-ffa450edef68
41 files changed, 819 insertions, 983 deletions
diff --git a/java/management/client/qman-config.xml b/java/management/client/qman-config.xml new file mode 100644 index 0000000000..185eb6f2f5 --- /dev/null +++ b/java/management/client/qman-config.xml @@ -0,0 +1,26 @@ +<configuration>
+ <brokers>
+ <broker>
+ <host>localhost</host>
+ <port>5672</port>
+ <virtual-host>test</virtual-host>
+ <user>guest</user>
+ <password>guest</password>
+ <max-pool-capacity>4</max-pool-capacity>
+ <initial-pool-capacity>0</initial-pool-capacity>
+ <max-wait-timeout>-1</max-wait-timeout>
+ </broker>
+<!--
+ <broker>
+ <host>myhost</host>
+ <port>5672</port>
+ <virtual-host>test</virtual-host>
+ <user>guest</user>
+ <password>guest</password>
+ <max-pool-capacity>4</max-pool-capacity>
+ <initial-pool-capacity>0</initial-pool-capacity>
+ <max-wait-timeout>-1</max-wait-timeout>
+ </broker>
+-->
+ </brokers>
+</configuration>
\ No newline at end of file diff --git a/java/management/client/src/main/java/log4j.xml b/java/management/client/src/main/java/log4j.xml deleted file mode 100644 index 0c16c56ac7..0000000000 --- a/java/management/client/src/main/java/log4j.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> -<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> - <appender name="console" class="org.apache.log4j.ConsoleAppender"> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/> - </layout> - </appender> - <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender"> - <param name="File" value="C:\\tmp\\qman.log"/> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/> - </layout> - </appender> - <category name="org.apache.qpid.management.domain.model.QpidClass"> - <priority value="DEBUG"/> - </category> - <category name="org.apache.qpid.management"> - <priority value="INFO"/> - </category> - <root> - <priority value="ERROR"/> - <appender-ref ref="console"/> - </root> -</log4j:configuration>
\ No newline at end of file diff --git a/java/management/client/src/main/java/org/apache/qpid/management/Messages.java b/java/management/client/src/main/java/org/apache/qpid/management/Messages.java index 1448ab379e..34d46df0f9 100644 --- a/java/management/client/src/main/java/org/apache/qpid/management/Messages.java +++ b/java/management/client/src/main/java/org/apache/qpid/management/Messages.java @@ -29,6 +29,8 @@ public interface Messages String QMAN_000019_QMAN_STARTED = "<QMAN-000019> : Q-Man open for e-business.";
String QMAN_000020_SHUTTING_DOWN_QMAN = "<QMAN-000020> : Shutting down Q-Man...";
String QMAN_000021_SHUT_DOWN = "<QMAN-000021> : Q-Man shut down.";
+ String QMAN_000022_NO_BROKER_CONFIGURED = "<QMAN-000022> : Q-Man has no configured broker : in order to connect with a running one use Q-Man Administration interface.";
+ String QMAN_000023_QMAN_REGISTERED_AS_MBEAN = "<QMAN-000023> : Q-Man service is now available on MBeanServer.";
// DEBUG
String QMAN_200001_INCOMING_MESSAGE_HAS_BEEN_RECEIVED = "<QMAN-200001> : New incoming message has been received. Message content is %s";
@@ -67,7 +69,9 @@ public interface Messages // WARNING
String QMAN_300001_MESSAGE_DISCARDED = "<QMAN-300001> : No handler has been configured for processing messages with \"%s\" as opcode. Message will be discarded.";
String QMAN_300002_UNKNOWN_SEQUENCE_NUMBER = "<QMAN-300002> : Unable to deal with incoming message because it contains a unknown sequence number (%s).";
-
+ String QMAN_300003_BROKER_ALREADY_CONNECTED = "<QMAN-300003> : Unable to enlist given broker connection data : QMan is already connected with broker %s";
+ String QMAN_300004_UNVALID_CONFIGURATION_FILE = "<QMAN-300004> : The given configuration file (%s) is not valid (it doesn't exist or cannot be read)";
+
// ERROR
String QMAN_100001_BAD_MAGIC_NUMBER_FAILURE = "<QMAN-100001> : Message processing failure : incoming message contains a bad magic number (%s) and therefore will be discaded.";
String QMAN_100002_MESSAGE_READ_FAILURE = "<QMAN-100002> : Message I/O failure : unable to read byte message content and therefore it will be discarded.";
@@ -86,9 +90,9 @@ public interface Messages String QMAN_100015_UNABLE_TO_SEND_SCHEMA_REQUEST = "<QMAN-100015> : Unable to send a schema request schema for %s.%s";
String QMAN_100016_UNABLE_TO_DECODE_FEATURE_VALUE = "<QMAN-100016> : Unable to decode value for %s::%s::%s";
String QMAN_100017_UNABLE_TO_CONNECT = "<QMAN-100017>: Cannot connect to broker %s on %s";
+ String QMAN_100018_UNABLE_TO_STARTUP_CORRECTLY = "<QMAN-100018> : Q-Man was unable to startup correctly : see logs for further details.";
// MESSAGES
String EVENT_SEVERITY_ATTRIBUTE_DESCRIPTION = "Severity level for this event.";
String EVENT_TIMESTAMP_ATTRIBUTE_DESCRIPTION = "Current timestamp of this event.";
- String UNABLE_TO_STARTUP_CORRECTLY = "<QMAN-100002> : Q-Man was unable to startup correctly : a configuration error occurred.";
}
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 index 4fabb40640..7ed0f8b24d 100644 --- 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 @@ -35,9 +35,8 @@ public interface Names String METHOD_REPLY_QUEUE_PREFIX = "reply."; String AMQ_DIRECT_QUEUE = "amq.direct"; - String AGENT_ROUTING_KEY = "agent.1.0"; - - String BROKER_ROUTING_KEY = "broker"; + String AGENT_ROUTING_KEY_PREFIX = "agent."; + String AGENT_ROUTING_KEY = AGENT_ROUTING_KEY_PREFIX+"1.0"; // Attributes String PACKAGE = "package"; @@ -45,9 +44,14 @@ public interface Names 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"; String DEFAULT_PARAM_NAME ="default"; + + String NUMBER_VALIDATOR = "org.apache.qpid.management.domain.model.QpidProperty$NumberValidator"; + String STRING_VALIDATOR = "org.apache.qpid.management.domain.model.QpidProperty$StringValidator"; + + String QMAN_CONFIG_OPTION_NAME = "qman-config"; + + String ADD_BROKER_OPERATION_NAME = "addBroker"; } 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 deleted file mode 100644 index 636ef9cb05..0000000000 --- a/java/management/client/src/main/java/org/apache/qpid/management/config.xml +++ /dev/null @@ -1,84 +0,0 @@ -<configuration> - <type-mappings> - <mapping> - <code>1</code> - <class-name>org.apache.qpid.management.domain.model.type.Uint8</class-name> - <validator-class-name>org.apache.qpid.management.domain.model.QpidProperty$NumberValidator</validator-class-name> - </mapping> - <mapping> - <code>2</code> - <class-name>org.apache.qpid.management.domain.model.type.Uint16</class-name> - <validator-class-name>org.apache.qpid.management.domain.model.QpidProperty$NumberValidator</validator-class-name> - </mapping> - <mapping> - <code>3</code> - <class-name>org.apache.qpid.management.domain.model.type.Uint32</class-name> - <validator-class-name>org.apache.qpid.management.domain.model.QpidProperty$NumberValidator</validator-class-name> - </mapping> - <mapping> - <code>4</code> - <class-name>org.apache.qpid.management.domain.model.type.Uint64</class-name> - <validator-class-name>org.apache.qpid.management.domain.model.QpidProperty$NumberValidator</validator-class-name> - </mapping> - <mapping> - <code>6</code> - <class-name>org.apache.qpid.management.domain.model.type.Str8</class-name> - <validator-class-name>org.apache.qpid.management.domain.model.QpidProperty$StringValidator</validator-class-name> - </mapping> - <mapping> - <code>7</code> - <class-name>org.apache.qpid.management.domain.model.type.Str16</class-name> - <validator-class-name>org.apache.qpid.management.domain.model.QpidProperty$StringValidator</validator-class-name> - </mapping> - <mapping> - <code>8</code> - <class-name>org.apache.qpid.management.domain.model.type.AbsTime</class-name> - </mapping> - <mapping> - <code>9</code> - <class-name>org.apache.qpid.management.domain.model.type.DeltaTime</class-name> - </mapping> - <mapping> - <code>10</code> - <class-name>org.apache.qpid.management.domain.model.type.ObjectReference</class-name> - </mapping> - <mapping> - <code>11</code> - <class-name>org.apache.qpid.management.domain.model.type.Boolean</class-name> - </mapping> - <mapping> - <code>14</code> - <class-name>org.apache.qpid.management.domain.model.type.Uuid</class-name> - </mapping> - <mapping> - <code>15</code> - <class-name>org.apache.qpid.management.domain.model.type.Map</class-name> - </mapping> - </type-mappings> - <access-mode-mappings> - <mapping> - <code>1</code> - <value>RC</value> - </mapping> - <mapping> - <code>2</code> - <value>RW</value> - </mapping> - <mapping> - <code>3</code> - <value>RO</value> - </mapping> - </access-mode-mappings> - <brokers> - <broker> - <host>localhost</host> - <port>5672</port> - <virtual-host>test</virtual-host> - <user>guest</user> - <password>guest</password> - <max-pool-capacity>4</max-pool-capacity> - <initial-pool-capacity>0</initial-pool-capacity> - <max-wait-timeout>-1</max-wait-timeout> - </broker> - </brokers> -</configuration> 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 index 899462a648..af6aaa36bf 100644 --- 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 @@ -29,20 +29,21 @@ import org.apache.qpid.management.domain.model.AccessMode; */ class AccessModeMapping { - private int _code; - private AccessMode _accessMode; + private final int _code; + private final AccessMode _accessMode; /** - * Sets the code for this mapping. - * Note that the given string must be a valid number (integer). + * Builds a new access mode mapping with the given parameters. * - * @param codeAsString the code value as a string. - * @throws NumberFormatException when the given string is not a number. + * @param code the access code. + * @param accessMode the access mode. */ - void setCode(String codeAsString) { - this._code = Integer.parseInt(codeAsString); + AccessModeMapping(int code, AccessMode accessMode) + { + this._code = code; + this._accessMode = accessMode; } - + /** * Returns the access mode of this mapping. * @@ -54,18 +55,6 @@ class AccessModeMapping } /** - * 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. @@ -91,4 +80,4 @@ class AccessModeMapping .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 deleted file mode 100644 index d9dcbd12d3..0000000000 --- a/java/management/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. - * - *<mapping> - <code>1</code> - <value>RC</value> - </mapping> - * - * @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/BrokerAlreadyConnectedException.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerAlreadyConnectedException.java new file mode 100644 index 0000000000..62b14e48b9 --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerAlreadyConnectedException.java @@ -0,0 +1,32 @@ +package org.apache.qpid.management.configuration;
+
+/**
+ * Thrown when an attempt is made in order to connect QMan with an already connected broker.
+ *
+ * @author Andrea Gazzarini
+ */
+public class BrokerAlreadyConnectedException extends Exception {
+
+ private static final long serialVersionUID = -5082431738056504669L;
+
+ private BrokerConnectionData _connectionData;
+
+ /**
+ * Builds a new exception with the given data.
+ *
+ * @param connectionData the broker connection data.
+ */
+ public BrokerAlreadyConnectedException(BrokerConnectionData connectionData) {
+ this._connectionData = connectionData;
+ }
+
+ /**
+ * Returns the connection data of the connected broker.
+ *
+ * @return the connection data of the connected broker.
+ */
+ public BrokerConnectionData getBrokerConnectionData()
+ {
+ return _connectionData;
+ }
+}
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 index 74e89ef19d..be04c67555 100644 --- 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 @@ -37,6 +37,38 @@ public class BrokerConnectionData private long _maxWaitTimeout; /** + * Builds a connection data with the given parameters. + * + * @param host the hostname where the broker is running. + * @param port the port where the broker is running. + * @param username the username for connecting with the broker. + * @param password the password for connecting with the broker. + * @param virtualHost the virtual host. + * @param initialPoolCapacity the number of the connection that must be immediately opened. + * @param maxPoolCapacity the maximum number of opened connection. + * @param maxWaitTimeout the maximum amount of time that a client will wait for obtaining a connection. + */ + public BrokerConnectionData( + String host, + int port, + String virtualHost, + String username, + String password, + int initialPoolCapacity, + int maxPoolCapacity, + long waitTimeout) { + + this._host = host; + this._port = port; + this._virtualHost = virtualHost; + this._username = username; + this._password = password; + _maxPoolCapacity = maxPoolCapacity; + _initialPoolCapacity = initialPoolCapacity; + _maxWaitTimeout = waitTimeout; + } + + /** * Builds a new empty broker connection data object. */ BrokerConnectionData() @@ -198,14 +230,41 @@ public class BrokerConnectionData return _maxWaitTimeout; } - public void setInitialPoolCapacity (String value) + /** + * Sets the initial connection pool capacity. + * + * @param capacity the initial connection pool capacity. + */ + public void setInitialPoolCapacity (String capacity) { - _initialPoolCapacity = Integer.parseInt(value); + _initialPoolCapacity = Integer.parseInt(capacity); } + /** + * Returns the initial connection pool capacity. + * + * @return the initial connection pool capacity. + */ public int getInitialPoolCapacity () { return _initialPoolCapacity; } -}
\ No newline at end of file + @Override + public boolean equals(Object object) { + try + { + BrokerConnectionData connectionData = (BrokerConnectionData) object; + return (_host.equals(connectionData._host) ) + && (_port == connectionData._port) + && (_virtualHost.equals(connectionData._virtualHost)); + } catch (Exception exception) { + return false; + } + } + + @Override + public int hashCode() { + return _host.hashCode()+_port+_virtualHost.hashCode(); + } +} diff --git a/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionException.java b/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionException.java new file mode 100644 index 0000000000..841570533d --- /dev/null +++ b/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionException.java @@ -0,0 +1,21 @@ +package org.apache.qpid.management.configuration;
+
+/**
+ * Thrown when a connection to a broker cannot be estabilished.
+ *
+ * @author Andrea Gazzarini
+ */
+public class BrokerConnectionException extends Exception
+{
+ private static final long serialVersionUID = 8170112238862494025L;
+
+ /**
+ * Builds a new exception with the given cause.
+ *
+ * @param cause the exception cause.
+ */
+ BrokerConnectionException(Throwable cause)
+ {
+ super(cause);
+ }
+}
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 index 2c27926f47..12b3c6be9e 100644 --- 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 @@ -86,6 +86,16 @@ public final class Configuration } /** + * Returns true if this configuration has at least one broker connection data. + * + * @return true if this configuration has at least one broker connection data. + */ + public boolean hasOneOrMoreBrokersDefined() + { + return !_brokerConnectionInfos.isEmpty(); + } + + /** * Returns the type associated to the given code. * * @param code the code used as search criteria. @@ -321,14 +331,27 @@ public final class Configuration * * @param brokerId the broker identifier. * @param connectionData the connection data. - * @throws Exception + * @throws BrokerAlreadyConnectedException when the broker is already connected. + * @throws BrokerConnectionException when a connection cannot be estabilished. */ - void addBrokerConnectionData (UUID brokerId, BrokerConnectionData connectionData) throws Exception + void addBrokerConnectionData (UUID brokerId, BrokerConnectionData connectionData) throws BrokerAlreadyConnectedException, BrokerConnectionException { - QpidDatasource.getInstance().addConnectionPool(brokerId, connectionData); - _brokerConnectionInfos.put(brokerId,connectionData); + if (_brokerConnectionInfos.containsValue(connectionData)) + { + throw new BrokerAlreadyConnectedException(connectionData); + } + + try + { + QpidDatasource.getInstance().addConnectionPool(brokerId, connectionData); + _brokerConnectionInfos.put(brokerId,connectionData); + + LOGGER.info(Messages.QMAN_000009_BROKER_DATA_CONFIGURED,brokerId,connectionData); + } catch(Exception exception) + { + throw new BrokerConnectionException(exception); + } - LOGGER.info(Messages.QMAN_000009_BROKER_DATA_CONFIGURED,brokerId,connectionData); } /** 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 index 6952d0ca4c..f9a662ffe7 100644 --- 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 @@ -21,11 +21,15 @@ package org.apache.qpid.management.configuration; import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; import java.io.InputStreamReader; +import java.util.UUID; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.apache.qpid.management.Messages; import org.apache.qpid.management.Names; import org.apache.qpid.management.Protocol; import org.apache.qpid.management.domain.handler.impl.ConfigurationMessageHandler; @@ -34,6 +38,17 @@ import org.apache.qpid.management.domain.handler.impl.HeartBeatIndicationMessage import org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler; import org.apache.qpid.management.domain.handler.impl.MethodResponseMessageHandler; import org.apache.qpid.management.domain.handler.impl.SchemaResponseMessageHandler; +import org.apache.qpid.management.domain.model.AccessMode; +import org.apache.qpid.management.domain.model.type.AbsTime; +import org.apache.qpid.management.domain.model.type.DeltaTime; +import org.apache.qpid.management.domain.model.type.ObjectReference; +import org.apache.qpid.management.domain.model.type.Str16; +import org.apache.qpid.management.domain.model.type.Str8; +import org.apache.qpid.management.domain.model.type.Uint16; +import org.apache.qpid.management.domain.model.type.Uint32; +import org.apache.qpid.management.domain.model.type.Uint64; +import org.apache.qpid.management.domain.model.type.Uint8; +import org.apache.qpid.transport.util.Logger; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -47,7 +62,9 @@ import org.xml.sax.helpers.DefaultHandler; */ public class Configurator extends DefaultHandler { - /** + private final static Logger LOGGER = Logger.get(Configurator.class); + + /** * Default (empty) parser used when there's no need to process data (non relevant elements). */ final static IParser DEFAULT_PARSER = new IParser() { @@ -61,11 +78,9 @@ public class Configurator extends DefaultHandler } }; - IParser _typeMappingParser = new TypeMappingParser(); - IParser _accessModeMappingParser = new AccessModeMappingParser(); IParser _brokerConfigurationParser = new BrokerConnectionDataParser(); IParser _currentParser = DEFAULT_PARSER; - + /** * Delegates the processing to the current parser. */ @@ -85,15 +100,6 @@ public class Configurator extends DefaultHandler 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; @@ -115,22 +121,116 @@ public class Configurator extends DefaultHandler */ public void configure() throws ConfigurationException { + BufferedReader reader = null; 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); + String initialConfigFileName = System.getProperty(Names.QMAN_CONFIG_OPTION_NAME); + if (initialConfigFileName != null && initialConfigFileName.trim().length() != 0) + { + File initialConfigurationFile = new File(initialConfigFileName); + if (initialConfigurationFile.canRead()) + { + SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); + reader = new BufferedReader(new InputStreamReader(new FileInputStream(initialConfigFileName))); + InputSource source = new InputSource(reader); + parser.parse(source, this); + } else { + LOGGER.warn(Messages.QMAN_300004_UNVALID_CONFIGURATION_FILE, initialConfigFileName); + } + } + + addTypeMappings(); + addAccessModeMappings(); - // Hard-coded configuration for message handlers : we need that because those handler mustn't be configurable. - // QMan is not able to work without them! addMandatoryManagementMessageHandlers(); addMandatoryMethodReplyMessageHandlers(); } catch (Exception exception) { throw new ConfigurationException(exception); + } finally + { + try + { + reader.close(); + } catch (Exception ignore) + { + } } } + + /** + * Creates and return a value object (BrokerConnectionData) with the given parameters. + * Note that that object will be stored on configuration and it could be used to set a connection with the broker. + * This happens when the "initialPoolCapacity" is greater than 0 : in this case the caller is indicatinf that it wants to open + * one or more connections immediately at startup and therefore Q-Man will try to do that. + * + * @param host the hostname where the broker is running. + * @param port the port where the broker is running. + * @param username the username for connecting with the broker. + * @param password the password for connecting with the broker. + * @param virtualHost the virtual host. + * @param initialPoolCapacity the number of the connection that must be immediately opened. + * @param maxPoolCapacity the maximum number of opened connection. + * @param maxWaitTimeout the maximum amount of time that a client will wait for obtaining a connection. + * @return the value object containing the data above. + * @throws BrokerAlreadyConnectedException when the broker is already connected. + * @throws BrokerConnectionException when a connection cannot be estabilished. + */ + public BrokerConnectionData createAndReturnBrokerConnectionData( + UUID brokerId, + String host, + int port, + String username, + String password, + String virtualHost, + int initialPoolCapacity, + int maxPoolCapacity, + long maxWaitTimeout) throws BrokerAlreadyConnectedException, BrokerConnectionException + { + BrokerConnectionData data = new BrokerConnectionData( + host, + port, + virtualHost, + username, + password, + initialPoolCapacity, + maxPoolCapacity, + maxWaitTimeout); + Configuration.getInstance().addBrokerConnectionData(brokerId, data); + return data; + } + + /** + * Configures access mode mappings. + * An access mode mapping is an association between a code and an access mode. + */ + private void addAccessModeMappings() { + Configuration configuration = Configuration.getInstance(); + configuration.addAccessModeMapping(new AccessModeMapping(1,AccessMode.RC)); + configuration.addAccessModeMapping(new AccessModeMapping(2,AccessMode.RW)); + configuration.addAccessModeMapping(new AccessModeMapping(3,AccessMode.RO)); + } + + /** + * Configures type mappings. + * A type mapping is an association between a code and a management type. + */ + private void addTypeMappings() + { + Configuration configuration = Configuration.getInstance(); + configuration.addTypeMapping(new TypeMapping(1,new Uint8(),Names.NUMBER_VALIDATOR)); + configuration.addTypeMapping(new TypeMapping(2,new Uint16(),Names.NUMBER_VALIDATOR)); + configuration.addTypeMapping(new TypeMapping(3,new Uint32(),Names.NUMBER_VALIDATOR)); + configuration.addTypeMapping(new TypeMapping(4,new Uint64(),Names.NUMBER_VALIDATOR)); + configuration.addTypeMapping(new TypeMapping(6,new Str8(),Names.STRING_VALIDATOR)); + configuration.addTypeMapping(new TypeMapping(7,new Str16(),Names.STRING_VALIDATOR)); + configuration.addTypeMapping(new TypeMapping(8,new AbsTime())); + configuration.addTypeMapping(new TypeMapping(9,new DeltaTime())); + configuration.addTypeMapping(new TypeMapping(10,new ObjectReference())); + configuration.addTypeMapping(new TypeMapping(11,new org.apache.qpid.management.domain.model.type.Boolean())); + configuration.addTypeMapping(new TypeMapping(14,new org.apache.qpid.management.domain.model.type.Uuid())); + configuration.addTypeMapping(new TypeMapping(15,new org.apache.qpid.management.domain.model.type.Map())); + } /** * Configures the mandatory management message handlers. @@ -146,11 +246,6 @@ public class Configurator extends DefaultHandler new MessageHandlerMapping( Protocol.SCHEMA_RESPONSE_OPCODE, SchemaResponseMessageHandler.class.getName())); - - Configuration.getInstance().addMethodReplyMessageHandlerMapping( - new MessageHandlerMapping( - Protocol.HEARTBEAT_INDICATION_RESPONSE_OPCODE, - HeartBeatIndicationMessageHandler.class.getName())); } /** @@ -172,15 +267,10 @@ public class Configurator extends DefaultHandler new MessageHandlerMapping( Protocol.EVENT_CONTENT_RESPONSE_OPCDE, EventContentMessageHandler.class.getName())); - } - - /** - * Returns the name of the configuration file. - * - * @return the name of the configuration file. - */ - String getConfigurationFileName() - { - return Names.CONFIGURATION_FILE_NAME; + + Configuration.getInstance().addManagementMessageHandlerMapping( + new MessageHandlerMapping( + Protocol.HEARTBEAT_INDICATION_RESPONSE_OPCODE, + HeartBeatIndicationMessageHandler.class.getName())); } } 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 index fed926e214..a5f61350d6 100644 --- 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 @@ -6,17 +6,7 @@ package org.apache.qpid.management.configuration; * @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"; }}, @@ -37,4 +27,4 @@ public enum Tag { 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 index 714c8eb6f5..2c0a460c1a 100644 --- 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 @@ -21,6 +21,7 @@ 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. * @@ -28,70 +29,56 @@ import org.apache.qpid.management.domain.model.type.Type; */ class TypeMapping { - private int _code; - private Type _type; - private String _validatorClass; + private final int _code; + private final Type _type; + private final String _validatorClass; /** - * Returns the code of this mapping. + * Builds a new type mapping with the given parameters and no validator. * - * @return the code of this mapping. + * @param code the code. + * @param type the management type. */ - int getCode () + TypeMapping(int code, Type type) { - return _code; + this(code,type,null); } - + /** - * Sets the code for this mapping. - * Note that the given string must be a valid number (integer). + * Builds a new type mapping with the given parameters. * - * @param codeAsString the code as a string. - * @throws NumberFormatException when the given string is not a valid number. + * @param code the code. + * @param type the management type. + * @param validatorClassName the class name of the validator to be used. */ - void setCode (String codeAsString) + TypeMapping(int code, Type type, String validatorClassName) { - this._code = Integer.parseInt(codeAsString); + this._code = code; + this._type = type; + this._validatorClass = validatorClassName; } - + /** - * Returns the type for this mapping. + * Returns the code of this mapping. * - * @return the type for this mapping. + * @return the code of this mapping. */ - Type getType () + int getCode () { - return _type; + return _code; } /** - * Sets the type of this mapping. + * Returns the type for this mapping. * - * @param typeClass the type class as a string. - * @throw IllegalArgumentException when it's not possible to load the given class. + * @return the type for this mapping. */ - void setType (String typeClass) + Type getType () { - try - { - this._type = (Type) Class.forName(typeClass).newInstance(); - } catch (Exception exception) - { - throw new IllegalArgumentException(exception); - } + return _type; } /** - * 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. @@ -100,4 +87,4 @@ class TypeMapping { 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 deleted file mode 100644 index 40b9cf84ca..0000000000 --- a/java/management/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. - * - * <mapping> - <code>1</code> - <class-name>org.apache.qpid.management.domain.model.type.Uint8</class-name> - <validator-class-name>org.apache.qpid.management.domain.model.QpidProperty$NumberValidator</validator-class-name> - </mapping> - * - * @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/domain/handler/impl/ConfigurationMessageHandler.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/ConfigurationMessageHandler.java index a5f8c238a7..3158138172 100644 --- 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 @@ -52,7 +52,6 @@ public class ConfigurationMessageHandler extends ContentIndicationMessageHandler 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/HeartBeatIndicationMessageHandler.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/HeartBeatIndicationMessageHandler.java index 7bc5c71a39..f3bb102926 100644 --- a/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/HeartBeatIndicationMessageHandler.java +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/HeartBeatIndicationMessageHandler.java @@ -11,7 +11,6 @@ import org.apache.qpid.transport.codec.ManagementDecoder; */
public class HeartBeatIndicationMessageHandler extends BaseMessageHandler
{
- @Override
public void process(ManagementDecoder decoder, int sequenceNumber)
{
_domainModel.updateLastRefreshDate();
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 index ee6d1f0092..e86a44f829 100644 --- 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 @@ -52,7 +52,6 @@ public class InstrumentationMessageHandler extends ContentIndicationMessageHandl 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/SchemaResponseMessageHandler.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/SchemaResponseMessageHandler.java index add7fd073b..04357b8eb4 100644 --- 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 @@ -60,7 +60,6 @@ public class SchemaResponseMessageHandler extends BaseMessageHandler */ final IProcessor _classSchemaProcessor = new IProcessor() { - @Override public void process(ManagementDecoder decoder) { try @@ -93,7 +92,6 @@ public class SchemaResponseMessageHandler extends BaseMessageHandler */ final IProcessor _eventSchemaProcessor = new IProcessor() { - @Override public void process(ManagementDecoder decoder) { try 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 index 1e03815768..d919fdacae 100644 --- 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 @@ -24,6 +24,7 @@ import java.lang.management.ManagementFactory; import java.util.Set; import java.util.UUID; +import javax.management.MBeanException; import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; @@ -33,6 +34,7 @@ import org.apache.qpid.management.Names; import org.apache.qpid.management.domain.model.QpidClass.QpidManagedObject; import org.apache.qpid.management.domain.model.QpidEvent.QpidManagedEvent; import org.apache.qpid.management.domain.model.type.Binary; +import org.apache.qpid.management.domain.services.QMan; import org.apache.qpid.transport.util.Logger; /** @@ -40,11 +42,31 @@ import org.apache.qpid.transport.util.Logger; * * @author Andrea Gazzarini */ -class JmxService +public class JmxService { private final static Logger LOGGER = Logger.get(JmxService.class); MBeanServer _mxServer = ManagementFactory.getPlatformMBeanServer(); + /** + * Registers QMan with the MBeanServer. + * After that QMan management interface will be JMX-exposed. + * + * @param qman QMan + * @throws MBeanException when some error occurs during registration. + */ + public void registerQManService(QMan qman) throws MBeanException + { + ObjectName name = createQManName(); + if (!_mxServer.isRegistered(name)) + { + try { + _mxServer.registerMBean(qman, name); + } catch (Exception exception) { + throw new MBeanException(exception); + } + } + } + void registerEventInstance( QpidManagedEvent eventInstance, UUID brokerId, @@ -220,6 +242,50 @@ class JmxService throw new RuntimeException(exception); } } + + /** + * Creates an object name that will be used for searching all registered events. + * + * @return the object name that will be used for searching all registered events. + */ + ObjectName createEventSearchName() + { + String asString = new StringBuilder() + .append(Names.DOMAIN_NAME) + .append(':') + .append('*') + .append(",type=Event") + .toString(); + try + { + return new ObjectName(asString); + } catch (MalformedObjectNameException exception) + { + throw new RuntimeException(exception); + } + } + + /** + * Creates an object name that will be used for searching all registered object instances. + * + * @return the object name that will be used for searching all registered object instances. + */ + private ObjectName createObjectInstanceSearchName() + { + String asString = new StringBuilder() + .append(Names.DOMAIN_NAME) + .append(':') + .append('*') + .append(",type=Object") + .toString(); + try + { + return new ObjectName(asString); + } catch (MalformedObjectNameException exception) + { + throw new RuntimeException(exception); + } + } /** * Factory method for ObjectNames. @@ -257,42 +323,19 @@ class JmxService { throw new RuntimeException(exception); } - } - - /** - * Creates an object name that will be used for searching all registered events. - * - * @return the object name that will be used for searching all registered events. - */ - ObjectName createEventSearchName() - { - String asString = new StringBuilder() - .append(Names.DOMAIN_NAME) - .append(':') - .append('*') - .append(",type=Event") - .toString(); - try - { - return new ObjectName(asString); - } catch (MalformedObjectNameException exception) - { - throw new RuntimeException(exception); - } } /** - * Creates an object name that will be used for searching all registered object instances. + * Creates the QMan object name. * - * @return the object name that will be used for searching all registered object instances. + * @return the QMan object name. */ - private ObjectName createObjectInstanceSearchName() + private ObjectName createQManName() { String asString = new StringBuilder() .append(Names.DOMAIN_NAME) .append(':') - .append('*') - .append(",type=Object") + .append("Type=Service") .toString(); try { @@ -301,5 +344,5 @@ class JmxService { throw new RuntimeException(exception); } - } + } } 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 index ec26ef819e..277d9e47a8 100644 --- 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 @@ -662,7 +662,6 @@ class QpidClass extends QpidEntity _methodInvocationListener.operationIsGoingToBeInvoked(new InvocationEvent(this,sequenceNumber,_exchangeChannelForMethodInvocations)); _service.invoke(_parent.getName(), _name, _hash,objectId,parameters, method,sequenceNumber,objectId.getBankId(),objectId.getBrokerId()); - // TODO : Shoudl be configurable? InvocationResult result = _exchangeChannelForMethodInvocations.poll(5000,TimeUnit.MILLISECONDS); if (result == null) 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 index 4be48d1436..135acbd36d 100644 --- 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 @@ -150,7 +150,6 @@ class BrokerMessageListener implements MessageListener { 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)) { diff --git a/java/management/client/src/main/java/org/apache/qpid/management/domain/services/MessageTokenizer.java b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/MessageTokenizer.java index 623d74e737..1b5de9663e 100644 --- a/java/management/client/src/main/java/org/apache/qpid/management/domain/services/MessageTokenizer.java +++ b/java/management/client/src/main/java/org/apache/qpid/management/domain/services/MessageTokenizer.java @@ -52,13 +52,11 @@ class MessageTokenizer implements Enumeration<Message> build(compoundMessage);
}
- @Override
public boolean hasMoreElements()
{
return _iterator.hasNext();
}
- @Override
public Message nextElement()
{
return _iterator.next();
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 index 81434c14fb..600b54a6c9 100644 --- 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 @@ -28,12 +28,24 @@ import java.util.List; import java.util.UUID; import java.util.Map.Entry; +import javax.management.Attribute; +import javax.management.AttributeList; +import javax.management.DynamicMBean; +import javax.management.MBeanException; +import javax.management.MBeanInfo; +import javax.management.MBeanOperationInfo; +import javax.management.MBeanParameterInfo; +import javax.management.ReflectionException; + import org.apache.log4j.xml.DOMConfigurator; import org.apache.qpid.management.Messages; +import org.apache.qpid.management.Names; +import org.apache.qpid.management.configuration.BrokerAlreadyConnectedException; import org.apache.qpid.management.configuration.BrokerConnectionData; +import org.apache.qpid.management.configuration.BrokerConnectionException; import org.apache.qpid.management.configuration.Configuration; -import org.apache.qpid.management.configuration.ConfigurationException; import org.apache.qpid.management.configuration.Configurator; +import org.apache.qpid.management.domain.model.JmxService; import org.apache.qpid.transport.util.Logger; /** @@ -41,11 +53,11 @@ import org.apache.qpid.transport.util.Logger; * * @author Andrea Gazzarini */ -public class QMan +public class QMan implements DynamicMBean { private final static Logger LOGGER = Logger.get(QMan.class); private final List<ManagementClient> managementClients = new ArrayList<ManagementClient>(); - + /** * Starts QMan. * @throws StartupFailureException when it's not possible to proceed with startup. @@ -59,45 +71,92 @@ public class QMan try { configurator.configure(); - LOGGER.info(Messages.QMAN_000003_CREATING_MANAGEMENT_CLIENTS); - for (Entry<UUID, BrokerConnectionData> entry : Configuration.getInstance().getConnectionInfos()) + Configuration configuration = Configuration.getInstance(); + if (configuration.hasOneOrMoreBrokersDefined()) { - UUID brokerId = entry.getKey(); - BrokerConnectionData data = entry.getValue(); - try - { - ManagementClient client = new ManagementClient(brokerId,data); - managementClients.add(client); - client.estabilishFirstConnectionWithBroker(); - - LOGGER.info(Messages.QMAN_000004_MANAGEMENT_CLIENT_CONNECTED,brokerId); - } catch(StartupFailureException exception) { - LOGGER.error(exception, Messages.QMAN_100017_UNABLE_TO_CONNECT,brokerId,data); - } + LOGGER.info(Messages.QMAN_000003_CREATING_MANAGEMENT_CLIENTS); + for (Entry<UUID, BrokerConnectionData> entry : Configuration.getInstance().getConnectionInfos()) + { + createManagementClient(entry.getKey(), entry.getValue()); + } + } else + { + LOGGER.info(Messages.QMAN_000022_NO_BROKER_CONFIGURED); } + + registerQManService(); + LOGGER.info(Messages.QMAN_000019_QMAN_STARTED); - } catch(ConfigurationException exception) { - LOGGER.error(exception,Messages.UNABLE_TO_STARTUP_CORRECTLY); + } catch(Exception exception) { + LOGGER.error(exception,Messages.QMAN_100018_UNABLE_TO_STARTUP_CORRECTLY ); throw new StartupFailureException(exception); } } - /** - * Compose method used for adding a "graceful" shutdown hook. + /** + * Creates a management client using the given data. + * + * @param brokerId the broker identifier. + * @param data the broker connection data. */ - private void addShutDownHook() + private void createManagementClient(UUID brokerId, BrokerConnectionData data) { - // SHUTDOWN HOOK - Runtime.getRuntime().addShutdownHook(new Thread() + try { - @Override - public void run () - { - QMan.this.stop(); - } - }); + ManagementClient client = new ManagementClient(brokerId,data); + client.estabilishFirstConnectionWithBroker(); + managementClients.add(client); + + LOGGER.info(Messages.QMAN_000004_MANAGEMENT_CLIENT_CONNECTED,brokerId); + } catch(StartupFailureException exception) { + LOGGER.error(exception, Messages.QMAN_100017_UNABLE_TO_CONNECT,brokerId,data); + } } + /** + * Connects Q-Man with a broker defined by the given parameter. + * + * @param host the hostname where the broker is running. + * @param port the port where the broker is running. + * @param username the username for connecting with the broker. + * @param password the password for connecting with the broker. + * @param virtualHost the virtual host. + * @param initialPoolCapacity the number of the connection that must be immediately opened. + * @param maxPoolCapacity the maximum number of opened connection. + * @param maxWaitTimeout the maximum amount of time that a client will wait for obtaining a connection. + * @throws MBeanException when it's not possible to connect with the broker. + */ + public void addBroker( + String host, + int port, + String username, + String password, + String virtualHost, + int initialPoolCapacity, + int maxPoolCapacity, + long maxWaitTimeout) throws BrokerAlreadyConnectedException, BrokerConnectionException + { + Configurator configurator = new Configurator(); + try { + UUID brokerId = UUID.randomUUID(); + BrokerConnectionData data = configurator.createAndReturnBrokerConnectionData( + brokerId, + host, + port, + username, + password, + virtualHost, + initialPoolCapacity, + maxPoolCapacity, + maxWaitTimeout); + createManagementClient(brokerId, data); + } catch (BrokerAlreadyConnectedException exception) + { + LOGGER.warn(Messages.QMAN_300003_BROKER_ALREADY_CONNECTED, exception.getBrokerConnectionData()); + throw exception; + } + } + /** * Stop Qman */ @@ -129,27 +188,178 @@ public class QMan DOMConfigurator.configureAndWatch(logFileName,5000); } - QMan qman = new QMan(); - qman.addShutDownHook(); + final QMan qman = new QMan(); + + Thread hook = new Thread() + { + @Override + public void run () + { + qman.stop(); + } + }; + + Runtime.getRuntime().addShutdownHook(hook); try { qman.start(); - // TODO : console enhancement (i.e. : connect another broker) - System.out.println("Type \"q\" to quit."); + System.out.println("Type \"q\" to quit."); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while ( !"q".equals(reader.readLine()) ) { } + Runtime.getRuntime().removeShutdownHook(hook); + qman.stop(); System.exit(-1); } catch (StartupFailureException exception) { - exception.printStackTrace(); + qman.stop(); System.exit(-1); } catch (IOException exception) { System.exit(-1); } } + + /** + * Not implemented for this MBean. + */ + public Object getAttribute(String attribute) + { + return null; + } + + /** + * Not implemented for this MBean. + */ + public AttributeList getAttributes(String[] attributes) + { + return null; + } + + /** + * Returns the metadata for this MBean + * + * @return the metadata for this MBean + */ + public MBeanInfo getMBeanInfo() + { + MBeanParameterInfo parameters [] = new MBeanParameterInfo[8]; + + parameters[0] = new MBeanParameterInfo( + "host", + String.class.getName(), + "The IP address or DNS name that Qpid Broker uses to listen for incoming connections."); + parameters[1] = new MBeanParameterInfo( + "port", + int.class.getName(), + "The port number that Qpid Broker uses to listen for incoming connections."); + parameters[2] = new MBeanParameterInfo( + "username", + String.class.getName(), + "The Qpid account name used in the physical connection."); + parameters[3] = new MBeanParameterInfo( + "password", + String.class.getName(), + "The Qpid account password used in the physical connection."); + parameters[4]= new MBeanParameterInfo( + "virtualHost", + String.class.getName(), + "The virtualHost name."); + parameters[5]= new MBeanParameterInfo( + "initialPoolCapacity", + int.class.getName(), + "The number of physical connections (between 0 and a positive 32-bit integer) to create when creating the (Qpid) connection pool."); + parameters[6]= new MBeanParameterInfo( + "maxPoolCapacity", + int.class.getName(), + "The maximum number of physical database connections (between 0 and a positive 32-bit integer) that the (Qpid) connection pool can contain. "); + parameters[7]= new MBeanParameterInfo( + "maxWaitTimeout", + long.class.getName(), + "The maximum amount of time to wait for an idle connection.A value of -1 indicates an illimted amount of time (i.e. forever)"); + + MBeanOperationInfo operation = new MBeanOperationInfo( + "addBroker", + "Connects QMan with a broker.", + parameters, + void.class.getName(), + MBeanOperationInfo.ACTION); + + MBeanInfo mbean = new MBeanInfo( + QMan.class.getName(), + "QMan Management & Administration interface.", + null, + null, + new MBeanOperationInfo[]{operation}, + null); + + return mbean; + } + + /** + * Invokes an operation on QMan (MBean). + * + * @param actionName the operation name. + * @param params the operation parameters. + * @param signature the operation signature. + * @return the result of the invocation (if the operation is not void); + * @exception MBeanException Wraps a <CODE>java.lang.Exception</CODE> thrown by the MBean's invoked method. + * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE> thrown while trying to invoke the method + */ + public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException + { + if (Names.ADD_BROKER_OPERATION_NAME.equals(actionName)) + { + try + { + addBroker( + (String)params[0], + (Integer)params[1], + (String)params[2], + (String)params[3], + (String)params[4], + (Integer)params[5], + (Integer)params[6], + (Long)params[7]); + } catch(Exception exception) + { + throw new MBeanException(exception); + } + } else + { + throw new ReflectionException(new NoSuchMethodException(actionName)); + } + return null; + } + + /** + * Not implemented for this MBean. + */ + public void setAttribute(Attribute attribute) + { + } + + /** + * Not implemented for this MBean. + */ + public AttributeList setAttributes(AttributeList attributes) + { + return null; + } + + /** + * Registers QMan as an MBean on MBeanServer. + * + * @throws MBeanException when it's not possible to proceeed with registration. + */ + private void registerQManService() throws MBeanException + { + JmxService service = new JmxService(); + service.registerQManService(this); + + LOGGER.info(Messages.QMAN_000023_QMAN_REGISTERED_AS_MBEAN); + } } diff --git a/java/management/client/src/main/java/org/apache/qpid/management/messages/MethodInvocationRequestMessage.java b/java/management/client/src/main/java/org/apache/qpid/management/messages/MethodInvocationRequestMessage.java index 3021e2f3d9..fad42b125c 100644 --- a/java/management/client/src/main/java/org/apache/qpid/management/messages/MethodInvocationRequestMessage.java +++ b/java/management/client/src/main/java/org/apache/qpid/management/messages/MethodInvocationRequestMessage.java @@ -21,6 +21,7 @@ package org.apache.qpid.management.messages; import org.apache.qpid.management.Messages; +import org.apache.qpid.management.Names; import org.apache.qpid.management.Protocol; import org.apache.qpid.management.configuration.Configuration; import org.apache.qpid.management.domain.model.QpidMethod; @@ -58,7 +59,7 @@ public abstract class MethodInvocationRequestMessage extends ManagementMessage _messageProperties = new MessageProperties(); _messageProperties.setReplyTo(replyTo); - String routingKey = String.format("agent.%s.%s", brokerId,bankId); + String routingKey = String.format(Names.AGENT_ROUTING_KEY_PREFIX+"%s.%s", brokerId,bankId); LOGGER.debug(Messages.QMAN_200032_COMMAND_MESSAGE_ROUTING_KEY, routingKey); 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 deleted file mode 100644 index 4c53c3d428..0000000000 --- a/java/management/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. - * - * <br>precondition : given code is a valid number. - * <br>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. - * - * <br>precondition : given code is an invalid number. - * <br>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. - * - * <br>precondition : given code is valid (i.e. RW, RC or RO). - * <br>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. - * - * <br>precondition : given code is an unknown code. - * <br>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 index c948db59bf..ca6ae846a8 100644 --- 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 @@ -57,11 +57,8 @@ public class ConfigurationTest extends TestCase */ public void testGetTypeOk() throws UnknownTypeCodeException { - TypeMapping mapping = new TypeMapping(); - mapping.setCode(String.valueOf(TestConstants.VALID_CODE)); - mapping.setType(Uint8.class.getName()); + TypeMapping mapping = new TypeMapping(TestConstants.VALID_CODE,new Uint8()); Configuration.getInstance().addTypeMapping(mapping); - Type type = Configuration.getInstance().getType(TestConstants.VALID_CODE); assertTrue(type instanceof Uint8); @@ -93,14 +90,10 @@ public class ConfigurationTest extends TestCase */ public void testGetAccessModeOk() throws UnknownAccessCodeException { - String accessModeAsString = "RW"; - - AccessModeMapping mapping = new AccessModeMapping(); - mapping.setCode(String.valueOf(TestConstants.VALID_CODE)); - mapping.setAccessMode(accessModeAsString); + AccessModeMapping mapping = new AccessModeMapping(TestConstants.VALID_CODE,AccessMode.RW); Configuration.getInstance().addAccessModeMapping(mapping); - AccessMode accessMode = Configuration.getInstance().getAccessMode(TestConstants.VALID_CODE); + assertSame(AccessMode.RW,accessMode); } @@ -234,4 +227,4 @@ public class ConfigurationTest extends TestCase 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 index 639fe224ec..6237f21cc9 100644 --- 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 @@ -20,10 +20,32 @@ */ package org.apache.qpid.management.configuration; -import org.xml.sax.SAXException; +import java.util.Map; +import java.util.UUID; import junit.framework.TestCase; +import org.apache.qpid.management.Names; +import org.apache.qpid.management.Protocol; +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.EventContentMessageHandler; +import org.apache.qpid.management.domain.handler.impl.HeartBeatIndicationMessageHandler; +import org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler; +import org.apache.qpid.management.domain.handler.impl.MethodResponseMessageHandler; +import org.apache.qpid.management.domain.handler.impl.SchemaResponseMessageHandler; +import org.apache.qpid.management.domain.model.AccessMode; +import org.apache.qpid.management.domain.model.type.AbsTime; +import org.apache.qpid.management.domain.model.type.DeltaTime; +import org.apache.qpid.management.domain.model.type.ObjectReference; +import org.apache.qpid.management.domain.model.type.Str16; +import org.apache.qpid.management.domain.model.type.Str8; +import org.apache.qpid.management.domain.model.type.Uint16; +import org.apache.qpid.management.domain.model.type.Uint32; +import org.apache.qpid.management.domain.model.type.Uint64; +import org.apache.qpid.management.domain.model.type.Uint8; +import org.xml.sax.SAXException; + /** * Test case for configurator. * @@ -32,40 +54,65 @@ import junit.framework.TestCase; */ public class ConfiguratorTest extends TestCase { - - /** - * Tests the execution of the configure() method when a inexistent configuration file is used. - * - * <br>precondition : the configuration file doesn't exist. - * <br>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. + * Tests the execution of the configure() method when no configuration file is given. * - * <br>precondition : the configuration file is null. - * <br>postcondition : an exception is thrown indicating the failure. + * <br>precondition : configuration file option is not set + * <br>postcondition : no exception is thrown, the configuration is holding no broker data and the predefined mappings are + * stored in configuration. */ - 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) { - - } - } + public void testConfigureOK_WithNoConfigurationFile() throws Exception + { + Configurator configurator = new Configurator(); + configurator.configure(); + Configuration configuration = Configuration.getInstance(); + + assertEquals(new Uint8(), configuration.getType(1)); + assertEquals(new Uint16(), configuration.getType(2)); + assertEquals(new Uint32(), configuration.getType(3)); + assertEquals(new Uint64(), configuration.getType(4)); + assertEquals(new Str8(), configuration.getType(6)); + assertEquals(new Str16(), configuration.getType(7)); + assertEquals(new AbsTime(), configuration.getType(8)); + assertEquals(new DeltaTime(), configuration.getType(9)); + assertEquals(new ObjectReference(), configuration.getType(10)); + assertEquals(new org.apache.qpid.management.domain.model.type.Boolean(), configuration.getType(11)); + assertEquals(new org.apache.qpid.management.domain.model.type.Uuid(), configuration.getType(14)); + assertEquals(new org.apache.qpid.management.domain.model.type.Map(), configuration.getType(15)); + + assertEquals(AccessMode.RC,configuration.getAccessMode(1)); + assertEquals(AccessMode.RW,configuration.getAccessMode(2)); + assertEquals(AccessMode.RO,configuration.getAccessMode(3)); + + Map<Character, IMessageHandler> managementHandlers = configuration.getManagementQueueHandlers(); + assertEquals(4,managementHandlers.size()); + assertEquals( + InstrumentationMessageHandler.class, + managementHandlers.get(Protocol.INSTRUMENTATION_CONTENT_RESPONSE_OPCODE).getClass()); + + assertEquals( + ConfigurationMessageHandler.class, + managementHandlers.get(Protocol.CONFIGURATION_CONTENT_RESPONSE_OPCDE).getClass()); + + assertEquals( + EventContentMessageHandler.class, + managementHandlers.get(Protocol.EVENT_CONTENT_RESPONSE_OPCDE).getClass()); + + assertEquals( + HeartBeatIndicationMessageHandler.class, + managementHandlers.get(Protocol.HEARTBEAT_INDICATION_RESPONSE_OPCODE).getClass()); + + Map<Character, IMessageHandler> methodReplyHandlers = configuration.getMethodReplyQueueHandlers(); + assertEquals(2, methodReplyHandlers.size()); + + assertEquals( + MethodResponseMessageHandler.class, + methodReplyHandlers.get(Protocol.OPERATION_INVOCATION_RESPONSE_OPCODE).getClass()); + + assertEquals( + SchemaResponseMessageHandler.class, + methodReplyHandlers.get(Protocol.SCHEMA_RESPONSE_OPCODE).getClass()); + } /** * Tests the changes of the configurator internal state while configuration file is parsed. @@ -77,30 +124,41 @@ public class ConfiguratorTest extends TestCase 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); } + /** - * Create a stub configurator which returns the given datafile path. + * It's not possibile to add twice the same broker connection data. + * Is so an exception must be thrown indicating that the given broker is already connected. * - * @param filename the configuration file to be injected. - * @return a configurator which returns the given datafile path. + * <br>precondition : the given data identifies an already connected broker. + * <br>postcondition : an exception is thrown indicating the failure. */ - private Configurator getConfiguratorWithDatafileInjected(final String filename) { - return new Configurator() - { - @Override - String getConfigurationFileName () - { - return filename; - } - }; + public void testAddTwoIdenticalBrokers() throws ConfigurationException, BrokerConnectionException + { + Configurator configurator = new Configurator(); + configurator.configure(); + + BrokerConnectionData data = new BrokerConnectionData("sofia.gazzax.com",5672,"virtualHost","user","pwd",1,4,-1); + + Configuration.getInstance()._brokerConnectionInfos.put(UUID.randomUUID(),data); + + try { + configurator.createAndReturnBrokerConnectionData( + UUID.randomUUID(), + data.getHost(), + data.getPort(), + "anotherUser", + "anotherPassword", + data.getVirtualHost(), + 33, + 12, + 1000); + fail("If a broker is added twice an exception must be thrown."); + } catch (BrokerAlreadyConnectedException expected) { + assertEquals(data,expected.getBrokerConnectionData()); + } } -}
\ 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 index 4c8885dbc8..af261024bd 100644 --- 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 @@ -25,9 +25,6 @@ import java.util.UUID; import junit.framework.TestCase; import org.apache.qpid.management.TestConstants; -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. @@ -37,25 +34,6 @@ import org.apache.qpid.management.domain.model.type.Uint8; public class MappingParsersTest extends TestCase { /** - * Tests the execution of the access mode mapping parser. - * - * <br>precondition: An access mode mapping is built by the parser; - * <br>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. * * <br>precondition: A broker connection datamapping is built by the parser; @@ -98,32 +76,4 @@ public class MappingParsersTest extends TestCase assertEquals(username,result.getUsername()); assertEquals(password,result.getPassword()); } - - /** - * Tests the execution of the type mapping parser. - * - * <br>precondition: two type mappings are built by the parser; - * <br>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 deleted file mode 100644 index 8bb4985a89..0000000000 --- a/java/management/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java +++ /dev/null @@ -1,65 +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", "RC"); - addAccessModeMapping("2", "RW"); - addAccessModeMapping("3", "RO"); - - 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 addTypeMapping(String code,String clazzName,String validatorClassName) - { - TypeMapping mapping = new TypeMapping(); - mapping.setCode(code); - mapping.setType(clazzName); - mapping.setValidatorClassName(validatorClassName); - 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 deleted file mode 100644 index bf44608c0e..0000000000 --- a/java/management/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. - * - * <br>precondition : given code is a valid number. - * <br>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. - * - * <br>precondition : given code is an invalid number. - * <br>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. - * - * <br>precondition : a valid class type is supplied. - * <br>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. - * - * <br>precondition : an invalid class type is supplied. - * <br>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. - * - * <br>precondition : an invalid class type is supplied (is not a Type). - * <br>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/model/BaseDomainModelTestCase.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java index 0c67811621..3ed9ed8a61 100644 --- 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 @@ -22,7 +22,7 @@ package org.apache.qpid.management.domain.model; import org.apache.qpid.management.configuration.Configurator; -import junit.framework.TestCase;; +import junit.framework.TestCase; /** * Layer supertype for all domain model related test cases. 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 index 43793e588a..3d3783eb04 100644 --- 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 @@ -28,9 +28,8 @@ import java.util.Map; import junit.framework.TestCase; -import org.apache.qpid.management.configuration.StubConfigurator; +import org.apache.qpid.management.configuration.Configurator; 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. @@ -42,23 +41,18 @@ public abstract class BaseQpidFeatureBuilderTestCase extends TestCase protected final static String NAME = "aName"; protected final static String DESCRIPTION = "A description."; - protected Integer _type; protected Map <String,Object> _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()); - + Configurator configurator = new Configurator(); + configurator.configure(); _featureDefinition = new HashMap<String, Object>(); _featureDefinition.put(name.name(),NAME); _featureDefinition.put(desc.name(), DESCRIPTION); @@ -99,4 +93,4 @@ public abstract class BaseQpidFeatureBuilderTestCase extends TestCase } -}
\ No newline at end of file +} diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java index fab35d4c59..ace8dc19bd 100644 --- a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java @@ -14,7 +14,7 @@ import junit.framework.TestCase; import org.apache.qpid.management.TestConstants; import org.apache.qpid.management.configuration.ConfigurationException; -import org.apache.qpid.management.configuration.StubConfigurator; +import org.apache.qpid.management.configuration.Configurator; import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject; import org.apache.qpid.management.domain.model.QpidClass.QpidManagedObject; @@ -31,7 +31,7 @@ public class QpidClassTest extends TestCase @Override protected void setUp () throws ConfigurationException { - StubConfigurator configurator = new StubConfigurator(); + Configurator configurator = new Configurator(); configurator.configure(); _package = new QpidPackage(TestConstants.QPID_PACKAGE_NAME,TestConstants.DOMAIN_MODEL); _class = new QpidClass(TestConstants.EXCHANGE_CLASS_NAME,TestConstants.HASH,_package); @@ -214,7 +214,7 @@ public class QpidClassTest extends TestCase assertEquals(TestConstants.SAMPLE_MAX_VALUE,property.getMaxValue()); assertEquals(Integer.MIN_VALUE,property.getMaxLength()); assertEquals(TestConstants.AGE_ATTRIBUTE_DESCRIPTION,property.getDescription()); - assertEquals(String.class,property.getJavaType()); + assertEquals(Short.class,property.getJavaType()); assertFalse(property.isOptional()); property = _class._properties.get(TestConstants.SURNAME_ATTRIBUTE_NAME); @@ -225,7 +225,7 @@ public class QpidClassTest extends TestCase assertEquals(Integer.MIN_VALUE,property.getMaxValue()); assertEquals(TestConstants.SAMPLE_MAX_VALUE,property.getMaxLength()); assertEquals(TestConstants.SURNAME_ATTRIBUTE_DESCRIPTION,property.getDescription()); - assertEquals(String.class,property.getJavaType()); + assertEquals(Short.class,property.getJavaType()); assertTrue(property.isOptional()); MBeanInfo mbeanInfo = _class._metadata; @@ -239,14 +239,14 @@ public class QpidClassTest extends TestCase assertEquals(TestConstants.AGE_ATTRIBUTE_DESCRIPTION,attribute.getDescription()); assertFalse(attribute.isWritable()); assertTrue(attribute.isReadable()); - assertEquals(String.class.getName(),attribute.getType()); + assertEquals(Short.class.getName(),attribute.getType()); attribute = attributes[1]; assertEquals(TestConstants.SURNAME_ATTRIBUTE_NAME,attribute.getName()); assertEquals(TestConstants.SURNAME_ATTRIBUTE_DESCRIPTION,attribute.getDescription()); assertFalse(attribute.isWritable()); assertTrue(attribute.isReadable()); - assertEquals(String.class.getName(),attribute.getType()); + assertEquals(Short.class.getName(),attribute.getType()); } /** diff --git a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidEventTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidEventTest.java index 8a8adee294..954a419787 100644 --- a/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidEventTest.java +++ b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidEventTest.java @@ -35,7 +35,7 @@ import junit.framework.TestCase; import org.apache.qpid.management.TestConstants;
import org.apache.qpid.management.configuration.ConfigurationException;
-import org.apache.qpid.management.configuration.StubConfigurator;
+import org.apache.qpid.management.configuration.Configurator;
import org.apache.qpid.management.domain.model.QpidEvent.QpidManagedEvent;
/**
@@ -142,7 +142,7 @@ public class QpidEventTest extends TestCase }
};
- StubConfigurator configurator = new StubConfigurator();
+ Configurator configurator = new Configurator();
configurator.configure();
List<Map<String,Object>> arguments = new ArrayList<Map<String, Object>>();
@@ -168,14 +168,14 @@ public class QpidEventTest extends TestCase assertEquals(TestConstants.AGE_ATTRIBUTE_NAME,argument.getName());
assertEquals(AccessMode.RO,argument.getAccessMode());
assertEquals(TestConstants.AGE_ATTRIBUTE_DESCRIPTION,argument.getDescription());
- assertEquals(String.class,argument.getJavaType());
+ assertEquals(Short.class,argument.getJavaType());
assertFalse(argument.isOptional());
argument = _event._arguments.get(TestConstants.SURNAME_ATTRIBUTE_NAME);
assertEquals(TestConstants.SURNAME_ATTRIBUTE_NAME,argument.getName());
assertEquals(AccessMode.RO,argument.getAccessMode());
assertEquals(TestConstants.SURNAME_ATTRIBUTE_DESCRIPTION,argument.getDescription());
- assertEquals(String.class,argument.getJavaType());
+ assertEquals(Short.class,argument.getJavaType());
assertFalse(argument.isOptional());
assertEquals(1,_event._eventInstances.size());
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 index 53320e5c28..06dc35b0b1 100644 --- 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 @@ -56,19 +56,19 @@ public class QpidMethodBuilderTest extends BaseQpidFeatureBuilderTestCase Map<String,Object> arg1 = new HashMap<String,Object>(); arg1.put(name.name(), "arg1"); - arg1.put(type.name(),_type); + arg1.put(type.name(),1); arg1.put(dir.name(),Direction.I.name()); arg1.put(unit.name(), "bytes"); Map<String,Object> arg2 = new HashMap<String,Object>(); arg2.put(name.name(), "arg2"); - arg2.put(type.name(),_type); + arg2.put(type.name(),1); arg2.put(dir.name(),Direction.O.name()); arg2.put(unit.name(), "bytes"); Map<String,Object> arg3 = new HashMap<String,Object>(); arg3.put(name.name(), "arg3"); - arg3.put(type.name(),_type); + arg3.put(type.name(),1); arg3.put(dir.name(),Direction.IO.name()); arg3.put(unit.name(), "bytes"); @@ -144,4 +144,4 @@ public class QpidMethodBuilderTest extends BaseQpidFeatureBuilderTestCase assertEquals(method.getDescription(),info.getDescription()); assertEquals(method.getName(),info.getName()); } -}
\ 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 index 55a9403bc8..374011d150 100644 --- 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 @@ -22,8 +22,8 @@ package org.apache.qpid.management.domain.model; import junit.framework.TestCase; -import org.apache.qpid.management.configuration.StubConfigurator; -import org.apache.qpid.management.domain.model.type.Uint64; +import org.apache.qpid.management.configuration.Configurator; +import org.apache.qpid.management.domain.model.type.Uint8; public class QpidNumberPropertyTest extends TestCase { @@ -33,12 +33,12 @@ public class QpidNumberPropertyTest extends TestCase @Override protected void setUp () throws Exception { - StubConfigurator configurator = new StubConfigurator(); - configurator.addTypeMapping("1", Uint64.class.getName(),QpidProperty.NumberValidator.class.getName()); + Configurator configurator = new Configurator(); + configurator.configure(); _property = new QpidProperty(); _property.setName("average"); _property.setAccessMode(AccessMode.RW); - _property.setType(new Uint64()); + _property.setType(new Uint8()); } /** @@ -168,4 +168,4 @@ public class QpidNumberPropertyTest extends TestCase 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/QpidPropertyBuilderTest.java b/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidPropertyBuilderTest.java index 4ac399def0..8ad177645c 100644 --- 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 @@ -52,14 +52,12 @@ public class QpidPropertyBuilderTest extends BaseQpidFeatureBuilderTestCase 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(type.name(), 1); _featureDefinition.put(optional.name(),0); _featureDefinition.put(index.name(), 0); @@ -255,17 +253,17 @@ public class QpidPropertyBuilderTest extends BaseQpidFeatureBuilderTestCase MBeanAttributeInfo info = (MBeanAttributeInfo) _builder.getManagementFeature(); assertEquals(NAME,property.getName()); - assertEquals(AccessMode.RW,property.getAccessMode()); + assertEquals(AccessMode.RC,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()); + assertEquals(Short.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 index 7f4cf72895..b7a8540b2d 100644 --- 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 @@ -42,7 +42,7 @@ public class QpidStatisticBuilderTest extends BaseQpidFeatureBuilderTestCase { super.setUp(); _featureDefinition.put(unit.name(),UNIT); - _featureDefinition.put(type.name(), _type); + _featureDefinition.put(type.name(), 1); _builder = QpidFeatureBuilder.createStatisticBuilder(_featureDefinition); } @@ -150,10 +150,10 @@ public class QpidStatisticBuilderTest extends BaseQpidFeatureBuilderTestCase assertEquals(NAME,statistic.getName()); assertEquals(UNIT,statistic.getUnit()); assertEquals(DESCRIPTION,statistic.getDescription()); - assertEquals(Integer.class,statistic.getJavaType()); + assertEquals(Short.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 index 534a019503..8aeb7c8550 100644 --- 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 @@ -22,7 +22,7 @@ package org.apache.qpid.management.domain.model; import junit.framework.TestCase; -import org.apache.qpid.management.configuration.StubConfigurator; +import org.apache.qpid.management.configuration.Configurator; import org.apache.qpid.management.domain.model.type.Str16; public class QpidStringPropertyTest extends TestCase @@ -33,8 +33,8 @@ public class QpidStringPropertyTest extends TestCase @Override protected void setUp () throws Exception { - StubConfigurator configurator = new StubConfigurator(); - configurator.addTypeMapping("1", Str16.class.getName(),QpidProperty.StringValidator.class.getName()); + Configurator configurator = new Configurator(); + configurator.configure(); _property = new QpidProperty(); _property.setName("name"); _property.setAccessMode(AccessMode.RW); diff --git a/java/management/client/src/test/java/org/apache/qpid/management/online/TestMethodInvocation.java b/java/management/client/src/test/java/org/apache/qpid/management/online/TestMethodInvocation.java deleted file mode 100644 index dc4ab64503..0000000000 --- a/java/management/client/src/test/java/org/apache/qpid/management/online/TestMethodInvocation.java +++ /dev/null @@ -1,78 +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.online; - -import java.io.IOException; -import java.util.Set; - -import javax.management.InstanceNotFoundException; -import javax.management.MBeanException; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; -import javax.management.ReflectionException; - -import org.apache.qpid.management.domain.handler.impl.InvocationResult; - -public class TestMethodInvocation extends BaseOnlineTestCase -{ - /** - * Tests the execution of the purge() method on a queue instance. - * - * <br>precondition : QMan is up and running; managed domain model contains at least one queue. - * <br>postcondition : method is invoked and result object indicates that all was performed correctly. - */ - public void testInvokePurgeOnQueue() throws Exception - { - Set<ObjectName> names = connection.queryNames( - new ObjectName("Q-MAN:*,package=org.apache.qpid.broker,class=queue"),null); - - for (ObjectName objectName : names) - { - InvocationResult result = (InvocationResult) connection.invoke(objectName,"purge",new Object[]{0},new String[]{Integer.class.getName()}); - assertEquals(0,result.getReturnCode()); - assertEquals("OK",result.getStatusText()); - } - } - - /** - * Tests the execution of the invocation request with an unknown method. - * - * <br>precondition : QMan is up and running; managed domain model contains at least one queue. - * <br>postcondition An exception is thrown indicating that the method was not found. - */ - public void testInvokeWithUnknwonMethod() throws MalformedObjectNameException, NullPointerException, IOException, InstanceNotFoundException, MBeanException - { - Set<ObjectName> names = connection.queryNames(new ObjectName("Q-MAN:*,package=org.apache.qpid.broker,class=queue"),null); - System.out.println(names.size()); - - for (ObjectName objectName : names) - { - try - { - InvocationResult result = (InvocationResult) connection.invoke(objectName,"spurgexyzhopethatitwontexists",new Object[]{1},new String[]{Integer.class.getName()}); - } catch (ReflectionException expected) - { - NoSuchMethodException exception = (NoSuchMethodException) expected.getCause(); - assertEquals("spurge",exception.getMessage()); - } - } - } -}
\ No newline at end of file |