Class EJBTimerService

java.lang.Object
com.sun.ejb.containers.EJBTimerService

public class EJBTimerService extends Object
  • Field Details

    • ejbContainerUtil

      protected final EjbContainerUtil ejbContainerUtil
    • isDas

      protected boolean isDas
    • ownerIdOfThisServer_

      protected String ownerIdOfThisServer_
    • timerCache_

      protected EJBTimerService.TimerCache timerCache_
    • totalTimedObjectsInitialized_

      protected long totalTimedObjectsInitialized_
    • STATE_ACTIVE

      public static final int STATE_ACTIVE
      See Also:
    • STATE_CANCELLED

      public static final int STATE_CANCELLED
      See Also:
  • Constructor Details

  • Method Details

    • setEJBTimerService

      protected static void setEJBTimerService(EJBTimerService es)
    • getEJBTimerService

      public static EJBTimerService getEJBTimerService()
    • getValidEJBTimerService

      public static EJBTimerService getValidEJBTimerService()
    • isEJBTimerServiceLoaded

      public static boolean isEJBTimerServiceLoaded()
    • getEJBTimerService

      public static EJBTimerService getEJBTimerService(String target)
    • getEJBTimerService

      public static EJBTimerService getEJBTimerService(String target, boolean force)
    • 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
    • migrateTimers

      public int migrateTimers(String fromOwnerId)
      Called by CLI. Take ownership of another server's timers.
    • createEJBException

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

      protected 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-persitent timers
    • addToSchedules

      protected void addToSchedules(long containerId, TimerPrimaryKey timerId, EJBTimerSchedule ts)
    • 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)
    • stopTimers

      protected 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.
    • stopTimers

      protected void stopTimers(Set<TimerPrimaryKey> timerIds)
    • scheduleTask

      protected void scheduleTask(TimerPrimaryKey timerId, Date expiration)
    • 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 thise 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<com.sun.enterprise.deployment.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
    • getTimerIds

      protected 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 Collection<TimerPrimaryKey> getTimerIds(Collection<Long> containerIds)
      Parameters:
      containerIds - the EJBs which own the timers
      Returns:
      Collection of Timer Ids.
    • getTimerClassLoader

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

      protected RuntimeTimerState getTimerState(TimerPrimaryKey timerId)
    • getNonPersistentActiveTimerIdsByThisServer

      public Set<TimerPrimaryKey> getNonPersistentActiveTimerIdsByThisServer()
    • cancelTimersByKey

      protected 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.
    • cancelTimer

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

      protected boolean cancelNonPersistentTimer(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException, Exception
      Throws:
      jakarta.ejb.FinderException
      Exception
    • getNextTimeout

      protected 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.
      Throws:
      jakarta.ejb.FinderException
    • _getNextTimeout

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

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

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

      protected boolean timerExists(TimerPrimaryKey timerId)
    • getTimerSchedule

      protected EJBTimerSchedule getTimerSchedule(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
      Called by #getScheduleExpression and #isCalendarTimer
      Throws:
      jakarta.ejb.FinderException
    • getNonPersistentTimer

      protected RuntimeTimerState getNonPersistentTimer(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
      Throws:
      jakarta.ejb.FinderException
    • 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()
    • isValidTimerForThisServer

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

      protected void resetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState timerState)
      Nothing special to do for non-persistent timers
    • getMaxRedeliveries

      protected long getMaxRedeliveries()
    • addTimerSynchronization

      public void addTimerSynchronization(EJBContextImpl context_, String timerId, Date initialExpiration, long containerId, String ownerId) throws Exception
      Throws:
      Exception
    • addTimerSynchronization

      public void addTimerSynchronization(EJBContextImpl context_, String timerId, Date initialExpiration, long containerId, String ownerId, boolean persistent) throws Exception
      Throws:
      Exception
    • cancelTimerSynchronization

      public void cancelTimerSynchronization(EJBContextImpl context_, TimerPrimaryKey timerId, long containerId, String ownerId) throws Exception
      Throws:
      Exception
    • getNextScheduledTimeout

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

      public boolean isPersistent()
    • onShutdown

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

      public static String timerStateToString(int state)