4 Replies Latest reply on Oct 9, 2006 4:51 AM by Przemyslaw Madzik

    load-balance-policy tag in jboss.xml not working

    Przemyslaw Madzik Newbie

      Hello!

      I try to obtain clustering for SLSB using jboss.xml description:

      HelloBean.java:
      import javax.ejb.Stateless;
      
      import java.net.InetAddress;
      import java.net.UnknownHostException;
      
      import org.jboss.annotation.ejb.Clustered;
      
      @Stateless//@Clustered(loadBalancePolicy=org.jboss.ha.framework.interfaces.RoundRobin.class)public class HelloBean implements HelloRemote {
       public String sayHelloFrom() throws UnknownHostException {
       String host = InetAddress.getLocalHost().getHostAddress();
      
       return "Hello from " + host + "!";
       }
      }
      
      jboss.xml:
      <?xml version="1.0"?>
      <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>HelloBean</ejb-name>
       <clustered>true</clustered>
       <cluster-config>
       <partition-name>${jboss.partition.name:DefaultPartition}</partition-name> <load-balance-policy>org.jboss.ha.framework.interfaces.RoundRobin</load-balance-policy> </cluster-config>
       </session>
       </enterprise-beans>
      </jboss>
      
      Client.java:
      import javax.naming.InitialContext;
      import javax.naming.Context;
      import javax.naming.NamingException;
      
      import java.net.UnknownHostException;
      
      
      public class Client
      {
       public static void main(String[] args)
       {
       try {
       Context jndiContext = getInitialContext();
       Object ref = jndiContext.lookup("HelloBean/remote");
       HelloRemote hello = (HelloRemote) ref;
      
       for (int i = 0; i < 10; i++) {
       System.out.println(hello.sayHelloFrom());
       }
       }
       catch (NamingException ne) {
       ne.printStackTrace();
       }
       catch (UnknownHostException he) {
       he.printStackTrace();
       }
       }
      
       public static Context getInitialContext() throws NamingException
       {
       return new InitialContext();
       }
      }
      


      I setup cluster with to nodes (10.1.2.71, 10.1.1.192).
      After client start i always get:
      Hello from 10.1.1.192!
      Hello from 10.1.1.192!
      Hello from 10.1.1.192!
      Hello from 10.1.1.192!
      Hello from 10.1.1.192!
      Hello from 10.1.1.192!
      Hello from 10.1.1.192!
      Hello from 10.1.1.192!
      Hello from 10.1.1.192!
      Hello from 10.1.1.192!
      

      or
      Hello from 10.1.2.71!
      Hello from 10.1.2.71!
      Hello from 10.1.2.71!
      Hello from 10.1.2.71!
      Hello from 10.1.2.71!
      Hello from 10.1.2.71!
      Hello from 10.1.2.71!
      Hello from 10.1.2.71!
      Hello from 10.1.2.71!
      Hello from 10.1.2.71!
      


      Seems that load-balance-policy tag is not working because removing comment with @Clustered annotation in HelloBean.java results:
      Hello from 10.1.1.192!
      Hello from 10.1.2.71!
      Hello from 10.1.1.192!
      Hello from 10.1.2.71!
      Hello from 10.1.1.192!
      Hello from 10.1.2.71!
      Hello from 10.1.1.192!
      Hello from 10.1.2.71!
      Hello from 10.1.1.192!
      Hello from 10.1.2.71!
      


      Is it bug in jboss or in my configuration?