Chapter 6. EJB Clustering

Table of Contents

6.1. Overview
6.2. Major Functions
6.2.1. Load Balancing
6.2.2. Failover(EJB Restoration)
6.2.3. EJB Recovery through Idempotent Method
6.2.4. Session Replication
6.3. EJB Clustering Configuration
6.3.1. Clustering Configuration through Annotation
6.3.2. Clustering Configuration through xml
6.3.3. Clustering Configuration for Stateful Session Bean
6.4. EJB Failover Restrictions

This chapter describes the concept of EJB clustering and how to configure main functions of EJB.

In order to use the failover and load balancing functions in EJB, individual beans may be deployed across several EJB engines to form a cluster. Clustering is accomplished on the component level (individual beans) and may be used by Stateless/Stateful session beans and entity beans. A Message Driven Bean (MDB) is not a clustering target.

JEUS EJB clustering has the following two functions:

The following figure explains two major functions of EJB clustering, load balancing and failover.


If you deploy modules that need clustering, they are all bound to the same name in the Naming Service. Using this name, client can perform load-balancing and failover. Therefore, even if you deploy the same module by binding it to the Naming Server using a different name, the module will not be included in the cluster.

Note

Stateful session beans use the JEUS session manager for failover. There is only one session manager for each EJB engine, and therefore the clustering scope of a bean should not be dependent on the individual bean. For example, if bean A is bound to EJB engine1 and EJB engine 2, and bean2 is bound to EJB engine1 and engine 3, the session manager wrongly assumes that the bean A and B are clustered on EJB enigne1, engine2, and engine3.

The following explains major functions of EJB clustering.

Failover is the ability to recover from a failure in a single EJB service (e.g., OS crash, network disruption, or severe EJB engine failure).

There are two types of recoveries that the JEUS system can perform:

The difference between the previous two scenarios is when the error condition is detected: before invoking a remote EJB business method or while the bean is processing the request.

An Idempotent method is a getter method that has no side effects. This means that we can invoke an idempotent method with the assurance that no states (e.g., instance variables, database fields, etc.) are changed during its execution.

An idempotent method can be used to deal with the second recovery issue of "6.2.2. Failover(EJB Restoration)": if a method is idempotent, we can safely re-invoke it on a different bean even if the first attempt to invoke the method failed during execution. However, if a method is not idempotent, there is nothing we can do in such a scenario. It is better to throw an exception than re-executing the method when a runtime error occurs. Hence, EJB failover performs better when more Idempotent methods are used. The status of the business method must be identified before configuring it.

EJB clustering can be configured either by using annotation in the bean class or the jeus-ejb-dd.xml file. Configuration items for clustering include the Bean to be configured, idempotent methods of the bean, and session replication mode of each bean or method.

This section shows how to configure annotation and descriptor (xml) for clustering through examples.

Configure classes or methods of a clustered bean by using annotation as follows.


Descriptions for each class are as follows:

ClassDescription
@jeus.ejb.ClusteredCompletely activates or inactivates the clustering of the bean.
@jeus.ejb.Idempotent
  • Defines whether a bean or business method is idempotent.

  • If the value is false, it is not idempotent.

  • When an exception occurs while creating a remote bean object, always perform retries using idempotent methods for stateless session beans, and throw an exception to the application using a non-idempotent operation for stateful session beans.

@jeus.ejb.CreateIdempotent
  • Defines whether to set methods as idempotent when creating session bean.

  • If the value is false, methods are not idempotent. If this annotation is not described, stateless session bean methods are always assumed to be idempotent.

@jeus.ejb.Replication
  • Specifies session replication mode for each bean or each business method.

  • For this, an enum type class called jeus.ejb.ReplicationMode should be used. Refer to JEUS API documents (javadoc) about this class. This annotation can be used in the form, @Replication(Replication- Mode.SYNC). Users can use the annotation for each bean, but if it is not configured, the default value is ReplicationMode.SYNC. In general, a method, that is not configured, follows the bean configuration. But for @Idempotent, ReplicationMode.NONE is the default value, and the create() method, a home business method, follows the configuration of the bean.

The following configuration for each clustered bean can be configured inside the <clustering> tag in the JEUS EJB module DD file (jeus-ejb-dd.xml).


Descriptions for each tag are as follows:

TagDescription
<enable-clustering>Completely activates or inactivates the clustering of the bean.
<ejb-remote-idempotent-method>Defines idempotent methods among bean methods. (Refer to @jeus.ejb.Idempotent in"6.3.1. Clustering Configuration through Annotation").
<ejb-remote-idempotent-exclude-method>Defines methods that need to be excluded from methods that are defined as idempotent. This has precedence over the <ejb-remote-idempotent-method> setting, but is used in the same way.
<ejb-home-idempotent-method>Defines idempotent methods among methods defined in 2.x style home interface (Refer to @jeus.ejb.CreateIdempotent of "6.3.1. Clustering Configuration through Annotation"). This is used in the same way as <ejb-remote-idempotent-method>.
<ejb-home-idempotent-exclude-method>Defines methods that need to be exclude from idempotent methods defined in 2.x style home interface. This has higher priority over <ejb-home-idempotent-method>, but is used the same way as <ejb-remote-idempotent-method>.
<create-idempotent>Defines whether to declare a bean as idempotent when creating a session bean.
<replication>Specifies the session replication mode at the bean or method level. For more information, refer to "6.2.4. Session Replication" and [Example 6.2].

In order for the previously defined bean clustering to work, you must consider these issues.

  • All beans participating in clustering should have the same settings inside the <clustering> element.

  • In order to create a cluster, beans should have the same <export-name> value.

A client may use the EJB reference (Stub) by caching it or using injection, instead of doing a look up each time. In this case, failover may not be performed even though there is another alive end-point. This may occur when MSs, that were alive in the EJB end-point list at the time of the lookup, are not alive, and only new MSs that started after the lookup are alive.

EJB references are looked up internally at the time of the failover, and a new EJB reference is sent to the client. However, if all deployed MSs are terminated when you are doing a lookup of an EJB reference that is in use, failover cannot be performed even though there is a new EJB end-point that is deployed after the lookup and is able to provide the service.

In the previous case, the termination of existing MSs means that the nodes are abnormally terminated or shut down, or an EJB end-point is undeployed and cannot provide the service. The deployment of a new EJB end-point can mean that the time when the new MS was included to a cluster was too late (when EJB reference is already looked up and used), downed MS was restarted too late, or the undeployed EJB end-point was redeployed too late.

This may occur when two MSs are used for active/backup clustering. The following is an example scenario.

A single EJB engine exists in each MSs: A, B, and C. A client looks up EJB references for the first time and caches them.

  1. EJBs are deployed to A, B, and C, and EJB on A is obtained as a result of a lookup.

  2. EJB on A is abnormally terminated during use. EJB on B is obtained through lookup internally and it continues to provide the service.

  3. EJB on B is undeployed, and EJB on C is obtained through lookup.

  4. At this time, EJB on B is redeployed, and C is abnormally terminated.

In this case, when EJB reference of C is looked up, EJB end-point of B was undeployed and was redeployed after EJB on C was looked up. When C was terminated, B was still alive, but failover was not performed. However, if B was not deployed or undeployed, but was abnormally started or terminated, failover is performed. This is because the status of the engine for rebooting is checked for abnormal terminations.

It is possible to avoid the previous situation, if a new EJB Reference is looked up again and a new end-point list is obtained.