Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.gui4j.core
Class Gui4jThreadManager  view Gui4jThreadManager download Gui4jThreadManager.java

java.lang.Object
  extended byorg.gui4j.core.Gui4jThreadManager
All Implemented Interfaces:
org.gui4j.exception.ErrorTags, java.io.Serializable

public final class Gui4jThreadManager
extends java.lang.Object
implements org.gui4j.exception.ErrorTags, java.io.Serializable

The Thread Manager deals with worker threads used to perform GUI actions. The intention is to take a thread from a pool, use this thread to perform the necessary action and then put the thread back into the pool.


Nested Class Summary
private static class Gui4jThreadManager.InvokerCallStack
           
 class Gui4jThreadManager.WorkerThread
           
private static class Gui4jThreadManager.WorkPackage
           
 
Field Summary
private  int mFreeThreadCount
           
protected  Gui4jInternal mGui4j
           
protected  boolean mHighPriorityThreadActive
           
protected static org.apache.commons.logging.Log mLogger
           
private  int mMaxNumberOfWorkerThreads
           
private  java.util.LinkedList mThreadPool
           
private  boolean mUseWorkerThreads
           
private  int mWorkerCount
           
private  int mWorkPackageCount
           
private  java.util.LinkedList mWorkPackages
           
 
Fields inherited from interface org.gui4j.exception.ErrorTags
EXCEPTION_OCCURED, PROGRAMMING_ERROR, PROGRAMMING_ERROR_illegal_access_exception, PROGRAMMING_ERROR_instantiation_exception, PROGRAMMING_ERROR_invocation_target_exception, PROGRAMMING_ERROR_method_ambiguous, PROGRAMMING_ERROR_method_not_found, PROGRAMMING_ERROR_parameter_null, RESOURCE_ERROR, RESOURCE_ERROR_access_type_not_compatible, RESOURCE_ERROR_access_unexpected_character, RESOURCE_ERROR_access_unexpected_end, RESOURCE_ERROR_access_value_type_not_defined, RESOURCE_ERROR_alias_already_defined, RESOURCE_ERROR_alias_class_not_found, RESOURCE_ERROR_alias_not_defined_in_path, RESOURCE_ERROR_alias_undefined, RESOURCE_ERROR_attribute_editable_defined, RESOURCE_ERROR_attribute_listEditable_defined, RESOURCE_ERROR_attribute_not_defined, RESOURCE_ERROR_double_DataConversionException, RESOURCE_ERROR_element_at_row_col_already_defined, RESOURCE_ERROR_gui4jComponent_already_defined, RESOURCE_ERROR_gui4jComponent_already_registered, RESOURCE_ERROR_gui4jComponent_not_defined, RESOURCE_ERROR_gui4jComponent_not_registered, RESOURCE_ERROR_int_DataConversionException, RESOURCE_ERROR_invalid_column, RESOURCE_ERROR_invalid_defaultButton, RESOURCE_ERROR_invalid_keystroke, RESOURCE_ERROR_invalid_row, RESOURCE_ERROR_invalid_url, RESOURCE_ERROR_jdom_exception, RESOURCE_ERROR_labelform_column_conflict, RESOURCE_ERROR_placement_must_contain_gui4jComponent, RESOURCE_ERROR_property_getter_type_incompatible, RESOURCE_ERROR_style_defined_twice, RESOURCE_ERROR_style_not_defined, RESOURCE_ERROR_tableLayout_invalid_col_row_str, RESOURCE_ERROR_type_not_compatible, RESOURCE_ERROR_unexpected_gui4jStyle_end, RESOURCE_ERROR_unknown_param, RESOURCE_ERROR_unknown_param_in_include
 
Constructor Summary
private Gui4jThreadManager(Gui4jInternal gui4j, int numberOfWorkerThreads)
          Constructor for Gui4jThreadManager.
 
Method Summary
 void clearThreadsInPool()
           
static void executeInSwingThreadAndContinue(java.lang.Runnable run)
          The given task is executed in the GUI thread as soon as possible.
static void executeInSwingThreadAndWait(java.lang.Runnable run)
          Insertes the given Runnable into the task queue of the GUI Thread.
static Gui4jThreadManager getNewInstance(Gui4jInternal gui4j, int numberOfWorkerThreads)
           
protected  Gui4jThreadManager.WorkerThread getWorkerThread(org.gui4j.Gui4jCallBase gui4jController, org.gui4j.Gui4jGetValue[] work, java.util.Map paramMap, Gui4jComponentInstance actionHandler, Gui4jThreadManager.InvokerCallStack callStack, boolean isHighPriorityThread)
           
 void performPriorityWork(org.gui4j.Gui4jCallBase gui4jController, org.gui4j.Gui4jGetValue[] work, java.util.Map paramMap, Gui4jComponentInstance actionHandler)
           
 void performPriorityWork(org.gui4j.Gui4jCallBase gui4jController, org.gui4j.Gui4jGetValue[] work, java.util.Map paramMap, Gui4jComponentInstance actionHandler, boolean forceExecutionInCurrentThread)
          Performs the given work.
 void performWork(org.gui4j.Gui4jCallBase gui4jController, org.gui4j.Gui4jGetValue[] work, java.util.Map paramMap)
          Performs the given work.
 void performWork(org.gui4j.Gui4jCallBase gui4jController, org.gui4j.Gui4jGetValue[] work, java.util.Map paramMap, boolean forceExecutionInCurrentThread)
          Performs the given work.
 void performWork(org.gui4j.Gui4jCallBase gui4jController, org.gui4j.Gui4jGetValue[] work, java.util.Map paramMap, Gui4jComponentInstance actionHandler)
           
 void performWork(org.gui4j.Gui4jCallBase gui4jController, org.gui4j.Gui4jGetValue[] work, java.util.Map paramMap, Gui4jComponentInstance actionHandler, boolean forceExecutionInCurrentThread)
          Performs the given work.
private  void performWork(org.gui4j.Gui4jCallBase gui4jController, org.gui4j.Gui4jGetValue[] work, java.util.Map paramMap, Gui4jComponentInstance actionHandler, boolean forceExecutionInCurrentThread, boolean isHighPriorityThread)
          Performs the given work.
 void performWork(org.gui4j.Gui4jCallBase gui4jController, org.gui4j.Gui4jGetValue action, java.util.Map paramMap)
          Perform the given work.
 void performWork(org.gui4j.Gui4jCallBase gui4jController, org.gui4j.Gui4jGetValue action, java.util.Map paramMap, boolean forceExecutionInCurrentThread)
          Perform the given work.
protected  void putThreadBackIntoPool(Gui4jThreadManager.WorkerThread thread)
           
 void setNumberOfWorkerThreads(int numberOfWorkerThreads)
          Sets the maximum number of worker threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mLogger

protected static org.apache.commons.logging.Log mLogger

mThreadPool

private java.util.LinkedList mThreadPool

mWorkPackages

private java.util.LinkedList mWorkPackages

mHighPriorityThreadActive

protected boolean mHighPriorityThreadActive

mGui4j

protected final Gui4jInternal mGui4j

mFreeThreadCount

private int mFreeThreadCount

mWorkPackageCount

private int mWorkPackageCount

mWorkerCount

private int mWorkerCount

mMaxNumberOfWorkerThreads

private int mMaxNumberOfWorkerThreads

mUseWorkerThreads

private boolean mUseWorkerThreads
Constructor Detail

Gui4jThreadManager

private Gui4jThreadManager(Gui4jInternal gui4j,
                           int numberOfWorkerThreads)
Constructor for Gui4jThreadManager.

Method Detail

getNewInstance

public static Gui4jThreadManager getNewInstance(Gui4jInternal gui4j,
                                                int numberOfWorkerThreads)

setNumberOfWorkerThreads

public void setNumberOfWorkerThreads(int numberOfWorkerThreads)
Sets the maximum number of worker threads. The value -1 represents an unlimited number of threads. Value 0 implies always using the Swing GUI Thread. Any number greater than 0 really sets the maximum number of worker threads. If there is work to do and no worker is free, then the work is put into a FIFO queue and handled when worker gets free.


performWork

public void performWork(org.gui4j.Gui4jCallBase gui4jController,
                        org.gui4j.Gui4jGetValue[] work,
                        java.util.Map paramMap)
Performs the given work. Dependant of the number of maximum worker threads, the work is either performed in the same thread, or by a new worker, or put into a FIFO queue.


performWork

public void performWork(org.gui4j.Gui4jCallBase gui4jController,
                        org.gui4j.Gui4jGetValue[] work,
                        java.util.Map paramMap,
                        boolean forceExecutionInCurrentThread)
Performs the given work. Dependant of the number of maximum worker threads, the work is either performed in the same thread, or by a new worker, or put into a FIFO queue.


performWork

public void performWork(org.gui4j.Gui4jCallBase gui4jController,
                        org.gui4j.Gui4jGetValue[] work,
                        java.util.Map paramMap,
                        Gui4jComponentInstance actionHandler)

performPriorityWork

public void performPriorityWork(org.gui4j.Gui4jCallBase gui4jController,
                                org.gui4j.Gui4jGetValue[] work,
                                java.util.Map paramMap,
                                Gui4jComponentInstance actionHandler)

performWork

public void performWork(org.gui4j.Gui4jCallBase gui4jController,
                        org.gui4j.Gui4jGetValue[] work,
                        java.util.Map paramMap,
                        Gui4jComponentInstance actionHandler,
                        boolean forceExecutionInCurrentThread)
Performs the given work. Dependant of the number of maximum worker threads, the work is either performed in the same thread, or by a new worker, or put into a FIFO queue.


performPriorityWork

public void performPriorityWork(org.gui4j.Gui4jCallBase gui4jController,
                                org.gui4j.Gui4jGetValue[] work,
                                java.util.Map paramMap,
                                Gui4jComponentInstance actionHandler,
                                boolean forceExecutionInCurrentThread)
Performs the given work. Dependant of the number of maximum worker threads, the work is either performed in the same thread, or by a new worker, or put into a FIFO queue.


performWork

private void performWork(org.gui4j.Gui4jCallBase gui4jController,
                         org.gui4j.Gui4jGetValue[] work,
                         java.util.Map paramMap,
                         Gui4jComponentInstance actionHandler,
                         boolean forceExecutionInCurrentThread,
                         boolean isHighPriorityThread)
Performs the given work. Dependant of the number of maximum worker threads, the work is either performed in the same thread, or by a new worker, or put into a FIFO queue.


performWork

public void performWork(org.gui4j.Gui4jCallBase gui4jController,
                        org.gui4j.Gui4jGetValue action,
                        java.util.Map paramMap)
Perform the given work.


performWork

public void performWork(org.gui4j.Gui4jCallBase gui4jController,
                        org.gui4j.Gui4jGetValue action,
                        java.util.Map paramMap,
                        boolean forceExecutionInCurrentThread)
Perform the given work.


getWorkerThread

protected Gui4jThreadManager.WorkerThread getWorkerThread(org.gui4j.Gui4jCallBase gui4jController,
                                                          org.gui4j.Gui4jGetValue[] work,
                                                          java.util.Map paramMap,
                                                          Gui4jComponentInstance actionHandler,
                                                          Gui4jThreadManager.InvokerCallStack callStack,
                                                          boolean isHighPriorityThread)

putThreadBackIntoPool

protected void putThreadBackIntoPool(Gui4jThreadManager.WorkerThread thread)

clearThreadsInPool

public void clearThreadsInPool()

executeInSwingThreadAndWait

public static void executeInSwingThreadAndWait(java.lang.Runnable run)
Insertes the given Runnable into the task queue of the GUI Thread. If the calling thread is the GUI thread, this call immediately returns. If the calling thread is not the GUI thread, this call does not return until the GUI thread has completed the task.


executeInSwingThreadAndContinue

public static void executeInSwingThreadAndContinue(java.lang.Runnable run)
The given task is executed in the GUI thread as soon as possible. There are two cases:
If this thread is not the GUI thread, the given Runnable is inserted into the task queue of the GUI thread. This call then returns immediately without waiting for the scheduled task to be finished.
If this thread is the GUI thread itself, the given task is executed immediately and synchronously, i.e. this call will not return until the task is completed.