org.objectweb.jonas_ejb.container
Class JTimer

java.lang.Object
  extended byorg.objectweb.jonas_ejb.container.JTimer
All Implemented Interfaces:
javax.ejb.Timer, TimerEventListener

public class JTimer
extends java.lang.Object
implements javax.ejb.Timer, TimerEventListener

JOnAS Implementation of the Timer interface (from EJB 2.1) This is a basic implementation based on jonas_timer. A later (and better ?) implementation could be based on Quartz.

Author:
Philippe Durieux

Constructor Summary
JTimer(JTimerService timerservice, long initial, long period, java.io.Serializable info)
          constructor
 
Method Summary
 void cancel()
          Cause the timer and all its associated expiration notifications to be cancelled.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
 javax.ejb.TimerHandle getHandle()
          Get a serializable handle to the timer.
 java.io.Serializable getInfo()
          Get the information associated with the timer at the time of creation.
 long getInitial()
           
 java.util.Date getNextTimeout()
          Get the point in time at which the next timer expiration is scheduled to occur.
 long getPeriod()
           
 long getStartTime()
           
 long getTimeRemaining()
          Get the number of milliseconds that will elapse before the next scheduled timer expiration.
 JTimerService getTimerService()
           
 int hashCode()
          Returns a hash code value for the object.
 void startTimer()
          start the Timer
 void stopTimer()
          Stop a timer.
 void timeoutExpired(java.lang.Object arg)
          The timer has just expired.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTimer

public JTimer(JTimerService timerservice,
              long initial,
              long period,
              java.io.Serializable info)
constructor

Method Detail

getStartTime

public long getStartTime()
Returns:
the start time in millisec.

getInitial

public long getInitial()
Returns:
the initial duration in millisec.

getPeriod

public long getPeriod()
Returns:
the period in millisec. (periodic timers only)

getTimerService

public JTimerService getTimerService()
Returns:
the Jonas Timer Service that manages this Timer

startTimer

public void startTimer()
start the Timer


stopTimer

public void stopTimer()
Stop a timer. Used internally.


equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.

Parameters:
obj - - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

hashCode

public int hashCode()
Returns a hash code value for the object.

Returns:
a hash code value for this object.

timeoutExpired

public void timeoutExpired(java.lang.Object arg)
The timer has just expired.

Specified by:
timeoutExpired in interface TimerEventListener

cancel

public void cancel()
            throws java.lang.IllegalStateException,
                   javax.ejb.NoSuchObjectLocalException,
                   javax.ejb.EJBException
Cause the timer and all its associated expiration notifications to be cancelled.

Specified by:
cancel in interface javax.ejb.Timer
Throws:
java.lang.IllegalStateException - the instance is in a state that does not allow access to this method.
javax.ejb.NoSuchObjectLocalException - If invoked on a timer that has expired or has been cancelled.
javax.ejb.EJBException - If this method could not complete due to a system-level failure.

getTimeRemaining

public long getTimeRemaining()
                      throws java.lang.IllegalStateException,
                             javax.ejb.NoSuchObjectLocalException,
                             javax.ejb.EJBException
Get the number of milliseconds that will elapse before the next scheduled timer expiration.

Specified by:
getTimeRemaining in interface javax.ejb.Timer
Returns:
the number of milliseconds that will elapse before the next scheduled timer expiration.
Throws:
java.lang.IllegalStateException - the instance is in a state that does not allow access to this method.
javax.ejb.NoSuchObjectLocalException - If invoked on a timer that has expired or has been cancelled.
javax.ejb.EJBException - If this method could not complete due to a system-level failure.

getNextTimeout

public java.util.Date getNextTimeout()
                              throws java.lang.IllegalStateException,
                                     javax.ejb.NoSuchObjectLocalException,
                                     javax.ejb.EJBException
Get the point in time at which the next timer expiration is scheduled to occur.

Specified by:
getNextTimeout in interface javax.ejb.Timer
Returns:
the point in time at which the next timer expiration is scheduled to occur.
Throws:
java.lang.IllegalStateException - the instance is in a state that does not allow access to this method.
javax.ejb.NoSuchObjectLocalException - If invoked on a timer that has expired or has been cancelled.
javax.ejb.EJBException - If this method could not complete due to a system-level failure.

getInfo

public java.io.Serializable getInfo()
                             throws java.lang.IllegalStateException,
                                    javax.ejb.NoSuchObjectLocalException,
                                    javax.ejb.EJBException
Get the information associated with the timer at the time of creation.

Specified by:
getInfo in interface javax.ejb.Timer
Returns:
The Serializable object that was passed in at timer creation, or null if the info argument passed in at timer creation was null.
Throws:
java.lang.IllegalStateException - the instance is in a state that does not allow access to this method.
javax.ejb.NoSuchObjectLocalException - If invoked on a timer that has expired or has been cancelled.
javax.ejb.EJBException - If this method could not complete due to a system-level failure.

getHandle

public javax.ejb.TimerHandle getHandle()
                                throws java.lang.IllegalStateException,
                                       javax.ejb.NoSuchObjectLocalException,
                                       javax.ejb.EJBException
Get a serializable handle to the timer. This handle can be used at a later time to re-obtain the timer reference.

Specified by:
getHandle in interface javax.ejb.Timer
Returns:
a serializable handle to the timer.
Throws:
java.lang.IllegalStateException - the instance is in a state that does not allow access to this method.
javax.ejb.NoSuchObjectLocalException - If invoked on a timer that has expired or has been cancelled.
javax.ejb.EJBException - If this method could not complete due to a system-level failure.