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 " --jmxuser <user> Set the JMX user used for authenticating.", 034 " --jmxpassword <password> Set the JMX password used for authenticating.", 035 " --jmxlocal Use the local JMX server instead of a remote one.", 036 " --version Display the version information.", 037 " -h,-?,--help Display the stop broker help information.", 038 "" 039 }; 040 041 /** 042 * List all running brokers registered in the specified JMX context 043 * @param tokens - command arguments 044 * @throws Exception 045 */ 046 protected void runTask(List tokens) throws Exception { 047 try { 048 Set<String> propsView = new HashSet<String>(); 049 propsView.add("BrokerName"); 050 context.printMBean(JmxMBeansUtil.filterMBeansView(JmxMBeansUtil.getAllBrokers(createJmxConnection()), propsView)); 051 } catch (Exception e) { 052 context.printException(new RuntimeException("Failed to execute list task. Reason: " + e)); 053 throw new Exception(e); 054 } 055 } 056 057 /** 058 * Print the help messages for the browse command 059 */ 060 protected void printHelp() { 061 context.printHelp(helpFile); 062 } 063 064 }