Class EJBTimerService

    • Constructor Detail

    • Method Detail

      • setPersistentTimerService

        protected static void setPersistentTimerService​(EJBTimerService timerService)
      • setNonPersistentTimerService

        protected static void setNonPersistentTimerService​(EJBTimerService timerService)
      • getPersistentTimerService

        public static EJBTimerService getPersistentTimerService()
      • getNonPersistentTimerService

        public static EJBTimerService getNonPersistentTimerService()
      • isPersistentTimerServiceLoaded

        public static boolean isPersistentTimerServiceLoaded()
      • isNonPersistentTimerServiceLoaded

        public static boolean isNonPersistentTimerServiceLoaded()
      • getEJBTimerService

        public static EJBTimerService getEJBTimerService​(boolean persistent)
      • getEJBTimerService

        public static EJBTimerService getEJBTimerService​(String target,
                                                         boolean force)
      • getEJBTimerService

        public static EJBTimerService getEJBTimerService​(String target,
                                                         boolean force,
                                                         boolean persistent)
      • isPersistent

        public abstract boolean isPersistent()
      • migrateTimers

        public abstract int migrateTimers​(String fromOwnerId)
        Called by CLI.Take ownership of another server's timers.
        Parameters:
        fromOwnerId -
        Returns:
      • resetEJBTimers

        protected abstract void resetEJBTimers​(String target)
        Called at server startup *after* user apps have been re-activated to restart any active EJB timers or cleanup old timers.No-op for non-persistent timers
        Parameters:
        target -
      • stopTimers

        protected abstract void stopTimers​(long containerId)
        Remove from the cache and stop all timers associated with a particular ejb container and known to this server instance.This is typically called when an ejb is disabled or on a server shutdown to avoid accidentally removing a valid timer. This is also called when an ejb is disabled as part of an undeploy. Removal of the associated timer from the database is done as the last step of undeployment.
        Parameters:
        containerId -
      • getTimerIds

        protected abstract Collection<TimerPrimaryKey> getTimerIds​(long containerId,
                                                                   Object timedObjectPrimaryKey)
        Called by EJBTimerServiceWrapper when caller calls getTimers.
        Parameters:
        containerId - the id of the EJB which owns the timers
        timedObjectPrimaryKey - can be null if not entity bean
        Returns:
        Collection of Timer Ids.
      • getTimerIds

        protected abstract Collection<TimerPrimaryKey> getTimerIds​(Collection<Long> containerIds)
        Parameters:
        containerIds - the EJBs which own the timers
        Returns:
        Collection of Timer Ids.
      • cancelTimersByKey

        protected abstract void cancelTimersByKey​(long containerId,
                                                  Object primaryKey)
        Cancel all timers associated with a particular entity bean identity.This is typically called when an entity bean is removed.Note that this action falls under the normal EJB Timer removal semantics, which means it can be rolled back if the transaction rolls back.
        Parameters:
        containerId -
        primaryKey -
      • cancelTimer

        protected abstract void cancelTimer​(TimerPrimaryKey timerId)
                                     throws jakarta.ejb.FinderException,
                                            Exception
        Throws:
        jakarta.ejb.FinderException
        Exception
      • getNextTimeout

        protected abstract Date getNextTimeout​(TimerPrimaryKey timerId)
                                        throws jakarta.ejb.FinderException
        Return next planned timeout for this timer.We have a fair amount of leeway regarding the consistency of this information.We should strive to detect the case where the timer no longer exists.However, since the current timer instance may not even own this timer, it's difficult to know the exact time of delivery in another server instance. In the case of single-action timers, we return the expiration time that was provided upon timer creation. For periodic timers, we can derive the next scheduled fixed rate expiration based on the initial expiration and the interval.
        Parameters:
        timerId -
        Returns:
        Throws:
        jakarta.ejb.FinderException
      • getInfo

        protected abstract Serializable getInfo​(TimerPrimaryKey timerId)
                                         throws jakarta.ejb.FinderException
        Throws:
        jakarta.ejb.FinderException
      • isPersistent

        protected abstract boolean isPersistent​(TimerPrimaryKey timerId)
                                         throws jakarta.ejb.FinderException
        Throws:
        jakarta.ejb.FinderException
      • timerExists

        protected abstract boolean timerExists​(TimerPrimaryKey timerId)
      • getTimerSchedule

        protected abstract EJBTimerSchedule getTimerSchedule​(TimerPrimaryKey timerId)
                                                      throws jakarta.ejb.FinderException
        Called by #getScheduleExpression and #isCalendarTimer
        Parameters:
        timerId -
        Returns:
        Throws:
        jakarta.ejb.FinderException
      • isValidTimerForThisServer

        protected abstract boolean isValidTimerForThisServer​(TimerPrimaryKey timerId,
                                                             RuntimeTimerState timerState)
        Non-persistent timers are always valid because to be executed on this server instance.
        Parameters:
        timerId -
        timerState -
        Returns:
      • resetLastExpiration

        protected abstract void resetLastExpiration​(TimerPrimaryKey timerId,
                                                    RuntimeTimerState timerState)
        Nothing special to do for non-persistent timers
        Parameters:
        timerId -
        timerState -
      • getNonPersistentActiveTimerIdsByThisServer

        public abstract Set<TimerPrimaryKey> getNonPersistentActiveTimerIdsByThisServer()
      • getOwnerIdOfThisServer

        public String getOwnerIdOfThisServer()
        Return the ownerId of the server instance in which we are running.
      • listTimers

        public String[] listTimers​(String[] serverIds)
        Provide a count of timers owned by each server. Persistence timers are unknown to non-persistent timer service
      • createEJBException

        protected jakarta.ejb.EJBException createEJBException​(Exception ex)
        Create EJBException using the exception that is passed in
      • destroyTimers

        public void destroyTimers​(long containerId)
        Destroy all timers associated with a particular ejb container This is typically called when an ejb is undeployed. It expunges all timers whose timed object matches the given container. In the case of an entity bean container, all timers associated with any of that container's entity bean identities will be destroyed. This action *can not* be rolled back.
      • destroyAllTimers

        public void destroyAllTimers​(long applicationId)
        Destroy all timers associated with a particular application. This is called when an application is undeployed. It expunges all timers whose timed object matches the given application. In the case of an entity bean container, all timers associated with any of that container's entity bean identities will be destroyed. This action *can not* be rolled back.
      • _destroyTimers

        protected void _destroyTimers​(long id,
                                      boolean all)
      • calcNextFixedRateExpiration

        protected Date calcNextFixedRateExpiration​(RuntimeTimerState timerState)
      • calcNextFixedRateExpiration

        protected Date calcNextFixedRateExpiration​(Date initialExpiration,
                                                   long intervalDuration)
      • expungeTimer

        protected void expungeTimer​(TimerPrimaryKey timerId,
                                    boolean removeTimerBean)
        Remove all traces of a timer. This should be written defensively so that if expunge is called multiple times for the same timer id, the second, third, fourth, etc. calls will not cause exceptions.
      • _createTimer

        protected void _createTimer​(TimerPrimaryKey timerId,
                                    long containerId,
                                    long applicationId,
                                    Object timedObjectPrimaryKey,
                                    String server_name,
                                    Date initialExpiration,
                                    long intervalDuration,
                                    EJBTimerSchedule schedule,
                                    jakarta.ejb.TimerConfig timerConfig)
                             throws Exception
        Parameters:
        timedObjectPrimaryKey - can be null if timed object is not an entity bean.
        Throws:
        Exception
      • recoverAndCreateSchedules

        protected Map<TimerPrimaryKey,​Method> recoverAndCreateSchedules​(long containerId,
                                                                              long applicationId,
                                                                              Map<Method,​List<ScheduledTimerDescriptor>> schedules,
                                                                              boolean deploy)
        Create automatic non-persistent timers defined by the @Schedule annotation on the EJB bean. Recover part is a no-op in this case.
        Returns:
        a Map of created timers, where the key is TimerPrimaryKey and the value is the Method to be executed by the container when the timer with this PK times out.
      • createSchedulesOnServer

        public void createSchedulesOnServer​(EjbDescriptor ejbDescriptor,
                                            String server_name)
        Called in a clustered environment to eagerly create automatic persistent timers on the specific server instance. In a EJB Lite distribution if there is at least one persistent automatic timer defined, this method will fail with a RuntimeException.
      • createSchedules

        public void createSchedules​(long containerId,
                                    long applicationId,
                                    Map<MethodDescriptor,​List<ScheduledTimerDescriptor>> methodDescriptorSchedules,
                                    String server_name)
        Create automatic timers defined by the @Schedule annotation on the EJB bean during deployment to a cluster or the first create-application-ref call after deployment to DAS only. Only persistent schedule based timers for the containerId that has no timers associated with it, will be created. And no timers will be scheduled.
      • createSchedules

        protected void createSchedules​(long containerId,
                                       long applicationId,
                                       Map<?,​List<ScheduledTimerDescriptor>> schedules,
                                       Map<TimerPrimaryKey,​Method> result,
                                       String server_name,
                                       boolean startTimers,
                                       boolean deploy)
                                throws Exception
        Create automatic timers defined by the @Schedule annotation on the EJB bean. XXX??? If this method is called on a deploy in a clustered deployment, only persistent schedule based timers will be created. And no timers will be scheduled. If it is called from deploy on a non-clustered instance, both persistent and non-persistent timers will be created. Otherwise only non-persistent timers are created by this method.
        Throws:
        Exception
      • getTimerClassLoader

        public ClassLoader getTimerClassLoader​(long containerId)
        Get the application class loader for the timed object that created a given timer.
      • _getNextTimeout

        protected Date _getNextTimeout​(RuntimeTimerState rt)
        Non-persistent part of the implementation of the getNextTimeout() call
      • getContainer

        protected BaseContainer getContainer​(long containerId)
      • isCancelledByAnotherInstance

        protected boolean isCancelledByAnotherInstance​(RuntimeTimerState timerState)
        For a non-persistent timer, it's not possible to be cancelled by another server instance
      • redeliverTimeout

        protected boolean redeliverTimeout​(RuntimeTimerState timerState)
        Returns:
        true if this timer should be redelivered
      • stopOnFailure

        protected boolean stopOnFailure()
      • getMaxRedeliveries

        protected long getMaxRedeliveries()
      • enableRescheduleTimers

        protected void enableRescheduleTimers()
        Sets failed times to be rescheduled rather than removed. This is called by HazelcastTimerStore, as when an instance is removed from a cluster it is possible that a delivery could fail in the time in which an instance is removed from the cluster and before the timer is recreated.
      • getNextScheduledTimeout

        protected Date getNextScheduledTimeout​(EJBTimerSchedule ts)
        Returns next schedule-based timeout or null if such schedule will not expire again.
      • onShutdown

        public static void onShutdown()
        Called from TimerBean PreDestroy
      • timerStateToString

        public static String timerStateToString​(int state)