Package fish.payara.ejb.timer.hazelcast
Class HazelcastTimerStore
- java.lang.Object
-
- com.sun.ejb.containers.EJBTimerService
-
- com.sun.ejb.containers.NonPersistentEJBTimerService
-
- fish.payara.ejb.timer.hazelcast.HazelcastTimerStore
-
- All Implemented Interfaces:
ClusterListener,MessageReceiver<EjbTimerEvent>
public class HazelcastTimerStore extends NonPersistentEJBTimerService implements ClusterListener, MessageReceiver<EjbTimerEvent>
Store for EJB timers that exist across a Hazelcast cluster.- Since:
- 4.1.1.163
- Author:
- steve
-
-
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_
-
-
Constructor Summary
Constructors Constructor Description HazelcastTimerStore(HazelcastCore core)
-
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)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.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 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)Called by EJBTimerServiceWrapper when caller calls getTimers.protected Collection<TimerPrimaryKey>getTimerIds(Collection<Long> containerIds)protected EJBTimerSchedulegetTimerSchedule(TimerPrimaryKey timerId)Called by #getScheduleExpression and #isCalendarTimerprotected booleanisCancelledByAnotherInstance(RuntimeTimerState timerState)For a non-persistent timer, it's not possible to be cancelled by another server instancebooleanisPersistent()protected 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.voidmemberAdded(MemberEvent event)voidmemberRemoved(MemberEvent event)intmigrateTimers(String fromOwnerId)Called by CLI.Take ownership of another server's timers.voidreceiveMessage(ClusterMessage<EjbTimerEvent> ejbTimerEvent)Method to call when aClusterMessageis receivedprotected 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 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)Nothing special to do for non-persistent timersprotected 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
_destroyTimers, _getNextTimeout, addTimerSynchronization, addTimerSynchronization, addToSchedules, calcNextFixedRateExpiration, calcNextFixedRateExpiration, cancelTimerSynchronization, cancelTimerSynchronization, createEJBException, createSchedules, enableRescheduleTimers, getContainer, getEJBTimerService, getEJBTimerService, getEJBTimerService, getEJBTimerService, getEJBTimerServiceWrapper, getMaxRedeliveries, getNextScheduledTimeout, getNonPersistentTimerService, getOwnerIdOfThisServer, getPersistentTimerService, getTimerClassLoader, getTimerState, isNonPersistentTimerServiceLoaded, isPersistentTimerServiceLoaded, onShutdown, scheduleTask, setNonPersistentTimerService, setPersistentTimerService, stopTimers, timerStateToString
-
-
-
-
Constructor Detail
-
HazelcastTimerStore
public HazelcastTimerStore(HazelcastCore core) throws Exception
- Throws:
Exception
-
-
Method Detail
-
_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
- Overrides:
_createTimerin classEJBTimerServicetimedObjectPrimaryKey- can be null if timed object is not an entity bean.- Throws:
Exception
-
destroyAllTimers
public void destroyAllTimers(long applicationId)
Description copied from class:EJBTimerServiceDestroy 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.- Overrides:
destroyAllTimersin classEJBTimerService
-
destroyTimers
public void destroyTimers(long containerId)
Description copied from class:EJBTimerServiceDestroy 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.- Overrides:
destroyTimersin classEJBTimerService
-
cancelTimer
protected void cancelTimer(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException, Exception
- Overrides:
cancelTimerin classNonPersistentEJBTimerService- Throws:
jakarta.ejb.FinderExceptionException
-
getInfo
protected Serializable getInfo(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
- Overrides:
getInfoin classNonPersistentEJBTimerService- Throws:
jakarta.ejb.FinderException
-
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
-
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
-
createSchedules
public void createSchedules(long containerId, long applicationId, Map<MethodDescriptor,List<ScheduledTimerDescriptor>> methodDescriptorSchedules, String server_name)Description copied from class:EJBTimerServiceCreate 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
-
createSchedulesOnServer
public void createSchedulesOnServer(EjbDescriptor ejbDescriptor, String server_name)
Description copied from class:EJBTimerServiceCalled 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.- Overrides:
createSchedulesOnServerin classEJBTimerService
-
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
-
getTimerIds
protected Collection<TimerPrimaryKey> getTimerIds(Collection<Long> containerIds)
- Overrides:
getTimerIdsin classNonPersistentEJBTimerService- Parameters:
containerIds- the EJBs which own the timers- Returns:
- Collection of Timer Ids.
-
getTimerIds
protected Collection<TimerPrimaryKey> getTimerIds(long containerId, Object timedObjectPrimaryKey)
Description copied from class:EJBTimerServiceCalled by EJBTimerServiceWrapper when caller calls getTimers.- Overrides:
getTimerIdsin classNonPersistentEJBTimerService- Parameters:
containerId- the id of the EJB which owns the timerstimedObjectPrimaryKey- can be null if not entity bean- Returns:
- Collection of Timer Ids.
-
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
-
isPersistent
public boolean isPersistent()
- Overrides:
isPersistentin classNonPersistentEJBTimerService
-
isCancelledByAnotherInstance
protected boolean isCancelledByAnotherInstance(RuntimeTimerState timerState)
Description copied from class:EJBTimerServiceFor a non-persistent timer, it's not possible to be cancelled by another server instance- Overrides:
isCancelledByAnotherInstancein classEJBTimerService
-
isPersistent
protected boolean isPersistent(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
- Overrides:
isPersistentin classNonPersistentEJBTimerService- Throws:
jakarta.ejb.FinderException
-
isValidTimerForThisServer
protected boolean isValidTimerForThisServer(TimerPrimaryKey timerId, RuntimeTimerState timerState)
Description copied from class:EJBTimerServiceNon-persistent timers are always valid because to be executed on this server instance.- Overrides:
isValidTimerForThisServerin classNonPersistentEJBTimerService- Returns:
-
listTimers
public String[] listTimers(String[] serverIds)
Description copied from class:EJBTimerServiceProvide a count of timers owned by each server. Persistence timers are unknown to non-persistent timer service- Overrides:
listTimersin classEJBTimerService
-
migrateTimers
public int migrateTimers(String fromOwnerId)
Description copied from class:EJBTimerServiceCalled by CLI.Take ownership of another server's timers.- Overrides:
migrateTimersin classNonPersistentEJBTimerService- Returns:
-
recoverAndCreateSchedules
protected Map<TimerPrimaryKey,Method> recoverAndCreateSchedules(long containerId, long applicationId, Map<Method,List<ScheduledTimerDescriptor>> schedules, boolean deploy)
Description copied from class:EJBTimerServiceCreate automatic non-persistent timers defined by the @Schedule annotation on the EJB bean. Recover part is a no-op in this case.- Overrides:
recoverAndCreateSchedulesin classEJBTimerService- 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.
-
redeliverTimeout
protected boolean redeliverTimeout(RuntimeTimerState timerState)
- Overrides:
redeliverTimeoutin classEJBTimerService- Returns:
- true if this timer should be redelivered
-
resetLastExpiration
protected void resetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState timerState)
Description copied from class:EJBTimerServiceNothing special to do for non-persistent timers- Overrides:
resetLastExpirationin classNonPersistentEJBTimerService
-
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
-
stopOnFailure
protected boolean stopOnFailure()
- Overrides:
stopOnFailurein classEJBTimerService
-
timerExists
protected boolean timerExists(TimerPrimaryKey timerId)
- Overrides:
timerExistsin 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
-
memberAdded
public void memberAdded(MemberEvent event)
- Specified by:
memberAddedin interfaceClusterListener
-
memberRemoved
public void memberRemoved(MemberEvent event)
- Specified by:
memberRemovedin interfaceClusterListener
-
receiveMessage
public void receiveMessage(ClusterMessage<EjbTimerEvent> ejbTimerEvent)
Description copied from interface:MessageReceiverMethod to call when aClusterMessageis received- Specified by:
receiveMessagein interfaceMessageReceiver<EjbTimerEvent>
-
-