1 18 package org.apache.activemq.console.command; 19 20 import org.apache.activemq.console.formatter.GlobalWriter; 21 import org.apache.activemq.console.formatter.CommandShellOutputFormatter; 22 23 import java.util.List ; 24 import java.util.Arrays ; 25 import java.util.ArrayList ; 26 import java.io.InputStream ; 27 import java.io.PrintStream ; 28 29 public class ShellCommand extends AbstractCommand { 30 31 private boolean interactive; 32 private String [] helpFile; 33 34 35 public ShellCommand() { 36 this(false); 37 } 38 39 public ShellCommand(boolean interactive) { 40 this.interactive = interactive; 41 this.helpFile = new String []{ 42 (interactive ? "Usage: [task] [task-options] [task data]" : "Usage: Main [--extdir <dir>] [task] [task-options] [task data]"), 43 "", 44 "Tasks (default task is start):", 45 " start - Creates and starts a broker using a configuration file, or a broker URI.", 46 " stop - Stops a running broker specified by the broker name.", 47 " list - Lists all available brokers in the specified JMX context.", 48 " query - Display selected broker component's attributes and statistics.", 49 " browse - Display selected messages in a specified destination.", 50 "", 51 "Task Options (Options specific to each task):", 52 " --extdir <dir> - Add the jar files in the directory to the classpath.", 53 " --version - Display the version information.", 54 " -h,-?,--help - Display this help information. To display task specific help, use " + (interactive ? "" : "Main ") + "[task] -h,-?,--help", 55 "", 56 "Task Data:", 57 " - Information needed by each specific task.", 58 "" 59 }; 60 } 61 62 69 public static int main(String [] args, InputStream in, PrintStream out) { 70 GlobalWriter.instantiate(new CommandShellOutputFormatter(out)); 71 72 List tokens = new ArrayList (Arrays.asList(args)); 74 75 ShellCommand main = new ShellCommand(); 76 try { 77 main.execute(tokens); 78 return 0; 79 } catch (Exception e) { 80 GlobalWriter.printException(e); 81 return -1; 82 } 83 } 84 85 86 public boolean isInteractive() { 87 return interactive; 88 } 89 90 public void setInteractive(boolean interactive) { 91 this.interactive = interactive; 92 } 93 94 99 protected void runTask(List tokens) throws Exception { 100 101 if( tokens.size() > 0 ) { 103 String taskToken = (String )tokens.remove(0); 104 if (taskToken.equals("start")) { 105 new StartCommand().execute(tokens); 106 } else if (taskToken.equals("stop")) { 107 new ShutdownCommand().execute(tokens); 108 } else if (taskToken.equals("list")) { 109 new ListCommand().execute(tokens); 110 } else if (taskToken.equals("query")) { 111 new QueryCommand().execute(tokens); 112 } else if (taskToken.equals("bstat")) { 113 new BstatCommand().execute(tokens); 114 } else if (taskToken.equals("browse")) { 115 new AmqBrowseCommand().execute(tokens); 116 } else if (taskToken.equals("purge")) { 117 new PurgeCommand().execute(tokens); 118 } else if (taskToken.equals("help")) { 119 printHelp(); 120 } else { 121 printHelp(); 122 } 123 } else { 124 printHelp(); 125 } 126 127 } 128 129 132 protected void printHelp() { 133 GlobalWriter.printHelp(helpFile); 134 } 135 } 136 | Popular Tags |