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 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.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
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)
Called by EJBTimerServiceWrapper when caller calls getTimers.protected Collection<TimerPrimaryKey>
getTimerIds(Collection<Long> containerIds)
protected EJBTimerSchedule
getTimerSchedule(TimerPrimaryKey timerId)
Called by #getScheduleExpression and #isCalendarTimerprotected boolean
isCancelledByAnotherInstance(RuntimeTimerState timerState)
For a non-persistent timer, it's not possible to be cancelled by another server instanceboolean
isPersistent()
protected boolean
isPersistent(TimerPrimaryKey timerId)
protected 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.void
memberAdded(MemberEvent event)
void
memberRemoved(MemberEvent event)
int
migrateTimers(String fromOwnerId)
Called by CLI.Take ownership of another server's timers.void
receiveMessage(ClusterMessage<EjbTimerEvent> ejbTimerEvent)
Method to call when aClusterMessage
is 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 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)
Nothing special to do for non-persistent timersprotected 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
_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:
_createTimer
in classEJBTimerService
timedObjectPrimaryKey
- can be null if timed object is not an entity bean.- Throws:
Exception
-
destroyAllTimers
public void destroyAllTimers(long applicationId)
Description copied from class:EJBTimerService
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.- Overrides:
destroyAllTimers
in classEJBTimerService
-
destroyTimers
public void destroyTimers(long containerId)
Description copied from class:EJBTimerService
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.- Overrides:
destroyTimers
in classEJBTimerService
-
cancelTimer
protected void cancelTimer(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException, Exception
- Overrides:
cancelTimer
in classNonPersistentEJBTimerService
- Throws:
jakarta.ejb.FinderException
Exception
-
getInfo
protected Serializable getInfo(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
- Overrides:
getInfo
in classNonPersistentEJBTimerService
- Throws:
jakarta.ejb.FinderException
-
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
-
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
-
createSchedules
public void createSchedules(long containerId, long applicationId, Map<MethodDescriptor,List<ScheduledTimerDescriptor>> methodDescriptorSchedules, String server_name)
Description copied from class:EJBTimerService
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
-
createSchedulesOnServer
public void createSchedulesOnServer(EjbDescriptor ejbDescriptor, String server_name)
Description copied from class:EJBTimerService
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.- Overrides:
createSchedulesOnServer
in classEJBTimerService
-
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
-
getTimerIds
protected Collection<TimerPrimaryKey> getTimerIds(Collection<Long> containerIds)
- Overrides:
getTimerIds
in 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:EJBTimerService
Called by EJBTimerServiceWrapper when caller calls getTimers.- Overrides:
getTimerIds
in 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:EJBTimerService
Called by #getScheduleExpression and #isCalendarTimer- Overrides:
getTimerSchedule
in classNonPersistentEJBTimerService
- Returns:
- Throws:
jakarta.ejb.FinderException
-
isPersistent
public boolean isPersistent()
- Overrides:
isPersistent
in classNonPersistentEJBTimerService
-
isCancelledByAnotherInstance
protected boolean isCancelledByAnotherInstance(RuntimeTimerState timerState)
Description copied from class:EJBTimerService
For a non-persistent timer, it's not possible to be cancelled by another server instance- Overrides:
isCancelledByAnotherInstance
in classEJBTimerService
-
isPersistent
protected boolean isPersistent(TimerPrimaryKey timerId) throws jakarta.ejb.FinderException
- Overrides:
isPersistent
in classNonPersistentEJBTimerService
- Throws:
jakarta.ejb.FinderException
-
isValidTimerForThisServer
protected boolean isValidTimerForThisServer(TimerPrimaryKey timerId, RuntimeTimerState timerState)
Description copied from class:EJBTimerService
Non-persistent timers are always valid because to be executed on this server instance.- Overrides:
isValidTimerForThisServer
in classNonPersistentEJBTimerService
- Returns:
-
listTimers
public String[] listTimers(String[] serverIds)
Description copied from class:EJBTimerService
Provide a count of timers owned by each server. Persistence timers are unknown to non-persistent timer service- Overrides:
listTimers
in classEJBTimerService
-
migrateTimers
public int migrateTimers(String fromOwnerId)
Description copied from class:EJBTimerService
Called by CLI.Take ownership of another server's timers.- Overrides:
migrateTimers
in classNonPersistentEJBTimerService
- Returns:
-
recoverAndCreateSchedules
protected Map<TimerPrimaryKey,Method> recoverAndCreateSchedules(long containerId, long applicationId, Map<Method,List<ScheduledTimerDescriptor>> schedules, boolean deploy)
Description copied from class:EJBTimerService
Create automatic non-persistent timers defined by the @Schedule annotation on the EJB bean. Recover part is a no-op in this case.- Overrides:
recoverAndCreateSchedules
in 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:
redeliverTimeout
in classEJBTimerService
- Returns:
- true if this timer should be redelivered
-
resetLastExpiration
protected void resetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState timerState)
Description copied from class:EJBTimerService
Nothing special to do for non-persistent timers- Overrides:
resetLastExpiration
in classNonPersistentEJBTimerService
-
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
-
stopOnFailure
protected boolean stopOnFailure()
- Overrides:
stopOnFailure
in classEJBTimerService
-
timerExists
protected boolean timerExists(TimerPrimaryKey timerId)
- Overrides:
timerExists
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
-
memberAdded
public void memberAdded(MemberEvent event)
- Specified by:
memberAdded
in interfaceClusterListener
-
memberRemoved
public void memberRemoved(MemberEvent event)
- Specified by:
memberRemoved
in interfaceClusterListener
-
receiveMessage
public void receiveMessage(ClusterMessage<EjbTimerEvent> ejbTimerEvent)
Description copied from interface:MessageReceiver
Method to call when aClusterMessage
is received- Specified by:
receiveMessage
in interfaceMessageReceiver<EjbTimerEvent>
-
-