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