|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.zkoss.zk.ui.impl.DesktopImpl
public class DesktopImpl
The implementation of Desktop.
Note: though DesktopImpl is serializable, it is designed
to work with Web container to enable the serialization of sessions.
It is not suggested to serialize and desrialize it directly since
many fields might be lost.
On the other hand, it is OK to serialize and deserialize
Component.
| Constructor Summary | |
|---|---|
DesktopImpl(WebApp wapp,
java.lang.String updateURI,
java.lang.String path,
java.lang.String deviceType)
|
|
| Method Summary | |
|---|---|
void |
addComponent(Component comp)
Adds a component to this page. |
void |
addEventInterceptor(EventInterceptor ei)
Adds an event interceptor to this desktop. |
void |
addPage(Page page)
Adds a page to this desktop. |
void |
afterProcessEvent(Event event)
Invokes EventInterceptor.afterProcessEvent(org.zkoss.zk.ui.event.Event)
registered by Desktop.addEventInterceptor(org.zkoss.zk.ui.util.EventInterceptor). |
Event |
beforePostEvent(Event event)
Invokes EventInterceptor.beforePostEvent(org.zkoss.zk.ui.event.Event)
registered by Desktop.addEventInterceptor(org.zkoss.zk.ui.util.EventInterceptor). |
Event |
beforeProcessEvent(Event event)
Invokes EventInterceptor.beforeProcessEvent(org.zkoss.zk.ui.event.Event)
registered by Desktop.addEventInterceptor(org.zkoss.zk.ui.util.EventInterceptor). |
Event |
beforeSendEvent(Event event)
Invokes EventInterceptor.beforeSendEvent(org.zkoss.zk.ui.event.Event)
registered by Desktop.addEventInterceptor(org.zkoss.zk.ui.util.EventInterceptor). |
boolean |
ceaseSuspendedThread(EventProcessingThread evtthd,
java.lang.String cause)
Ceases the specified event thread. |
void |
destroy()
Called when the desktop is about to be destroyed. |
boolean |
enableServerPush(boolean enable)
Enables or disables the server-push feature. |
boolean |
enableServerPush(ServerPush serverpush)
Enables the server-push feature with the specified server-push controller. |
java.lang.Object |
getAttribute(java.lang.String name)
Returns the value of the specified custom attribute associated with the desktop. |
java.util.Map |
getAttributes()
Returns all custom attributes associated with this desktop. |
java.lang.String |
getBookmark()
Returns the current bookmark (never null). |
Component |
getComponentByUuid(java.lang.String uuid)
Returns the component of the specified UUID ( Component.getUuid()). |
Component |
getComponentByUuidIfAny(java.lang.String uuid)
Returns the component of the specified UUID ( Component.getUuid()), or null if not found. |
java.util.Collection |
getComponents()
Returns all components contained in this desktop. |
java.lang.String |
getCurrentDirectory()
Returns the current directory (never null). |
Device |
getDevice()
Returns the device that is associated with this desktop. |
java.lang.String |
getDeviceType()
Returns the device type that this desktop belongs to. |
org.zkoss.util.media.Media |
getDownloadMedia(java.lang.String medId,
boolean remove)
Returns the media that is associated with Desktop.getDownloadMediaURI(org.zkoss.util.media.Media, java.lang.String), or
null if not found. |
java.lang.String |
getDownloadMediaURI(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.String |
getDynamicMediaURI(Component comp,
java.lang.String pathInfo)
Returns URI for a dynamic generated media associated with a component. |
Execution |
getExecution()
Returns the execution, or null if this desktop is not under seving any execution (aka., not locked). |
java.lang.String |
getId()
Returns ID of this desktop. |
int |
getNextKey()
Returns the next available key which is unique in the whole desktop. |
java.lang.String |
getNextUuid()
Returns the next available UUID for a component. |
Page |
getPage(java.lang.String pageId)
Returns the page of the specified ID. |
Page |
getPageIfAny(java.lang.String pageId)
Returns the page of the specified ID, or null if no such page. |
java.util.Collection |
getPages()
Returns a readonly collection of all Page in this desktop. |
java.lang.String |
getRequestPath()
Returns the path of the request that causes this desktop to be created, or "" if not available. |
RequestQueue |
getRequestQueue()
Returns the request queue. |
int |
getResponseSequence(boolean advance)
Returns the sequence ID of the response. |
ServerPush |
getServerPush()
Returns the server-push controller, or null if it is not enabled yet. |
Session |
getSession()
Returns the session of this desktop. |
java.util.Collection |
getSuspendedThreads()
Returns a collection of suspended event processing threads, or empty if no suspended thread at all. |
java.lang.String |
getUpdateURI(java.lang.String pathInfo)
Returns the URI for asynchronous update. |
WebApp |
getWebApp()
Returns the Web application this desktop belongs to. |
boolean |
hasPage(java.lang.String pageId)
Returns whether a page exists. |
boolean |
isAlive()
Returns whether the desktop is still alive. |
boolean |
isServerPushEnabled()
Returns whether the server-push feature is enabled for this desktop. |
protected RequestQueue |
newRequestQueue()
Creates the request queue. |
void |
onPiggyback()
Called each time ZK Update Engine processes all events. |
void |
onPiggybackListened(Component comp,
boolean listen)
Called when a component added or removed a listener for Events.ON_PIGGYBACK. |
void |
recoverDidFail(java.lang.Throwable ex)
Called when the recoving failed. |
java.lang.Object |
removeAttribute(java.lang.String name)
Removes the specified custom attribute associated with the desktop. |
void |
removeComponent(Component comp)
Removes a component to this page. |
boolean |
removeEventInterceptor(EventInterceptor ei)
Removes an event interceptor from this desktop. |
void |
removePage(Page page)
Removes a page from this desktop. |
void |
sessionDidActivate(Session sess)
Notification that the session, which owns this desktop, has just been activated (aka., deserialized) by the Web container. |
void |
sessionWillPassivate(Session sess)
Notification that the session, which owns this desktop, is about to be passivated (aka., serialized) by the Web container. |
java.lang.Object |
setAttribute(java.lang.String name,
java.lang.Object value)
Sets the value of the specified custom attribute associated with the desktop. |
void |
setBookmark(java.lang.String name)
Sets a bookmark to this desktop. |
void |
setBookmarkByClient(java.lang.String name)
Sets the bookmark when receiving the onBookmarkChanged command from the client. |
void |
setCurrentDirectory(java.lang.String dir)
Sets the current directory. |
void |
setDeviceType(java.lang.String deviceType)
Sets the device type that this desktop belongs to. |
void |
setExecution(Execution exec)
Sets the execution (used to represent a lock). |
void |
setId(java.lang.String id)
Sets the desktop identifier. |
void |
setResponseSequence(int seqId)
Sets the sequence ID of the response. |
void |
setServerPushDelay(int min,
int max,
int factor)
Sets the delay between each polling. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DesktopImpl(WebApp wapp,
java.lang.String updateURI,
java.lang.String path,
java.lang.String deviceType)
updateURI - 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.| Method Detail |
|---|
public java.lang.String getId()
Desktop
getId in interface Desktopprotected RequestQueue newRequestQueue()
You may override it to provide your implementation of
RequestQueue to control how to optimize the AU requests.
Default: creates an instance from RequestQueueImpl;
public java.lang.String getDeviceType()
DesktopA 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 Richlet is used, its language definition's device type is
assumed.
getDeviceType in interface Desktoppublic Device getDevice()
DesktopNote: the device is shared by all desktops of the same device type.
getDevice in interface Desktoppublic void setDeviceType(java.lang.String deviceType)
DesktopNote: 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 to Desktop.getDevice().
setDeviceType in interface Desktoppublic Execution getExecution()
Desktop
getExecution in interface Desktoppublic final Session getSession()
Desktop
getSession in interface Desktoppublic java.lang.String getUpdateURI(java.lang.String pathInfo)
DesktopYou rarely need this method unless for implementing special components, such as file upload.
getUpdateURI in interface DesktoppathInfo - the path to append to the returned URI, or null
to ignore
public java.lang.String getDynamicMediaURI(Component comp,
java.lang.String pathInfo)
DesktopDynamicMedia.getMedia(java.lang.String) to response.
Note: to use with this method, DynamicMedia
must be implemented as part of the object returned by
ComponentCtrl.getExtraCtrl().
Used mainly for component implementation.
getDynamicMediaURI in interface Desktop
public java.lang.String getDownloadMediaURI(org.zkoss.util.media.Media media,
java.lang.String pathInfo)
DesktopNote: once called, the media belongs to desktop and it is purged automatically. Thus, don't access it again after calling this method.
getDownloadMediaURI in interface Desktop
public org.zkoss.util.media.Media getDownloadMedia(java.lang.String medId,
boolean remove)
DesktopCtrlDesktop.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.
getDownloadMedia in interface DesktopCtrlremove - whether to remove it from cache once returned.
public Page getPage(java.lang.String pageId)
DesktopThis is one of the only few method you could access before activating an execution.
getPage in interface Desktoppublic Page getPageIfAny(java.lang.String pageId)
Desktop
getPageIfAny in interface Desktoppublic boolean hasPage(java.lang.String pageId)
Desktop
hasPage in interface Desktoppublic java.util.Collection getPages()
DesktopPage in this desktop.
getPages in interface Desktoppublic java.lang.String getBookmark()
DesktopDesktop.setBookmark(java.lang.String),
because user might use BACK, FORWARD or others to change the bookmark.
getBookmark in interface Desktoppublic void setBookmark(java.lang.String name)
Desktop
setBookmark in interface Desktoppublic java.util.Collection getComponents()
Desktop
getComponents in interface Desktoppublic Component getComponentByUuid(java.lang.String uuid)
DesktopComponent.getUuid()).
getComponentByUuid in interface Desktoppublic Component getComponentByUuidIfAny(java.lang.String uuid)
DesktopComponent.getUuid()), or null if not found.
getComponentByUuidIfAny in interface Desktoppublic void addComponent(Component comp)
DesktopCtrlIt is used internally and developers shall not invoke it explicityly.
addComponent in interface DesktopCtrlpublic void removeComponent(Component comp)
DesktopCtrlIt is used internally and developers shall not invoke it explicityly.
removeComponent in interface DesktopCtrlpublic java.util.Map getAttributes()
Desktop
getAttributes in interface Desktoppublic java.lang.Object getAttribute(java.lang.String name)
Desktop
getAttribute in interface Desktop
public java.lang.Object setAttribute(java.lang.String name,
java.lang.Object value)
Desktop
setAttribute in interface Desktoppublic java.lang.Object removeAttribute(java.lang.String name)
Desktop
removeAttribute in interface Desktoppublic WebApp getWebApp()
Desktop
getWebApp in interface Desktoppublic java.lang.String getRequestPath()
DesktopPage.getRequestPath()).
For example, "/userguide/index.zul" (a ZUML page is requested) or /test (a richlet).
getRequestPath in interface DesktopPage.getRequestPath()public java.lang.String getCurrentDirectory()
Desktop
getCurrentDirectory in interface Desktoppublic void setCurrentDirectory(java.lang.String dir)
Desktop
setCurrentDirectory in interface Desktopdir - the current directory. If null, an empty string is assumed
(means no current directory at all).public boolean isAlive()
Desktop
isAlive in interface DesktopDesktopCtrl.destroy()public RequestQueue getRequestQueue()
DesktopCtrl
getRequestQueue in interface DesktopCtrlpublic void setExecution(Execution exec)
DesktopCtrl
setExecution in interface DesktopCtrlpublic int getNextKey()
DesktopCtrl
getNextKey in interface DesktopCtrlpublic java.lang.String getNextUuid()
DesktopCtrlRawId is used
(developer's responsibility to avoid conflict),
or integer overflow (too many UUID in one session, which
can be considered as impossible).
getNextUuid in interface DesktopCtrlpublic void addPage(Page page)
DesktopCtrlThis is one of the only few method you could access before activating an execution.
addPage in interface DesktopCtrlpublic void removePage(Page page)
DesktopCtrlNOTE: once a page is removed, you can NOT add it back. You shall just GC it.
removePage in interface DesktopCtrlpublic void setBookmarkByClient(java.lang.String name)
DesktopCtrl
setBookmarkByClient in interface DesktopCtrlpublic void setId(java.lang.String id)
DesktopCtrlIt is callable only if it is the recovering phase, i.e.,
ExecutionCtrl.isRecovering() is true.
In other words, callable only in the invocation of
FailoverManager.recover(org.zkoss.zk.ui.Session, org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Desktop).
setId in interface DesktopCtrlpublic void recoverDidFail(java.lang.Throwable ex)
DesktopCtrl
recoverDidFail in interface DesktopCtrlpublic int getResponseSequence(boolean advance)
DesktopCtrlThe range of the sequence IDs is 0~1023.
getResponseSequence in interface DesktopCtrladvance - whether to advance the number before returning.
If true, the ID is increased and then returned.
If false, the previous value is returnedpublic void setResponseSequence(int seqId)
DesktopCtrlIt is rarely called other than in the recovering mode, i.e.,
ExecutionCtrl.isRecovering() is true.
setResponseSequence in interface DesktopCtrlseqId - a value between 0 and 1023.
Since ZK 2.4.1, you can reset the sequence by passing a negative
value to this argument.public void destroy()
DesktopCtrl
destroy in interface DesktopCtrlpublic java.util.Collection getSuspendedThreads()
DesktopCtrlAn 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 pathern 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();) {
//...
}
}
}
getSuspendedThreads in interface DesktopCtrl
public boolean ceaseSuspendedThread(EventProcessingThread evtthd,
java.lang.String cause)
DesktopCtrl
ceaseSuspendedThread in interface DesktopCtrlcause - an arbitrary text to describe the cause.
It will be the message of the thrown InterruptedException.
public java.lang.String toString()
toString in class java.lang.Objectpublic void sessionWillPassivate(Session sess)
DesktopCtrl
sessionWillPassivate in interface DesktopCtrlpublic void sessionDidActivate(Session sess)
DesktopCtrl
sessionDidActivate in interface DesktopCtrlpublic void addEventInterceptor(EventInterceptor ei)
Desktop
addEventInterceptor in interface Desktoppublic boolean removeEventInterceptor(EventInterceptor ei)
Desktop
removeEventInterceptor in interface Desktoppublic Event beforeSendEvent(Event event)
DesktopCtrlEventInterceptor.beforeSendEvent(org.zkoss.zk.ui.event.Event)
registered by Desktop.addEventInterceptor(org.zkoss.zk.ui.util.EventInterceptor).
Note: it invokes
Configuration.beforeSendEvent(org.zkoss.zk.ui.event.Event)
automatically.
beforeSendEvent in interface DesktopCtrlpublic Event beforePostEvent(Event event)
DesktopCtrlEventInterceptor.beforePostEvent(org.zkoss.zk.ui.event.Event)
registered by Desktop.addEventInterceptor(org.zkoss.zk.ui.util.EventInterceptor).
Note: it invokes
Configuration.beforePostEvent(org.zkoss.zk.ui.event.Event)
automatically.
beforePostEvent in interface DesktopCtrlpublic Event beforeProcessEvent(Event event)
DesktopCtrlEventInterceptor.beforeProcessEvent(org.zkoss.zk.ui.event.Event)
registered by Desktop.addEventInterceptor(org.zkoss.zk.ui.util.EventInterceptor).
Note: it invokes
Configuration.beforeProcessEvent(org.zkoss.zk.ui.event.Event)
automatically.
beforeProcessEvent in interface DesktopCtrlpublic void afterProcessEvent(Event event)
DesktopCtrlEventInterceptor.afterProcessEvent(org.zkoss.zk.ui.event.Event)
registered by Desktop.addEventInterceptor(org.zkoss.zk.ui.util.EventInterceptor).
Note: it invokes
Configuration.afterProcessEvent(org.zkoss.zk.ui.event.Event)
automatically.
afterProcessEvent in interface DesktopCtrlpublic boolean enableServerPush(boolean enable)
DesktopExecutions.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.
enableServerPush in interface Desktopenable - whether to enable or to disable the server-push
feature.Executions.activate(org.zkoss.zk.ui.Desktop),
Device.getServerPushClass()public boolean enableServerPush(ServerPush serverpush)
DesktopCtrl
enableServerPush in interface DesktopCtrlserverpush - 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.Desktop.enableServerPush(boolean)public boolean isServerPushEnabled()
DesktopDefault: false.
isServerPushEnabled in interface Desktoppublic ServerPush getServerPush()
DesktopCtrl
getServerPush in interface DesktopCtrl
public void setServerPushDelay(int min,
int max,
int factor)
DesktopDesktop.enableServerPush(boolean)).
Note: not all server-push controllers support this method. Currently, only on the client-polling-based controller (the default) supports this method.
To make the system more scalable, the implementation usually change the delay dynamically based on the loading. By specifying the minimal and maximal values, you can control the frequence to poll the server depending on the character of your Web applications.
Default: It looks up the value defined in the preferences
(Configuration.getPreference(java.lang.String, java.lang.String)):
PollingServerPush.delay.min
PollingServerPush.delay.max,
and PollingServerPush.delay.factor.
If not defined, min is 1100, max is 10000 and factor is 5.
setServerPushDelay in interface Desktopmin - the minimal delay to poll the server for any pending
server-push threads.
Ignore (aka., the default value is used) if non-positive.
Unit: milliseconds.max - the maximal delay to poll the server for any pending
server-push threads.
Ignore (aka., the default value is used) if non-positive.
Unit: milliseconds.factor - the delay factor. The real delay is the processing
time multiplies the delay factor. For example, if the last request
took 1 second to process, then the client polling will be delayed
for 1 x factor seconds, unless it is value
Ignore (aka., the default value is used) if non-positive.
public void onPiggybackListened(Component comp,
boolean listen)
DesktopCtrlEvents.ON_PIGGYBACK.
The implementation usualy uses it to optimize whether to
call the listener when DesktopCtrl.onPiggyback() is called.
onPiggybackListened in interface DesktopCtrlcomp - 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).public void onPiggyback()
DesktopCtrlEvents.ON_PIGGYBACK).
Used only internally. Application develepers shall not call it.
onPiggyback in interface DesktopCtrl
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||