1 22 package org.jboss.monitor; 23 24 25 26 import java.net.URL ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import java.util.Map ; 31 import java.util.Set ; 32 import javax.management.JMException ; 33 import javax.management.MBeanRegistration ; 34 import javax.management.MBeanServer ; 35 import javax.management.ObjectInstance ; 36 import javax.management.ObjectName ; 37 import org.jboss.ejb.Container; 38 import org.jboss.ejb.EJBDeployer; 39 import org.jboss.ejb.EJBDeployerMBean; 40 import org.jboss.ejb.EjbModule; 41 import org.jboss.ejb.EntityContainer; 42 import org.jboss.ejb.InstanceCache; 43 import org.jboss.ejb.StatefulSessionContainer; 44 import org.jboss.logging.Logger; 45 import org.jboss.monitor.client.BeanCacheSnapshot; 46 47 54 public class BeanCacheMonitor 55 implements BeanCacheMonitorMBean, MBeanRegistration 56 { 57 59 static Logger log = Logger.getLogger(BeanCacheMonitor.class); 61 MBeanServer m_mbeanServer; 62 64 public BeanCacheMonitor() 66 {} 67 68 70 public ObjectName preRegister(MBeanServer server, ObjectName name) 72 throws Exception 73 { 74 m_mbeanServer = server; 75 return name; 76 } 77 78 public void postRegister(Boolean registrationDone) 79 {} 80 public void preDeregister() throws Exception 81 {} 82 public void postDeregister() 83 {} 84 85 92 public BeanCacheSnapshot[] getSnapshots() 93 { 94 try 95 { 96 Collection snapshots = listSnapshots(); 97 BeanCacheSnapshot[] snapshotArray = new BeanCacheSnapshot[snapshots.size()]; 98 return (BeanCacheSnapshot[])snapshots.toArray(snapshotArray); 99 } 100 catch (JMException e) 101 { 102 log.error("Problem getting bean cache snapshots", e); 103 return null; 104 } } 106 107 114 public Collection listSnapshots() throws JMException 115 { 116 ArrayList cacheSnapshots = new ArrayList (); 117 118 Collection ejbModules = m_mbeanServer.queryNames(EjbModule.EJB_MODULE_QUERY_NAME, null); 119 120 for (Iterator i = ejbModules.iterator(); i.hasNext(); ) 122 { 123 ObjectName ejbModule = (ObjectName ) i.next(); 124 String name = ejbModule.getKeyProperty("jndiName"); 125 126 129 Collection containers = (Collection )m_mbeanServer.getAttribute(ejbModule, "Containers"); 130 for (Iterator cs = containers.iterator(); cs.hasNext();) 131 { 132 InstanceCache cache = null; 134 Object container = cs.next(); 135 if (container instanceof EntityContainer) 136 { 137 cache = ((EntityContainer)container).getInstanceCache(); 138 } 139 else if (container instanceof StatefulSessionContainer) 140 { 141 cache = ((StatefulSessionContainer)container).getInstanceCache(); 142 } 143 144 if (cache instanceof Monitorable) 146 { 147 BeanCacheSnapshot snapshot = new BeanCacheSnapshot(); 148 snapshot.m_application = name; 149 snapshot.m_container = ((Container)container).getBeanMetaData().getEjbName(); 150 ((Monitorable)cache).sample(snapshot); 151 cacheSnapshots.add(snapshot); 152 } 153 } 154 } 155 return cacheSnapshots; 156 } 157 158 } 160 161 | Popular Tags |