1 Reply Latest reply on Jan 28, 2009 5:11 AM by brettcave

    Load balancing and clustering in JBoss 4.2.2 GA

    pepelara

      Hi,

      Needed for EJB 3.0

      I have implemented the same sample in Eclipse Ganymede RS1.

      The first one call a local interface and it does not work. The second one call a remote interface with the same business logic and it works.

      I have been visiting some webs and I have found this Jboss post,

      http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4105969#4105969


      He has got the solution. He is talking about @Clustered annotation.

      My problem is that I have not configured my JBoss 4.2.2 GA for clustering and load balancing. And I do not know if it is possible.

      Are you following me? I mean, I do not manage these terms as well as I would like.

      I have set the @Clustered annotation in my session stateless bean, and my default configuration returns me the following exception at deployment,

      20:44:46,576 WARN [ServiceController] Problem creating service jboss.j2ee:service=EJB3,module=CalculatorEJB.jar
      java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.jboss.annotation.ejb.Clustered.loadBalancePolicy()
       at java.lang.reflect.Method.getDefaultValue(Unknown Source)
       at sun.reflect.annotation.AnnotationType.<init>(Unknown Source)
       at sun.reflect.annotation.AnnotationType.getInstance(Unknown Source)
       at sun.reflect.annotation.AnnotationParser.parseAnnotation(Unknown Source)
       at sun.reflect.annotation.AnnotationParser.parseAnnotations2(Unknown Source)
       at sun.reflect.annotation.AnnotationParser.parseAnnotations(Unknown Source)
       at java.lang.Class.initAnnotationsIfNecessary(Unknown Source)
       at java.lang.Class.getAnnotation(Unknown Source)
       at org.jboss.aop.annotation.AnnotationElement.getVisibleAnnotation(AnnotationElement.java:88)
       at org.jboss.aop.Advisor.resolveAnnotation(Advisor.java:321)
       at org.jboss.ejb3.SessionContainer.checkForDuplicateLocalAndRemoteInterfaces(SessionContainer.java:126)
       at org.jboss.ejb3.SessionContainer.instantiated(SessionContainer.java:119)
       at org.jboss.ejb3.Ejb3Deployment.deployElement(Ejb3Deployment.java:492)
       at org.jboss.ejb3.Ejb3Deployment.deployElement(Ejb3Deployment.java:442)
       at org.jboss.ejb3.Ejb3Deployment.deployUrl(Ejb3Deployment.java:423)
       at org.jboss.ejb3.Ejb3Deployment.deploy(Ejb3Deployment.java:384)
       at org.jboss.ejb3.Ejb3Deployment.create(Ejb3Deployment.java:327)
       at org.jboss.ejb3.Ejb3Module.createService(Ejb3Module.java:77)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalCreate(ServiceMBeanSupport.java:260)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:243)
       at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
       at $Proxy0.create(Unknown Source)
       at org.jboss.system.ServiceController.create(ServiceController.java:330)
       at org.jboss.system.ServiceController.create(ServiceController.java:273)
       at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy33.create(Unknown Source)
       at org.jboss.ejb3.EJB3Deployer.create(EJB3Deployer.java:492)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
       at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
       at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
       at org.jboss.wsf.container.jboss42.DeployerInterceptor.create(DeployerInterceptor.java:76)
       at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.create(SubDeployerInterceptorSupport.java:180)
       at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:91)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy34.create(Unknown Source)
       at org.jboss.deployment.MainDeployer.create(MainDeployer.java:969)
       at org.jboss.deployment.MainDeployer.create(MainDeployer.java:959)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:818)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
       at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy9.deploy(Unknown Source)
       at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
       at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
       at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:417)
       at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy4.start(Unknown Source)
       at org.jboss.deployment.SARDeployer.start(SARDeployer.java:302)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy5.deploy(Unknown Source)
       at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
       at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
       at org.jboss.Main.boot(Main.java:200)
       at org.jboss.Main$1.run(Main.java:508)
       at java.lang.Thread.run(Unknown Source)
      


      And at the end, the log says,

      20:44:50,854 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
      
      --- MBeans waiting for other MBeans ---
      ObjectName: jboss.j2ee:service=EJB3,module=CalculatorEJB.jar
       State: FAILED
       Reason: java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.jboss.annotation.ejb.Clustered.loadBalancePolicy()
      
      --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
      ObjectName: jboss.j2ee:service=EJB3,module=CalculatorEJB.jar
       State: FAILED
       Reason: java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.jboss.annotation.ejb.Clustered.loadBalancePolicy()
      


      This are my my class,

      #1 The local interface
      package jboss.tutorial;
      
      import javax.ejb.Local;
      
      @Local
      public interface Calculator {
       public int add(int x, int y);
       public int subtract(int x, int y);
      }
      


      #2 The bean
      package jboss.tutorial;
      
      import javax.ejb.Stateless;
      import org.jboss.annotation.ejb.Clustered;
      
      /**
       * Session Bean implementation class CalculatorBean
       */
      @Stateless
      @Clustered
      public class CalculatorBean implements Calculator {
      
       /**
       * Default constructor.
       */
       public CalculatorBean() {
       // TODO Auto-generated constructor stub
       }
      
       @Override
       public int add(int x, int y) {
       // TODO Auto-generated method stub
       return x + y;
       }
      
       @Override
       public int subtract(int x, int y) {
       // TODO Auto-generated method stub
       return x - y;
       }
      }
      


      #3 The client
      package jboss.tutorial;
      
      import java.util.Properties;
      import javax.ejb.EJB;
      import javax.naming.InitialContext;
      import javax.naming.Context;
      
      public class CalculatorClient {
      
       @EJB
       private static Calculator calculator;
      
       public CalculatorClient() {
       try {
       Properties props = new Properties();
       props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
       props.put("java.naming.factory.url.pkgs", "jnp://localhost:1099");
       props.put("java.naming.provider.url", "jnp://localhost:1099");
       Context ctx = new InitialContext(props);
       calculator = (Calculator) ctx.lookup("CalculatorEAR/CalculatorBean/local");
       } catch (Exception ex) {
       System.out.println("Couldn’t create calculator bean. "+
       ex.getMessage());
       }
       }
      
       public void doOperations() {
       try {
       System.out.println("1 + 1 = " + calculator.add(1, 1));
       System.out.println("1 - 1 = " + calculator.subtract(1, 1));
      
       System.exit(0);
       } catch (Exception ex) {
       System.err.println("Caught an unexpected exception!");
       ex.printStackTrace();
       }
       }
      
       /**
       * @param args
       */
       public static void main(String[] args) {
       // TODO Auto-generated method stub
       CalculatorClient cClient = new CalculatorClient();
       cClient.doOperations();
       }
      }
      


      Running the application I can instantiate the local interface, but when I call it in the doOperations() method, it gives me the catch exception.

      So I guess it is a configuration question.

      Regards,
      pepelara

        • 1. Re: Load balancing and clustering in JBoss 4.2.2 GA
          brettcave

          from what I understand, your @clustered is for maintaining state across the cluster, but @stateless has no state, so it might be redundant code.

          Jboss will cluster by default, so no special config needed, just deploy your app the the /server//farm/ directory, (e.g. config = "all"), so the bean will be on all nodes.