org.das2.system
Class RequestProcessor

java.lang.Object
  extended by org.das2.system.RequestProcessor

public final class RequestProcessor
extends java.lang.Object

Utility class for synchronous execution. This class maintains a pool of threads that are used to execute arbitrary code. This class also serves as a central place to catch and handle unchecked exceptions. The invokeLater(java.lang.Runnable) method is similar to the SwingUtilities SwingUtilities.invokeLater(java.lang.Runnable) method, except that the request is not executed on the event thread. The invokeLater(java.lang.Runnable, java.lang.Object), the invokeAfter(java.lang.Runnable, java.lang.Object), and the waitFor(java.lang.Object) methods are designed to work together. Both of the first two methods execute code asynchronously with respect to the calling thread. Multiple requests made with a call to invokeLater that specified the same lock can execute at the same time, but not while a request made with the invokeAfter with the same lock is processing. Any requests made before an invokeAfter request with the same lock will finish before that invokeAfter request begins. An invokeAfter request will finish before any requests with the same lock made after that invokeAfter request begins. The waitFor(java.lang.Object) method will cause the calling thread to block until all requests with the specified lock finish.


Method Summary
static void invokeAfter(java.lang.Runnable run, java.lang.Object lock)
          Executes run.run() asynchronously on a thread from the thread pool.
static void invokeLater(java.lang.Runnable run)
          Executes run.run() asynchronously on a thread from the thread pool.
static void invokeLater(java.lang.Runnable run, java.lang.Object lock)
          Executes run.run() asynchronously on a thread from the thread pool.
static void waitFor(java.lang.Object lock)
          Blocks until all tasks with the same lock have finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

invokeLater

public static void invokeLater(java.lang.Runnable run)
Executes run.run() asynchronously on a thread from the thread pool.

Parameters:
run - the task to be executed.

invokeLater

public static void invokeLater(java.lang.Runnable run,
                               java.lang.Object lock)
Executes run.run() asynchronously on a thread from the thread pool. The task will not be executed until after all requests made with invokeAfter(java.lang.Runnable, java.lang.Object) with the same lock have finished.

Parameters:
run - the taks to be executed.
lock - associates run with other tasks.

invokeAfter

public static void invokeAfter(java.lang.Runnable run,
                               java.lang.Object lock)
Executes run.run() asynchronously on a thread from the thread pool. The task will not be executed until after all requests made with invokeAfter(java.lang.Runnable, java.lang.Object) or invokeLater(java.lang.Runnable, java.lang.Object) with the same lock have finished.

Parameters:
run - the taks to be executed.
lock - associates run with other tasks.

waitFor

public static void waitFor(java.lang.Object lock)
                    throws java.lang.InterruptedException
Blocks until all tasks with the same lock have finished.

Parameters:
lock -
Throws:
java.lang.InterruptedException - if the current thread is interrupted while waiting.