[jboss-user] [EJB 3.0] - A better IsLocalInterceptor?

jahlborn do-not-reply at jboss.com
Thu Nov 30 12:09:11 EST 2006


Jboss has always had the behavior where calls to remote beans are made locally if the same service exists on the local server.  This may or not be desired behavior.  We've had this problem in the past, where we really do want to call the remote server, even if the same service exists locally.  In the ejb3 world, this optimization is done by the IsLocalInterceptor, which makes it fairly easy to factor out of the picture (in the ejb 2 world the behavior is embedded within the interceptor which actually makes the remote call).  So, we've written a new interceptor for ejb3 which uses the jboss partition name to determine if the local call optimization should really be done or not.  This seems to be correct behavior and seems to work.  I'd appreciate feedback from jboss people indicating whether or not this is really a valid test.  If so, it would be great if this code could be included in jboss for others to use (even if it is not used by default).  

To use this you would replace the relevant references to IsLocalInterceptor in the deploy/ejb3-interceptors-aop.xml with references to this class instead.


  | package com.hmsonline.jbossbootstrap.remoting;
  | 
  | import java.io.Serializable;
  | 
  | import org.jboss.aop.advice.Interceptor;
  | import org.jboss.aop.joinpoint.Invocation;
  | import org.jboss.ejb3.remoting.IsLocalInterceptor;
  | import org.jboss.system.server.ServerConfigUtil;
  | 
  | 
  | /**
  |  * This interceptor fixes the IsLocalInterceptor, which makes local calls
  |  * regardless of whether that's what is intended by the user.  This
  |  * Interceptor instead stores the PartitionName of the partition on which the
  |  * interceptor was created and compares that to the partition name of the
  |  * invoking partition.  If the names differ, the call is treated as a remote
  |  * call.  Assuming that the partition names are setup correctly (which they
  |  * must be, or other bad things happen), then this test should be
  |  * sufficient for both clustered and non-clustered remote proxies.
  |  *
  |  * @author James Ahlborn
  |  */
  | public class IsReallyLocalInterceptor implements Interceptor, Serializable
  | {
  |   private static final long serialVersionUID = -2472756311741041575L;  
  | 
  |   /** interceptor which handles actual local invocations */
  |   private IsLocalInterceptor _delegate = new IsLocalInterceptor();
  |   /** the name of the partition on which this interceptor was created, filled
  |       in at construction */
  |   private String _creationPartitionName;
  |   /** the name of the partition on which the interceptor is being utilized,
  |       re-filled in on deserialization */
  |   private transient String _invocationPartitionName;
  | 
  |   
  |   public IsReallyLocalInterceptor() {
  |     // store the partition name on which this interceptor is created
  |     _creationPartitionName = getInternedPartitionName();
  |     _invocationPartitionName = _creationPartitionName;
  |   }
  |   
  |   public String getName()
  |   {
  |     return getClass().getName();
  |   }
  | 
  |   public Object invoke(Invocation invocation) throws Throwable
  |   {
  |     // if we got the interceptor locally, let IsLocalInterceptor handle the
  |     // call, otherwise continue down the interceptor chain.  Note, we intern
  |     // the partition names so we can use object equality.
  |     if(_creationPartitionName == _invocationPartitionName) {
  |       return _delegate.invoke(invocation);
  |     }
  |     
  |     return invocation.invokeNext();
  |   }
  | 
  |   private void readObject(java.io.ObjectInputStream in)
  |      throws java.io.IOException, ClassNotFoundException
  |   {
  |     // handle serialized fields
  |     in.defaultReadObject();
  | 
  |     // make sure creation partition is interned
  |     _creationPartitionName = _creationPartitionName.intern();
  | 
  |     // grab the invocation partition
  |     _invocationPartitionName = getInternedPartitionName();
  |   }
  | 
  |   /**
  |    * Returns the partition name of the current environment, interned.
  |    */
  |   private static String getInternedPartitionName() {
  |     return ServerConfigUtil.getDefaultPartitionName().intern();
  |   }
  |   
  | }
  | 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3990154#3990154

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3990154



More information about the jboss-user mailing list