Programming Tips"

From Documentation
Line 41: Line 41:
 
If there are non-serializable objects, you could implement one of clustering listeners to handle them manually as described below. Basically, there are two kinds of clustering listeners for different purpose:
 
If there are non-serializable objects, you could implement one of clustering listeners to handle them manually as described below. Basically, there are two kinds of clustering listeners for different purpose:
  
*Serialization Listeners: they are called when an object is about to be serialized, and after it has been de-serialized.
+
*Serialization Listeners: they are called when an object is about to be serialized, and after it has been de-serialized. Example: <javadoc type="interface">org.zkoss.zk.ui.util.ComponentSerializationListener</javadoc> and <javadoc type="interface">org.zkoss.zk.ui.util.PageSerializationListener</javadoc>
*Activation Listeners: they are called when a session is about to be passivated, and after it has been activated.
+
*Activation Listeners: they are called when a session is about to be passivated, and after it has been activated. Examples:  <javadoc type="interface">org.zkoss.zk.ui.util.ComponentActivationListener</javadoc> and <javadoc type="interface">org.zkoss.zk.ui.util.PageActivationListener</javadoc>.
  
 
When a session is about to be passivated (such as moving to anther machine), the activation listeners will be called first to notify the passivation, and then the serialization listeners will be called before the object is serialized.
 
When a session is about to be passivated (such as moving to anther machine), the activation listeners will be called first to notify the passivation, and then the serialization listeners will be called before the object is serialized.
Line 50: Line 50:
  
 
To register a listener is straightforward: implements the corresponding listener interface, such as <javadoc type="interface">org.zkoss.zk.ui.util.ComponentActivationListener</javadoc> and <javadoc type="interface">org.zkoss.zk.ui.util.ComponentSerializationListener</javadoc>.
 
To register a listener is straightforward: implements the corresponding listener interface, such as <javadoc type="interface">org.zkoss.zk.ui.util.ComponentActivationListener</javadoc> and <javadoc type="interface">org.zkoss.zk.ui.util.ComponentSerializationListener</javadoc>.
 
==Activation Listener for Non-Serializable Objects==
 
==Serialization Listeners for Customizing Serialization==
 
  
 
=Working Thread Cannot Last Two or More Requests=
 
=Working Thread Cannot Last Two or More Requests=

Revision as of 06:03, 18 November 2010


Programming Tips


Objects Referenced by UI Must Serializable

Objects that are referenced by an UI object, such as component and page, have to be serializable. Otherwise, they might have no value after de-serialized, or causes an exception (depending how it is used).

Attributes of UI Objects

If the value of an attribute is not serializable, it will be ignored. Thus, it will become null after de-serialized. Thus, it is better to make them all serializable (such as implementing java.io.Serializable), or handle the serialization manually (refer to the Clustering Listeners section below) .

zscript

It is OK, though not recommended, to use zscript in a clustering environment, but there are some limitations.

  • BeanShell's function is not serializable. For example, the following won't work:
void foo() {
}
  • The values of variables must be serializable

Notice that it is not recommended to use zscript in the clustering environment. After all, the performance of BeanShell is not good.

Event Listeners

Event listeners have to be serializable. Otherwise, it will be ignored after serialization.

Data Models

The data model, such as ListModel and ChartModel, have to be serializable. Otherwise, the UI object (such as grid) won't behave correctly. The implementations provided by ZK are serializable. However, the items to be stored in the data models have to be serializable too.

Composers

If you extend from GenericForwardComposer or GenericAutowireComposer, you have to make sure all of its members are serializable (or transient), since the implementation will keep a reference in the applied component.

If you implement from Composer directly, the composer could be non-serializable if you don't keep a reference in any UI object. In other words, the composer will be dropped after Composer.doAfterCompose(Component)

Clustering Listeners

If there are non-serializable objects, you could implement one of clustering listeners to handle them manually as described below. Basically, there are two kinds of clustering listeners for different purpose:

When a session is about to be passivated (such as moving to anther machine), the activation listeners will be called first to notify the passivation, and then the serialization listeners will be called before the object is serialized.


When a session is about to be activated (such as moved from another machine), the serialization listener is called after the object has been deserialized. After all objects are deserialized, the activation listener will be called to notify a session has been activated.

To register a listener is straightforward: implements the corresponding listener interface, such as ComponentActivationListener and ComponentSerializationListener.

Working Thread Cannot Last Two or More Requests

Version History

Last Update : 2010/11/18


Version Date Content
     



Last Update : 2010/11/18

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.