org.apache.hadoop.hbase
Class Chore

java.lang.Object
  extended by java.lang.Thread
      extended by org.apache.hadoop.hbase.Chore
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
AssignmentManager.TimeoutMonitor, LogCleaner

public abstract class Chore
extends Thread

Chore is a task performed on a period in hbase. The chore is run in its own thread. This base abstract class provides while loop and sleeping facility. If an unhandled exception, the threads exit is logged. Implementers just need to add checking if there is work to be done and if so, do it. Its the base of most of the chore threads in hbase.

Don't subclass Chore if the task relies on being woken up for something to do, such as an entry being added to a queue, etc.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  Stoppable stopper
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Chore(String name, int p, Stoppable stopper)
           
 
Method Summary
protected abstract  void chore()
          Look for chores.
protected  boolean initialChore()
          Override to run a task before we start looping.
 void run()
           
protected  void sleep()
          Sleep for period.
 void triggerNow()
          If the thread is currently sleeping, trigger the core to happen immediately.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

stopper

protected final Stoppable stopper
Constructor Detail

Chore

public Chore(String name,
             int p,
             Stoppable stopper)
Parameters:
p - Period at which we should run. Will be adjusted appropriately should we find work and it takes time to complete.
stopper - When Stoppable.isStopped() is true, this thread will cleanup and exit cleanly.
Method Detail

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread
See Also:
Thread.run()

triggerNow

public void triggerNow()
If the thread is currently sleeping, trigger the core to happen immediately. If it's in the middle of its operation, will begin another operation immediately after finishing this one.


initialChore

protected boolean initialChore()
Override to run a task before we start looping.

Returns:
true if initial chore was successful

chore

protected abstract void chore()
Look for chores. If any found, do them else just return.


sleep

protected void sleep()
Sleep for period.



Copyright © 2011 The Apache Software Foundation. All Rights Reserved.