[jboss-user] [Clustering/JBoss] - Partition name for clustered EJB3 SLSB

kkrivopustov do-not-reply at jboss.com
Thu Sep 28 08:46:34 EDT 2006


Hello
I'm using JBoss-4.0.4.GA and trying to set up clustered EJB3 SLSB for work in dedicated partition. Annotated bean with explicit partition name works fine, failover and load balancing take place. But I don't want to hardcode partition name into the bean class...

Unfortunately @Clustered annotation doesn't allow partition name in ${jboss.partition.name:DefaultPartition} notation, so I switched to XML deployment descriptor. But in this case bean's behaviour is not clustered regardless of using explicit partition name or jboss.partition.name environment variable: requests execute on one server and if this server goes down, client gets an exception. 

Below is my test code:

  | package test.cluster.intf;
  | public interface Foo {
  |     int doSomething(int value);
  | }
  | 
  | package test.cluster.ejb;
  | import org.apache.log4j.LogManager;
  | import test.cluster.intf.Foo;
  | public class FooBean implements Foo {
  |     public int doSomething(int value) {
  |         LogManager.getLogger(FooBean.class).info("iteration " + value);
  |         return 100;
  |     }
  | }
  | 
  | package test.cluster.client;
  | import java.util.Properties;
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | import test.cluster.intf.Foo;
  | public class Client {
  |     private Foo foo;
  | 
  |     private void connect() {
  |         Properties props = new Properties();
  |         props.put("java.naming.factory.initial", "org.jboss.naming.NamingContextFactory");
  |         props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  |         props.put("java.naming.provider.url", "localhost:1100,shamrock-a4:1100");
  |         props.put("jnp.partitionName", "ShamrockPartition");
  |         Context ctx = null;
  |         try {
  |             ctx = new InitialContext(props);
  |             foo = (Foo) ctx.lookup("Foo");
  |         } catch (NamingException e) {
  |             throw new RuntimeException("Unable to lookup bean", e);
  |         }
  |     }
  |     private void process() {
  |         assert foo != null;
  |         for (int i = 0; i < 10000; i++) {
  |             foo.doSomething(i);
  |             System.out.println("iteration " + i + " success");
  |             try {
  |                 Thread.sleep((long) (Math.random() * 500));
  |             } catch (InterruptedException e) {
  |                 throw new RuntimeException(e);
  |             }
  |         }
  |     }
  |     public static void main(String[] args) {
  |         Client client = new Client();
  |         client.connect();
  |         client.process();
  |     }
  | }
  | 
  | <?xml version="1.0" encoding="UTF-8"?>
  | <ejb-jar
  |         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/ejb-jar_3_0.xsd"
  |         version="3.0">
  |    <enterprise-beans>
  |       <session>
  |          <ejb-name>FooBean</ejb-name>
  |          <remote>test.cluster.intf.Foo</remote>
  |          <ejb-class>test.cluster.ejb.FooBean</ejb-class>
  |          <session-type>Stateless</session-type>
  |       </session>
  |    </enterprise-beans>
  | </ejb-jar>
  | 
  | <?xml version="1.0" encoding="UTF-8"?>
  | <jboss 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://www.jboss.org/j2ee/schema/jboss_5_0.xsd"
  |         version="3.0">
  | 	<enterprise-beans>
  | 		<session>
  | 			<ejb-name>FooBean</ejb-name>
  | 			<jndi-name>Foo</jndi-name> 
  | 			<clustered>true</clustered>
  | 			<cluster-config>
  | 				<partition-name>${jboss.partition.name:DefaultPartition}</partition-name>
  | 				<load-balance-policy>org.jboss.ha.framework.interfaces.RandomRobin</load-balance-policy>
  | 			</cluster-config>
  | 		</session>
  | 	</enterprise-beans>
  | </jboss>
  | 
I start server with -Djboss.partition.name=ShamrockPartition -Djboss.partition.udpGroup=228.1.2.4 environment variables.

What's wrong with my configuration? 
Is there any other way to define cluster partition for annotated beans at deployment time?

Thanks in advance.
Konstantin.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3974859#3974859

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3974859



More information about the jboss-user mailing list