Montag Sep 17, 2007

GlassFish v2 released today!

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!

You can get from here or here

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

  • Performance!

  • and much more - See Eduardo's writeup

You can read more about this exciting release as usually on the

Dienstag Apr 17, 2007

Clustering Web Applications with GlassFish V2

Here is a short tutorial on how to make your web apps highly available with GlassFish V2 and it's new in memory replication features.

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!
If you prefer cluster creation using command line tools you can do it with asadmin this way:
  • <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" ....... >  
    <display-name>myclusterable webapp</display-name>
  • 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" "">

    <session-manager persistence-type="replicated">
    <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!
  • If things went fine the server.log of your instances should have an entry like this:
    _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]|#]
Now you can access your application on both of your cluster instances by directly pointing your browser to each server instances. (eg <host1>:<httpport> and <host2>:<httpport>). If your application changes attributes in the HTTPSession you should see those changes getting replicated to the other server in your cluster.

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

Standalone IIOP Clients with GlassFish

I often get asked how a standalone client can be used to connect to EJBs deployed on GlassFish or Sun Appserver 8.x. Here are the choices:

  • Set system properties org.omg.CORBA\*
    You can do this either in your application code or as jvm start parameters
    System.setProperty("org.omg.CORBA.ORBInitialPort",""); System.setProperty("org.omg.CORBA.ORBInitialHost","");
    or set it as JVM property like this: java -Dorg.omg.CORBA.ORBInitialHost=host -Dorg.omg.CORBA.ORBInitialPort=3700

  • Set System property com.sun.appserv.iiop.endpoints:
    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.

  • Set InitialContext Properties
    The last approach that may be used is to set ORBInitialHost/ORBInitialPort as properties for the InitialContext like this:
    Properties p = new Properties();
    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 file that is contained in above jars. More information can also be found in the GlassFish EJB FAQ:
  • Montag Dez 04, 2006

    Loadbalancing with mod_jk and GlassFish

    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:

    Software needed:

  • Apache 2.0.x
  • Apache Tomcat Connectors link
  • Apache Tomcat 5.5.16 (needed for just one jar File)
  • Apache Commons Logging 1.0.4 link
  • Apache Commons Modeler 1.1 link
  • And of course you need at least two running installations of GlassFish V1/V2.

    Steps to setup load balancing:

  • Install mod_jk into your Apache config (copy to your Apache modules directory)
  • Configure your Apache httpd to include by editing your httpd.conf to include the following:

    LoadModule jk_module modules/
    JkWorkersFile path_to_your_config/conf/
    JkLogFile path_to_your_log_dir/mod_jk.log
    JkLogLevel info
    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

  • Create a File for the mod_jk connector. In the example shown below a load balancing worker for two local GlassFish instances (listening on jk port 8009/8010) is provided.


  • Enable the jk connector in each GlassFish instance by adding a JVM Option with asadmin. If your instances run on the same box you have to choose different JK ports. The ports must also match your worker.workerX.port definitions in your files.
    $GLASSFISH_HOME/bin/asadmin create-jvm-options 

  • Copy the following jar archives to your GlassFish Installations lib directory ($GLASSFISH_HOME/lib): tomcat-ajp.jar (from Tomcat 5.5.16 /server/lib dir), commons-logging.jar and commons-modeler.jar.
  • Next restart your apache httpd and your glassfish instances.
  • If JK connector was enabled successfully in glassfish you should see a log entry in your server log as for example:
    org.apache.jk.common.ChannelSocket|_ThreadID=11;_ThreadName=Thread-5;|JK: ajp13 listening on /|#]

    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

  • About

    Daniel Adelhardt


    « Juli 2016