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, FileProcessor, 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
           
protected  java.util.Set workQueue
           
protected  Latch workQueueLatch
           
 
Constructor Summary
DaemonThread(long waitTime, java.lang.String name, EnvironmentImpl env)
           
 
Method Summary
 void addToQueue(java.lang.Object o)
           
 void addToQueueAlreadyLatched(java.util.Collection c)
           
 int getNWakeupRequests()
          For unit testing.
 int getQueueSize()
           
 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  int 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 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

workQueue

protected java.util.Set workQueue

workQueueLatch

protected Latch workQueueLatch

nWakeupRequests

protected int nWakeupRequests

stifleExceptionChatter

protected boolean stifleExceptionChatter
Constructor Detail

DaemonThread

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

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

addToQueue

public void addToQueue(java.lang.Object o)
                throws DatabaseException
Throws:
DatabaseException

getQueueSize

public int getQueueSize()
                 throws DatabaseException
Throws:
DatabaseException

addToQueueAlreadyLatched

public void addToQueueAlreadyLatched(java.util.Collection c)
                              throws DatabaseException
Throws:
DatabaseException

wakeup

public void wakeup()

run

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

nDeadlockRetries

protected int 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. isRunnable must be called from within onWakeup to avoid having the following sequence: Thread A: isRunnable() => true, Thread B: isRunnable() => true, Thread A: onWakeup() starts Thread B: waits for monitor on thread to call onWakeup() Thread A: onWakeup() completes rendering isRunnable() predicate false Thread B: onWakeup() starts, but isRunnable predicate is now false

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 2004,2008 Oracle. All rights reserved.