com.sleepycat.je.utilint
Class DaemonThread

java.lang.Object
  extended by com.sleepycat.je.utilint.DaemonThread
All Implemented Interfaces:
DaemonRunner, java.lang.Runnable
Direct Known Subclasses:
Checkpointer, Evictor, INCompressor

public abstract class DaemonThread
extends java.lang.Object
implements DaemonRunner, java.lang.Runnable

A daemon thread.


Field Summary
protected  java.lang.String name
           
protected  int nWakeupRequests
           
protected  boolean stifleExceptionChatter
           
 
Constructor Summary
DaemonThread(long waitTime, java.lang.String name, EnvironmentImpl envImpl)
           
 
Method Summary
 boolean checkErrorListener(java.lang.Throwable t)
           
 ExceptionListener getExceptionListener()
          For testing.
 int getNWakeupRequests()
          For unit testing.
 java.lang.Thread getThread()
          For testing.
protected  boolean isPaused()
          Returns whether the daemon is currently paused/disabled.
 boolean isRunning()
          Returns whether the onWakeup method is currently executing.
protected  boolean isShutdownRequested()
          Returns whether shutdown has been requested.
protected  long nDeadlockRetries()
          Returns the number of retries to perform when Deadlock Exceptions occur.
protected abstract  void onWakeup()
          onWakeup is synchronized to ensure that multiple invocations of the DaemonThread aren't made.
 void requestShutdown()
           
 void run()
           
 void runOrPause(boolean run)
          If run is true, starts the thread if not started or unpauses it if already started; if run is false, pauses the thread if started or does nothing if not started.
 void setExceptionListener(ExceptionListener exceptionListener)
           
 void shutdown()
          Requests shutdown and calls join() to wait for the thread to stop.
 java.lang.String toString()
           
 void wakeup()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

nWakeupRequests

protected int nWakeupRequests

stifleExceptionChatter

protected boolean stifleExceptionChatter
Constructor Detail

DaemonThread

public DaemonThread(long waitTime,
                    java.lang.String name,
                    EnvironmentImpl envImpl)
Method Detail

setExceptionListener

public void setExceptionListener(ExceptionListener exceptionListener)
Specified by:
setExceptionListener in interface DaemonRunner

getExceptionListener

public ExceptionListener getExceptionListener()
For testing.


getThread

public java.lang.Thread getThread()
For testing.


runOrPause

public void runOrPause(boolean run)
If run is true, starts the thread if not started or unpauses it if already started; if run is false, pauses the thread if started or does nothing if not started.

Specified by:
runOrPause in interface DaemonRunner

requestShutdown

public void requestShutdown()
Specified by:
requestShutdown in interface DaemonRunner

shutdown

public void shutdown()
Requests shutdown and calls join() to wait for the thread to stop.

Specified by:
shutdown in interface DaemonRunner

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

wakeup

public void wakeup()

run

public void run()
Specified by:
run in interface java.lang.Runnable

checkErrorListener

public boolean checkErrorListener(java.lang.Throwable t)

nDeadlockRetries

protected long nDeadlockRetries()
                         throws DatabaseException
Returns the number of retries to perform when Deadlock Exceptions occur.

Throws:
DatabaseException

onWakeup

protected abstract void onWakeup()
                          throws DatabaseException
onWakeup is synchronized to ensure that multiple invocations of the DaemonThread aren't made.

Throws:
DatabaseException

isShutdownRequested

protected boolean isShutdownRequested()
Returns whether shutdown has been requested. This method should be used to to terminate daemon loops.


isPaused

protected boolean isPaused()
Returns whether the daemon is currently paused/disabled. This method should be used to to terminate daemon loops.


isRunning

public boolean isRunning()
Returns whether the onWakeup method is currently executing. This is only an approximation and is used to avoid unnecessary wakeups.


getNWakeupRequests

public int getNWakeupRequests()
For unit testing.

Specified by:
getNWakeupRequests in interface DaemonRunner