org.zkoss.zk.ui.impl
Class EventProcessingThreadImpl

java.lang.Object
  extended by java.lang.Thread
      extended by org.zkoss.zk.ui.impl.EventProcessingThreadImpl
All Implemented Interfaces:
java.lang.Runnable, EventProcessingThread

public class EventProcessingThreadImpl
extends java.lang.Thread
implements EventProcessingThread

Thread to handle events. We need to handle events in a separate thread, because it might suspend (by calling UiEngine.wait(java.lang.Object)), such as waiting a modal dialog to complete.

Author:
tomyeh

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
EventProcessingThreadImpl()
           
 
Method Summary
 void cease(java.lang.String cause)
          Stops the thread.
 void ceaseSilently(java.lang.String cause)
          Stops the thread silently.
 boolean doResume()
          Resumes this thread and returns only if the execution (being suspended by doSuspend(java.lang.Object)) completes.
static void doSuspend(java.lang.Object mutex)
          Suspends the current thread and Waits until doResume() is called.
 Component getComponent()
          Returns the component being processed by this thread, or null if idle.
 Event getEvent()
          Returns the event being processed by this thread, or null if idle.
static int getThreadNumber()
          Returns the number of event threads.
static int getThreadNumberInProcessing()
          Returns the number of event threads in processing.
 boolean isCeased()
          Returns whether it is ceased.
 boolean isIdle()
          Returns whether this thread is idle, i.e., not processing any event.
 boolean isSuspended()
          Returns whether it is suspended.
 void newEventThreadSuspends(java.lang.Object mutex)
          Invokes Configuration.newEventThreadSuspends(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event, java.lang.Object).
 boolean processEvent(Desktop desktop, Component comp, Event event)
          Ask this event thread to process the specified event.
 void run()
           
 void sendEvent(Component comp, Event event)
          Sends the specified component and event and processes the event synchronously.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, 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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EventProcessingThreadImpl

public EventProcessingThreadImpl()
Method Detail

isCeased

public boolean isCeased()
Description copied from interface: EventProcessingThread
Returns whether it is ceased.

The event processing thread is ceased automatically. If you want to cease it manually, you can invoke DesktopCtrl.ceaseSuspendedThread(org.zkoss.zk.ui.sys.EventProcessingThread, java.lang.String).

An event processing thread is ceased if DesktopCtrl.ceaseSuspendedThread(org.zkoss.zk.ui.sys.EventProcessingThread, java.lang.String) was called manually, or if it is dead (Thread.isAlive() returns false). That is, it returns true if it is going to die, or dead already.

Specified by:
isCeased in interface EventProcessingThread

isSuspended

public boolean isSuspended()
Description copied from interface: EventProcessingThread
Returns whether it is suspended.

Specified by:
isSuspended in interface EventProcessingThread
See Also:
DesktopCtrl.getSuspendedThreads(), DesktopCtrl.ceaseSuspendedThread(org.zkoss.zk.ui.sys.EventProcessingThread, java.lang.String)

isIdle

public boolean isIdle()
Description copied from interface: EventProcessingThread
Returns whether this thread is idle, i.e., not processing any event.

Specified by:
isIdle in interface EventProcessingThread

getEvent

public final Event getEvent()
Description copied from interface: EventProcessingThread
Returns the event being processed by this thread, or null if idle.

Specified by:
getEvent in interface EventProcessingThread

getComponent

public final Component getComponent()
Description copied from interface: EventProcessingThread
Returns the component being processed by this thread, or null if idle.

Specified by:
getComponent in interface EventProcessingThread

sendEvent

public void sendEvent(Component comp,
                      Event event)
               throws java.lang.Exception
Description copied from interface: EventProcessingThread
Sends the specified component and event and processes the event synchronously. Used to implements Events.sendEvent(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event).

Specified by:
sendEvent in interface EventProcessingThread
Throws:
java.lang.Exception

cease

public void cease(java.lang.String cause)
Stops the thread. Called only by UiEngine when it is stopping.

Application developers shall use DesktopCtrl.ceaseSuspendedThread(org.zkoss.zk.ui.sys.EventProcessingThread, java.lang.String) instead.

Parameters:
cause - a human readable text describing the cause. If null, an empty string is assumed.

ceaseSilently

public void ceaseSilently(java.lang.String cause)
Stops the thread silently. Called by UiEngine to stop abnormally.


getThreadNumber

public static final int getThreadNumber()
Returns the number of event threads.


getThreadNumberInProcessing

public static final int getThreadNumberInProcessing()
Returns the number of event threads in processing.


doSuspend

public static void doSuspend(java.lang.Object mutex)
                      throws java.lang.InterruptedException
Suspends the current thread and Waits until doResume() is called.

Note:

Throws:
java.lang.InterruptedException

doResume

public boolean doResume()
                 throws java.lang.InterruptedException
Resumes this thread and returns only if the execution (being suspended by doSuspend(java.lang.Object)) completes.

It executes in the main thread (i.e., the servlet thread).

Returns:
whether the event has been processed completely or just be suspended
Throws:
java.lang.InterruptedException

processEvent

public boolean processEvent(Desktop desktop,
                            Component comp,
                            Event event)
Ask this event thread to process the specified event.

Used internally to implement UiEngine. Application developers shall use Events.sendEvent(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event) instead.

Returns:
whether the event has been processed completely or just be suspended. Recycle it only if true is returned.

newEventThreadSuspends

public void newEventThreadSuspends(java.lang.Object mutex)
Invokes Configuration.newEventThreadSuspends(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event, java.lang.Object). The caller must execute in the event processing thread. It is called only for implementing UiEngine. Don't call it directly.


run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

toString

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


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo