[jboss-cvs] JBossAS SVN: r59595 - in trunk/ejb3/src/main/org/jboss/ejb3: stateless and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 12 07:01:46 EST 2007


Author: wolfc
Date: 2007-01-12 07:01:37 -0500 (Fri, 12 Jan 2007)
New Revision: 59595

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/BeanContextLifecycleCallback.java
Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/EJBContainerInvocation.java
   trunk/ejb3/src/main/org/jboss/ejb3/EJBContainerInvocationWrapper.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
Log:
EJBTHREE-757: BeanContextLifecycleCallback

Added: trunk/ejb3/src/main/org/jboss/ejb3/BeanContextLifecycleCallback.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/BeanContextLifecycleCallback.java	2007-01-12 08:56:18 UTC (rev 59594)
+++ trunk/ejb3/src/main/org/jboss/ejb3/BeanContextLifecycleCallback.java	2007-01-12 12:01:37 UTC (rev 59595)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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;
+
+/**
+ * The EJBContextLifecycleCallback provides a way to modify the
+ * EJBContext prior to use by the bean.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface BeanContextLifecycleCallback<T extends BeanContext>
+{
+   /**
+    * The context has been attached to a bean instance.
+    * 
+    * @param ctx
+    */
+   void attached(T ctx);
+   
+   /**
+    * The context has been released from a bean instance.
+    * 
+    * @param ctx
+    */
+   void released(T ctx);
+}

Modified: trunk/ejb3/src/main/org/jboss/ejb3/EJBContainerInvocation.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContainerInvocation.java	2007-01-12 08:56:18 UTC (rev 59594)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContainerInvocation.java	2007-01-12 12:01:37 UTC (rev 59595)
@@ -34,9 +34,12 @@
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
  */
-public class EJBContainerInvocation extends MethodInvocation
+public class EJBContainerInvocation<A extends EJBContainer, T extends BeanContext> extends MethodInvocation
 {
-   protected BeanContext ctx;
+   private static final long serialVersionUID = 4941832732679380382L;
+   
+   protected T ctx;
+   private BeanContextLifecycleCallback<T> callback;
 
    public EJBContainerInvocation(MethodInfo info, Interceptor[] interceptors)
    {
@@ -53,30 +56,53 @@
       super(null, null);
    }
 
-   public BeanContext getBeanContext()
+   @SuppressWarnings("unchecked")
+   public A getAdvisor()
    {
+      return (A) super.getAdvisor();
+   }
+   
+   public T getBeanContext()
+   {
       return ctx;
    }
 
-   public void setBeanContext(BeanContext ctx)
+   public void setBeanContext(T ctx)
    {
       this.ctx = ctx;
+      
+      if(callback != null)
+      {
+         if(ctx != null)
+         {
+            callback.attached(ctx);
+         }
+         else
+         {
+            callback.released(ctx);
+         }
+      }
    }
 
    public Invocation getWrapper(Interceptor[] newchain)
    {
-      return new EJBContainerInvocationWrapper(this, newchain);
+      return new EJBContainerInvocationWrapper<A, T>(this, newchain);
    }
 
    public Invocation copy()
    {
-      EJBContainerInvocation wrapper = new EJBContainerInvocation(interceptors, methodHash, advisedMethod, unadvisedMethod, advisor);
+      EJBContainerInvocation<A, T> wrapper = new EJBContainerInvocation<A, T>(interceptors, methodHash, advisedMethod, unadvisedMethod, advisor);
       wrapper.metadata = this.metadata;
       wrapper.currentInterceptor = this.currentInterceptor;
       wrapper.setTargetObject(this.getTargetObject());
       wrapper.setArguments(this.getArguments());
       wrapper.setBeanContext(this.ctx);
+      wrapper.callback = this.callback;
       return wrapper;
    }
-
+   
+   public void setContextCallback(BeanContextLifecycleCallback<T> callback)
+   {
+      this.callback = callback;
+   }
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/EJBContainerInvocationWrapper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContainerInvocationWrapper.java	2007-01-12 08:56:18 UTC (rev 59594)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContainerInvocationWrapper.java	2007-01-12 12:01:37 UTC (rev 59595)
@@ -23,7 +23,6 @@
 
 import java.lang.reflect.Method;
 import java.util.Map;
-import org.jboss.aop.Advisor;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.metadata.SimpleMetaData;
@@ -35,13 +34,15 @@
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
  */
-public class EJBContainerInvocationWrapper extends EJBContainerInvocation
+public class EJBContainerInvocationWrapper<A extends EJBContainer, T extends BeanContext> extends EJBContainerInvocation<A, T>
 {
+   private static final long serialVersionUID = 5402917625526438235L;
+
    private static final Logger log = Logger.getLogger(EJBContainerInvocationWrapper.class);
    
-   protected EJBContainerInvocation wrapped;
+   protected EJBContainerInvocation<A, T> wrapped;
 
-   public EJBContainerInvocationWrapper(EJBContainerInvocation wrapped, Interceptor[] interceptors)
+   public EJBContainerInvocationWrapper(EJBContainerInvocation<A, T> wrapped, Interceptor[] interceptors)
    {
       this.wrapped = wrapped;
       this.interceptors = interceptors;
@@ -166,7 +167,7 @@
       return wrapped.invokeNext(newInterceptors);
    }
 
-   public Advisor getAdvisor()
+   public A getAdvisor()
    {
       return wrapped.getAdvisor();
    }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2007-01-12 08:56:18 UTC (rev 59594)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2007-01-12 12:01:37 UTC (rev 59595)
@@ -36,6 +36,7 @@
 import org.jboss.ejb.AllowedOperationsAssociation;
 import org.jboss.ejb.AllowedOperationsFlags;
 import org.jboss.ejb3.EJBContainerInvocation;
+import org.jboss.ejb3.BeanContextLifecycleCallback;
 import org.jboss.ejb3.Ejb3Deployment;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.ProxyUtils;
@@ -51,6 +52,7 @@
 
 import javax.ejb.EJBException;
 import javax.ejb.Handle;
+import javax.ejb.SessionContext;
 import javax.ejb.Timer;
 import javax.ejb.TimerService;
 import javax.naming.NamingException;
@@ -180,6 +182,11 @@
     */
    public Object localInvoke(Method method, Object[] args, FutureHolder provider) throws Throwable
    {
+      return localInvoke(method, args, provider, null);
+   }
+   
+   public Object localInvoke(Method method, Object[] args, FutureHolder provider, BeanContextLifecycleCallback<StatelessBeanContext> callback) throws Throwable
+   {
       long start = System.currentTimeMillis();
       
       ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
@@ -206,9 +213,10 @@
             }
 
             Interceptor[] aspects = info.getInterceptors();
-            EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info, aspects);
+            EJBContainerInvocation<StatelessContainer, StatelessBeanContext> nextInvocation = new EJBContainerInvocation<StatelessContainer, StatelessBeanContext>(info, aspects);
             nextInvocation.setAdvisor(this);
             nextInvocation.setArguments(args);
+            nextInvocation.setContextCallback(callback);
 
             ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
             return nextInvocation.invokeNext();




More information about the jboss-cvs-commits mailing list