You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2006/11/15 13:10:43 UTC

svn commit: r475211 - in /incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console: ./ command/ filter/ formatter/ util/

Author: jstrachan
Date: Wed Nov 15 04:10:41 2006
New Revision: 475211

URL: http://svn.apache.org/viewvc?view=rev&rev=475211
Log:
added a simple interactive console via SimpleConsole together with making the commands usable from the CommandAgent in activemq-core

Added:
    incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java   (with props)
Modified:
    incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java
    incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java
    incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java
    incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MBeansRegExQueryFilter.java
    incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/GlobalWriter.java

Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java?view=diff&rev=475211&r1=475210&r2=475211
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java Wed Nov 15 04:10:41 2006
@@ -34,7 +34,7 @@
  */
 public class ConsoleCommandHandler implements CommandHandler {
 
-    private ShellCommand command = new ShellCommand();
+    private ShellCommand command = new ShellCommand(true);
 
     public void processCommand(TextMessage request, TextMessage response) throws Exception {
 
@@ -42,14 +42,17 @@
         GlobalWriter.instantiate(new CommandShellOutputFormatter(out));
 
         // lets turn the text into a list of arguments
-        List tokens = tokenize(request.getText());
+        String requestText = request.getText();
+
+        List tokens = tokenize(requestText);
         command.execute(tokens);
 
         out.flush();
         byte[] bytes = out.toByteArray();
 
-        String text = new String(bytes);
-        response.setText(text);
+        String answer = new String(bytes);
+
+        response.setText(answer);
     }
 
     protected List tokenize(String text) {

Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java?view=diff&rev=475211&r1=475210&r2=475211
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java Wed Nov 15 04:10:41 2006
@@ -196,34 +196,34 @@
         "    -h,-?,--help                  Display the query broker help information.",
         "",
         "Examples:",
-        "    Main query",
+        "    query",
         "        - Print all the attributes of all registered objects queues, topics, connections, etc).",
         "",
-        "    Main query -QQueue=TEST.FOO",
+        "    query -QQueue=TEST.FOO",
         "        - Print all the attributes of the queue with destination name TEST.FOO.",
         "",
-        "    Main query -QTopic=*",
+        "    query -QTopic=*",
         "        - Print all the attributes of all registered topics.",
         "",
-        "    Main query --view EnqueueCount,DequeueCount",
+        "    query --view EnqueueCount,DequeueCount",
         "        - Print the attributes EnqueueCount and DequeueCount of all registered objects.",
         "",
-        "    Main -QTopic=* --view EnqueueCount,DequeueCount",
+        "    query -QTopic=* --view EnqueueCount,DequeueCount",
         "        - Print the attributes EnqueueCount and DequeueCount of all registered topics.",
         "",
-        "    Main -QTopic=* -QQueue=* --view EnqueueCount,DequeueCount",
+        "    query -QTopic=* -QQueue=* --view EnqueueCount,DequeueCount",
         "        - Print the attributes EnqueueCount and DequeueCount of all registered topics and",
         "          queues.",
         "",
-        "    Main -QTopic=* -xQTopic=ActiveMQ.Advisory.*",
+        "    query -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=*",
+        "    query --objname Type=*Connect*,BrokerName=local* -xQNetworkConnector=*",
         "        - Print all attributes of all connectors, connections excluding network connectors",
         "          that belongs to the broker that begins with local.",
         "",
-        "    Main -QQueue=* -xQQueue=????",
+        "    query -QQueue=* -xQQueue=????",
         "        - Print all attributes of all queues except those that are 4 letters long.",
         "",
     };

Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java?view=diff&rev=475211&r1=475210&r2=475211
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java Wed Nov 15 04:10:41 2006
@@ -28,6 +28,17 @@
 
 public class ShellCommand extends AbstractCommand {
 
+    private boolean interactive;
+
+
+    public ShellCommand() {
+        this(false);
+    }
+
+    public ShellCommand(boolean interactive) {
+        this.interactive = interactive;
+    }
+
     /**
      * Main method to run a command shell client.
      * @param args - command line arguments
@@ -51,6 +62,15 @@
         }
     }
 
+
+    public boolean isInteractive() {
+        return interactive;
+    }
+
+    public void setInteractive(boolean interactive) {
+        this.interactive = interactive;
+    }
+
     /**
      * Parses for specific command task, default task is a start task.
      * @param tokens - command arguments
@@ -73,6 +93,8 @@
                 new AmqBrowseCommand().execute(tokens);
             } else if (taskToken.equals("purge")) {
                 new PurgeCommand().execute(tokens);
+            } else if (taskToken.equals("help")) {
+                printHelp();
             } else {
                 // If not valid task, push back to list
                 tokens.add(0, taskToken);

Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MBeansRegExQueryFilter.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MBeansRegExQueryFilter.java?view=diff&rev=475211&r1=475210&r2=475211
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MBeansRegExQueryFilter.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MBeansRegExQueryFilter.java Wed Nov 15 04:10:41 2006
@@ -45,6 +45,8 @@
      * @throws Exception
      */
     protected boolean matches(Object data, Map regex) throws Exception {
+        // TODO why not just use instanceof?
+
         // Use reflection to determine where the object should go
         try {
             Method method = this.getClass().getDeclaredMethod("matches", new Class[] {data.getClass(), Map.class});

Modified: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/GlobalWriter.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/GlobalWriter.java?view=diff&rev=475211&r1=475210&r2=475211
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/GlobalWriter.java (original)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/formatter/GlobalWriter.java Wed Nov 15 04:10:41 2006
@@ -39,9 +39,7 @@
      * @param formatter - the output formatter to use
      */
     public static void instantiate(OutputFormatter formatter) {
-        if (GlobalWriter.formatter == null) {
             GlobalWriter.formatter = formatter;
-        }
     }
 
     /**

Added: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java?view=auto&rev=475211
==============================================================================
--- incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java (added)
+++ incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java Wed Nov 15 04:10:41 2006
@@ -0,0 +1,56 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.console.util;
+
+import org.apache.activemq.broker.util.CommandMessageListener;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+/**
+ * A simple interactive console which can be used to communicate with a running broker
+ * assuming that the classpath is fully setup
+ *
+ * @version $Revision$
+ */
+public class SimpleConsole {
+
+    public static void main(String[] args) {
+        CommandMessageListener listener = new CommandMessageListener(null);
+
+        try {
+            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+            while (true) {
+                String line = reader.readLine();
+                if (line == null || "quit".equalsIgnoreCase(line)) {
+                    break;
+                }
+                line = line.trim();
+                if (line.length() == 0) {
+                    continue;
+                }
+
+                System.out.println(listener.processCommandText(line));
+            }
+        }
+        catch (Exception e) {
+            System.out.println("Caught: " + e);
+            e.printStackTrace();
+        }
+    }
+}

Propchange: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain