Class TimerServiceImpl

    • Method Detail

      • 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
      • 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
      • 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 -
      • 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()
      • 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