ozone core API

org.ozoneDB.core.storage.gammaStore
Class AsyncExec

java.lang.Object
  extended byorg.ozoneDB.core.storage.gammaStore.AsyncExec

public class AsyncExec
extends java.lang.Object

Runs tasks in a separate thread. Tasks are identified by the keys used to put them in this AsyncExec. When a task has been run, it will be automatically removed from this instance.

If a task throws a Throwable in its run() method, it will be caught and displayed; the thread handling all tasks will continue normally.

For every instance of this class 1 thread is created, so keep this in mind when creating instances...

Author:
leo

Nested Class Summary
private  class AsyncExec.ProcessorThread
          Handles all execution of tasks.
 
Field Summary
private  java.util.LinkedHashMap _map
           
private  java.lang.Object currentKey
          key of the Runnable that is currently being processed, or has recently finished its run() method.
private static java.util.logging.Logger log
           
private static int NOT_STARTED
           
private static int RUNNING
           
private  int status
           
private static int STOPPED
           
private static int STOPPING
           
private  AsyncExec.ProcessorThread thread
           
 
Constructor Summary
AsyncExec(java.lang.String threadName, int priority, boolean useDaemonThread)
           
 
Method Summary
private  void checkStatus()
           
 java.lang.Runnable get(java.lang.Object key)
          Returns the task that was put into this instance with the specified key.
private  java.lang.Object getCurrentKey()
           
private  java.util.Map getMap()
           
private  int getStatus()
           
 java.lang.Runnable put(java.lang.Object key, java.lang.Runnable task)
          Puts a task into this instance.
 java.lang.Runnable remove(java.lang.Object key)
          Removes the task that was put into this instance with the specified key.
private  void setCurrentKey(java.lang.Object currentKey)
           
private  void setStatus(int status)
           
 int size()
          Returns the number of tasks currently in this instance.
 void stopWhenReady()
          Tells this instance to stop; no more tasks can be put in or removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final java.util.logging.Logger log

NOT_STARTED

private static final int NOT_STARTED
See Also:
Constant Field Values

RUNNING

private static final int RUNNING
See Also:
Constant Field Values

STOPPING

private static final int STOPPING
See Also:
Constant Field Values

STOPPED

private static final int STOPPED
See Also:
Constant Field Values

_map

private java.util.LinkedHashMap _map

status

private volatile int status

currentKey

private volatile java.lang.Object currentKey
key of the Runnable that is currently being processed, or has recently finished its run() method.


thread

private AsyncExec.ProcessorThread thread
Constructor Detail

AsyncExec

public AsyncExec(java.lang.String threadName,
                 int priority,
                 boolean useDaemonThread)
Method Detail

put

public java.lang.Runnable put(java.lang.Object key,
                              java.lang.Runnable task)
Puts a task into this instance. If a task is already present under that key it will be 'overwritten', just like in java.util.Map instances.

Parameters:
key - key used to identify the given task
task - task to be run
Returns:
Runnable the task already present under the given key
Throws:
java.lang.IllegalStateException - if stopped or stopping

checkStatus

private void checkStatus()
Throws:
java.lang.IllegalStateException - if stopped or stopping

get

public java.lang.Runnable get(java.lang.Object key)
Returns the task that was put into this instance with the specified key. If the task with corresponding specified key is being run at the very moment of this call, then this method will block until the tasks run() method has completed.

Parameters:
key - key used to lookup the task
Returns:
task for specified key (null if no such key)
Throws:
java.lang.IllegalStateException - if stopped or stopping

remove

public java.lang.Runnable remove(java.lang.Object key)
Removes the task that was put into this instance with the specified key.

Parameters:
key - key used to lookup the task
Returns:
task for specified key (null if no such key)
Throws:
java.lang.IllegalStateException - if stopped or stopping

size

public int size()
Returns the number of tasks currently in this instance. Note that this number will decrease over time (if no new tasks are put in) every time a task has completed.

Returns:
number of tasks

stopWhenReady

public void stopWhenReady()
Tells this instance to stop; no more tasks can be put in or removed. Blocks until all tasks have completed.


setStatus

private void setStatus(int status)

getStatus

private int getStatus()

getCurrentKey

private java.lang.Object getCurrentKey()

setCurrentKey

private void setCurrentKey(java.lang.Object currentKey)

getMap

private java.util.Map getMap()

ozone core API

Copyright (C) The Ozone Database Project - www.ozone-db.org. All rights reserved.