1 package examples.proxy.tracing; 2 3 import org.codehaus.aspectwerkz.proxy.Proxy; 4 import org.codehaus.aspectwerkz.intercept.Advisable; 5 import org.codehaus.aspectwerkz.intercept.AroundAdvice; 6 import org.codehaus.aspectwerkz.joinpoint.JoinPoint; 7 8 public class TraceMe1 { 9 10 public void step1() { 11 System.out.println(" - TraceMe1.step1"); 12 step2(); 13 } 14 15 protected void step2() { 16 System.out.println(" - TraceMe1.step2"); 17 step3(); 18 } 19 20 void step3() { 21 System.out.println(" - TraceMe1.step3"); 22 } 23 24 public static void main(String [] args) { 25 26 System.out.println("\nINFO:: ------ get a weaved proxy to the TraceMe1 class -----"); 29 TraceMe1 traceMe1 = (TraceMe1) Proxy.newInstance(TraceMe1.class, false, true); 30 31 System.out.println("\nINFO:: ------ run method chain with only regular AW aspects -----"); 33 traceMe1.step1(); 34 35 System.out.println("\nINFO:: ------ adding an around per instance interceptor on the fly -----"); 37 ((Advisable) traceMe1).aw_addAdvice( 38 "execution(* *.step3())", 39 new AroundAdvice() { 40 public Object invoke(JoinPoint jp) throws Throwable { 41 System.out.println("Interceptor::ENTERING - step3()"); 42 Object result = jp.proceed(); 43 System.out.println("Interceptor::EXITING - step3()"); 44 return result; 45 } 46 } 47 ); 48 49 System.out.println( 51 "\nINFO:: ------ run method chain with the added per instance runtime added around interceptor -----" 52 ); 53 traceMe1.step1(); 54 } 55 } 56 | Popular Tags |