Package com.sun.ejb.containers
Class EJBTimerService
- java.lang.Object
-
- com.sun.ejb.containers.EJBTimerService
-
- Direct Known Subclasses:
NonPersistentEJBTimerService
public abstract class EJBTimerService extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EJBTimerService.TimerCache
-
Field Summary
Fields Modifier and Type Field Description protected String
domainName_
protected EjbContainerUtil
ejbContainerUtil
protected boolean
isDas
protected String
ownerIdOfThisServer_
static int
STATE_ACTIVE
static int
STATE_CANCELLED
protected EJBTimerService.TimerCache
timerCache_
protected long
totalTimedObjectsInitialized_
-
Constructor Summary
Constructors Modifier Constructor Description protected
EJBTimerService()
-
Method Summary
All Methods Static Methods Instance Methods Abstract 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)
protected void
_destroyTimers(long id, boolean all)
protected Date
_getNextTimeout(RuntimeTimerState rt)
Non-persistent part of the implementation of the getNextTimeout() callvoid
addTimerSynchronization(EJBContextImpl context_, String timerId, Date initialExpiration, long containerId, String ownerId)
void
addTimerSynchronization(EJBContextImpl context_, String timerId, Date initialExpiration, long containerId, String ownerId, boolean persistent)
protected void
addToSchedules(long containerId, TimerPrimaryKey timerId, EJBTimerSchedule ts)
protected Date
calcNextFixedRateExpiration(RuntimeTimerState timerState)
protected Date
calcNextFixedRateExpiration(Date initialExpiration, long intervalDuration)
protected abstract void
cancelTimer(TimerPrimaryKey timerId)
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.void
cancelTimerSynchronization(EJBContextImpl context_, TimerPrimaryKey timerId, long containerId, String ownerId)
protected void
cancelTimerSynchronization(EJBContextImpl context_, TimerPrimaryKey timerId, long containerId, String ownerId, boolean persistent)
protected jakarta.ejb.EJBException
createEJBException(Exception ex)
Create EJBException using the exception that is passed inprotected void
createSchedules(long containerId, long applicationId, Map<?,List<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.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.void
destroyAllTimers(long applicationId)
Destroy all timers associated with a particular application.void
destroyTimers(long containerId)
Destroy all timers associated with a particular ejb container This is typically called when an ejb is undeployed.protected void
enableRescheduleTimers()
Sets failed times to be rescheduled rather than removed.protected void
expungeTimer(TimerPrimaryKey timerId, boolean removeTimerBean)
Remove all traces of a timer.protected BaseContainer
getContainer(long containerId)
static EJBTimerService
getEJBTimerService(boolean persistent)
static EJBTimerService
getEJBTimerService(String target)
static EJBTimerService
getEJBTimerService(String target, boolean force)
static EJBTimerService
getEJBTimerService(String target, boolean force, boolean persistent)
static EJBTimerServiceWrapper
getEJBTimerServiceWrapper(EJBContextImpl ejbContext)
protected abstract Serializable
getInfo(TimerPrimaryKey timerId)
protected long
getMaxRedeliveries()
protected Date
getNextScheduledTimeout(EJBTimerSchedule ts)
Returns next schedule-based timeout or null if such schedule will not expire again.protected abstract 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.abstract Set<TimerPrimaryKey>
getNonPersistentActiveTimerIdsByThisServer()
static EJBTimerService
getNonPersistentTimerService()
String
getOwnerIdOfThisServer()
Return the ownerId of the server instance in which we are running.static EJBTimerService
getPersistentTimerService()
ClassLoader
getTimerClassLoader(long containerId)
Get the application class loader for the timed object that created a given timer.protected abstract Collection<TimerPrimaryKey>
getTimerIds(long containerId, Object timedObjectPrimaryKey)
Called by EJBTimerServiceWrapper when caller calls getTimers.protected abstract Collection<TimerPrimaryKey>
getTimerIds(Collection<Long> containerIds)
protected abstract EJBTimerSchedule
getTimerSchedule(TimerPrimaryKey timerId)
Called by #getScheduleExpression and #isCalendarTimerprotected RuntimeTimerState
getTimerState(TimerPrimaryKey timerId)
protected boolean
isCancelledByAnotherInstance(RuntimeTimerState timerState)
For a non-persistent timer, it's not possible to be cancelled by another server instancestatic boolean
isNonPersistentTimerServiceLoaded()
abstract boolean
isPersistent()
protected abstract boolean
isPersistent(TimerPrimaryKey timerId)
static boolean
isPersistentTimerServiceLoaded()
protected abstract boolean
isValidTimerForThisServer(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.abstract int
migrateTimers(String fromOwnerId)
Called by CLI.Take ownership of another server's timers.static void
onShutdown()
Called from TimerBean PreDestroyprotected 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.protected boolean
redeliverTimeout(RuntimeTimerState timerState)
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 timersprotected abstract void
resetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState timerState)
Nothing special to do for non-persistent timersprotected void
scheduleTask(TimerPrimaryKey timerId, Date expiration)
protected static void
setNonPersistentTimerService(EJBTimerService timerService)
protected static void
setPersistentTimerService(EJBTimerService timerService)
protected boolean
stopOnFailure()
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.protected void
stopTimers(Set<TimerPrimaryKey> timerIds)
protected abstract boolean
timerExists(TimerPrimaryKey timerId)
static String
timerStateToString(int state)
-
-
-
Field Detail
-
ejbContainerUtil
protected EjbContainerUtil ejbContainerUtil
-
domainName_
protected String domainName_
-
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:
- Constant Field Values
-
STATE_CANCELLED
public static final int STATE_CANCELLED
- See Also:
- Constant Field Values
-
-
Method Detail
-
getEJBTimerServiceWrapper
public static EJBTimerServiceWrapper getEJBTimerServiceWrapper(EJBContextImpl ejbContext)
-
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)
-
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 timerstimedObjectPrimaryKey
- 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
-
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(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 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.
-
getTimerState
protected RuntimeTimerState getTimerState(TimerPrimaryKey timerId)
-
_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()
-
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
-
cancelTimerSynchronization
protected void cancelTimerSynchronization(EJBContextImpl context_, TimerPrimaryKey timerId, long containerId, String ownerId, boolean persistent) throws Exception
- Throws:
Exception
-
enableRescheduleTimers
protected void enableRescheduleTimers()
Sets failed times to be rescheduled rather than removed. This is called byHazelcastTimerStore
, 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)
-
-