Java EE 6 SDK

# The Cluster JSP Sample Application.

The cluster JSP sample application demonstrates how a request to a JSP is shared in all of server instances in a GlassFish cluster.

## Building and Deploying the Application

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:

1. 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.

2. 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.

3. 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.

4. Create the cluster by running command 'asadmin create-cluster'.

5. 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.

6. 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'.

7. Now deploy the clusterjsp to the cluster by running 'asadmin deploy –availabilityenabled=true –target <clustername> <application path>/clusterjsp.ear'.

8. 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.

  $ ./asadmin list-domains
  domain1 running
  Command list-domains executed successfully.
  $ ./asadmin create-cluster cluster1
  Command create-cluster executed successfully.
  $ ./asadmin create-local-instance --cluster cluster1 instance1
  Rendezvoused with DAS on localhost:4848.
  Port Assignments for server instance instance1:
  JMX_SYSTEM_CONNECTOR_PORT=28686
  JMS_PROVIDER_PORT=27676
  HTTP_LISTENER_PORT=28080
  ASADMIN_LISTENER_PORT=24848
  JAVA_DEBUGGER_PORT=29009
  IIOP_SSL_LISTENER_PORT=23820
  IIOP_LISTENER_PORT=23700
  OSGI_SHELL_TELNET_PORT=26666
  HTTP_SSL_LISTENER_PORT=28181
  IIOP_SSL_MUTUALAUTH_PORT=23920
  Command create-local-instance executed successfully.
  $ ./asadmin create-local-instance --cluster cluster1 instance2
  Using DAS host localhost and port 4848 from existing das.properties for node
  localhost. To use a different DAS, create a new node using create-node-ssh or
  create-node-config. Create the instance with the new node and correct
  host and port:
  asadmin --host das_host --port das_port create-local-instance --node node_name instance_name.
  Rendezvoused with DAS on localhost:4848.
  Port Assignments for server instance instance2:
  JMX_SYSTEM_CONNECTOR_PORT=28687
  JMS_PROVIDER_PORT=27677
  HTTP_LISTENER_PORT=28081
  ASADMIN_LISTENER_PORT=24849
  JAVA_DEBUGGER_PORT=29010
  IIOP_SSL_LISTENER_PORT=23821
  IIOP_LISTENER_PORT=23701
  OSGI_SHELL_TELNET_PORT=26667
  HTTP_SSL_LISTENER_PORT=28182
  IIOP_SSL_MUTUALAUTH_PORT=23921
  WARNING: Instance instance1 seems to be offline; command _register-instance-at-instance was not replicated to that instance
  Command create-local-instance executed successfully.
  $ ./asadmin start-cluster cluster1
  Command start-cluster executed successfully.
  $ ./asadmin list-instances
  instance1 running
  instance2 running
  Command list-instances executed successfully.
  $ ./asadmin deploy --availabilityenabled=true --target cluster1 /tmp/clusterjsp.ear
  Application deployed with name clusterjsp.
  Command deploy executed successfully.

## Running the Sample 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

1. Access the clusterjsp application through instance1 by launching a web browser and entering the URL http://<hostname>:<Instance1HTTPPort>/clusterjsp

2. Add session data by entering the session attribute name and value and clicking 'ADD SESSION DATA' button in the web page.

3. Stop instance1 by running 'asadmin stop-instance instance1' command from command line.

4. Access the clusterjsp application through instance2 by entering the URL http://<hostname>:<Instance1HTTPPort>/clusterjsp on the same browser window opened in step 1.

5. 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.