001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.activemq.console.command;
018
019 import java.util.HashSet;
020 import java.util.List;
021 import java.util.Set;
022
023 import org.apache.activemq.console.util.JmxMBeansUtil;
024
025 public class ListCommand extends AbstractJmxCommand {
026
027 protected String[] helpFile = new String[] {
028 "Task Usage: Main list [list-options]",
029 "Description: Lists all available broker in the specified JMX context.",
030 "",
031 "List Options:",
032 " --jmxurl <url> Set the JMX URL to connect to.",
033 " --version Display the version information.",
034 " -h,-?,--help Display the stop broker help information.",
035 ""
036 };
037
038 /**
039 * List all running brokers registered in the specified JMX context
040 * @param tokens - command arguments
041 * @throws Exception
042 */
043 protected void runTask(List tokens) throws Exception {
044 try {
045 Set<String> propsView = new HashSet<String>();
046 propsView.add("BrokerName");
047 context.printMBean(JmxMBeansUtil.filterMBeansView(JmxMBeansUtil.getAllBrokers(useJmxServiceUrl()), propsView));
048 } catch (Exception e) {
049 context.printException(new RuntimeException("Failed to execute list task. Reason: " + e));
050 throw new Exception(e);
051 }
052 }
053
054 /**
055 * Print the help messages for the browse command
056 */
057 protected void printHelp() {
058 context.printHelp(helpFile);
059 }
060
061 }