[jboss-cvs] JBossAS SVN: r109654 - in projects/ejb3/trunk/core/src/main: resources and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 2 12:32:11 EST 2010


Author: wolfc
Date: 2010-12-02 12:32:10 -0500 (Thu, 02 Dec 2010)
New Revision: 109654

Added:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulCacheInterceptor.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceAssociationInterceptor.java
Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
   projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml
Log:
EJBTHREE-2179: refactored StatefulInstanceInterceptor and disabled async


Copied: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulCacheInterceptor.java (from rev 109643, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java)
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulCacheInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulCacheInterceptor.java	2010-12-02 17:32:10 UTC (rev 109654)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.stateful;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.ejb3.aop.AbstractInterceptor;
+import org.jboss.logging.Logger;
+
+import javax.ejb.EJBException;
+import java.rmi.RemoteException;
+
+/**
+ * All interaction with between an instance and the cache.
+ *
+ * Note that removal is still done by StatefulRemoveInterceptor.
+ *
+ * This interceptor must come after concurrency aspects are handled.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class StatefulCacheInterceptor extends AbstractInterceptor
+{
+   private static final Logger log = Logger.getLogger(StatefulCacheInterceptor.class);
+   
+   public StatefulCacheInterceptor()
+   {
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      StatefulContainerInvocation ejb = (StatefulContainerInvocation) invocation;
+      Object id = ejb.getId();
+      StatefulContainer container = getEJBContainer(invocation);
+      // mark the instance in use
+      StatefulBeanContext target = container.getCache().get(id);
+
+      // probably obsolete
+      target.setInInvocation(true);
+
+      StatefulBeanContext.currentBean.push(target);
+      container.pushContext(target);
+      try
+      {
+         if (target.isDiscarded()) throw new EJBException("SFSB was discarded by another thread");
+         return ejb.invokeNext();
+      }
+      catch (Exception ex)
+      {
+         if (StatefulRemoveInterceptor.isApplicationException(ex, (MethodInvocation)invocation)) throw ex;
+         if (ex instanceof RuntimeException
+                 || ex instanceof RemoteException)
+         {
+            if(log.isTraceEnabled())
+               log.trace("Removing bean " + id + " because of exception", ex);
+            container.getCache().remove(id);
+            target.setDiscarded(true);
+         }
+         throw ex;
+      }
+      finally
+      {
+         container.popContext();
+         StatefulBeanContext.currentBean.pop();
+         target.setInInvocation(false);
+         // nobody attached the bean to the tx and nobody discarded it
+         if (!target.isTxSynchronized() && !target.isDiscarded()) container.getCache().release(target);
+      }
+   }
+}

Copied: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceAssociationInterceptor.java (from rev 109643, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java)
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceAssociationInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceAssociationInterceptor.java	2010-12-02 17:32:10 UTC (rev 109654)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.stateful;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ejb3.aop.AbstractInterceptor;
+import org.jboss.logging.Logger;
+
+/**
+ * Associates the invocation with an instance.
+ *
+ * It does nothing else. The instance is *not* marked as being in use.
+ *
+ * After this interceptor AOP can use instance interceptors.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class StatefulInstanceAssociationInterceptor extends AbstractInterceptor
+{
+   private static final Logger log = Logger.getLogger(StatefulInstanceAssociationInterceptor.class);
+   
+   public StatefulInstanceAssociationInterceptor()
+   {
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      StatefulContainerInvocation ejb = (StatefulContainerInvocation) invocation;
+      Object id = ejb.getId();
+      StatefulContainer container = getEJBContainer(invocation);
+      StatefulBeanContext target = container.getCache().get(id, false);
+
+      ejb.setBeanContext(target);
+      try
+      {
+         return ejb.invokeNext();
+      }
+      finally
+      {
+         // FIXME: the bean context should really be disaccociated, but then the StatefulRemoveInterceptor will fail
+         //ejb.setBeanContext(null);
+      }
+   }
+}

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java	2010-12-02 16:38:50 UTC (rev 109653)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java	2010-12-02 17:32:10 UTC (rev 109654)
@@ -21,26 +21,27 @@
  */
 package org.jboss.ejb3.stateful;
 
-import java.rmi.RemoteException;
-
-import javax.ejb.ConcurrentAccessException;
-import javax.ejb.EJBException;
-
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.ejb3.annotation.SerializedConcurrentAccess;
 import org.jboss.ejb3.aop.AbstractInterceptor;
 import org.jboss.logging.Logger;
 
+import javax.ejb.ConcurrentAccessException;
+import javax.ejb.EJBException;
+import java.rmi.RemoteException;
+
 /**
  * Comment
  *
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
+ * @deprecated use StatefulInstanceAssociationInterceptor and StatefulCacheInterceptor
  */
+ at Deprecated
 public class StatefulInstanceInterceptor extends AbstractInterceptor
 {
-   private static final Logger log = Logger.getLogger(StatefulInstanceInterceptor.class);
+   private static final Logger log = Logger.getLogger(StatefulInstanceAssociationInterceptor.class);
    
    public StatefulInstanceInterceptor()
    {

Modified: projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml
===================================================================
--- projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml	2010-12-02 16:38:50 UTC (rev 109653)
+++ projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml	2010-12-02 17:32:10 UTC (rev 109654)
@@ -12,13 +12,20 @@
    <interceptor name="CMConcurrency" factory="org.jboss.ejb3.concurrency.aop.interceptor.ContainerManagedConcurrencyInterceptorFactory" scope="PER_INSTANCE"/>
 
    <interceptor class="org.jboss.aspects.tx.TxPropagationInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.interceptors.aop.NopInterceptor" scope="PER_VM"/>
    
    <stack name="LocalClientInterceptors">
+      <!-- must have at least one interceptor for the stack to exist -->
+      <interceptor-ref name="org.jboss.ejb3.interceptors.aop.NopInterceptor"/>
+      <!--
       <interceptor-ref name="org.jboss.ejb3.async.impl.interceptor.AsynchronousInterceptor" />
+      -->
    </stack>
 
    <stack name="ServiceClientInterceptors">
+      <!--
       <interceptor-ref name="org.jboss.ejb3.async.impl.interceptor.AsynchronousInterceptor" />
+      -->
       <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
       <interceptor-ref name="org.jboss.ejb3.security.client.SecurityClientInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
@@ -26,7 +33,9 @@
    </stack>
 
    <stack name="StatelessSessionClientInterceptors">
+      <!--
       <interceptor-ref name="org.jboss.ejb3.async.impl.interceptor.AsynchronousInterceptor" />
+      -->
       <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
       <interceptor-ref name="org.jboss.ejb3.security.client.SecurityClientInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
@@ -34,7 +43,9 @@
    </stack>
 
    <stack name="StatefulSessionClientInterceptors">
+      <!--
       <interceptor-ref name="org.jboss.ejb3.async.impl.interceptor.AsynchronousInterceptor" />
+      -->
       <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
       <interceptor-ref name="org.jboss.ejb3.security.client.SecurityClientInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
@@ -42,7 +53,9 @@
    </stack>
 
    <stack name="ClusteredStatelessSessionClientInterceptors">
+      <!--
       <interceptor-ref name="org.jboss.ejb3.async.impl.interceptor.AsynchronousInterceptor" />
+      -->
       <interceptor-ref name="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor"/>
       <interceptor-ref name="org.jboss.ejb3.security.client.SecurityClientInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
@@ -51,7 +64,9 @@
    </stack>
 
    <stack name="ClusteredStatefulSessionClientInterceptors">
+      <!--
       <interceptor-ref name="org.jboss.ejb3.async.impl.interceptor.AsynchronousInterceptor" />
+      -->
       <interceptor-ref name="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor"/>
       <interceptor-ref name="org.jboss.ejb3.security.client.SecurityClientInterceptor"/>
       <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
@@ -67,7 +82,8 @@
    <interceptor factory="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory" scope="PER_CLASS"/>
    <interceptor class="org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor" scope="PER_VM"/>
    <interceptor class="org.jboss.ejb3.stateless.StatelessInstanceInterceptor" scope="PER_VM"/>
-   <interceptor class="org.jboss.ejb3.stateful.StatefulInstanceInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.stateful.StatefulCacheInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.stateful.StatefulInstanceAssociationInterceptor" scope="PER_VM"/>
    <interceptor class="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor" scope="PER_VM"/>
    <interceptor class="org.jboss.ejb3.service.ServiceSingletonInterceptor" scope="PER_VM"/>
    <interceptor class="org.jboss.ejb3.cache.StatefulReplicationInterceptor" scope="PER_VM"/>
@@ -258,7 +274,10 @@
          <interceptor-ref name="org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor"/>
          <!-- advice name="setup" aspect="InvocationContextInterceptor"/ -->
          <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
-         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceAssociationInterceptor"/>
+         <!-- CMConcurrency must happen after an instance is associated -->
+         <interceptor-ref name="CMConcurrency"/>
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulCacheInterceptor"/>
       </stack>
 
       <bind pointcut="execution(public * *->*(..))">
@@ -282,11 +301,12 @@
          <interceptor-ref name="org.jboss.ejb3.stateful.StatefulRemoveFactory"/>
       </bind>
       <bind pointcut="execution(public * *->*(..))">
-         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceAssociationInterceptor"/>
+         <!-- CMConcurrency must happen after an instance is associated -->
+         <interceptor-ref name="CMConcurrency"/>
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulCacheInterceptor"/>
          <interceptor-ref name="org.jboss.ejb3.tx.BMTTxInterceptorFactory"/>
          <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
-         <!-- CMConcurrency must happen after an instance is associated -->
-         <interceptor-ref name="CMConcurrency"/>
          <!-- EJBTHREE-2020: session synchronization callbacks must be called within a context -->
          <interceptor-ref name="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor"/>
          <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
@@ -350,7 +370,10 @@
          <interceptor-ref name="org.jboss.ejb3.stateful.StatefulRemoveFactory"/>
       </bind>
       <bind pointcut="execution(public * *->*(..))">
-         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceAssociationInterceptor"/>
+         <!-- CMConcurrency must happen after an instance is associated -->
+         <interceptor-ref name="CMConcurrency"/>
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulCacheInterceptor"/>
          <interceptor-ref name="org.jboss.ejb3.tx.BMTTxInterceptorFactory"/>
          <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
          <interceptor-ref name="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor"/>



More information about the jboss-cvs-commits mailing list