This content has been marked as final.
Show 2 replies
-
1. Re: Intercepting method calls on non EJB Seam component
asookazian Jul 29, 2009 7:03 PM (in response to javanaute)
You can even use Seam interceptors with JavaBean components, not just EJB3 beans!No example cited.
So I created one. No EJBs.
ProfilingInterceptor.java:
public class ProfilingInterceptor { Log log = Logging.getLog(ProfilingInterceptor.class); @AroundInvoke public Object profile(InvocationContext ic) throws Exception { log.info("*** Entering method: " + ic.getMethod().getName()); long startTime = 0; long endTime = 0; try { startTime = System.currentTimeMillis(); return ic.proceed(); } finally { endTime = System.currentTimeMillis(); log.info("*** Method " + ic.getClass() + "." + ic.getMethod() + " executed in " + (endTime - startTime) + "ms ***"); } } }
ProfileMe.java:
@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Interceptors(ProfilingInterceptor.class) public @interface ProfileMe {}
TestStartupInterceptor.java:
@Name("startupInterceptor") @ProfileMe @Scope(ScopeType.APPLICATION) @Startup public class TestStartupInterceptor { @Create public void init(){ try{ Thread.sleep(5000); } catch(Exception e){ //no op } } }
09:58:45,552 INFO [ProfilingInterceptor] *** Entering method: init 09:58:50,552 INFO [ProfilingInterceptor] *** Method class org.jboss.seam.intercept.EE5SeamInvocationContext.public void org.jboss.seam.example.booking.TestStartupInterceptor.init() executed in 5000ms ***
-
2. Re: Intercepting method calls on non EJB Seam component
asookazian Jul 29, 2009 7:14 PM (in response to javanaute)https://jira.jboss.org/jira/browse/JBSEAM-4327
Add example code of how to use Seam interceptors with JavaBean components in ref doc