Class TimerImpl

    • Field Detail

      • id

        protected final String id
        Unique id for this timer instance
      • timerState

        protected volatile TimerState timerState
        The timer state
      • timerService

        protected final TimerServiceImpl timerService
        The TimerService through which this timer was created
      • info

        protected Serializable info
        The info which was passed while creating the timer.
      • persistent

        protected final boolean persistent
        Indicates whether the timer is persistent
      • initialExpiration

        protected final Date initialExpiration
        The initial (first) expiry date of this timer
      • intervalDuration

        protected final long intervalDuration
        The duration in milli sec. between timeouts
      • nextExpiration

        protected volatile Date nextExpiration
        Next expiry date of this timer
      • previousRun

        protected volatile Date previousRun
        The date of the previous run of this timer
    • Constructor Detail

      • TimerImpl

        protected TimerImpl​(TimerImpl.Builder builder,
                            TimerServiceImpl service)
        Creates a TimerImpl
        Parameters:
        builder - The builder with the timer information
        service - The timer service through which this timer was created
    • Method Detail

      • getId

        public String getId()
        Returns the id of this timer
        Specified by:
        getId in interface ManagedTimer
        Returns:
      • isCalendarTimer

        public boolean isCalendarTimer()
                                throws IllegalStateException,
                                       jakarta.ejb.EJBException
        Specified by:
        isCalendarTimer in interface jakarta.ejb.Timer
        Throws:
        IllegalStateException
        jakarta.ejb.EJBException
      • getHandle

        public jakarta.ejb.TimerHandle getHandle()
                                          throws IllegalStateException,
                                                 jakarta.ejb.EJBException
        Specified by:
        getHandle in interface jakarta.ejb.Timer
        Throws:
        IllegalStateException
        jakarta.ejb.EJBException
      • isPersistent

        public boolean isPersistent()
                             throws IllegalStateException,
                                    jakarta.ejb.EJBException
        Specified by:
        isPersistent in interface jakarta.ejb.Timer
        Throws:
        IllegalStateException
        jakarta.ejb.EJBException
      • getTimerInfo

        public 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.
        Returns:
        the timer info; if not available in-memory, retrieve it from persistence
      • getCachedTimerInfo

        public Serializable getCachedTimerInfo()
        Obtains the timer info cached in memory, without checking the persistent store.
        Returns:
        the cached timer info
      • setCachedTimerInfo

        public void setCachedTimerInfo​(Serializable newInfo)
        Sets the timer info to a new value. The purpose of this method is for DatabaseTimerPersistence to 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
      • getNextExpiration

        public 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.
        Returns:
      • setNextTimeout

        public void setNextTimeout​(Date next)
        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:
        getSchedule in interface jakarta.ejb.Timer
        Throws:
        IllegalStateException
        jakarta.ejb.EJBException
      • getTimeRemaining

        public long getTimeRemaining()
                              throws IllegalStateException,
                                     jakarta.ejb.EJBException
        Specified by:
        getTimeRemaining in interface jakarta.ejb.Timer
        Throws:
        IllegalStateException
        jakarta.ejb.EJBException
      • isAutoTimer

        public boolean isAutoTimer()
      • getInitialExpiration

        public Date 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

        public String getTimedObjectId()
        Returns the timed object id to which this timer belongs
        Returns:
      • getTimerService

        public TimerServiceImpl 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 TimerState is neither of the following:

        And if the corresponding timer service is still up

        Specified by:
        isActive in interface ManagedTimer
        Returns:
      • isInRetry

        public boolean isInRetry()
        Returns true if this timer is in TimerState.RETRY_TIMEOUT. Else returns false.
        Returns:
      • getPreviousRun

        public Date getPreviousRun()
        Returns the Date of the previous timeout of this timer
        Returns:
      • setPreviousRun

        public void setPreviousRun​(Date previousRun)
        Sets the Date of the previous timeout of this timer
        Parameters:
        previousRun -
      • getState

        public TimerState getState()
        Returns the current state of this timer
        Returns:
      • getExecutingThread

        protected Thread getExecutingThread()
        Returns the executing thread which is processing the timeout task
        Returns:
        the executingThread
      • setTimerState

        public void setTimerState​(TimerState state,
                                  Thread thread)
        Sets the state and timer task executing thread of this timer
        Parameters:
        state - The state of this timer
        thread - The executing thread which is processing the timeout task
      • activate

        public void activate()
        Description copied from interface: ManagedTimer
        Activates a previously suspended timer. Once active, the timer will receive timeout events as usual, including any timeouts missed while inactive.
        Specified by:
        activate in interface ManagedTimer
      • suspend

        public void suspend()
        Suspends any currently scheduled task for this timer

        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.

        Specified by:
        suspend in interface ManagedTimer
      • invoke

        public void invoke()
                    throws Exception
        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:
        invoke in interface ManagedTimer
        Throws:
        Exception
      • scheduleTimeout

        public void scheduleTimeout​(boolean newTimer)
        Creates and schedules a TimerTask for the next timeout of this timer
        Parameters:
        newTimer - true if this is a new timer being scheduled, and not a re-schedule due to a timeout
      • getTimerTask

        protected TimerTask getTimerTask()
        Returns the task which handles the timeouts of this TimerImpl
        Returns:
        See Also:
        TimerTask
      • unlock

        public void unlock()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toString

        public String toString()
        A nice formatted string output for this timer
        Overrides:
        toString in class Object