Archive for February, 2011

February 10, 2011

Clustered EJB 2.x deployment on JBoss 5.1.0

Recently I encountered a situation wherein I had to migrate an existing EJB2.x application. The application was using JBoss 4.0.3 as the container. It had to be migrated to JBoss 5.1.0.
Also, the EJBs to be migrated were Stateful and Stateless Session beans. The beans had to be deployed in a clustered environment.

If you have ever deployed a clustered EJB, you will know the container configuration file – jboss.xml in this case – packaged with the EJB has to contain the corresponding configuration for clustered deployment.
Below is a snippet:

<jboss>
<security-domain>java:/jaas/csl2-ejb</security-domain>
<missing-method-permissions-excluded-mode>false</missing-method-permissions-excluded-mode>
<enterprise-beans>
<session>
<ejb-name>SampleBean</ejb-name>
<jndi-name>com.example.SampleBean</jndi-name>
<call-by-value>true</call-by-value>
<configuration-name>SampleBeanContainer</configuration-name>
<clustered>True</clustered>
<cluster-config>
<partition-name>DefaultPartition</partition-name>
<home-load-balance-policy>org.jboss.ha.framework.interfaces.RandomRobin</home-load-balance-policy>
<session-state-manager-jndi-name>/HASessionState/Default</session-state-manager-jndi-name>
</cluster-config>
<method-attributes>
<method>
<method-name>*</method-name>
<transaction-timeout>1200</transaction-timeout>
</method>
</method-attributes>
</session>
</enterprise-beans>
<container-configurations>
<container-configuration extends="Clustered Stateful SessionBean">
<container-name>SampleBeanContainer</container-name>
<container-pool-conf>
<MaximumSize>100</MaximumSize>
<strictMaximumSize>true</strictMaximumSize>
</container-pool-conf>
</container-configuration>
</container-configurations>
</jboss>

Here I want to cover a specific point. The bolded tag, PartitionName is set by default in JBoss to DefaultPartition. In case this tag is not specified, JBoss picks up the default partition name from /conf/standardjboss.xml.

However, we observed that inspite of configuring the appropriate default ‘partitionName’ in standardjboss.xml, JBoss 5.1.0 simply would not deploy the EJBs throwing a deployment exception.

The only way out that I found was to keep a placeholder for PartitionName in my jboss.xml corresponding to each clustered EJB.
JBoss accepts a runtime parameter of jboss.partition.name. Providing this as a JVM option during JBoss startup will act to replace the corresponding partition name and successfully startup the server.

so, the above configuration looks like this now:
<partition-name>${jboss.partition.name}</partition-name>