KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > console > command > ListCommand


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.console.command;
19
20 import org.apache.activemq.console.formatter.GlobalWriter;
21 import org.apache.activemq.console.util.JmxMBeansUtil;
22
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.HashSet JavaDoc;
26
27 public class ListCommand extends AbstractJmxCommand {
28
29     /**
30      * List all running brokers registered in the specified JMX context
31      * @param tokens - command arguments
32      * @throws Exception
33      */

34     protected void runTask(List JavaDoc tokens) throws Exception JavaDoc {
35         try {
36             Set JavaDoc propsView = new HashSet JavaDoc();
37             propsView.add("BrokerName");
38             GlobalWriter.printMBean(JmxMBeansUtil.filterMBeansView(JmxMBeansUtil.getAllBrokers(useJmxServiceUrl()), propsView));
39         } catch (Exception JavaDoc e) {
40             GlobalWriter.printException(new RuntimeException JavaDoc("Failed to execute list task. Reason: " + e));
41             throw new Exception JavaDoc(e);
42         }
43     }
44     
45     /**
46      * Print the help messages for the browse command
47      */

48     protected void printHelp() {
49         GlobalWriter.printHelp(helpFile);
50     }
51
52     protected String JavaDoc[] helpFile = new String JavaDoc[] {
53         "Task Usage: Main list [list-options]",
54         "Description: Lists all available broker in the specified JMX context.",
55         "",
56         "List Options:",
57         " --jmxurl <url> Set the JMX URL to connect to.",
58         " --version Display the version information.",
59         " -h,-?,--help Display the stop broker help information.",
60         ""
61     };
62 }
63
Popular Tags