org.ow2.jonas.lib.ejb21
Class JTimer

java.lang.Object
  extended by org.ow2.jonas.lib.ejb21.JTimer
All Implemented Interfaces:
Timer, Synchronization, TimerEventListener

public class JTimer
extends Object
implements Timer, TimerEventListener, Synchronization

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, Serializable info)
          constructor
 
Method Summary
 void afterCompletion(int status)
          The afterCompletion method is called by the transaction manager after the transaction is committed or rolled back.
 void beforeCompletion()
           
 void cancel()
          Cause the timer and all its associated expiration notifications to be cancelled.
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this one.
 TimerHandle getHandle()
          Get a serializable handle to the timer.
 Serializable getInfo()
          Get the information associated with the timer at the time of creation.
 long getInitialDuration()
           
 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.
 boolean isCancelled()
           
 boolean sameas(Object obj)
          This is used to retrieve a Timer from its Handle only.
 void setFile(File file)
          Set the file associated with this timer.
 void startTimer()
          start the Timer
 void stopTimer()
          Stop a timer.
 void timeoutExpired(Object arg)
          The timer has just expired.
 String toString()
          Give a String representation of the Timer
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JTimer

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

Method Detail

toString

public String toString()
Give a String representation of the Timer

Overrides:
toString in class Object

setFile

public void setFile(File file)
Set the file associated with this timer.


getStartTime

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

getInitialDuration

public long getInitialDuration()
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.


isCancelled

public boolean isCancelled()
Returns:
true if timer has been cancelled

equals

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

Overrides:
equals in class Object
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.

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.

sameas

public boolean sameas(Object obj)
This is used to retrieve a Timer from its Handle only.


timeoutExpired

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

Specified by:
timeoutExpired in interface TimerEventListener

cancel

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

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

getTimeRemaining

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

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

getNextTimeout

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

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

getInfo

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

Specified by:
getInfo in interface 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:
IllegalStateException - the instance is in a state that does not allow access to this method.
NoSuchObjectLocalException - If invoked on a timer that has expired or has been cancelled.
EJBException - If this method could not complete due to a system-level failure.

getHandle

public TimerHandle getHandle()
                      throws IllegalStateException,
                             NoSuchObjectLocalException,
                             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 Timer
Returns:
a serializable handle to the timer.
Throws:
IllegalStateException - the instance is in a state that does not allow access to this method.
NoSuchObjectLocalException - If invoked on a timer that has expired or has been cancelled.
EJBException - If this method could not complete due to a system-level failure.

afterCompletion

public void afterCompletion(int status)
The afterCompletion method is called by the transaction manager after the transaction is committed or rolled back. This method executes without a transaction context.

Specified by:
afterCompletion in interface Synchronization
Parameters:
status - The status of the transaction completion.

beforeCompletion

public void beforeCompletion()
Specified by:
beforeCompletion in interface Synchronization


Copyright © 2010 OW2 Consortium. All Rights Reserved.