Class EventProcessingThreadImpl
- java.lang.Object
-
- java.lang.Thread
-
- 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 callingUiEngine.wait(java.lang.Object)), such as waiting a modal dialog to complete.- Author:
- tomyeh
-
-
Constructor Summary
Constructors Constructor Description EventProcessingThreadImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcease(java.lang.String cause)Stops the thread.voidceaseSilently(java.lang.String cause)Stops the thread silently.booleandoResume()Resumes this thread and returns only if the execution (being suspended bydoSuspend(java.lang.Object)) completes.static voiddoSuspend(java.lang.Object mutex)Suspends the current thread and Waits untildoResume()is called.ComponentgetComponent()Returns the component being processed by this thread, or null if idle.EventgetEvent()Returns the event being processed by this thread, or null if idle.static intgetThreadNumber()Returns the number of event threads.static intgetThreadNumberInProcessing()Returns the number of event threads in processing.booleanisCeased()Returns whether it is ceased.booleanisIdle()Returns whether this thread is idle, i.e., not processing any event.booleanisSuspended()Returns whether it is suspended.voidnewEventThreadSuspends(java.lang.Object mutex)booleanprocessEvent(Desktop desktop, Component comp, Event event)Ask this event thread to process the specified event.voidrun()voidsendEvent(Component comp, Event event)Sends the specified component and event and processes the event synchronously.java.lang.StringtoString()-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, yield
-
-
-
-
Method Detail
-
isCeased
public boolean isCeased()
Description copied from interface:EventProcessingThreadReturns 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:
isCeasedin interfaceEventProcessingThread
-
isSuspended
public boolean isSuspended()
Description copied from interface:EventProcessingThreadReturns whether it is suspended.- Specified by:
isSuspendedin interfaceEventProcessingThread- See Also:
DesktopCtrl.getSuspendedThreads(),DesktopCtrl.ceaseSuspendedThread(org.zkoss.zk.ui.sys.EventProcessingThread, java.lang.String)
-
isIdle
public boolean isIdle()
Description copied from interface:EventProcessingThreadReturns whether this thread is idle, i.e., not processing any event.- Specified by:
isIdlein interfaceEventProcessingThread
-
getEvent
public final Event getEvent()
Description copied from interface:EventProcessingThreadReturns the event being processed by this thread, or null if idle.- Specified by:
getEventin interfaceEventProcessingThread
-
getComponent
public final Component getComponent()
Description copied from interface:EventProcessingThreadReturns the component being processed by this thread, or null if idle.- Specified by:
getComponentin interfaceEventProcessingThread
-
sendEvent
public void sendEvent(Component comp, Event event) throws java.lang.Exception
Description copied from interface:EventProcessingThreadSends the specified component and event and processes the event synchronously. Used to implementsEvents.sendEvent(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event).- Specified by:
sendEventin interfaceEventProcessingThread- Throws:
java.lang.Exception
-
cease
public void cease(java.lang.String cause)
Stops the thread. Called only byUiEnginewhen 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 byUiEngineto 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.InterruptedExceptionSuspends the current thread and Waits untildoResume()is called.Note:
- It is used internally only for implementing
UiEngineDon't call it directly. - Caller must invoke
newEventThreadSuspends(java.lang.Object)before calling this method. (Reason: UiEngine might have to store some info afternewEventThreadSuspends(java.lang.Object)is called. - The current thread must be
EventProcessingThreadImpl. - It is a static method.
- Throws:
java.lang.InterruptedException
- It is used internally only for implementing
-
doResume
public boolean doResume() throws java.lang.InterruptedExceptionResumes this thread and returns only if the execution (being suspended bydoSuspend(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 useEvents.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)
InvokesConfiguration.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 implementingUiEngine. Don't call it directly.
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Thread
-
-