You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2007/08/11 23:29:33 UTC
svn commit: r564977 [2/8] - in /activemq/trunk:
activemq-console/src/main/java/org/apache/activemq/console/
activemq-console/src/main/java/org/apache/activemq/console/command/
activemq-console/src/main/java/org/apache/activemq/console/filter/
activemq-...
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,37 +16,72 @@
*/
package org.apache.activemq.console.command;
-import org.apache.activemq.console.formatter.GlobalWriter;
-import org.apache.activemq.console.util.AmqMessagesUtil;
-import org.apache.activemq.console.util.JmxMBeansUtil;
-
-import javax.management.ObjectInstance;
-import java.util.List;
-import java.util.StringTokenizer;
import java.util.ArrayList;
-import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.management.ObjectInstance;
+
+import org.apache.activemq.console.formatter.GlobalWriter;
+import org.apache.activemq.console.util.AmqMessagesUtil;
+import org.apache.activemq.console.util.JmxMBeansUtil;
public class BrowseCommand extends AbstractJmxCommand {
+
public static final String QUEUE_PREFIX = "queue:";
public static final String TOPIC_PREFIX = "topic:";
public static final String VIEW_GROUP_HEADER = "header:";
public static final String VIEW_GROUP_CUSTOM = "custom:";
- public static final String VIEW_GROUP_BODY = "body:";
+ public static final String VIEW_GROUP_BODY = "body:";
- private final List queryAddObjects = new ArrayList(10);
- private final List querySubObjects = new ArrayList(10);
- private final Set groupViews = new HashSet(10);
- private final Set queryViews = new HashSet(10);
+ protected String[] helpFile = new String[] {
+ "Task Usage: Main browse [browse-options] <destinations>", "Description: Display selected destination's messages.",
+ "",
+ "Browse Options:",
+ " --msgsel <msgsel1,msglsel2> Add to the search list messages matched by the query similar to",
+ " the messages selector format.",
+ " -V<header|custom|body> Predefined view that allows you to view the message header, custom",
+ " message header, or the message body.",
+ " --view <attr1>,<attr2>,... Select the specific attribute of the message to view.",
+ " --jmxurl <url> Set the JMX URL to connect to.",
+ " --version Display the version information.",
+ " -h,-?,--help Display the browse broker help information.",
+ "",
+ "Examples:",
+ " Main browse FOO.BAR",
+ " - Print the message header, custom message header, and message body of all messages in the",
+ " queue FOO.BAR",
+ "",
+ " Main browse -Vheader,body queue:FOO.BAR",
+ " - Print only the message header and message body of all messages in the queue FOO.BAR",
+ "",
+ " Main browse -Vheader --view custom:MyField queue:FOO.BAR",
+ " - Print the message header and the custom field 'MyField' of all messages in the queue FOO.BAR",
+ "",
+ " Main browse --msgsel JMSMessageID='*:10',JMSPriority>5 FOO.BAR",
+ " - Print all the message fields that has a JMSMessageID in the header field that matches the",
+ " wildcard *:10, and has a JMSPriority field > 5 in the queue FOO.BAR",
+ " * To use wildcard queries, the field must be a string and the query enclosed in ''",
+ ""
+ };
+
+ private final List<String> queryAddObjects = new ArrayList<String>(10);
+ private final List<String> querySubObjects = new ArrayList<String>(10);
+ private final Set<String> groupViews = new HashSet<String>(10);
+ private final Set queryViews = new HashSet(10);
/**
- * Execute the browse command, which allows you to browse the messages in a given JMS destination
+ * Execute the browse command, which allows you to browse the messages in a
+ * given JMS destination
+ *
* @param tokens - command arguments
* @throws Exception
*/
- protected void runTask(List tokens) throws Exception {
+ protected void runTask(List<String> tokens) throws Exception {
try {
// If there is no queue name specified, let's select all
if (tokens.isEmpty()) {
@@ -55,11 +89,11 @@
}
// Iterate through the queue names
- for (Iterator i=tokens.iterator(); i.hasNext();) {
+ for (Iterator<String> i = tokens.iterator(); i.hasNext();) {
List queueList = JmxMBeansUtil.queryMBeans(useJmxServiceUrl(), "Type=Queue,Destination=" + i.next() + ",*");
// Iterate through the queue result
- for (Iterator j=queueList.iterator(); j.hasNext();) {
+ for (Iterator j = queueList.iterator(); j.hasNext();) {
List messages = JmxMBeansUtil.createMessageQueryFilter(useJmxServiceUrl(), ((ObjectInstance)j.next()).getObjectName()).query(queryAddObjects);
GlobalWriter.printMessage(JmxMBeansUtil.filterMessagesView(messages, groupViews, queryViews));
}
@@ -72,16 +106,18 @@
/**
* Handle the --msgsel, --xmsgsel, --view, -V options.
+ *
* @param token - option token to handle
* @param tokens - succeeding command arguments
* @throws Exception
*/
- protected void handleOption(String token, List tokens) throws Exception {
+ protected void handleOption(String token, List<String> tokens) throws Exception {
// If token is an additive message selector option
if (token.startsWith("--msgsel")) {
- // If no message selector is specified, or next token is a new option
+ // If no message selector is specified, or next token is a new
+ // option
if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
return;
@@ -91,12 +127,11 @@
while (queryTokens.hasMoreTokens()) {
queryAddObjects.add(queryTokens.nextToken());
}
- }
-
- // If token is a substractive message selector option
- else if (token.startsWith("--xmsgsel")) {
+ } else if (token.startsWith("--xmsgsel")) {
+ // If token is a substractive message selector option
- // If no message selector is specified, or next token is a new option
+ // If no message selector is specified, or next token is a new
+ // option
if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
return;
@@ -107,10 +142,8 @@
querySubObjects.add(queryTokens.nextToken());
}
- }
-
- // If token is a view option
- else if (token.startsWith("--view")) {
+ } else if (token.startsWith("--view")) {
+ // If token is a view option
// If no view specified, or next token is a new option
if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
@@ -127,46 +160,44 @@
if (viewToken.equals(VIEW_GROUP_HEADER)) {
queryViews.add(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + viewToken.substring(VIEW_GROUP_HEADER.length()));
- // If view is explicitly specified to belong to the JMS custom header
+ // If view is explicitly specified to belong to the JMS
+ // custom header
} else if (viewToken.equals(VIEW_GROUP_CUSTOM)) {
queryViews.add(AmqMessagesUtil.JMS_MESSAGE_CUSTOM_PREFIX + viewToken.substring(VIEW_GROUP_CUSTOM.length()));
- // If view is explicitly specified to belong to the JMS body
+ // If view is explicitly specified to belong to the JMS body
} else if (viewToken.equals(VIEW_GROUP_BODY)) {
queryViews.add(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX + viewToken.substring(VIEW_GROUP_BODY.length()));
- // If no view explicitly specified, let's check the view for each group
+ // If no view explicitly specified, let's check the view for
+ // each group
} else {
queryViews.add(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + viewToken);
queryViews.add(AmqMessagesUtil.JMS_MESSAGE_CUSTOM_PREFIX + viewToken);
- queryViews.add(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX + viewToken);
+ queryViews.add(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX + viewToken);
}
}
- }
-
- // If token is a predefined group view option
- else if (token.startsWith("-V")) {
+ } else if (token.startsWith("-V")) {
+ // If token is a predefined group view option
String viewGroup = token.substring(2);
// If option is a header group view
if (viewGroup.equals("header")) {
groupViews.add(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX);
- // If option is a custom header group view
+ // If option is a custom header group view
} else if (viewGroup.equals("custom")) {
groupViews.add(AmqMessagesUtil.JMS_MESSAGE_CUSTOM_PREFIX);
- // If option is a body group view
+ // If option is a body group view
} else if (viewGroup.equals("body")) {
groupViews.add(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX);
- // Unknown group view
+ // Unknown group view
} else {
GlobalWriter.printInfo("Unknown group view: " + viewGroup + ". Ignoring group view option.");
}
- }
-
- // Let super class handle unknown option
- else {
+ } else {
+ // Let super class handle unknown option
super.handleOption(token, tokens);
}
}
@@ -178,35 +209,4 @@
GlobalWriter.printHelp(helpFile);
}
- protected String[] helpFile = new String[] {
- "Task Usage: Main browse [browse-options] <destinations>",
- "Description: Display selected destination's messages.",
- "",
- "Browse Options:",
- " --msgsel <msgsel1,msglsel2> Add to the search list messages matched by the query similar to",
- " the messages selector format.",
- " -V<header|custom|body> Predefined view that allows you to view the message header, custom",
- " message header, or the message body.",
- " --view <attr1>,<attr2>,... Select the specific attribute of the message to view.",
- " --jmxurl <url> Set the JMX URL to connect to.",
- " --version Display the version information.",
- " -h,-?,--help Display the browse broker help information.",
- "",
- "Examples:",
- " Main browse FOO.BAR",
- " - Print the message header, custom message header, and message body of all messages in the",
- " queue FOO.BAR",
- "",
- " Main browse -Vheader,body queue:FOO.BAR",
- " - Print only the message header and message body of all messages in the queue FOO.BAR",
- "",
- " Main browse -Vheader --view custom:MyField queue:FOO.BAR",
- " - Print the message header and the custom field 'MyField' of all messages in the queue FOO.BAR",
- "",
- " Main browse --msgsel JMSMessageID='*:10',JMSPriority>5 FOO.BAR",
- " - Print all the message fields that has a JMSMessageID in the header field that matches the",
- " wildcard *:10, and has a JMSPriority field > 5 in the queue FOO.BAR",
- " * To use wildcard queries, the field must be a string and the query enclosed in ''",
- "",
- };
}
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BstatCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BstatCommand.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BstatCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BstatCommand.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,18 +16,34 @@
*/
package org.apache.activemq.console.command;
-import java.util.List;
-import java.util.Iterator;
import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
public class BstatCommand extends QueryCommand {
+
+ protected String[] helpFile = new String[] {
+ "Task Usage: activemq-admin bstat [bstat-options] [broker-name]",
+ "Description: Performs a predefined query that displays useful statistics regarding the specified broker.",
+ " If no broker name is specified, it will try and select from all registered brokers.",
+ "",
+ "Bstat Options:",
+ " --jmxurl <url> Set the JMX URL to connect to.",
+ " --version Display the version information.",
+ " -h,-?,--help Display the query broker help information.",
+ "",
+ "Examples:",
+ " activemq-admin bstat localhost",
+ " - Display a summary of statistics for the broker 'localhost'"
+ };
+
/**
* Performs a predefiend query option
* @param tokens - command arguments
* @throws Exception
*/
- protected void runTask(List tokens) throws Exception {
- List queryTokens = new ArrayList();
+ protected void runTask(List<String> tokens) throws Exception {
+ List<String> queryTokens = new ArrayList<String>();
// Find the first non-option token
String brokerName = "*";
for (Iterator i = tokens.iterator(); i.hasNext();) {
@@ -47,26 +62,12 @@
queryTokens.add("Type=*,BrokerName=" + brokerName);
queryTokens.add("-xQTopic=ActiveMQ.Advisory.*");
queryTokens.add("--vuew");
- queryTokens.add("Type,BrokerName,Destination,ConnectorName,EnqueueCount," +
- "DequeueCount,TotalEnqueueCount,TotalDequeueCount,Messages," +
- "TotalMessages,ConsumerCount,TotalConsumerCount,DispatchQueueSize");
+ queryTokens.add("Type,BrokerName,Destination,ConnectorName,EnqueueCount,"
+ + "DequeueCount,TotalEnqueueCount,TotalDequeueCount,Messages,"
+ + "TotalMessages,ConsumerCount,TotalConsumerCount,DispatchQueueSize");
// Call the query command
super.runTask(queryTokens);
}
- protected String[] helpFile = new String[] {
- "Task Usage: activemq-admin bstat [bstat-options] [broker-name]",
- "Description: Performs a predefined query that displays useful statistics regarding the specified broker.",
- " If no broker name is specified, it will try and select from all registered brokers.",
- "",
- "Bstat Options:",
- " --jmxurl <url> Set the JMX URL to connect to.",
- " --version Display the version information.",
- " -h,-?,--help Display the query broker help information.",
- "",
- "Examples:",
- " activemq-admin bstat localhost",
- " - Display a summary of statistics for the broker 'localhost'"
- };
}
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -26,5 +25,5 @@
* @param tokens - arguments to the command
* @throws Exception
*/
- public void execute(List tokens) throws Exception;
+ void execute(List<String> tokens) throws Exception;
}
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,15 +16,26 @@
*/
package org.apache.activemq.console.command;
-import org.apache.activemq.console.formatter.GlobalWriter;
-import org.apache.activemq.console.util.JmxMBeansUtil;
-
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.HashSet;
+
+import org.apache.activemq.console.formatter.GlobalWriter;
+import org.apache.activemq.console.util.JmxMBeansUtil;
public class ListCommand extends AbstractJmxCommand {
+ protected String[] helpFile = new String[] {
+ "Task Usage: Main list [list-options]",
+ "Description: Lists all available broker in the specified JMX context.",
+ "",
+ "List Options:",
+ " --jmxurl <url> Set the JMX URL to connect to.",
+ " --version Display the version information.",
+ " -h,-?,--help Display the stop broker help information.",
+ ""
+ };
+
/**
* List all running brokers registered in the specified JMX context
* @param tokens - command arguments
@@ -33,7 +43,7 @@
*/
protected void runTask(List tokens) throws Exception {
try {
- Set propsView = new HashSet();
+ Set<String> propsView = new HashSet<String>();
propsView.add("BrokerName");
GlobalWriter.printMBean(JmxMBeansUtil.filterMBeansView(JmxMBeansUtil.getAllBrokers(useJmxServiceUrl()), propsView));
} catch (Exception e) {
@@ -49,14 +59,4 @@
GlobalWriter.printHelp(helpFile);
}
- protected String[] helpFile = new String[] {
- "Task Usage: Main list [list-options]",
- "Description: Lists all available broker in the specified JMX context.",
- "",
- "List Options:",
- " --jmxurl <url> Set the JMX URL to connect to.",
- " --version Display the version information.",
- " -h,-?,--help Display the stop broker help information.",
- ""
- };
}
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,30 +16,56 @@
*/
package org.apache.activemq.console.command;
-import org.apache.activemq.console.formatter.GlobalWriter;
-import org.apache.activemq.console.util.JmxMBeansUtil;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
-import javax.management.MBeanServerConnection;
import javax.management.openmbean.CompositeData;
import javax.management.remote.JMXConnector;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.ArrayList;
-import java.util.Iterator;
+
+import org.apache.activemq.console.formatter.GlobalWriter;
+import org.apache.activemq.console.util.JmxMBeansUtil;
public class PurgeCommand extends AbstractJmxCommand {
- private final List queryAddObjects = new ArrayList(10);
- private final List querySubObjects = new ArrayList(10);
+ protected String[] helpFile = new String[] {
+ "Task Usage: Main purge [browse-options] <destinations>",
+ "Description: Delete selected destination's messages that matches the message selector.",
+ "",
+ "Browse Options:",
+ " --msgsel <msgsel1,msglsel2> Add to the search list messages matched by the query similar to",
+ " the messages selector format.",
+ " --jmxurl <url> Set the JMX URL to connect to.",
+ " --version Display the version information.",
+ " -h,-?,--help Display the browse broker help information.",
+ "",
+ "Examples:",
+ " Main purge FOO.BAR",
+ " - Delete all the messages in queue FOO.BAR",
+
+ " Main purge --msgsel JMSMessageID='*:10',JMSPriority>5 FOO.*",
+ " - Delete all the messages in the destinations that matches FOO.* and has a JMSMessageID in",
+ " the header field that matches the wildcard *:10, and has a JMSPriority field > 5 in the",
+ " queue FOO.BAR",
+ " * To use wildcard queries, the field must be a string and the query enclosed in ''",
+ "",
+ };
+
+ private final List<String> queryAddObjects = new ArrayList<String>(10);
+ private final List<String> querySubObjects = new ArrayList<String>(10);
/**
- * Execute the purge command, which allows you to purge the messages in a given JMS destination
+ * Execute the purge command, which allows you to purge the messages in a
+ * given JMS destination
+ *
* @param tokens - command arguments
* @throws Exception
*/
- protected void runTask(List tokens) throws Exception {
+ protected void runTask(List<String> tokens) throws Exception {
try {
// If there is no queue name specified, let's select all
if (tokens.isEmpty()) {
@@ -48,10 +73,10 @@
}
// Iterate through the queue names
- for (Iterator i=tokens.iterator(); i.hasNext();) {
+ for (Iterator<String> i = tokens.iterator(); i.hasNext();) {
List queueList = JmxMBeansUtil.queryMBeans(useJmxServiceUrl(), "Type=Queue,Destination=" + i.next() + ",*");
- for (Iterator j=queueList.iterator(); j.hasNext();) {
+ for (Iterator j = queueList.iterator(); j.hasNext();) {
ObjectName queueName = ((ObjectInstance)j.next()).getObjectName();
if (queryAddObjects.isEmpty()) {
purgeQueue(queueName);
@@ -69,6 +94,7 @@
/**
* Purge all the messages in the queue
+ *
* @param queue - ObjectName of the queue to purge
* @throws Exception
*/
@@ -82,6 +108,7 @@
/**
* Purge selected messages in the queue
+ *
* @param queue - ObjectName of the queue to purge the messages from
* @param messages - List of messages to purge
* @throws Exception
@@ -91,11 +118,13 @@
MBeanServerConnection server = conn.getMBeanServerConnection();
Object[] param = new Object[1];
- for (Iterator i=messages.iterator(); i.hasNext();) {
+ for (Iterator i = messages.iterator(); i.hasNext();) {
CompositeData msg = (CompositeData)i.next();
param[0] = "" + msg.get("JMSMessageID");
GlobalWriter.printInfo("Removing message: " + param[0] + " from queue: " + queue.getKeyProperty("Destination"));
- server.invoke(queue, "removeMessage", param, new String[] {"java.lang.String"});
+ server.invoke(queue, "removeMessage", param, new String[] {
+ "java.lang.String"
+ });
}
conn.close();
@@ -103,15 +132,17 @@
/**
* Handle the --msgsel, --xmsgsel.
+ *
* @param token - option token to handle
* @param tokens - succeeding command arguments
* @throws Exception
*/
- protected void handleOption(String token, List tokens) throws Exception {
+ protected void handleOption(String token, List<String> tokens) throws Exception {
// If token is an additive message selector option
if (token.startsWith("--msgsel")) {
- // If no message selector is specified, or next token is a new option
+ // If no message selector is specified, or next token is a new
+ // option
if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
return;
@@ -121,12 +152,11 @@
while (queryTokens.hasMoreTokens()) {
queryAddObjects.add(queryTokens.nextToken());
}
- }
-
- // If token is a substractive message selector option
- else if (token.startsWith("--xmsgsel")) {
+ } else if (token.startsWith("--xmsgsel")) {
+ // If token is a substractive message selector option
- // If no message selector is specified, or next token is a new option
+ // If no message selector is specified, or next token is a new
+ // option
if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
return;
@@ -137,10 +167,8 @@
querySubObjects.add(queryTokens.nextToken());
}
- }
-
- // Let super class handle unknown option
- else {
+ } else {
+ // Let super class handle unknown option
super.handleOption(token, tokens);
}
}
@@ -152,26 +180,4 @@
GlobalWriter.printHelp(helpFile);
}
- protected String[] helpFile = new String[] {
- "Task Usage: Main purge [browse-options] <destinations>",
- "Description: Delete selected destination's messages that matches the message selector.",
- "",
- "Browse Options:",
- " --msgsel <msgsel1,msglsel2> Add to the search list messages matched by the query similar to",
- " the messages selector format.",
- " --jmxurl <url> Set the JMX URL to connect to.",
- " --version Display the version information.",
- " -h,-?,--help Display the browse broker help information.",
- "",
- "Examples:",
- " Main purge FOO.BAR",
- " - Delete all the messages in queue FOO.BAR",
-
- " Main purge --msgsel JMSMessageID='*:10',JMSPriority>5 FOO.*",
- " - Delete all the messages in the destinations that matches FOO.* and has a JMSMessageID in",
- " the header field that matches the wildcard *:10, and has a JMSPriority field > 5 in the",
- " queue FOO.BAR",
- " * To use wildcard queries, the field must be a string and the query enclosed in ''",
- "",
- };
}
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,40 +16,92 @@
*/
package org.apache.activemq.console.command;
-import org.apache.activemq.console.util.JmxMBeansUtil;
-import org.apache.activemq.console.formatter.GlobalWriter;
-
-import java.util.List;
-import java.util.Properties;
import java.util.ArrayList;
import java.util.Enumeration;
-import java.util.StringTokenizer;
-import java.util.Set;
import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.apache.activemq.console.formatter.GlobalWriter;
+import org.apache.activemq.console.util.JmxMBeansUtil;
public class QueryCommand extends AbstractJmxCommand {
// Predefined type=identifier query
private static final Properties PREDEFINED_OBJNAME_QUERY = new Properties();
static {
- PREDEFINED_OBJNAME_QUERY.setProperty("Broker", "Type=Broker,BrokerName=%1,*");
- PREDEFINED_OBJNAME_QUERY.setProperty("Connection", "Type=Connection,Connection=%1,*");
- PREDEFINED_OBJNAME_QUERY.setProperty("Connector", "Type=Connector,ConnectorName=%1,*");
+ PREDEFINED_OBJNAME_QUERY.setProperty("Broker", "Type=Broker,BrokerName=%1,*");
+ PREDEFINED_OBJNAME_QUERY.setProperty("Connection", "Type=Connection,Connection=%1,*");
+ PREDEFINED_OBJNAME_QUERY.setProperty("Connector", "Type=Connector,ConnectorName=%1,*");
PREDEFINED_OBJNAME_QUERY.setProperty("NetworkConnector", "Type=NetworkConnector,BrokerName=%1,*");
- PREDEFINED_OBJNAME_QUERY.setProperty("Queue", "Type=Queue,Destination=%1,*");
- PREDEFINED_OBJNAME_QUERY.setProperty("Topic", "Type=Topic,Destination=%1,*");
+ PREDEFINED_OBJNAME_QUERY.setProperty("Queue", "Type=Queue,Destination=%1,*");
+ PREDEFINED_OBJNAME_QUERY.setProperty("Topic", "Type=Topic,Destination=%1,*");
+ };
+
+ protected String[] helpFile = new String[] {
+ "Task Usage: Main query [query-options]",
+ "Description: Display selected broker component's attributes and statistics.",
+ "",
+ "Query Options:",
+ " -Q<type>=<name> Add to the search list the specific object type matched",
+ " by the defined object identifier.",
+ " -xQ<type>=<name> Remove from the search list the specific object type",
+ " matched by the object identifier.",
+ " --objname <query> Add to the search list objects matched by the query similar",
+ " to the JMX object name format.",
+ " --xobjname <query> Remove from the search list objects matched by the query",
+ " similar to the JMX object name format.",
+ " --view <attr1>,<attr2>,... Select the specific attribute of the object to view.",
+ " By default all attributes will be displayed.",
+ " --jmxurl <url> Set the JMX URL to connect to.",
+ " --version Display the version information.",
+ " -h,-?,--help Display the query broker help information.",
+ "", "Examples:",
+ " query",
+ " - Print all the attributes of all registered objects queues, topics, connections, etc).",
+ "",
+ " query -QQueue=TEST.FOO",
+ " - Print all the attributes of the queue with destination name TEST.FOO.",
+ "",
+ " query -QTopic=*",
+ " - Print all the attributes of all registered topics.",
+ "",
+ " query --view EnqueueCount,DequeueCount",
+ " - Print the attributes EnqueueCount and DequeueCount of all registered objects.",
+ "",
+ " query -QTopic=* --view EnqueueCount,DequeueCount",
+ " - Print the attributes EnqueueCount and DequeueCount of all registered topics.",
+ "",
+ " query -QTopic=* -QQueue=* --view EnqueueCount,DequeueCount",
+ " - Print the attributes EnqueueCount and DequeueCount of all registered topics and",
+ " queues.",
+ "",
+ " query -QTopic=* -xQTopic=ActiveMQ.Advisory.*",
+ " - Print all attributes of all topics except those that has a name that begins",
+ " with \"ActiveMQ.Advisory\".",
+ "",
+ " query --objname Type=*Connect*,BrokerName=local* -xQNetworkConnector=*",
+ " - Print all attributes of all connectors, connections excluding network connectors",
+ " that belongs to the broker that begins with local.",
+ "",
+ " query -QQueue=* -xQQueue=????",
+ " - Print all attributes of all queues except those that are 4 letters long.",
+ "",
};
- private final List queryAddObjects = new ArrayList(10);
- private final List querySubObjects = new ArrayList(10);
- private final Set queryViews = new HashSet(10);
+ private final List<String> queryAddObjects = new ArrayList<String>(10);
+ private final List<String> querySubObjects = new ArrayList<String>(10);
+ private final Set queryViews = new HashSet(10);
/**
* Queries the mbeans registered in the specified JMX context
+ *
* @param tokens - command arguments
* @throws Exception
*/
- protected void runTask(List tokens) throws Exception {
+ protected void runTask(List<String> tokens) throws Exception {
try {
// Query for the mbeans to add
List addMBeans = JmxMBeansUtil.queryMBeans(useJmxServiceUrl(), queryAddObjects, queryViews);
@@ -61,7 +112,6 @@
addMBeans.removeAll(subMBeans);
}
-
GlobalWriter.printMBean(JmxMBeansUtil.filterMBeansView(addMBeans, queryViews));
} catch (Exception e) {
@@ -72,11 +122,12 @@
/**
* Handle the -Q, -xQ, --objname, --xobjname, --view options.
+ *
* @param token - option token to handle
* @param tokens - succeeding command arguments
* @throws Exception
*/
- protected void handleOption(String token, List tokens) throws Exception {
+ protected void handleOption(String token, List<String> tokens) throws Exception {
// If token is a additive predefined query define option
if (token.startsWith("-Q")) {
String key = token.substring(2);
@@ -98,10 +149,8 @@
while (queryTokens.hasMoreTokens()) {
queryAddObjects.add(queryTokens.nextToken());
}
- }
-
- // If token is a substractive predefined query define option
- else if (token.startsWith("-xQ")) {
+ } else if (token.startsWith("-xQ")) {
+ // If token is a substractive predefined query define option
String key = token.substring(3);
String value = "";
int pos = key.indexOf("=");
@@ -121,12 +170,11 @@
while (queryTokens.hasMoreTokens()) {
querySubObjects.add(queryTokens.nextToken());
}
- }
-
- // If token is an additive object name query option
- else if (token.startsWith("--objname")) {
+ } else if (token.startsWith("--objname")) {
+ // If token is an additive object name query option
- // If no object name query is specified, or next token is a new option
+ // If no object name query is specified, or next token is a new
+ // option
if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
GlobalWriter.printException(new IllegalArgumentException("Object name query not specified"));
return;
@@ -136,12 +184,11 @@
while (queryTokens.hasMoreTokens()) {
queryAddObjects.add(queryTokens.nextToken());
}
- }
-
- // If token is a substractive object name query option
- else if (token.startsWith("--xobjname")) {
+ } else if (token.startsWith("--xobjname")) {
+ // If token is a substractive object name query option
- // If no object name query is specified, or next token is a new option
+ // If no object name query is specified, or next token is a new
+ // option
if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
GlobalWriter.printException(new IllegalArgumentException("Object name query not specified"));
return;
@@ -151,10 +198,8 @@
while (queryTokens.hasMoreTokens()) {
querySubObjects.add(queryTokens.nextToken());
}
- }
-
- // If token is a view option
- else if (token.startsWith("--view")) {
+ } else if (token.startsWith("--view")) {
+ // If token is a view option
// If no view specified, or next token is a new option
if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
@@ -167,10 +212,8 @@
while (viewTokens.hasMoreElements()) {
queryViews.add(viewTokens.nextElement());
}
- }
-
- // Let super class handle unknown option
- else {
+ } else {
+ // Let super class handle unknown option
super.handleOption(token, tokens);
}
}
@@ -181,56 +224,5 @@
protected void printHelp() {
GlobalWriter.printHelp(helpFile);
}
-
- protected String[] helpFile = new String[] {
- "Task Usage: Main query [query-options]",
- "Description: Display selected broker component's attributes and statistics.",
- "",
- "Query Options:",
- " -Q<type>=<name> Add to the search list the specific object type matched",
- " by the defined object identifier.",
- " -xQ<type>=<name> Remove from the search list the specific object type",
- " matched by the object identifier.",
- " --objname <query> Add to the search list objects matched by the query similar",
- " to the JMX object name format.",
- " --xobjname <query> Remove from the search list objects matched by the query",
- " similar to the JMX object name format.",
- " --view <attr1>,<attr2>,... Select the specific attribute of the object to view.",
- " By default all attributes will be displayed.",
- " --jmxurl <url> Set the JMX URL to connect to.",
- " --version Display the version information.",
- " -h,-?,--help Display the query broker help information.",
- "",
- "Examples:",
- " query",
- " - Print all the attributes of all registered objects queues, topics, connections, etc).",
- "",
- " query -QQueue=TEST.FOO",
- " - Print all the attributes of the queue with destination name TEST.FOO.",
- "",
- " query -QTopic=*",
- " - Print all the attributes of all registered topics.",
- "",
- " query --view EnqueueCount,DequeueCount",
- " - Print the attributes EnqueueCount and DequeueCount of all registered objects.",
- "",
- " query -QTopic=* --view EnqueueCount,DequeueCount",
- " - Print the attributes EnqueueCount and DequeueCount of all registered topics.",
- "",
- " query -QTopic=* -QQueue=* --view EnqueueCount,DequeueCount",
- " - Print the attributes EnqueueCount and DequeueCount of all registered topics and",
- " queues.",
- "",
- " query -QTopic=* -xQTopic=ActiveMQ.Advisory.*",
- " - Print all attributes of all topics except those that has a name that begins",
- " with \"ActiveMQ.Advisory\".",
- "",
- " query --objname Type=*Connect*,BrokerName=local* -xQNetworkConnector=*",
- " - Print all attributes of all connectors, connections excluding network connectors",
- " that belongs to the broker that begins with local.",
- "",
- " query -QQueue=* -xQQueue=????",
- " - Print all attributes of all queues except those that are 4 letters long.",
- "",
- };
+
}
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,50 +16,50 @@
*/
package org.apache.activemq.console.command;
-import org.apache.activemq.console.formatter.GlobalWriter;
-import org.apache.activemq.console.formatter.CommandShellOutputFormatter;
-
-import java.util.List;
-import java.util.Arrays;
-import java.util.ArrayList;
import java.io.InputStream;
import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.activemq.console.formatter.CommandShellOutputFormatter;
+import org.apache.activemq.console.formatter.GlobalWriter;
public class ShellCommand extends AbstractCommand {
private boolean interactive;
private String[] helpFile;
-
public ShellCommand() {
this(false);
}
public ShellCommand(boolean interactive) {
this.interactive = interactive;
- this.helpFile = new String[]{
- (interactive ? "Usage: [task] [task-options] [task data]" : "Usage: Main [--extdir <dir>] [task] [task-options] [task data]"),
- "",
- "Tasks (default task is start):",
- " start - Creates and starts a broker using a configuration file, or a broker URI.",
- " stop - Stops a running broker specified by the broker name.",
- " list - Lists all available brokers in the specified JMX context.",
- " query - Display selected broker component's attributes and statistics.",
- " browse - Display selected messages in a specified destination.",
- "",
- "Task Options (Options specific to each task):",
- " --extdir <dir> - Add the jar files in the directory to the classpath.",
- " --version - Display the version information.",
- " -h,-?,--help - Display this help information. To display task specific help, use " + (interactive ? "" : "Main ") + "[task] -h,-?,--help",
- "",
- "Task Data:",
- " - Information needed by each specific task.",
- ""
+ this.helpFile = new String[] {
+ interactive ? "Usage: [task] [task-options] [task data]" : "Usage: Main [--extdir <dir>] [task] [task-options] [task data]",
+ "",
+ "Tasks (default task is start):",
+ " start - Creates and starts a broker using a configuration file, or a broker URI.",
+ " stop - Stops a running broker specified by the broker name.",
+ " list - Lists all available brokers in the specified JMX context.",
+ " query - Display selected broker component's attributes and statistics.",
+ " browse - Display selected messages in a specified destination.",
+ "",
+ "Task Options (Options specific to each task):",
+ " --extdir <dir> - Add the jar files in the directory to the classpath.",
+ " --version - Display the version information.",
+ " -h,-?,--help - Display this help information. To display task specific help, use " + (interactive ? "" : "Main ") + "[task] -h,-?,--help",
+ "",
+ "Task Data:",
+ " - Information needed by each specific task.",
+ ""
};
}
/**
* Main method to run a command shell client.
+ *
* @param args - command line arguments
* @param in - input stream to use
* @param out - output stream to use
@@ -70,7 +69,7 @@
GlobalWriter.instantiate(new CommandShellOutputFormatter(out));
// Convert arguments to list for easier management
- List tokens = new ArrayList(Arrays.asList(args));
+ List<String> tokens = new ArrayList<String>(Arrays.asList(args));
ShellCommand main = new ShellCommand();
try {
@@ -82,7 +81,6 @@
}
}
-
public boolean isInteractive() {
return interactive;
}
@@ -93,13 +91,14 @@
/**
* Parses for specific command task.
+ *
* @param tokens - command arguments
* @throws Exception
*/
- protected void runTask(List tokens) throws Exception {
-
+ protected void runTask(List<String> tokens) throws Exception {
+
// Process task token
- if( tokens.size() > 0 ) {
+ if (tokens.size() > 0) {
String taskToken = (String)tokens.remove(0);
if (taskToken.equals("start")) {
new StartCommand().execute(tokens);
@@ -123,7 +122,7 @@
} else {
printHelp();
}
-
+
}
/**
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShutdownCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShutdownCommand.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShutdownCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShutdownCommand.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,23 +16,43 @@
*/
package org.apache.activemq.console.command;
-import org.apache.activemq.console.util.JmxMBeansUtil;
-import org.apache.activemq.console.formatter.GlobalWriter;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
import javax.management.ObjectInstance;
+import javax.management.ObjectName;
import javax.management.remote.JMXServiceURL;
-import java.util.List;
-import java.util.Iterator;
-import java.util.Collection;
-import java.util.HashSet;
+
+import org.apache.activemq.console.formatter.GlobalWriter;
+import org.apache.activemq.console.util.JmxMBeansUtil;
public class ShutdownCommand extends AbstractJmxCommand {
- private boolean isStopAllBrokers = false;
+
+ protected String[] helpFile = new String[] {
+ "Task Usage: Main stop [stop-options] [broker-name1] [broker-name2] ...",
+ "Description: Stops a running broker.",
+ "",
+ "Stop Options:",
+ " --jmxurl <url> Set the JMX URL to connect to.",
+ " --all Stop all brokers.",
+ " --version Display the version information.",
+ " -h,-?,--help Display the stop broker help information.",
+ "",
+ "Broker Names:",
+ " Name of the brokers that will be stopped.",
+ " If omitted, it is assumed that there is only one broker running, and it will be stopped.",
+ " Use -all to stop all running brokers.",
+ ""
+ };
+
+ private boolean isStopAllBrokers;
/**
* Shuts down the specified broker or brokers
+ *
* @param brokerNames - names of brokers to shutdown
* @throws Exception
*/
@@ -45,10 +64,8 @@
if (isStopAllBrokers) {
mbeans = JmxMBeansUtil.getAllBrokers(useJmxServiceUrl());
brokerNames.clear();
- }
-
- // Stop the default broker
- else if (brokerNames.isEmpty()) {
+ } else if (brokerNames.isEmpty()) {
+ // Stop the default broker
mbeans = JmxMBeansUtil.getAllBrokers(useJmxServiceUrl());
// If there is no broker to stop
@@ -56,21 +73,19 @@
GlobalWriter.printInfo("There are no brokers to stop.");
return;
- // There should only be one broker to stop
+ // There should only be one broker to stop
} else if (mbeans.size() > 1) {
GlobalWriter.printInfo("There are multiple brokers to stop. Please select the broker(s) to stop or use --all to stop all brokers.");
return;
- // Get the first broker only
+ // Get the first broker only
} else {
Object firstBroker = mbeans.iterator().next();
mbeans.clear();
mbeans.add(firstBroker);
}
- }
-
- // Stop each specified broker
- else {
+ } else {
+ // Stop each specified broker
String brokerName;
mbeans = new HashSet();
while (!brokerNames.isEmpty()) {
@@ -94,6 +109,7 @@
/**
* Stops the list of brokers.
+ *
* @param jmxServiceUrl - JMX service url to connect to
* @param brokerBeans - broker mbeans to stop
* @throws Exception
@@ -102,18 +118,23 @@
MBeanServerConnection server = createJmxConnector().getMBeanServerConnection();
ObjectName brokerObjName;
- for (Iterator i=brokerBeans.iterator(); i.hasNext();) {
+ for (Iterator i = brokerBeans.iterator(); i.hasNext();) {
brokerObjName = ((ObjectInstance)i.next()).getObjectName();
String brokerName = brokerObjName.getKeyProperty("BrokerName");
GlobalWriter.print("Stopping broker: " + brokerName);
try {
- server.invoke(brokerObjName, "terminateJVM", new Object[] {Integer.valueOf(0)}, new String[] {"int"});
+ server.invoke(brokerObjName, "terminateJVM", new Object[] {
+ Integer.valueOf(0)
+ }, new String[] {
+ "int"
+ });
GlobalWriter.print("Succesfully stopped broker: " + brokerName);
} catch (Exception e) {
// TODO: Check exceptions throwned
- //System.out.println("Failed to stop broker: [ " + brokerName + " ]. Reason: " + e.getMessage());
+ // System.out.println("Failed to stop broker: [ " + brokerName +
+ // " ]. Reason: " + e.getMessage());
}
}
@@ -122,11 +143,12 @@
/**
* Handle the --all option.
+ *
* @param token - option token to handle
* @param tokens - succeeding command arguments
* @throws Exception
*/
- protected void handleOption(String token, List tokens) throws Exception {
+ protected void handleOption(String token, List<String> tokens) throws Exception {
// Try to handle the options first
if (token.equals("--all")) {
isStopAllBrokers = true;
@@ -143,20 +165,4 @@
GlobalWriter.printHelp(helpFile);
}
- protected String[] helpFile = new String[] {
- "Task Usage: Main stop [stop-options] [broker-name1] [broker-name2] ...",
- "Description: Stops a running broker.",
- "",
- "Stop Options:",
- " --jmxurl <url> Set the JMX URL to connect to.",
- " --all Stop all brokers.",
- " --version Display the version information.",
- " -h,-?,--help Display the stop broker help information.",
- "",
- "Broker Names:",
- " Name of the brokers that will be stopped.",
- " If omitted, it is assumed that there is only one broker running, and it will be stopped.",
- " Use -all to stop all running brokers.",
- ""
- };
}
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,35 +17,64 @@
package org.apache.activemq.console.command;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.console.formatter.GlobalWriter;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.net.URI;
-import java.net.URISyntaxException;
-
public class StartCommand extends AbstractCommand {
- public static final String DEFAULT_CONFIG_URI = "xbean:activemq.xml";
+ public static final String DEFAULT_CONFIG_URI = "xbean:activemq.xml";
- private URI configURI;
- private List brokers = new ArrayList(5);
+ protected String[] helpFile = new String[] {
+ "Task Usage: Main start [start-options] [uri]",
+ "Description: Creates and starts a broker using a configuration file, or a broker URI.",
+ "",
+ "Start Options:",
+ " -D<name>=<value> Define a system property.",
+ " --version Display the version information.",
+ " -h,-?,--help Display the start broker help information.",
+ "",
+ "URI:",
+ "",
+ " XBean based broker configuration:",
+ "",
+ " Example: Main xbean:file:activemq.xml",
+ " Loads the xbean configuration file from the current working directory",
+ " Example: Main xbean:activemq.xml",
+ " Loads the xbean configuration file from the classpath",
+ "",
+ " URI Parameter based broker configuration:",
+ "",
+ " Example: Main broker:(tcp://localhost:61616, tcp://localhost:5000)?useJmx=true",
+ " Configures the broker with 2 transport connectors and jmx enabled",
+ " Example: Main broker:(tcp://localhost:61616, network:tcp://localhost:5000)?persistent=false",
+ " Configures the broker with 1 transport connector, and 1 network connector and persistence disabled",
+ ""
+ };
+
+ private URI configURI;
+ private List<BrokerService> brokers = new ArrayList<BrokerService>(5);
/**
* The default task to start a broker or a group of brokers
+ *
* @param brokerURIs
*/
- protected void runTask(List brokerURIs) throws Exception {
+ protected void runTask(List<String> brokerURIs) throws Exception {
try {
// If no config uri, use default setting
if (brokerURIs.isEmpty()) {
setConfigUri(new URI(DEFAULT_CONFIG_URI));
startBroker(getConfigUri());
- // Set configuration data, if available, which in this case would be the config URI
+ // Set configuration data, if available, which in this case
+ // would be the config URI
} else {
String strConfigURI;
@@ -64,7 +92,8 @@
}
}
- // Prevent the main thread from exiting unless it is terminated elsewhere
+ // Prevent the main thread from exiting unless it is terminated
+ // elsewhere
waitForShutdown();
} catch (Exception e) {
GlobalWriter.printException(new RuntimeException("Failed to execute start task. Reason: " + e, e));
@@ -74,6 +103,7 @@
/**
* Create and run a broker specified by the given configuration URI
+ *
* @param configURI
* @throws Exception
*/
@@ -81,28 +111,30 @@
System.out.println("Loading message broker from: " + configURI);
BrokerService broker = BrokerFactory.createBroker(configURI);
brokers.add(broker);
-
broker.start();
}
/**
* Wait for a shutdown invocation elsewhere
+ *
* @throws Exception
*/
protected void waitForShutdown() throws Exception {
- final boolean[] shutdown = new boolean[] {false};
+ final boolean[] shutdown = new boolean[] {
+ false
+ };
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
- synchronized(shutdown) {
- shutdown[0]=true;
+ synchronized (shutdown) {
+ shutdown[0] = true;
shutdown.notify();
}
}
});
// Wait for any shutdown event
- synchronized(shutdown) {
- while( !shutdown[0] ) {
+ synchronized (shutdown) {
+ while (!shutdown[0]) {
try {
shutdown.wait();
} catch (InterruptedException e) {
@@ -111,14 +143,15 @@
}
// Stop each broker
- for (Iterator i=brokers.iterator(); i.hasNext();) {
- BrokerService broker = (BrokerService)i.next();
+ for (Iterator<BrokerService> i = brokers.iterator(); i.hasNext();) {
+ BrokerService broker = i.next();
broker.stop();
}
}
/**
* Sets the current configuration URI used by the start task
+ *
* @param uri
*/
public void setConfigUri(URI uri) {
@@ -127,6 +160,7 @@
/**
* Gets the current configuration URI used by the start task
+ *
* @return current configuration URI
*/
public URI getConfigUri() {
@@ -140,30 +174,4 @@
GlobalWriter.printHelp(helpFile);
}
- protected String[] helpFile = new String[] {
- "Task Usage: Main start [start-options] [uri]",
- "Description: Creates and starts a broker using a configuration file, or a broker URI.",
- "",
- "Start Options:",
- " -D<name>=<value> Define a system property.",
- " --version Display the version information.",
- " -h,-?,--help Display the start broker help information.",
- "",
- "URI:",
- "",
- " XBean based broker configuration:",
- "",
- " Example: Main xbean:file:activemq.xml",
- " Loads the xbean configuration file from the current working directory",
- " Example: Main xbean:activemq.xml",
- " Loads the xbean configuration file from the classpath",
- "",
- " URI Parameter based broker configuration:",
- "",
- " Example: Main broker:(tcp://localhost:61616, tcp://localhost:5000)?useJmx=true",
- " Configures the broker with 2 transport connectors and jmx enabled",
- " Example: Main broker:(tcp://localhost:61616, network:tcp://localhost:5000)?persistent=false",
- " Configures the broker with 1 transport connector, and 1 network connector and persistence disabled",
- ""
- };
}
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/AbstractQueryFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/AbstractQueryFilter.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/AbstractQueryFilter.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/AbstractQueryFilter.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,9 +16,9 @@
*/
package org.apache.activemq.console.filter;
+import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
-import java.util.Collections;
public abstract class AbstractQueryFilter implements QueryFilter {
protected QueryFilter next;
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/AmqMessagesQueryFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/AmqMessagesQueryFilter.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/AmqMessagesQueryFilter.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/AmqMessagesQueryFilter.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,19 +16,20 @@
*/
package org.apache.activemq.console.filter;
-import org.apache.activemq.command.ActiveMQTopic;
-import org.apache.activemq.command.ActiveMQQueue;
-import org.apache.activemq.ActiveMQConnectionFactory;
+import java.net.URI;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
-import javax.jms.Destination;
import javax.jms.Connection;
+import javax.jms.Destination;
import javax.jms.JMSException;
-import javax.jms.Session;
import javax.jms.QueueBrowser;
-import java.net.URI;
-import java.util.Collections;
-import java.util.List;
-import java.util.Iterator;
+import javax.jms.Session;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
public class AmqMessagesQueryFilter extends AbstractQueryFilter {
@@ -38,17 +38,19 @@
/**
* Create a JMS message query filter
+ *
* @param brokerUrl - broker url to connect to
* @param destination - JMS destination to query
*/
public AmqMessagesQueryFilter(URI brokerUrl, Destination destination) {
super(null);
- this.brokerUrl = brokerUrl;
+ this.brokerUrl = brokerUrl;
this.destination = destination;
}
/**
* Queries the specified destination using the message selector format query
+ *
* @param queries - message selector queries
* @return list messages that matches the selector
* @throws Exception
@@ -57,12 +59,12 @@
String selector = "";
// Convert to message selector
- for (Iterator i=queries.iterator(); i.hasNext();) {
+ for (Iterator i = queries.iterator(); i.hasNext();) {
selector = selector + "(" + i.next().toString() + ") AND ";
}
// Remove last AND
- if (selector != "") {
+ if (!selector.equals("")) {
selector = selector.substring(0, selector.length() - 5);
}
@@ -75,6 +77,7 @@
/**
* Query the messages of a queue destination using a queue browser
+ *
* @param queue - queue destination
* @param selector - message selector
* @return list of messages that matches the selector
@@ -95,19 +98,23 @@
/**
* Query the messages of a topic destination using a message consumer
+ *
* @param topic - topic destination
* @param selector - message selector
* @return list of messages that matches the selector
* @throws Exception
*/
protected List queryMessages(ActiveMQTopic topic, String selector) throws Exception {
- // TODO: should we use a durable subscriber or a retroactive non-durable subscriber?
- // TODO: if a durable subscriber is used, how do we manage it? subscribe/unsubscribe tasks?
+ // TODO: should we use a durable subscriber or a retroactive non-durable
+ // subscriber?
+ // TODO: if a durable subscriber is used, how do we manage it?
+ // subscribe/unsubscribe tasks?
return null;
}
/**
* Create and start a JMS connection
+ *
* @param brokerUrl - broker url to connect to.
* @return JMS connection
* @throws JMSException
@@ -120,6 +127,7 @@
/**
* Get the broker url being used.
+ *
* @return broker url
*/
public URI getBrokerUrl() {
@@ -128,6 +136,7 @@
/**
* Set the broker url to use.
+ *
* @param brokerUrl - broker url
*/
public void setBrokerUrl(URI brokerUrl) {
@@ -136,6 +145,7 @@
/**
* Get the destination being used.
+ *
* @return - JMS destination
*/
public Destination getDestination() {
@@ -144,6 +154,7 @@
/**
* Set the destination to use.
+ *
* @param destination - JMS destination
*/
public void setDestination(Destination destination) {
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/GroupPropertiesViewFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/GroupPropertiesViewFilter.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/GroupPropertiesViewFilter.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/GroupPropertiesViewFilter.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,15 +16,17 @@
*/
package org.apache.activemq.console.filter;
-import java.util.Set;
-import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
public class GroupPropertiesViewFilter extends PropertiesViewFilter {
/**
- * Creates a group properties filter that is able to filter the display result based on a group prefix
+ * Creates a group properties filter that is able to filter the display
+ * result based on a group prefix
+ *
* @param next - the next query filter
*/
public GroupPropertiesViewFilter(QueryFilter next) {
@@ -33,7 +34,9 @@
}
/**
- * Creates a group properties filter that is able to filter the display result based on a group prefix
+ * Creates a group properties filter that is able to filter the display
+ * result based on a group prefix
+ *
* @param groupView - the group filter to use
* @param next - the next query filter
*/
@@ -43,6 +46,7 @@
/**
* Filter the properties that matches the group prefix only.
+ *
* @param data - map data to filter
* @return - filtered map data
*/
@@ -55,18 +59,18 @@
Map newData;
try {
// Lets try to use the same class as the original
- newData = (Map)data.getClass().newInstance();
+ newData = data.getClass().newInstance();
} catch (Exception e) {
// Lets use a default HashMap
newData = new HashMap();
}
// Filter the keys to view
- for (Iterator i=data.keySet().iterator(); i.hasNext();) {
- String key = (String)i.next();
+ for (Iterator<String> i = data.keySet().iterator(); i.hasNext();) {
+ String key = i.next();
// Checks if key matches any of the group filter
- for (Iterator j=viewFilter.iterator(); j.hasNext();) {
+ for (Iterator j = viewFilter.iterator(); j.hasNext();) {
String group = (String)j.next();
if (key.startsWith(group)) {
newData.put(key, data.get(key));
Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MBeansAttributeQueryFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MBeansAttributeQueryFilter.java?view=diff&rev=564977&r1=564976&r2=564977
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MBeansAttributeQueryFilter.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MBeansAttributeQueryFilter.java Sat Aug 11 14:29:21 2007
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,33 +16,36 @@
*/
package org.apache.activemq.console.filter;
-import javax.management.remote.JMXServiceURL;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXConnector;
-import javax.management.ObjectInstance;
-import javax.management.ObjectName;
-import javax.management.MBeanServerConnection;
-import javax.management.ReflectionException;
-import javax.management.InstanceNotFoundException;
-import javax.management.AttributeList;
-import javax.management.Attribute;
-import javax.management.MBeanAttributeInfo;
-import javax.management.IntrospectionException;
-import java.util.Set;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import java.util.ArrayList;
import java.util.List;
-import java.io.IOException;
+import java.util.Set;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.InstanceNotFoundException;
+import javax.management.IntrospectionException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
public class MBeansAttributeQueryFilter extends AbstractQueryFilter {
public static final String KEY_OBJECT_NAME_ATTRIBUTE = "Attribute:ObjectName:";
private JMXServiceURL jmxServiceUrl;
- private Set attribView;
+ private Set attribView;
/**
- * Create an mbean attributes query filter that is able to select specific mbean attributes based on the object name to get.
+ * Create an mbean attributes query filter that is able to select specific
+ * mbean attributes based on the object name to get.
+ *
* @param jmxServiceUrl - JMX service url to connect to.
* @param attribView - the attributes to extract
* @param next - the next query filter
@@ -51,13 +53,16 @@
public MBeansAttributeQueryFilter(JMXServiceURL jmxServiceUrl, Set attribView, MBeansObjectNameQueryFilter next) {
super(next);
this.jmxServiceUrl = jmxServiceUrl;
- this.attribView = attribView;
+ this.attribView = attribView;
}
/**
- * Filter the query by retrieving the attributes specified, this will modify the collection to a list of AttributeList
+ * Filter the query by retrieving the attributes specified, this will modify
+ * the collection to a list of AttributeList
+ *
* @param queries - query list
- * @return List of AttributeList, which includes the ObjectName, which has a key of MBeansAttributeQueryFilter.KEY_OBJECT_NAME_ATTRIBUTE
+ * @return List of AttributeList, which includes the ObjectName, which has a
+ * key of MBeansAttributeQueryFilter.KEY_OBJECT_NAME_ATTRIBUTE
* @throws Exception
*/
public List query(List queries) throws Exception {
@@ -66,6 +71,7 @@
/**
* Retrieve the specified attributes of the mbean
+ *
* @param result - collection of ObjectInstances and/or ObjectNames
* @return List of AttributeList
* @throws IOException
@@ -76,7 +82,7 @@
protected List getMBeanAttributesCollection(Collection result) throws IOException, ReflectionException, InstanceNotFoundException, NoSuchMethodException, IntrospectionException {
List mbeansCollection = new ArrayList();
- for (Iterator i=result.iterator(); i.hasNext();) {
+ for (Iterator i = result.iterator(); i.hasNext();) {
Object mbean = i.next();
if (mbean instanceof ObjectInstance) {
mbeansCollection.add(getMBeanAttributes(((ObjectInstance)mbean).getObjectName(), attribView));
@@ -92,6 +98,7 @@
/**
* Retrieve the specified attributes of the mbean
+ *
* @param obj - mbean ObjectInstance
* @param attrView - list of attributes to retrieve
* @return AttributeList for the mbean
@@ -105,6 +112,7 @@
/**
* Retrieve the specified attributes of the mbean
+ *
* @param objName - mbean ObjectName
* @param attrView - list of attributes to retrieve
* @return AttributeList for the mbean
@@ -113,7 +121,7 @@
* @throws InstanceNotFoundException
*/
protected AttributeList getMBeanAttributes(ObjectName objName, Set attrView) throws IOException, ReflectionException, InstanceNotFoundException, IntrospectionException {
- JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl);
+ JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl);
MBeanServerConnection server = jmxConnector.getMBeanServerConnection();
// If no attribute view specified, get all attributes
@@ -122,18 +130,18 @@
MBeanAttributeInfo[] infos = server.getMBeanInfo(objName).getAttributes();
attribs = new String[infos.length];
- for (int i=0; i<infos.length; i++) {
+ for (int i = 0; i < infos.length; i++) {
if (infos[i].isReadable()) {
attribs[i] = infos[i].getName();
}
}
- // Get selected attributes
+ // Get selected attributes
} else {
attribs = new String[attrView.size()];
int count = 0;
- for (Iterator i=attrView.iterator(); i.hasNext();) {
+ for (Iterator i = attrView.iterator(); i.hasNext();) {
attribs[count++] = (String)i.next();
}
}