📄 executions.java
字号:
/** Sends a temporary redirect response to the client using the specified * redirect location URL by use of the current execution, * {@link #getCurrent}. * * <p>After calling this method, the caller shall end the processing * immediately (by returning). All pending requests and events will * be dropped. * * @param uri the URI to redirect to, or null to reload the same page * @see Execution#sendRedirect */ public static void sendRedirect(String uri) { getCurrent().sendRedirect(uri); } /** A shortcut of Executions.getCurrent().include(page). * * @see Execution#include(Writer,String,Map,int) * @see Execution#include(String) */ public static void include(String page) throws IOException { getCurrent().include(page); } /** A shortcut of Executions.getCurrent().forward(page). * * @see Execution#forward(Writer,String,Map,int) * @see Execution#forward(String) */ public static void forward(String page) throws IOException { getCurrent().forward(page); } //-- wait/notify --// /** Suspends the current processing of an event and wait until the * other thread invokes {@link #notify(Object)}, {@link #notifyAll(Object)}, * {@link #notify(Desktop, Object)} or {@link #notifyAll(Desktop, Object)} * for the specified object. * * <p>It can only be called when the current thread is processing an event. * And, when called, the current processing is suspended and ZK continues * to process the next event and finally render the result. * * <p>It is typical use to implement a modal dialog where it won't return * until the modal dialog ends. * * @param mutex any non-null object to identify what to notify. * It must be same object passed to {@link #notify(Desktop, Object)}. * If there is racing issue, you have to enclose it with * <code>synchronized</code> (though it is optional). * @exception UiException if it is called not during event processing. */ public static final void wait(Object mutex) throws InterruptedException { getUiEngine().wait(mutex); } /** Wakes up a single event processing thread that is waiting on the * specified object. * * <p>Unlike {@link #notify(Desktop, Object)}, this method can be invoked only * in the event listener that processing the same desktop. * In addition, this method can be called under the event listener. * * <p>Use {@link #notify(Desktop, Object)} if you want to notify in other * thread, such as a working thread. * * @param mutex any non-null object to identify what to notify. * It must be same object passed to {@link #wait}. * If there is racing issue, you have to enclose it with * <code>synchronized</code> (though it is optional). * @see #notify(Desktop, Object) * @see #notifyAll(Object) * @exception UiException if it is called not during event processing. */ public static final void notify(Object mutex) { getUiEngine().notify(mutex); } /** Wakes up all event processing thread that are waiting on the * specified object. * * <p>Unlike {@link #notify(Desktop, Object)}, this method can be invoked only * in the event listener that processing the same desktop. * In addition, this method can be called under the event listener. * * <p>Use {@link #notifyAll(Desktop, Object)} if you want to notify in other * thread, such as a working thread. * * @param mutex any non-null object to identify what to notify. * It must be same object passed to {@link #wait}. * If there is racing issue, you have to enclose it with * <code>synchronized</code> (though it is optional). * @see #notify(Desktop, Object) * @see #notifyAll(Object) * @exception UiException if it is called not during event processing. */ public static final void notifyAll(Object mutex) { getUiEngine().notifyAll(mutex); } /** Wakes up a single event processing thread for the specified desktop * that is waiting on the specified object. * * <p>Unlike {@link #notify(Object)}, this method can be called any time. * It is designed to let working threads resume an event processing * thread. * * <p>Notice: if this method is NOT called in an event processing thread, * the resumed thread won't execute until the next request is received. * To enforce it happen, you might use the timer component (found in ZUL). * * <p>Notice: to resolve racing issue, you usually need to follow * this pattern. * <pre><code>//Event Handling Threadsynchronized (mutex) { final WorkingThread worker = new WorkingThread(desktop); synchronized (mutex) { worker.start(); Executions.wait(mutex); } ....}//Working Threadpublic void run() { .... synchronized (mutex) { Executions.notify(desktop, mutex); }} </code></pre> * * @param desktop the desktop which the suspended thread is processing. * It must be the same desktop of the suspended thread. * @param mutex any non-null object to identify what to notify. * It must be same object passed to {@link #wait}. * If there is racing issue, you have to enclose it with * <code>synchronized</code> (though it is optional). * @see #notify(Object) * @see #notifyAll(Desktop, Object) */ public static final void notify(Desktop desktop, Object mutex) { getUiEngine(desktop).notify(desktop, mutex); } /** Wakes up all event processing theads for the specified desktop * that are waiting on the specified object. * * <p>Unlike {@link #notifyAll(Object)}, this method can be called any time. * It is designed to let working threads resume an event processing * thread. * * <p>Notice: if this method is NOT called in an event processing thread, * the resumed thread won't execute until the next request is received. * To enforce it happen, you might use the timer component (found in ZUL). * * <p>Notice: to resolve racing issue, you usually need to follow * this pattern. * <pre><code>//Event Handling Threadsynchronized (mutex) { final WorkingThread worker = new WorkingThread(desktop); synchronized (mutex) { worker.start(); Executions.wait(mutex); } ....}//Working Threadpublic void run() { .... synchronized (mutex) { Executions.notifyAll(desktop, mutex); }} </code></pre> * * @param desktop the desktop which the suspended thread is processing. * It must be the same desktop of the suspended thread. * @param mutex any non-null object to identify what to notify. * It must be same object passed to {@link #wait}. * If there is racing issue, you have to enclose it with * <code>synchronized</code> (though it is optional). * @see #notify(Object) * @see #notifyAll(Desktop, Object) */ public static final void notifyAll(Desktop desktop, Object mutex) { getUiEngine(desktop).notifyAll(desktop, mutex); } private static final UiEngine getUiEngine(Desktop desktop) { if (desktop == null) throw new IllegalArgumentException("desktop cannot be null"); return ((WebAppCtrl)desktop.getWebApp()).getUiEngine(); } private static final UiEngine getUiEngine() { final Execution exec = getCurrent(); if (exec == null) throw new IllegalStateException("This method can be called only under an event listener"); return ((WebAppCtrl)exec.getDesktop().getWebApp()).getUiEngine(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -