org.tranche.flatfile
Class ReplaceCorruptedDataBlockThread

java.lang.Object
  extended by java.lang.Thread
      extended by org.tranche.flatfile.ReplaceCorruptedDataBlockThread
All Implemented Interfaces:
java.lang.Runnable

public class ReplaceCorruptedDataBlockThread
extends java.lang.Thread

Thread replaces any missing chunks from a corrupted data block. Reads requests for corrupted DataBlock objects from a queue.

Author:
Bryan E. Smith - bryanesmith@gmail.com

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int MAX_QUEUE_SIZE
          Maximum size before allowed queue blocks.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected ReplaceCorruptedDataBlockThread(DataBlockUtil dbu)
          Private constructor.
 
Method Summary
 void addChunkToRetrieve(BigHash hash, boolean isMetaData)
          Add a chunk that should be repaired from a corrupted data block.
 boolean isStop()
          Returns value for flag that determines if the thread should stop.
 void run()
           
 void setStop(boolean stop)
          Set whether the thread should stop.
 void waitForQueueToEmpty(long maxTimeToWaitMillis)
          Wait up to a certain amount of time for queue to empty.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_QUEUE_SIZE

public static final int MAX_QUEUE_SIZE

Maximum size before allowed queue blocks.

See Also:
Constant Field Values
Constructor Detail

ReplaceCorruptedDataBlockThread

protected ReplaceCorruptedDataBlockThread(DataBlockUtil dbu)
Private constructor. This is a singleton.

Parameters:
dataHashes - List of data hashes that need replaced immediately.
metaHashes - List of meta data hashes that need replaced immediately.
Method Detail

run

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

isStop

public boolean isStop()

Returns value for flag that determines if the thread should stop.

Note that the thread will continue until queue is empty.

Returns:
True if set to stop, false otherwise

setStop

public void setStop(boolean stop)

Set whether the thread should stop.

Note that the thread will continue until queue is empty.

Parameters:
stop - True if want to stop, false otherwise

addChunkToRetrieve

public void addChunkToRetrieve(BigHash hash,
                               boolean isMetaData)
                        throws java.lang.InterruptedException

Add a chunk that should be repaired from a corrupted data block.

Parameters:
hash -
isMetaData -
Throws:
java.lang.InterruptedException

waitForQueueToEmpty

public void waitForQueueToEmpty(long maxTimeToWaitMillis)
                         throws java.lang.InterruptedException

Wait up to a certain amount of time for queue to empty. This is done to alleviate resources on server.

Parameters:
maxTimeToWaitMillis - Maximum time to wait for queue to empty in milliseconds. For example, if want to wait up to five seconds, value would be 5000.
Throws:
java.lang.InterruptedException


This code is free for use both commercially and non-commercially as stated in the project's license