public class TimerImpl extends Object implements javax.ejb.Timer
Timer
Modifier and Type | Field and Description |
---|---|
protected TimerHandleImpl |
handle
A
TimerHandle for this timer |
protected String |
id
Unique id for this timer instance
|
protected Serializable |
info
The info which was passed while creating the timer.
|
protected Date |
initialExpiration
The initial (first) expiry date of this timer
|
protected long |
intervalDuration
The duration in milli sec.
|
protected Date |
nextExpiration
Next expiry date of this timer
|
protected boolean |
persistent
Indicates whether the timer is persistent
|
protected Date |
previousRun
The date of the previous run of this timer
|
protected Object |
primaryKey
If this is an entity bean then this is the primary key
|
protected TimedObjectInvoker |
timedObjectInvoker
The
TimedObjectInvoker to which this timer corresponds |
protected TimerServiceImpl |
timerService
The
TimerService through which this timer was created |
protected TimerState |
timerState
The timer state
|
Constructor and Description |
---|
TimerImpl(String id,
TimerServiceImpl service,
Date initialExpiry,
long intervalDuration,
Date nextEpiry,
Serializable info,
boolean persistent,
Object primaryKey,
TimerState timerState)
Creates a
TimerImpl |
TimerImpl(String id,
TimerServiceImpl service,
Date initialExpiry,
long intervalDuration,
Serializable info,
boolean persistent,
Object primaryKey,
TimerState timerState)
Creates a
TimerImpl |
TimerImpl(TimerEntity persistedTimer,
TimerServiceImpl service)
Creates a
TimerImpl out of a persisted timer |
Modifier and Type | Method and Description |
---|---|
protected void |
assertTimerState()
Asserts that the timer is not in any of the following states:
TimerState.CANCELED
TimerState.EXPIRED
|
void |
cancel() |
protected void |
cancelTimeout()
Cancels any scheduled timer task for this timer
|
protected TimerEntity |
createPersistentState()
Creates and returns a new persistent state of this timer
|
boolean |
equals(Object obj)
A
Timer is equal to another Timer if their
TimerHandle s are equal |
void |
expireTimer()
Expire, and remove it from the timer service.
|
javax.ejb.TimerHandle |
getHandle() |
String |
getId()
Returns the id of this timer
|
Serializable |
getInfo() |
Date |
getInitialExpiration()
Returns the initial (first) timeout date of this timer
|
long |
getInterval()
Returns the interval (in milli seconds), between timeouts, of this timer.
|
Date |
getNextExpiration()
This method is similar to
getNextTimeout() , except that this method does not check the timer state
and hence does not throw either IllegalStateException or NoSuchObjectLocalException
or EJBException . |
Date |
getNextTimeout() |
TimerEntity |
getPersistentState()
Returns the current persistent state of this timer
|
Date |
getPreviousRun()
Returns the
Date of the previous timeout of this timer |
Object |
getPrimaryKey() |
javax.ejb.ScheduleExpression |
getSchedule() |
TimerState |
getState()
Returns the current state of this timer
|
String |
getTimedObjectId()
Returns the timed object id to which this timer belongs
|
long |
getTimeRemaining() |
javax.ejb.TimerHandle |
getTimerHandle()
This method returns the
TimerHandle corresponding to this TimerImpl . |
Serializable |
getTimerInfo()
This method is similar to
getInfo() , except that this method does not check the timer state
and hence does not throw either IllegalStateException or NoSuchObjectLocalException
or EJBException . |
TimerServiceImpl |
getTimerService()
Returns the timer service through which this timer was created
|
protected TimerTask<?> |
getTimerTask()
Returns the task which handles the timeouts of this
TimerImpl |
int |
hashCode() |
boolean |
isActive()
Returns true if this timer is active.
|
boolean |
isAutoTimer() |
boolean |
isCalendarTimer() |
boolean |
isCanceled()
Returns true if this timer is in
TimerState.CANCELED state. |
boolean |
isExpired()
Returns true if this timer is in
TimerState.EXPIRED state. |
boolean |
isInRetry()
Returns true if this timer is in
TimerState.RETRY_TIMEOUT . |
boolean |
isPersistent() |
void |
scheduleTimeout(boolean newTimer)
Creates and schedules a
TimerTask for the next timeout of this timer |
void |
setNextTimeout(Date next)
Sets the next timeout of this timer
|
void |
setPreviousRun(Date previousRun)
Sets the
Date of the previous timeout of this timer |
void |
setTimerState(TimerState state)
Sets the state of this timer
|
void |
suspend()
Suspends any currently scheduled task for this timer
|
String |
toString()
A nice formatted string output for this timer
|
protected final String id
protected volatile TimerState timerState
protected final TimerServiceImpl timerService
TimerService
through which this timer was createdprotected final TimedObjectInvoker timedObjectInvoker
TimedObjectInvoker
to which this timer correspondsprotected final Serializable info
protected final boolean persistent
protected final TimerHandleImpl handle
TimerHandle
for this timerprotected final Date initialExpiration
protected final long intervalDuration
protected final Object primaryKey
protected volatile Date nextExpiration
protected volatile Date previousRun
public TimerImpl(String id, TimerServiceImpl service, Date initialExpiry, long intervalDuration, Serializable info, boolean persistent, Object primaryKey, TimerState timerState)
TimerImpl
id
- The id of this timerservice
- The timer service through which this timer was createdinitialExpiry
- The first expiry of this timerintervalDuration
- The duration (in milli sec) between timeoutsinfo
- The info that will be passed on through the Timer
and will be available through the Timer.getInfo()
methodpersistent
- True if this timer is persistent. False otherwisepublic TimerImpl(String id, TimerServiceImpl service, Date initialExpiry, long intervalDuration, Date nextEpiry, Serializable info, boolean persistent, Object primaryKey, TimerState timerState)
TimerImpl
id
- The id of this timerservice
- The timer service through which this timer was createdinitialExpiry
- The first expiry of this timer. Can be nullintervalDuration
- The duration (in milli sec) between timeoutsnextEpiry
- The next expiry of this timerinfo
- The info that will be passed on through the Timer
and will be available through the Timer.getInfo()
methodpersistent
- True if this timer is persistent. False otherwisepublic TimerImpl(TimerEntity persistedTimer, TimerServiceImpl service)
TimerImpl
out of a persisted timerpersistedTimer
- The persisted state of the timerservice
- The timer service to which this timer belongspublic String getId()
public boolean isCalendarTimer() throws IllegalStateException, javax.ejb.EJBException
isCalendarTimer
in interface javax.ejb.Timer
IllegalStateException
javax.ejb.EJBException
public void cancel() throws IllegalStateException, javax.ejb.EJBException
cancel
in interface javax.ejb.Timer
IllegalStateException
javax.ejb.EJBException
public javax.ejb.TimerHandle getHandle() throws IllegalStateException, javax.ejb.EJBException
getHandle
in interface javax.ejb.Timer
IllegalStateException
javax.ejb.EJBException
getTimerHandle()
public javax.ejb.TimerHandle getTimerHandle()
TimerHandle
corresponding to this TimerImpl
.
Unlike the getHandle()
method, this method does not throw an IllegalStateException
or NoSuchObjectLocalException
or EJBException
, for non-persistent timers.
Instead this method returns the TimerHandle
corresponding to that non-persistent
timer (remember that TimerImpl
creates TimerHandle
for both persistent and non-persistent timers)public boolean isPersistent() throws IllegalStateException, javax.ejb.EJBException
isPersistent
in interface javax.ejb.Timer
IllegalStateException
javax.ejb.EJBException
public Serializable getInfo() throws IllegalStateException, javax.ejb.EJBException
getInfo
in interface javax.ejb.Timer
IllegalStateException
javax.ejb.EJBException
getTimerInfo()
public Serializable getTimerInfo()
getInfo()
, except that this method does not check the timer state
and hence does not throw either IllegalStateException
or NoSuchObjectLocalException
or EJBException
.public Date getNextTimeout() throws IllegalStateException, javax.ejb.EJBException
getNextTimeout
in interface javax.ejb.Timer
IllegalStateException
javax.ejb.EJBException
getNextExpiration()
public Date getNextExpiration()
getNextTimeout()
, except that this method does not check the timer state
and hence does not throw either IllegalStateException
or NoSuchObjectLocalException
or EJBException
.public void setNextTimeout(Date next)
next
- The next scheduled timeout of this timerpublic javax.ejb.ScheduleExpression getSchedule() throws IllegalStateException, javax.ejb.EJBException
getSchedule
in interface javax.ejb.Timer
IllegalStateException
javax.ejb.EJBException
public long getTimeRemaining() throws IllegalStateException, javax.ejb.EJBException
getTimeRemaining
in interface javax.ejb.Timer
IllegalStateException
javax.ejb.EJBException
public boolean isAutoTimer()
protected void cancelTimeout()
public Date getInitialExpiration()
public long getInterval()
public String getTimedObjectId()
public TimerServiceImpl getTimerService()
public boolean isActive()
A timer is considered to be "active", if its TimerState
is neither of the following:
public boolean isCanceled()
TimerState.CANCELED
state. Else returns false.public boolean isExpired()
TimerState.EXPIRED
state. Else returns falsepublic boolean isInRetry()
TimerState.RETRY_TIMEOUT
. Else returns false.public Date getPreviousRun()
Date
of the previous timeout of this timerpublic void setPreviousRun(Date previousRun)
Date
of the previous timeout of this timerpreviousRun
- public TimerState getState()
protected void assertTimerState()
javax.ejb.NoSuchObjectLocalException
- if the txtimer was canceled or has expiredpublic void expireTimer()
public void setTimerState(TimerState state)
state
- The state of this timerpublic TimerEntity getPersistentState()
public void suspend()
Note that, suspend does not cancel the Timer
. Instead,
it just cancels the next scheduled timeout. So once the Timer
is restored (whenever that happens), the Timer
will continue to
timeout at appropriate times.
public void scheduleTimeout(boolean newTimer)
TimerTask
for the next timeout of this timernewTimer
- true
if this is a new timer being scheduled, and not a re-schedule due to a timeoutprotected TimerEntity createPersistentState()
protected TimerTask<?> getTimerTask()
TimerImpl
TimerTask
public boolean equals(Object obj)
Timer
is equal to another Timer
if their
TimerHandle
s are equalpublic String toString()
public Object getPrimaryKey()
Copyright © 2012 JBoss, a division of Red Hat, Inc.. All Rights Reserved.