[jboss-cvs] JBossAS SVN: r78696 - in projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy: objectfactory and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 19 03:13:28 EDT 2008


Author: ALRubinger
Date: 2008-09-19 03:13:28 -0400 (Fri, 19 Sep 2008)
New Revision: 78696

Modified:
   projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java
   projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/ProxyFactoryReferenceAddressTypes.java
   projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/ProxyObjectFactory.java
Log:
[EJBTHREE-1403] Denote Proxies as local/remote

Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java	2008-09-19 07:10:18 UTC (rev 78695)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java	2008-09-19 07:13:28 UTC (rev 78696)
@@ -218,7 +218,7 @@
       {
          // Obtain RemoteBinding URL
          List<RemoteBindingMetaData> bindings = smd.getRemoteBindings();
-         
+
          // Get Client Bind URL
          RemoteBindingMetaData remoteBinding = null;
          String url = null;
@@ -238,7 +238,7 @@
             remoteBinding = new RemoteBindingMetaData();
             smd.getRemoteBindings().add(remoteBinding);
          }
-         
+
          // If no explicit Client Bind URL is specified
          if (url == null || url.trim().equals(""))
          {
@@ -285,7 +285,7 @@
                   ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_REMOTE, homeType);
             RefAddr refAddrRemoting = this.createRemotingRefAddr(smd);
             Reference homeRef = createStandardReference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
-                  + homeType, remoteProxyFactoryKey, containerName);
+                  + homeType, remoteProxyFactoryKey, containerName, false);
             homeRef.add(refAddrHomeInterface);
             homeRef.add(refAddrRemoting);
 
@@ -309,7 +309,7 @@
 
          // Create a Reference
          Reference defaultRemoteRef = createStandardReference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
-               + defaultRemoteClassName, remoteProxyFactoryKey, containerName);
+               + defaultRemoteClassName, remoteProxyFactoryKey, containerName, false);
 
          // Add all Reference Addresses for Default Remote Reference
          for (RefAddr refAddr : refAddrsForDefaultRemote)
@@ -336,7 +336,7 @@
                      ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_REMOTE, businessRemote);
                RefAddr refAddrRemoting = this.createRemotingRefAddr(smd);
                Reference ref = createStandardReference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
-                     + businessRemote, remoteProxyFactoryKey, containerName);
+                     + businessRemote, remoteProxyFactoryKey, containerName, false);
                ref.add(refAddrBusinessInterface);
                ref.add(refAddrRemoting);
                String address = JbossSessionBeanJndiNameResolver.resolveJndiName(smd, businessRemote);
@@ -386,7 +386,7 @@
             RefAddr refAddr = new StringRefAddr(
                   ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_EJB2x_INTERFACE_HOME_LOCAL, localHomeType);
             Reference localHomeRef = createStandardReference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
-                  + localHomeType, localProxyFactoryKey, containerName);
+                  + localHomeType, localProxyFactoryKey, containerName, true);
             localHomeRef.add(refAddr);
             String localHomeAddress = smd.getLocalHomeJndiName();
             log.debug("Local Home View for EJB " + smd.getEjbName() + " to be bound into JNDI at \"" + localHomeAddress
@@ -404,7 +404,7 @@
 
          // Create a Reference
          Reference defaultLocalRef = createStandardReference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
-               + defaultLocalClassName, localProxyFactoryKey, containerName);
+               + defaultLocalClassName, localProxyFactoryKey, containerName, true);
 
          // Add all Reference Addresses for Default Local Reference
          for (RefAddr refAddr : refAddrsForDefaultLocal)
@@ -430,7 +430,7 @@
                RefAddr refAddr = new StringRefAddr(
                      ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_LOCAL, businessLocal);
                Reference ref = createStandardReference(JndiSessionRegistrarBase.OBJECT_FACTORY_CLASSNAME_PREFIX
-                     + businessLocal, localProxyFactoryKey, containerName);
+                     + businessLocal, localProxyFactoryKey, containerName, true);
                ref.add(refAddr);
                String address = JbossSessionBeanJndiNameResolver.resolveJndiName(smd, businessLocal);
                log.debug("Local Business View for " + businessLocal + " of EJB " + smd.getEjbName()
@@ -615,7 +615,7 @@
     * target EJB Container Name as ReferenceAddresses.
     */
    protected Reference createStandardReference(String referenceName, String proxyFactoryRegistryKey,
-         String containerName)
+         String containerName, boolean isLocal)
    {
       Reference ref = new Reference(referenceName, this.getSessionProxyObjectFactoryType(), null);
 
@@ -635,6 +635,12 @@
       log.debug("Adding " + RefAddr.class.getSimpleName() + " to " + Reference.class.getSimpleName() + ": Type \""
             + ejbContainerRefType + "\", Content \"" + containerName + "\"");
 
+      // Add a RefAddr to mark local/remote
+      String isLocalRefAddrType = ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_IS_LOCAL;
+      RefAddr isLocalRefAddr = new StringRefAddr(isLocalRefAddrType, Boolean.toString(isLocal));
+      ref.add(isLocalRefAddr);
+
+      // Return
       return ref;
    }
 
@@ -813,7 +819,7 @@
       assert bindings != null && bindings.size() > 0 : "Remote Bindings are required and none are present";
       RemoteBindingMetaData remoteBinding = smd.getRemoteBindings().get(0);
 
-      // Create RefAddr
+      // Create RefAddr for InvokerLocator
       String url = remoteBinding.getClientBindUrl();
       assert url != null && url.trim().toString().length() != 0 : InvokerLocator.class.getSimpleName()
             + " URL must be defined, and is unspecified";

Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/ProxyFactoryReferenceAddressTypes.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/ProxyFactoryReferenceAddressTypes.java	2008-09-19 07:10:18 UTC (rev 78695)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/ProxyFactoryReferenceAddressTypes.java	2008-09-19 07:13:28 UTC (rev 78696)
@@ -86,5 +86,7 @@
     */
    
    String REF_ADDR_TYPE_INVOKER_LOCATOR_URL = "Remoting Host URL";
+   
+   String REF_ADDR_TYPE_IS_LOCAL = "Proxy Factory is Local";
 
 }

Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/ProxyObjectFactory.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/ProxyObjectFactory.java	2008-09-19 07:10:18 UTC (rev 78695)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/ProxyObjectFactory.java	2008-09-19 07:13:28 UTC (rev 78696)
@@ -23,7 +23,6 @@
 
 import java.io.Serializable;
 import java.lang.reflect.Proxy;
-import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -114,35 +113,38 @@
       // Obtain Proxy Factory
       ProxyFactory proxyFactory = null;
 
-      try
+      // Determine if Remote or Local (EJBTHREE-1403)
+      String isLocalStringFromRefAddr = this.getSingleRequiredReferenceAddressValue(name, refAddrs,
+            ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_IS_LOCAL);
+      assert isLocalStringFromRefAddr != null && isLocalStringFromRefAddr.trim().length() > 0 : "Required "
+            + RefAddr.class.getSimpleName() + " \"" + ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_IS_LOCAL
+            + "\" was not found at JNDI Name " + name;
+      boolean isLocal = new Boolean(isLocalStringFromRefAddr);
+
+      // If this is local
+      if (isLocal)
       {
-         // Attempt to get local EJB3 Registrar
-         //TODO EJBTHREE-1403
-         // This is the wrong way to determine local/remote 
-         Ejb3Registrar registrar = Ejb3RegistrarLocator.locateRegistrar();
+         try
+         {
+            // Get local EJB3 Registrar 
+            Ejb3Registrar registrar = Ejb3RegistrarLocator.locateRegistrar();
 
-         // Local lookup succeeded, so use it
-         // BES 2008/08/22 -- a NotBoundException doesn't mean failure, just
-         // means the container isn't deployed in this server. So don't catch it
-         // in an inner try/catch; let it propagate to the outer catch.
-         // This may or may not be the proper fix for EJBTHREE-1403, but it allows
-         // clustering unit tests to pass.
-//         try
-//         {
             Object pfObj = registrar.lookup(proxyFactoryRegistryKey);
             assert pfObj != null : ProxyFactory.class.getName() + " from key " + proxyFactoryRegistryKey + " was null";
             assert pfObj instanceof ProxyFactory : " Object obtained from key " + proxyFactoryRegistryKey
                   + " was expected to be of type " + ProxyFactory.class.getName() + " but was instead " + pfObj;
             proxyFactory = (ProxyFactory) pfObj;
-//         }
-//         catch (NotBoundException nbe)
-//         {
-//            throw new RuntimeException("Could not obtain " + ProxyFactory.class.getSimpleName()
-//                  + " from expected key \"" + proxyFactoryRegistryKey + "\"", nbe);
-//         }
+         }
+         // BES 2008/08/22 -- a NotBoundException doesn't mean failure, just
+         // means the container isn't deployed in this server. So don't catch it
+         // in an inner try/catch; let it propagate to the outer catch.
+         catch (NotBoundException nbe)
+         {
+            proxyFactory = createProxyFactoryProxy(name, refAddrs, proxyFactoryRegistryKey);
+         }
       }
       // Registrar is not local, so use Remoting to Obtain Proxy Factory
-      catch (NotBoundException nbe)
+      else
       {
          proxyFactory = createProxyFactoryProxy(name, refAddrs, proxyFactoryRegistryKey);
       }
@@ -168,20 +170,27 @@
          String proxyFactoryRegistryKey) throws Exception
    {
       // Obtain the URL for invoking upon the Registry
-      String url = this.getSingleRequiredReferenceAddressValue(name, refAddrs,
+      String url = this.getSingleReferenceAddressValue(name, refAddrs,
             ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_INVOKER_LOCATOR_URL);
 
       // Create an InvokerLocator
-      assert url != null && !url.trim().equals("") : InvokerLocator.class.getSimpleName()
-            + " URL is required, but is not specified; improperly bound reference in JNDI";
+      assert url != null && url.trim().length() != 0 : InvokerLocator.class.getSimpleName()
+            + " URL is required, but is not specified; improperly bound reference "
+            + "in JNDI or looking up local Proxy from Remote JVM";
+      if (url == null || url.trim().length() == 0)
+      {
+         throw new RuntimeException("Could not find " + InvokerLocator.class.getSimpleName()
+               + " URL at JNDI address \"" + name + "\"; looking up local Proxy from Remote JVM?");
+      }
       InvokerLocator locator = new InvokerLocator(url);
 
       // Create a POJI Proxy to the Registrar
       Interceptor[] interceptors =
       {IsLocalProxyFactoryInterceptor.singleton, InvokeRemoteInterceptor.singleton};
       PojiProxy handler = new PojiProxy(proxyFactoryRegistryKey, locator, interceptors);
-      Class<?>[] interfaces = new Class<?>[]{this.getProxyFactoryClass()};
-      
+      Class<?>[] interfaces = new Class<?>[]
+      {this.getProxyFactoryClass()};
+
       return (ProxyFactory) Proxy.newProxyInstance(interfaces[0].getClassLoader(), interfaces, handler);
    }
 
@@ -201,7 +210,7 @@
       // Get the value
       String value = this.getSingleReferenceAddressValue(name, referenceAddresses, refAddrType);
       assert (value != null && !value.trim().equals("")) : "Exactly one " + RefAddr.class.getSimpleName() + " of type "
-            + refAddrType + " must be defined for Name " + name.toString() +", none found";
+            + refAddrType + " must be defined for Name " + name.toString() + ", none found";
 
       // Return
       return value;




More information about the jboss-cvs-commits mailing list