9 Replies Latest reply on Sep 17, 2004 10:02 AM by Arnold Fung

    Client calling clustered EJB in same JVM

    Arnold Fung Newbie

      Hello all,

      Newbie here. I am having some problem with clustered beans being called from the same JVM as the container. This was discussed briefly in http://jboss.org/index.html?module=bb&op=viewtopic&t=52786&start=0&postdays=postDays&postorder=postOrder&highlight=highlight

      Imagine the scenario, two EJBs X and Y, where X calls Y, and Y is clustered. Now I believe JBoss's invocation stack is smart enough to realise that X and Y lives in the same VM, so it bypass the clustering mechanism. Is there a recommended way to change this behaviour?

      Many thanks,
      Arnold

        • 1. Re: Client calling clustered EJB in same JVM
          Sacha Labourey Master

          why do you want to change this behaviour? which use case?

          • 2. Re: Client calling clustered EJB in same JVM
            Arnold Fung Newbie

            Thanks for the prompt response.

            OK, EJB X is a wrapper to a set of services provided by our EJBs.
            The calculation service provided by Y is CPU intensive, so we clustered it to take advantage of load balancing.

            There are two use cases w.r.t. accessing the calculation service of Y:
            1. via a convenience wrapper EJB X from client on different VM
            2. directly accessing Y from client on different VM

            Clustering EJB X is probably out of the question, thus I am seeking a solution with changing the invocation stack.

            • 3. Re: Client calling clustered EJB in same JVM
              Sacha Labourey Master

              the easiest is to run two instances of jboss on the same machine then.

              Cheers,

              sacha

              • 4. Re: Client calling clustered EJB in same JVM
                dbuch Newbie

                I also interested on a solution to fix this problem.

                I have a singleton MBean that starts CPU intensive processes. This processes calls EJBs but at this time only localy. It is important that the work is done in the cluster.

                Thanks a lot

                Dirk

                • 5. Re: Client calling clustered EJB in same JVM
                  Arnold Fung Newbie

                  I am not sure how running multiple instances of JBoss would help my situation (for clustering EJBs I am running multiple instances of JBoss already).

                  Basically, is there a way to configure the invocation stack to NOT use the local calling protocol?

                  • 6. Re: Client calling clustered EJB in same JVM
                    Sacha Labourey Master

                    no.

                    split the "LB" ejb from the "workers" ejb.

                    cheers,

                    sacha

                    • 7. Re: Client calling clustered EJB in same JVM
                      Arnold Fung Newbie

                      Hi dbuch,

                      What avenue have you tried in solving your problem?

                      • 8. Re: Client calling clustered EJB in same JVM
                        dbuch Newbie

                        Hi arnold,

                        I have found a solution that fix the problem.

                        1. Create this classes

                        public class MyInvokerInterceptor extends InvokerInterceptor implements Externalizable {
                         public MyInvokerInterceptor() {
                         super();
                         }
                         public boolean isLocal() {
                         return false;
                         }
                        }
                        public class MyMarshallingInvokerInterceptor extends MarshallingInvokerInterceptor {
                         public boolean isLocal() {
                         return false;
                         }
                        }
                        public class MyJRMPInvokerProxyHA extends JRMPInvokerProxyHA {
                         public MyJRMPInvokerProxyHA() {
                         super();
                         }
                        
                         public MyJRMPInvokerProxyHA(ArrayList replicants, LoadBalancePolicy policy, String familyName, long currentViewId) {
                         super(replicants, policy, familyName, currentViewId);
                         }
                        
                         public boolean isLocal(Invocation invocation) {
                         return false;
                         }
                        }
                        public class MyJRMPInvokerHA extends JRMPInvokerHA {
                         public Invoker createProxy(ObjectName beanName, LoadBalancePolicy policy, String proxyFamilyName) throws Exception {
                         Integer hash = new Integer(beanName.hashCode());
                         HATarget target = (HATarget) beanMap.get(hash);
                         if (target == null) {
                         throw new IllegalStateException("The bean hashCode not found");
                         }
                         String familyName = proxyFamilyName;
                         if (familyName == null)
                         familyName = target.getAssociatedPartition().getPartitionName() + "/" + beanName;
                         MyJRMPInvokerProxyHA proxy = new MyJRMPInvokerProxyHA(target.getReplicants(), policy, familyName,
                         target.getCurrentViewId());
                         return proxy;
                         }
                        }


                        2. create a jar file and copy it in to the <JBOSS_HOME>/server/lib directory. IMPORTANT: This file is also needed by the clients.

                        3. change 'org.jboss.invocation.jrmp.server.JRMPInvokerHA' to MyJRMPInvokerHA in the cluster-service.xml

                        4. change 'org.jboss.invocation.InvokerInterceptor' and 'org.jboss.invocation.MarshallingInvokerInterceptor' to MyInvokerInterceptor resp. MyMarshallingInvoker. I have only changed invoker-proxy-binding tags with name clustered-stateless-rmi-invoker, clustered-statefull-rmi-invoker, stateless-rmi-invoker and statefull-rmi-invoker. This can be done in the standardjboss.xml file or in a jboss.xml file (read the docu for this).

                        I hope this can help you.

                        Dirk

                        • 9. Re: Client calling clustered EJB in same JVM
                          Arnold Fung Newbie

                          Hi dbuch,

                          Thanks a lot for your help.
                          I also have a similar 'hack' which involed patching jbosshar.jar (I only changed InvokerInterceptor and JRMPInvokerProxyHA).

                          Personally, I don't like such hacks as it requires maintainence from our side (e.g. what if we want to switch to another version of JBoss?)

                          Sacha's suggestion of running separate JBoss might be better for portability and future proofing.

                          Thanks again,
                          Arnold