com.creamtec.ajaxswing.core
Class AjaxSwingThread

java.lang.Object
  extended by java.lang.Thread
      extended by com.creamtec.ajaxswing.core.AjaxSwingThread
All Implemented Interfaces:
java.lang.Runnable

public class AjaxSwingThread
extends java.lang.Thread

AjaxSwing uses a pool of its own threads to process incoming requests. Some of the operations, such as displaying a modal dialog, can block the current thread until the user closes the dialog. While this is expected behavior for GUI applications, it is undesirable for HTTP request processing. To solve the blocking issue, AjaxSwing emulates the requests on AjaxSwingThread and if a modal dialog is displayed, the thread notifies the client agent that it is blocked. The client agent then renders the top level window and returns to the router.


Nested Class Summary
static class AjaxSwingThread.ThreadFlag
          Lock flag that is used to synchronize the execution of operations on this thread
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int EMULATE_REQUEST
           
static int VOID_METHOD_VOID
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AjaxSwingThread(AjaxSwingThreadGroup group)
           
 
Method Summary
 void emulateRequest(AbstractDocument page, HttpRequestData data)
          Runs request emulation on this thread
 AjaxSwingThreadGroup getAjaxSwingThreadGroup()
          Returns AjaxSwingThreadGroup that own this thread
 ClientAgent getClientAgent()
          Returns the client agent that owns this thread
 java.lang.Object getFlag()
          Returns thread flag.
 boolean isBlocked()
          Returns true if this thread is currently blocked
 boolean isRunning()
          Returns true if this thread is currently executing an operation
 void raiseFlag()
          Notifies the caller (the client agent) that the thread has finished the processing of an operation
 void resetData()
          Release all references so objects can be garbage collected
 void run()
          Runs a loop waiting for an operation to process.
 void runMethod(ClientAgent clientAgent, java.lang.Object object, java.lang.String methodName)
          Runs the object's method with a given name on this thread.
 void setBlocked(boolean blocked)
          Called by GUI subsystem to notify this thread that it is about to become blocked.
 void shutdown()
          Stops this thread
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VOID_METHOD_VOID

public static final int VOID_METHOD_VOID
See Also:
Constant Field Values

EMULATE_REQUEST

public static final int EMULATE_REQUEST
See Also:
Constant Field Values
Constructor Detail

AjaxSwingThread

public AjaxSwingThread(AjaxSwingThreadGroup group)
Method Detail

run

public void run()
Runs a loop waiting for an operation to process. If an operation processing is requested via notify() method, executes the operation.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

runMethod

public void runMethod(ClientAgent clientAgent,
                      java.lang.Object object,
                      java.lang.String methodName)
               throws java.lang.Exception
Runs the object's method with a given name on this thread.

Parameters:
clientAgent - ClientAgent
object - Object
methodName - name of the method to run. The method should have no parameters and should return no values
Throws:
java.lang.Exception

emulateRequest

public void emulateRequest(AbstractDocument page,
                           HttpRequestData data)
                    throws java.lang.Exception
Runs request emulation on this thread

Parameters:
page - HTMLPage
data - HttpRequestData
Throws:
java.lang.Exception

setBlocked

public void setBlocked(boolean blocked)
Called by GUI subsystem to notify this thread that it is about to become blocked. The implementation raises the flag to notify the client agent that this thread will not return and that the agent can render the top window

Parameters:
blocked - boolean

isBlocked

public boolean isBlocked()
Returns true if this thread is currently blocked

Returns:
true if this thread is blocked

isRunning

public boolean isRunning()
Returns true if this thread is currently executing an operation

Returns:
true if this thread is currently executing an operation

getFlag

public java.lang.Object getFlag()
Returns thread flag. It is used to notify the caller (the client agent) that the thread has finished the processing of an operation

Returns:
operation flag

raiseFlag

public void raiseFlag()
Notifies the caller (the client agent) that the thread has finished the processing of an operation


getClientAgent

public ClientAgent getClientAgent()
Returns the client agent that owns this thread

Returns:
the client agent that owns this thread

resetData

public void resetData()
Release all references so objects can be garbage collected


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Thread

getAjaxSwingThreadGroup

public AjaxSwingThreadGroup getAjaxSwingThreadGroup()
Returns AjaxSwingThreadGroup that own this thread

Returns:
AjaxSwingThreadGroup

shutdown

public void shutdown()
Stops this thread



Copyright © 2000-2012 CreamTec LLC. All Rights Reserved.