8 Replies Latest reply on Oct 7, 2006 5:40 PM by brian.stansberry

    Partition name for clustered EJB3 SLSB

    kkrivopustov

      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.

        • 1. Re: Partition name for clustered EJB3 SLSB
          brian.stansberry

          Your config looks OK. Do things work correctly if you skip the -Djboss.partition.name=... i.e. just accept DefaultPartition?

          There is a JIRA to make the value of the @Clustered partitionName attribute configurable via a system property -- se http://jira.jboss.com/jira/browse/EJBTHREE-424 . At this point the only way to do it is via XML.

          • 2. Re: Partition name for clustered EJB3 SLSB
            brian.stansberry

            There's another recent post describing a failover problem with EJBs configured with XML -- see http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3973991#3973991 .

            We're investigating the cause.

            • 3. Re: Partition name for clustered EJB3 SLSB
              kkrivopustov

              Brian,
              I've tried to skip -D variables, but result was the same. It looks like cluster configuration in jboss.xml is completely ignored.

              • 4. Re: Partition name for clustered EJB3 SLSB
                brian.stansberry

                Please post the stack trace of the exception you're seeing.

                • 5. Re: Partition name for clustered EJB3 SLSB
                  kkrivopustov

                  I run two servers, then start the client, but all requests are executed on one server (whereas with annotated beans requests go sequentially to both servers). When I stop server executing requests, I get the following exception on the client:

                  Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
                   at $Proxy1.doSomething(Unknown Source)
                   at test.cluster.client.Client.process(Client.java:46)
                   at test.cluster.client.Client.main(Client.java:59)
                  Caused by: org.jboss.aop.NotFoundInDispatcherException: Object with oid: jboss.j2ee:jar=test-cluster.jar,name=FooBean,service=EJB3 was not found in the Dispatcher
                   at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:85)
                   at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
                   at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
                   at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
                   at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
                   at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
                   at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
                   at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:190)
                   at org.jboss.remoting.Client.invoke(Client.java:525)
                   at org.jboss.remoting.Client.invoke(Client.java:488)
                   at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:65)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
                   ... 3 more


                  • 6. Re: Partition name for clustered EJB3 SLSB
                    kkrivopustov
                    • 7. Re: Partition name for clustered EJB3 SLSB
                      brian.stansberry

                      OK, so what's happening is you're not getting a cluster-aware client proxy (i.e. the proxy isn't failing to do what its designed for, it's not the correct type of proxy.) So I'll figure out why that is; I ran some tests yesterday w/o problem, but my config was slightly different from yours.

                      • 8. Re: Partition name for clustered EJB3 SLSB
                        brian.stansberry

                        OK, my ignorance is revealed. XML override of the clustering configuration will not work in 4.0.4.GA; you'd need to upgrade the EJB3 implementation to EJB3 RC9, where support for xml override was added -- see http://jira.jboss.com/jira/browse/EJBTHREE-569 . Sorry for not knowing this earlier.