Package org.jboss.as.ejb3.timerservice
Class TimerServiceImpl
- java.lang.Object
-
- org.jboss.as.ejb3.timerservice.TimerServiceImpl
-
- All Implemented Interfaces:
jakarta.ejb.TimerService,ManagedTimerService,Restartable
public class TimerServiceImpl extends Object implements ManagedTimerService
MK2 implementation of Enterprise Beans 3.1ManagedTimerService- Version:
- $Revision: $
- Author:
- Carlo de Wolf
-
-
Constructor Summary
Constructors Constructor Description TimerServiceImpl(TimerServiceConfiguration configuration)Creates aTimerServiceImpl.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcancelTimeout(TimerImpl timer)Cancels any scheduledFuturecorresponding to the passedtimervoidcancelTimer(TimerImpl timer)jakarta.ejb.TimercreateCalendarTimer(jakarta.ejb.ScheduleExpression schedule, jakarta.ejb.TimerConfig timerConfig)jakarta.ejb.TimercreateIntervalTimer(Date initialExpiration, long intervalDuration, jakarta.ejb.TimerConfig timerConfig)jakarta.ejb.TimercreateSingleActionTimer(Date expiration, jakarta.ejb.TimerConfig timerConfig)voidexpireTimer(TimerImpl timer)ManagedTimerfindTimer(String timerId)Returns the timer corresponding to the passed timer id and timed object id.Collection<jakarta.ejb.Timer>getAllTimers()TimedObjectInvokergetInvoker()Returns theTimedObjectInvokerto which this timer service belongsSerializablegetPersistedTimerInfo(TimerImpl timer)Retrieves the timer info from the timer database.TimerImplgetTimer(String timerId)Collection<jakarta.ejb.Timer>getTimers()protected jakarta.transaction.TransactiongetTransaction()booleanisScheduled(String tid)booleanisStarted()TimerImplloadAutoTimer(jakarta.ejb.ScheduleExpression schedule, jakarta.ejb.TimerConfig timerConfig, Method timeoutMethod)voidpersistTimer(TimerImpl timer, boolean newTimer)Persists the passedtimer.voidrestoreTimers(List<AutoTimer> newAutoTimers)Restores persisted timers, corresponding to this timerservice, which are eligible for any new timeouts.static voidsafeClose(AutoCloseable resource)Safely closes some resource without throwing an exception.protected voidscheduleTimeout(TimerImpl timer, boolean newTimer)Creates and schedules aTimerTaskfor the next timeout of the passedtimerbooleanshouldRun(TimerImpl timer)Check if a persistent timer is already executed from a different instance or should be executed.voidstart()protected voidstartTimer(TimerImpl timer)Registers a timer with a transaction (if any in progress) and then moves the timer to an active state, so that it becomes eligible for timeoutsvoidstop()voidsuspendTimers()Suspends any currently scheduled tasks forTimersStringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jboss.as.ejb3.timerservice.spi.ManagedTimerService
createCalendarTimer, createIntervalTimer, createSingleActionTimer, createTimer, createTimer, createTimer, createTimer, validateInvocationContext
-
-
-
-
Constructor Detail
-
TimerServiceImpl
public TimerServiceImpl(TimerServiceConfiguration configuration)
Creates aTimerServiceImpl.- Parameters:
configuration- the configuration of this timer service
-
-
Method Detail
-
start
public void start()
- Specified by:
startin interfaceRestartable
-
stop
public void stop()
- Specified by:
stopin interfaceRestartable
-
createCalendarTimer
public jakarta.ejb.Timer createCalendarTimer(jakarta.ejb.ScheduleExpression schedule, jakarta.ejb.TimerConfig timerConfig)- Specified by:
createCalendarTimerin interfacejakarta.ejb.TimerService
-
createIntervalTimer
public jakarta.ejb.Timer createIntervalTimer(Date initialExpiration, long intervalDuration, jakarta.ejb.TimerConfig timerConfig)
- Specified by:
createIntervalTimerin interfacejakarta.ejb.TimerService
-
createSingleActionTimer
public jakarta.ejb.Timer createSingleActionTimer(Date expiration, jakarta.ejb.TimerConfig timerConfig)
- Specified by:
createSingleActionTimerin interfacejakarta.ejb.TimerService
-
loadAutoTimer
public TimerImpl loadAutoTimer(jakarta.ejb.ScheduleExpression schedule, jakarta.ejb.TimerConfig timerConfig, Method timeoutMethod)
-
getTimers
public Collection<jakarta.ejb.Timer> getTimers()
- Specified by:
getTimersin interfacejakarta.ejb.TimerService
-
getAllTimers
public Collection<jakarta.ejb.Timer> getAllTimers() throws IllegalStateException, jakarta.ejb.EJBException
When
PROGRAMMATIC_TIMER_REFRESH_ENABLEDis set to true, this method programmatically refreshes from the database timer persistence before returning all timers.- Specified by:
getAllTimersin interfacejakarta.ejb.TimerService- Throws:
IllegalStateExceptionjakarta.ejb.EJBException
-
getPersistedTimerInfo
public Serializable getPersistedTimerInfo(TimerImpl timer)
Retrieves the timer info from the timer database.- Parameters:
timer- the timer whose info to be retrieved- Returns:
- the timer info from database; cached timer info if the timer persistence store is not database
-
getInvoker
public TimedObjectInvoker getInvoker()
Returns theTimedObjectInvokerto which this timer service belongs- Specified by:
getInvokerin interfaceManagedTimerService- Returns:
-
findTimer
public ManagedTimer findTimer(String timerId)
Returns the timer corresponding to the passed timer id and timed object id.- Specified by:
findTimerin interfaceManagedTimerService- Parameters:
timerId- timer idtimedObjectId- timed object id- Returns:
- the
TimerImplcorresponding to the passed timer id and timed object id
-
getTransaction
protected jakarta.transaction.Transaction getTransaction()
- Returns:
- Returns the current transaction, if any. Else returns null.
- Throws:
jakarta.ejb.EJBException- If there is any system level exception
-
persistTimer
public void persistTimer(TimerImpl timer, boolean newTimer)
Persists the passedtimer.If the passed timer is null or is non-persistent (i.e.
Timer.isPersistent()returns false), then this method acts as a no-op- Parameters:
timer-
-
cancelTimer
public void cancelTimer(TimerImpl timer) throws InterruptedException
- Throws:
InterruptedException
-
expireTimer
public void expireTimer(TimerImpl timer)
-
suspendTimers
public void suspendTimers()
Suspends any currently scheduled tasks forTimersNote 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.
-
restoreTimers
public void restoreTimers(List<AutoTimer> newAutoTimers)
Restores persisted timers, corresponding to this timerservice, which are eligible for any new timeouts.This includes timers whose
TimerStateis neither of the following:All such restored timers will be schedule for their next timeouts.
- Parameters:
newAutoTimers-
-
startTimer
protected void startTimer(TimerImpl timer)
Registers a timer with a transaction (if any in progress) and then moves the timer to an active state, so that it becomes eligible for timeouts
-
scheduleTimeout
protected void scheduleTimeout(TimerImpl timer, boolean newTimer)
Creates and schedules aTimerTaskfor the next timeout of the passedtimer
-
cancelTimeout
protected void cancelTimeout(TimerImpl timer)
Cancels any scheduledFuturecorresponding to the passedtimer- Parameters:
timer- the timer to cancel
-
isScheduled
public boolean isScheduled(String tid)
-
isStarted
public boolean isStarted()
-
shouldRun
public boolean shouldRun(TimerImpl timer)
Check if a persistent timer is already executed from a different instance or should be executed. For non-persistent timer it always returntrue.- Parameters:
timer- the timer which should be checked- Returns:
trueif the timer is not persistent or the persistent timer should start
-
safeClose
public static void safeClose(AutoCloseable resource)
Safely closes some resource without throwing an exception. Any exception will be logged at TRACE level.- Parameters:
resource- the resource to close
-
-