0 Replies Latest reply on Oct 30, 2006 10:26 AM by mlsreekanth

    Error while timeout handler is executed

    mlsreekanth

      Hi all,

      Environment : Windows XP with java1.6 beta and Jboss 4.0.4GA

      I am using Container managed Persistence context (EJB3 entity manager)

      I have a problem with a timer. It is being created properly with a warning

      20:53:13,343 WARN [TxConnectionManager] Prepare called on a local tx. Use of local transactions on a jta transaction with more than one branch may result in inconsistent data in some cases of failure.


      Time out handler also called properly. At the end of the method it is raising one error and whole transaction is rolled back.

      Error:

      20:55:00,234 ERROR [TimerImpl] Error invoking ejbTimeout: java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=lakssrikd/50, BranchQual=, localId=50] status=STATUS_NO_TRANSACTION; - nested throwable: (java.lang.NullPointerException)


      There is no other trace is available for htis error.

      Please help me to resolve the issue.

      Timer Code:


      import java.util.Collection;
      import java.util.Date;
      import java.util.Iterator;

      import javax.annotation.Resource;
      import javax.annotation.security.PermitAll;
      import javax.ejb.Local;
      import javax.ejb.SessionContext;
      import javax.ejb.Stateless;
      import javax.ejb.Timeout;
      import javax.ejb.Timer;
      import javax.interceptor.Interceptors;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;

      import org.jboss.seam.Component;
      import org.jboss.seam.annotations.Intercept;
      import org.jboss.seam.annotations.Name;

      @Name("tenderUnlockTimer")
      @Stateless
      @Local(TenderUnlockTimer.class)
      public class TenderUnlockTimerAction implements TenderUnlockTimer {

      @Resource
      private SessionContext ctx;

      @PersistenceContext
      EntityManager entityManager;



      public void scheduleTimer(long milliseconds, String nitId) {

      ctx.getTimerService().createTimer(
      new Date(new Date().getTime() + milliseconds), nitId);
      }

      @Timeout
      public void timeoutHandler(Timer timer) {

      try{
      String processName = "process_name"; // masked
      String id= timer.getInfo().toString();
      ProcessHelper processHelper = (ProcessHelper) Component
      .getInstance("processHelper");
      String processId = processHelper.startEvaluationProcess(processName,
      id);
      // Chnage the status of the entity using EM
      timer.cancel();
      // After this statement it is raising the error .. found while debugging
      }catch(Exception e){
      e.printStackTrace();
      }

      }

      public void scheduleTimer(String nitId, Date unlockingDate) {
      // Create UnlockTimer for the task "taskName"
      try {
      if (ctx != null) {
      if (ctx.getTimerService() != null) {
      ctx.getTimerService().createTimer(unlockingDate, nitId);
      }else{
      System.out.println("Timer service is null");
      }
      }else{
      System.out.println(" Session context is null");
      }
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      public void cancelTimerByName(String name) {
      // Cancel the timer by name
      if (name != null) {
      Collection timers = ctx.getTimerService().getTimers();
      Timer timer = null;
      if (!timers.isEmpty()) {
      Iterator timersIterator = timers.iterator();
      while (timersIterator.hasNext()) {
      timer = (Timer) timersIterator.next();
      System.out.println(" Timer name " + timer.getInfo());
      if (timer.getInfo().toString().trim().equals(name.trim())) {
      System.out.println(" Canceling the Timer with name " + timer.getInfo());
      timer.cancel();
      break;
      }
      }
      }else{
      System.out.println(" There are no timer defined ");
      }
      } else {
      // If name is null throw runtime exception
      throw new ApplicationDefaultException(
      ExceptionCodes.UNDEFINED_EXCEPTION);
      }
      }

      public void scheduleTimer(long milliseconds) {
      // TODO Auto-generated method stub

      }

      public void rescheduleTimer(String name, Date newDate) {
      cancelTimerByName(name);
      scheduleTimer(name, newDate);
      }

      }