Class PeriodicRecovery
- All Implemented Interfaces:
Runnable
n.b. recovery scans may be performed by this object (it is a thread and may be started as a background task) and by other ad hoc threads
- Version:
- $Id: PeriodicRecovery.java 2342 2006-03-30 13:06:17Z $
- Author:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
state values indicating operating mode of scanning process for ad hoc threads and controlling behaviour of singleton periodic recovery thread.static enum
state values indicating whether or not some thread is currently scanning.Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
default value for _backoffPeriod if not specified via RecoveryEnvironmentBeanstatic final int
default value for _recoveryPeriod if not specified via RecoveryEnvironmentBeanFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addModule
(RecoveryModule module) Add the specified module to the end of the recovery module list.final void
doWork()
Perform a recovery scan on all registered modules.getMode()
fetch the current recovery operation mode either ENABLED, SUSPENDED or TERMINATED Caveats: must only be called while synchronized on_stateLock
final Vector
<RecoveryModule> return a copy of the current recovery modules listfinal void
removeAllModules
(boolean waitOnScan) Remove all modules.final void
removeModule
(RecoveryModule module, boolean waitOnScan) remove a recovery module from the recovery modules listvoid
resume scanning operations This switches the recovery operation mode from SUSPENDED to RESUMED.void
run()
Implements the background thread which performs the periodic recoveryvoid
shutdown
(boolean async) initiate termination of the periodic recovery thread and stop any subsequent scan requests from proceeding.suspendScan
(boolean async) Make all scanning operations suspend.void
wakeUp()
called by the listener worker to wake the periodic recovery thread and get it to start a scan if one is not already in progressMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
_defaultBackoffPeriod
public static final int _defaultBackoffPerioddefault value for _backoffPeriod if not specified via RecoveryEnvironmentBean- See Also:
-
_defaultRecoveryPeriod
public static final int _defaultRecoveryPerioddefault value for _recoveryPeriod if not specified via RecoveryEnvironmentBean- See Also:
-
-
Constructor Details
-
PeriodicRecovery
public PeriodicRecovery(boolean threaded, boolean useListener) - Parameters:
threaded
-useListener
- if true, start a socket based listener.
-
-
Method Details
-
shutdown
public void shutdown(boolean async) initiate termination of the periodic recovery thread and stop any subsequent scan requests from proceeding. this switches the recovery operation mode to TERMINATED. if a scan is in progress when this method is called and has not yet started phase 2 of its scan it will be forced to return before completing phase 2.- Parameters:
async
- false if the calling thread should wait for any in-progress scan to complete before returning
-
suspendScan
Make all scanning operations suspend.This switches the recovery operation mode to
SUSPENDED
. Any attempt to start a new scan either by ad hoc threads or by the periodic recovery thread will suspend its thread until the mode changes. If a scan is in progress when this method is called it will complete its scan without suspending.Note that this method is also influenced by
RecoveryEnvironmentBean.isWaitForWorkLeftToDo()
. In caseRecoveryEnvironmentBean.setWaitForWorkLeftToDo(boolean)
was initialised to true, it is important that, before invoking this method, all transactions will either be terminated by the Transaction Reaper or they have prepared and a log has been written, otherwise the suspend call may never return.- Parameters:
async
- false if the calling thread should wait for any in-progress scan to complete before returning. In caseRecoveryEnvironmentBean.isWaitForWorkLeftToDo()
is true, this parameter is overridden.- Returns:
- the previous mode before attempting the suspension
-
resumeScan
public void resumeScan()resume scanning operations This switches the recovery operation mode from SUSPENDED to RESUMED. Any threads which suspended when they tried to start a scan will be woken up by this transition. -
getServerSocket
- Returns:
- a bound server socket corresponding to the recovery manager
- Throws:
IOException
- if the host name is unknown or the endpoint has already been bound
-
run
public void run()Implements the background thread which performs the periodic recovery -
doWork
public final void doWork()Perform a recovery scan on all registered modules. Caveats: if a scan is already in progress this method will wait for it to complete otherwise it will perform its own scan before returning. If scanning is suspended this will require waiting for scanning to resume. -
wakeUp
public void wakeUp()called by the listener worker to wake the periodic recovery thread and get it to start a scan if one is not already in progress -
addModule
Add the specified module to the end of the recovery module list. There is no way to specify relative ordering of recovery modules with respect to modules loaded via the property file.- Parameters:
module
- The module to append.
-
removeModule
remove a recovery module from the recovery modules list- Parameters:
module
- the module to be removedwaitOnScan
- true if the remove operation should wait for any in-progress scan to complete
-
removeAllModules
public final void removeAllModules(boolean waitOnScan) Remove all modules.- Parameters:
waitOnScan
- true if the remove operation should wait for any in-progress scan to complete.
-
getModules
return a copy of the current recovery modules list- Returns:
- a copy of the the recovery modules list.
-
getListener
-
getMode
fetch the current recovery operation mode either ENABLED, SUSPENDED or TERMINATED Caveats: must only be called while synchronized on_stateLock
- Returns:
- the current recovery operation mode
-