1 7 package org.jboss.cache.aop; 8 9 11 import org.jboss.aop.advice.Interceptor; 12 import org.jboss.aop.joinpoint.Invocation; 13 import org.jboss.aop.joinpoint.MethodInvocation; 14 15 import java.lang.reflect.Method ; 16 17 21 public class MetricsInterceptor implements org.jboss.aop.advice.Interceptor 22 { 23 24 public MetricsInterceptor() 25 { 26 System.out.println("### MetricsInterceptor was created ####"); 27 } 28 29 public String getName() 30 { 31 return "MetricsInterceptor"; 32 } 33 34 public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable 35 { 36 if (invocation == null) { 37 System.err.println("\n-- MetricsInterceptor: invocation is null !"); 38 return null; 39 } 40 41 try { 42 43 System.out.println("*** MetricsInterceptor: inv=" + invocation); 44 org.jboss.aop.joinpoint.MethodInvocation methodInvocation = (org.jboss.aop.joinpoint.MethodInvocation) invocation; 45 Object [] args = methodInvocation.getArguments(); 46 Method meth = methodInvocation.getMethod(); 47 String method_name = meth != null ? meth.getName() : null; 48 49 System.out.println("\n\n-- [MetricsInterceptor]: type=" + invocation.getClass().getName()); 50 if (method_name != null) 51 System.out.println("-- [MetricsInterceptor]: method_name(" 52 + printArgs(args) 53 + ")"); 54 } catch (Throwable t) { 55 System.err.println("\n-- [MetricsInterceptor]: error " + t); 56 throw t; 57 } 58 59 return invocation.invokeNext(); 60 } 61 62 String printArgs(Object [] args) 63 { 64 StringBuffer sb = new StringBuffer (); 65 if (args != null) { 66 for (int i = 0; i < args.length; i++) { 67 Object arg = args[i]; 68 sb.append(arg).append(" "); 69 } 70 } 71 return sb.toString(); 72 } 73 74 } 75 | Popular Tags |