1 Reply Latest reply on Jan 13, 2004 8:48 AM by Jean-MarcSpaggiari

    Call Clustred SessionBean into same JVM ...

    Jean-MarcSpaggiari Newbie

       

      "jmspaggi" wrote:
      Hi all.

      I have installed a working fine cluster with 3 machine.
      I have deploy a very simple clustered Session Bean, and when I call it whith standalone class, the cluster is working fine and the 10 beans was created over the cluster on each computer. Nice.

      Now, when I try to do the same think on a servlet, in the servlet contenair of one of the 3 computer, my session bean is no more clusterised. All the instanca was created on the same compture. I not able to clusterised it any more.

      The question is, how can I invoke clusterised session bean from a servlet running in Tomcat/JBoss, not only on the current machine ?

      Thanks for help.

      JMS.


        • 1. Re: Call Clustred SessionBean into same JVM ...
          Jean-MarcSpaggiari Newbie

           

          "jmspaggi" wrote:
          OK. I have found a solution. Not the best, but a working solution.

          In standardjboss.xml

          Modify org.jboss.proxy.TransactionInterceptor by org.jboss.proxy.MyInterceptor

          Here is MyInterceptor :

          
          package org.jboss.invocation;
          
          /*
           * JBoss, the OpenSource J2EE webOS
           *
           * Distributable under LGPL license. See terms of license at gnu.org.
           */
          
          import java.io.Externalizable;
          
          import javax.management.ObjectName;
          
          import org.jboss.invocation.Invocation;
          import org.jboss.invocation.InvocationContext;
          import org.jboss.invocation.Invoker;
          import org.jboss.invocation.InvokerInterceptor;
          import org.jboss.system.Registry;
          
          /**
           * A very simple implementation of it that branches to the local stuff.
           *
           * @author <a href="mailto:marc.fleury@jboss.org">Marc Fleury</a>
           * @author Scott.Stark@jboss.org
           * @version $Revision: 1.2.2.2 $
           */
          public class MyInterceptor extends InvokerInterceptor implements Externalizable
          {
          
           public static final String FORCEREMOTE = "forceremote";
          
           public static boolean isForceRemote(Invocation invocation)
           {
           ObjectName mbean = null;
           mbean = (ObjectName)Registry.lookup(invocation.getObjectName());
           return mbean.getCanonicalName().indexOf(FORCEREMOTE) >= 0;
           }
          
           /**
           * The invocation on the delegate, calls the right invoker. Remote if we are remote, local if we are local.
           */
           public Object invoke(Invocation invocation) throws Exception
           {
           Object returnValue = null;
           InvocationContext ctx = invocation.getInvocationContext();
           // optimize if calling another bean in same server VM
           if (isForceRemote(invocation) || ! isLocal())
           {
           // The payload will go through marshalling at the invoker layer
           Invoker invoker = ctx.getInvoker();
           returnValue = invoker.invoke(invocation);
           }
           else
           {
           // The payload as is is good
           returnValue = localInvoker.invoke(invocation);
           }
           return returnValue;
           }
          }
          


          After, modify JRMPInvokerProxyHA by changing isLocal like this :

           public boolean isLocal(Invocation invocation)
           {
           return colocation.contains(invocation.getObjectName()) && !MyInterceptor.isForceRemote(invocation);
           }
          


          When it's done, put back this classes in jbossha.jar in \all\lib\.

          Now, if your EJB name containt forceremote, it will be load anywhere in the cluster. On other case, it will be load only on the local JVM.

          You can improved this stub by adding XML configuration file with class name instead of looking at "forceremote" in the JNDI name, but it's enough for me.

          JMS.