Package com.sun.ejb.containers
Class EJBTimerService
java.lang.Object
com.sun.ejb.containers.EJBTimerService
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final EjbContainerUtilprotected booleanprotected Stringstatic final intstatic final intprotected EJBTimerService.TimerCacheprotected long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void_createTimer(TimerPrimaryKey timerId, long containerId, long applicationId, Object timedObjectPrimaryKey, String server_name, Date initialExpiration, long intervalDuration, EJBTimerSchedule schedule, jakarta.ejb.TimerConfig timerConfig) protected void_destroyTimers(long id, boolean all) protected DateNon-persistent part of the implementation of the getNextTimeout() callvoidaddTimerSynchronization(EJBContextImpl context_, String timerId, Date initialExpiration, long containerId, String ownerId) voidaddTimerSynchronization(EJBContextImpl context_, String timerId, Date initialExpiration, long containerId, String ownerId, boolean persistent) protected voidaddToSchedules(long containerId, TimerPrimaryKey timerId, EJBTimerSchedule ts) protected DatecalcNextFixedRateExpiration(RuntimeTimerState timerState) protected DatecalcNextFixedRateExpiration(Date initialExpiration, long intervalDuration) protected booleancancelNonPersistentTimer(TimerPrimaryKey timerId) protected voidcancelTimer(TimerPrimaryKey timerId) protected voidcancelTimersByKey(long containerId, Object primaryKey) Cancel all timers associated with a particular entity bean identity.voidcancelTimerSynchronization(EJBContextImpl context_, TimerPrimaryKey timerId, long containerId, String ownerId) protected jakarta.ejb.EJBExceptionCreate EJBException using the exception that is passed inprotected voidcreateSchedules(long containerId, long applicationId, Map<?, List<com.sun.enterprise.deployment.ScheduledTimerDescriptor>> schedules, Map<TimerPrimaryKey, Method> result, String server_name, boolean startTimers, boolean deploy) Create automatic timers defined by the @Schedule annotation on the EJB bean.voidcreateSchedules(long containerId, long applicationId, Map<com.sun.enterprise.deployment.MethodDescriptor, List<com.sun.enterprise.deployment.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.voidcreateSchedulesOnServer(EjbDescriptor ejbDescriptor, String server_name) Called in a clustered environment to eagerly create automatic persistent timers on the specific server instance.voiddestroyAllTimers(long applicationId) Destroy all timers associated with a particular application.voiddestroyTimers(long containerId) Destroy all timers associated with a particular ejb container This is typically called when an ejb is undeployed.protected voidexpungeTimer(TimerPrimaryKey timerId, boolean removeTimerBean) Remove all traces of a timer.protected BaseContainergetContainer(long containerId) static EJBTimerServicestatic EJBTimerServicegetEJBTimerService(String target) static EJBTimerServicegetEJBTimerService(String target, boolean force) protected SerializablegetInfo(TimerPrimaryKey timerId) protected longprotected DateReturns next schedule-based timeout or null if such schedule will not expire again.protected DategetNextTimeout(TimerPrimaryKey timerId) Return next planned timeout for this timer.protected RuntimeTimerStategetNonPersistentTimer(TimerPrimaryKey timerId) Return the ownerId of the server instance in which we are running.getTimerClassLoader(long containerId) Get the application class loader for the timed object that created a given timer.protected Collection<TimerPrimaryKey> getTimerIds(long containerId, Object timedObjectPrimaryKey) Called by EJBTimerServiceWrapper when caller calls getTimers.protected Collection<TimerPrimaryKey> getTimerIds(Collection<Long> containerIds) protected EJBTimerSchedulegetTimerSchedule(TimerPrimaryKey timerId) Called by #getScheduleExpression and #isCalendarTimerprotected RuntimeTimerStategetTimerState(TimerPrimaryKey timerId) static EJBTimerServiceprotected booleanisCancelledByAnotherInstance(RuntimeTimerState timerState) For a non-persistent timer, it's not possible to be cancelled by another server instancestatic booleanbooleanprotected booleanisPersistent(TimerPrimaryKey timerId) protected booleanisValidTimerForThisServer(TimerPrimaryKey timerId, RuntimeTimerState timerState) Non-persistent timers are always valid because to be executed on this server instance.String[]listTimers(String[] serverIds) Provide a count of timers owned by each server.intmigrateTimers(String fromOwnerId) Called by CLI.static voidCalled from TimerBean PreDestroyprotected Map<TimerPrimaryKey, Method> recoverAndCreateSchedules(long containerId, long applicationId, Map<Method, List<com.sun.enterprise.deployment.ScheduledTimerDescriptor>> schedules, boolean deploy) Create automatic non-persistent timers defined by the @Schedule annotation on the EJB bean.protected booleanredeliverTimeout(RuntimeTimerState timerState) protected voidresetEJBTimers(String target) Called at server startup *after* user apps have been re-activated to restart any active EJB timers or cleanup old timers.protected voidresetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState timerState) Nothing special to do for non-persistent timersprotected voidscheduleTask(TimerPrimaryKey timerId, Date expiration) protected static voidprotected booleanprotected voidstopTimers(long containerId) Remove from the cache and stop all timers associated with a particular ejb container and known to this server instance.protected voidstopTimers(Set<TimerPrimaryKey> timerIds) protected booleantimerExists(TimerPrimaryKey timerId) static StringtimerStateToString(int state)
-
Field Details
-
ejbContainerUtil
-
isDas
protected boolean isDas -
ownerIdOfThisServer_
-
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
-
EJBTimerService
- Throws:
Exception
-
-
Method Details
-
setEJBTimerService
-
getEJBTimerService
-
getValidEJBTimerService
-
isEJBTimerServiceLoaded
public static boolean isEJBTimerServiceLoaded() -
getEJBTimerService
-
getEJBTimerService
-
getOwnerIdOfThisServer
Return the ownerId of the server instance in which we are running. -
listTimers
Provide a count of timers owned by each server. Persistence timers are unknown to non-persistent timer service -
migrateTimers
Called by CLI. Take ownership of another server's timers. -
createEJBException
Create EJBException using the exception that is passed in -
resetEJBTimers
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
-
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
-
scheduleTask
-
calcNextFixedRateExpiration
-
calcNextFixedRateExpiration
-
expungeTimer
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<com.sun.enterprise.deployment.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
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<com.sun.enterprise.deployment.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<com.sun.enterprise.deployment.ScheduledTimerDescriptor>> schedules, Map<TimerPrimaryKey, throws ExceptionMethod> result, String server_name, boolean startTimers, boolean deploy) 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
Called by EJBTimerServiceWrapper when caller calls getTimers.- Parameters:
containerId- the id of the EJB which owns the timerstimedObjectPrimaryKey- can be null if not entity bean- Returns:
- Collection of Timer Ids.
-
getTimerIds
- Parameters:
containerIds- the EJBs which own the timers- Returns:
- Collection of Timer Ids.
-
getTimerClassLoader
Get the application class loader for the timed object that created a given timer. -
getTimerState
-
getNonPersistentActiveTimerIdsByThisServer
-
cancelTimersByKey
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
- Throws:
jakarta.ejb.FinderExceptionException
-
cancelNonPersistentTimer
protected boolean cancelNonPersistentTimer(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException, Exception - Throws:
jakarta.ejb.FinderExceptionException
-
getNextTimeout
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
Non-persistent part of the implementation of the getNextTimeout() call -
getInfo
- Throws:
jakarta.ejb.FinderException
-
isPersistent
- Throws:
jakarta.ejb.FinderException
-
timerExists
-
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
-
isCancelledByAnotherInstance
For a non-persistent timer, it's not possible to be cancelled by another server instance -
redeliverTimeout
- Returns:
- true if this timer should be redelivered
-
stopOnFailure
protected boolean stopOnFailure() -
isValidTimerForThisServer
Non-persistent timers are always valid because to be executed on this server instance. -
resetLastExpiration
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
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
-