0 Replies Latest reply on Aug 14, 2008 3:09 PM by Kyle Bober

    Jboss 4.2.2 and TimerService

    Kyle Bober Newbie

      I have a Stateless session bean that is also a WebService. When I attempt to inject a TimerService and create a new timer Instance the TimerService is always returned as null. It seems the TimerService is never injected. I alos attempted injecting the SessionContext as well using @Resource and obtaining the TimerService via the SessionContext but the SessionContext is also null. Here is the code:

      package somepackage;

      import java.rmi.RemoteException;
      import java.util.Date;
      import java.util.Set;

      import javax.annotation.Resource;
      import javax.ejb.Remote;
      import javax.ejb.SessionContext;
      import javax.ejb.Stateless;
      import javax.ejb.Timeout;
      import javax.ejb.Timer;
      import javax.ejb.TimerService;
      import javax.jws.WebMethod;
      import javax.jws.WebParam;
      import javax.jws.WebResult;
      import javax.jws.WebService;

      import org.jboss.annotation.ejb.RemoteBinding;
      import org.jboss.annotation.ejb.Service;

      /**
      * Class which contains each of the services calls used by the client side.
      * @author pcrane
      *
      */
      @WebService
      @Stateless
      @Remote(IMemberService.class)
      @RemoteBinding(jndiBinding="MemberService/remote")
      public class MemberService implements IMemberService
      {
      // @Resource
      // public SessionContext theSessionContext;

      @Resource
      public TimerService theTimerService;

      @Timeout
      public void deleteUnauthorizedMembers(Timer aTimer) throws RemoteException
      {
      Long memberID = (Long) aTimer.getInfo();
      MemberServiceImpl.deleteMember(memberID);
      }

      /* (non-Javadoc)
      * @see com.thesearchagency.transformer.services.member.IMemberService#memberServiceUpdateAccount()
      */
      @WebMethod
      @WebResult(name = "memberID")
      public String memberServicePersistMember(@WebParam(name="memberProfile") MemberServiceUser aUser) throws RemoteException
      {
      TimerService ts = theSessionContext.getTimerService();
      ts.createTimer(timerExecutionDate, aUser.getMemberId());
      return MemberServiceImpl.memberServicePersistMember(aUser);
      }
      }



      package somepackage;

      import java.rmi.RemoteException;
      import java.util.Date;
      import java.util.Set;

      public interface IMemberService
      {
      String memberServicePersistMember(MemberServiceUser aUser) throws RemoteException;
      }

      Please help! I ahve been racking my brain on this for a few hours now and Timers should be fairly easy in EJB3.0!

      Thanks,
      Kyle