Class DatabaseTimerPersistence
- java.lang.Object
-
- org.jboss.as.ejb3.timerservice.persistence.database.DatabaseTimerPersistence
-
- All Implemented Interfaces:
TimerPersistence,org.jboss.msc.Service,org.jboss.msc.service.Service<DatabaseTimerPersistence>,org.jboss.msc.value.Value<DatabaseTimerPersistence>
public class DatabaseTimerPersistence extends Object implements TimerPersistence, org.jboss.msc.service.Service<DatabaseTimerPersistence>
Database timer persistence store.
- Author:
- Stuart Douglas, Wolf-Dieter Fink, Joerg Baesner
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.as.ejb3.timerservice.persistence.TimerPersistence
TimerPersistence.TimerChangeListener
-
-
Field Summary
-
Fields inherited from interface org.jboss.as.ejb3.timerservice.persistence.TimerPersistence
SERVICE_NAME
-
-
Constructor Summary
Constructors Constructor Description DatabaseTimerPersistence(String database, String partition, String nodeName, int refreshInterval, boolean allowExecution)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTimer(TimerImpl timerEntity)Called when a timer is being persisted.ObjectdeSerialize(String data)org.jboss.msc.value.InjectedValue<ManagedReferenceFactory>getDataSourceInjectedValue()org.jboss.msc.value.InjectedValue<org.jboss.modules.ModuleLoader>getModuleLoader()SerializablegetPersistedTimerInfo(TimerImpl timer)Retrieves the timer info from the timer database.org.jboss.msc.value.InjectedValue<Timer>getTimerInjectedValue()DatabaseTimerPersistencegetValue()List<TimerImpl>loadActiveTimers(String timedObjectId, TimerServiceImpl timerService)Load all active timers for the given object.TimerImplloadTimer(String timedObjectId, String timerId, TimerServiceImpl timerService)Loads a timer from database by its id and timed object id.voidpersistTimer(TimerImpl timerEntity)Called when a timer is being persistedvoidrefreshTimers()CloseableregisterChangeListener(String timedObjectId, TimerPersistence.TimerChangeListener listener)Registers a listener to listed for new timers that are added to the database.booleanshouldRun(TimerImpl timer)Invoked before running a timer in order to determine if this node should run the timer.voidstart(org.jboss.msc.service.StartContext context)voidstop(org.jboss.msc.service.StopContext context)voidtimerDeployed(String timedObjectId)Signals that the timer is being deployed and any internal structured required should be added.voidtimerUndeployed(String timedObjectId)Signals that a timer is being undeployed, and all cached data relating to this object should be dropped to prevent a class loader leak
-
-
-
Method Detail
-
start
public void start(org.jboss.msc.service.StartContext context) throws org.jboss.msc.service.StartException- Specified by:
startin interfaceorg.jboss.msc.Service- Specified by:
startin interfaceorg.jboss.msc.service.Service<DatabaseTimerPersistence>- Throws:
org.jboss.msc.service.StartException
-
stop
public void stop(org.jboss.msc.service.StopContext context)
- Specified by:
stopin interfaceorg.jboss.msc.Service- Specified by:
stopin interfaceorg.jboss.msc.service.Service<DatabaseTimerPersistence>
-
loadTimer
public TimerImpl loadTimer(String timedObjectId, String timerId, TimerServiceImpl timerService)
Loads a timer from database by its id and timed object id.- Parameters:
timedObjectId- the timed object id for the timertimerId- the timer idtimerService- the active timer service- Returns:
- the timer loaded from database; null if nothing can be loaded
-
addTimer
public void addTimer(TimerImpl timerEntity)
Description copied from interface:TimerPersistenceCalled when a timer is being persisted. In a clustered environment, if an auto timer has already been persisted by another concurrent node, it should not be persisted again, and its state should be set toCANCELED.- Specified by:
addTimerin interfaceTimerPersistence- Parameters:
timerEntity- The timer
-
persistTimer
public void persistTimer(TimerImpl timerEntity)
Description copied from interface:TimerPersistenceCalled when a timer is being persisted- Specified by:
persistTimerin interfaceTimerPersistence- Parameters:
timerEntity- The timer
-
shouldRun
public boolean shouldRun(TimerImpl timer)
Description copied from interface:TimerPersistenceInvoked before running a timer in order to determine if this node should run the timer.- Specified by:
shouldRunin interfaceTimerPersistence- Parameters:
timer- The timer- Returns:
- true if the timer should be run
-
timerUndeployed
public void timerUndeployed(String timedObjectId)
Description copied from interface:TimerPersistenceSignals that a timer is being undeployed, and all cached data relating to this object should be dropped to prevent a class loader leak- Specified by:
timerUndeployedin interfaceTimerPersistence
-
timerDeployed
public void timerDeployed(String timedObjectId)
Description copied from interface:TimerPersistenceSignals that the timer is being deployed and any internal structured required should be added.- Specified by:
timerDeployedin interfaceTimerPersistence
-
loadActiveTimers
public List<TimerImpl> loadActiveTimers(String timedObjectId, TimerServiceImpl timerService)
Description copied from interface:TimerPersistenceLoad all active timers for the given object. If the object is an entity bean timers for all beans will be returned.- Specified by:
loadActiveTimersin interfaceTimerPersistence- Parameters:
timedObjectId- The timed object id to load timers for- Returns:
- A list of all active timers
-
registerChangeListener
public Closeable registerChangeListener(String timedObjectId, TimerPersistence.TimerChangeListener listener)
Description copied from interface:TimerPersistenceRegisters a listener to listed for new timers that are added to the database.- Specified by:
registerChangeListenerin interfaceTimerPersistence- Parameters:
timedObjectId- The timed objectlistener- The listener- Returns:
- A Closable that can be used to unregister the listener
-
getValue
public DatabaseTimerPersistence getValue() throws IllegalStateException, IllegalArgumentException
- Specified by:
getValuein interfaceorg.jboss.msc.value.Value<DatabaseTimerPersistence>- Throws:
IllegalStateExceptionIllegalArgumentException
-
refreshTimers
public void refreshTimers()
-
getPersistedTimerInfo
public Serializable getPersistedTimerInfo(TimerImpl timer)
Retrieves the timer info from the timer database.- Parameters:
timer- the timer whose info to be retrieved- Returns:
- the timer info from database; null if
SQLException
-
deSerialize
public Object deSerialize(String data) throws SQLException
- Throws:
SQLException
-
getDataSourceInjectedValue
public org.jboss.msc.value.InjectedValue<ManagedReferenceFactory> getDataSourceInjectedValue()
-
getModuleLoader
public org.jboss.msc.value.InjectedValue<org.jboss.modules.ModuleLoader> getModuleLoader()
-
getTimerInjectedValue
public org.jboss.msc.value.InjectedValue<Timer> getTimerInjectedValue()
-
-