0 Replies Latest reply on Jul 29, 2009 12:42 AM by asookazian

    Custom method interceptors

    asookazian

      I just read thru section 6.6 Custom method interceptors in the SiA book.


      Apparently stereotypes are new in Seam 2.1 (I did not find keyword 'stereotype' in 2.0.2.SP1 ref doc).  Stereotypes have been mentioned frequently in the Web Beans forum but not in this forum.


      So I found the Seam interceptors section to be somewhat confusing.


      Who is using interceptors and in what use cases (there were no real examples in the SiA book)?


      I have an EJB 3.0 interceptor for profiling business method execution times in my session beans.


      But I'm wondering what I can do with the Seam interceptors and some more elaboration on the client-side aspect of it.


      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 ***");
              }
          }
      }



      In Spring AOP, the orthogonal concerns that are handled declaratively (or perhaps now via annotations) are transactions, security, logging.


      But in Seam, those three concerns are already taken care of.  So I'm wondering exactly how/when I would use the Seam interceptors in my projects???