[jboss-cvs] JBossAS SVN: r61680 - in trunk/ejb3: src/main/org/jboss/ejb3/remoting and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Mar 25 14:22:46 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-03-25 14:22:46 -0400 (Sun, 25 Mar 2007)
New Revision: 61680

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java
Modified:
   trunk/ejb3/build.xml
   trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
   trunk/ejb3/src/resources/ejb3-interceptors-aop.xml
Log:
[EJBTHREE-881] Create a clustered version of IsLocalInterceptor

Modified: trunk/ejb3/build.xml
===================================================================
--- trunk/ejb3/build.xml	2007-03-25 18:20:53 UTC (rev 61679)
+++ trunk/ejb3/build.xml	2007-03-25 18:22:46 UTC (rev 61680)
@@ -325,6 +325,7 @@
             <include name="org/jboss/ejb3/interceptor/ClientInterceptorUtil.class"/>
             <include name="org/jboss/ejb3/mdb/ConsumerManager.class"/>
             <include name="org/jboss/ejb3/mdb/Producer*.class"/>
+            <include name="org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.*"/>
             <include name="org/jboss/ejb3/remoting/IsLocalInterceptor.*"/>
             <include name="org/jboss/ejb3/stateful/ForwardId.class"/>
             <include name="org/jboss/ejb3/stateful/StatefulRemoteInvocation.class"/>

Copied: trunk/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java (from rev 61672, branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java	2007-03-25 18:22:46 UTC (rev 61680)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting;
+
+import org.jboss.aop.Dispatcher;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.logging.Logger;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.Ejb3Registry;
+
+/**
+ * Routes the call to the local container, bypassing further client-side
+ * interceptors and any remoting layer, if a container with the same OID 
+ * and partition name is available.
+ *
+ * @author Brian Stansberry
+ * 
+ * @version $Revision: 60233 $
+ */
+public class ClusteredIsLocalInterceptor extends IsLocalInterceptor
+{
+   private static final long serialVersionUID = 5765933584762500725L;
+
+   private static final Logger log = Logger.getLogger(ClusteredIsLocalInterceptor.class);
+
+   public static final String PARTITION_NAME = "PARTITION_NAME";
+   
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      Container localContainer = findLocalContainer(invocation);
+      if (localContainer != null)
+      {
+         return invokeLocal(invocation, localContainer);
+      }
+      return invocation.invokeNext();
+   }
+
+   private Container findLocalContainer(Invocation invocation)
+   {
+      Object oid = invocation.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
+      Container container = null;
+      try
+      {
+         container = Ejb3Registry.getContainer(oid.toString());
+      }
+      catch (IllegalStateException ignored)
+      {
+         if (log.isTraceEnabled())
+            log.trace("Cannot find local container for " + oid);
+      }
+      
+      if (container != null)
+      {
+         String partitionName = (String) invocation.getMetaData(PARTITION_NAME, PARTITION_NAME);
+         if (partitionName != null)
+         {
+            if (!partitionName.equals(((EJBContainer) container).getPartitionName()))
+            {
+               if (log.isTraceEnabled())
+               {
+                  log.trace("Partition (" + ((EJBContainer) container).getPartitionName() + 
+                            ") for local container " + oid + " does not match invocation (" +
+                            partitionName + ")");
+               }
+               container = null;
+            }
+            else if (log.isTraceEnabled())
+            {
+               log.trace("Partition (" + ((EJBContainer) container).getPartitionName() + 
+                     ") for local container " + oid + " matches invocation (" +
+                     partitionName + ")");
+            }
+         }
+         else
+         {
+            log.warn("No PARTITION_NAME metadata associated with invocation");
+            container = null;
+         }
+      }
+      
+      return container;
+   }
+}

Modified: trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2007-03-25 18:20:53 UTC (rev 61679)
+++ trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2007-03-25 18:22:46 UTC (rev 61680)
@@ -31,25 +31,30 @@
 import org.jboss.logging.Logger;
 import org.jboss.serial.io.MarshalledObjectForLocalCalls;
 import org.jboss.ejb3.Container;
-import org.jboss.ejb3.EJBContainer;
 import org.jboss.ejb3.Ejb3Registry;
 
 /**
- * Comment
+ * Routes the call to the local container, bypassing further client-side
+ * interceptors and any remoting layer, if this interceptor was created 
+ * in this JVM.
  *
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author Brian Stansberry
+ *
  * @version $Revision$
  */
 public class IsLocalInterceptor implements Interceptor, Serializable
 {
+   private static final long serialVersionUID = 337700910587744646L;
+
    private static final Logger log = Logger.getLogger(IsLocalInterceptor.class);
-   
+
    public static final String IS_LOCAL = "IS_LOCAL";
    public static final String IS_LOCAL_EXCEPTION = "IS_LOCAL_EXCEPTION";
    
    private static final long stamp = System.currentTimeMillis();
    private long marshalledStamp = stamp;
-   
+
    public String getName()
    {
       return getClass().getName();
@@ -60,34 +65,39 @@
       if (isLocal())
       {
          Object oid = invocation.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
-         Container container = Ejb3Registry.findContainer(oid.toString());
-         Invocation copy = (Invocation) new MarshalledObjectForLocalCalls(invocation).get();
-         copy.getMetaData().addMetaData(IS_LOCAL, IS_LOCAL, Boolean.TRUE);
-         org.jboss.aop.joinpoint.InvocationResponse response = ((Advisor) container).dynamicInvoke(null, copy);
-         Map contextInfo = response.getContextInfo();
-         if (contextInfo != null)
-         {
-            MarshalledObjectForLocalCalls wrappedException = (MarshalledObjectForLocalCalls) response.getContextInfo().get(IS_LOCAL_EXCEPTION);
-            if (wrappedException != null)
-            {
-               throw (Throwable) wrappedException.get();
-            }
-         }
-         invocation.setResponseContextInfo(response.getContextInfo());
-         MarshalledObjectForLocalCalls wrapped = (MarshalledObjectForLocalCalls) response.getResponse();
-         Object rtn = null;
-         if (wrapped != null)
-         {
-            rtn = wrapped.get();
-         }
-         return rtn;
+         Container container = Ejb3Registry.getContainer(oid.toString());
+         
+         return invokeLocal(invocation, container);
       }
       return invocation.invokeNext();
    }
    
-   private boolean isLocal()
+   protected Object invokeLocal(Invocation invocation, Container container) throws Throwable
    {
+      Invocation copy = (Invocation) new MarshalledObjectForLocalCalls(invocation).get();
+      copy.getMetaData().addMetaData(IS_LOCAL, IS_LOCAL, Boolean.TRUE);
+      org.jboss.aop.joinpoint.InvocationResponse response = ((Advisor) container).dynamicInvoke(null, copy);
+      Map contextInfo = response.getContextInfo();
+      if (contextInfo != null)
+      {
+         MarshalledObjectForLocalCalls wrappedException = (MarshalledObjectForLocalCalls) response.getContextInfo().get(IS_LOCAL_EXCEPTION);
+         if (wrappedException != null)
+         {
+            throw (Throwable) wrappedException.get();
+         }
+      }
+      invocation.setResponseContextInfo(response.getContextInfo());
+      MarshalledObjectForLocalCalls wrapped = (MarshalledObjectForLocalCalls) response.getResponse();
+      Object rtn = null;
+      if (wrapped != null)
+      {
+         rtn = wrapped.get();
+      }
+      return rtn;
+   }
+
+   protected boolean isLocal()
+   {
       return stamp == marshalledStamp;
    }
-
 }

Modified: trunk/ejb3/src/resources/ejb3-interceptors-aop.xml
===================================================================
--- trunk/ejb3/src/resources/ejb3-interceptors-aop.xml	2007-03-25 18:20:53 UTC (rev 61679)
+++ trunk/ejb3/src/resources/ejb3-interceptors-aop.xml	2007-03-25 18:22:46 UTC (rev 61680)
@@ -8,6 +8,7 @@
    <interceptor class="org.jboss.aspects.security.SecurityClientInterceptor" scope="PER_VM"/>
    <interceptor class="org.jboss.aspects.tx.ClientTxPropagationInterceptor" scope="PER_VM"/>
    <interceptor class="org.jboss.ejb3.remoting.IsLocalInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor" scope="PER_VM"/>
    <interceptor class="org.jboss.aspects.remoting.ClusterChooserInterceptor" scope="PER_VM"/>
 
    <interceptor class="org.jboss.aspects.tx.TxPropagationInterceptor" scope="PER_VM"/>
@@ -48,7 +49,7 @@
    </stack>
 
    <stack name="ClusteredStatelessSessionClientInterceptors">
-      <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+      <interceptor-ref name="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.remoting.ClusterChooserInterceptor"/>
@@ -56,7 +57,7 @@
    </stack>
 
    <stack name="ClusteredStatefulSessionClientInterceptors">
-      <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+      <interceptor-ref name="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.remoting.ClusterChooserInterceptor"/>




More information about the jboss-cvs-commits mailing list