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 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 bydoSuspend(java.lang.Object)
) completes.static void
doSuspend(java.lang.Object mutex)
Suspends the current thread and Waits untildoResume()
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)
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, 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: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 interfaceEventProcessingThread
-
isSuspended
public boolean isSuspended()
Description copied from interface:EventProcessingThread
Returns whether it is suspended.- Specified by:
isSuspended
in interfaceEventProcessingThread
- 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 interfaceEventProcessingThread
-
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 interfaceEventProcessingThread
-
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 interfaceEventProcessingThread
-
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 implementsEvents.sendEvent(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event)
.- Specified by:
sendEvent
in interfaceEventProcessingThread
- Throws:
java.lang.Exception
-
cease
public void cease(java.lang.String cause)
Stops the thread. Called only byUiEngine
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 byUiEngine
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 untildoResume()
is called.Note:
- It is used internally only for implementing
UiEngine
Don'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.InterruptedException
Resumes 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:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Thread
-
-