proai.cache
Class Committer

java.lang.Object
  extended by java.lang.Thread
      extended by proai.cache.Committer
All Implemented Interfaces:
java.lang.Runnable

public class Committer
extends java.lang.Thread

A thread for committing a series of QueueItem updates to the database.

Items are added to a "commit queue" by Worker threads via the synchronized handoff() method. This can occur before the thread is actually started. Once the thread is started, the items are removed asynchronously, then committed, until all workers have finished and ( the queue is empty or processing has been aborted ).

Author:
Chris Wilper

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Committer(Updater updater, RCDatabase db, int maxCommitQueueSize, int maxRecordsPerTransaction)
          Construct a new committer with the given configuration.
 
Method Summary
protected  int getProcessedCount()
           
protected  long getTotalCommitTime()
           
protected  int getTransactionCount()
           
protected  boolean handoff(java.util.List<QueueItem> queueItems)
          Attempt to add the list of QueueItems to the commit queue and return immediately.
 void run()
          Run the thread.
 
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
 

Constructor Detail

Committer

public Committer(Updater updater,
                 RCDatabase db,
                 int maxCommitQueueSize,
                 int maxRecordsPerTransaction)
          throws ServerException
Construct a new committer with the given configuration. The caller is responsible for actually starting the thread.

Throws:
ServerException
Method Detail

handoff

protected boolean handoff(java.util.List<QueueItem> queueItems)
Attempt to add the list of QueueItems to the commit queue and return immediately. This method will block until adding the list would not cause the queue to exceed its capacity or the thread is finished running.

Returns:
whether the handoff was successful. The handoff will only fail if the Committer thread has been stopped.

run

public void run()
Run the thread. This works in two phases. The first phase executes while workers are running and the second phase commits all remaining items unless processing is aborted.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getTransactionCount

protected int getTransactionCount()

getProcessedCount

protected int getProcessedCount()

getTotalCommitTime

protected long getTotalCommitTime()