public class TimerImpl extends Object implements javax.ejb.Timer
Timer
Modifier and Type | Class and Description |
---|---|
static class |
TimerImpl.Builder |
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
|
Modifier | Constructor and Description |
---|---|
protected |
TimerImpl(TimerImpl.Builder builder,
TimerServiceImpl service)
Creates a
TimerImpl |
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
|
static TimerImpl.Builder |
builder() |
void |
cancel() |
protected void |
cancelTimeout()
Cancels any scheduled timer task for this timer
|
boolean |
equals(Object obj)
A
Timer is equal to another Timer if their
TimerHandle s are equal |
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 milliseconds), 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() |
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() |
void |
invokeOneOff()
Triggers timer, outside of normal expiration.
|
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() |
boolean |
isTimerPersistent() |
void |
lock() |
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
|
void |
unlock() |
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
protected TimerImpl(TimerImpl.Builder builder, TimerServiceImpl service)
TimerImpl
builder
- The builder with the timer informationservice
- The timer service through which this timer was createdpublic void cancel() throws IllegalStateException, javax.ejb.EJBException
cancel
in interface javax.ejb.Timer
IllegalStateException
javax.ejb.EJBException
public String getId()
public boolean isCalendarTimer() throws IllegalStateException, javax.ejb.EJBException
isCalendarTimer
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 boolean isTimerPersistent()
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:
TimerState.CANCELED
TimerState.EXPIRED
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 setTimerState(TimerState state)
state
- The state of this timerpublic 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 invokeOneOff() throws Exception
Exception
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 TimerTask<?> getTimerTask()
TimerImpl
TimerTask
public void lock()
public void unlock()
public boolean equals(Object obj)
Timer
is equal to another Timer
if their
TimerHandle
s are equalpublic String toString()
public Object getPrimaryKey()
public static TimerImpl.Builder builder()
Copyright © 2016 JBoss by Red Hat. All rights reserved.