com.sleepycat.je.utilint
Class DaemonThread

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

public abstract class DaemonThread
extends Object
implements DaemonRunner, Runnable, ExceptionListenerUser

A daemon thread. Also see StoppableThread for an alternative daemon construct.


Field Summary
protected  EnvironmentImpl envImpl
           
protected  Logger logger
           
protected  String name
           
protected  int nWakeupRequests
           
protected  boolean stifleExceptionChatter
           
 
Constructor Summary
DaemonThread(long waitTime, String name, EnvironmentImpl envImpl)
           
 
Method Summary
 boolean checkErrorListener(Throwable e)
          If Daemon Thread throws errors and exceptions, this function will catch it and throw a EnvironmentFailureException, and fail the test.
protected  Logger createLogger()
           
 ExceptionListener getExceptionListener()
          For testing.
 int getNWakeupRequests()
          For unit testing.
 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.
 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 String name

nWakeupRequests

protected int nWakeupRequests

stifleExceptionChatter

protected boolean stifleExceptionChatter

envImpl

protected EnvironmentImpl envImpl

logger

protected final Logger logger
Constructor Detail

DaemonThread

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

setExceptionListener

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

createLogger

protected Logger createLogger()

getExceptionListener

public ExceptionListener getExceptionListener()
For testing.


getThread

public 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 String toString()
Overrides:
toString in class Object

wakeup

public void wakeup()

run

public void run()
Specified by:
run in interface Runnable

checkErrorListener

public boolean checkErrorListener(Throwable e)
If Daemon Thread throws errors and exceptions, this function will catch it and throw a EnvironmentFailureException, and fail the test. Only used during testing.


nDeadlockRetries

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


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


Copyright (c) 2004-2010 Oracle. All rights reserved.