public class CometServerPush extends java.lang.Object implements ServerPush
CometServerPush
instead.
Available in ZK PE.
Modifier and Type | Class and Description |
---|---|
static interface |
CometServerPush.AsyncInfo
The interface for implementing asynchronous processing.
|
Constructor and Description |
---|
CometServerPush() |
Modifier and Type | Method and Description |
---|---|
boolean |
activate(long timeout)
Activate the current thread (which must be a server-push thread).
|
boolean |
deactivate(boolean stop)
Deactivates the current thread (which must be a server-push thread).
|
Desktop |
getDesktop()
Returns the desktop that this server push belongs to (never null).
|
protected java.lang.String |
getStartScript()
Returns the JavaScript codes to enable (a.k.a., start) the server push.
|
protected java.lang.String |
getStopScript()
Returns the JavaScript codes to disable (a.k.a., stop) the server push.
|
boolean |
isActive()
Returns if the working thread of the server push is active.
|
void |
onPiggyback()
Called when
Events.ON_PIGGYBACK
is received. |
protected void |
onStart()
Called when
start(org.zkoss.zk.ui.Desktop) is called. |
protected void |
onStop()
Called when
stop() is called. |
protected void |
processRequest(Execution exec,
CometServerPush.AsyncInfo ai)
Called when receiving the comet request from the client.
|
void |
resume()
ZK-1777 resume serverpush after DesktopRecycling
|
<T extends Event> |
schedule(EventListener<T> listener,
T event,
Scheduler<T> scheduler)
Called by the associated desktop to schedule a task to execute
asynchronously.
|
protected boolean |
setBusy()
Sets busy and return if it is busy for processing other request.
|
void |
start(Desktop desktop)
Starts the server push.
|
protected void |
startClientPush()
Sends an AU response to the client to start the server push.
|
void |
stop()
Stops the server push.
|
protected void |
stopClientPush()
Sends an AU response the client to stop the server push.
|
protected void startClientPush()
start(org.zkoss.zk.ui.Desktop)
.
The derived class usually overrides this method to support different devices.
The default implementation is to send an AuScript
response to contain
the script specified in a preference called CometServerPush.start
,
or the script returned by getStartScript()
, if the preference is not found.
Devices that don't support scripts could override this method
to send a custom AU response (AuResponse
).
protected void stopClientPush()
The derived class usually overrides this method to support different devices, such as ZK Mobile.
The default implementation is to send an AuScript
instance to contain
the script specified in a preference called CometServerPush.stop
,'
or the script returned by getStopScript()
, if the preference is not found.
Devices that don't support scripts could override this method
to send a custom AU response (AuResponse
).
protected java.lang.String getStartScript()
startClientPush()
to prepare the script
of AuScript
that will be sent to the client.protected java.lang.String getStopScript()
stopClientPush()
to prepare the script
of AuScript
that will be sent to the client.public Desktop getDesktop()
public boolean isActive()
ServerPush
Executions.activate(org.zkoss.zk.ui.Desktop)
and
Executions.deactivate(org.zkoss.zk.ui.Desktop)
.isActive
in interface ServerPush
public void start(Desktop desktop)
The derived class rarely need to override this method.
Rather, override startClientPush()
.
start
in interface ServerPush
public void resume()
resume
in interface ServerPush
public void stop()
The derived class rarely need to override this method.
Rather, override stopClientPush()
.
stop
in interface ServerPush
protected void onStart()
start(org.zkoss.zk.ui.Desktop)
is called.
This method is called before startClientPush()
, and used to initialize the desktop,
if necessary.
The default implementation initializes an extension to process the comet request.
protected void onStop()
stop()
is called.
This method is called after stopClientPush()
is called and this server push
has been cleaned up.
The default implementation does nothing.
public void onPiggyback()
ServerPush
Events.ON_PIGGYBACK
is received. The invocation is passive (i.e., triggered by
other events, rather than spontaneous).
This method is called in
the context of an event listener. In other words, the execution
is activated and you can retrieve it by
Executions.getCurrent()
.
onPiggyback
in interface ServerPush
public <T extends Event> void schedule(EventListener<T> listener, T event, Scheduler<T> scheduler)
ServerPush
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.
schedule
in interface ServerPush
listener
- the task to executeevent
- 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.protected boolean setBusy()
It is possible since the client might abort the previous one and issue a new one but their server didn't know.
protected void processRequest(Execution exec, CometServerPush.AsyncInfo ai) throws java.io.IOException
java.io.IOException
public boolean activate(long timeout) throws java.lang.InterruptedException, DesktopUnavailableException
ServerPush
The invoker of this method must invoke ServerPush.deactivate(boolean)
in this finally clause.
Note: the activation is applied to the desktop that was
assigned by ServerPush.start(org.zkoss.zk.ui.Desktop)
.
Unlike ServerPush.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.
activate
in interface ServerPush
timeout
- the maximum time to wait in milliseconds.
Ignored (i.e., never timeout) if non-positive.java.lang.InterruptedException
- if it is interrupted by other threadDesktopUnavailableException
- if the desktop is removed
(when activating).public boolean deactivate(boolean stop)
ServerPush
deactivate
in interface ServerPush
stop
- whether to stop after deactivateServerPush.activate(long)
Copyright © 2005-2011 Potix Corporation. All Rights Reserved.