org.apache.hadoop.hbase
Class Chore

java.lang.Object
  extended by org.apache.hadoop.hbase.util.HasThread
      extended by org.apache.hadoop.hbase.Chore
All Implemented Interfaces:
Runnable

@InterfaceAudience.Private
public abstract class Chore
extends HasThread

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.


Field Summary
protected  Stoppable stopper
           
 
Constructor Summary
protected Chore()
          This constructor is for test only.
  Chore(String name, int p, Stoppable stopper)
           
 
Method Summary
protected abstract  void chore()
          Look for chores.
 void choreForTesting()
           
protected  void cleanup()
          Called when the chore has completed, allowing subclasses to cleanup any extra overhead
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 org.apache.hadoop.hbase.util.HasThread
getName, getThread, interrupt, isAlive, isInterrupted, join, join, join, setDaemon, setName, setPriority, setUncaughtExceptionHandler, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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.

Chore

protected Chore()
This constructor is for test only. It allows to create an object and to call chore() on it. There is no sleeper nor stoppable.

Method Detail

run

public void run()
Specified by:
run in interface Runnable
Specified by:
run in class HasThread
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.


choreForTesting

public void choreForTesting()

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.


cleanup

protected void cleanup()
Called when the chore has completed, allowing subclasses to cleanup any extra overhead



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