Class TimerServiceImpl

java.lang.Object
org.jboss.as.ejb3.timerservice.TimerServiceImpl
All Implemented Interfaces:
jakarta.ejb.TimerService, ManagedTimerService, org.wildfly.clustering.server.manager.Service

public class TimerServiceImpl extends Object implements ManagedTimerService
MK2 implementation of Enterprise Beans 3.1 ManagedTimerService
Version:
$Revision: $
Author:
Carlo de Wolf
  • Constructor Details

  • Method Details

    • start

      public void start()
      Specified by:
      start in interface org.wildfly.clustering.server.manager.Service
    • stop

      public void stop()
      Specified by:
      stop in interface org.wildfly.clustering.server.manager.Service
    • createCalendarTimer

      public jakarta.ejb.Timer createCalendarTimer(jakarta.ejb.ScheduleExpression schedule, jakarta.ejb.TimerConfig timerConfig)
      Specified by:
      createCalendarTimer in interface jakarta.ejb.TimerService
    • createIntervalTimer

      public jakarta.ejb.Timer createIntervalTimer(Date initialExpiration, long intervalDuration, jakarta.ejb.TimerConfig timerConfig)
      Specified by:
      createIntervalTimer in interface jakarta.ejb.TimerService
    • createSingleActionTimer

      public jakarta.ejb.Timer createSingleActionTimer(Date expiration, jakarta.ejb.TimerConfig timerConfig)
      Specified by:
      createSingleActionTimer in interface jakarta.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:
      getTimers in interface jakarta.ejb.TimerService
    • getAllTimers

      public Collection<jakarta.ejb.Timer> getAllTimers() throws IllegalStateException, jakarta.ejb.EJBException

      When PROGRAMMATIC_TIMER_REFRESH_ENABLED is set to true, this method programmatically refreshes from the database timer persistence before returning all timers.

      Specified by:
      getAllTimers in interface jakarta.ejb.TimerService
      Throws:
      IllegalStateException
      jakarta.ejb.EJBException
    • getTimer

      public TimerImpl getTimer(String timerId)
    • 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 the TimedObjectInvoker to which this timer service belongs
      Specified by:
      getInvoker in interface ManagedTimerService
      Returns:
    • findTimer

      public ManagedTimer findTimer(String timerId)
      Returns the timer corresponding to the passed timer id and timed object id.
      Specified by:
      findTimer in interface ManagedTimerService
      Parameters:
      timerId - timer id
      timedObjectId - timed object id
      Returns:
      the TimerImpl corresponding 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 passed timer.

      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 for Timers

      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.

    • 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 TimerState is 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 a TimerTask for the next timeout of the passed timer
    • cancelTimeout

      protected void cancelTimeout(TimerImpl timer)
      Cancels any scheduled Future corresponding to the passed timer
      Parameters:
      timer - the timer to cancel
    • isScheduled

      public boolean isScheduled(String tid)
    • isStarted

      public boolean isStarted()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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 return true.
      Parameters:
      timer - the timer which should be checked
      Returns:
      true if 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