Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ikayaki.util.LastExecutor Class Reference

List of all members.

Public Member Functions

 LastExecutor ()
 LastExecutor (int delayMillis)
 LastExecutor (boolean execOnlyLast)
 LastExecutor (int delayMillis, boolean execOnlyLast)
synchronized boolean isExecOnlyLast ()
synchronized void setExecOnlyLast (boolean execOnlyLast)
synchronized int getDelayMillis ()
synchronized void setDelayMillis (int delayMillis)
synchronized void execute (Runnable command)
synchronized void join () throws InterruptedException
synchronized void clear ()

Static Public Member Functions

static void main (String[] args) throws InterruptedException

Private Attributes

int delayMillis
boolean execOnlyLast
DelayQueue< RunDelayedqueue = new DelayQueue<RunDelayed>()
Thread workerThread = null

Classes

class  LastExecutorThread
class  RunDelayed

Detailed Description

Executes the last Runnable tasks of a series of tasks after a delay. The worker thread will terminate automatically when there are no runnables to be executed. Optionally executes all of the tasks and not only the last one. All operations are thread-safe. <p/> This class can be used for example in connection with a "continuous search" invoked by a series of GUI events (such as a DocumentListener), but it is necessary to react to only the last event after a short period of user inactivity.

Author:
Esko Luontola

Definition at line 40 of file LastExecutor.java.


Constructor & Destructor Documentation

ikayaki.util.LastExecutor.LastExecutor  ) 
 

Creates an empty LastExecutor with a delay of 0 and execOnlyLast set to true.

Definition at line 68 of file LastExecutor.java.

Referenced by ikayaki.util.LastExecutor.main().

ikayaki.util.LastExecutor.LastExecutor int  delayMillis  ) 
 

Creates an empty LastExecutor with execOnlyLast set to true.

Parameters:
delayMillis the length of execution delay in milliseconds; if less than 0, then 0 will be used.

Definition at line 77 of file LastExecutor.java.

ikayaki.util.LastExecutor.LastExecutor boolean  execOnlyLast  ) 
 

Creates an empty LastExecutor with a delay of 0.

Parameters:
execOnlyLast if true, only the last event will be executed after the delay; otherwise all are executed in order of appearance.

Definition at line 87 of file LastExecutor.java.

ikayaki.util.LastExecutor.LastExecutor int  delayMillis,
boolean  execOnlyLast
 

Creates an empty LastExecutor.

Parameters:
delayMillis the length of execution delay in milliseconds; if less than 0, then 0 will be used.
execOnlyLast if true, only the last task will be executed after the delay; otherwise all are executed in order of appearance.

Definition at line 98 of file LastExecutor.java.


Member Function Documentation

synchronized void ikayaki.util.LastExecutor.clear  ) 
 

Removes all of the elements from the execution queue. The queue will be empty after this call returns. The execution thread will stop after the currently running task, if any.

Definition at line 175 of file LastExecutor.java.

References ikayaki.util.LastExecutor.queue, and ikayaki.util.LastExecutor.workerThread.

Referenced by ikayaki.Project.saveNow().

synchronized void ikayaki.util.LastExecutor.execute Runnable  command  ) 
 

Inserts a runnable task to the end of the queue. It will remain there until it is executed or another object replaces it. If execOnlyLast is set to true, the queue will be cleared before inserting this runnable to it. If there is no worker thread running, a new one will be spawned.

Parameters:
command the runnable task to be executed after a pre-defined delay.
Exceptions:
NullPointerException if command is null.

Definition at line 145 of file LastExecutor.java.

References ikayaki.util.LastExecutor.delayMillis, ikayaki.util.LastExecutor.execOnlyLast, ikayaki.util.LastExecutor.queue, and ikayaki.util.LastExecutor.workerThread.

Referenced by ikayaki.util.LastExecutor.main(), ikayaki.squid.Handler.moveToBackground(), ikayaki.squid.Handler.moveToDegausserY(), ikayaki.squid.Handler.moveToDegausserZ(), ikayaki.squid.Handler.moveToLeftLimit(), ikayaki.squid.Handler.moveToMeasurement(), ikayaki.squid.Handler.moveToRightLimit(), ikayaki.squid.Handler.moveToSampleLoad(), ikayaki.squid.Handler.rotateTo(), and ikayaki.Project.save().

synchronized int ikayaki.util.LastExecutor.getDelayMillis  ) 
 

Returns:
the delay in milliseconds.

Definition at line 124 of file LastExecutor.java.

References ikayaki.util.LastExecutor.delayMillis.

synchronized boolean ikayaki.util.LastExecutor.isExecOnlyLast  ) 
 

Returns:
true if only the last task will be executed after the delay; otherwise false.

Definition at line 109 of file LastExecutor.java.

References ikayaki.util.LastExecutor.execOnlyLast.

synchronized void ikayaki.util.LastExecutor.join  )  throws InterruptedException
 

Waits for the queue to become empty.

Exceptions:
InterruptedException if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

Definition at line 165 of file LastExecutor.java.

References ikayaki.util.LastExecutor.workerThread.

Referenced by ikayaki.squid.Handler.join().

static void ikayaki.util.LastExecutor.main String[]  args  )  throws InterruptedException [static]
 

TEST METHOD

Definition at line 281 of file LastExecutor.java.

References ikayaki.util.LastExecutor.execute(), and ikayaki.util.LastExecutor.LastExecutor().

Here is the call graph for this function:

synchronized void ikayaki.util.LastExecutor.setDelayMillis int  delayMillis  ) 
 

Parameters:
delayMillis delay in milliseconds; if less than 0, then the new value is ignored.

Definition at line 131 of file LastExecutor.java.

synchronized void ikayaki.util.LastExecutor.setExecOnlyLast boolean  execOnlyLast  ) 
 

Parameters:
execOnlyLast if true, only the last task will be executed after the delay; otherwise all are executed in order of appearance.

Definition at line 117 of file LastExecutor.java.


Member Data Documentation

int ikayaki.util.LastExecutor.delayMillis [private]
 

Defines how long is the delay in milliseconds, after which the events need to be run.

Definition at line 45 of file LastExecutor.java.

Referenced by ikayaki.util.LastExecutor.execute(), and ikayaki.util.LastExecutor.getDelayMillis().

boolean ikayaki.util.LastExecutor.execOnlyLast [private]
 

Defines if only the last event should be executed. If false, then all of the events are executed in the order of appearance.

Definition at line 51 of file LastExecutor.java.

Referenced by ikayaki.util.LastExecutor.execute(), and ikayaki.util.LastExecutor.isExecOnlyLast().

DelayQueue<RunDelayed> ikayaki.util.LastExecutor.queue = new DelayQueue<RunDelayed>() [private]
 

Prioritized FIFO queue for containing the RunDelayed items that have not expired. If execOnlyLast is true, then this queue should never contain more than one item.

Definition at line 57 of file LastExecutor.java.

Referenced by ikayaki.util.LastExecutor.clear(), and ikayaki.util.LastExecutor.execute().

Thread ikayaki.util.LastExecutor.workerThread = null [private]
 

The worker thread that will run the inserted runnables. If the thread has no more work to do, it will set workerThread to null and terminate itself.

Definition at line 63 of file LastExecutor.java.

Referenced by ikayaki.util.LastExecutor.clear(), ikayaki.util.LastExecutor.execute(), and ikayaki.util.LastExecutor.join().


The documentation for this class was generated from the following file:
Generated on Fri May 6 16:01:33 2005 for Squid by  doxygen 1.4.1