com.datasalt.pangool.solr
Class HeartBeater

java.lang.Object
  extended by java.lang.Thread
      extended by com.datasalt.pangool.solr.HeartBeater
All Implemented Interfaces:
Runnable

public class HeartBeater
extends Thread

This class runs a background thread that once ever 5 seconds checks to see if a progress report is needed. If a report is needed it is issued. A simple counter threadsNeedingHeartBeat handles the number of threads requesting a heart beat. The expected usage pattern is

  try {
       heartBeater.needHeartBeat();
       do something that may take a while
    } finally {
       heartBeater.cancelHeartBeat();
    }
 

This class has been copied from SOLR-1301 patch although it might be slightly different from it.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static org.apache.commons.logging.Log LOG
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
HeartBeater(org.apache.hadoop.util.Progressable progress)
          Create the heart beat object thread set it to daemon priority and start the thread.
 
Method Summary
 void cancelHeartBeat()
          inform the background thread that this heartbeat request is not needed.
 org.apache.hadoop.util.Progressable getProgress()
           
 void needHeartBeat()
          inform the background thread that heartbeats are to be issued.
 void run()
           
 void setProgress(org.apache.hadoop.util.Progressable progress)
           
 void setStatus(String status)
           
 
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

LOG

public static org.apache.commons.logging.Log LOG
Constructor Detail

HeartBeater

public HeartBeater(org.apache.hadoop.util.Progressable progress)
Create the heart beat object thread set it to daemon priority and start the thread. When the count in threadsNeedingHeartBeat is positive, the heart beat will be issued on the progress object ever 5 seconds.

Method Detail

getProgress

public org.apache.hadoop.util.Progressable getProgress()

setProgress

public void setProgress(org.apache.hadoop.util.Progressable progress)

run

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

needHeartBeat

public void needHeartBeat()
inform the background thread that heartbeats are to be issued. Issue a heart beat also


cancelHeartBeat

public void cancelHeartBeat()
inform the background thread that this heartbeat request is not needed. This must be called at some point after each needHeartBeat() request.


setStatus

public void setStatus(String status)


Copyright © –2014 Datasalt Systems S.L.. All rights reserved.