Revision history [back]

click to hide/show revision 1
initial version

asked 2013-01-22 16:46:26 +0800

carpolva gravatar image carpolva

ZK Clustering, Session Replication Question

Hi !!

I'm working on a very basic zk example deploying it in a clustered architecture with 3 Tomcat nodes. I will omit all the Apache Web Server and Tomcat cluster configuration.

In my web.xml I have the following tag in order to activate session exchange:

<distributable/>

In my zk.xml I have the following (more details about ZK Clustering in ZK Tomcat Clustering Part II):

<system-config>
    <ui-factory-class>org.zkoss.zk.ui.http.SerializableUiFactory</ui-factory-class>
</system-config>

Here is part of my .zul page:

<label id="myLabel" value="0"/>
<button label="Generate Value" forward="onClick=onClickGenerate()"/>
<button label="Read Value" forward="onClick=onClickRead()"/>

This is the associated java bean:

public class MyBean extends GenericForwardComposer implements Serializable {
       private Label myLabel;

       public void doAfterCompose(Component comp) {
              try {
                  super.doAfterCompose(comp);
              } catch (Exception e) {e.printStackTrace();}
       }

       public void onClickGenerate(ForwardEvent event){
              System.out.println("onClickGenerate invoked");
              myLabel.setValue("XXXXXXX");
       }

       public void onClickRead(ForwardEvent event){
              System.out.println("Label value: " + myLabel.getValue());
       }
}

I deploy the .war file in each Tomcat node, I start the Apache Web Server and each Tomcat node.

The following is a test case:

When page loads, the label default value is "0". Then I press the "Generate Value" button, so the "onClickGenerate" method is invoked in the java bean and the label value is updated to "XXXXXXX". Looking at the Tomcat console I can see that Tomcat Node 1 processed this request because the output "onClickGenerate invoked" appeared in this node's console right?.

Next step, I press the "Read Value" button... if the same Tomcat node processes this new request, the output will be the following: "Label value: XXXXXXX".

BUT... if a different Tomcat node processes this new request, the output will be the following: "Label value: 0".

What does it mean?, that only in the first Tomcat node which processed the "onClickGenerate" the label's value was updated, but this label's value was not replicated with its updated value to the other Tomcat nodes, so... if a different Tomcat processes a new request in order to read the label's value, that value is not updated and remains with its default value. I want to know what should I do in order to give each Tomcat node the ability to know session data no matter which Tomcat processes the request, if Tomcat 1 updated the label's value the other Tomcat nodes must know this updated value too, is this possible right?.

I hope I made me understand. it's a simple zk clustering case but I'm still learning.

Any help will be appreciated, thank you very much!!

Best regards.

ZK Clustering, Session Replication Question

Hi !!

I'm working on a very basic zk example deploying it in a clustered architecture with 3 Tomcat nodes. I will omit all the Apache Web Server and Tomcat cluster configuration.

In my web.xml I have the following tag in order to activate session exchange:

<distributable/>

In my zk.xml I have the following (more details about ZK Clustering in ZK Tomcat Clustering Part II):

<system-config>
    <ui-factory-class>org.zkoss.zk.ui.http.SerializableUiFactory</ui-factory-class>
</system-config>

Here is part of my .zul page:

<label id="myLabel" value="0"/>
<button label="Generate Value" forward="onClick=onClickGenerate()"/>
<button label="Read Value" forward="onClick=onClickRead()"/>

This is the associated java bean:

public class MyBean extends GenericForwardComposer implements Serializable {
       private Label myLabel;

       public void doAfterCompose(Component comp) {
              try {
                  super.doAfterCompose(comp);
              } catch (Exception e) {e.printStackTrace();}
       }

       public void onClickGenerate(ForwardEvent event){
              System.out.println("onClickGenerate invoked");
              myLabel.setValue("XXXXXXX");
       }

       public void onClickRead(ForwardEvent event){
              System.out.println("Label value: " + myLabel.getValue());
       }
}

I deploy the .war file in each Tomcat node, I start the Apache Web Server and each Tomcat node.

The following is a test case:

When page loads, the label default value is "0". Then I press the "Generate Value" button, so the "onClickGenerate" method is invoked in the java bean and the label value is updated to "XXXXXXX". Looking at the Tomcat console I can see that Tomcat Node 1 processed this request because the output "onClickGenerate invoked" appeared in this node's console right?.

Next step, I press the "Read Value" button... if the same Tomcat node processes this new request, the output will be the following: "Label value: XXXXXXX".

BUT... if a different Tomcat node processes this new request, the output will be the following: "Label value: 0".

What does it mean?, that only in the first Tomcat node which processed the "onClickGenerate" the label's value was updated, but this label's value was not replicated with its updated value to the other Tomcat nodes, so... if a different Tomcat processes a new request in order to read the label's value, that value is not updated and remains with its default value. I want to know what should I do in order to give each Tomcat node the ability to know session data no matter which Tomcat processes the request, if Tomcat 1 updated the label's value the other Tomcat nodes must know this updated value too, is this possible right?.

I hope I made me understand. it's a simple zk clustering case but I'm still learning.

Any help will be appreciated, thank you very much!!

Best regards.

ZK Clustering, Session Replication Question

Hi !!

I'm working on a very basic zk example deploying it in a clustered architecture with 3 Tomcat nodes. I will omit all the Apache Web Server and Tomcat cluster configuration.

In my web.xml I have the following tag in order to activate session exchange:

<distributable/>

In my zk.xml I have the following (more details about ZK Clustering in ZK Tomcat Clustering Part II):

<system-config>
    <ui-factory-class>org.zkoss.zk.ui.http.SerializableUiFactory</ui-factory-class>
</system-config>

Here is part of my .zul page:

<label id="myLabel" value="0"/>
<button label="Generate Value" forward="onClick=onClickGenerate()"/>
<button label="Read Value" forward="onClick=onClickRead()"/>

This is the associated java bean:

public class MyBean extends GenericForwardComposer implements Serializable {
       private Label myLabel;

       public void doAfterCompose(Component comp) {
              try {
                  super.doAfterCompose(comp);
              } catch (Exception e) {e.printStackTrace();}
       }

       public void onClickGenerate(ForwardEvent event){
              System.out.println("onClickGenerate invoked");
              myLabel.setValue("XXXXXXX");
       }

       public void onClickRead(ForwardEvent event){
              System.out.println("Label value: " + myLabel.getValue());
       }
}

I deploy the .war file in each Tomcat node, I start the Apache Web Server and each Tomcat node.

The following is a test case:

When page loads, the label default value is "0". Then I press the "Generate Value" button, so the "onClickGenerate" method is invoked in the java bean and the label value is updated to "XXXXXXX". Looking at the Tomcat console I can see that Tomcat Node 1 processed this request because the output "onClickGenerate invoked" appeared in this node's console right?.

Next step, I press the "Read Value" button... if the same Tomcat node processes this new request, the output will be the following: "Label value: XXXXXXX".

BUT... if a different Tomcat node processes this new request, the output will be the following: "Label value: 0".

What does it mean?, that only in the first Tomcat node which processed the "onClickGenerate" the label's value was updated, but this label's value was not replicated with its updated value to the other Tomcat nodes, so... if a different Tomcat processes a new request in order to read the label's value, that value is not updated and remains with its default value. I want to know what should I do in order to give each Tomcat node the ability to know session data no matter which Tomcat processes the request, if Tomcat 1 updated the label's value the other Tomcat nodes must know this updated value too, is this possible right?.

I hope I made me understand. it's a simple zk clustering case but I'm still learning.

Any help will be appreciated, thank you very much!!

Best regards.

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More