org.hypergraphdb.util
Class ActionQueueThread

java.lang.Object
  extended by java.lang.Thread
      extended by org.hypergraphdb.util.ActionQueueThread
All Implemented Interfaces:
java.lang.Runnable

public class ActionQueueThread
extends java.lang.Thread

This a simple queue that runs as a thread and executes passed in action object (i.e. Runnable instances) in a sequence. It can be configured with a maximum size. When this maximum size is reached and a new element is added to it, it will not return until some percentage of the accumulated actions has been completed.

Author:
Borislav Iordanov

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int DEFAULT_FREE_PERCENT_ON_BLOCK
           
static int DEFAULT_NON_BLOCKING_SIZE
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ActionQueueThread()
          Default constructor.
ActionQueueThread(java.lang.String name)
          Constructs an ActionQueue with a specific thread name and a default max size.
ActionQueueThread(java.lang.String name, int maxSizeBeforeBlock, int completePercentUponBlocking)
          Constructs an ActionQueue with a specific thread name and max size.
 
Method Summary
 void addAction(java.lang.Runnable action)
           
 void clearAll()
          Clear all actions.
 void completeAll()
          Complete all scheduled actions at the time of this call.
 long getCompletedCount()
          Return the total number of actions executed by this thread, whether or not the actions have terminated with an exception.
 boolean isRunning()
           
 void pauseActions()
          Suspend the execution of actions until the resumeActions method is called.
 void prependAction(java.lang.Runnable action)
          Put an action in front of the queue so that it's executed next or close to next.
 void resumeActions()
          Resume action processing previously paused by a call to pauseActions.
 void run()
           
 void stopRunning()
           
 
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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_NON_BLOCKING_SIZE

public static final int DEFAULT_NON_BLOCKING_SIZE
See Also:
Constant Field Values

DEFAULT_FREE_PERCENT_ON_BLOCK

public static final int DEFAULT_FREE_PERCENT_ON_BLOCK
See Also:
Constant Field Values
Constructor Detail

ActionQueueThread

public ActionQueueThread()

Default constructor. Unnamed action queue with a default max size.


ActionQueueThread

public ActionQueueThread(java.lang.String name)

Constructs an ActionQueue with a specific thread name and a default max size.

Parameters:
name - The name of the action queue thread.

ActionQueueThread

public ActionQueueThread(java.lang.String name,
                         int maxSizeBeforeBlock,
                         int completePercentUponBlocking)

Constructs an ActionQueue with a specific thread name and max size.

Parameters:
name - The name of the action queue thread.
maxSizeBeforeBlock - The maximum number of actions waiting in the queue before this ActionQueue blocks a calling thread.
completPercentUponBlocking - The amount, in percent, of action to execute from a filled up queue before we return to the blocked thread.
Method Detail

run

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

pauseActions

public void pauseActions()

Suspend the execution of actions until the resumeActions method is called. Block until the current action completes execution.


resumeActions

public void resumeActions()

Resume action processing previously paused by a call to pauseActions.


addAction

public void addAction(java.lang.Runnable action)

prependAction

public void prependAction(java.lang.Runnable action)

Put an action in front of the queue so that it's executed next or close to next. This method will not block even if the size of the accumulated actions exceeds the blocking threshold


completeAll

public void completeAll()

Complete all scheduled actions at the time of this call. Since other threads may keep adding actions, this method makes sure that only the actions in the queue at the time of the call are waited upon.


clearAll

public void clearAll()

Clear all actions. The currently executing actions will still complete, but all others will be removed.


getCompletedCount

public long getCompletedCount()

Return the total number of actions executed by this thread, whether or not the actions have terminated with an exception.


isRunning

public boolean isRunning()

stopRunning

public void stopRunning()