1 25 26 package org.objectweb.easybeans.examples.statelessbean; 27 28 import javax.ejb.Local ; 29 import javax.ejb.Remote ; 30 import javax.ejb.Stateless ; 31 import javax.interceptor.AroundInvoke; 32 import javax.interceptor.ExcludeClassInterceptors; 33 import javax.interceptor.Interceptors; 34 import javax.interceptor.InvocationContext; 35 36 40 @Stateless 41 @Local (StatelessLocal.class) 42 @Remote (StatelessRemote.class) 43 @Interceptors({StatelessInterceptor.class}) 44 public class StatelessBean implements StatelessRemote { 45 46 49 public void helloWorld() { 50 System.out.println("Hello world !"); 51 } 52 53 59 @Interceptors({StatelessOnlyAddMethodInterceptor.class}) 60 public int add(final int a, final int b) { 61 return a + b; 62 } 63 64 70 public int div(final int a, final int b) { 71 if (b == 0) { 72 throw new IllegalArgumentException ("cannot divide by 0"); 73 } 74 return a / b; 75 } 76 77 80 @ExcludeClassInterceptors 81 public void notInterceptedMethod() { 82 83 } 84 85 86 92 @AroundInvoke 93 public Object trace(final InvocationContext invocationContext) throws Exception { 94 System.out.println("TraceInterceptor : method '" + invocationContext.getMethod().getName() 95 + "'."); 96 long startPeriod = System.nanoTime(); 97 try { 98 return invocationContext.proceed(); 99 } finally { 100 long elapsed = System.nanoTime() - startPeriod; 101 System.out.println("TraceInterceptor : Elapsed time = " + elapsed + " ns"); 102 } 103 } 104 105 } 106 | Popular Tags |