[jboss-cvs] JBossAS SVN: r96721 - in projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3: core/proxy and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 23 05:06:43 EST 2009


Author: wolfc
Date: 2009-11-23 05:06:43 -0500 (Mon, 23 Nov 2009)
New Revision: 96721

Added:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/CurrentRemoteProxyFactory.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/EJB2RemoteProxyFactory.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/RemoteProxyFactory.java
Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
Log:
EJBTHREE-1961: Introduce RemoteProxyFactory SPI

Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/CurrentRemoteProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/CurrentRemoteProxyFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/CurrentRemoteProxyFactory.java	2009-11-23 10:06:43 UTC (rev 96721)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.proxy.spi;
+
+/**
+ * Allows you to specify a ProxyFactory to use for creating the remote proxies.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class CurrentRemoteProxyFactory
+{
+   private static ThreadLocal<RemoteProxyFactory> current = new ThreadLocal<RemoteProxyFactory>();
+   
+   public static RemoteProxyFactory get()
+   {
+      return current.get();
+   }
+   
+   public static <T extends RemoteProxyFactory> T get(Class<T> type)
+   {
+      return type.cast(get());
+   }
+   
+   public static boolean isSet()
+   {
+      return current.get() != null;
+   }
+   
+   public static void remove()
+   {
+      if(!isSet())
+         throw new IllegalStateException("There is no current remote proxy set");
+      current.remove();
+   }
+   
+   public static void set(RemoteProxyFactory factory)
+   {
+      // Normally we would only communicate via one channel, so any recursive call
+      // would still mean the same channel.
+      RemoteProxyFactory previous = current.get();
+      if(previous != null)
+         throw new IllegalStateException("Already have a current remote proxy factory " + previous);
+      
+      current.set(factory);
+   }
+}

Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/EJB2RemoteProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/EJB2RemoteProxyFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/EJB2RemoteProxyFactory.java	2009-11-23 10:06:43 UTC (rev 96721)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.proxy.spi;
+
+import java.io.Serializable;
+
+import javax.ejb.EJBHome;
+import javax.ejb.EJBObject;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface EJB2RemoteProxyFactory extends RemoteProxyFactory
+{
+   EJBObject create(Serializable id);
+   
+   EJBHome createHome();
+}

Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/RemoteProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/RemoteProxyFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/proxy/spi/RemoteProxyFactory.java	2009-11-23 10:06:43 UTC (rev 96721)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.proxy.spi;
+
+import java.io.Serializable;
+
+/**
+ * Create a remote proxy for the given id.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface RemoteProxyFactory
+{
+   Object create(Serializable id);
+}

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java	2009-11-23 09:16:07 UTC (rev 96720)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java	2009-11-23 10:06:43 UTC (rev 96721)
@@ -58,6 +58,8 @@
 import org.jboss.ejb3.common.registrar.spi.Ejb3Registrar;
 import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
 import org.jboss.ejb3.common.registrar.spi.NotBoundException;
+import org.jboss.ejb3.core.proxy.spi.CurrentRemoteProxyFactory;
+import org.jboss.ejb3.core.proxy.spi.EJB2RemoteProxyFactory;
 import org.jboss.ejb3.endpoint.Endpoint;
 import org.jboss.ejb3.endpoint.SessionFactory;
 import org.jboss.ejb3.proxy.clustered.objectstore.ClusteredObjectStoreBindings;
@@ -703,6 +705,8 @@
       Method unadvisedMethod = info.getUnadvisedMethod();
       if(unadvisedMethod.getName().equals("getEJBHome"))
       {
+         if(CurrentRemoteProxyFactory.isSet())
+            return CurrentRemoteProxyFactory.get(EJB2RemoteProxyFactory.class).createHome();
          return this.getInitialContext().lookup(this.getMetaData().getHomeJndiName());
       }
       if(unadvisedMethod.getName().equals("getPrimaryKey"))

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java	2009-11-23 09:16:07 UTC (rev 96720)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java	2009-11-23 10:06:43 UTC (rev 96721)
@@ -20,6 +20,8 @@
 import org.jboss.ejb3.ThreadLocalStack;
 import org.jboss.ejb3.common.lang.SerializableMethod;
 import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.core.proxy.spi.CurrentRemoteProxyFactory;
+import org.jboss.ejb3.core.proxy.spi.RemoteProxyFactory;
 import org.jboss.ejb3.endpoint.Endpoint;
 import org.jboss.ejb3.proxy.impl.factory.session.SessionProxyFactory;
 import org.jboss.ejb3.proxy.impl.factory.session.SessionSpecProxyFactory;
@@ -412,6 +414,14 @@
                + this.getEjbName());
       }
 
+      // Allow override of the remote proxy
+      if(!isLocal)
+      {
+         RemoteProxyFactory remoteProxyFactory = CurrentRemoteProxyFactory.get();
+         if(remoteProxyFactory != null)
+            return remoteProxyFactory.create(null);
+      }
+      
       // Lookup
       String proxyFactoryKey = this.getJndiRegistrar().getProxyFactoryRegistryKey(jndiName, smd, isLocal);
       Object factory = Ejb3RegistrarLocator.locateRegistrar().lookup(proxyFactoryKey);

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java	2009-11-23 09:16:07 UTC (rev 96720)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java	2009-11-23 10:06:43 UTC (rev 96721)
@@ -64,6 +64,9 @@
 import org.jboss.ejb3.cache.StatefulObjectFactory;
 import org.jboss.ejb3.common.lang.SerializableMethod;
 import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.core.proxy.spi.CurrentRemoteProxyFactory;
+import org.jboss.ejb3.core.proxy.spi.EJB2RemoteProxyFactory;
+import org.jboss.ejb3.core.proxy.spi.RemoteProxyFactory;
 import org.jboss.ejb3.endpoint.SessionFactory;
 import org.jboss.ejb3.interceptors.container.StatefulSessionContainerMethodInvocation;
 import org.jboss.ejb3.proxy.clustered.objectstore.ClusteredObjectStoreBindings;
@@ -980,6 +983,16 @@
                + this.getEjbName());
       }
 
+      Serializable sessionId = createSession(method.getParameterTypes(), args);
+      
+      // Allow override of the remote proxy
+      if(!isLocal)
+      {
+         RemoteProxyFactory remoteProxyFactory = CurrentRemoteProxyFactory.get();
+         if(remoteProxyFactory != null)
+            return remoteProxyFactory.create(sessionId);
+      }
+      
       // Lookup
       String proxyFactoryKey = this.getJndiRegistrar().getProxyFactoryRegistryKey(jndiName, smd, isLocal);
       Object factory = Ejb3RegistrarLocator.locateRegistrar().lookup(proxyFactoryKey);
@@ -991,7 +1004,6 @@
       StatefulSessionProxyFactory statefulFactory = null;
       statefulFactory = StatefulSessionProxyFactory.class.cast(factory);
 
-      Serializable sessionId = createSession(method.getParameterTypes(), args);
       Object proxy = statefulFactory.createProxyEjb2x(sessionId);
 
       return proxy;
@@ -1109,30 +1121,38 @@
 
       if (unadvisedMethod.getName().equals("getHandle"))
       {
-         StatefulContainerInvocation newStatefulInvocation = buildInvocation(info, statefulInvocation);
+         EJBObject proxy;
+         if(CurrentRemoteProxyFactory.isSet())
+         {
+            proxy = CurrentRemoteProxyFactory.get(EJB2RemoteProxyFactory.class).create((Serializable) statefulInvocation.getId());
+         }
+         else
+         {
+            StatefulContainerInvocation newStatefulInvocation = buildInvocation(info, statefulInvocation);
+   
+            // Get JNDI Registrar
+            JndiSessionRegistrarBase sfsbJndiRegistrar = this.getJndiRegistrar();
+   
+            // Determine if local/remote
+            boolean isLocal = EJBLocalObject.class.isAssignableFrom(unadvisedMethod.getDeclaringClass());
+   
+            // Get the metadata
+            JBossSessionBeanMetaData smd = this.getMetaData();
+   
+            // Get the appropriate JNDI Name
+            String jndiName = isLocal ? smd.getLocalJndiName() : smd.getJndiName();
+   
+            // Find the Proxy Factory Key for this SFSB
+            String proxyFactoryKey = sfsbJndiRegistrar.getProxyFactoryRegistryKey(jndiName, smd, isLocal);
+   
+            // Lookup the Proxy Factory in the Object Store
+            StatefulSessionProxyFactory proxyFactory = Ejb3RegistrarLocator.locateRegistrar().lookup(proxyFactoryKey,
+                  StatefulSessionProxyFactory.class);
+   
+            // Create a new EJB2.x Proxy
+            proxy = (EJBObject) proxyFactory.createProxyEjb2x((Serializable) newStatefulInvocation.getId());
+         }
 
-         // Get JNDI Registrar
-         JndiSessionRegistrarBase sfsbJndiRegistrar = this.getJndiRegistrar();
-
-         // Determine if local/remote
-         boolean isLocal = EJBLocalObject.class.isAssignableFrom(unadvisedMethod.getDeclaringClass());
-
-         // Get the metadata
-         JBossSessionBeanMetaData smd = this.getMetaData();
-
-         // Get the appropriate JNDI Name
-         String jndiName = isLocal ? smd.getLocalJndiName() : smd.getJndiName();
-
-         // Find the Proxy Factory Key for this SFSB
-         String proxyFactoryKey = sfsbJndiRegistrar.getProxyFactoryRegistryKey(jndiName, smd, isLocal);
-
-         // Lookup the Proxy Factory in the Object Store
-         StatefulSessionProxyFactory proxyFactory = Ejb3RegistrarLocator.locateRegistrar().lookup(proxyFactoryKey,
-               StatefulSessionProxyFactory.class);
-
-         // Create a new EJB2.x Proxy
-         EJBObject proxy = (EJBObject) proxyFactory.createProxyEjb2x((Serializable) newStatefulInvocation.getId());
-
          StatefulHandleRemoteImpl handle = new StatefulHandleRemoteImpl(proxy);
          InvocationResponse response = marshallResponse(statefulInvocation, handle, null);
          return response;
@@ -1158,14 +1178,22 @@
       }
       else if (unadvisedMethod.getName().equals("getEJBHome"))
       {
-         HomeHandleImpl homeHandle = null;
+         EJBHome ejbHome;
+         if(CurrentRemoteProxyFactory.isSet())
+         {
+            ejbHome = CurrentRemoteProxyFactory.get(EJB2RemoteProxyFactory.class).createHome();
+         }
+         else
+         {
+            HomeHandleImpl homeHandle = null;
+   
+            RemoteBinding remoteBindingAnnotation = this.getAnnotation(RemoteBinding.class);
+            if (remoteBindingAnnotation != null)
+               homeHandle = new HomeHandleImpl(ProxyFactoryHelper.getHomeJndiName(this));
+   
+            ejbHome = homeHandle.getEJBHome();
+         }
 
-         RemoteBinding remoteBindingAnnotation = this.getAnnotation(RemoteBinding.class);
-         if (remoteBindingAnnotation != null)
-            homeHandle = new HomeHandleImpl(ProxyFactoryHelper.getHomeJndiName(this));
-
-         EJBHome ejbHome = homeHandle.getEJBHome();
-
          InvocationResponse response = marshallResponse(statefulInvocation, ejbHome, null);
          return response;
       }

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java	2009-11-23 09:16:07 UTC (rev 96720)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java	2009-11-23 10:06:43 UTC (rev 96721)
@@ -58,6 +58,8 @@
 import org.jboss.ejb3.annotation.RemoteHomeBinding;
 import org.jboss.ejb3.common.lang.SerializableMethod;
 import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.core.proxy.spi.CurrentRemoteProxyFactory;
+import org.jboss.ejb3.core.proxy.spi.EJB2RemoteProxyFactory;
 import org.jboss.ejb3.proxy.clustered.objectstore.ClusteredObjectStoreBindings;
 import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
 import org.jboss.ejb3.proxy.impl.EJBMetaDataImpl;
@@ -473,28 +475,36 @@
       Method unadvisedMethod = info.getUnadvisedMethod();
       if (unadvisedMethod.getName().equals("getHandle"))
       {
-         // Get JNDI Registrar
-         JndiSessionRegistrarBase slsbJndiRegistrar = this.getJndiRegistrar();
-
-         // Determine if local/remote
-         boolean isLocal = EJBLocalObject.class.isAssignableFrom(unadvisedMethod.getDeclaringClass());
+         EJBObject proxy;
+         if(CurrentRemoteProxyFactory.isSet())
+         {
+            proxy = CurrentRemoteProxyFactory.get(EJB2RemoteProxyFactory.class).create(null);
+         }
+         else
+         {
+            // Get JNDI Registrar
+            JndiSessionRegistrarBase slsbJndiRegistrar = this.getJndiRegistrar();
+   
+            // Determine if local/remote
+            boolean isLocal = EJBLocalObject.class.isAssignableFrom(unadvisedMethod.getDeclaringClass());
+            
+            // Get the metadata
+            JBossSessionBeanMetaData smd = this.getMetaData();
+   
+            // Get the appropriate JNDI Name
+            String jndiName = isLocal ? smd.getLocalJndiName() : smd.getJndiName();
+   
+            // Find the Proxy Factory Key for this SLSB
+            String proxyFactoryKey = slsbJndiRegistrar.getProxyFactoryRegistryKey(jndiName, smd, isLocal);
+   
+            // Lookup the Proxy Factory in the Object Store
+            StatelessSessionProxyFactoryBase proxyFactory = Ejb3RegistrarLocator.locateRegistrar().lookup(proxyFactoryKey,
+                  StatelessSessionProxyFactoryBase.class);
+   
+            // Create a new EJB2.x Proxy
+            proxy = (EJBObject) proxyFactory.createProxyEjb2x();
+         }
          
-         // Get the metadata
-         JBossSessionBeanMetaData smd = this.getMetaData();
-
-         // Get the appropriate JNDI Name
-         String jndiName = isLocal ? smd.getLocalJndiName() : smd.getJndiName();
-
-         // Find the Proxy Factory Key for this SLSB
-         String proxyFactoryKey = slsbJndiRegistrar.getProxyFactoryRegistryKey(jndiName, smd, isLocal);
-
-         // Lookup the Proxy Factory in the Object Store
-         StatelessSessionProxyFactoryBase proxyFactory = Ejb3RegistrarLocator.locateRegistrar().lookup(proxyFactoryKey,
-               StatelessSessionProxyFactoryBase.class);
-
-         // Create a new EJB2.x Proxy
-         EJBObject proxy = (EJBObject) proxyFactory.createProxyEjb2x();
-
          // Create a Handle
          StatelessHandleRemoteImpl handle = new StatelessHandleRemoteImpl(proxy);
 
@@ -507,6 +517,10 @@
       }
       else if (unadvisedMethod.getName().equals("getEJBHome"))
       {
+         if(CurrentRemoteProxyFactory.isSet())
+         {
+            return CurrentRemoteProxyFactory.get(EJB2RemoteProxyFactory.class).createHome();
+         }
          HomeHandleImpl homeHandle = null;
 
          RemoteBinding remoteBindingAnnotation = this.getAnnotation(RemoteBinding.class);




More information about the jboss-cvs-commits mailing list