activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r371880 [1/3] - in /incubator/activemq/trunk: activemq-core/src/main/java/org/apache/activemq/broker/ activemq-core/src/main/java/org/apache/activemq/broker/console/ activemq-core/src/main/java/org/apache/activemq/broker/console/command/ ac...
Date Tue, 24 Jan 2006 10:24:03 GMT
Author: aco
Date: Tue Jan 24 02:23:34 2006
New Revision: 371880

URL: http://svn.apache.org/viewcvs?rev=371880&view=rev
Log:
- Added task to browse a queue for messages that includes the ability to query for selected messages only, and specify the properties to view. (Still considering adding one for topics too)
- Redesigned the querying mechanism to allow easy insertion and/or extension of specific querying filters
- Redesigned the output mechanism to allow easy inclusion of different output formatters (i.e. output in command shell friendly format, script friendly format, xml format, etc.)
- Currently have just included a not-so-friendly command shell formatter. :) Have plans to modify this and maybe include an xml formatter and/or script friendly formatter.

PS: I plan to move the console package outside activemq-core and include some unit tests with it sometime in the very near future. I know its kinda messy right know. :)

Added:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/AmqMessagesUtil.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/JmxMBeansUtil.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractAmqCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractJmxCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/BrowseCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/Command.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ListCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/QueryCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ShellCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ShutdownCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/StartCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/AbstractQueryFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/GroupPropertiesViewFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/MBeansAttributeQueryFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/MBeansObjectNameQueryFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/MBeansRegExQueryFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/MapTransformFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/MessagesQueryFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/PropertiesViewFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/QueryFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/RegExQueryFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/ResultTransformFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/StubQueryFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/WildcardToMsgSelectorTransformFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/WildcardToRegExTransformFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/WildcardTransformFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/formatter/
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/formatter/CommandShellOutputFormatter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/formatter/GlobalWriter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/formatter/OutputFormatter.java
    incubator/activemq/trunk/assembly/src/release/bin/browse
    incubator/activemq/trunk/assembly/src/release/bin/browse.bat
Removed:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/AbstractCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/AbstractJmxCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/AmqJmxSupport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/Command.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/DefaultCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/ListCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/QueryCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/ShutdownCommand.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/StartCommand.java
Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/Main.java
    incubator/activemq/trunk/assembly/src/release/bin/bstat
    incubator/activemq/trunk/assembly/src/release/bin/bstat.bat

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/Main.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/Main.java?rev=371880&r1=371879&r2=371880&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/Main.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/Main.java Tue Jan 24 02:23:34 2006
@@ -40,7 +40,7 @@
  */
 public class Main {
 
-    public static final String TASK_DEFAULT_CLASS  = "org.apache.activemq.broker.console.DefaultCommand";
+    public static final String TASK_DEFAULT_CLASS  = "org.apache.activemq.broker.console.command.ShellCommand";
 
     private File          activeMQHome;
     private ClassLoader   classLoader;
@@ -74,56 +74,52 @@
         if (tokens.isEmpty()) {
             return;
         }
-        int tokencnt = tokens.size();
-        String token = (String) tokens.remove(0);
 
-        for (int processedcnt = 0; processedcnt < tokencnt; processedcnt++)
-        {
+        int count = tokens.size();
+        int i = 0;
+
+        // Parse for all --extdir and --noDefExt options
+        while (i < count) {
+            String token = (String)tokens.get(i);
             // If token is an extension dir option
             if (token.equals("--extdir")) {
+                // Process token
+                count--;
+                tokens.remove(i);
 
                 // If no extension directory is specified, or next token is another option
-                if (!tokens.isEmpty()) {
-                    token = (String) tokens.remove(0);
-                    if (token.startsWith("-"))
-                    {
-                        System.out.println("Extension directory not specified.");
-                        System.out.println("Ignoring extension directory option.");
-                        continue;
-                    }
-                } else
-                {
-                    break;
+                if (i >= count || ((String)tokens.get(i)).startsWith("-")) {
+                    System.out.println("Extension directory not specified.");
+                    System.out.println("Ignoring extension directory option.");
+                    continue;
                 }
 
-                // Process token
-                processedcnt++;
-                
+                // Process extension dir token
+                count--;
+                File extDir = new File((String)tokens.remove(i));
+
                 if(!canUseExtdir()) {
                     System.out.println("Extension directory feature not available due to the system classpath being able to load: " + TASK_DEFAULT_CLASS);
                     System.out.println("Ignoring extension directory option.");
-                } else
-                {
-                    // Process extension dir token
-                    File extDir = new File(token);
-
-                    if (!extDir.isDirectory()) {
-                        System.out.println("Extension directory specified is not valid directory: " + extDir);
-                        System.out.println("Ignoring extension directory option.");
-                        continue;
-                    }
+                    continue;
+                }
 
-                    addExtensionDirectory(extDir);
+                if (!extDir.isDirectory()) {
+                    System.out.println("Extension directory specified is not valid directory: " + extDir);
+                    System.out.println("Ignoring extension directory option.");
+                    continue;
                 }
+
+                addExtensionDirectory(extDir);
             } else if (token.equals("--noDefExt")) { // If token is --noDefExt option
-                System.out.println("Bypassing default ext add.");
+                count--;
+                tokens.remove(i);
                 useDefExt = false;
-            } else
-            {
-                break;
+            } else {
+                i++;
             }
-            if (!tokens.isEmpty()) token = (String) tokens.remove(0);
-        }
+		}
+
     }
 
     public void runTaskClass(List tokens) throws Throwable {
@@ -139,8 +135,6 @@
             runTask.invoke(task.newInstance(), new Object[] { args, System.in, System.out });
         } catch (InvocationTargetException e) {
             throw e.getCause();
-        } catch (Throwable e) {
-            throw e;
         }
     }
 

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/AmqMessagesUtil.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/AmqMessagesUtil.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/AmqMessagesUtil.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/AmqMessagesUtil.java Tue Jan 24 02:23:34 2006
@@ -0,0 +1,64 @@
+/**
+ *
+ * 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.broker.console;
+
+import org.apache.activemq.broker.console.filter.QueryFilter;
+import org.apache.activemq.broker.console.filter.WildcardToMsgSelectorTransformFilter;
+import org.apache.activemq.broker.console.filter.MessagesQueryFilter;
+import org.apache.activemq.broker.console.filter.PropertiesViewFilter;
+import org.apache.activemq.broker.console.filter.StubQueryFilter;
+import org.apache.activemq.broker.console.filter.MapTransformFilter;
+import org.apache.activemq.broker.console.filter.GroupPropertiesViewFilter;
+
+import javax.jms.Destination;
+import java.net.URI;
+import java.util.List;
+import java.util.Set;
+
+public class AmqMessagesUtil {
+    public static final String JMS_MESSAGE_HEADER_PREFIX = "JMS_HEADER_FIELD:";
+    public static final String JMS_MESSAGE_CUSTOM_PREFIX = "JMS_CUSTOM_FIELD:";
+    public static final String JMS_MESSAGE_BODY_PREFIX   = "JMS_BODY_FIELD:";
+
+    public static List getAllMessages(URI brokerUrl, Destination dest) throws Exception {
+       return getMessages(brokerUrl, dest, "");
+    }
+
+    public static List getMessages(URI brokerUrl, Destination dest, String selector) throws Exception {
+        return createMessageQueryFilter(brokerUrl, dest).query(selector);
+    }
+
+    public static List getMessages(URI brokerUrl, Destination dest, List selectors) throws Exception {
+        return createMessageQueryFilter(brokerUrl, dest).query(selectors);
+    }
+
+    public static List filterMessagesView(List messages, Set groupViews, Set attributeViews) throws Exception {
+        return (new PropertiesViewFilter(attributeViews,
+            new GroupPropertiesViewFilter(groupViews,
+                new MapTransformFilter(
+                    new StubQueryFilter(messages)
+                )
+            )
+        )).query("");
+    }
+
+    public static QueryFilter createMessageQueryFilter(URI brokerUrl, Destination dest) {
+        return new WildcardToMsgSelectorTransformFilter(
+            new MessagesQueryFilter(brokerUrl, dest)
+        );
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/JmxMBeansUtil.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/JmxMBeansUtil.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/JmxMBeansUtil.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/JmxMBeansUtil.java Tue Jan 24 02:23:34 2006
@@ -0,0 +1,116 @@
+/**
+ *
+ * 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.broker.console;
+
+import org.apache.activemq.broker.console.filter.QueryFilter;
+import org.apache.activemq.broker.console.filter.MBeansObjectNameQueryFilter;
+import org.apache.activemq.broker.console.filter.WildcardToRegExTransformFilter;
+import org.apache.activemq.broker.console.filter.MBeansRegExQueryFilter;
+import org.apache.activemq.broker.console.filter.MBeansAttributeQueryFilter;
+import org.apache.activemq.broker.console.filter.PropertiesViewFilter;
+import org.apache.activemq.broker.console.filter.StubQueryFilter;
+import org.apache.activemq.broker.console.filter.MapTransformFilter;
+
+import javax.management.remote.JMXServiceURL;
+import java.util.Set;
+import java.util.List;
+import java.util.Iterator;
+
+public class JmxMBeansUtil {
+
+    public static List getAllBrokers(JMXServiceURL jmxUrl) throws Exception {
+        return (new MBeansObjectNameQueryFilter(jmxUrl)).query("Type=Broker");
+    }
+
+    public static List getBrokersByName(JMXServiceURL jmxUrl, String brokerName) throws Exception {
+        return (new MBeansObjectNameQueryFilter(jmxUrl)).query("Type=Broker,BrokerName=" + brokerName);
+    }
+
+    public static List getAllBrokers(JMXServiceURL jmxUrl, Set attributes) throws Exception {
+        return (new MBeansAttributeQueryFilter(jmxUrl, attributes, new MBeansObjectNameQueryFilter(jmxUrl))).query("Type=Broker");
+    }
+
+    public static List getBrokersByName(JMXServiceURL jmxUrl, String brokerName, Set attributes) throws Exception {
+        return (new MBeansAttributeQueryFilter(jmxUrl, attributes, new MBeansObjectNameQueryFilter(jmxUrl))).query("Type=Broker,BrokerName=" + brokerName);
+    }
+
+    public static List queryMBeans(JMXServiceURL jmxUrl, List queryList) throws Exception {
+        // If there is no query defined get all mbeans
+        if (queryList==null || queryList.size()==0) {
+            return createMBeansObjectNameQuery(jmxUrl).query("");
+
+        // Parse through all the query strings
+        } else {
+            return createMBeansObjectNameQuery(jmxUrl).query(queryList);
+        }
+    }
+
+    public static List queryMBeans(JMXServiceURL jmxUrl, List queryList, Set attributes) throws Exception {
+        // If there is no query defined get all mbeans
+        if (queryList==null || queryList.size()==0) {
+            return createMBeansAttributeQuery(jmxUrl, attributes).query("");
+
+        // Parse through all the query strings
+        } else {
+            return createMBeansAttributeQuery(jmxUrl, attributes).query(queryList);
+        }
+    }
+
+    public static List queryMBeans(JMXServiceURL jmxUrl, String queryString) throws Exception {
+        return createMBeansObjectNameQuery(jmxUrl).query(queryString);
+    }
+
+    public static List queryMBeans(JMXServiceURL jmxUrl, String queryString, Set attributes) throws Exception {
+        return createMBeansAttributeQuery(jmxUrl, attributes).query(queryString);
+    }
+
+    public static List filterMBeansView(List mbeans, Set viewFilter) throws Exception {
+        return (new PropertiesViewFilter(viewFilter, new MapTransformFilter(new StubQueryFilter(mbeans))).query(""));
+    }
+
+    public static String createQueryString(String query, String param) {
+        return query.replaceAll("%1", param);
+    }
+
+    public static String createQueryString(String query, List params) {
+
+        int count = 1;
+        for (Iterator i=params.iterator();i.hasNext();) {
+            query.replaceAll("%" + count++, i.next().toString());
+        }
+
+        return query;
+    }
+
+    public static QueryFilter createMBeansObjectNameQuery(JMXServiceURL jmxUrl) {
+        return new WildcardToRegExTransformFilter(       // Let us be able to accept wildcard queries
+            new MBeansRegExQueryFilter(                  // Use regular expressions to filter the query results
+                new MBeansObjectNameQueryFilter(jmxUrl)  // Let us retrieve the mbeans object name specified by the query
+            )
+        );
+    }
+
+    public static QueryFilter createMBeansAttributeQuery(JMXServiceURL jmxUrl, Set attributes) {
+        return new WildcardToRegExTransformFilter(                  // Let use be able to accept wildcard queries
+            new MBeansRegExQueryFilter(                             // Use regular expressions to filter the query result
+                new MBeansAttributeQueryFilter(jmxUrl, attributes,  // Retrieve the attributes needed
+                    new MBeansObjectNameQueryFilter(jmxUrl)         // Retrieve the mbeans object name specified by the query
+                )
+            )
+        );
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractAmqCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractAmqCommand.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractAmqCommand.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractAmqCommand.java Tue Jan 24 02:23:34 2006
@@ -0,0 +1,156 @@
+/**
+ *
+ * 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.broker.console.command;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.console.formatter.GlobalWriter;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+public abstract class AbstractAmqCommand extends AbstractCommand {
+    private URI brokerUrl;
+    private ConnectionFactory factory;
+    private final List connections = new ArrayList();
+
+    /**
+     * Establishes a connection to the remote broker specified by the broker url.
+     * @return - connection to the broker
+     * @throws JMSException
+     */
+    protected Connection createConnection() throws JMSException {
+        if (getBrokerUrl() == null) {
+            GlobalWriter.printException(new IllegalStateException("You must specify a broker URL to connect to using the --amqurl option."));
+            return null;
+        }
+
+        if (factory == null) {
+            factory = new ActiveMQConnectionFactory(getBrokerUrl());
+        }
+
+        Connection conn = factory.createConnection();
+        connections.add(conn);
+
+        return conn;
+    }
+
+    /**
+     * Establishes a connection to the remote broker specified by the broker url.
+     * @param username - username for the connection
+     * @param password - password for the connection
+     * @return - connection to the broker
+     * @throws JMSException
+     */
+    protected Connection createConnection(String username, String password) throws JMSException {
+        if (getBrokerUrl() == null) {
+            GlobalWriter.printException(new IllegalStateException("You must specify a broker URL to connect to using the --amqurl option."));
+            return null;
+        }
+
+        if (factory == null) {
+            factory = new ActiveMQConnectionFactory(getBrokerUrl());
+        }
+
+        Connection conn = factory.createConnection(username, password);
+        connections.add(conn);
+        conn.start();
+
+        return conn;
+    }
+
+    /**
+     * Close all created connections.
+     */
+    protected void closeAllConnections() {
+        for (Iterator i=connections.iterator(); i.hasNext();) {
+            try {
+                ((Connection)i.next()).close();
+            } catch (Exception e) { }
+        }
+
+        connections.clear();
+    }
+
+    /**
+     * Handle the --amqurl option.
+     * @param token - current option
+     * @param tokens - succeeding list of arguments
+     * @throws Exception
+     */
+    protected void handleOption(String token, List tokens) throws Exception {
+        // Try to handle the options first
+        if (token.equals("--amqurl")) {
+            // If no broker url specified, or next token is a new option
+            if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
+                GlobalWriter.printException(new IllegalArgumentException("Broker URL not specified."));
+                tokens.clear();
+                return;
+            }
+
+            // If broker url already specified
+            if (getBrokerUrl() != null) {
+                GlobalWriter.printException(new IllegalArgumentException("Multiple broker URL cannot be specified."));
+                tokens.clear();
+                return;
+            }
+
+            String strBrokerUrl = (String)tokens.remove(0);
+
+            try {
+                setBrokerUrl(new URI(strBrokerUrl));
+            } catch (URISyntaxException e) {
+                GlobalWriter.printException(e);
+                tokens.clear();
+                return;
+            }
+        } else {
+            // Let the super class handle the option
+            super.handleOption(token, tokens);
+        }
+    }
+
+    /**
+     * Set the broker url.
+     * @param brokerUrl - new broker url
+     */
+    protected void setBrokerUrl(URI brokerUrl) {
+        this.brokerUrl = brokerUrl;
+    }
+
+    /**
+     * Set the broker url.
+     * @param address - address of the new broker url
+     * @throws URISyntaxException
+     */
+    protected void setBrokerUrl(String address) throws URISyntaxException {
+        this.brokerUrl = new URI(address);
+    }
+
+    /**
+     * Get the current broker url.
+     * @return current broker url
+     */
+    protected URI getBrokerUrl() {
+        return brokerUrl;
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractCommand.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractCommand.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractCommand.java Tue Jan 24 02:23:34 2006
@@ -0,0 +1,120 @@
+/**
+ *
+ * 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.broker.console.command;
+
+import org.apache.activemq.ActiveMQConnectionMetaData;
+import org.apache.activemq.broker.console.formatter.GlobalWriter;
+
+import java.util.List;
+
+public abstract class AbstractCommand implements Command {
+    public static final String COMMAND_OPTION_DELIMETER = ",";
+
+    private boolean isPrintHelp    = false;
+    private boolean isPrintVersion = false;
+
+    /**
+     * Exceute a generic command, which includes parsing the options for the command and running the specific task.
+     * @param tokens - command arguments
+     * @throws Exception
+     */
+    public void execute(List tokens) throws Exception {
+        // Parse the options specified by "-"
+        parseOptions(tokens);
+
+        // Print the help file of the task
+        if (isPrintHelp) {
+            printHelp();
+
+        // Print the AMQ version
+        } else if (isPrintVersion) {
+            GlobalWriter.printVersion(ActiveMQConnectionMetaData.PROVIDER_VERSION);
+
+        // Run the specified task
+        } else {
+            runTask(tokens);
+        }
+    }
+
+    /**
+     * Parse any option parameters in the command arguments specified by a '-' as the first character of the token.
+     * @param tokens - command arguments
+     * @throws Exception
+     */
+    protected void parseOptions(List tokens) throws Exception {
+        while (!tokens.isEmpty()) {
+            String token = (String)tokens.remove(0);
+            if (token.startsWith("-")) {
+                // Token is an option
+                handleOption(token, tokens);
+            } else {
+                // Push back to list of tokens
+                tokens.add(0, token);
+                return;
+            }
+        }
+    }
+
+    /**
+     * Handle the general options for each command, which includes -h, -?, --help, -D, --version.
+     * @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 a help option
+        if (token.equals("-h") || token.equals("-?") || token.equals("--help")) {
+            isPrintHelp = true;
+            tokens.clear();
+
+        // If token is a version option
+        } else if (token.equals("--version")) {
+            isPrintVersion = true;
+            tokens.clear();
+        }
+
+        // If token is a system property define option
+        else if (token.startsWith("-D")) {
+            String key = token.substring(2);
+            String value = "";
+            int pos = key.indexOf("=");
+            if (pos >= 0) {
+                value = key.substring(pos + 1);
+                key = key.substring(0, pos);
+            }
+            System.setProperty(key, value);
+
+        }
+
+        // Token is unrecognized
+        else {
+            GlobalWriter.printInfo("Ignoring unrecognized option: " + token);
+        }
+    }
+
+    /**
+     * Run the specific task.
+     * @param tokens - command arguments
+     * @throws Exception
+     */
+    abstract protected void runTask(List tokens) throws Exception;
+
+    /**
+     * Print the help messages for the specific task
+     */
+    abstract protected void printHelp();
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractJmxCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractJmxCommand.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractJmxCommand.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/AbstractJmxCommand.java Tue Jan 24 02:23:34 2006
@@ -0,0 +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.broker.console.command;
+
+import org.apache.activemq.broker.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);
+        }
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/BrowseCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/BrowseCommand.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/BrowseCommand.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/BrowseCommand.java Tue Jan 24 02:23:34 2006
@@ -0,0 +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.broker.console.command;
+
+import org.apache.activemq.broker.console.AmqMessagesUtil;
+import org.apache.activemq.broker.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 BrowseCommand 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 ''",
+        "",
+    };
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/Command.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/Command.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/Command.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/Command.java Tue Jan 24 02:23:34 2006
@@ -0,0 +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.broker.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;
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ListCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ListCommand.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ListCommand.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ListCommand.java Tue Jan 24 02:23:34 2006
@@ -0,0 +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.broker.console.command;
+
+import org.apache.activemq.broker.console.formatter.GlobalWriter;
+import org.apache.activemq.broker.console.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.",
+        ""
+    };
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/QueryCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/QueryCommand.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/QueryCommand.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/QueryCommand.java Tue Jan 24 02:23:34 2006
@@ -0,0 +1,229 @@
+/**
+ *
+ * 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.broker.console.command;
+
+import org.apache.activemq.broker.console.JmxMBeansUtil;
+import org.apache.activemq.broker.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;
+
+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("NetworkConnector", "Type=NetworkConnector,BrokerName=%1,*");
+        PREDEFINED_OBJNAME_QUERY.setProperty("Queue",            "Type=Queue,Destination=%1,*");
+        PREDEFINED_OBJNAME_QUERY.setProperty("Topic",            "Type=Topic,Destination=%1,*");
+    };
+
+    private final List queryAddObjects = new ArrayList(10);
+    private final List querySubObjects = new ArrayList(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 {
+        try {
+            // Query for the mbeans to add
+            List addMBeans = JmxMBeansUtil.queryMBeans(useJmxServiceUrl(), queryAddObjects, queryViews);
+
+            // Query for the mbeans to sub
+            if (querySubObjects.size() > 0) {
+                List subMBeans = JmxMBeansUtil.queryMBeans(useJmxServiceUrl(), querySubObjects, queryViews);
+                addMBeans.removeAll(subMBeans);
+            }
+
+
+            GlobalWriter.printMBean(JmxMBeansUtil.filterMBeansView(addMBeans, queryViews));
+
+        } catch (Exception e) {
+            GlobalWriter.printException(new RuntimeException("Failed to execute query task. Reason: " + e));
+            throw new Exception(e);
+        }
+    }
+
+    /**
+     * 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 {
+        // If token is a additive predefined query define option
+        if (token.startsWith("-Q")) {
+            String key = token.substring(2);
+            String value = "";
+            int pos = key.indexOf("=");
+            if (pos >= 0) {
+                value = key.substring(pos + 1);
+                key = key.substring(0, pos);
+            }
+
+            // If additive query
+            String predefQuery = PREDEFINED_OBJNAME_QUERY.getProperty(key);
+            if (predefQuery == null) {
+                GlobalWriter.printException(new IllegalArgumentException("Unknown query object type: " + key));
+                return;
+            }
+            String queryStr = JmxMBeansUtil.createQueryString(predefQuery, value);
+            queryAddObjects.add(queryStr);
+        }
+
+        // If token is a substractive predefined query define option
+        else if (token.startsWith("-xQ")) {
+            String key = token.substring(3);
+            String value = "";
+            int pos = key.indexOf("=");
+            if (pos >= 0) {
+                value = key.substring(pos + 1);
+                key = key.substring(0, pos);
+            }
+
+            // If subtractive query
+            String predefQuery = PREDEFINED_OBJNAME_QUERY.getProperty(key);
+            if (predefQuery == null) {
+                GlobalWriter.printException(new IllegalArgumentException("Unknown query object type: " + key));
+                return;
+            }
+            String queryStr = JmxMBeansUtil.createQueryString(predefQuery, value);
+            querySubObjects.add(queryStr);
+        }
+
+        // If token is an additive object name query option
+        else if (token.startsWith("--objname")) {
+
+            // 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;
+            }
+
+            StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
+            while (queryTokens.hasMoreTokens()) {
+                queryAddObjects.add(queryTokens.nextToken());
+            }
+        }
+
+        // If token is a substractive object name query option
+        else if (token.startsWith("--xobjname")) {
+
+            // 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;
+            }
+
+            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
+            Enumeration viewTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
+            while (viewTokens.hasMoreElements()) {
+                queryViews.add(viewTokens.nextElement());
+            }
+        }
+
+        // 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 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:",
+        "    Main query",
+        "        - Print all the attributes of all registered objects queues, topics, connections, etc).",
+        "",
+        "    Main query -QQueue=TEST.FOO",
+        "        - Print all the attributes of the queue with destination name TEST.FOO.",
+        "",
+        "    Main query -QTopic=*",
+        "        - Print all the attributes of all registered topics.",
+        "",
+        "    Main query --view EnqueueCount,DequeueCount",
+        "        - Print the attributes EnqueueCount and DequeueCount of all registered objects.",
+        "",
+        "    Main -QTopic=* --view EnqueueCount,DequeueCount",
+        "        - Print the attributes EnqueueCount and DequeueCount of all registered topics.",
+        "",
+        "    Main -QTopic=* -QQueue=* --view EnqueueCount,DequeueCount",
+        "        - Print the attributes EnqueueCount and DequeueCount of all registered topics and",
+        "          queues.",
+        "",
+        "    Main -QTopic=* -xQTopic=ActiveMQ.Advisory.*",
+        "        - Print all attributes of all topics except those that has a name that begins",
+        "          with \"ActiveMQ.Advisory\".",
+        "",
+        "    Main --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.",
+        "",
+        "    Main -QQueue=* -xQQueue=????",
+        "        - Print all attributes of all queues except those that are 4 letters long.",
+        "",
+    };
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ShellCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ShellCommand.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ShellCommand.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ShellCommand.java Tue Jan 24 02:23:34 2006
@@ -0,0 +1,110 @@
+/**
+ *
+ * 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.broker.console.command;
+
+import org.apache.activemq.broker.console.formatter.GlobalWriter;
+import org.apache.activemq.broker.console.formatter.CommandShellOutputFormatter;
+
+import java.util.List;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.io.InputStream;
+import java.io.PrintStream;
+
+public class ShellCommand extends AbstractCommand {
+
+    /**
+     * 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
+     * @return 0 for a successful run, -1 if there are any exception
+     */
+    public static int main(String[] args, InputStream in, PrintStream out) {
+        GlobalWriter.instantiate(new CommandShellOutputFormatter(out));
+
+        // Convert arguments to list for easier management
+        List tokens = new ArrayList(Arrays.asList(args));
+
+        ShellCommand main = new ShellCommand();
+        try {
+            main.execute(tokens);
+            return 0;
+        } catch (Exception e) {
+            GlobalWriter.printException(e);
+            return -1;
+        }
+    }
+
+    /**
+     * Parses for specific command task, default task is a start task.
+     * @param tokens - command arguments
+     * @throws Exception
+     */
+    protected void runTask(List tokens) throws Exception {
+        
+        // Process task token
+        if( tokens.size() > 0 ) {
+            String taskToken = (String)tokens.remove(0);
+            if (taskToken.equals("start")) {
+                new StartCommand().execute(tokens);
+            } else if (taskToken.equals("stop")) {
+                new ShutdownCommand().execute(tokens);
+            } else if (taskToken.equals("list")) {
+                new ListCommand().execute(tokens);
+            } else if (taskToken.equals("query")) {
+                new QueryCommand().execute(tokens);
+            } else if (taskToken.equals("browse")) {
+                new BrowseCommand().execute(tokens);
+            } else {
+                // If not valid task, push back to list
+                tokens.add(0, taskToken);
+                new StartCommand().execute(tokens);
+            }
+        } else {
+            new StartCommand().execute(tokens);
+        }
+        
+    }
+
+    /**
+     * Print the help messages for the browse command
+     */
+    protected void printHelp() {
+        GlobalWriter.printHelp(helpFile);
+    }
+
+    protected String[] helpFile = new String[] {
+        "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 Main [task] -h,-?,--help",
+        "",
+        "Task Data:",
+        "    - Information needed by each specific task.",
+        ""
+    };
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ShutdownCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ShutdownCommand.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ShutdownCommand.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/ShutdownCommand.java Tue Jan 24 02:23:34 2006
@@ -0,0 +1,161 @@
+/**
+ *
+ * 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.broker.console.command;
+
+import org.apache.activemq.broker.console.JmxMBeansUtil;
+import org.apache.activemq.broker.console.formatter.GlobalWriter;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.ObjectInstance;
+import javax.management.remote.JMXServiceURL;
+import java.util.List;
+import java.util.Iterator;
+import java.util.Collection;
+import java.util.HashSet;
+
+public class ShutdownCommand extends AbstractJmxCommand {
+    private boolean isStopAllBrokers = false;
+
+    /**
+     * Shuts down the specified broker or brokers
+     * @param brokerNames - names of brokers to shutdown
+     * @throws Exception
+     */
+    protected void runTask(List brokerNames) throws Exception {
+        try {
+            Collection mbeans;
+
+            // Stop all brokers
+            if (isStopAllBrokers) {
+                mbeans = JmxMBeansUtil.getAllBrokers(useJmxServiceUrl());
+                brokerNames.clear();
+            }
+
+            // Stop the default broker
+            else if (brokerNames.isEmpty()) {
+                mbeans = JmxMBeansUtil.getAllBrokers(useJmxServiceUrl());
+
+                // If there is no broker to stop
+                if (mbeans.isEmpty()) {
+                    GlobalWriter.printInfo("There are no brokers to stop.");
+                    return;
+
+                // 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
+                } else {
+                    Object firstBroker = mbeans.iterator().next();
+                    mbeans.clear();
+                    mbeans.add(firstBroker);
+                }
+            }
+
+            // Stop each specified broker
+            else {
+                String brokerName;
+                mbeans = new HashSet();
+                while (!brokerNames.isEmpty()) {
+                    brokerName = (String)brokerNames.remove(0);
+                    Collection matchedBrokers = JmxMBeansUtil.getBrokersByName(useJmxServiceUrl(), brokerName);
+                    if (matchedBrokers.isEmpty()) {
+                        GlobalWriter.printInfo(brokerName + " did not match any running brokers.");
+                    } else {
+                        mbeans.addAll(matchedBrokers);
+                    }
+                }
+            }
+
+            // Stop all brokers in set
+            stopBrokers(useJmxServiceUrl(), mbeans);
+        } catch (Exception e) {
+            GlobalWriter.printException(new RuntimeException("Failed to execute stop task. Reason: " + e));
+            throw new Exception(e);
+        }
+    }
+
+    /**
+     * Stops the list of brokers.
+     * @param jmxServiceUrl - JMX service url to connect to
+     * @param brokerBeans - broker mbeans to stop
+     * @throws Exception
+     */
+    protected void stopBrokers(JMXServiceURL jmxServiceUrl, Collection brokerBeans) throws Exception {
+        MBeanServerConnection server = createJmxConnector().getMBeanServerConnection();
+
+        ObjectName brokerObjName;
+        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[] {new Integer(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());
+            }
+        }
+
+        closeJmxConnector();
+    }
+
+    /**
+     * 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 {
+        // Try to handle the options first
+        if (token.equals("--all")) {
+            isStopAllBrokers = true;
+        } else {
+            // Let the super class handle the option
+            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 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.",
+        ""
+    };
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/StartCommand.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/StartCommand.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/StartCommand.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/command/StartCommand.java Tue Jan 24 02:23:34 2006
@@ -0,0 +1,168 @@
+/**
+ *
+ * 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.broker.console.command;
+
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.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";
+
+    private URI  configURI;
+    private List brokers = new ArrayList(5);
+
+    /**
+     * The default task to start a broker or a group of brokers
+     * @param brokerURIs
+     */
+    protected void runTask(List 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
+            } else {
+                String strConfigURI;
+
+                while (!brokerURIs.isEmpty()) {
+                    strConfigURI = (String)brokerURIs.remove(0);
+
+                    try {
+                        setConfigUri(new URI(strConfigURI));
+                    } catch (URISyntaxException e) {
+                        GlobalWriter.printException(e);
+                        return;
+                    }
+
+                    startBroker(getConfigUri());
+                }
+            }
+
+            // 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));
+            throw new Exception(e);
+        }
+    }
+
+    /**
+     * Create and run a broker specified by the given configuration URI
+     * @param configURI
+     * @throws Exception
+     */
+    public void startBroker(URI configURI) throws Exception {
+        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};
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            public void run() {
+                synchronized(shutdown) {
+                    shutdown[0]=true;
+                    shutdown.notify();
+                }
+            }
+        });
+
+        // Wait for any shutdown event
+        synchronized(shutdown) {
+            while( !shutdown[0] ) {
+                try {
+                    shutdown.wait();
+                } catch (InterruptedException e) {
+                }
+            }
+        }
+
+        // Stop each broker
+        for (Iterator i=brokers.iterator(); i.hasNext();) {
+            BrokerService broker = (BrokerService)i.next();
+            broker.stop();
+        }
+    }
+
+    /**
+     * Sets the current configuration URI used by the start task
+     * @param uri
+     */
+    public void setConfigUri(URI uri) {
+        configURI = uri;
+    }
+
+    /**
+     * Gets the current configuration URI used by the start task
+     * @return current configuration URI
+     */
+    public URI getConfigUri() {
+        return configURI;
+    }
+
+    /**
+     * Print the help messages for the browse command
+     */
+    protected void printHelp() {
+        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",
+        ""
+    };
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/AbstractQueryFilter.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/AbstractQueryFilter.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/AbstractQueryFilter.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/AbstractQueryFilter.java Tue Jan 24 02:23:34 2006
@@ -0,0 +1,45 @@
+/**
+ *
+ * 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.broker.console.filter;
+
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.Collections;
+
+public abstract class AbstractQueryFilter implements QueryFilter {
+    protected QueryFilter next;
+
+    /**
+     * Creates a query filter, with the next filter specified by next.
+     * @param next - the next query filter
+     */
+    protected AbstractQueryFilter(QueryFilter next) {
+        this.next = next;
+    }
+
+    /**
+     * Performs a query given the query string
+     * @param query - query string
+     * @return objects that matches the query
+     * @throws Exception
+     */
+    public List query(String query) throws Exception {
+        // Converts string query to map query
+        StringTokenizer tokens = new StringTokenizer(query, QUERY_DELIMETER);
+        return query(Collections.list(tokens));
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/GroupPropertiesViewFilter.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/GroupPropertiesViewFilter.java?rev=371880&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/GroupPropertiesViewFilter.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/console/filter/GroupPropertiesViewFilter.java Tue Jan 24 02:23:34 2006
@@ -0,0 +1,79 @@
+/**
+ *
+ * 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.broker.console.filter;
+
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+public class GroupPropertiesViewFilter extends PropertiesViewFilter {
+
+    /**
+     * 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) {
+        super(next);
+    }
+
+    /**
+     * 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
+     */
+    public GroupPropertiesViewFilter(Set groupView, QueryFilter next) {
+        super(groupView, next);
+    }
+
+    /**
+     * Filter the properties that matches the group prefix only.
+     * @param data - map data to filter
+     * @return - filtered map data
+     */
+    protected Map filterView(Map data) {
+        // If no view specified, display all attributes
+        if (viewFilter == null || viewFilter.isEmpty()) {
+            return data;
+        }
+
+        Map newData;
+        try {
+            // Lets try to use the same class as the original
+            newData = (Map)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();
+
+            // Checks if key matches any of the group filter
+            for (Iterator j=viewFilter.iterator(); j.hasNext();) {
+                String group = (String)j.next();
+                if (key.startsWith(group)) {
+                    newData.put(key, data.get(key));
+                    break;
+                }
+            }
+        }
+
+        return newData;
+    }
+}



Mime
View raw message