Class PersistentEJBTimerService
- java.lang.Object
-
- com.sun.ejb.containers.EJBTimerService
-
- com.sun.ejb.containers.NonPersistentEJBTimerService
-
- org.glassfish.ejb.persistent.timer.PersistentEJBTimerService
-
public class PersistentEJBTimerService extends NonPersistentEJBTimerService
Persistent support part of the EJBTimerService- Author:
- Marina Vatkina
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.sun.ejb.containers.EJBTimerService
EJBTimerService.TimerCache
-
-
Field Summary
-
Fields inherited from class com.sun.ejb.containers.EJBTimerService
domainName_, ejbContainerUtil, isDas, ownerIdOfThisServer_, STATE_ACTIVE, STATE_CANCELLED, timerCache_, totalTimedObjectsInitialized_
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_createTimer(TimerPrimaryKey timerId, long containerId, long applicationId, Object timedObjectPrimaryKey, String server_name, Date initialExpiration, long intervalDuration, EJBTimerSchedule schedule, jakarta.ejb.TimerConfig timerConfig)Create persistent timer.protected void_destroyTimers(long id, boolean all)protected voidcancelTimer(TimerPrimaryKey timerId)protected voidcancelTimersByKey(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.voidcreateSchedules(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.voidcreateSchedulesOnServer(EjbDescriptor ejbDescriptor, String server_name)Called in a clustered environment to eagerly create automatic persistent timers on the specific server instance.protected voidexpungeTimer(TimerPrimaryKey timerId, boolean removeTimerBean)Remove all traces of a timer.protected SerializablegetInfo(TimerPrimaryKey timerId)protected DategetNextTimeout(TimerPrimaryKey timerId)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.protected Collection<TimerPrimaryKey>getTimerIds(long containerId, Object timedObjectPrimaryKey)Use database query to retrieve persistrent timer ids of all active timers.protected Collection<TimerPrimaryKey>getTimerIds(Collection<Long> containerIds)Return the Ids of active timers owned by EJBs.protected EJBTimerSchedulegetTimerSchedule(TimerPrimaryKey timerId)Called by #getScheduleExpression and #isCalendarTimerprotected booleanisCancelledByAnotherInstance(RuntimeTimerState timerState)Check if another server instance cancelled this timer.booleanisPersistent()protected booleanisPersistent(TimerPrimaryKey timerId)protected booleanisValidTimerForThisServer(TimerPrimaryKey timerId, RuntimeTimerState timerState)Persistent timers can be cancelled from another server instanceString[]listTimers(String[] serverIds)Provide a count of timers owned by each serverintmigrateTimers(String fromOwnerId)Take ownership of another server's timers.protected Map<TimerPrimaryKey,Method>recoverAndCreateSchedules(long containerId, long applicationId, Map<Method,List<ScheduledTimerDescriptor>> schedules, boolean deploy)Recover pre-existing timers associated with the Container identified by the containerId, and create automatic 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.No-op for non-persistent timersprotected voidresetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState timerState)Update database for a persistent timerprotected booleanstopOnFailure()protected voidstopTimers(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.protected booleantimerExists(TimerPrimaryKey timerId)-
Methods inherited from class com.sun.ejb.containers.NonPersistentEJBTimerService
cancelNonPersistentTimer, getNonPersistentActiveTimerIdsByThisServer, getNonPersistentTimer, isNonpersistent
-
Methods inherited from class com.sun.ejb.containers.EJBTimerService
_getNextTimeout, addTimerSynchronization, addTimerSynchronization, addToSchedules, calcNextFixedRateExpiration, calcNextFixedRateExpiration, cancelTimerSynchronization, cancelTimerSynchronization, createEJBException, createSchedules, destroyAllTimers, destroyTimers, enableRescheduleTimers, getContainer, getEJBTimerService, getEJBTimerService, getEJBTimerService, getEJBTimerService, getEJBTimerServiceWrapper, getMaxRedeliveries, getNextScheduledTimeout, getNonPersistentTimerService, getOwnerIdOfThisServer, getPersistentTimerService, getTimerClassLoader, getTimerState, isNonPersistentTimerServiceLoaded, isPersistentTimerServiceLoaded, onShutdown, scheduleTask, setNonPersistentTimerService, setPersistentTimerService, stopTimers, timerStateToString
-
-
-
-
Method Detail
-
listTimers
public String[] listTimers(String[] serverIds)
Provide a count of timers owned by each server- Overrides:
listTimersin classEJBTimerService
-
migrateTimers
public int migrateTimers(String fromOwnerId)
Take ownership of another server's timers.- Overrides:
migrateTimersin classNonPersistentEJBTimerService- Returns:
-
isPersistent
public boolean isPersistent()
- Overrides:
isPersistentin classNonPersistentEJBTimerService
-
cancelTimersByKey
protected void cancelTimersByKey(long containerId, Object primaryKey)Description copied from class:EJBTimerServiceCancel 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.- Overrides:
cancelTimersByKeyin classNonPersistentEJBTimerService
-
stopTimers
protected void stopTimers(long containerId)
Description copied from class:EJBTimerServiceRemove 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.- Overrides:
stopTimersin classNonPersistentEJBTimerService
-
_destroyTimers
protected void _destroyTimers(long id, boolean all)- Overrides:
_destroyTimersin classEJBTimerService
-
_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
Create persistent timer.- Overrides:
_createTimerin classEJBTimerServicetimedObjectPrimaryKey- 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)
Recover pre-existing timers associated with the Container identified by the containerId, and create automatic timers defined by the @Schedule annotation on the EJB bean. 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.- Overrides:
recoverAndCreateSchedulesin classEJBTimerService- Returns:
- a Map of both, restored and 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.- Overrides:
createSchedulesOnServerin classEJBTimerService
-
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.- Overrides:
createSchedulesin classEJBTimerService
-
getTimerIds
protected Collection<TimerPrimaryKey> getTimerIds(long containerId, Object timedObjectPrimaryKey)
Use database query to retrieve persistrent timer ids of all active timers. Results must be transactionally consistent. E.g., a client calling getTimerIds within a transaction where a timer has been created but not committed "sees" the timer but a client in a different transaction doesn't. Called by EJBTimerServiceWrapper when caller calls getTimers.- Overrides:
getTimerIdsin classNonPersistentEJBTimerService- Parameters:
timedObjectPrimaryKey- can be null if not entity beancontainerId- the id of the EJB which owns the timers- Returns:
- Collection of Timer Ids.
-
getTimerIds
protected Collection<TimerPrimaryKey> getTimerIds(Collection<Long> containerIds)
Return the Ids of active timers owned by EJBs. Primary key of entity bean is unnecessary because all of the active timers are expected- Overrides:
getTimerIdsin classNonPersistentEJBTimerService- Parameters:
containerIds- the EJBs which own the timers- Returns:
- Collection of Timer Ids.
-
cancelTimer
protected void cancelTimer(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException, Exception
- Overrides:
cancelTimerin classNonPersistentEJBTimerService- Throws:
jakarta.ejb.FinderExceptionException
-
getNextTimeout
protected Date getNextTimeout(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
Description copied from class:EJBTimerServiceReturn 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.- Overrides:
getNextTimeoutin classNonPersistentEJBTimerService- Returns:
- Throws:
jakarta.ejb.FinderException
-
getInfo
protected Serializable getInfo(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
- Overrides:
getInfoin classNonPersistentEJBTimerService- Throws:
jakarta.ejb.FinderException
-
isPersistent
protected boolean isPersistent(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
- Overrides:
isPersistentin classNonPersistentEJBTimerService- Throws:
jakarta.ejb.FinderException
-
timerExists
protected boolean timerExists(TimerPrimaryKey timerId)
- Overrides:
timerExistsin classNonPersistentEJBTimerService
-
getTimerSchedule
protected EJBTimerSchedule getTimerSchedule(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
Description copied from class:EJBTimerServiceCalled by #getScheduleExpression and #isCalendarTimer- Overrides:
getTimerSchedulein classNonPersistentEJBTimerService- Returns:
- Throws:
jakarta.ejb.FinderException
-
isCancelledByAnotherInstance
protected boolean isCancelledByAnotherInstance(RuntimeTimerState timerState)
Check if another server instance cancelled this timer.- Overrides:
isCancelledByAnotherInstancein classEJBTimerService
-
redeliverTimeout
protected boolean redeliverTimeout(RuntimeTimerState timerState)
- Overrides:
redeliverTimeoutin classEJBTimerService- Returns:
- true if this timer should be redelivered
-
isValidTimerForThisServer
protected boolean isValidTimerForThisServer(TimerPrimaryKey timerId, RuntimeTimerState timerState)
Persistent timers can be cancelled from another server instance- Overrides:
isValidTimerForThisServerin classNonPersistentEJBTimerService- Returns:
-
resetLastExpiration
protected void resetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState timerState)
Update database for a persistent timer- Overrides:
resetLastExpirationin classNonPersistentEJBTimerService
-
expungeTimer
protected void expungeTimer(TimerPrimaryKey timerId, boolean removeTimerBean)
Description copied from class:EJBTimerServiceRemove 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.- Overrides:
expungeTimerin classEJBTimerService
-
stopOnFailure
protected boolean stopOnFailure()
- Overrides:
stopOnFailurein classEJBTimerService
-
resetEJBTimers
protected void resetEJBTimers(String target)
Description copied from class:EJBTimerServiceCalled 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- Overrides:
resetEJBTimersin classNonPersistentEJBTimerService
-
-