|
Java EE 6 SDK |
The cluster JSP sample application demonstrates how a request to a JSP is shared in all of server instances in a GlassFish cluster.
This version of Java EE 6 SDK only includes a pre-built clusterjsp application and does not provide the mechanism to build it. The application ear file, clusterjsp.ear is bundled and available under install_dir/samples/javaee6/ha/clusterjsp.
install_dir is
the the directory by name “glassfish” that is created under the
path chosen during installation.
NOTE: The instructions here only apply to creating local instances on a single machine.
Follow this procedure to setup the necessary environment and deploy clusterjsp:
For this exercise you may use the domain created by installer. If you have elected not to create the domain during installation, then create your own domain by running 'asadmin create-domain' command.
Verify that the domain is running by using the command 'asadmin list-domains'. Start the domain by running 'asadmin start-domain' command if it has not been already started.
Verify if “multicast” is enabled on your network by running 'asadmin validate-multicast' command on two terminal windows. The output should show messages being sent and received between the two terminals and ensure that basic multicast support exists on your network.
Create the cluster by running command 'asadmin create-cluster'.
Create local instances and add them to the newly created cluster by running command 'asadmin create-local-instance' with '--cluster <clustername>' option. For this exercise at the least two instances are needed, so you will be running this command at the least two times. Scan the output of this command and note down the value of HTTP_LISTENER_PORT for each run. You will be using this port to connect to the instance and launch the clusterjsp application later.
Start the cluster by running 'asadmin start-cluster'. This also starts the instances that are part of the cluster. To verify run 'asadmin list-instances'.
Now deploy the clusterjsp to the cluster by running 'asadmin deploy –availabilityenabled=true –target <clustername> <application path>/clusterjsp.ear'.
Run the application, as described below.
An example sequence of setup commands including the output to create the cluster 'cluster1' (in a pre-existing domain by name 'domain1') with two instances 'instance1' and 'instance2' and deploys the application.
The objective of this run is to demonstrate clustering and replication of session information across instances in a cluster. We achieve this by doing the following
Access the clusterjsp application through instance1 by launching a web browser and entering the URL http://<hostname>:<Instance1HTTPPort>/clusterjsp
Add session data by entering the session attribute name and value and clicking 'ADD SESSION DATA' button in the web page.
Stop instance1 by running 'asadmin stop-instance instance1' command from command line.
Access the clusterjsp application through instance2 by entering the URL http://<hostname>:<Instance1HTTPPort>/clusterjsp on the same browser window opened in step 1.
Verify that the session data generated from the application accessed through instance1 is automatically persisted and is visible when the application is accessed through instance2 of the cluster. You will be able to see the session attribute name and values persisted from instance1.
Please see the image below for a sample output of running steps 1 and 2 from above.

Please see the image below for a sample output of running steps 4 and 5 from above.

Copyright © 1997-2010 Oracle and/or its affiliates. All rights reserved.