Class DesktopImpl
- java.lang.Object
-
- org.zkoss.zk.ui.impl.DesktopImpl
-
- All Implemented Interfaces:
java.io.Serializable,Desktop,Scope,DesktopCtrl
public class DesktopImpl extends java.lang.Object implements Desktop, DesktopCtrl, java.io.Serializable
The implementation ofDesktop.Note: though
DesktopImplis serializable, it is designed to work with Web container to enable the serialization of sessions. It is not suggested to serialize and deserialize it directly since many fields might be lost.On the other hand, it is OK to serialize and deserialize
Component.- Author:
- tomyeh
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DesktopImpl(WebApp wapp, java.lang.String updateURI, java.lang.String path, java.lang.String deviceType, java.lang.Object request)DesktopImpl(WebApp wapp, java.lang.String updateURI, java.lang.String resourceURI, java.lang.String path, java.lang.String deviceType, java.lang.Object request)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanactivateServerPush(long timeout)Activates the current thread for accessing this desktop by the server push.voidaddComponent(Component comp)Adds a component to this page.voidaddListener(java.lang.Object listener)Adds a listener.voidaddPage(Page page)Adds a page to this desktop.booleanaddScopeListener(ScopeListener listener)Adds a listener to listen whether this scope is changed.voidafterComponentAttached(Component comp, Page page)voidafterComponentDetached(Component comp, Page prevpage)voidafterComponentMoved(Component parent, Component child, Component prevparent)voidafterProcessEvent(Event event)EventbeforePostEvent(Event event)EventbeforeProcessEvent(Event event)EventbeforeSendEvent(Event event)booleanceaseSuspendedThread(EventProcessingThread evtthd, java.lang.String cause)Ceases the specified event thread.voiddeactivateServerPush()Deactivates the thread that has invokedDesktopCtrl.activateServerPush(long)successfully.voiddestroy()Called when the desktop is about to be destroyed.booleanenableServerPush(boolean enable)Enables or disables the server-push feature.booleanenableServerPush(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.booleanenableServerPush(ServerPush serverpush)Enables the server-push feature with the specified server-push controller.java.lang.ObjectgetActivationLock()Returns the lock used to activate an execution.java.lang.ObjectgetAttribute(java.lang.String name)Returns the value of the specified custom attribute associated with the desktop.java.lang.ObjectgetAttribute(java.lang.String name, boolean recurse)Returns the custom attribute associated with this object.java.util.Map<java.lang.String,java.lang.Object>getAttributes()Returns all custom attributes associated with this desktop.java.lang.StringgetBookmark()Returns the current bookmark (never null).ComponentgetComponentByUuid(java.lang.String uuid)Returns the component of the specified UUID (Component.getUuid()).ComponentgetComponentByUuidIfAny(java.lang.String uuid)Returns the component of the specified UUID (Component.getUuid()), or null if not found.java.util.Collection<Component>getComponents()Returns all components contained in this desktop.java.lang.StringgetCurrentDirectory()Returns the current directory (never null).DevicegetDevice()Returns the device that is associated with this desktop.java.lang.StringgetDeviceType()Returns the device type that this desktop belongs to.org.zkoss.util.media.MediagetDownloadMedia(java.lang.String medId, boolean reserved)Returns the media that is associated withDesktop.getDownloadMediaURI(org.zkoss.util.media.Media, java.lang.String), or null if not found.java.lang.StringgetDownloadMediaURI(org.zkoss.util.media.Media media, java.lang.String pathInfo)Returns URI for a media that is used to download to the client.java.lang.StringgetDynamicMediaURI(Component comp, java.lang.String pathInfo)Returns URI for a dynamic generated media associated with a component.ExecutiongetExecution()Returns the execution, or null if this desktop is not serving any execution (a.k.a., not locked).PagegetFirstPage()Returns the first page, or null if no page at all (happens when the desktop has been destroyed)java.lang.StringgetId()Returns ID of this desktop.java.lang.ObjectgetLastResponse(java.lang.String reqId)Returns the response for the last request, or null if no response yet, or the specified request ID doesn't match the last one (passed toDesktopCtrl.responseSent(java.lang.String, java.lang.Object)).intgetNextKey()Returns the next available key which is unique in the whole desktop.java.lang.StringgetNextUuid(Component comp)Returns the next available UUID for a component.java.lang.StringgetNextUuid(Page page)Returns the next available UUID for a page.PagegetPage(java.lang.String pageId)Returns the page of the specified ID or UUID.PagegetPageIfAny(java.lang.String pageId)Returns the page of the specified ID or UUID, or null if no such page.java.util.Collection<Page>getPages()Returns a readonly collection of allPagein this desktop.java.lang.StringgetQueryString()Returns the query string that is contained in the request URL after the path (Desktop.getRequestPath()), or null if the URL does not have a query string.java.lang.StringgetRequestPath()Returns the path of the request that causes this desktop to be created, or "" if not available.RequestQueuegetRequestQueue()Returns the request queue.java.lang.StringgetResourceURI(java.lang.String pathInfo)Returns the URI for ZK resource.intgetResponseId(boolean advance)Returns the sequence ID of the response.ServerPushgetServerPush()Returns the server-push controller, or null if it is not enabled yet.SessiongetSession()Returns the session of this desktop.StoragegetStorage()Returns the storage in a desktop scope.java.util.Collection<EventProcessingThread>getSuspendedThreads()Returns a collection of suspended event processing threads, or empty if no suspended thread at all.java.lang.StringgetUpdateURI(java.lang.String pathInfo)Returns the URI for asynchronous update.VisualizergetVisualizer()Returns the visualizer associated with this desktop.WebAppgetWebApp()Returns the Web application this desktop belongs to.booleanhasAttribute(java.lang.String name)Returns if a custom attribute is associated with this object (scope).booleanhasAttribute(java.lang.String name, boolean recurse)Returns if a custom attribute is associated with this object.booleanhasPage(java.lang.String pageId)Returns whether a page exists.voidinvalidate()Invalidates the desktop.voidinvokeDesktopCleanups()InvokesDesktopCleanup.cleanup(org.zkoss.zk.ui.Desktop)for each relevant listener registered byDesktop.addListener(java.lang.Object).voidinvokeExecutionCleanups(Execution exec, Execution parent, java.util.List<java.lang.Throwable> errs)InvokesExecutionCleanup.cleanup(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Execution, java.util.List<java.lang.Throwable>)for each relevant listener registered byDesktop.addListener(java.lang.Object).voidinvokeExecutionInits(Execution exec, Execution parent)InvokesExecutionInit.init(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Execution)for each relevant listener registered byDesktop.addListener(java.lang.Object).booleanisAlive()Returns whether the desktop is still alive.booleanisServerPushEnabled()Returns whether the server-push feature is enabled for this desktop.ComponentmapComponent(java.lang.String uuid, Component comp)Maps a component associated with the given UUID to this page.protected RequestQueuenewRequestQueue()Creates the request queue.voidonPiggyback()Called each time when ZK Update Engine retrieves events.voidonPiggybackListened(Component comp, boolean listen)Called when a component added or removed a listener forEvents.ON_PIGGYBACK.java.util.List<AuResponse>piggyResponse(java.util.Collection<AuResponse> response, boolean reset)Adds the responses to the so-called piggy-back queue.voidpushHistoryState(java.lang.Object state, java.lang.String title, java.lang.String url)Pushes a new history state.voidrecoverDidFail(java.lang.Throwable ex)Called when the recovering failed.voidrecycle()Called when the desktop has been recycled.java.lang.ObjectremoveAttribute(java.lang.String name)Removes the specified custom attribute associated with the desktop.java.lang.ObjectremoveAttribute(java.lang.String name, boolean recurse)Removes the custom attribute associated with this scope.booleanremoveComponent(Component comp)Removes a component to this page.booleanremoveListener(java.lang.Object listener)Removes a listener.voidremovePage(Page page)Removes a page from this desktop.booleanremoveScopeListener(ScopeListener listener)Removes a change listener from this scope.voidreplaceHistoryState(java.lang.Object state, java.lang.String title, java.lang.String url)Replaces the current history state.voidresponseSent(java.lang.String reqId, java.lang.Object response)Called when ZK Update Engine has sent a response to the client.booleanscheduledServerPush()Returns if there is any scheduled task for server push.<T extends Event>
voidscheduleServerPush(EventListener<T> listener, T event)Schedules a task to run under the server push of the given desktop asynchronously.voidservice(AuRequest request, boolean everError)Processes an AU request.voidsessionDidActivate(Session sess)Notification that the session, which owns this desktop, has just been activated (a.k.a., deserialized) by the Web container.voidsessionWillPassivate(Session sess)Notification that the session, which owns this desktop, is about to be passivated (a.k.a., serialized) by the Web container.java.lang.ObjectsetAttribute(java.lang.String name, java.lang.Object value)Sets the value of the specified custom attribute associated with the desktop.java.lang.ObjectsetAttribute(java.lang.String name, java.lang.Object value, boolean recurse)Sets the custom attribute associated with this scope, or the parent scope.voidsetBookmark(java.lang.String name)Sets a bookmark to this desktop.voidsetBookmark(java.lang.String name, boolean replace)Sets the bookmark to this desktop. with more control.voidsetCurrentDirectory(java.lang.String dir)Sets the current directory.voidsetDeviceType(java.lang.String deviceType)Sets the device type that this desktop belongs to.voidsetExecution(Execution exec)Sets the execution (used to represent a lock).voidsetId(java.lang.String id)Sets the desktop identifier.voidsetResponseId(int resId)Sets the sequence ID of the response.voidsetVisualizer(Visualizer uv)Sets the visualizer associated with is desktop.java.lang.StringtoString()
-
-
-
Constructor Detail
-
DesktopImpl
public DesktopImpl(WebApp wapp, java.lang.String updateURI, java.lang.String path, java.lang.String deviceType, java.lang.Object request)
- Parameters:
wapp- the web applicationupdateURI- the URI to access the update engine (no expression allowed). Note: it is NOT encoded yet.path- the path that causes this desktop to create. If null or empty is specified, it means not available.deviceType- the device type. If null or empty is specified, "ajax" is assumed.request- the request (HttpServletRequest if HTTP)- Since:
- 3.0.1
-
DesktopImpl
public DesktopImpl(WebApp wapp, java.lang.String updateURI, java.lang.String resourceURI, java.lang.String path, java.lang.String deviceType, java.lang.Object request)
- Parameters:
wapp- the web applicationupdateURI- the URI to access the update engine (no expression allowed). Note: it is NOT encoded yet.resourceURI- the URI to access the resource engine (no expression allowed). Note: it is NOT encoded yet.path- the path that causes this desktop to create. If null or empty is specified, it means not available.deviceType- the device type. If null or empty is specified, "ajax" is assumed.request- the request (HttpServletRequest if HTTP)- Since:
- 9.5.0
-
-
Method Detail
-
getQueryString
public java.lang.String getQueryString()
Description copied from interface:DesktopReturns the query string that is contained in the request URL after the path (Desktop.getRequestPath()), or null if the URL does not have a query string.- Specified by:
getQueryStringin interfaceDesktop
-
getId
public java.lang.String getId()
Description copied from interface:DesktopReturns ID of this desktop. It is unique in the whole session.
-
newRequestQueue
protected RequestQueue newRequestQueue()
Creates the request queue. It is called when the desktop is initialized.You may override it to provide your implementation of
RequestQueueto control how to optimize the AU requests.Default: creates an instance from
RequestQueueImpl;- Since:
- 2.4.0
-
getDeviceType
public java.lang.String getDeviceType()
Description copied from interface:DesktopReturns the device type that this desktop belongs to.A device type identifies the type of a client. For example, "ajax" represents the Web browsers with Ajax support, while "mil" represents clients that supports Mobile Interactive markup Language (on Limited Connected Device, such as mobile phones).
A desktop can use the languages belonging to the same device type. See also
LanguageDefinition.getDeviceType().A component can be added to a desktop only if they belong to the same device type.
Default: depends on the extension of the resource path, "ajax" if the path or extension not available. If
Richletis used, its language definition's device type is assumed.- Specified by:
getDeviceTypein interfaceDesktop
-
getDevice
public Device getDevice()
Description copied from interface:DesktopReturns the device that is associated with this desktop.Note: the device is shared by all desktops of the same device type.
-
setDeviceType
public void setDeviceType(java.lang.String deviceType)
Description copied from interface:DesktopSets the device type that this desktop belongs to.Note: you can change the device type only before any component is attached to a page of the desktop. In other words, you can set the device type only at the initialization stage.
If the device type is changed, any device allocated for this desktop (
Desktop.getDevice()) will be dropped and recreated at the next invocation toDesktop.getDevice().- Specified by:
setDeviceTypein interfaceDesktop
-
getExecution
public Execution getExecution()
Description copied from interface:DesktopReturns the execution, or null if this desktop is not serving any execution (a.k.a., not locked).- Specified by:
getExecutionin interfaceDesktop
-
getSession
public final Session getSession()
Description copied from interface:DesktopReturns the session of this desktop.- Specified by:
getSessionin interfaceDesktop
-
getUpdateURI
public java.lang.String getUpdateURI(java.lang.String pathInfo)
Description copied from interface:DesktopReturns the URI for asynchronous update.You rarely need this method unless for implementing special components, such as file upload.
- Specified by:
getUpdateURIin interfaceDesktop- Parameters:
pathInfo- the path to append to the returned URI, or null to ignore
-
getResourceURI
public java.lang.String getResourceURI(java.lang.String pathInfo)
Description copied from interface:DesktopReturns the URI for ZK resource.- Specified by:
getResourceURIin interfaceDesktop- Parameters:
pathInfo- the path to append to the returned URI, or null to ignore
-
getDynamicMediaURI
public java.lang.String getDynamicMediaURI(Component comp, java.lang.String pathInfo)
Description copied from interface:DesktopReturns URI for a dynamic generated media associated with a component. ZK Update Engine will then invoke invokeDynamicMedia.getMedia(java.lang.String)to response.Note: to use with this method,
DynamicMediamust be implemented as part of the object returned byComponentCtrl.getExtraCtrl().Used mainly for component implementation.
- Specified by:
getDynamicMediaURIin interfaceDesktop
-
getDownloadMediaURI
public java.lang.String getDownloadMediaURI(org.zkoss.util.media.Media media, java.lang.String pathInfo)Description copied from interface:DesktopReturns URI for a media that is used to download to the client. The client will open a Save As dialog to save the specified file.Note: once called, the media belongs to desktop and it is purged automatically. Thus, don't access it again after calling this method.
- Specified by:
getDownloadMediaURIin interfaceDesktop
-
getDownloadMedia
public org.zkoss.util.media.Media getDownloadMedia(java.lang.String medId, boolean reserved)Description copied from interface:DesktopCtrlReturns the media that is associated withDesktop.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.
- Specified by:
getDownloadMediain interfaceDesktopCtrlreserved- reserved for future use.- Returns:
- the media or null if not found.
-
getPage
public Page getPage(java.lang.String pageId)
Description copied from interface:DesktopReturns the page of the specified ID or UUID.This is one of the only few method you could access before activating an execution.
-
getPageIfAny
public Page getPageIfAny(java.lang.String pageId)
Description copied from interface:DesktopReturns the page of the specified ID or UUID, or null if no such page.- Specified by:
getPageIfAnyin interfaceDesktop- Parameters:
pageId- the page's ID or UUID. ID has the higher priority.
-
hasPage
public boolean hasPage(java.lang.String pageId)
Description copied from interface:DesktopReturns whether a page exists.
-
getPages
public java.util.Collection<Page> getPages()
Description copied from interface:DesktopReturns a readonly collection of allPagein this desktop.
-
getFirstPage
public Page getFirstPage()
Description copied from interface:DesktopReturns the first page, or null if no page at all (happens when the desktop has been destroyed)- Specified by:
getFirstPagein interfaceDesktop
-
getBookmark
public java.lang.String getBookmark()
Description copied from interface:DesktopReturns the current bookmark (never null). The returned might be the same as the last call toDesktop.setBookmark(java.lang.String), because user might use BACK, FORWARD or others to change the bookmark.- Specified by:
getBookmarkin interfaceDesktop
-
setBookmark
public void setBookmark(java.lang.String name)
Description copied from interface:DesktopSets a bookmark to this desktop. Then, when user press BACK, FORWARD or specify an URL with this bookmark, the onBookmarkChange event is sent to all pages of the desktop.It is the same as
setBookmark(name, false)- Specified by:
setBookmarkin interfaceDesktop
-
setBookmark
public void setBookmark(java.lang.String name, boolean replace)Description copied from interface:DesktopSets the bookmark to this desktop. with more control.- Specified by:
setBookmarkin interfaceDesktop- Parameters:
name- the name of the bookmarkreplace- if true, the bookmark is replaced (in the history list)- See Also:
Desktop.setBookmark(String)
-
getComponents
public java.util.Collection<Component> getComponents()
Description copied from interface:DesktopReturns all components contained in this desktop.- Specified by:
getComponentsin interfaceDesktop
-
getComponentByUuid
public Component getComponentByUuid(java.lang.String uuid)
Description copied from interface:DesktopReturns the component of the specified UUID (Component.getUuid()).- Specified by:
getComponentByUuidin interfaceDesktop
-
getComponentByUuidIfAny
public Component getComponentByUuidIfAny(java.lang.String uuid)
Description copied from interface:DesktopReturns the component of the specified UUID (Component.getUuid()), or null if not found.- Specified by:
getComponentByUuidIfAnyin interfaceDesktop
-
addComponent
public void addComponent(Component comp)
Description copied from interface:DesktopCtrlAdds a component to this page.It is used internally and developers shall not invoke it explicityly.
- Specified by:
addComponentin interfaceDesktopCtrl
-
removeComponent
public boolean removeComponent(Component comp)
Description copied from interface:DesktopCtrlRemoves a component to this page.It is used internally and developers shall not invoke it explicitly.
- Specified by:
removeComponentin interfaceDesktopCtrl- Returns:
- false always since 10.0.0 (Deprecated:
whether UUID is recycled. If true, the caller shall reset UUID of the give component.)
-
mapComponent
public Component mapComponent(java.lang.String uuid, Component comp)
Description copied from interface:DesktopCtrlMaps 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
DesktopCtrl.addComponent(org.zkoss.zk.ui.Component)andDesktopCtrl.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.
- Specified by:
mapComponentin interfaceDesktopCtrlcomp- 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.
-
getAttributes
public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
Description copied from interface:DesktopReturns all custom attributes associated with this desktop.- Specified by:
getAttributesin interfaceDesktop- Specified by:
getAttributesin interfaceScope
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface:DesktopReturns the value of the specified custom attribute associated with the desktop.- Specified by:
getAttributein interfaceDesktop- Specified by:
getAttributein interfaceScope
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name, boolean recurse)Description copied from interface:ScopeReturns the custom attribute associated with this object.- Specified by:
getAttributein interfaceScoperecurse- whether to search its ancestor scope. If true and the current scope doen't define the attribute, it searches up its ancestor to see any of them has defined the specified attribute.
-
hasAttribute
public boolean hasAttribute(java.lang.String name)
Description copied from interface:ScopeReturns if a custom attribute is associated with this object (scope).Notice that
nullis a valid value, so you can tell if an attribute is associated by examining the return value ofScope.getAttribute(java.lang.String).- Specified by:
hasAttributein interfaceScope
-
hasAttribute
public boolean hasAttribute(java.lang.String name, boolean recurse)Description copied from interface:ScopeReturns if a custom attribute is associated with this object.Notice that
nullis a valid value, so you can tell if an attribute is associated by examining the return value ofScope.getAttribute(java.lang.String).- Specified by:
hasAttributein interfaceScoperecurse- whether to search its ancestor scope. If true and the current scope doen't define the attribute, it searches up its ancestor to see any of them has defined the specified attribute.
-
setAttribute
public java.lang.Object setAttribute(java.lang.String name, java.lang.Object value)Description copied from interface:DesktopSets the value of the specified custom attribute associated with the desktop.- Specified by:
setAttributein interfaceDesktop- Specified by:
setAttributein interfaceScope- Returns:
- the previous value associated with the attribute, if any
-
setAttribute
public java.lang.Object setAttribute(java.lang.String name, java.lang.Object value, boolean recurse)Description copied from interface:ScopeSets the custom attribute associated with this scope, or the parent scope.- Specified by:
setAttributein interfaceScoperecurse- whether to look up the parent scope for the existence of the attribute.
If recurse is true and the attribute is defined in one of its ancestor (including page), the attribute is replaced. Otherwise, it is the same asScope.setAttribute(String,Object).
-
removeAttribute
public java.lang.Object removeAttribute(java.lang.String name)
Description copied from interface:DesktopRemoves the specified custom attribute associated with the desktop.- Specified by:
removeAttributein interfaceDesktop- Specified by:
removeAttributein interfaceScope- Returns:
- the previous value associated with the attribute, if any,
-
removeAttribute
public java.lang.Object removeAttribute(java.lang.String name, boolean recurse)Description copied from interface:ScopeRemoves the custom attribute associated with this scope.- Specified by:
removeAttributein interfaceScoperecurse- whether to look up the parent scope for the existence of the attribute.
If recurse is true and the attribute is defined in one of its ancestor (including page), the attribute is removed. Otherwise, it is the same asScope.removeAttribute(String).
-
addScopeListener
public boolean addScopeListener(ScopeListener listener)
Description copied from interface:ScopeAdds a listener to listen whether this scope is changed. The listener is called when a custom attribute is added, removed, or the parent is changed.- Specified by:
addScopeListenerin interfaceScope- Returns:
- weather the listener is added successfully. Note: if the resolver was added before, it won't be added again and this method returns false.
-
removeScopeListener
public boolean removeScopeListener(ScopeListener listener)
Description copied from interface:ScopeRemoves a change listener from this scope.- Specified by:
removeScopeListenerin interfaceScope- Returns:
- false if listener is not added before.
-
getWebApp
public WebApp getWebApp()
Description copied from interface:DesktopReturns the Web application this desktop belongs to.
-
getRequestPath
public java.lang.String getRequestPath()
Description copied from interface:DesktopReturns the path of the request that causes this desktop to be created, or "" if not available. In other words, it is the request path of the first page (seePage.getRequestPath()).For example, "/foo/index.zul" (a ZUML page is requested) or /test (a richlet).
- Specified by:
getRequestPathin interfaceDesktop- See Also:
Page.getRequestPath()
-
getCurrentDirectory
public java.lang.String getCurrentDirectory()
Description copied from interface:DesktopReturns the current directory (never null). It is empty if no current directory at all. Otherwise, it must end with '/'. In other words, you could use getCurrentDirectory() + relative_path.- Specified by:
getCurrentDirectoryin interfaceDesktop
-
setCurrentDirectory
public void setCurrentDirectory(java.lang.String dir)
Description copied from interface:DesktopSets the current directory.- Specified by:
setCurrentDirectoryin interfaceDesktop- Parameters:
dir- the current directory. If null, an empty string is assumed (means no current directory at all).
-
getRequestQueue
public RequestQueue getRequestQueue()
Description copied from interface:DesktopCtrlReturns the request queue.- Specified by:
getRequestQueuein interfaceDesktopCtrl
-
setExecution
public void setExecution(Execution exec)
Description copied from interface:DesktopCtrlSets the execution (used to represent a lock).Used only to implement
UiEngine.- Specified by:
setExecutionin interfaceDesktopCtrl
-
service
public void service(AuRequest request, boolean everError)
Description copied from interface:DesktopCtrlProcesses an AU request. Notice that not only the requests for a desktop but also the requests for any component in the desktop will go thru this method.To override the default processing, register an AU request service
AuServiceby invokingDesktop.addListener(java.lang.Object).- This method first invokes the registered AU request service
(
AuService) one-by-one, until the first one returns true. - If none of them returns true or no AU service at all,
it checks if the request is targeting a component
(i.e.,
AuRequest.getComponent()is not null). - If it is targeting a component, it invokes
ComponentCtrl.service(org.zkoss.zk.au.AuRequest, boolean)to handle the service. - If it is not targeting a component (i.e., targeting to
this desktop), it handles as follows.
- It handles the recognized requests, including onBookmarkChange, onURIChange and onClientInfo.
- If the request is not one of above, it converts the request to
an event (by
Event.getEvent(org.zkoss.zk.au.AuRequest)) and then posts the event (byEvents.postEvent(org.zkoss.zk.ui.event.Event)).
Notice that the registered AU request service (
AuService) will be called, no matter the request is targeting a component or a desktop. And, it can 'intercept' or 'filter' it by returning false.To send responses to the client, use
AbstractComponent.smartUpdate(java.lang.String, java.lang.Object),AbstractComponent.response(org.zkoss.zk.au.AuResponse)orComponent.invalidate().If you want to intercept events, you can register a listener implementing
EventInterceptor, or overridingDesktopCtrl.afterProcessEvent(org.zkoss.zk.ui.event.Event).- Specified by:
servicein interfaceDesktopCtrleverError- if any error ever occurred before processing this request. In other words, indicates if the previous request causes any exception.
- This method first invokes the registered AU request service
(
-
getVisualizer
public Visualizer getVisualizer()
Description copied from interface:DesktopCtrlReturns the visualizer associated with this desktop.Used only to implement
UiEngine.- Specified by:
getVisualizerin interfaceDesktopCtrl
-
setVisualizer
public void setVisualizer(Visualizer uv)
Description copied from interface:DesktopCtrlSets the visualizer associated with is desktop.Used only to implement
UiEngine.- Specified by:
setVisualizerin interfaceDesktopCtrl
-
getActivationLock
public java.lang.Object getActivationLock()
Description copied from interface:DesktopCtrlReturns the lock used to activate an execution. Before callingDesktopCtrl.setVisualizer(org.zkoss.zk.ui.sys.Visualizer), this object returned by this method must be locked first.Used only to implement
UiEngine.- Specified by:
getActivationLockin interfaceDesktopCtrl
-
getNextKey
public int getNextKey()
Description copied from interface:DesktopCtrlReturns the next available key which is unique in the whole desktop.- Specified by:
getNextKeyin interfaceDesktopCtrl
-
getNextUuid
public java.lang.String getNextUuid(Page page)
Description copied from interface:DesktopCtrlReturns 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 ifRawIdis 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.- Specified by:
getNextUuidin interfaceDesktopCtrl
-
getNextUuid
public java.lang.String getNextUuid(Component comp)
Description copied from interface:DesktopCtrlReturns 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 ifRawIdis 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.- Specified by:
getNextUuidin interfaceDesktopCtrl
-
addPage
public void addPage(Page page)
Description copied from interface:DesktopCtrlAdds 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.
- Specified by:
addPagein interfaceDesktopCtrl
-
removePage
public void removePage(Page page)
Description copied from interface:DesktopCtrlRemoves a page from this desktop.NOTE: once a page is removed, you can NOT add it back. You shall just GC it.
- Specified by:
removePagein interfaceDesktopCtrl
-
setId
public void setId(java.lang.String id)
Description copied from interface:DesktopCtrlSets the desktop identifier.It is callable only if it is the recovering phase, i.e.,
ExecutionCtrl.isRecovering()is true. In other words, callable only in the invocation ofFailoverManager.recover(org.zkoss.zk.ui.Session, org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Desktop).- Specified by:
setIdin interfaceDesktopCtrl
-
recoverDidFail
public void recoverDidFail(java.lang.Throwable ex)
Description copied from interface:DesktopCtrlCalled when the recovering failed.- Specified by:
recoverDidFailin interfaceDesktopCtrl
-
recycle
public void recycle()
Description copied from interface:DesktopCtrlCalled 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.- Specified by:
recyclein interfaceDesktopCtrl
-
isAlive
public boolean isAlive()
Description copied from interface:DesktopReturns whether the desktop is still alive. It returns false once it is destroyed.- Specified by:
isAlivein interfaceDesktop- See Also:
DesktopCtrl.destroy()
-
destroy
public void destroy()
Description copied from interface:DesktopCtrlCalled when the desktop is about to be destroyed.- Specified by:
destroyin interfaceDesktopCtrl
-
getSuspendedThreads
public java.util.Collection<EventProcessingThread> getSuspendedThreads()
Description copied from interface:DesktopCtrlReturns a collection of suspended event processing threads, or empty if no suspended thread at all.An event processing thread is an instance of
EventProcessingThreadNote: 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();) { //... } } }- Specified by:
getSuspendedThreadsin interfaceDesktopCtrl
-
ceaseSuspendedThread
public boolean ceaseSuspendedThread(EventProcessingThread evtthd, java.lang.String cause)
Description copied from interface:DesktopCtrlCeases the specified event thread.- Specified by:
ceaseSuspendedThreadin interfaceDesktopCtrlcause- 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.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
sessionWillPassivate
public void sessionWillPassivate(Session sess)
Description copied from interface:DesktopCtrlNotification that the session, which owns this desktop, is about to be passivated (a.k.a., serialized) by the Web container.- Specified by:
sessionWillPassivatein interfaceDesktopCtrl
-
sessionDidActivate
public void sessionDidActivate(Session sess)
Description copied from interface:DesktopCtrlNotification that the session, which owns this desktop, has just been activated (a.k.a., deserialized) by the Web container.- Specified by:
sessionDidActivatein interfaceDesktopCtrl
-
addListener
public void addListener(java.lang.Object listener)
Description copied from interface:DesktopAdds a listener.Note: if the listener is added twice, it will be invoked twice when a corresponding event occurs.
- Specified by:
addListenerin interfaceDesktop- Parameters:
listener- the listener. It cannot be null. It must be an instance that implementsDesktopCleanup,ExecutionInit,ExecutionCleanup,UiLifeCycle,EventInterceptorand/orAuService.
Note:DesktopInit,EventThreadInit,EventThreadCleanup,EventThreadSuspendandEventThreadResumeare not supported.
-
removeListener
public boolean removeListener(java.lang.Object listener)
Description copied from interface:DesktopRemoves a listener.- Specified by:
removeListenerin interfaceDesktop- Returns:
- whether the listener is removed successfully.
Object.equals(java.lang.Object)is used to check whether a listener is added.
-
beforeSendEvent
public Event beforeSendEvent(Event event)
Description copied from interface:DesktopCtrlInvokesEventInterceptor.beforeSendEvent(org.zkoss.zk.ui.event.Event)registered byDesktop.addListener(java.lang.Object).Note: it invokes
Configuration.beforeSendEvent(org.zkoss.zk.ui.event.Event)automatically.- Specified by:
beforeSendEventin interfaceDesktopCtrl
-
beforePostEvent
public Event beforePostEvent(Event event)
Description copied from interface:DesktopCtrlInvokesEventInterceptor.beforePostEvent(org.zkoss.zk.ui.event.Event)registered byDesktop.addListener(java.lang.Object).Note: it invokes
Configuration.beforePostEvent(org.zkoss.zk.ui.event.Event)automatically.- Specified by:
beforePostEventin interfaceDesktopCtrl
-
beforeProcessEvent
public Event beforeProcessEvent(Event event) throws java.lang.Exception
Description copied from interface:DesktopCtrlInvokesEventInterceptor.beforeProcessEvent(org.zkoss.zk.ui.event.Event)registered byDesktop.addListener(java.lang.Object).Note: it invokes
Configuration.beforeProcessEvent(org.zkoss.zk.ui.event.Event)automatically.- Specified by:
beforeProcessEventin interfaceDesktopCtrl- Throws:
java.lang.Exception
-
afterProcessEvent
public void afterProcessEvent(Event event) throws java.lang.Exception
Description copied from interface:DesktopCtrlInvokesEventInterceptor.afterProcessEvent(org.zkoss.zk.ui.event.Event)registered byDesktop.addListener(java.lang.Object).Note: it invokes
Configuration.afterProcessEvent(org.zkoss.zk.ui.event.Event)automatically.- Specified by:
afterProcessEventin interfaceDesktopCtrl- Throws:
java.lang.Exception
-
invokeDesktopCleanups
public void invokeDesktopCleanups()
Description copied from interface:DesktopCtrlInvokesDesktopCleanup.cleanup(org.zkoss.zk.ui.Desktop)for each relevant listener registered byDesktop.addListener(java.lang.Object).Used only internally.
It never throws an exception.
- Specified by:
invokeDesktopCleanupsin interfaceDesktopCtrl
-
invokeExecutionInits
public void invokeExecutionInits(Execution exec, Execution parent) throws UiException
Description copied from interface:DesktopCtrlInvokesExecutionInit.init(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Execution)for each relevant listener registered byDesktop.addListener(java.lang.Object).Used only internally.
- Specified by:
invokeExecutionInitsin interfaceDesktopCtrl- Parameters:
exec- the execution that is createdparent- the previous execution, or null if no previous at all- Throws:
UiException- to prevent an execution from being created
-
invokeExecutionCleanups
public void invokeExecutionCleanups(Execution exec, Execution parent, java.util.List<java.lang.Throwable> errs)
Description copied from interface:DesktopCtrlInvokesExecutionCleanup.cleanup(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Execution, java.util.List<java.lang.Throwable>)for each relevant listener registered byDesktop.addListener(java.lang.Object).Used only internally.
It never throws an exception but logs and adds it to the errs argument, if not null.
- Specified by:
invokeExecutionCleanupsin interfaceDesktopCtrl- Parameters:
exec- the execution that is being destroyedparent- the previous execution, or null if no previous at allerrs- 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.
-
afterComponentAttached
public void afterComponentAttached(Component comp, Page page)
Description copied from interface:DesktopCtrl- Specified by:
afterComponentAttachedin interfaceDesktopCtrl
-
afterComponentDetached
public void afterComponentDetached(Component comp, Page prevpage)
Description copied from interface:DesktopCtrl- Specified by:
afterComponentDetachedin interfaceDesktopCtrl
-
afterComponentMoved
public void afterComponentMoved(Component parent, Component child, Component prevparent)
Description copied from interface:DesktopCtrl- Specified by:
afterComponentMovedin interfaceDesktopCtrlprevparent- the previous parent. If it is the same as comp'sComponent.getParent(), comp is moved in the same parent.
-
enableServerPush
public boolean enableServerPush(boolean enable)
Description copied from interface:DesktopEnables or disables the server-push feature. Before using any server-push threads, you have to enable it for the particular desktop first by use of this method. Refer toExecutions.activate(org.zkoss.zk.ui.Desktop)for more details.Default: false
This method uses the default class (defined by
Device.getServerPushClass()) to instantiate the server-push controller.- Specified by:
enableServerPushin interfaceDesktop- Parameters:
enable- whether to enable or to disable the server-push feature.- See Also:
Executions.activate(org.zkoss.zk.ui.Desktop),Device.getServerPushClass(),DesktopCtrl.enableServerPush(org.zkoss.zk.ui.sys.ServerPush)
-
enableServerPush
public boolean enableServerPush(boolean enable, java.io.Serializable enabler)Description copied from interface:DesktopCtrlEnable/Disable serverpush using reference counting, so that multiple enablers can use the same serverpush and deregister whenever they want.- Specified by:
enableServerPushin interfaceDesktopCtrl- Parameters:
enable- true/false enable/disable serverpushenabler- the same reference must be used to disable again- Returns:
- Currently only used by
DesktopEventQueueto enable several eventqueues to use the sameServerPush
-
enableServerPush
public boolean enableServerPush(ServerPush serverpush)
Description copied from interface:DesktopCtrlEnables the server-push feature with the specified server-push controller. If you want to use the default serverpush, useDesktop.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.
- Specified by:
enableServerPushin interfaceDesktopCtrl- Parameters:
serverpush- the server-push controller. If null, the server-push feature is disabled (for this desktop). Note: this method will invokeServerPush.start(org.zkoss.zk.ui.Desktop), so the caller doesn't need to do it.- See Also:
Desktop.enableServerPush(boolean)
-
isServerPushEnabled
public boolean isServerPushEnabled()
Description copied from interface:DesktopReturns whether the server-push feature is enabled for this desktop.Default: false.
- Specified by:
isServerPushEnabledin interfaceDesktop
-
getServerPush
public ServerPush getServerPush()
Description copied from interface:DesktopCtrlReturns the server-push controller, or null if it is not enabled yet.- Specified by:
getServerPushin interfaceDesktopCtrl
-
scheduleServerPush
public <T extends Event> void scheduleServerPush(EventListener<T> listener, T event)
Description copied from interface:DesktopCtrlSchedules a task to run under the server push of the given desktop asynchronously. It is called byExecutions.schedule(org.zkoss.zk.ui.Desktop, org.zkoss.zk.ui.event.EventListener<T>, T). Don't call it directly.Like
DesktopCtrl.activateServerPush(long)andDesktopCtrl.deactivateServerPush(), this method could be called in any thread, so the implementation of this method has to be safe for concurrent access.- Specified by:
scheduleServerPushin interfaceDesktopCtrl- Parameters:
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.
-
scheduledServerPush
public boolean scheduledServerPush()
Description copied from interface:DesktopCtrlReturns if there is any scheduled task for server push.- Specified by:
scheduledServerPushin interfaceDesktopCtrl
-
activateServerPush
public boolean activateServerPush(long timeout) throws java.lang.InterruptedExceptionDescription copied from interface:DesktopCtrlActivates the current thread for accessing this desktop by the server push. It is called byExecutions.activate(org.zkoss.zk.ui.Desktop). Don't call it directly.Like
DesktopCtrl.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)).- Specified by:
activateServerPushin interfaceDesktopCtrl- Parameters:
timeout- the maximum time to wait in milliseconds. Ignored (i.e., never timeout) if non-positive.- Throws:
java.lang.InterruptedException
-
deactivateServerPush
public void deactivateServerPush()
Description copied from interface:DesktopCtrlDeactivates the thread that has invokedDesktopCtrl.activateServerPush(long)successfully. It is called byExecutions.deactivate(org.zkoss.zk.ui.Desktop). Don't call it directly.- Specified by:
deactivateServerPushin interfaceDesktopCtrl
-
onPiggybackListened
public void onPiggybackListened(Component comp, boolean listen)
Description copied from interface:DesktopCtrlCalled when a component added or removed a listener forEvents.ON_PIGGYBACK.The implementation usually uses it to optimize whether to call the listener when
DesktopCtrl.onPiggyback()is called.- Specified by:
onPiggybackListenedin interfaceDesktopCtrl- Parameters:
comp- the component that adds an listener forEvents.ON_PIGGYBACK. The component may or may not be a root component.listen- whether the listener is added (or removed).
-
onPiggyback
public void onPiggyback()
Description copied from interface:DesktopCtrlCalled each time when ZK Update Engine retrieves events. It is used to implement the piggyback feature by posting the events (seeEvents.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.
- Specified by:
onPiggybackin interfaceDesktopCtrl
-
responseSent
public void responseSent(java.lang.String reqId, java.lang.Object response)Description copied from interface:DesktopCtrlCalled when ZK Update Engine has sent a response to the client.- Specified by:
responseSentin interfaceDesktopCtrl- Parameters:
reqId- the request ID that the response is generated for. Ignore if null.response- the response. Ignored if reqId is null.
-
getLastResponse
public java.lang.Object getLastResponse(java.lang.String reqId)
Description copied from interface:DesktopCtrlReturns the response for the last request, or null if no response yet, or the specified request ID doesn't match the last one (passed toDesktopCtrl.responseSent(java.lang.String, java.lang.Object)).The return value is the value passed to resInfo when calling
DesktopCtrl.responseSent(java.lang.String, java.lang.Object).- Specified by:
getLastResponsein interfaceDesktopCtrl
-
getResponseId
public int getResponseId(boolean advance)
Description copied from interface:DesktopCtrlReturns 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.
- Specified by:
getResponseIdin interfaceDesktopCtrl- 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
-
setResponseId
public void setResponseId(int resId)
Description copied from interface:DesktopCtrlSets the sequence ID of the response.It is rarely called other than in the recovering mode, i.e.,
ExecutionCtrl.isRecovering()is true.- Specified by:
setResponseIdin interfaceDesktopCtrl- Parameters:
resId- a value between 1 and 999. You can reset the ID by passing a non-positive value.
-
piggyResponse
public java.util.List<AuResponse> piggyResponse(java.util.Collection<AuResponse> response, boolean reset)
Description copied from interface:DesktopCtrlAdds 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.
- Specified by:
piggyResponsein interfaceDesktopCtrl- 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.
-
invalidate
public void invalidate()
Description copied from interface:DesktopInvalidates the desktop. All pages will be redrawn.- Specified by:
invalidatein interfaceDesktop
-
getStorage
public Storage getStorage()
Description copied from interface:DesktopReturns the storage in a desktop scope.- Specified by:
getStoragein interfaceDesktop- Returns:
- a storage implementation, never null.
-
pushHistoryState
public void pushHistoryState(java.lang.Object state, java.lang.String title, java.lang.String url)Description copied from interface:DesktopPushes a new history state.- Specified by:
pushHistoryStatein interfaceDesktop- Parameters:
state- a state object.title- a title for the state. May be ignored by some browsers.url- the history entry's URL. Could be null.
-
replaceHistoryState
public void replaceHistoryState(java.lang.Object state, java.lang.String title, java.lang.String url)Description copied from interface:DesktopReplaces the current history state.- Specified by:
replaceHistoryStatein interfaceDesktop- Parameters:
state- a state object.title- a title for the state. May be ignored by some browsers.url- the history entry's URL. Could be null.
-
-