[jboss-user] [EJB 3.0] - Re: A better IsLocalInterceptor?
jahlborn
do-not-reply at jboss.com
Thu Dec 7 11:11:27 EST 2006
The class went through a variety of iterations, and i realized the version above could be simplified a bit more:
| 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
| {
|
| /** interceptor which handles actual local invocations */
| private final IsLocalInterceptor _delegate = new IsLocalInterceptor();
| /** the name of the partition on which this interceptor was created, filled
| in at construction */
| private final String _creationPartitionName;
| /** whether or not this object is on a box in the same cluster in which the
| object was originally created */
| private transient boolean _isCreationCluster;
|
|
| public IsReallyLocalInterceptor() {
| // store the partition name on which this interceptor is created
| _creationPartitionName = getPartitionName();
| _isCreationCluster = true;
| }
|
| public String getName()
| {
| return getClass().getName();
| }
|
| public Object invoke(Invocation invocation) throws Throwable
| {
| // if we got the interceptor on this cluster, let IsLocalInterceptor
| // handle the call, otherwise continue down the interceptor chain.
| if(_isCreationCluster) {
| return _delegate.invoke(invocation);
| }
|
| return invocation.invokeNext();
| }
|
| private void readObject(java.io.ObjectInputStream in)
| throws java.io.IOException, ClassNotFoundException
| {
| // handle serialized fields
| in.defaultReadObject();
|
| // grab the invocation partition and determine if we are still on the same
| // cluster
| String invocationPartitionName = getPartitionName();
| _isCreationCluster =
| _creationPartitionName.equals(invocationPartitionName);
| }
|
| /**
| * Returns the partition name of the current environment.
| */
| private static String getPartitionName() {
| return ServerConfigUtil.getDefaultPartitionName();
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3991990#3991990
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3991990
More information about the jboss-user
mailing list