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 void
cancelTimer(TimerPrimaryKey timerId)
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.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.void
createSchedulesOnServer(EjbDescriptor ejbDescriptor, String server_name)
Called in a clustered environment to eagerly create automatic persistent timers on the specific server instance.protected void
expungeTimer(TimerPrimaryKey timerId, boolean removeTimerBean)
Remove all traces of a timer.protected Serializable
getInfo(TimerPrimaryKey timerId)
protected Date
getNextTimeout(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 EJBTimerSchedule
getTimerSchedule(TimerPrimaryKey timerId)
Called by #getScheduleExpression and #isCalendarTimerprotected boolean
isCancelledByAnotherInstance(RuntimeTimerState timerState)
Check if another server instance cancelled this timer.boolean
isPersistent()
protected boolean
isPersistent(TimerPrimaryKey timerId)
protected boolean
isValidTimerForThisServer(TimerPrimaryKey timerId, RuntimeTimerState timerState)
Persistent timers can be cancelled from another server instanceString[]
listTimers(String[] serverIds)
Provide a count of timers owned by each serverint
migrateTimers(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 boolean
redeliverTimeout(RuntimeTimerState timerState)
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-persistent timersprotected void
resetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState timerState)
Update database for a persistent timerprotected boolean
stopOnFailure()
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.protected boolean
timerExists(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:
listTimers
in classEJBTimerService
-
migrateTimers
public int migrateTimers(String fromOwnerId)
Take ownership of another server's timers.- Overrides:
migrateTimers
in classNonPersistentEJBTimerService
- Returns:
-
isPersistent
public boolean isPersistent()
- Overrides:
isPersistent
in classNonPersistentEJBTimerService
-
cancelTimersByKey
protected void cancelTimersByKey(long containerId, Object primaryKey)
Description copied from class:EJBTimerService
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.- Overrides:
cancelTimersByKey
in classNonPersistentEJBTimerService
-
stopTimers
protected void stopTimers(long containerId)
Description copied from class:EJBTimerService
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.- Overrides:
stopTimers
in classNonPersistentEJBTimerService
-
_destroyTimers
protected void _destroyTimers(long id, boolean all)
- Overrides:
_destroyTimers
in 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:
_createTimer
in classEJBTimerService
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)
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:
recoverAndCreateSchedules
in 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:
createSchedulesOnServer
in 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:
createSchedules
in 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:
getTimerIds
in 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:
getTimerIds
in 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:
cancelTimer
in classNonPersistentEJBTimerService
- Throws:
jakarta.ejb.FinderException
Exception
-
getNextTimeout
protected Date getNextTimeout(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
Description copied from class:EJBTimerService
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.- Overrides:
getNextTimeout
in classNonPersistentEJBTimerService
- Returns:
- Throws:
jakarta.ejb.FinderException
-
getInfo
protected Serializable getInfo(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
- Overrides:
getInfo
in classNonPersistentEJBTimerService
- Throws:
jakarta.ejb.FinderException
-
isPersistent
protected boolean isPersistent(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
- Overrides:
isPersistent
in classNonPersistentEJBTimerService
- Throws:
jakarta.ejb.FinderException
-
timerExists
protected boolean timerExists(TimerPrimaryKey timerId)
- Overrides:
timerExists
in classNonPersistentEJBTimerService
-
getTimerSchedule
protected EJBTimerSchedule getTimerSchedule(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
Description copied from class:EJBTimerService
Called by #getScheduleExpression and #isCalendarTimer- Overrides:
getTimerSchedule
in classNonPersistentEJBTimerService
- Returns:
- Throws:
jakarta.ejb.FinderException
-
isCancelledByAnotherInstance
protected boolean isCancelledByAnotherInstance(RuntimeTimerState timerState)
Check if another server instance cancelled this timer.- Overrides:
isCancelledByAnotherInstance
in classEJBTimerService
-
redeliverTimeout
protected boolean redeliverTimeout(RuntimeTimerState timerState)
- Overrides:
redeliverTimeout
in 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:
isValidTimerForThisServer
in classNonPersistentEJBTimerService
- Returns:
-
resetLastExpiration
protected void resetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState timerState)
Update database for a persistent timer- Overrides:
resetLastExpiration
in classNonPersistentEJBTimerService
-
expungeTimer
protected void expungeTimer(TimerPrimaryKey timerId, boolean removeTimerBean)
Description copied from class:EJBTimerService
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.- Overrides:
expungeTimer
in classEJBTimerService
-
stopOnFailure
protected boolean stopOnFailure()
- Overrides:
stopOnFailure
in classEJBTimerService
-
resetEJBTimers
protected void resetEJBTimers(String target)
Description copied from class:EJBTimerService
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- Overrides:
resetEJBTimers
in classNonPersistentEJBTimerService
-
-