In this tutorial we will show how to achieve High Availability with your Enterprise Java Beans using a simple Stateful clustered EJB and a remote Client.
Clustering stateful session beans requires JBoss AS to manage the state information. The component that is in charge to manage state information is Infinispan, which by default uses Replication to keep the session synchronized between components, each time the state of a bean changes.
In this tutorial we will set up and test a standalone cluster made up of two nodes and we will deploy our Stateful EJB on both nodes, by simply dropping the artifact on the deployments folder. Here's a picture of our cluster definition:
Now let's code a Simple SFSB with a counter variable instance that will be used to keep track of the session:
And here's the corresponding SampleBeanRemote interface:
On the other hand, if you are using Maven to build your project, you need to add the following dependency in order to compile your Clustered EJB: