http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0189f156/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSServerControl.java ---------------------------------------------------------------------- diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSServerControl.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSServerControl.java deleted file mode 100644 index 8e93c6e..0000000 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSServerControl.java +++ /dev/null @@ -1,381 +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.activemq.artemis.api.jms.management; - -import javax.management.MBeanOperationInfo; - -import org.apache.activemq.artemis.api.core.management.Attribute; -import org.apache.activemq.artemis.api.core.management.Operation; -import org.apache.activemq.artemis.api.core.management.Parameter; - -/** - * A JMSSserverControl is used to manage ActiveMQ Artemis JMS server. - */ -public interface JMSServerControl { - // Attributes ---------------------------------------------------- - - /** - * Returns whether this server is started. - */ - @Attribute(desc = "whether this server is started") - boolean isStarted(); - - /** - * Returns this server's version - */ - @Attribute(desc = "server's version") - String getVersion(); - - /** - * Returns the names of the JMS topics available on this server. - */ - @Attribute(desc = "names of the JMS topics available on this server") - String[] getTopicNames(); - - /** - * Returns the names of the JMS queues available on this server. - */ - @Attribute(desc = "names of the JMS queues available on this server") - String[] getQueueNames(); - - /** - * Returns the names of the JMS connection factories available on this server. - */ - @Attribute(desc = "names of the JMS connection factories available on this server") - String[] getConnectionFactoryNames(); - - /** - * Returns the server's nodeId - */ - @Attribute(desc = "server's nodeId") - String getNodeID(); - - // Operations ---------------------------------------------------- - - /** - * Creates a durable JMS Queue. - * - * @return {@code true} if the queue was created, {@code false} else - */ - @Operation(desc = "Create a JMS Queue", impact = MBeanOperationInfo.ACTION) - boolean createQueue(@Parameter(name = "name", desc = "Name of the queue to create") String name) throws Exception; - - /** - * Creates a durable JMS Queue with the specified name and JNDI binding. - * - * @return {@code true} if the queue was created, {@code false} else - */ - @Operation(desc = "Create a JMS Queue", impact = MBeanOperationInfo.ACTION) - boolean createQueue(@Parameter(name = "name", desc = "Name of the queue to create") String name, - @Parameter(name = "jndiBindings", desc = "comma-separated list of JNDI bindings (use ',' if u need to use commas in your jndi name)") String jndiBindings) throws Exception; - - /** - * Creates a durable JMS Queue with the specified name, JNDI binding and selector. - * - * @return {@code true} if the queue was created, {@code false} else - */ - @Operation(desc = "Create a JMS Queue", impact = MBeanOperationInfo.ACTION) - boolean createQueue(@Parameter(name = "name", desc = "Name of the queue to create") String name, - @Parameter(name = "jndiBindings", desc = "comma-separated list of JNDI bindings (use ',' if u need to use commas in your jndi name)") String jndiBindings, - @Parameter(name = "selector", desc = "the jms selector") String selector) throws Exception; - - /** - * Creates a JMS Queue with the specified name, durability, selector and JNDI binding. - * - * @return {@code true} if the queue was created, {@code false} else - */ - @Operation(desc = "Create a JMS Queue", impact = MBeanOperationInfo.ACTION) - boolean createQueue(@Parameter(name = "name", desc = "Name of the queue to create") String name, - @Parameter(name = "jndiBindings", desc = "comma-separated list of JNDI bindings (use ',' if u need to use commas in your jndi name)") String jndiBindings, - @Parameter(name = "selector", desc = "the jms selector") String selector, - @Parameter(name = "durable", desc = "durability of the queue") boolean durable) throws Exception; - - /** - * Destroys a JMS Queue with the specified name. - * - * @return {@code true} if the queue was destroyed, {@code false} else - */ - @Operation(desc = "Destroy a JMS Queue", impact = MBeanOperationInfo.ACTION) - boolean destroyQueue(@Parameter(name = "name", desc = "Name of the queue to destroy") String name) throws Exception; - - /** - * Destroys a JMS Queue with the specified name. - * - * @return {@code true} if the queue was destroyed, {@code false} else - */ - @Operation(desc = "Destroy a JMS Queue", impact = MBeanOperationInfo.ACTION) - boolean destroyQueue(@Parameter(name = "name", desc = "Name of the queue to destroy") String name, - @Parameter(name = "removeConsumers", desc = "disconnect any consumers connected to this queue") boolean removeConsumers) throws Exception; - - /** - * Creates a JMS Topic. - * - * @return {@code true} if the topic was created, {@code false} else - */ - @Operation(desc = "Create a JMS Topic", impact = MBeanOperationInfo.ACTION) - boolean createTopic(@Parameter(name = "name", desc = "Name of the topic to create") String name) throws Exception; - - /** - * Creates a JMS Topic with the specified name and JNDI binding. - * - * @return {@code true} if the topic was created, {@code false} else - */ - @Operation(desc = "Create a JMS Topic", impact = MBeanOperationInfo.ACTION) - boolean createTopic(@Parameter(name = "name", desc = "Name of the topic to create") String name, - @Parameter(name = "jndiBindings", desc = "comma-separated list of JNDI bindings (use ',' if u need to use commas in your jndi name)") String jndiBindings) throws Exception; - - /** - * Destroys a JMS Topic with the specified name. - * - * @return {@code true} if the topic was destroyed, {@code false} else - */ - @Operation(desc = "Destroy a JMS Topic", impact = MBeanOperationInfo.ACTION) - boolean destroyTopic(@Parameter(name = "name", desc = "Name of the topic to destroy") String name, - @Parameter(name = "removeConsumers", desc = "disconnect any consumers connected to this queue") boolean removeConsumers) throws Exception; - - /** - * Destroys a JMS Topic with the specified name. - * - * @return {@code true} if the topic was destroyed, {@code false} else - */ - @Operation(desc = "Destroy a JMS Topic", impact = MBeanOperationInfo.ACTION) - boolean destroyTopic(@Parameter(name = "name", desc = "Name of the topic to destroy") String name) throws Exception; - - /** - * Create a JMS ConnectionFactory with the specified name connected to a static list of live-backup servers. - * <br> - * The ConnectionFactory is bound to JNDI for all the specified bindings Strings. - * <br> - * {@code liveConnectorsTransportClassNames} are the class names - * of the {@link org.apache.activemq.artemis.spi.core.remoting.ConnectorFactory} to connect to the live servers - * and {@code liveConnectorTransportParams} are Map<String, Object> for the corresponding {@link org.apache.activemq.artemis.api.core.TransportConfiguration}'s parameters. - */ - void createConnectionFactory(String name, - boolean ha, - boolean useDiscovery, - @Parameter(name = "cfType", desc = "RegularCF=0, QueueCF=1, TopicCF=2, XACF=3, QueueXACF=4, TopicXACF=5") int cfType, - String[] connectorNames, - Object[] bindings) throws Exception; - - /** - * Create a JMS ConnectionFactory with the specified name connected to a single live-backup pair of servers. - * <br> - * The ConnectionFactory is bound to JNDI for all the specified bindings Strings. - */ - @Operation(desc = "Create a JMS ConnectionFactory", impact = MBeanOperationInfo.ACTION) - void createConnectionFactory(@Parameter(name = "name") String name, - @Parameter(name = "ha") boolean ha, - @Parameter(name = "useDiscovery", desc = "should we use discovery or a connector configuration") boolean useDiscovery, - @Parameter(name = "cfType", desc = "RegularCF=0, QueueCF=1, TopicCF=2, XACF=3, QueueXACF=4, TopicXACF=5") int cfType, - @Parameter(name = "connectorNames", desc = "comma-separated list of connectorNames or the discovery group name") String connectors, - @Parameter(name = "jndiBindings", desc = "comma-separated list of JNDI bindings (use ',' if u need to use commas in your jndi name)") String jndiBindings) throws Exception; - - @Operation(desc = "Create a JMS ConnectionFactory", impact = MBeanOperationInfo.ACTION) - void createConnectionFactory(@Parameter(name = "name") String name, - @Parameter(name = "ha") boolean ha, - @Parameter(name = "useDiscovery", desc = "should we use discovery or a connector configuration") boolean useDiscovery, - @Parameter(name = "cfType", desc = "RegularCF=0, QueueCF=1, TopicCF=2, XACF=3, QueueXACF=4, TopicXACF=5") int cfType, - @Parameter(name = "connectorNames", desc = "An array of connector or the binding address") String[] connectors, - @Parameter(name = "jndiBindings", desc = "array JNDI bindings (use ',' if u need to use commas in your jndi name)") String[] jndiBindings, - @Parameter(name = "clientID", desc = "The clientID configured for the connectionFactory") String clientID, - @Parameter(name = "clientFailureCheckPeriod", desc = "clientFailureCheckPeriod") long clientFailureCheckPeriod, - @Parameter(name = "connectionTTL", desc = "connectionTTL") long connectionTTL, - @Parameter(name = "callTimeout", desc = "callTimeout") long callTimeout, - @Parameter(name = "callFailoverTimeout", desc = "callFailoverTimeout") long callFailoverTimeout, - @Parameter(name = "minLargeMessageSize", desc = "minLargeMessageSize") int minLargeMessageSize, - @Parameter(name = "compressLargeMessages", desc = "compressLargeMessages") boolean compressLargeMessages, - @Parameter(name = "consumerWindowSize", desc = "consumerWindowSize") int consumerWindowSize, - @Parameter(name = "consumerMaxRate", desc = "consumerMaxRate") int consumerMaxRate, - @Parameter(name = "confirmationWindowSize", desc = "confirmationWindowSize") int confirmationWindowSize, - @Parameter(name = "producerWindowSize", desc = "producerWindowSize") int producerWindowSize, - @Parameter(name = "producerMaxRate", desc = "producerMaxRate") int producerMaxRate, - @Parameter(name = "blockOnAcknowledge", desc = "blockOnAcknowledge") boolean blockOnAcknowledge, - @Parameter(name = "blockOnDurableSend", desc = "blockOnDurableSend") boolean blockOnDurableSend, - @Parameter(name = "blockOnNonDurableSend", desc = "blockOnNonDurableSend") boolean blockOnNonDurableSend, - @Parameter(name = "autoGroup", desc = "autoGroup") boolean autoGroup, - @Parameter(name = "preAcknowledge", desc = "preAcknowledge") boolean preAcknowledge, - @Parameter(name = "loadBalancingPolicyClassName", desc = "loadBalancingPolicyClassName (null or blank mean use the default value)") String loadBalancingPolicyClassName, - @Parameter(name = "transactionBatchSize", desc = "transactionBatchSize") int transactionBatchSize, - @Parameter(name = "dupsOKBatchSize", desc = "dupsOKBatchSize") int dupsOKBatchSize, - @Parameter(name = "useGlobalPools", desc = "useGlobalPools") boolean useGlobalPools, - @Parameter(name = "scheduledThreadPoolMaxSize", desc = "scheduledThreadPoolMaxSize") int scheduledThreadPoolMaxSize, - @Parameter(name = "threadPoolMaxSize", desc = "threadPoolMaxSize") int threadPoolMaxSize, - @Parameter(name = "retryInterval", desc = "retryInterval") long retryInterval, - @Parameter(name = "retryIntervalMultiplier", desc = "retryIntervalMultiplier") double retryIntervalMultiplier, - @Parameter(name = "maxRetryInterval", desc = "maxRetryInterval") long maxRetryInterval, - @Parameter(name = "reconnectAttempts", desc = "reconnectAttempts") int reconnectAttempts, - @Parameter(name = "failoverOnInitialConnection", desc = "failoverOnInitialConnection") boolean failoverOnInitialConnection, - @Parameter(name = "groupId", desc = "groupId") String groupId) throws Exception; - - @Operation(desc = "Create a JMS ConnectionFactory", impact = MBeanOperationInfo.ACTION) - void createConnectionFactory(@Parameter(name = "name") String name, - @Parameter(name = "ha") boolean ha, - @Parameter(name = "useDiscovery", desc = "should we use discovery or a connector configuration") boolean useDiscovery, - @Parameter(name = "cfType", desc = "RegularCF=0, QueueCF=1, TopicCF=2, XACF=3, QueueXACF=4, TopicXACF=5") int cfType, - @Parameter(name = "connectorNames", desc = "comma-separated list of connectorNames or the discovery group name") String connectors, - @Parameter(name = "jndiBindings", desc = "comma-separated list of JNDI bindings (use ',' if u need to use commas in your jndi name)") String jndiBindings, - @Parameter(name = "clientID", desc = "The clientID configured for the connectionFactory") String clientID, - @Parameter(name = "clientFailureCheckPeriod", desc = "clientFailureCheckPeriod") long clientFailureCheckPeriod, - @Parameter(name = "connectionTTL", desc = "connectionTTL") long connectionTTL, - @Parameter(name = "callTimeout", desc = "callTimeout") long callTimeout, - @Parameter(name = "callFailoverTimeout", desc = "callFailoverTimeout") long callFailoverTimeout, - @Parameter(name = "minLargeMessageSize", desc = "minLargeMessageSize") int minLargeMessageSize, - @Parameter(name = "compressLargeMessages", desc = "compressLargeMessages") boolean compressLargeMessages, - @Parameter(name = "consumerWindowSize", desc = "consumerWindowSize") int consumerWindowSize, - @Parameter(name = "consumerMaxRate", desc = "consumerMaxRate") int consumerMaxRate, - @Parameter(name = "confirmationWindowSize", desc = "confirmationWindowSize") int confirmationWindowSize, - @Parameter(name = "producerWindowSize", desc = "producerWindowSize") int producerWindowSize, - @Parameter(name = "producerMaxRate", desc = "producerMaxRate") int producerMaxRate, - @Parameter(name = "blockOnAcknowledge", desc = "blockOnAcknowledge") boolean blockOnAcknowledge, - @Parameter(name = "blockOnDurableSend", desc = "blockOnDurableSend") boolean blockOnDurableSend, - @Parameter(name = "blockOnNonDurableSend", desc = "blockOnNonDurableSend") boolean blockOnNonDurableSend, - @Parameter(name = "autoGroup", desc = "autoGroup") boolean autoGroup, - @Parameter(name = "preAcknowledge", desc = "preAcknowledge") boolean preAcknowledge, - @Parameter(name = "loadBalancingPolicyClassName", desc = "loadBalancingPolicyClassName (null or blank mean use the default value)") String loadBalancingPolicyClassName, - @Parameter(name = "transactionBatchSize", desc = "transactionBatchSize") int transactionBatchSize, - @Parameter(name = "dupsOKBatchSize", desc = "dupsOKBatchSize") int dupsOKBatchSize, - @Parameter(name = "useGlobalPools", desc = "useGlobalPools") boolean useGlobalPools, - @Parameter(name = "scheduledThreadPoolMaxSize", desc = "scheduledThreadPoolMaxSize") int scheduledThreadPoolMaxSize, - @Parameter(name = "threadPoolMaxSize", desc = "threadPoolMaxSize") int threadPoolMaxSize, - @Parameter(name = "retryInterval", desc = "retryInterval") long retryInterval, - @Parameter(name = "retryIntervalMultiplier", desc = "retryIntervalMultiplier") double retryIntervalMultiplier, - @Parameter(name = "maxRetryInterval", desc = "maxRetryInterval") long maxRetryInterval, - @Parameter(name = "reconnectAttempts", desc = "reconnectAttempts") int reconnectAttempts, - @Parameter(name = "failoverOnInitialConnection", desc = "failoverOnInitialConnection") boolean failoverOnInitialConnection, - @Parameter(name = "groupId", desc = "groupId") String groupId) throws Exception; - - @Operation(desc = "Destroy a JMS ConnectionFactory", impact = MBeanOperationInfo.ACTION) - void destroyConnectionFactory(@Parameter(name = "name", desc = "Name of the ConnectionFactory to destroy") String name) throws Exception; - - /** - * Lists the addresses of all the clients connected to this address. - */ - @Operation(desc = "List the client addresses", impact = MBeanOperationInfo.INFO) - String[] listRemoteAddresses() throws Exception; - - /** - * Lists the addresses of the clients connected to this address which matches the specified IP address. - */ - @Operation(desc = "List the client addresses which match the given IP Address", impact = MBeanOperationInfo.INFO) - String[] listRemoteAddresses(@Parameter(desc = "an IP address", name = "ipAddress") String ipAddress) throws Exception; - - /** - * Closes all the connections of clients connected to this server which matches the specified IP address. - */ - @Operation(desc = "Closes all the connections for the given IP Address", impact = MBeanOperationInfo.INFO) - boolean closeConnectionsForAddress(@Parameter(desc = "an IP address", name = "ipAddress") String ipAddress) throws Exception; - - /** - * Closes all the connections on this server for consumers which are consuming from a queue associated with a particular address. - */ - @Operation(desc = "Closes all the consumer connections for the given messaging address", impact = MBeanOperationInfo.INFO) - boolean closeConsumerConnectionsForAddress(@Parameter(desc = "a messaging address", name = "address") String address) throws Exception; - - /** - * Closes all the connections on this server for sessions using a particular user name. - */ - @Operation(desc = "Closes all the connections for session using a particular user name", impact = MBeanOperationInfo.INFO) - boolean closeConnectionsForUser(@Parameter(desc = "a user name", name = "userName") String address) throws Exception; - - /** - * Lists all the IDs of the connections connected to this server. - */ - @Operation(desc = "List all the connection IDs", impact = MBeanOperationInfo.INFO) - String[] listConnectionIDs() throws Exception; - - /** - * Lists all the connections connected to this server. - * The returned String is a JSON string containing an array of JMSConnectionInfo objects. - * - * @see JMSConnectionInfo#from(String) - */ - @Operation(desc = "List all JMS connections") - String listConnectionsAsJSON() throws Exception; - - /** - * Lists all the sessions IDs for the specified connection ID. - */ - @Operation(desc = "List the sessions for the given connectionID", impact = MBeanOperationInfo.INFO) - String[] listSessions(@Parameter(desc = "a connection ID", name = "connectionID") String connectionID) throws Exception; - - /** - * Lists all the consumers which belongs to the JMS Connection specified by the connectionID. - * The returned String is a JSON string containing an array of JMSConsumerInfo objects. - * - * @see JMSConsumerInfo#from(String) - */ - @Operation(desc = "List all JMS consumers associated with a JMS Connection") - String listConsumersAsJSON(@Parameter(desc = "a connection ID", name = "connectionID") String connectionID) throws Exception; - - /** - * Lists all the consumers - * The returned String is a JSON string containing an array of JMSConsumerInfo objects. - * - * @see JMSConsumerInfo#from(String) - */ - @Operation(desc = "List all JMS consumers associated with a JMS Connection") - String listAllConsumersAsJSON() throws Exception; - - /** - * Lists all addresses to which the designated server session has sent messages. - */ - @Operation(desc = "Lists all addresses to which the designated session has sent messages", impact = MBeanOperationInfo.INFO) - String[] listTargetDestinations(@Parameter(desc = "a session ID", name = "sessionID") String sessionID) throws Exception; - - /** - * Returns the last sent message's ID from the given session to an address. - */ - @Operation(desc = "Returns the last sent message's ID from the given session to an address", impact = MBeanOperationInfo.INFO) - String getLastSentMessageID(@Parameter(desc = "session name", name = "sessionID") String sessionID, - @Parameter(desc = "address", name = "address") String address) throws Exception; - - /** - * Gets the session's creation time. - */ - @Operation(desc = "Gets the sessions creation time", impact = MBeanOperationInfo.INFO) - String getSessionCreationTime(@Parameter(desc = "session name", name = "sessionID") String sessionID) throws Exception; - - /** - * Lists all the sessions IDs for the specified connection ID. - */ - @Operation(desc = "List the sessions for the given connectionID", impact = MBeanOperationInfo.INFO) - String listSessionsAsJSON(@Parameter(desc = "a connection ID", name = "connectionID") String connectionID) throws Exception; - - @Operation(desc = "List the Network Topology", impact = MBeanOperationInfo.INFO) - String listNetworkTopology() throws Exception; - - /** - * List all the prepared transaction, sorted by date, - * oldest first, with details, in text format - */ - @Operation(desc = "List all the prepared transaction, sorted by date, oldest first, with details, in JSON format", impact = MBeanOperationInfo.INFO) - String listPreparedTransactionDetailsAsJSON() throws Exception; - - /** - * List all the prepared transaction, sorted by date, - * oldest first, with details, in HTML format - */ - @Operation(desc = "List all the prepared transaction, sorted by date, oldest first, with details, in HTML format", impact = MBeanOperationInfo.INFO) - String listPreparedTransactionDetailsAsHTML() throws Exception; - - /** - * List all the prepared transaction, sorted by date, - * oldest first, with details, in HTML format - */ - @Operation(desc = "Will close any connection with the given connectionID", impact = MBeanOperationInfo.INFO) - String closeConnectionWithClientID(@Parameter(desc = "the clientID used to connect", name = "clientID") String clientID) throws Exception; -}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0189f156/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSSessionInfo.java ---------------------------------------------------------------------- diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSSessionInfo.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSSessionInfo.java deleted file mode 100644 index f09c5cd..0000000 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSSessionInfo.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.artemis.api.jms.management; - -import javax.json.JsonArray; -import javax.json.JsonObject; - -import org.apache.activemq.artemis.api.core.JsonUtil; - -public class JMSSessionInfo { - - private final String sessionID; - - private final long creationTime; - - public JMSSessionInfo(String sessionID, long creationTime) { - this.sessionID = sessionID; - this.creationTime = creationTime; - } - - public static JMSSessionInfo[] from(final String jsonString) { - JsonArray array = JsonUtil.readJsonArray(jsonString); - JMSSessionInfo[] infos = new JMSSessionInfo[array.size()]; - for (int i = 0; i < array.size(); i++) { - JsonObject obj = array.getJsonObject(i); - - JMSSessionInfo info = new JMSSessionInfo(obj.getString("sessionID"), obj.getJsonNumber("creationTime").longValue()); - infos[i] = info; - } - return infos; - } - - public String getSessionID() { - return sessionID; - } - - public long getCreationTime() { - return creationTime; - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0189f156/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/SubscriptionInfo.java ---------------------------------------------------------------------- diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/SubscriptionInfo.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/SubscriptionInfo.java deleted file mode 100644 index eee2667..0000000 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/SubscriptionInfo.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.artemis.api.jms.management; - -import javax.json.JsonArray; -import javax.json.JsonObject; - -import org.apache.activemq.artemis.api.core.JsonUtil; - -/** - * Helper class to create Java Objects from the - * JSON serialization returned by {@link TopicControl#listAllSubscriptionsAsJSON()} and related methods. - */ -public class SubscriptionInfo { - - private final String queueName; - - private final String clientID; - - private final String name; - - private final boolean durable; - - private final String selector; - - private final int messageCount; - - private final int deliveringCount; - - // Static -------------------------------------------------------- - - /** - * Returns an array of SubscriptionInfo corresponding to the JSON serialization returned - * by {@link TopicControl#listAllSubscriptionsAsJSON()} and related methods. - */ - public static SubscriptionInfo[] from(final String jsonString) throws Exception { - JsonArray array = JsonUtil.readJsonArray(jsonString); - SubscriptionInfo[] infos = new SubscriptionInfo[array.size()]; - for (int i = 0; i < array.size(); i++) { - JsonObject sub = array.getJsonObject(i); - SubscriptionInfo info = new SubscriptionInfo(sub.getString("queueName"), sub.getString("clientID", null), sub.getString("name", null), sub.getBoolean("durable"), sub.getString("selector", null), sub.getInt("messageCount"), sub.getInt("deliveringCount")); - infos[i] = info; - } - - return infos; - } - - // Constructors -------------------------------------------------- - - private SubscriptionInfo(final String queueName, - final String clientID, - final String name, - final boolean durable, - final String selector, - final int messageCount, - final int deliveringCount) { - this.queueName = queueName; - this.clientID = clientID; - this.name = name; - this.durable = durable; - this.selector = selector; - this.messageCount = messageCount; - this.deliveringCount = deliveringCount; - } - - // Public -------------------------------------------------------- - - /** - * Returns the name of the ActiveMQ Artemis core queue corresponding to this subscription. - */ - public String getQueueName() { - return queueName; - } - - /** - * Returns the client ID of this subscription or {@code null}. - */ - public String getClientID() { - return clientID; - } - - /** - * Returns the name of this subscription. - */ - public String getName() { - return name; - } - - /** - * Returns whether this subscription is durable. - */ - public boolean isDurable() { - return durable; - } - - /** - * Returns the JMS message selector associated to this subscription. - */ - public String getSelector() { - return selector; - } - - /** - * Returns the number of messages currently held by this subscription. - */ - public int getMessageCount() { - return messageCount; - } - - /** - * Returns the number of messages currently delivered to this subscription. - */ - public int getDeliveringCount() { - return deliveringCount; - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0189f156/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/TopicControl.java ---------------------------------------------------------------------- diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/TopicControl.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/TopicControl.java deleted file mode 100644 index 7e643f1..0000000 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/TopicControl.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.artemis.api.jms.management; - -import javax.management.MBeanOperationInfo; -import java.util.Map; - -import org.apache.activemq.artemis.api.core.management.Attribute; -import org.apache.activemq.artemis.api.core.management.Operation; -import org.apache.activemq.artemis.api.core.management.Parameter; - -/** - * A TopicControl is used to manage a JMS Topic. - */ -public interface TopicControl extends DestinationControl { - - /** - * Returns the number of (durable and non-durable) subscribers for this topic. - */ - @Attribute(desc = "number of (durable and non-durable) subscribers for this topic") - int getSubscriptionCount(); - - /** - * Returns the number of <em>durable</em> subscribers for this topic. - */ - @Attribute(desc = "number of durable subscribers for this topic") - int getDurableSubscriptionCount(); - - /** - * Returns the number of <em>non-durable</em> subscribers for this topic. - */ - @Attribute(desc = "number of non-durable subscribers for this topic") - int getNonDurableSubscriptionCount(); - - /** - * Returns the number of messages for all <em>durable</em> subscribers for this topic. - */ - @Attribute(desc = "number of messages for all durable subscribers for this topic") - int getDurableMessageCount(); - - /** - * Returns the number of messages for all <em>non-durable</em> subscribers for this topic. - */ - @Attribute(desc = "number of messages for all non-durable subscribers for this topic") - int getNonDurableMessageCount(); - - /** - * Returns the Registry bindings associated with this topic. - */ - @Attribute(desc = "the list of Registry bindings associated with this topic") - String[] getRegistryBindings(); - - /** - * Add the Registry binding to this destination - */ - @Operation(desc = "Adds the queue to another Registry binding") - void addBinding(@Parameter(name = "binding", desc = "the name of the binding for Registry") String binding) throws Exception; - - // Operations ---------------------------------------------------- - - /** - * Lists all the subscriptions for this topic (both durable and non-durable). - */ - @Operation(desc = "List all subscriptions") - Object[] listAllSubscriptions() throws Exception; - - /** - * Lists all the subscriptions for this topic (both durable and non-durable) using JSON serialization. - * <br> - * Java objects can be recreated from JSON serialization using {@link SubscriptionInfo#from(String)}. - */ - @Operation(desc = "List all subscriptions") - String listAllSubscriptionsAsJSON() throws Exception; - - /** - * Lists all the <em>durable</em> subscriptions for this topic. - */ - @Operation(desc = "List only the durable subscriptions") - Object[] listDurableSubscriptions() throws Exception; - - /** - * Lists all the <em>durable</em> subscriptions using JSON serialization. - * <br> - * Java objects can be recreated from JSON serialization using {@link SubscriptionInfo#from(String)}. - */ - @Operation(desc = "List only the durable subscriptions") - String listDurableSubscriptionsAsJSON() throws Exception; - - /** - * Lists all the <em>non-durable</em> subscriptions for this topic. - */ - @Operation(desc = "List only the non durable subscriptions") - Object[] listNonDurableSubscriptions() throws Exception; - - /** - * Lists all the <em>non-durable</em> subscriptions using JSON serialization. - * <br> - * Java objects can be recreated from JSON serialization using {@link SubscriptionInfo#from(String)}. - */ - @Operation(desc = "List only the non durable subscriptions") - String listNonDurableSubscriptionsAsJSON() throws Exception; - - /** - * Lists all the messages in this queue matching the specified queue representing the subscription. - * <br> - * 1 Map represents 1 message, keys are the message's properties and headers, values are the corresponding values. - */ - @Operation(desc = "List all the message for the given subscription") - Map<String, Object>[] listMessagesForSubscription(@Parameter(name = "queueName", desc = "the name of the queue representing a subscription") String queueName) throws Exception; - - /** - * Lists all the messages in this queue matching the specified queue representing the subscription using JSON serialization. - */ - @Operation(desc = "List all the message for the given subscription") - String listMessagesForSubscriptionAsJSON(@Parameter(name = "queueName", desc = "the name of the queue representing a subscription") String queueName) throws Exception; - - /** - * Counts the number of messages in the subscription specified by the specified client ID and subscription name. Only messages matching the filter will be counted. - * <br> - * Using {@code null} or an empty filter will count <em>all</em> messages from this queue. - */ - @Operation(desc = "Count the number of messages matching the filter for the given subscription") - int countMessagesForSubscription(@Parameter(name = "clientID", desc = "the client ID") String clientID, - @Parameter(name = "subscriptionName", desc = "the name of the durable subscription") String subscriptionName, - @Parameter(name = "filter", desc = "a JMS filter (can be empty)") String filter) throws Exception; - - /** - * Drops the subscription specified by the specified client ID and subscription name. - */ - @Operation(desc = "Drop a durable subscription", impact = MBeanOperationInfo.ACTION) - void dropDurableSubscription(@Parameter(name = "clientID", desc = "the client ID") String clientID, - @Parameter(name = "subscriptionName", desc = "the name of the durable subscription") String subscriptionName) throws Exception; - - /** - * Drops all subscriptions. - */ - @Operation(desc = "Drop all subscriptions from this topic", impact = MBeanOperationInfo.ACTION) - void dropAllSubscriptions() throws Exception; -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0189f156/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/management/impl/JMSConnectionFactoryControlImpl.java ---------------------------------------------------------------------- diff --git a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/management/impl/JMSConnectionFactoryControlImpl.java b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/management/impl/JMSConnectionFactoryControlImpl.java deleted file mode 100644 index 3175b9c..0000000 --- a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/management/impl/JMSConnectionFactoryControlImpl.java +++ /dev/null @@ -1,471 +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.activemq.artemis.jms.management.impl; - -import javax.management.MBeanInfo; -import javax.management.NotCompliantMBeanException; -import javax.management.StandardMBean; - -import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.artemis.api.core.TransportConfiguration; -import org.apache.activemq.artemis.api.core.management.Parameter; -import org.apache.activemq.artemis.api.jms.management.ConnectionFactoryControl; -import org.apache.activemq.artemis.core.management.impl.MBeanInfoHelper; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.activemq.artemis.jms.server.JMSServerManager; -import org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration; - -public class JMSConnectionFactoryControlImpl extends StandardMBean implements ConnectionFactoryControl { - // Constants ----------------------------------------------------- - - // Attributes ---------------------------------------------------- - - private final ConnectionFactoryConfiguration cfConfig; - - private ActiveMQConnectionFactory cf; - - private final String name; - - private final JMSServerManager jmsManager; - - // Static -------------------------------------------------------- - - // Constructors -------------------------------------------------- - - public JMSConnectionFactoryControlImpl(final ConnectionFactoryConfiguration cfConfig, - final ActiveMQConnectionFactory cf, - final JMSServerManager jmsManager, - final String name) throws NotCompliantMBeanException { - super(ConnectionFactoryControl.class); - this.cfConfig = cfConfig; - this.cf = cf; - this.name = name; - this.jmsManager = jmsManager; - } - - // Public -------------------------------------------------------- - - // ManagedConnectionFactoryMBean implementation ------------------ - - @Override - public String[] getRegistryBindings() { - return jmsManager.getBindingsOnConnectionFactory(name); - } - - @Override - public boolean isCompressLargeMessages() { - return cf.isCompressLargeMessage(); - } - - @Override - public void setCompressLargeMessages(final boolean compress) { - cfConfig.setCompressLargeMessages(compress); - recreateCF(); - } - - @Override - public boolean isHA() { - return cfConfig.isHA(); - } - - @Override - public int getFactoryType() { - return cfConfig.getFactoryType().intValue(); - } - - @Override - public String getClientID() { - return cfConfig.getClientID(); - } - - @Override - public long getClientFailureCheckPeriod() { - return cfConfig.getClientFailureCheckPeriod(); - } - - @Override - public void setClientID(String clientID) { - cfConfig.setClientID(clientID); - recreateCF(); - } - - @Override - public void setDupsOKBatchSize(int dupsOKBatchSize) { - cfConfig.setDupsOKBatchSize(dupsOKBatchSize); - recreateCF(); - } - - @Override - public void setTransactionBatchSize(int transactionBatchSize) { - cfConfig.setTransactionBatchSize(transactionBatchSize); - recreateCF(); - } - - @Override - public void setClientFailureCheckPeriod(long clientFailureCheckPeriod) { - cfConfig.setClientFailureCheckPeriod(clientFailureCheckPeriod); - recreateCF(); - } - - @Override - public void setConnectionTTL(long connectionTTL) { - cfConfig.setConnectionTTL(connectionTTL); - recreateCF(); - } - - @Override - public void setCallTimeout(long callTimeout) { - cfConfig.setCallTimeout(callTimeout); - recreateCF(); - } - - @Override - public void setCallFailoverTimeout(long callTimeout) { - cfConfig.setCallFailoverTimeout(callTimeout); - recreateCF(); - } - - @Override - public void setConsumerWindowSize(int consumerWindowSize) { - cfConfig.setConsumerWindowSize(consumerWindowSize); - recreateCF(); - } - - @Override - public void setConsumerMaxRate(int consumerMaxRate) { - cfConfig.setConsumerMaxRate(consumerMaxRate); - recreateCF(); - } - - @Override - public void setConfirmationWindowSize(int confirmationWindowSize) { - cfConfig.setConfirmationWindowSize(confirmationWindowSize); - recreateCF(); - } - - @Override - public void setProducerMaxRate(int producerMaxRate) { - cfConfig.setProducerMaxRate(producerMaxRate); - recreateCF(); - } - - @Override - public int getProducerWindowSize() { - return cfConfig.getProducerWindowSize(); - } - - @Override - public void setProducerWindowSize(int producerWindowSize) { - cfConfig.setProducerWindowSize(producerWindowSize); - recreateCF(); - } - - @Override - public void setCacheLargeMessagesClient(boolean cacheLargeMessagesClient) { - cfConfig.setCacheLargeMessagesClient(cacheLargeMessagesClient); - recreateCF(); - } - - @Override - public boolean isCacheLargeMessagesClient() { - return cfConfig.isCacheLargeMessagesClient(); - } - - @Override - public void setMinLargeMessageSize(int minLargeMessageSize) { - cfConfig.setMinLargeMessageSize(minLargeMessageSize); - recreateCF(); - } - - @Override - public void setBlockOnNonDurableSend(boolean blockOnNonDurableSend) { - cfConfig.setBlockOnNonDurableSend(blockOnNonDurableSend); - recreateCF(); - } - - @Override - public void setBlockOnAcknowledge(boolean blockOnAcknowledge) { - cfConfig.setBlockOnAcknowledge(blockOnAcknowledge); - recreateCF(); - } - - @Override - public void setBlockOnDurableSend(boolean blockOnDurableSend) { - cfConfig.setBlockOnDurableSend(blockOnDurableSend); - recreateCF(); - } - - @Override - public void setAutoGroup(boolean autoGroup) { - cfConfig.setAutoGroup(autoGroup); - recreateCF(); - } - - @Override - public void setPreAcknowledge(boolean preAcknowledge) { - cfConfig.setPreAcknowledge(preAcknowledge); - recreateCF(); - } - - @Override - public void setMaxRetryInterval(long retryInterval) { - cfConfig.setMaxRetryInterval(retryInterval); - recreateCF(); - } - - @Override - public void setRetryIntervalMultiplier(double retryIntervalMultiplier) { - cfConfig.setRetryIntervalMultiplier(retryIntervalMultiplier); - recreateCF(); - } - - @Override - public void setReconnectAttempts(int reconnectAttempts) { - cfConfig.setReconnectAttempts(reconnectAttempts); - recreateCF(); - } - - @Override - public void setFailoverOnInitialConnection(boolean failover) { - cfConfig.setFailoverOnInitialConnection(failover); - recreateCF(); - } - - @Override - public boolean isUseGlobalPools() { - return cfConfig.isUseGlobalPools(); - } - - @Override - public void setScheduledThreadPoolMaxSize(int scheduledThreadPoolMaxSize) { - cfConfig.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize); - recreateCF(); - } - - @Override - public int getThreadPoolMaxSize() { - return cfConfig.getThreadPoolMaxSize(); - } - - @Override - public void setThreadPoolMaxSize(int threadPoolMaxSize) { - cfConfig.setThreadPoolMaxSize(threadPoolMaxSize); - recreateCF(); - } - - @Override - public int getInitialMessagePacketSize() { - return cf.getInitialMessagePacketSize(); - } - - @Override - public void setGroupID(String groupID) { - cfConfig.setGroupID(groupID); - recreateCF(); - } - - @Override - public String getGroupID() { - return cfConfig.getGroupID(); - } - - @Override - public void setUseGlobalPools(boolean useGlobalPools) { - cfConfig.setUseGlobalPools(useGlobalPools); - recreateCF(); - } - - @Override - public int getScheduledThreadPoolMaxSize() { - return cfConfig.getScheduledThreadPoolMaxSize(); - } - - @Override - public void setRetryInterval(long retryInterval) { - cfConfig.setRetryInterval(retryInterval); - recreateCF(); - } - - @Override - public long getMaxRetryInterval() { - return cfConfig.getMaxRetryInterval(); - } - - @Override - public String getConnectionLoadBalancingPolicyClassName() { - return cfConfig.getLoadBalancingPolicyClassName(); - } - - @Override - public void setConnectionLoadBalancingPolicyClassName(String name) { - cfConfig.setLoadBalancingPolicyClassName(name); - recreateCF(); - } - - @Override - public TransportConfiguration[] getStaticConnectors() { - return cf.getStaticConnectors(); - } - - @Override - public DiscoveryGroupConfiguration getDiscoveryGroupConfiguration() { - return cf.getDiscoveryGroupConfiguration(); - } - - @Override - public void addBinding(@Parameter(name = "binding", desc = "the name of the binding for the Registry") String binding) throws Exception { - jmsManager.addConnectionFactoryToBindingRegistry(name, binding); - } - - @Override - public void removeBinding(@Parameter(name = "binding", desc = "the name of the binding for the Registry") String binding) throws Exception { - jmsManager.removeConnectionFactoryFromBindingRegistry(name, binding); - } - - @Override - public long getCallTimeout() { - return cfConfig.getCallTimeout(); - } - - @Override - public long getCallFailoverTimeout() { - return cfConfig.getCallFailoverTimeout(); - } - - @Override - public int getConsumerMaxRate() { - return cfConfig.getConsumerMaxRate(); - } - - @Override - public int getConsumerWindowSize() { - return cfConfig.getConsumerWindowSize(); - } - - @Override - public int getProducerMaxRate() { - return cfConfig.getProducerMaxRate(); - } - - @Override - public int getConfirmationWindowSize() { - return cfConfig.getConfirmationWindowSize(); - } - - @Override - public int getDupsOKBatchSize() { - return cfConfig.getDupsOKBatchSize(); - } - - @Override - public boolean isBlockOnAcknowledge() { - return cfConfig.isBlockOnAcknowledge(); - } - - @Override - public boolean isBlockOnNonDurableSend() { - return cfConfig.isBlockOnNonDurableSend(); - } - - @Override - public boolean isBlockOnDurableSend() { - return cfConfig.isBlockOnDurableSend(); - } - - @Override - public boolean isPreAcknowledge() { - return cfConfig.isPreAcknowledge(); - } - - @Override - public String getName() { - return name; - } - - @Override - public long getConnectionTTL() { - return cfConfig.getConnectionTTL(); - } - - @Override - public int getReconnectAttempts() { - return cfConfig.getReconnectAttempts(); - } - - @Override - public boolean isFailoverOnInitialConnection() { - return cfConfig.isFailoverOnInitialConnection(); - } - - @Override - public int getMinLargeMessageSize() { - return cfConfig.getMinLargeMessageSize(); - } - - @Override - public long getRetryInterval() { - return cfConfig.getRetryInterval(); - } - - @Override - public double getRetryIntervalMultiplier() { - return cfConfig.getRetryIntervalMultiplier(); - } - - @Override - public int getTransactionBatchSize() { - return cfConfig.getTransactionBatchSize(); - } - - @Override - public void setProtocolManagerFactoryStr(String protocolManagerFactoryStr) { - cfConfig.setProtocolManagerFactoryStr(protocolManagerFactoryStr); - recreateCF(); - } - - @Override - public String getProtocolManagerFactoryStr() { - return cfConfig.getProtocolManagerFactoryStr(); - } - - @Override - public boolean isAutoGroup() { - return cfConfig.isAutoGroup(); - } - - @Override - public MBeanInfo getMBeanInfo() { - MBeanInfo info = super.getMBeanInfo(); - return new MBeanInfo(info.getClassName(), info.getDescription(), info.getAttributes(), info.getConstructors(), MBeanInfoHelper.getMBeanOperationsInfo(ConnectionFactoryControl.class), info.getNotifications()); - } - - // Package protected --------------------------------------------- - - // Protected ----------------------------------------------------- - - private void recreateCF() { - try { - this.cf = jmsManager.recreateCF(this.name, this.cfConfig); - } catch (Exception e) { - throw new RuntimeException(e.getMessage(), e); - } - } - - // Private ------------------------------------------------------- - - // Inner classes ------------------------------------------------- -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0189f156/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/management/impl/JMSQueueControlImpl.java ---------------------------------------------------------------------- diff --git a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/management/impl/JMSQueueControlImpl.java b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/management/impl/JMSQueueControlImpl.java deleted file mode 100644 index 36cba96..0000000 --- a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/management/impl/JMSQueueControlImpl.java +++ /dev/null @@ -1,532 +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.activemq.artemis.jms.management.impl; - -import javax.jms.InvalidSelectorException; -import javax.json.JsonArrayBuilder; -import javax.management.MBeanInfo; -import javax.management.StandardMBean; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.CompositeDataSupport; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.activemq.artemis.api.core.ActiveMQBuffer; -import org.apache.activemq.artemis.api.core.ActiveMQBuffers; -import org.apache.activemq.artemis.api.core.ActiveMQException; -import org.apache.activemq.artemis.api.core.ActiveMQInvalidFilterExpressionException; -import org.apache.activemq.artemis.api.core.FilterConstants; -import org.apache.activemq.artemis.api.core.JsonUtil; -import org.apache.activemq.artemis.api.core.Message; -import org.apache.activemq.artemis.api.core.SimpleString; -import org.apache.activemq.artemis.api.core.management.MessageCounterInfo; -import org.apache.activemq.artemis.api.core.management.Operation; -import org.apache.activemq.artemis.api.core.management.QueueControl; -import org.apache.activemq.artemis.api.jms.management.JMSQueueControl; -import org.apache.activemq.artemis.core.management.impl.MBeanInfoHelper; -import org.apache.activemq.artemis.core.messagecounter.MessageCounter; -import org.apache.activemq.artemis.core.messagecounter.impl.MessageCounterHelper; -import org.apache.activemq.artemis.jms.client.ActiveMQDestination; -import org.apache.activemq.artemis.jms.client.ActiveMQMessage; -import org.apache.activemq.artemis.jms.management.impl.openmbean.JMSOpenTypeSupport; -import org.apache.activemq.artemis.jms.server.JMSServerManager; -import org.apache.activemq.artemis.utils.Base64; -import org.apache.activemq.artemis.utils.JsonLoader; -import org.apache.activemq.artemis.utils.SelectorTranslator; -import org.apache.activemq.artemis.utils.UUIDGenerator; - -public class JMSQueueControlImpl extends StandardMBean implements JMSQueueControl { - - private final ActiveMQDestination managedQueue; - - private final JMSServerManager jmsServerManager; - - private final QueueControl coreQueueControl; - - private final MessageCounter counter; - - // Static -------------------------------------------------------- - - /** - * Returns null if the string is null or empty - */ - public static String createFilterFromJMSSelector(final String selectorStr) throws ActiveMQException { - return selectorStr == null || selectorStr.trim().length() == 0 ? null : SelectorTranslator.convertToActiveMQFilterString(selectorStr); - } - - private static String createFilterForJMSMessageID(final String jmsMessageID) throws Exception { - return FilterConstants.ACTIVEMQ_USERID + " = '" + jmsMessageID + "'"; - } - - static String toJSON(final Map<String, Object>[] messages) { - JsonArrayBuilder array = JsonLoader.createArrayBuilder(); - for (Map<String, Object> message : messages) { - array.add(JsonUtil.toJsonObject(message)); - } - return array.build().toString(); - } - - // Constructors -------------------------------------------------- - - public JMSQueueControlImpl(final ActiveMQDestination managedQueue, - final QueueControl coreQueueControl, - final JMSServerManager jmsServerManager, - final MessageCounter counter) throws Exception { - super(JMSQueueControl.class); - this.managedQueue = managedQueue; - this.jmsServerManager = jmsServerManager; - this.coreQueueControl = coreQueueControl; - this.counter = counter; - } - - // Public -------------------------------------------------------- - - // ManagedJMSQueueMBean implementation --------------------------- - - @Override - public String getName() { - return managedQueue.getName(); - } - - @Override - public String getAddress() { - return managedQueue.getAddress(); - } - - @Override - public boolean isTemporary() { - return managedQueue.isTemporary(); - } - - @Override - public long getMessageCount() { - return coreQueueControl.getMessageCount(); - } - - @Override - public long getMessagesAdded() { - return coreQueueControl.getMessagesAdded(); - } - - @Override - public long getMessagesExpired() { - return coreQueueControl.getMessagesExpired(); - } - - @Override - public long getMessagesKilled() { - return coreQueueControl.getMessagesKilled(); - } - - @Override - public int getConsumerCount() { - return coreQueueControl.getConsumerCount(); - } - - @Override - public int getDeliveringCount() { - return coreQueueControl.getDeliveringCount(); - } - - @Override - public long getScheduledCount() { - return coreQueueControl.getScheduledCount(); - } - - public boolean isDurable() { - return coreQueueControl.isDurable(); - } - - @Override - public String getDeadLetterAddress() { - return coreQueueControl.getDeadLetterAddress(); - } - - @Override - public String getExpiryAddress() { - return coreQueueControl.getExpiryAddress(); - } - - @Override - public String getFirstMessageAsJSON() throws Exception { - return coreQueueControl.getFirstMessageAsJSON(); - } - - @Override - public Long getFirstMessageTimestamp() throws Exception { - return coreQueueControl.getFirstMessageTimestamp(); - } - - @Override - public Long getFirstMessageAge() throws Exception { - return coreQueueControl.getFirstMessageAge(); - } - - @Override - public void addBinding(String binding) throws Exception { - jmsServerManager.addQueueToBindingRegistry(managedQueue.getName(), binding); - } - - @Override - public String[] getRegistryBindings() { - return jmsServerManager.getBindingsOnQueue(managedQueue.getName()); - } - - @Override - public boolean removeMessage(final String messageID) throws Exception { - String filter = JMSQueueControlImpl.createFilterForJMSMessageID(messageID); - int removed = coreQueueControl.removeMessages(filter); - if (removed != 1) { - throw new IllegalArgumentException("No message found for JMSMessageID: " + messageID); - } - return true; - } - - @Override - public int removeMessages(final String filterStr) throws Exception { - String filter = JMSQueueControlImpl.createFilterFromJMSSelector(filterStr); - return coreQueueControl.removeMessages(filter); - } - - @Override - public Map<String, Object>[] listMessages(final String filterStr) throws Exception { - try { - String filter = JMSQueueControlImpl.createFilterFromJMSSelector(filterStr); - Map<String, Object>[] coreMessages = coreQueueControl.listMessages(filter); - - return toJMSMap(coreMessages); - } catch (ActiveMQException e) { - throw new IllegalStateException(e.getMessage()); - } - } - - private Map<String, Object>[] toJMSMap(Map<String, Object>[] coreMessages) { - Map<String, Object>[] jmsMessages = new Map[coreMessages.length]; - - int i = 0; - - for (Map<String, Object> coreMessage : coreMessages) { - Map<String, Object> jmsMessage = ActiveMQMessage.coreMaptoJMSMap(coreMessage); - jmsMessages[i++] = jmsMessage; - } - return jmsMessages; - } - - private CompositeData toJMSCompositeType(CompositeDataSupport data) throws Exception { - return JMSOpenTypeSupport.convert(data); - } - - @Override - public Map<String, Object>[] listScheduledMessages() throws Exception { - Map<String, Object>[] coreMessages = coreQueueControl.listScheduledMessages(); - - return toJMSMap(coreMessages); - } - - @Override - public String listScheduledMessagesAsJSON() throws Exception { - return coreQueueControl.listScheduledMessagesAsJSON(); - } - - @Override - public Map<String, Map<String, Object>[]> listDeliveringMessages() throws Exception { - try { - Map<String, Map<String, Object>[]> returnMap = new HashMap<>(); - - // the workingMap from the queue-control - Map<String, Map<String, Object>[]> workingMap = coreQueueControl.listDeliveringMessages(); - - for (Map.Entry<String, Map<String, Object>[]> entry : workingMap.entrySet()) { - returnMap.put(entry.getKey(), toJMSMap(entry.getValue())); - } - - return returnMap; - } catch (ActiveMQException e) { - throw new IllegalStateException(e.getMessage()); - } - } - - @Override - public String listDeliveringMessagesAsJSON() throws Exception { - return coreQueueControl.listDeliveringMessagesAsJSON(); - } - - @Override - public String listMessagesAsJSON(final String filter) throws Exception { - return JMSQueueControlImpl.toJSON(listMessages(filter)); - } - - @Override - public long countMessages(final String filterStr) throws Exception { - String filter = JMSQueueControlImpl.createFilterFromJMSSelector(filterStr); - return coreQueueControl.countMessages(filter); - } - - @Override - public boolean expireMessage(final String messageID) throws Exception { - String filter = JMSQueueControlImpl.createFilterForJMSMessageID(messageID); - int expired = coreQueueControl.expireMessages(filter); - if (expired != 1) { - throw new IllegalArgumentException("No message found for JMSMessageID: " + messageID); - } - return true; - } - - @Override - public int expireMessages(final String filterStr) throws Exception { - String filter = JMSQueueControlImpl.createFilterFromJMSSelector(filterStr); - return coreQueueControl.expireMessages(filter); - } - - @Override - public boolean sendMessageToDeadLetterAddress(final String messageID) throws Exception { - String filter = JMSQueueControlImpl.createFilterForJMSMessageID(messageID); - int dead = coreQueueControl.sendMessagesToDeadLetterAddress(filter); - if (dead != 1) { - throw new IllegalArgumentException("No message found for JMSMessageID: " + messageID); - } - return true; - } - - @Override - public int sendMessagesToDeadLetterAddress(final String filterStr) throws Exception { - String filter = JMSQueueControlImpl.createFilterFromJMSSelector(filterStr); - return coreQueueControl.sendMessagesToDeadLetterAddress(filter); - } - - @Override - public String sendTextMessageWithProperties(String properties) throws Exception { - String[] kvs = properties.split(","); - Map<String, String> props = new HashMap<>(); - for (String kv : kvs) { - String[] it = kv.split("="); - if (it.length == 2) { - props.put(it[0], it[1]); - } - } - return sendTextMessage(props, props.remove("body"), props.remove("username"), props.remove("password")); - } - - @Override - public String sendTextMessage(String body) throws Exception { - return sendTextMessage(Collections.EMPTY_MAP, body); - } - - @Override - public String sendTextMessage(Map<String, String> headers, String body) throws Exception { - return sendTextMessage(headers, body, null, null); - } - - @Override - public String sendTextMessage(String body, String user, String password) throws Exception { - return sendTextMessage(Collections.EMPTY_MAP, body, user, password); - } - - @Override - public String sendTextMessage(Map<String, String> headers, - String body, - String user, - String password) throws Exception { - boolean durable = false; - if (headers.containsKey("JMSDeliveryMode")) { - String jmsDeliveryMode = headers.remove("JMSDeliveryMode"); - if (jmsDeliveryMode != null && (jmsDeliveryMode.equals("2") || jmsDeliveryMode.equalsIgnoreCase("PERSISTENT"))) { - durable = true; - } - } - String userID = UUIDGenerator.getInstance().generateStringUUID(); - ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(56); - buffer.writeNullableSimpleString(new SimpleString(body)); - byte[] bytes = new byte[buffer.readableBytes()]; - buffer.readBytes(bytes); - coreQueueControl.sendMessage(headers, Message.TEXT_TYPE, Base64.encodeBytes(bytes), userID, durable, user, password); - return userID; - } - - @Override - public boolean changeMessagePriority(final String messageID, final int newPriority) throws Exception { - String filter = JMSQueueControlImpl.createFilterForJMSMessageID(messageID); - int changed = coreQueueControl.changeMessagesPriority(filter, newPriority); - if (changed != 1) { - throw new IllegalArgumentException("No message found for JMSMessageID: " + messageID); - } - return true; - } - - @Override - public int changeMessagesPriority(final String filterStr, final int newPriority) throws Exception { - String filter = JMSQueueControlImpl.createFilterFromJMSSelector(filterStr); - return coreQueueControl.changeMessagesPriority(filter, newPriority); - } - - @Override - public boolean retryMessage(final String jmsMessageID) throws Exception { - - // Figure out messageID from JMSMessageID. - final String filter = createFilterForJMSMessageID(jmsMessageID); - Map<String, Object>[] messages = coreQueueControl.listMessages(filter); - if (messages.length != 1) { // if no messages. There should not be more than one, JMSMessageID should be unique. - return false; - } - - final Map<String, Object> messageToRedeliver = messages[0]; - Long messageID = (Long) messageToRedeliver.get("messageID"); - return messageID != null && coreQueueControl.retryMessage(messageID); - } - - @Override - public int retryMessages() throws Exception { - return coreQueueControl.retryMessages(); - } - - @Override - public boolean moveMessage(final String messageID, final String otherQueueName) throws Exception { - return moveMessage(messageID, otherQueueName, false); - } - - @Override - public boolean moveMessage(final String messageID, - final String otherQueueName, - final boolean rejectDuplicates) throws Exception { - String filter = JMSQueueControlImpl.createFilterForJMSMessageID(messageID); - ActiveMQDestination otherQueue = ActiveMQDestination.createQueue(otherQueueName); - int moved = coreQueueControl.moveMessages(filter, otherQueue.getAddress(), rejectDuplicates); - if (moved != 1) { - throw new IllegalArgumentException("No message found for JMSMessageID: " + messageID); - } - - return true; - } - - @Override - public int moveMessages(final String filterStr, - final String otherQueueName, - final boolean rejectDuplicates) throws Exception { - String filter = JMSQueueControlImpl.createFilterFromJMSSelector(filterStr); - ActiveMQDestination otherQueue = ActiveMQDestination.createQueue(otherQueueName); - return coreQueueControl.moveMessages(filter, otherQueue.getAddress(), rejectDuplicates); - } - - @Override - public int moveMessages(final String filterStr, final String otherQueueName) throws Exception { - return moveMessages(filterStr, otherQueueName, false); - } - - @Override - @Operation(desc = "List all the existent consumers on the Queue") - public String listConsumersAsJSON() throws Exception { - return coreQueueControl.listConsumersAsJSON(); - } - - @Override - public String listMessageCounter() { - try { - return MessageCounterInfo.toJSon(counter); - } catch (Exception e) { - throw new IllegalStateException(e); - } - } - - @Override - public void resetMessageCounter() throws Exception { - coreQueueControl.resetMessageCounter(); - } - - @Override - public String listMessageCounterAsHTML() { - return MessageCounterHelper.listMessageCounterAsHTML(new MessageCounter[]{counter}); - } - - @Override - public String listMessageCounterHistory() throws Exception { - return MessageCounterHelper.listMessageCounterHistory(counter); - } - - @Override - public String listMessageCounterHistoryAsHTML() { - return MessageCounterHelper.listMessageCounterHistoryAsHTML(new MessageCounter[]{counter}); - } - - @Override - public boolean isPaused() throws Exception { - return coreQueueControl.isPaused(); - } - - @Override - public void pause() throws Exception { - coreQueueControl.pause(); - } - - @Override - public void pause(boolean persist) throws Exception { - coreQueueControl.pause(persist); - } - - @Override - public void resume() throws Exception { - coreQueueControl.resume(); - } - - @Override - public CompositeData[] browse() throws Exception { - return browse(null); - } - - @Override - public CompositeData[] browse(String filter) throws Exception { - try { - CompositeData[] messages = coreQueueControl.browse(filter); - - ArrayList<CompositeData> c = new ArrayList<>(); - - for (CompositeData message : messages) { - c.add(toJMSCompositeType((CompositeDataSupport) message)); - } - CompositeData[] rc = new CompositeData[c.size()]; - c.toArray(rc); - return rc; - } catch (ActiveMQInvalidFilterExpressionException e) { - throw new InvalidSelectorException(e.getMessage()); - } - } - - @Override - public String getSelector() { - return coreQueueControl.getFilter(); - } - - @Override - public void flushExecutor() { - coreQueueControl.flushExecutor(); - } - - @Override - public MBeanInfo getMBeanInfo() { - MBeanInfo info = super.getMBeanInfo(); - return new MBeanInfo(info.getClassName(), info.getDescription(), MBeanInfoHelper.getMBeanAttributesInfo(JMSQueueControl.class), info.getConstructors(), MBeanInfoHelper.getMBeanOperationsInfo(JMSQueueControl.class), info.getNotifications()); - } - - // Package protected --------------------------------------------- - - // Protected ----------------------------------------------------- - - // Private ------------------------------------------------------- - - // Inner classes ------------------------------------------------- -}
