1 22 package org.jboss.varia.stats; 23 24 import org.jboss.ejb.plugins.AbstractInterceptor; 25 import org.jboss.invocation.Invocation; 26 import org.jboss.invocation.InvocationType; 27 import org.jboss.metadata.XmlLoadable; 28 import org.jboss.metadata.BeanMetaData; 29 import org.jboss.deployment.DeploymentException; 30 import org.jboss.mx.util.MBeanServerLocator; 31 import org.w3c.dom.Element ; 32 33 import javax.management.MBeanServer ; 34 import javax.management.ObjectName ; 35 import java.lang.reflect.Method ; 36 37 38 42 public class TxStatisticsInterceptor 43 extends AbstractInterceptor 44 implements XmlLoadable 45 { 46 private MBeanServer server; 47 private ObjectName serviceName; 48 49 private String local; 50 private String localHome; 51 private String remote; 52 private String home; 53 54 56 public void importXml(Element element) throws Exception 57 { 58 String service = element.getAttribute("service"); 59 if(service == null || service.trim().length() == 0) 60 { 61 throw new DeploymentException("Required attribute 'service' is not set."); 62 } 63 64 serviceName = new ObjectName (service); 65 server = MBeanServerLocator.locateJBoss(); 66 } 67 68 70 public void start() 71 { 72 BeanMetaData bean = container.getBeanMetaData(); 73 local = bean.getLocal(); 74 localHome = bean.getLocalHome(); 75 remote = bean.getRemote(); 76 home = bean.getHome(); 77 } 78 79 public Object invokeHome(final Invocation mi) throws Exception 80 { 81 Method method = mi.getMethod(); 82 if(method != null) 83 { 84 String className = mi.getType() == InvocationType.LOCALHOME ? localHome : home; 85 logInvocation(className + "." + method.getName()); 86 } 87 88 return super.invokeHome(mi); 89 } 90 91 public Object invoke(final Invocation mi) throws Exception 92 { 93 Method method = mi.getMethod(); 94 if(method != null) 95 { 96 String className = mi.getType() == InvocationType.LOCAL ? local : remote; 97 logInvocation(className + "." + method.getName()); 98 } 99 100 return super.invoke(mi); 101 } 102 103 105 private void logInvocation(String method) 106 { 107 try 108 { 109 StatisticalItem item = new TxReport.MethodStats(method); 110 server.invoke(serviceName, "addStatisticalItem", 111 new Object []{item}, 112 new String []{StatisticalItem.class.getName()}); 113 } 114 catch(Exception e) 115 { 116 log.error("Failed to add invocation.", e); 117 } 118 } 119 } 120 | Popular Tags |