1 16 package org.jmanage.cmdui.commands; 17 18 import org.jmanage.cmdui.CommandHandler; 19 import org.jmanage.cmdui.HandlerContext; 20 import org.jmanage.cmdui.CommandConstants; 21 import org.jmanage.cmdui.util.CommandUtils; 22 import org.jmanage.cmdui.util.Out; 23 import org.jmanage.core.services.MBeanService; 24 import org.jmanage.core.services.ServiceFactory; 25 26 import java.util.List ; 27 28 33 public class QueryMBeansHandler implements CommandHandler { 34 35 41 public boolean execute(HandlerContext context) { 42 String [] args = context.getCommand().getArgs(); 43 if(args.length != 1 && args.length != 2){ 44 usage(); 45 return false; 46 } 47 48 String appName = args[0]; 49 String filter = null; 50 if(args.length > 1){ 51 filter = args[1]; 52 } 53 54 MBeanService mbeanService = ServiceFactory.getMBeanService(); 55 List mbeanDataList = 56 mbeanService.queryMBeans(context.getServiceContext(appName), 57 filter); 58 assert mbeanDataList != null; 59 CommandUtils.printMBeans(mbeanDataList); 60 return true; 61 } 62 63 public String getShortHelp() { 64 return "Queries mbeans for the given application"; 65 } 66 67 public void help() { 68 Out.println(getShortHelp()); 69 Out.println("Usage:"); 70 Out.println(CommandConstants.QUERY_MBEANS + " <application name> [filter]"); 71 } 72 73 private void usage(){ 74 Out.println("Invalid arguments"); 75 help(); 76 } 77 } 78 | Popular Tags |