[jboss-user] [EJB 3.0] - Re: Create timer -

oskar.carlstedt do-not-reply at jboss.com
Thu Mar 27 17:51:05 EDT 2008


Hmm... and now you're back where you started, aren't you?

This is a pretty annoying problem. Is there a working example of doing this within an EJB? Is the following solution possible?


  | @Stateless
  | @Local
  | public class A {
  | 
  |    @EJB
  |    B b;
  | 
  |    /**
  |    * this method is the one that is invoked by the 'user'
  |    **/
  |    public void someBusinessMethodThatHasToCreateATimer(...) {
  |       ...
  |       b.startTimer();
  |    }
  | 
  | 
  |    /**
  |    * this method will do the timeout job
  |    **/
  |    public void handleTimeout(Timer timer) {
  |       ...
  |    }
  | 
  | }
  | 
  | 
  | /**
  | * this is a wrapper class to get a new transaction that only has to
  | * deal with one data source in its own transaction.
  | **/
  | @Stateless
  | @Local
  | public class B {
  | 
  |    @Resource
  |    EJBContext ejbContext;
  | 
  |    @EJB
  |    A a;
  | 
  |    /**
  |    * this method is invoked by A. the result shall be
  |    * a created and persisted timer.
  |    **/
  |    public void startTimer() {
  |       ejbContext.getTimerService().createTimer(...);
  |    }
  | 
  |    /**
  |    * handles the timeout and will not do anything more
  |    * than just call the handleTimeout in A.
  |    **/
  |    @Timeout
  |    public void timeout(Timer timer) {
  |       a.handleTimeout(timer);
  |    }
  | 
  | }
  | 
  | 

This is not a nice solution using a circular reference, but is there any other way get around this problem without reconfiguring JBoss?


Cheers
/Oskar


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4139492#4139492

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4139492



More information about the jboss-user mailing list