1 17 18 package org.apache.geronimo.jmxdebug.web.beanlib; 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Collections ; 23 import java.util.List ; 24 import java.util.Set ; 25 import javax.management.MalformedObjectNameException ; 26 import javax.management.ObjectName ; 27 28 import org.apache.geronimo.jmxdebug.util.ObjectNameComparator; 29 import org.apache.geronimo.kernel.KernelRegistry; 30 import org.apache.geronimo.kernel.Kernel; 31 import org.apache.geronimo.kernel.management.State; 32 33 38 public class KernelHelper { 39 private final Kernel kernel; 40 41 public KernelHelper() { 42 kernel = KernelRegistry.getSingleKernel(); 43 } 44 45 public Kernel getKernel() { 46 return kernel; 47 } 48 49 54 public Collection getGBeanNames() { 55 return getGBeanNames("*:*"); 56 } 57 58 64 public Collection getGBeanNames(String filterString) { 65 if (filterString == null) { 66 filterString = "*:*"; 67 } 68 69 if (kernel != null) { 70 ObjectName filter = null; 71 try { 72 filter = new ObjectName (filterString); 73 Set names = kernel.listGBeans(filter); 74 75 List sortedNames = new ArrayList (names); 76 Collections.sort(sortedNames, ObjectNameComparator.INSTANCE); 77 78 return sortedNames; 79 } catch (MalformedObjectNameException e) { 80 e.printStackTrace(); 81 } 82 } else { 83 System.out.println("KernelHelper : error : no mbean server"); 84 } 85 86 return null; 87 } 88 89 public String getState(ObjectName name) { 90 try { 91 return State.toString(kernel.getGBeanState(name)); 92 } catch (Exception e) { 93 return null; 94 } 95 } 96 } 97 | Popular Tags |