mirror of https://github.com/apache/activemq.git
added a simple interactive console via SimpleConsole together with making the commands usable from the CommandAgent in activemq-core
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@475211 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
940850910d
commit
540ebc6651
|
@ -34,7 +34,7 @@ import java.io.ByteArrayOutputStream;
|
|||
*/
|
||||
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 @@ public class ConsoleCommandHandler implements CommandHandler {
|
|||
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) {
|
||||
|
|
|
@ -196,34 +196,34 @@ public class QueryCommand extends AbstractJmxCommand {
|
|||
" -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.",
|
||||
"",
|
||||
};
|
||||
|
|
|
@ -28,6 +28,17 @@ import java.io.PrintStream;
|
|||
|
||||
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 class ShellCommand extends AbstractCommand {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
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 @@ public class ShellCommand extends AbstractCommand {
|
|||
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);
|
||||
|
|
|
@ -45,6 +45,8 @@ public class MBeansRegExQueryFilter extends RegExQueryFilter {
|
|||
* @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});
|
||||
|
|
|
@ -39,9 +39,7 @@ public class GlobalWriter {
|
|||
* @param formatter - the output formatter to use
|
||||
*/
|
||||
public static void instantiate(OutputFormatter formatter) {
|
||||
if (GlobalWriter.formatter == null) {
|
||||
GlobalWriter.formatter = formatter;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue