FileDocCategorySizeDatePackage
TimerImpl.javaAPI DocJBoss 4.2.16456Fri Jul 13 20:53:54 BST 2007org.jboss.ejb3.timerservice.quartz

TimerImpl

public class TimerImpl extends Object implements javax.ejb.Timer
A view on an actual (persistent) timer. This object must never be serializable (EJB3 18.4.1)
author
Carlo de Wolf
version
$Revision: 60233 $

Fields Summary
private static final Logger
log
private org.quartz.Scheduler
scheduler
private org.quartz.Trigger
trigger
private Serializable
info
Constructors Summary
protected TimerImpl(org.quartz.Scheduler scheduler, org.quartz.Trigger trigger, Serializable info)

   
          
      assert scheduler != null;
      assert trigger != null;
      
      this.scheduler = scheduler;
      this.trigger = trigger;
      this.info = info;
   
Methods Summary
public voidcancel()
Cause the timer and all its associated expiration notifications to be cancelled.

throws
IllegalStateException If this method is invoked while the instance is in a state that does not allow access to this method.
throws
NoSuchObjectLocalException If invoked on a timer that has expired or has been cancelled.
throws
EJBException If this method could not complete due to a system-level failure.

      checkState();
      
      try {
         // TODO: call TimerServiceImpl.cancelTimer instead
         scheduler.unscheduleJob(trigger.getName(), trigger.getGroup());
      }
      catch(SchedulerException e) {
         log.error("cancel failed", e);
         throw new EJBException(e.getMessage());
      }
   
protected voidcheckState()

      // TODO: implement bean state checking to see if a call is allowed
      
      if(trigger.getNextFireTime() == null)
         throw new NoSuchObjectLocalException("timer has expired");
   
public javax.ejb.TimerHandlegetHandle()
Get a serializable handle to the timer. This handle can be used at a later time to re-obtain the timer reference.

return
A serializable handle to the timer.
throws
IllegalStateException If this method is invoked while the instance is in a state that does not allow access to this method.
throws
NoSuchObjectLocalException If invoked on a timer that has expired or has been cancelled.
throws
EJBException If this method could not complete due to a system-level failure.

      checkState();
      
      return null; // FIXME: implement getHandle
   
public java.io.SerializablegetInfo()
Get the information associated with the timer at the time of creation.

return
The Serializable object that was passed in at timer creation, or null if the info argument passed in at timer creation was null.
throws
IllegalStateException If this method is invoked while the instance is in a state that does not allow access to this method.
throws
NoSuchObjectLocalException If invoked on a timer that has expired or has been cancelled.
throws
EJBException If this method could not complete due to a system-level failure.

      checkState();
      
      return info;
   
public java.util.DategetNextTimeout()
Get the point in time at which the next timer expiration is scheduled to occur.

return
The point in time at which the next timer expiration is scheduled to occur.
throws
IllegalStateException If this method is invoked while the instance is in a state that does not allow access to this method.
throws
NoSuchObjectLocalException If invoked on a timer that has expired or has been cancelled.
throws
EJBException If this method could not complete due to a system-level failure.

      checkState();
      
      Date nextTimeout = trigger.getNextFireTime();
      if(nextTimeout == null)
         throw new IllegalStateException("trigger does not have a next fire time"); // TODO: proper EJB3 state check & exception
      return nextTimeout;
   
public longgetTimeRemaining()
Get the number of milliseconds that will elapse before the next scheduled timer expiration.

return
The number of milliseconds that will elapse before the next scheduled timer expiration.
throws
IllegalStateException If this method is invoked while the instance is in a state that does not allow access to this method.
throws
NoSuchObjectLocalException If invoked on a timer that has expired or has been cancelled.
throws
EJBException If this method could not complete due to a system-level failure.

      // leave all checks to getNextTimeout
      return getNextTimeout().getTime() - System.currentTimeMillis();