Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractJmxCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractJmxCommand.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractJmxCommand.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractJmxCommand.java Tue Feb 21 15:12:56 2006
@@ -1,135 +1,135 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed 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.console.command;
-
-import org.apache.activemq.console.formatter.GlobalWriter;
-
-import javax.management.remote.JMXServiceURL;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import java.util.List;
-import java.net.MalformedURLException;
-import java.io.IOException;
-
-public abstract class AbstractJmxCommand extends AbstractCommand {
- public static final String DEFAULT_JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
-
- private JMXServiceURL jmxServiceUrl;
- private JMXConnector jmxConnector;
-
- /**
- * Get the current specified JMX service url.
- * @return JMX service url
- */
- protected JMXServiceURL getJmxServiceUrl() {
- return jmxServiceUrl;
- }
-
- /**
- * Get the current JMX service url being used, or create a default one if no JMX service url has been specified.
- * @return JMX service url
- * @throws MalformedURLException
- */
- protected JMXServiceURL useJmxServiceUrl() throws MalformedURLException {
- if (getJmxServiceUrl() == null) {
- setJmxServiceUrl(DEFAULT_JMX_URL);
- }
-
- return getJmxServiceUrl();
- }
-
- /**
- * Sets the JMX service url to use.
- * @param jmxServiceUrl - new JMX service url to use
- */
- protected void setJmxServiceUrl(JMXServiceURL jmxServiceUrl) {
- this.jmxServiceUrl = jmxServiceUrl;
- }
-
- /**
- * Sets the JMX service url to use.
- * @param jmxServiceUrl - new JMX service url to use
- * @throws MalformedURLException
- */
- protected void setJmxServiceUrl(String jmxServiceUrl) throws MalformedURLException {
- setJmxServiceUrl(new JMXServiceURL(jmxServiceUrl));
- }
-
- /**
- * Create a JMX connector using the current specified JMX service url. If there is an existing connection,
- * it tries to reuse this connection.
- * @return created JMX connector
- * @throws IOException
- */
- protected JMXConnector createJmxConnector() throws IOException {
- // Reuse the previous connection
- if (jmxConnector != null) {
- jmxConnector.connect();
- return jmxConnector;
- }
-
- // Create a new JMX connector
- jmxConnector = JMXConnectorFactory.connect(useJmxServiceUrl());
- return jmxConnector;
- }
-
- /**
- * Close the current JMX connector
- */
- protected void closeJmxConnector() {
- try {
- if (jmxConnector != null) {
- jmxConnector.close();
- jmxConnector = null;
- }
- } catch (IOException e) {
- }
- }
-
- /**
- * Handle the --jmxurl option.
- * @param token - option token to handle
- * @param tokens - succeeding command arguments
- * @throws Exception
- */
- protected void handleOption(String token, List tokens) throws Exception {
- // Try to handle the options first
- if (token.equals("--jmxurl")) {
- // If no jmx url specified, or next token is a new option
- if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
- GlobalWriter.printException(new IllegalArgumentException("JMX URL not specified."));
- }
-
- // If jmx url already specified
- if (getJmxServiceUrl() != null) {
- GlobalWriter.printException(new IllegalArgumentException("Multiple JMX URL cannot be specified."));
- tokens.clear();
- }
-
- String strJmxUrl = (String)tokens.remove(0);
- try {
- this.setJmxServiceUrl(new JMXServiceURL(strJmxUrl));
- } catch (MalformedURLException e) {
- GlobalWriter.printException(e);
- tokens.clear();
- }
- } else {
- // Let the super class handle the option
- super.handleOption(token, tokens);
- }
- }
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.console.command;
+
+import org.apache.activemq.console.formatter.GlobalWriter;
+
+import javax.management.remote.JMXServiceURL;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import java.util.List;
+import java.net.MalformedURLException;
+import java.io.IOException;
+
+public abstract class AbstractJmxCommand extends AbstractCommand {
+ public static final String DEFAULT_JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
+
+ private JMXServiceURL jmxServiceUrl;
+ private JMXConnector jmxConnector;
+
+ /**
+ * Get the current specified JMX service url.
+ * @return JMX service url
+ */
+ protected JMXServiceURL getJmxServiceUrl() {
+ return jmxServiceUrl;
+ }
+
+ /**
+ * Get the current JMX service url being used, or create a default one if no JMX service url has been specified.
+ * @return JMX service url
+ * @throws MalformedURLException
+ */
+ protected JMXServiceURL useJmxServiceUrl() throws MalformedURLException {
+ if (getJmxServiceUrl() == null) {
+ setJmxServiceUrl(DEFAULT_JMX_URL);
+ }
+
+ return getJmxServiceUrl();
+ }
+
+ /**
+ * Sets the JMX service url to use.
+ * @param jmxServiceUrl - new JMX service url to use
+ */
+ protected void setJmxServiceUrl(JMXServiceURL jmxServiceUrl) {
+ this.jmxServiceUrl = jmxServiceUrl;
+ }
+
+ /**
+ * Sets the JMX service url to use.
+ * @param jmxServiceUrl - new JMX service url to use
+ * @throws MalformedURLException
+ */
+ protected void setJmxServiceUrl(String jmxServiceUrl) throws MalformedURLException {
+ setJmxServiceUrl(new JMXServiceURL(jmxServiceUrl));
+ }
+
+ /**
+ * Create a JMX connector using the current specified JMX service url. If there is an existing connection,
+ * it tries to reuse this connection.
+ * @return created JMX connector
+ * @throws IOException
+ */
+ protected JMXConnector createJmxConnector() throws IOException {
+ // Reuse the previous connection
+ if (jmxConnector != null) {
+ jmxConnector.connect();
+ return jmxConnector;
+ }
+
+ // Create a new JMX connector
+ jmxConnector = JMXConnectorFactory.connect(useJmxServiceUrl());
+ return jmxConnector;
+ }
+
+ /**
+ * Close the current JMX connector
+ */
+ protected void closeJmxConnector() {
+ try {
+ if (jmxConnector != null) {
+ jmxConnector.close();
+ jmxConnector = null;
+ }
+ } catch (IOException e) {
+ }
+ }
+
+ /**
+ * Handle the --jmxurl option.
+ * @param token - option token to handle
+ * @param tokens - succeeding command arguments
+ * @throws Exception
+ */
+ protected void handleOption(String token, List tokens) throws Exception {
+ // Try to handle the options first
+ if (token.equals("--jmxurl")) {
+ // If no jmx url specified, or next token is a new option
+ if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
+ GlobalWriter.printException(new IllegalArgumentException("JMX URL not specified."));
+ }
+
+ // If jmx url already specified
+ if (getJmxServiceUrl() != null) {
+ GlobalWriter.printException(new IllegalArgumentException("Multiple JMX URL cannot be specified."));
+ tokens.clear();
+ }
+
+ String strJmxUrl = (String)tokens.remove(0);
+ try {
+ this.setJmxServiceUrl(new JMXServiceURL(strJmxUrl));
+ } catch (MalformedURLException e) {
+ GlobalWriter.printException(e);
+ tokens.clear();
+ }
+ } else {
+ // Let the super class handle the option
+ super.handleOption(token, tokens);
+ }
+ }
+}
Propchange: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AbstractJmxCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AmqBrowseCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AmqBrowseCommand.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AmqBrowseCommand.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AmqBrowseCommand.java Tue Feb 21 15:12:56 2006
@@ -1,240 +1,240 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed 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.console.command;
-
-import org.apache.activemq.console.util.AmqMessagesUtil;
-import org.apache.activemq.console.formatter.GlobalWriter;
-import org.apache.activemq.command.ActiveMQQueue;
-import org.apache.activemq.command.ActiveMQTopic;
-
-import javax.jms.Destination;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.StringTokenizer;
-import java.util.Iterator;
-
-public class AmqBrowseCommand extends AbstractAmqCommand {
- 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:";
-
- 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);
-
- /**
- * 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 {
- try {
- // If no destination specified
- if (tokens.isEmpty()) {
- GlobalWriter.printException(new IllegalArgumentException("No JMS destination specified."));
- return;
- }
-
- // If no broker url specified
- if (getBrokerUrl() == null) {
- GlobalWriter.printException(new IllegalStateException("No broker url specified. Use the --amqurl option to specify a broker url."));
- return;
- }
-
- // Display the messages for each destination
- for (Iterator i=tokens.iterator(); i.hasNext();) {
- String destName = (String)i.next();
- Destination dest;
-
- // If destination has been explicitly specified as a queue
- if (destName.startsWith(QUEUE_PREFIX)) {
- dest = new ActiveMQQueue(destName.substring(QUEUE_PREFIX.length()));
-
- // If destination has been explicitly specified as a topic
- } else if (destName.startsWith(TOPIC_PREFIX)) {
- dest = new ActiveMQTopic(destName.substring(TOPIC_PREFIX.length()));
-
- // By default destination is assumed to be a queue
- } else {
- dest = new ActiveMQQueue(destName);
- }
-
- // Query for the messages to view
- List addMsgs = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, queryAddObjects);
-
- // Query for the messages to remove from view
- if (querySubObjects.size() > 0) {
- List subMsgs = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, querySubObjects);
- addMsgs.removeAll(subMsgs);
- }
-
- // Display the messages
- GlobalWriter.printMessage(AmqMessagesUtil.filterMessagesView(addMsgs, groupViews, queryViews));
- }
-
- } catch (Exception e) {
- GlobalWriter.printException(new RuntimeException("Failed to execute browse task. Reason: " + e));
- throw new Exception(e);
- }
- }
-
- /**
- * 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 {
-
- // 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 (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
- GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
- return;
- }
-
- StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
- while (queryTokens.hasMoreTokens()) {
- queryAddObjects.add(queryTokens.nextToken());
- }
- }
-
- // If token is a substractive message selector option
- else if (token.startsWith("--xmsgsel")) {
-
- // 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;
- }
-
- StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
- while (queryTokens.hasMoreTokens()) {
- querySubObjects.add(queryTokens.nextToken());
- }
-
- }
-
- // If token is a view option
- else if (token.startsWith("--view")) {
-
- // If no view specified, or next token is a new option
- if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
- GlobalWriter.printException(new IllegalArgumentException("Attributes to view not specified"));
- return;
- }
-
- // Add the attributes to view
- StringTokenizer viewTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
- while (viewTokens.hasMoreTokens()) {
- String viewToken = viewTokens.nextToken();
-
- // If view is explicitly specified to belong to the JMS header
- 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
- } 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
- } 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
- } 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);
- }
- }
- }
-
- // If token is a predefined group view option
- else if (token.startsWith("-V")) {
- 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
- } else if (viewGroup.equals("custom")) {
- groupViews.add(AmqMessagesUtil.JMS_MESSAGE_CUSTOM_PREFIX);
-
- // If option is a body group view
- } else if (viewGroup.equals("body")) {
- groupViews.add(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX);
-
- // Unknown group view
- } else {
- GlobalWriter.printInfo("Unknown group view: " + viewGroup + ". Ignoring group view option.");
- }
- }
-
- // Let super class handle unknown option
- else {
- super.handleOption(token, tokens);
- }
- }
-
- /**
- * Print the help messages for the browse command
- */
- protected void printHelp() {
- GlobalWriter.printHelp(helpFile);
- }
-
- protected String[] helpFile = new String[] {
- "Task Usage: Main browse --amqurl <broker url> [browse-options] <destinations>",
- "Description: Display selected destination's messages.",
- "",
- "Browse Options:",
- " --amqurl <url> Set the broker URL to connect to.",
- " --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.",
- " --version Display the version information.",
- " -h,-?,--help Display the browse broker help information.",
- "",
- "Examples:",
- " Main browse --amqurl tcp://localhost:61616 FOO.BAR",
- " - Print the message header, custom message header, and message body of all messages in the",
- " queue FOO.BAR",
- "",
- " Main browse --amqurl tcp://localhost:61616 -Vheader,body queue:FOO.BAR",
- " - Print only the message header and message body of all messages in the queue FOO.BAR",
- "",
- " Main browse --amqurl tcp://localhost:61616 -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 --amqurl tcp://localhost:61616 --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 ''",
- "",
- };
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.console.command;
+
+import org.apache.activemq.console.util.AmqMessagesUtil;
+import org.apache.activemq.console.formatter.GlobalWriter;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
+
+import javax.jms.Destination;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.StringTokenizer;
+import java.util.Iterator;
+
+public class AmqBrowseCommand extends AbstractAmqCommand {
+ 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:";
+
+ 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);
+
+ /**
+ * 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 {
+ try {
+ // If no destination specified
+ if (tokens.isEmpty()) {
+ GlobalWriter.printException(new IllegalArgumentException("No JMS destination specified."));
+ return;
+ }
+
+ // If no broker url specified
+ if (getBrokerUrl() == null) {
+ GlobalWriter.printException(new IllegalStateException("No broker url specified. Use the --amqurl option to specify a broker url."));
+ return;
+ }
+
+ // Display the messages for each destination
+ for (Iterator i=tokens.iterator(); i.hasNext();) {
+ String destName = (String)i.next();
+ Destination dest;
+
+ // If destination has been explicitly specified as a queue
+ if (destName.startsWith(QUEUE_PREFIX)) {
+ dest = new ActiveMQQueue(destName.substring(QUEUE_PREFIX.length()));
+
+ // If destination has been explicitly specified as a topic
+ } else if (destName.startsWith(TOPIC_PREFIX)) {
+ dest = new ActiveMQTopic(destName.substring(TOPIC_PREFIX.length()));
+
+ // By default destination is assumed to be a queue
+ } else {
+ dest = new ActiveMQQueue(destName);
+ }
+
+ // Query for the messages to view
+ List addMsgs = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, queryAddObjects);
+
+ // Query for the messages to remove from view
+ if (querySubObjects.size() > 0) {
+ List subMsgs = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, querySubObjects);
+ addMsgs.removeAll(subMsgs);
+ }
+
+ // Display the messages
+ GlobalWriter.printMessage(AmqMessagesUtil.filterMessagesView(addMsgs, groupViews, queryViews));
+ }
+
+ } catch (Exception e) {
+ GlobalWriter.printException(new RuntimeException("Failed to execute browse task. Reason: " + e));
+ throw new Exception(e);
+ }
+ }
+
+ /**
+ * 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 {
+
+ // 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 (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
+ GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
+ return;
+ }
+
+ StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
+ while (queryTokens.hasMoreTokens()) {
+ queryAddObjects.add(queryTokens.nextToken());
+ }
+ }
+
+ // If token is a substractive message selector option
+ else if (token.startsWith("--xmsgsel")) {
+
+ // 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;
+ }
+
+ StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
+ while (queryTokens.hasMoreTokens()) {
+ querySubObjects.add(queryTokens.nextToken());
+ }
+
+ }
+
+ // If token is a view option
+ else if (token.startsWith("--view")) {
+
+ // If no view specified, or next token is a new option
+ if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
+ GlobalWriter.printException(new IllegalArgumentException("Attributes to view not specified"));
+ return;
+ }
+
+ // Add the attributes to view
+ StringTokenizer viewTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
+ while (viewTokens.hasMoreTokens()) {
+ String viewToken = viewTokens.nextToken();
+
+ // If view is explicitly specified to belong to the JMS header
+ 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
+ } 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
+ } 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
+ } 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);
+ }
+ }
+ }
+
+ // If token is a predefined group view option
+ else if (token.startsWith("-V")) {
+ 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
+ } else if (viewGroup.equals("custom")) {
+ groupViews.add(AmqMessagesUtil.JMS_MESSAGE_CUSTOM_PREFIX);
+
+ // If option is a body group view
+ } else if (viewGroup.equals("body")) {
+ groupViews.add(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX);
+
+ // Unknown group view
+ } else {
+ GlobalWriter.printInfo("Unknown group view: " + viewGroup + ". Ignoring group view option.");
+ }
+ }
+
+ // Let super class handle unknown option
+ else {
+ super.handleOption(token, tokens);
+ }
+ }
+
+ /**
+ * Print the help messages for the browse command
+ */
+ protected void printHelp() {
+ GlobalWriter.printHelp(helpFile);
+ }
+
+ protected String[] helpFile = new String[] {
+ "Task Usage: Main browse --amqurl <broker url> [browse-options] <destinations>",
+ "Description: Display selected destination's messages.",
+ "",
+ "Browse Options:",
+ " --amqurl <url> Set the broker URL to connect to.",
+ " --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.",
+ " --version Display the version information.",
+ " -h,-?,--help Display the browse broker help information.",
+ "",
+ "Examples:",
+ " Main browse --amqurl tcp://localhost:61616 FOO.BAR",
+ " - Print the message header, custom message header, and message body of all messages in the",
+ " queue FOO.BAR",
+ "",
+ " Main browse --amqurl tcp://localhost:61616 -Vheader,body queue:FOO.BAR",
+ " - Print only the message header and message body of all messages in the queue FOO.BAR",
+ "",
+ " Main browse --amqurl tcp://localhost:61616 -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 --amqurl tcp://localhost:61616 --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 ''",
+ "",
+ };
+}
Propchange: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/AmqBrowseCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java Tue Feb 21 15:12:56 2006
@@ -1,211 +1,211 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed 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.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;
-
-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:";
-
- 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);
-
- /**
- * 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 {
- try {
- // If there is no queue name specified, let's select all
- if (tokens.isEmpty()) {
- tokens.add("*");
- }
-
- // Iterate through the queue names
- for (Iterator 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();) {
- List messages = JmxMBeansUtil.createMessageQueryFilter(useJmxServiceUrl(), ((ObjectInstance)j.next()).getObjectName()).query(queryAddObjects);
- GlobalWriter.printMessage(JmxMBeansUtil.filterMessagesView(messages, groupViews, queryViews));
- }
- }
- } catch (Exception e) {
- GlobalWriter.printException(new RuntimeException("Failed to execute browse task. Reason: " + e));
- throw new Exception(e);
- }
- }
-
- /**
- * 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 {
-
- // 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 (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
- GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
- return;
- }
-
- StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
- while (queryTokens.hasMoreTokens()) {
- queryAddObjects.add(queryTokens.nextToken());
- }
- }
-
- // If token is a substractive message selector option
- else if (token.startsWith("--xmsgsel")) {
-
- // 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;
- }
-
- StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
- while (queryTokens.hasMoreTokens()) {
- querySubObjects.add(queryTokens.nextToken());
- }
-
- }
-
- // If token is a view option
- else if (token.startsWith("--view")) {
-
- // If no view specified, or next token is a new option
- if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
- GlobalWriter.printException(new IllegalArgumentException("Attributes to view not specified"));
- return;
- }
-
- // Add the attributes to view
- StringTokenizer viewTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
- while (viewTokens.hasMoreTokens()) {
- String viewToken = viewTokens.nextToken();
-
- // If view is explicitly specified to belong to the JMS header
- 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
- } 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
- } 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
- } 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);
- }
- }
- }
-
- // If token is a predefined group view option
- else if (token.startsWith("-V")) {
- 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
- } else if (viewGroup.equals("custom")) {
- groupViews.add(AmqMessagesUtil.JMS_MESSAGE_CUSTOM_PREFIX);
-
- // If option is a body group view
- } else if (viewGroup.equals("body")) {
- groupViews.add(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX);
-
- // Unknown group view
- } else {
- GlobalWriter.printInfo("Unknown group view: " + viewGroup + ". Ignoring group view option.");
- }
- }
-
- // Let super class handle unknown option
- else {
- super.handleOption(token, tokens);
- }
- }
-
- /**
- * Print the help messages for the browse command
- */
- protected void printHelp() {
- 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 ''",
- "",
- };
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.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;
+
+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:";
+
+ 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);
+
+ /**
+ * 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 {
+ try {
+ // If there is no queue name specified, let's select all
+ if (tokens.isEmpty()) {
+ tokens.add("*");
+ }
+
+ // Iterate through the queue names
+ for (Iterator 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();) {
+ List messages = JmxMBeansUtil.createMessageQueryFilter(useJmxServiceUrl(), ((ObjectInstance)j.next()).getObjectName()).query(queryAddObjects);
+ GlobalWriter.printMessage(JmxMBeansUtil.filterMessagesView(messages, groupViews, queryViews));
+ }
+ }
+ } catch (Exception e) {
+ GlobalWriter.printException(new RuntimeException("Failed to execute browse task. Reason: " + e));
+ throw new Exception(e);
+ }
+ }
+
+ /**
+ * 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 {
+
+ // 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 (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
+ GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
+ return;
+ }
+
+ StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
+ while (queryTokens.hasMoreTokens()) {
+ queryAddObjects.add(queryTokens.nextToken());
+ }
+ }
+
+ // If token is a substractive message selector option
+ else if (token.startsWith("--xmsgsel")) {
+
+ // 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;
+ }
+
+ StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
+ while (queryTokens.hasMoreTokens()) {
+ querySubObjects.add(queryTokens.nextToken());
+ }
+
+ }
+
+ // If token is a view option
+ else if (token.startsWith("--view")) {
+
+ // If no view specified, or next token is a new option
+ if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
+ GlobalWriter.printException(new IllegalArgumentException("Attributes to view not specified"));
+ return;
+ }
+
+ // Add the attributes to view
+ StringTokenizer viewTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
+ while (viewTokens.hasMoreTokens()) {
+ String viewToken = viewTokens.nextToken();
+
+ // If view is explicitly specified to belong to the JMS header
+ 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
+ } 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
+ } 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
+ } 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);
+ }
+ }
+ }
+
+ // If token is a predefined group view option
+ else if (token.startsWith("-V")) {
+ 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
+ } else if (viewGroup.equals("custom")) {
+ groupViews.add(AmqMessagesUtil.JMS_MESSAGE_CUSTOM_PREFIX);
+
+ // If option is a body group view
+ } else if (viewGroup.equals("body")) {
+ groupViews.add(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX);
+
+ // Unknown group view
+ } else {
+ GlobalWriter.printInfo("Unknown group view: " + viewGroup + ". Ignoring group view option.");
+ }
+ }
+
+ // Let super class handle unknown option
+ else {
+ super.handleOption(token, tokens);
+ }
+ }
+
+ /**
+ * Print the help messages for the browse command
+ */
+ protected void printHelp() {
+ 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 ''",
+ "",
+ };
+}
Propchange: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/BrowseCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java Tue Feb 21 15:12:56 2006
@@ -1,29 +1,29 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed 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.console.command;
-
-import java.util.List;
-
-public interface Command {
- /**
- * Execute the specified command
- * @param tokens - arguments to the command
- * @throws Exception
- */
- public void execute(List tokens) throws Exception;
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.console.command;
+
+import java.util.List;
+
+public interface Command {
+ /**
+ * Execute the specified command
+ * @param tokens - arguments to the command
+ * @throws Exception
+ */
+ public void execute(List tokens) throws Exception;
+}
Propchange: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/Command.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java Tue Feb 21 15:12:56 2006
@@ -1,61 +1,61 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed 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.console.command;
-
-import org.apache.activemq.console.formatter.GlobalWriter;
-import org.apache.activemq.console.util.JmxMBeansUtil;
-
-import java.util.List;
-import java.util.Set;
-import java.util.HashSet;
-
-public class ListCommand extends AbstractJmxCommand {
-
- /**
- * List all running brokers registered in the specified JMX context
- * @param tokens - command arguments
- * @throws Exception
- */
- protected void runTask(List tokens) throws Exception {
- try {
- Set propsView = new HashSet();
- propsView.add("BrokerName");
- GlobalWriter.printMBean(JmxMBeansUtil.filterMBeansView(JmxMBeansUtil.getAllBrokers(useJmxServiceUrl()), propsView));
- } catch (Exception e) {
- GlobalWriter.printException(new RuntimeException("Failed to execute list task. Reason: " + e));
- throw new Exception(e);
- }
- }
-
- /**
- * Print the help messages for the browse command
- */
- protected void printHelp() {
- 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.",
- ""
- };
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.console.command;
+
+import org.apache.activemq.console.formatter.GlobalWriter;
+import org.apache.activemq.console.util.JmxMBeansUtil;
+
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+
+public class ListCommand extends AbstractJmxCommand {
+
+ /**
+ * List all running brokers registered in the specified JMX context
+ * @param tokens - command arguments
+ * @throws Exception
+ */
+ protected void runTask(List tokens) throws Exception {
+ try {
+ Set propsView = new HashSet();
+ propsView.add("BrokerName");
+ GlobalWriter.printMBean(JmxMBeansUtil.filterMBeansView(JmxMBeansUtil.getAllBrokers(useJmxServiceUrl()), propsView));
+ } catch (Exception e) {
+ GlobalWriter.printException(new RuntimeException("Failed to execute list task. Reason: " + e));
+ throw new Exception(e);
+ }
+ }
+
+ /**
+ * Print the help messages for the browse command
+ */
+ protected void printHelp() {
+ 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.",
+ ""
+ };
+}
Propchange: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ListCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java Tue Feb 21 15:12:56 2006
@@ -1,176 +1,176 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed 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.console.command;
-
-import org.apache.activemq.console.formatter.GlobalWriter;
-import org.apache.activemq.console.util.JmxMBeansUtil;
-
-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;
-
-public class PurgeCommand extends AbstractJmxCommand {
-
- private final List queryAddObjects = new ArrayList(10);
- private final List querySubObjects = new ArrayList(10);
-
- /**
- * 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 {
- try {
- // If there is no queue name specified, let's select all
- if (tokens.isEmpty()) {
- tokens.add("*");
- }
-
- // Iterate through the queue names
- for (Iterator i=tokens.iterator(); i.hasNext();) {
- List queueList = JmxMBeansUtil.queryMBeans(useJmxServiceUrl(), "Type=Queue,Destination=" + i.next() + ",*");
-
- for (Iterator j=queueList.iterator(); j.hasNext();) {
- ObjectName queueName = ((ObjectInstance)j.next()).getObjectName();
- if (queryAddObjects.isEmpty()) {
- purgeQueue(queueName);
- } else {
- List messages = JmxMBeansUtil.createMessageQueryFilter(useJmxServiceUrl(), queueName).query(queryAddObjects);
- purgeMessages(queueName, messages);
- }
- }
- }
- } catch (Exception e) {
- GlobalWriter.printException(new RuntimeException("Failed to execute purge task. Reason: " + e));
- throw new Exception(e);
- }
- }
-
- /**
- * Purge all the messages in the queue
- * @param queue - ObjectName of the queue to purge
- * @throws Exception
- */
- public void purgeQueue(ObjectName queue) throws Exception {
- JMXConnector conn = createJmxConnector();
- MBeanServerConnection server = conn.getMBeanServerConnection();
- GlobalWriter.printInfo("Purging all messages in queue: " + queue.getKeyProperty("Destination"));
- server.invoke(queue, "purge", new Object[] {}, new String[] {});
- conn.close();
- }
-
- /**
- * 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
- */
- public void purgeMessages(ObjectName queue, List messages) throws Exception {
- JMXConnector conn = createJmxConnector();
- MBeanServerConnection server = conn.getMBeanServerConnection();
-
- Object[] param = new Object[1];
- 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"});
- }
-
- conn.close();
- }
-
- /**
- * 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 {
- // 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 (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
- GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
- return;
- }
-
- StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
- while (queryTokens.hasMoreTokens()) {
- queryAddObjects.add(queryTokens.nextToken());
- }
- }
-
- // If token is a substractive message selector option
- else if (token.startsWith("--xmsgsel")) {
-
- // 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;
- }
-
- StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
- while (queryTokens.hasMoreTokens()) {
- querySubObjects.add(queryTokens.nextToken());
- }
-
- }
-
- // Let super class handle unknown option
- else {
- super.handleOption(token, tokens);
- }
- }
-
- /**
- * Print the help messages for the browse command
- */
- protected void printHelp() {
- 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 ''",
- "",
- };
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.console.command;
+
+import org.apache.activemq.console.formatter.GlobalWriter;
+import org.apache.activemq.console.util.JmxMBeansUtil;
+
+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;
+
+public class PurgeCommand extends AbstractJmxCommand {
+
+ private final List queryAddObjects = new ArrayList(10);
+ private final List querySubObjects = new ArrayList(10);
+
+ /**
+ * 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 {
+ try {
+ // If there is no queue name specified, let's select all
+ if (tokens.isEmpty()) {
+ tokens.add("*");
+ }
+
+ // Iterate through the queue names
+ for (Iterator i=tokens.iterator(); i.hasNext();) {
+ List queueList = JmxMBeansUtil.queryMBeans(useJmxServiceUrl(), "Type=Queue,Destination=" + i.next() + ",*");
+
+ for (Iterator j=queueList.iterator(); j.hasNext();) {
+ ObjectName queueName = ((ObjectInstance)j.next()).getObjectName();
+ if (queryAddObjects.isEmpty()) {
+ purgeQueue(queueName);
+ } else {
+ List messages = JmxMBeansUtil.createMessageQueryFilter(useJmxServiceUrl(), queueName).query(queryAddObjects);
+ purgeMessages(queueName, messages);
+ }
+ }
+ }
+ } catch (Exception e) {
+ GlobalWriter.printException(new RuntimeException("Failed to execute purge task. Reason: " + e));
+ throw new Exception(e);
+ }
+ }
+
+ /**
+ * Purge all the messages in the queue
+ * @param queue - ObjectName of the queue to purge
+ * @throws Exception
+ */
+ public void purgeQueue(ObjectName queue) throws Exception {
+ JMXConnector conn = createJmxConnector();
+ MBeanServerConnection server = conn.getMBeanServerConnection();
+ GlobalWriter.printInfo("Purging all messages in queue: " + queue.getKeyProperty("Destination"));
+ server.invoke(queue, "purge", new Object[] {}, new String[] {});
+ conn.close();
+ }
+
+ /**
+ * 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
+ */
+ public void purgeMessages(ObjectName queue, List messages) throws Exception {
+ JMXConnector conn = createJmxConnector();
+ MBeanServerConnection server = conn.getMBeanServerConnection();
+
+ Object[] param = new Object[1];
+ 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"});
+ }
+
+ conn.close();
+ }
+
+ /**
+ * 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 {
+ // 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 (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
+ GlobalWriter.printException(new IllegalArgumentException("Message selector not specified"));
+ return;
+ }
+
+ StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
+ while (queryTokens.hasMoreTokens()) {
+ queryAddObjects.add(queryTokens.nextToken());
+ }
+ }
+
+ // If token is a substractive message selector option
+ else if (token.startsWith("--xmsgsel")) {
+
+ // 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;
+ }
+
+ StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
+ while (queryTokens.hasMoreTokens()) {
+ querySubObjects.add(queryTokens.nextToken());
+ }
+
+ }
+
+ // Let super class handle unknown option
+ else {
+ super.handleOption(token, tokens);
+ }
+ }
+
+ /**
+ * Print the help messages for the browse command
+ */
+ protected void printHelp() {
+ 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 ''",
+ "",
+ };
+}
Propchange: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/PurgeCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
|