Skip to main content

Stateful EJB state replication on GlassFish cluster.

6 replies [Last post]
bahadyr
Offline
Joined: 2006-09-19
Points: 0

There are 2 CentOS machines. There is a GlassFish cluster on them. Also there are 2 HTTPDs configured with mod_jk as Load balancers for this cluster. And there are keepalived pointing to these machines having single Virtual IP as described in this tutorial http://blogs.nologin.es/rickyepoderi/index.php?/archives/53-Simple-but-F.... Everythings works great.

A have created a web application with these xml descriptors and deployed to cluster and set availability=true. So got session replicated on instances.

-- These xml are added to WEB-INF --

glassfish-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
    <class-loader delegate="true"/>
    <session-config>
        <session-manager persistence-type="replicated">
            <manager-properties>
                <property name="relaxCacheVersionSemantics" value="true"/>
            </manager-properties>
        </session-manager>
    </session-config>
    <jsp-config>
        <property name="keepgenerated" value="true">
            <description>Keep a copy of the generated servlet class' java code.</description>
        </property>
    </jsp-config>
</glassfish-web-app>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <distributable/>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

Question: How to achieve the Stateful EJB state replication on this cluster? What settings should be done, for instance to get the same counter value defined in Stateful EJB via web service?

Thanx in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mk111283
Offline
Joined: 2005-03-29
Points: 0

Not much!

Just package your StatefulEJB as part of your .war. I am assuming that you will be creating the StatefulEJB from a Servlet. All you have to do is to put the EJB reference into the Servlet's HTTPSession.

GlassFish EJB container will replicate the Stateful EJB's state at the end of each business method.

HTH

bahadyr
Offline
Joined: 2006-09-19
Points: 0

Thank you very much for the solution!

Is there any possible to make a standalone EJB with Stateful Bean whos state is replicated on a cluster?

mk111283
Offline
Joined: 2005-03-29
Points: 0

Yes. Just deploy the jar file to the cluster with --availability-enabled = true. Then access the EJB using appclient container

bahadyr
Offline
Joined: 2006-09-19
Points: 0

I did that, but it didn't work.

state is not replicated even i put --availability-enabled=true.

steps to recreate issue

Create EJB, add Stateful Bean, add a counter variable. Add get getCounter() method to return this counter value incremented by 1. Add a web service for this Stateful Bean. deploy on cluster with --availability-enabled=true. Go to web browser, and call this web service.

At this point i get counter values of SFSB's on instances but not the counter for the whole cluster.

TheDescio
Offline
Joined: 2013-01-17
Points: 0

Hi,

I have a similar scenario, but here SFSB value is replicated right after the first bean access, beyond that, each cluster node gets an unique bean value.
When i test my HTTPSession replication with loading balance, it's working fine.
I have saved SFSB reference in a HTTPSession and I saw in server logs files that cluster nodes are trying to get the same bean-ref. I also marked my methods with @TransactionAtrribute annotations as REQUIRED, trying force container update my bean value. I added my bean into glassfish-ejb-jar.xml and filled tag with my methods.
Nothing seem to work.
I started guess that GF is not updating my bean reference for others nodes after bean creation.
Did you find any solution?

Thank you in advance.
Descio

TheDescio
Offline
Joined: 2013-01-17
Points: 0

Hi,

I have a similar scenario, but here SFSB value is replicated right after the first bean access, beyond that, each cluster node gets an unique bean value.
When i test my HTTPSession replication with loading balance, it's working fine.
I have saved SFSB reference in a HTTPSession and I saw in server logs files that cluster nodes are trying to get the same bean-ref. I also marked my methods with @TransactionAtrribute annotations as REQUIRED, trying force container update my bean value. I added my bean into glassfish-ejb-jar.xml and filled tag with my methods.
Nothing seem to work.
I started guess that GF is not updating my bean reference for others nodes after bean creation.
Did you find any solution?

Thank you in advance.
Descio