1 23 24 31 package com.sun.enterprise.admin.monitor; 32 33 import java.util.ArrayList ; 34 import java.util.Iterator ; 35 36 import javax.management.InstanceNotFoundException ; 37 import javax.management.ObjectName ; 38 39 42 public class MonitorListCommand extends MonitorCommand { 43 44 47 private static final int LIST_TYPE = 1; 48 49 52 private static final int LIST_INSTANCE = 3; 53 54 57 private static final int LIST_TYPE_AND_INSTANCE = 5; 58 59 64 MonitorListCommand(ObjectName mbeanName) { 65 this.objectName = mbeanName; 66 this.actionCode = LIST_TYPE_AND_INSTANCE; 67 } 68 69 75 MonitorListCommand(ObjectName mbeanName, MonitoredObjectType type) { 76 this.objectName = mbeanName; 77 this.actionCode = LIST_INSTANCE; 78 this.monitoredObjectType = type.getTypeName(); 79 } 80 81 86 Object runCommand() throws InstanceNotFoundException { 87 BaseMonitorMBean mbean = MonitoringHelper.getMonitorMBean(objectName); 88 ArrayList childList = null; 89 if (actionCode == LIST_INSTANCE) { 90 childList = mbean.getChildList( 91 MonitoredObjectType.getMonitoredObjectType(monitoredObjectType)); 92 } else { 93 childList = mbean.getChildList(); 94 } 95 String [] result = new String [childList.size()]; 96 Iterator iter = childList.iterator(); 97 int i = 0; 98 while (iter.hasNext()) { 99 BaseMonitorMBean child = (BaseMonitorMBean)iter.next(); 100 MonitoredObjectType childType = 101 MonitoredObjectType.getMonitoredObjectType(child.getNodeType()); 102 if (actionCode == LIST_INSTANCE) { 103 result[i] = child.getNodeName(); 104 } else { 105 if (childType.isSingleton()) { 106 result[i] = child.getNodeType(); 107 } else { 108 result[i] = child.getNodeType() + "." + child.getNodeName(); 109 } 110 } 111 i++; 112 } 113 return result; 114 } 115 116 } 117 | Popular Tags |