ejb - Firing CDI event from interceptor class -
is possible fire cdi events within interceptor ? (using jboss 7.1.1)
for example, if have interceptor performanceloginterceptor
@interceptors({performanceloginterceptor.class}) public class processhandler extends handlerbase {
. . .
could fire event such:
public class performanceloginterceptor { private logger log = loggerfactory.getlogger("performancelog"); @ejb performancemonitor performancemonitor; @inject event<exceptionevent> exceptionevent; @aroundinvoke @aroundtimeout public object performancelog( invocationcontext invocationcontext ) throws exception { string methodname = invocationcontext.getmethod().tostring(); long start = system.currenttimemillis(); try { return invocationcontext.proceed(); } catch( exception e ) { log.warn( "during invocation of: {} exception occured: {}", methodname, throwables.getrootcause(e).getmessage() ); performancemonitor.addexception( methodname, e ); exception tosend; if(e instanceof efsobexceptioninformation ){ tosend = e; } else { log.debug("wrapping exception"); efsobexceptionwrapper wrapped = new efsobexceptionwrapper(e); tosend = wrapped; } if(exceptionevent != null) { log.debug("sending exceptionevent"); exceptionevent.fire(new exceptioneventbuilder() .setexceptionname(tosend) .setefsobexceptiontype(tosend) .setid(tosend) .setstacktrace(tosend) .build() ); } else { log.debug("exceptionevent null"); } log.debug("rethrowing"); throw tosend; } { long total = system.currenttimemillis() - start; performancemonitor.addperformancemetrics(methodname, total); } } }
note: exceptionevent null @ runtime in above.
i moved async block of performancemonitor bean referenced above.... , works (wat?)
@singleton @concurrencymanagement(concurrencymanagementtype.bean) public class performancemonitor { @inject event<exceptionevent> exceptionevent; private logger log = loggerfactory.getlogger("performancemonitor"); @asynchronous public void addexception(string methodname, exception e) { if(exceptionevent != null) { log.debug("sending exceptionevent"); exceptionevent.fire(new exceptioneventbuilder() .setexceptionname(e) .setefsobexceptiontype(e) .setid(e) .setstacktrace(e) .build() ); } else { log.debug("exceptionevent null"); } } }
Comments
Post a Comment