- All Known Implementing Classes:
public interface ServerPushRepresents a server-push controller. A server-push controller is a plugin to provide the server-push feature for ZK. A server-push thread is a working thread that want to manipulate a desktop whenever it wants, rather than in an event listener.
There are several to implement (or, to simulate) the server-push feature on a HTTP-based application.
First, the server-push feature can be simulated by client's polling. That is, the client polls the server for executing any pending server-push threads. The client can adjust the frequency based on the response time (in proportion to the server load) (see
PollingServerPushfor details). To poll, the client usually send the dummy command that does nothing but trigger
onPiggyback()to be execute.
Second, the server-push feature can be implemented by maintaining a persistent connection between client and server. It is also called Comet (see also Comet).
Third, the server-push feature can be simulated in a passive way. That is, it doesn't poll at all. Rather
onPiggyback()is called automatically when the user trigger some other events.
All Methods Instance Methods Abstract Methods Modifier and Type Method Description
activate(long timeout)Activate the current thread (which must be a server-push thread).
deactivate(boolean stop)Deactivates the current thread (which must be a server-push thread).
isActive()Returns if the working thread of the server push is active.
resume()Resumes server-push - this is required after desktop recycling.
<T extends Event>
schedule(EventListener<T> task, T event, Scheduler<T> scheduler)Called by the associated desktop to schedule a task to execute asynchronously.
start(Desktop desktop)Starts and initializes the server-push controller.
stop()Stops and cleans up the server-push controller.
boolean isActive()Returns if the working thread of the server push is active. In other words, it is true if it is between
void start(Desktop desktop)
void resume()Resumes server-push - this is required after desktop recycling. (added ServerPush interface to fix ZK-1777)
resume()is called when
UiEngine.recycleDesktop(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Page, java.io.Writer)is called to resume a previously enabled server-push on the recycled desktop.
<T extends Event> void schedule(EventListener<T> task, T event, Scheduler<T> scheduler)Called by the associated desktop to schedule a task to execute asynchronously.
The implementation usually delegates the scheduling to the scheduler passed as the third argument, which is controlled by the desktop. Of course, it could schedule it by itself.
task- the task to execute
event- the event to be passed to the task (i.e., the event listener). It could null or any instance as long as the task recognizes it.
scheduler- the default scheduler to schedule the task. The implementation usually delegates the scheduling back to it. If you prefer to handle it by yourself, you could ignore it.
boolean activate(long timeout) throws java.lang.InterruptedException, DesktopUnavailableExceptionActivate the current thread (which must be a server-push thread). It causes the current thread to wait until the desktop is available to access, the desktop no longer exists, some other thread interrupts this thread, or a certain amount of real time has elapsed.
The invoker of this method must invoke
deactivate(boolean)in this finally clause.
Note: the activation is applied to the desktop that was assigned by
onPiggyback(), this method is NOT called in the context of an event listener. Rather, it is called in the thread of a server-push thread.
timeout- the maximum time to wait in milliseconds. Ignored (i.e., never timeout) if non-positive.
- whether it is activated or it is timeout. The only reason it returns false is timeout.
java.lang.InterruptedException- if it is interrupted by other thread
DesktopUnavailableException- if the desktop is removed (when activating).
boolean deactivate(boolean stop)Deactivates the current thread (which must be a server-push thread).
stop- whether to stop after deactivate
- true if it is stopped
- See Also: