Class PushComponent<T extends PushController>

  • All Implemented Interfaces:
    DesktopRemovalAwareComponent, java.io.Serializable, java.lang.Cloneable, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.sys.ComponentCtrl

    public class PushComponent<T extends PushController>
    extends org.zkoss.zul.Span
    implements DesktopRemovalAwareComponent
    A push component is a component which allows ZK components to be updated asynchronously using reverse Ajax.

    Together with a PushController it enables server push in a Cockpit application. A push component is responsible for handling the execution of its PushController and sending CockpitEvents in an asynchronous fashion. It does not allow any child components to be added and should not be used for visually displaying content.

    Each push component typically has (or creates) its own PushController instance, typically implemented as a Java thread. The PushController (thread) is started as soon as the push component has been rendered by the browser using ZK's timer events.

    Note: Each thread is gently stopped (within the duration of the specified update interval) once the desktop to which this push component belongs has been removed. However, in order to avoid excessive creation of threads a push component should typically be added to a relatively "long-lived" component e.g. the ZK application's root component.

    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.zkoss.zk.ui.HtmlBasedComponent

        org.zkoss.zk.ui.HtmlBasedComponent.ExtraCtrl
      • Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent

        org.zkoss.zk.ui.AbstractComponent.Children
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static int DEFAULT_DELAY  
      • Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent

        _zclass
      • Fields inherited from interface org.zkoss.zk.ui.Component

        APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE
      • Fields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl

        AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE
    • Constructor Summary

      Constructors 
      Constructor Description
      PushComponent​(java.lang.Class<T> controllerClass)
      Creates a new push component instance with the default update interval and a PushController of the class specified by controllerClass.
      PushComponent​(java.lang.Class<T> controllerClass, int updateInterval)
      Creates a new push component instance with the specified update interval and a PushController of the class specified by controllerClass.
      PushComponent​(T controller)
      Creates a new push component instance with the specified PushController controller with an update interval set to the value of controller's update interval.
      PushComponent​(T controller, int updateInterval)
      Creates a new push component instance with the specified PushController controller and an update interval of updateInterval milliseconds.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEvent​(CockpitEvent event)
      Adds an event to this push components internal event queue.
      protected void appendChildInternal​(org.zkoss.zk.ui.Component child)  
      void clearEvents()
      Clears the event queue i.e.
      void desktopRemoved​(org.zkoss.zk.ui.Desktop desktop)  
      void detach()  
      void dispatchEvents()
      Dispatches the queued events.
      void enableServerPush​(boolean enable)  
      java.util.List<CockpitEvent> getEvents()
      Returns the events in the internal event queue.
      boolean insertBefore​(org.zkoss.zk.ui.Component newChild, org.zkoss.zk.ui.Component refChild)  
      void setParent​(org.zkoss.zk.ui.Component parent)  
      • Methods inherited from class org.zkoss.zul.impl.XulElement

        clone, getContext, getCtrlKeys, getPopup, getPropertyAccess, getTooltip, renderProperties, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributes
      • Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent

        focus, getAction, getDraggable, getDroppable, getExtraCtrl, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZclass, getZindex, getZIndex, service, setAction, setClass, setDraggable, setDroppable, setFocus, setHeight, setHeight0, setHeightDirectly, setHflex, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex, setVflex0, setVflexDirectly, setWidth, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectly
      • Methods inherited from class org.zkoss.zk.ui.AbstractComponent

        addAnnotation, addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, enableBindingAnnotation, equals, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotation, getAnnotations, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getId, getLastChild, getListenerIterator, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttribute, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, invalidate, isChildable, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, replace, response, response, response, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setStubonly, setStubonly, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetAttribute, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
      • Methods inherited from class java.lang.Object

        finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • PushComponent

        public PushComponent​(java.lang.Class<T> controllerClass)
                      throws java.lang.IllegalArgumentException,
                             java.lang.InstantiationException,
                             java.lang.IllegalAccessException
        Creates a new push component instance with the default update interval and a PushController of the class specified by controllerClass.
        Parameters:
        controllerClass - the class of the push controller to be used
        Throws:
        java.lang.IllegalArgumentException - if the push controller could not be created
        java.lang.InstantiationException - if the push controller could not be created
        java.lang.IllegalAccessException - if the push controller could not be created
        See Also:
        PushComponent(Class, int), PushComponent(PushController), PushComponent(PushController, int)
      • PushComponent

        public PushComponent​(java.lang.Class<T> controllerClass,
                             int updateInterval)
                      throws java.lang.IllegalArgumentException,
                             java.lang.InstantiationException,
                             java.lang.IllegalAccessException
        Creates a new push component instance with the specified update interval and a PushController of the class specified by controllerClass.
        Parameters:
        controllerClass - the class of the push controller to be used
        updateInterval - the update interval in milliseconds
        Throws:
        java.lang.IllegalArgumentException - if the push controller could not be created
        java.lang.InstantiationException - if the push controller could not be created
        java.lang.IllegalAccessException - if the push controller could not be created
        See Also:
        PushComponent(Class), PushComponent(PushController), PushComponent(PushController, int)
      • PushComponent

        public PushComponent​(T controller,
                             int updateInterval)
        Creates a new push component instance with the specified PushController controller and an update interval of updateInterval milliseconds.
        Parameters:
        controller - the push controller
        updateInterval - the update interval in milliseconds
    • Method Detail

      • insertBefore

        public boolean insertBefore​(org.zkoss.zk.ui.Component newChild,
                                    org.zkoss.zk.ui.Component refChild)
        Specified by:
        insertBefore in interface org.zkoss.zk.ui.Component
        Overrides:
        insertBefore in class org.zkoss.zk.ui.AbstractComponent
      • appendChildInternal

        protected void appendChildInternal​(org.zkoss.zk.ui.Component child)
      • clearEvents

        public void clearEvents()
        Clears the event queue i.e. removes all the previously queued events.
      • addEvent

        public void addEvent​(CockpitEvent event)
        Adds an event to this push components internal event queue.

        The events are typically dispatched as soon as control is returned from the push controller thread.

        Parameters:
        event - the event to be dispatched
      • getEvents

        public java.util.List<CockpitEvent> getEvents()
        Returns the events in the internal event queue.
        Returns:
        the queued events
      • dispatchEvents

        public void dispatchEvents()
        Dispatches the queued events.
      • detach

        public void detach()
        Specified by:
        detach in interface org.zkoss.zk.ui.Component
        Overrides:
        detach in class org.zkoss.zk.ui.AbstractComponent
      • setParent

        public void setParent​(org.zkoss.zk.ui.Component parent)
        Specified by:
        setParent in interface org.zkoss.zk.ui.Component
        Overrides:
        setParent in class org.zkoss.zk.ui.AbstractComponent
      • enableServerPush

        public void enableServerPush​(boolean enable)