Class CometServerPush
- java.lang.Object
-
- org.zkoss.zkex.ui.comet.CometServerPush
-
- All Implemented Interfaces:
org.zkoss.zk.ui.sys.ServerPush
public class CometServerPush extends java.lang.Object implements org.zkoss.zk.ui.sys.ServerPushA server-push implementation that is based on comet. This implementation is compatible with any version of Servlet. It also means it doesn't utilize Servlet 3 asynchronous processing support. If you are using Servlet 3 servers, it is recommended to useCometServerPushinstead.Available in ZK PE.
- Since:
- 6.0.0
- Author:
- tomyeh
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCometServerPush.AsyncInfoThe interface for implementing asynchronous processing.protected static classCometServerPush.ThreadInfoThe info of a server-push thread.
-
Constructor Summary
Constructors Constructor Description CometServerPush()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanactivate(long timeout)protected voidbeforeUpdate(CometServerPush.ThreadInfo info)booleandeactivate(boolean stop)org.zkoss.zk.ui.DesktopgetDesktop()Returns the desktop that this server push belongs to (never null).protected intgetIntPref(java.lang.String key)Retrieve the integer preference by the given key.protected java.lang.StringgetStartScript()Returns the JavaScript codes to enable (a.k.a., start) the server push.protected java.lang.StringgetStartScript(java.lang.String zkediton)protected java.lang.StringgetStopScript()Returns the JavaScript codes to disable (a.k.a., stop) the server push.booleanisActive()voidonPiggyback()protected voidonStart()Called whenstart(org.zkoss.zk.ui.Desktop)is called.protected voidonStop()Called whenstop()is called.protected voidprocessRequest(org.zkoss.zk.ui.Execution exec, CometServerPush.AsyncInfo ai)Called when receiving the comet request from the client.voidresume()ZK-1777 resume serverpush after DesktopRecycling<T extends org.zkoss.zk.ui.event.Event>
voidschedule(org.zkoss.zk.ui.event.EventListener<T> listener, T event, org.zkoss.zk.ui.sys.Scheduler<T> scheduler)protected booleansetBusy()Sets busy and return if it is busy for processing other request.voidstart(org.zkoss.zk.ui.Desktop desktop)Starts the server push.protected voidstartClientPush()Sends an AU response to the client to start the server push.voidstop()Stops the server push.protected voidstopClientPush()Sends an AU response the client to stop the server push.
-
-
-
Method Detail
-
startClientPush
protected void startClientPush()
Sends an AU response to the client to start the server push. It is called bystart(org.zkoss.zk.ui.Desktop).The derived class usually overrides this method to support different devices.
The default implementation is to send an
AuScriptresponse to contain the script specified in a preference calledCometServerPush.start, or the script returned bygetStartScript(), if the preference is not found. Devices that don't support scripts could override this method to send a custom AU response (AuResponse).
-
stopClientPush
protected void stopClientPush()
Sends an AU response the client to stop the server push.The derived class usually overrides this method to support different devices, such as ZK Mobile.
The default implementation is to send an
AuScriptinstance to contain the script specified in a preference calledCometServerPush.stop,' or the script returned bygetStopScript(), if the preference is not found. Devices that don't support scripts could override this method to send a custom AU response (AuResponse).
-
getStartScript
protected java.lang.String getStartScript()
Returns the JavaScript codes to enable (a.k.a., start) the server push. It is called bystartClientPush()to prepare the script ofAuScriptthat will be sent to the client.
-
getStartScript
protected java.lang.String getStartScript(java.lang.String zkediton)
-
getIntPref
protected int getIntPref(java.lang.String key)
Retrieve the integer preference by the given key. Visibility set to protected so that zkmax can have access to this method.
-
getStopScript
protected java.lang.String getStopScript()
Returns the JavaScript codes to disable (a.k.a., stop) the server push. It is called bystopClientPush()to prepare the script ofAuScriptthat will be sent to the client.
-
getDesktop
public org.zkoss.zk.ui.Desktop getDesktop()
Returns the desktop that this server push belongs to (never null).
-
isActive
public boolean isActive()
- Specified by:
isActivein interfaceorg.zkoss.zk.ui.sys.ServerPush
-
start
public void start(org.zkoss.zk.ui.Desktop desktop)
Starts the server push.The derived class rarely need to override this method. Rather, override
startClientPush().- Specified by:
startin interfaceorg.zkoss.zk.ui.sys.ServerPush
-
resume
public void resume()
ZK-1777 resume serverpush after DesktopRecycling- Specified by:
resumein interfaceorg.zkoss.zk.ui.sys.ServerPush
-
stop
public void stop()
Stops the server push.The derived class rarely need to override this method. Rather, override
stopClientPush().- Specified by:
stopin interfaceorg.zkoss.zk.ui.sys.ServerPush
-
onStart
protected void onStart()
Called whenstart(org.zkoss.zk.ui.Desktop)is called. This method is called beforestartClientPush(), and used to initialize the desktop, if necessary.The default implementation initializes an extension to process the comet request.
-
onStop
protected void onStop()
Called whenstop()is called. This method is called afterstopClientPush()is called and this server push has been cleaned up.The default implementation does nothing.
-
onPiggyback
public void onPiggyback()
- Specified by:
onPiggybackin interfaceorg.zkoss.zk.ui.sys.ServerPush
-
schedule
public <T extends org.zkoss.zk.ui.event.Event> void schedule(org.zkoss.zk.ui.event.EventListener<T> listener, T event, org.zkoss.zk.ui.sys.Scheduler<T> scheduler)- Specified by:
schedulein interfaceorg.zkoss.zk.ui.sys.ServerPush
-
setBusy
protected boolean setBusy()
Sets busy and return if it is busy for processing other request. If it is busy, true is returned. If it is not busy, false is returned but it is marked as busy.It is possible since the client might abort the previous one and issue a new one but their server didn't know.
-
processRequest
protected void processRequest(org.zkoss.zk.ui.Execution exec, CometServerPush.AsyncInfo ai) throws java.io.IOExceptionCalled when receiving the comet request from the client.- Throws:
java.io.IOException
-
activate
public boolean activate(long timeout) throws java.lang.InterruptedException, org.zkoss.zk.ui.DesktopUnavailableException- Specified by:
activatein interfaceorg.zkoss.zk.ui.sys.ServerPush- Throws:
java.lang.InterruptedExceptionorg.zkoss.zk.ui.DesktopUnavailableException
-
beforeUpdate
protected void beforeUpdate(CometServerPush.ThreadInfo info)
-
deactivate
public boolean deactivate(boolean stop)
- Specified by:
deactivatein interfaceorg.zkoss.zk.ui.sys.ServerPush
-
-