uic.model
Class WorkerThread

java.lang.Object
  extended byjava.lang.Thread
      extended byuic.model.WorkerThread
All Implemented Interfaces:
Runnable

public class WorkerThread
extends Thread

This is a helper class for the Actions framework. The basic job of this class is to queue and execute jobs added to it via the action framework.

The long explenation is (still very short) that in Swing you need to seperate long running actions that started due to button pressed into a separate thread to limit freezing GUIs. We do this automatically in the ActionFactory by means of placing the jobs that need to be done in a queue to be executed as soon as possible. The placing itself does not take time, allowing the repainting to continue on its way.

This class is the one that queues the jobs and is called from the UICSimpleAction and extending classes.

Since:
1.2

Nested Class Summary
static class WorkerThread.Job
           
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
static void addJob(UICSimpleAction action, Object source)
          add a job to the queue to be executed at a undefined date in the future.
static void addJob(UICSimpleAction action, Object source, boolean enable)
          add a job to the queue to be executed at a undefined date in the future.
static WorkerThread getInstance()
          Get the sole instance of the worker thread; if none exist create and start it.
 List getJobsList()
          Returns the jobs list which can be altered inline for advanced scheduling policies.
 void lock()
          Locks the worker thread from executing new jobs.
 void run()
          Never ending thread that executed job after job, waiting for more in beteen.
 int size()
           
 void unlock()
          Unlock the queue to resume executing jobs.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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
 

Method Detail

getInstance

public static WorkerThread getInstance()
Get the sole instance of the worker thread; if none exist create and start it. You probably don't need to call this.

See Also:
addJob(uic.model.UICSimpleAction, java.lang.Object, boolean)

addJob

public static void addJob(UICSimpleAction action,
                          Object source,
                          boolean enable)
add a job to the queue to be executed at a undefined date in the future.

Parameters:
action - the action that holdes the target method that should be invoked.
source - the source of the action, if this comes from an ActionEvent its most likely the getSource.
enable - the enabled-state to set the action to after completing the job.

addJob

public static void addJob(UICSimpleAction action,
                          Object source)
add a job to the queue to be executed at a undefined date in the future.

Parameters:
action - the action that holdes the target method that should be invoked.
source - the source of the action, if this comes from an ActionEvent its most likely the getSource.

run

public void run()
Never ending thread that executed job after job, waiting for more in beteen.


lock

public void lock()
Locks the worker thread from executing new jobs. If you want to provide advanced scheduling policies you will likely want to alter the jobsList. Before you are allowed to fetch the jobslist you will have to lock the WorkerThread so it will not use the jobslist while you work on it.

Throws:
IllegalStateException - if the thread is already locked; which implies a concurrency issue.
See Also:
getJobsList(), unlock(), UICSimpleAction.setExecutionPolity(uic.model.UICSimpleAction.ExecutePolicy)

getJobsList

public List getJobsList()
Returns the jobs list which can be altered inline for advanced scheduling policies. The jobs list is a List object with instances of Job. Altering the List by removing or moving around the job objects is allowed; adding other objects is not.

Returns:
a List of Job objects
Throws:
IllegalStateException - if the queue has not been locked before.
See Also:
lock(), unlock(), UICSimpleAction.setExecutionPolity(uic.model.UICSimpleAction.ExecutePolicy)

size

public int size()

unlock

public void unlock()
Unlock the queue to resume executing jobs.

See Also:
getJobsList(), lock(), UICSimpleAction.setExecutionPolity(uic.model.UICSimpleAction.ExecutePolicy)


Copyright © 2002,2003 Thomas Zander Available under the Free Apache licence