Interface DesktopCtrl

  • All Known Implementing Classes:
    DesktopImpl

    public interface DesktopCtrl
    An addition interface to Desktop for implementation.

    Note: applications shall never access this interface.

    Author:
    tomyeh
    • Method Detail

      • getRequestQueue

        RequestQueue getRequestQueue()
        Returns the request queue.
      • getNextKey

        int getNextKey()
        Returns the next available key which is unique in the whole desktop.
      • getNextUuid

        java.lang.String getNextUuid​(Page page)
        Returns the next available UUID for a page. The returned UUID is unique in the desktop. You can consider it as unique in the whole session, though it may not be true if RawId is used (developer's responsibility to avoid conflict), integer overflow (too many UUID in one session, which can be considered as impossible), or a custom ID generator (IdGenerator) is used.
        Since:
        5.0.3
      • getNextUuid

        java.lang.String getNextUuid​(Component comp)
        Returns the next available UUID for a component. The returned UUID is unique in the desktop. You can consider it as unique in the whole session, though it may not be true if RawId is used (developer's responsibility to avoid conflict), integer overflow (too many UUID in one session, which can be considered as impossible), or a custom ID generator (IdGenerator) is used.
        Since:
        5.0.3
      • addComponent

        void addComponent​(Component comp)
        Adds a component to this page.

        It is used internally and developers shall not invoke it explicityly.

        Throws:
        java.lang.InternalError - if there is a component associated with the same UUID
      • mapComponent

        Component mapComponent​(java.lang.String uuid,
                               Component comp)
        Maps a component associated with the given UUID to this page. Notice that the given uuid can be different from comp's UUID (Component.getUuid()).

        If the given component is null, the mapping of UUID is removed.

        Unlike addComponent(org.zkoss.zk.ui.Component) and removeComponent(org.zkoss.zk.ui.Component), this method simply replaces the mapping if the given UUID is already mapped to the other component.

        It is used internally and developers shall not invoke it explicitly.

        Parameters:
        comp - the component to associate with the given UUID. If not, the association (i.e., mapping) is removed.
        Returns:
        the previous component that was associated with the given UUID.
        Since:
        6.0.0
      • removeComponent

        boolean removeComponent​(Component comp)
        Removes a component to this page.

        It is used internally and developers shall not invoke it explicitly.

        Returns:
        false always since 10.0.0 (Deprecated: whether UUID is recycled. If true, the caller shall reset UUID of the give component.)
        Since:
        5.0.4
      • addPage

        void addPage​(Page page)
        Adds a page to this desktop. It must be called when a page is created.

        This is one of the only few method you could access before activating an execution.

      • removePage

        void removePage​(Page page)
        Removes a page from this desktop.

        NOTE: once a page is removed, you can NOT add it back. You shall just GC it.

      • recoverDidFail

        void recoverDidFail​(java.lang.Throwable ex)
        Called when the recovering failed.
      • sessionWillPassivate

        void sessionWillPassivate​(Session sess)
        Notification that the session, which owns this desktop, is about to be passivated (a.k.a., serialized) by the Web container.
      • sessionDidActivate

        void sessionDidActivate​(Session sess)
        Notification that the session, which owns this desktop, has just been activated (a.k.a., deserialized) by the Web container.
      • destroy

        void destroy()
        Called when the desktop is about to be destroyed.
      • recycle

        void recycle()
        Called when the desktop has been recycled. More precisely, it is called when the desktop is no longer used and ready to be re-used later.
        Since:
        5.0.7
      • getSuspendedThreads

        java.util.Collection<EventProcessingThread> getSuspendedThreads()
        Returns a collection of suspended event processing threads, or empty if no suspended thread at all.

        An event processing thread is an instance of EventProcessingThread

        Note: if you access this method NOT in an event listener for the SAME desktop, you have to synchronize the iteration (though the returned collection is synchronized). Of course, it is always safe to test whether it is empty (Collection.isEmpty()).

        
                //Use the following pattern IF it is not in the SAME desktop's listener
                Collection c = otherDesktop.getSuspendedThreads();
                if (c.isEmpty()) {
                //do something accordingly
                } else {
                synchronized (c) {
                for (Iterator it = c.iterator(); it.hasNext();) {
                  //...
                }
                }
                }
      • ceaseSuspendedThread

        boolean ceaseSuspendedThread​(EventProcessingThread evtthd,
                                     java.lang.String cause)
        Ceases the specified event thread.
        Parameters:
        cause - an arbitrary text to describe the cause. It will be the message of the thrown InterruptedException.
        Returns:
        true if the event processing thread is ceased successfully; false if no such thread or it is not suspended.
      • getDownloadMedia

        Media getDownloadMedia​(java.lang.String medId,
                               boolean reserved)
        Returns the media that is associated with Desktop.getDownloadMediaURI(org.zkoss.util.media.Media, java.lang.String), or null if not found.

        This method is used internally. Developers rarely need to access this method.

        Parameters:
        reserved - reserved for future use.
        Returns:
        the media or null if not found.
      • onPiggybackListened

        void onPiggybackListened​(Component comp,
                                 boolean listen)
        Called when a component added or removed a listener for Events.ON_PIGGYBACK.

        The implementation usually uses it to optimize whether to call the listener when onPiggyback() is called.

        Parameters:
        comp - the component that adds an listener for Events.ON_PIGGYBACK. The component may or may not be a root component.
        listen - whether the listener is added (or removed).
        Since:
        3.0.0
      • onPiggyback

        void onPiggyback()
        Called each time when ZK Update Engine retrieves events. It is used to implement the piggyback feature by posting the events (see Events.ON_PIGGYBACK). The implementation could post events here. It should not process event here (since event thread might be used).

        Used only internally. Application developers shall not call it.

        Since:
        3.0.0
      • getServerPush

        ServerPush getServerPush()
        Returns the server-push controller, or null if it is not enabled yet.
      • enableServerPush

        boolean enableServerPush​(ServerPush serverpush)
        Enables the server-push feature with the specified server-push controller. If you want to use the default serverpush, use Desktop.enableServerPush(boolean) instead. This method allows the caller to provide a server push for more control.

        Example:

        desktop.enableServerPush(new PollingServerPush(1000,6000,5));

        Notice: a server push controller can be used in one desktop. It cannot be shared.

        Parameters:
        serverpush - the server-push controller. If null, the server-push feature is disabled (for this desktop). Note: this method will invoke ServerPush.start(org.zkoss.zk.ui.Desktop), so the caller doesn't need to do it.
        Since:
        3.0.0
        See Also:
        Desktop.enableServerPush(boolean)
      • enableServerPush

        boolean enableServerPush​(boolean enable,
                                 java.io.Serializable enabler)
        Enable/Disable serverpush using reference counting, so that multiple enablers can use the same serverpush and deregister whenever they want.
        Parameters:
        enable - true/false enable/disable serverpush
        enabler - the same reference must be used to disable again
        Returns:
        Currently only used by DesktopEventQueue to enable several eventqueues to use the same ServerPush
        Since:
        6.5.4
      • invokeExecutionCleanups

        void invokeExecutionCleanups​(Execution exec,
                                     Execution parent,
                                     java.util.List<java.lang.Throwable> errs)
        Invokes ExecutionCleanup.cleanup(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Execution, java.util.List<java.lang.Throwable>) for each relevant listener registered by Desktop.addListener(java.lang.Object).

        Used only internally.

        It never throws an exception but logs and adds it to the errs argument, if not null.

        Parameters:
        exec - the execution that is being destroyed
        parent - the previous execution, or null if no previous at all
        errs - a list of exceptions (java.lang.Throwable) if any exception occurred before this method is called, or null if no exception at all. Note: you can manipulate the list directly to add or clean up exceptions. For example, if exceptions are fixed correctly, you can call errs.clear() such that no error message will be displayed at the client.
        Since:
        3.0.6
      • responseSent

        void responseSent​(java.lang.String reqId,
                          java.lang.Object resInfo)
        Called when ZK Update Engine has sent a response to the client.
        Parameters:
        reqId - the request ID that the response is generated for. Ignore if null.
        resInfo - the response. Ignored if reqId is null.
        Since:
        5.0.0
      • getResponseId

        int getResponseId​(boolean advance)
        Returns the sequence ID of the response. The client and server uses the sequence ID to make sure the responses are processed in the correct order.

        The range of the sequence IDs is 1~999.

        Parameters:
        advance - whether to advance the number before returning. If true, the ID is increased and then returned. If false, the previous value is returned
        Since:
        3.5.0
      • setResponseId

        void setResponseId​(int resId)
        Sets the sequence ID of the response.

        It is rarely called other than in the recovering mode, i.e., ExecutionCtrl.isRecovering() is true.

        Parameters:
        resId - a value between 1 and 999. You can reset the ID by passing a non-positive value.
        Since:
        3.5.0
      • piggyResponse

        java.util.List<AuResponse> piggyResponse​(java.util.Collection<AuResponse> response,
                                                 boolean reset)
        Adds the responses to the so-called piggy-back queue. The responses in the piggy-back queue will be sent in the next AU request.

        This method is useful for working thread that wants to sent the responses back to the client. A typical example is the Comet-based server push.

        Parameters:
        response - the responses to be appended to the piggy-back queue.
        reset - whether to reset the piggy-back queue after returning the queued responses.
        Returns:
        all responses in the piggy-back queue, or null if nothing in the queue.
        Since:
        5.0.0
      • scheduledServerPush

        boolean scheduledServerPush()
        Returns if there is any scheduled task for server push.
        Since:
        5.0.6
      • activateServerPush

        boolean activateServerPush​(long timeout)
                            throws java.lang.InterruptedException
        Activates the current thread for accessing this desktop by the server push. It is called by Executions.activate(org.zkoss.zk.ui.Desktop). Don't call it directly.

        Like scheduleServerPush(org.zkoss.zk.ui.event.EventListener<T>, T), this method could be called in any thread, so it has to be safe for concurrent access.

        Note: the server push must be enabled first (by use of Desktop.enableServerPush(boolean)).

        Parameters:
        timeout - the maximum time to wait in milliseconds. Ignored (i.e., never timeout) if non-positive.
        Throws:
        java.lang.IllegalStateException - if the server push is not enabled.
        java.lang.InterruptedException
        Since:
        3.5.2
      • setExecution

        void setExecution​(Execution exec)
        Sets the execution (used to represent a lock).

        Used only to implement UiEngine.

      • getVisualizer

        Visualizer getVisualizer()
        Returns the visualizer associated with this desktop.

        Used only to implement UiEngine.

        Since:
        3.6.2
      • setVisualizer

        void setVisualizer​(Visualizer uv)
        Sets the visualizer associated with is desktop.

        Used only to implement UiEngine.

        Since:
        3.6.2
      • getActivationLock

        java.lang.Object getActivationLock()
        Returns the lock used to activate an execution. Before calling setVisualizer(org.zkoss.zk.ui.sys.Visualizer), this object returned by this method must be locked first.

        Used only to implement UiEngine.

        Since:
        3.6.2