Package org.jboss.as.ejb3.timerservice
Class TimerImpl
java.lang.Object
org.jboss.as.ejb3.timerservice.TimerImpl
- All Implemented Interfaces:
jakarta.ejb.Timer,ManagedTimer
- Direct Known Subclasses:
CalendarTimer
Local implementation of
ManagedTimer.- Author:
- Carlo de Wolf
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StringUnique id for this timer instanceprotected SerializableThe info which was passed while creating the timer.protected final DateThe initial (first) expiry date of this timerprotected final longThe duration in milli sec.protected DateNext expiry date of this timerprotected final booleanIndicates whether the timer is persistentprotected DateThe date of the previous run of this timerprotected final TimedObjectInvokerTheTimedObjectInvokerto which this timer correspondsprotected final TimerServiceImplTheTimerServicethrough which this timer was createdprotected TimerStateThe timer state -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTimerImpl(TimerImpl.Builder builder, TimerServiceImpl service) Creates aTimerImpl -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Activates a previously suspended timer.static TimerImpl.Builderbuilder()voidcancel()booleanObtains the timer info cached in memory, without checking the persistent store.protected ThreadReturns the executing thread which is processing the timeout taskjakarta.ejb.TimerHandlegetId()Returns the id of this timergetInfo()Returns the initial (first) timeout date of this timerlongReturns the interval (in milliseconds), between timeouts, of this timer.This method is similar togetNextTimeout(), except that this method does not check the timer state and hence does not throw eitherIllegalStateExceptionorNoSuchObjectLocalExceptionorEJBException.Returns theDateof the previous timeout of this timerjakarta.ejb.ScheduleExpressiongetState()Returns the current state of this timerReturns the timed object id to which this timer belongslongThis method is similar togetInfo(), except that this method does not check the timer state and hence does not throw eitherIllegalStateExceptionorNoSuchObjectLocalExceptionorEJBException.Returns the timer service through which this timer was createdprotected TimerTaskReturns the task which handles the timeouts of thisTimerImplinthashCode()voidinvoke()Triggers timer, outside of normal expiration.booleanisActive()Returns true if this timer is active.booleanbooleanbooleanReturns true if this timer is inTimerState.CANCELEDstate.booleanReturns true if this timer is inTimerState.EXPIREDstate.booleanReturns true if this timer is inTimerState.RETRY_TIMEOUT.booleanvoidlock()voidscheduleTimeout(boolean newTimer) Creates and schedules aTimerTaskfor the next timeout of this timervoidsetCachedTimerInfo(Serializable newInfo) Sets the timer info to a new value.voidsetNextTimeout(Date next) Sets the next timeout of this timervoidsetPreviousRun(Date previousRun) Sets theDateof the previous timeout of this timervoidsetTimerState(TimerState state, Thread thread) Sets the state and timer task executing thread of this timervoidsuspend()Suspends any currently scheduled task for this timertoString()A nice formatted string output for this timervoidunlock()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jboss.as.ejb3.timerservice.spi.ManagedTimer
validateInvocationContext
-
Field Details
-
id
Unique id for this timer instance -
timerState
The timer state -
timerService
TheTimerServicethrough which this timer was created -
timedObjectInvoker
TheTimedObjectInvokerto which this timer corresponds -
info
The info which was passed while creating the timer. -
persistent
protected final boolean persistentIndicates whether the timer is persistent -
initialExpiration
The initial (first) expiry date of this timer -
intervalDuration
protected final long intervalDurationThe duration in milli sec. between timeouts -
nextExpiration
Next expiry date of this timer -
previousRun
The date of the previous run of this timer
-
-
Constructor Details
-
TimerImpl
Creates aTimerImpl- Parameters:
builder- The builder with the timer informationservice- The timer service through which this timer was created
-
-
Method Details
-
cancel
- Specified by:
cancelin interfacejakarta.ejb.Timer- Throws:
IllegalStateExceptionjakarta.ejb.EJBException
-
getId
Returns the id of this timer- Specified by:
getIdin interfaceManagedTimer- Returns:
-
isCalendarTimer
- Specified by:
isCalendarTimerin interfacejakarta.ejb.Timer- Throws:
IllegalStateExceptionjakarta.ejb.EJBException
-
getHandle
- Specified by:
getHandlein interfacejakarta.ejb.Timer- Throws:
IllegalStateExceptionjakarta.ejb.EJBException
-
isPersistent
- Specified by:
isPersistentin interfacejakarta.ejb.Timer- Throws:
IllegalStateExceptionjakarta.ejb.EJBException
-
getInfo
- Specified by:
getInfoin interfacejakarta.ejb.Timer- Throws:
IllegalStateExceptionjakarta.ejb.EJBException- See Also:
-
getTimerInfo
This method is similar togetInfo(), except that this method does not check the timer state and hence does not throw eitherIllegalStateExceptionorNoSuchObjectLocalExceptionorEJBException.- Returns:
- the timer info; if not available in-memory, retrieve it from persistence
-
getCachedTimerInfo
Obtains the timer info cached in memory, without checking the persistent store.- Returns:
- the cached timer info
-
setCachedTimerInfo
Sets the timer info to a new value. The purpose of this method is forDatabaseTimerPersistenceto reset the cached timer info. It should not be used for other purposes.- Parameters:
newInfo- the new timer info, typically null or an empty holder value
-
getNextTimeout
- Specified by:
getNextTimeoutin interfacejakarta.ejb.Timer- Throws:
IllegalStateExceptionjakarta.ejb.EJBException- See Also:
-
getNextExpiration
This method is similar togetNextTimeout(), except that this method does not check the timer state and hence does not throw eitherIllegalStateExceptionorNoSuchObjectLocalExceptionorEJBException.- Returns:
-
setNextTimeout
Sets the next timeout of this timer- Parameters:
next- The next scheduled timeout of this timer
-
getSchedule
public jakarta.ejb.ScheduleExpression getSchedule() throws IllegalStateException, jakarta.ejb.EJBException- Specified by:
getSchedulein interfacejakarta.ejb.Timer- Throws:
IllegalStateExceptionjakarta.ejb.EJBException
-
getTimeRemaining
- Specified by:
getTimeRemainingin interfacejakarta.ejb.Timer- Throws:
IllegalStateExceptionjakarta.ejb.EJBException
-
isAutoTimer
public boolean isAutoTimer() -
getInitialExpiration
Returns the initial (first) timeout date of this timer- Returns:
-
getInterval
public long getInterval()Returns the interval (in milliseconds), between timeouts, of this timer.- Returns:
-
getTimedObjectId
Returns the timed object id to which this timer belongs- Returns:
-
getTimerService
Returns the timer service through which this timer was created- Returns:
-
isActive
public boolean isActive()Returns true if this timer is active. Else returns false.A timer is considered to be "active", if its
TimerStateis neither of the following:TimerState.CANCELEDTimerState.EXPIRED- has not been suspended
- Specified by:
isActivein interfaceManagedTimer- Returns:
-
isCanceled
public boolean isCanceled()Returns true if this timer is inTimerState.CANCELEDstate. Else returns false.- Specified by:
isCanceledin interfaceManagedTimer- Returns:
-
isExpired
public boolean isExpired()Returns true if this timer is inTimerState.EXPIREDstate. Else returns false- Specified by:
isExpiredin interfaceManagedTimer- Returns:
-
isInRetry
public boolean isInRetry()Returns true if this timer is inTimerState.RETRY_TIMEOUT. Else returns false.- Returns:
-
getPreviousRun
Returns theDateof the previous timeout of this timer- Returns:
-
setPreviousRun
Sets theDateof the previous timeout of this timer- Parameters:
previousRun-
-
getState
Returns the current state of this timer- Returns:
-
getExecutingThread
Returns the executing thread which is processing the timeout task- Returns:
- the executingThread
-
setTimerState
Sets the state and timer task executing thread of this timer- Parameters:
state- The state of this timerthread- The executing thread which is processing the timeout task
-
activate
public void activate()Description copied from interface:ManagedTimerActivates a previously suspended timer. Once active, the timer will receive timeout events as usual, including any timeouts missed while inactive.- Specified by:
activatein interfaceManagedTimer
-
suspend
public void suspend()Suspends any currently scheduled task for this timerNote that, suspend does not cancel the
Timer. Instead, it just cancels the next scheduled timeout. So once theTimeris restored (whenever that happens), theTimerwill continue to timeout at appropriate times.- Specified by:
suspendin interfaceManagedTimer
-
invoke
Triggers timer, outside of normal expiration. Only used when running an explicit management trigger operation. The tigger operation simply runs the callback, it does not modify the timer state in any way, and there is no protection against overlapping events when running it. This is the expected behaviour, as otherwise the semantics of dealing with concurrent execution is complex and kinda weird.- Specified by:
invokein interfaceManagedTimer- Throws:
Exception
-
scheduleTimeout
public void scheduleTimeout(boolean newTimer) Creates and schedules aTimerTaskfor the next timeout of this timer- Parameters:
newTimer-trueif this is a new timer being scheduled, and not a re-schedule due to a timeout
-
getTimerTask
Returns the task which handles the timeouts of thisTimerImpl- Returns:
- See Also:
-
lock
- Throws:
InterruptedException
-
unlock
public void unlock() -
equals
-
hashCode
public int hashCode() -
toString
A nice formatted string output for this timer -
builder
-