Donnerstag Apr 24, 2008
Montag Sep 17, 2007
By Daniel Adelhardt on Sep 17, 2007
I have been busy over the past months and didn't find the time to blog. But today is an important day for the GlassFish community which forced me to blog again:
GlassFish v2 - also known officially as Sun Java System Application Server 9.1 - is finally released today!
If you are new to GlassFish here are some of the feature highlights:
- Full Java EE 5 Support
- Profile support: Developer, Cluster and Enterprise Profiles
- Clustering and failover support
- New in memory replication for failover more
- Java Business Integration support
- Easy to use intuitive admin console
- and much more - See Eduardo's writeup
You can read more about this exciting release as usually on the
Dienstag Apr 17, 2007
By Daniel Adelhardt on Apr 17, 2007
Step 1: Setup a GlassFish V2 domain:
- Download GlassFish V2 beta2 (eg build 41c) from here
- Execute java -jar glassfish-installer-v2-<buildnumber>.jar
- As we will have to use the cluster profile edit setup-cluster.xml as needed. If the default ports and passwords are ok for you there is no need to change anything. (I assume default settings for the next steps)
- Execute ant -f setup-cluster.xml and a GlassFish domain with its domain administration server is created for you.
- Start your domain admin server by executing asadmin start-domain --user admin and verify that its up and running by accessing the admin gui at http:<servername>:4848
- Next you have to create a node-agent. Node agents are responsible for communication between you domain admin server and server instances or clusters. You create a node agent be executing asadmin create-node-agent <nodeagentname>. If you don't specify a node agent name the hostname if your system will be used. If you create your node agent on a different server you also have to specify host/port information for your domain admin server by giving --host <hostname> --port <portnumber> to asadmin
- Fire up your node agent by asadmin start-node-agent <nodeagentname>
- Next look at your admin console. Your node agent should show up as running.
Step 2: Setup a GlassFish V2 cluster
Setting up a cluster means that we are going to define a cluster configuration that is shared among multiple instances. To create a cluster proceed this way in the admin gui:
- Select Clusters in the navigation tree
- Click on new to create a cluster, give your cluster a name, select default config and add cluster nodes (at least 2 for now). For each cluster node select your node agents representing the machines where your cluster instances shall run. The following picture shows my test setup.
- Click on OK and your cluster and its instances will be created (will take some time depending on your machine).
- On the next page that will show up in the admin gui you can select the checkbox left to the clustername and click on the Start Cluster button to start up your cluster.
- Now your cluster should be up and running and ready for application deployment!
- <glassfish-install-dir>/bin/asadmin create-cluster --user admin <clustername>
- <glassfish-install-dir>/bin/asadmin create-instance --user admin --nodeagent <nodeagentname> --cluster <clustername> <instancename1>
- <glassfish-install-dir>/bin/asadmin create-instance --user admin --nodeagent <nodeagentname> --cluster <clustername> <instancename2>
- <glassfish-install-dir>/bin/asadmin start-cluster <clustername>
Step 3: Deploy an application to your cluster
Now we can finally deploy an application to our new cluster environment. In order for a web application to make use of session failover in a cluster some preconditions must be met:
- The group membership service in your cluster must be running as it provides some hearbeat information about the health of your instances. Normally this service is enabled by default. You can doublecheck by selecting your cluster and look at the general tab - the checkbox Heartbeat should show enabled.
- The deployment descriptor of your web app - web-inf/web.xml must contain the <distributable/> element:
<web-app version="2.5" ....... >
- And also your application must provide a web-inf/sun-web.xml that contains properties for the session manager:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0
Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<property name="persistenceFrequency" value="web-method"/>
<property name="persistenceScope" value="session"/>
- In aboves extract of a sun-web.xml the session manager has to specify persistence-type="replicated" to use the in memory replication of your cluster. The persistenceFrequency property with value web-method means that after each request the session gets replicated. A different setting would be time-based replication. The persistenceScope property with a value of session means that on each request the whole HTTPSession gets replicated. Other potential settings are modified-session and modified-attribute.
- If you have changed your apps web.xml and sun-web.xml you are ready to deploy to your cluster. In the admin gui you can simply select your cluster as target. Usually only "server" is shown as selected Target which means that its deployed to the domain admin server. Just select your cluster and add it to the targets list.
- Before you click on the OK button for deployment make sure to select the Availability Enabled checkbox for your application!
_ThreadID=24;_ThreadName=RMI TCP connection(19)-<ip-address>/clusterjsp;replicated;
web-method;session;|WEB0130: Enabling ha-based persistence for web module [/clusterjsp]'s
sessions: persistence-type = [replicated] / persistenceFrequency = [web-method] /
persistenceScope = [session]|#]
Thats all for now about clustering with session failover for GlassFish V2. Of course you also want to use load balancing in front of your cluster. Do do this you can use either the Sun Web Server with GlassFish or use Apache+mod_jk with GlassFish V2.
Update: Shreedhar (check his excellent blog about Shoal) pointed out that 2 things should be considered when using in memory replication:
- The cluster instances should be located on the same subnet
- Clock times on all machines in the cluster should be time syncd to be as close as possible
Powered by ScribeFire.
Freitag Feb 09, 2007
By Daniel Adelhardt on Feb 09, 2007
You can do this either in your application code or as jvm start parameters
or set it as JVM property like this: java -Dorg.omg.CORBA.ORBInitialHost=host -Dorg.omg.CORBA.ORBInitialPort=3700
You can also use the JVM system property com.sun.appserv.iiop.endpoint=host:port to specify the endpoint address. Also this property supports multiple endpoints to support load balancing. For example setting java -Dcom.sun.appserv.iiop.endpoints=host1:port1,host2:port2 ... specifies host2 as failover endpoint if host1 crashes.
The last approach that may be used is to set ORBInitialHost/ORBInitialPort as properties for the InitialContext like this:
Properties p = new Properties(); p.put("org.omg.CORBA.ORBInitialHost","localhost"); p.put("org.omg.CORBA.ORBInitialPort","33700"); InitialContext ctx = new InitialContext(p); //... do the lookups...To make the standalone client run you also have to setup your classpath correct. You have to put appserv-rt.jar, appserv-admin.jar and javaee.jar in your client classpath in addition to the EJB interfaces. Additional parameters are not needed as more properties are picked from the jndi.properties file that is contained in above jars. More information can also be found in the GlassFish EJB FAQ: https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html
Montag Dez 04, 2006
By Daniel Adelhardt on Dez 04, 2006
In addition to jfarcands blog about mod_jk and GlassFish I also wanted to try out mod_jk loadbalancing with GlassFish. Here is the cookbook on how to get a simple load balancing scenario set up:
Steps to setup load balancing:
LoadModule jk_module modules/mod_jk.so
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
#Mount your webapps eg WebApplication1 using JkMount
JkMount /WebApplication1/\* loadbalancer
org.apache.jk.common.ChannelSocket|_ThreadID=11;_ThreadName=Thread-5;|JK: ajp13 listening on /0.0.0.0:8009|#]
Now all web applications that are deployed to your GlassFish instances and that are mounted in your httpd.conf through JkMount commands should be loadbalanced equally.
More advanced jk configuration properties may be found in the Tomcat connectors documentation