[jboss-cvs] JBossAS SVN: r64725 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/main/org/jboss/ejb3 and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 20 18:00:07 EDT 2007


Author: bdecoste
Date: 2007-08-20 18:00:07 -0400 (Mon, 20 Aug 2007)
New Revision: 64725

Modified:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/build.xml
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/LocalProxy.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxy.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxy.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/localfromremote/unit/LocalTestCase.java
Log:
[EJBTHREE-1019] StatefulLocalProxyFactory is Externalizable - no more NonSerialableFactory

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build.xml	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build.xml	2007-08-20 22:00:07 UTC (rev 64725)
@@ -325,7 +325,7 @@
       <!-- build client-jar -->
       <jar jarfile="${build.lib}/jboss-ejb3-client.jar" manifest="${build.etc}/default.mf">
          <fileset dir="${build.classes}">
-            <include name="org/jboss/ejb3/EJB3Util.class"/>
+         	<include name="org/jboss/ejb3/EJB3Util.class"/>
             <include name="org/jboss/ejb3/Ejb3Registry.class"/>
             <include name="org/jboss/ejb3/InitialContextFactory.class"/>
             <include name="org/jboss/ejb3/asynchronous/*"/>
@@ -339,10 +339,10 @@
             <include name="org/jboss/ejb3/stateful/StatefulRemoteInvocation.class"/>
             <include name="org/jboss/ejb3/ProxyUtils.class"/>
             <include name="org/jboss/ejb3/**/*Proxy.class"/>
-            <!--exclude name="org/jboss/ejb3/**/*LocalProxy.class"/-->
             <include name="org/jboss/ejb3/**/*HandleImpl.class"/>
-            <include name="org/jboss/ejb3/Container.class"/>
-            <include name="org/jboss/ejb3/*ProxyFactory.class"/>
+            <include name="org/jboss/ejb3/*Container.class"/>
+         	<include name="org/jboss/ejb3/stateful/StatefulContainer.class"/>
+            <include name="org/jboss/ejb3/**/*ProxyFactory.class"/>
             <include name="org/jboss/ejb3/proxy/**/*.class"/>
             <include name="org/jboss/ejb3/*ServiceServer*.class"/>
             <include name="org/jboss/ejb3/*KernelAbstraction*.class"/>

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -495,6 +495,8 @@
     */
    public String getPartitionName()
    {
+      if (partitionName == null)
+         this.findPartitionName();
       return partitionName;
    }
 

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/LocalProxy.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/LocalProxy.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/LocalProxy.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -40,7 +40,7 @@
 {
    private static Logger log = Logger.getLogger(LocalProxy.class);
    
-   protected transient Container container = null;
+   private transient Container container = null;
    protected String containerClusterUid;
    protected String containerGuid;
    protected String proxyName;

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -73,7 +73,7 @@
          return ret;
       }
 
-      ServiceContainer sc = (ServiceContainer) container;
+      ServiceContainer sc = (ServiceContainer) getContainer();
       return sc.localInvoke(method, args, (FutureHolder) provider);
    }
 
@@ -84,7 +84,7 @@
       {
          Class[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
          AsynchMixin mixin = new AsynchMixin();
-         ServiceLocalProxy handler = new ServiceLocalProxy(mixin, container);
+         ServiceLocalProxy handler = new ServiceLocalProxy(mixin, getContainer());
          return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
       }
 
@@ -108,7 +108,7 @@
 
    public String toString()
    {
-      return container.getEjbName().toString();
+      return proxyName;
    }
 
 }

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -21,19 +21,26 @@
  */
 package org.jboss.ejb3.session;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+
+import javax.ejb.EJBException;
 import javax.ejb.EJBMetaData;
 import javax.ejb.Handle;
 import javax.ejb.HomeHandle;
 import javax.ejb.Remote;
 import javax.ejb.RemoteHome;
 import org.jboss.annotation.ejb.RemoteBinding;
-import org.jboss.aop.Advisor;
 import org.jboss.ejb3.Container;
+import org.jboss.ejb3.Ejb3Registry;
 import org.jboss.ejb3.EJBContainer;
 import org.jboss.ejb3.ProxyFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.logging.Logger;
-import org.jboss.util.StringPropertyReplacer;
 import org.jboss.ejb3.proxy.EJBMetaDataImpl;
 import org.jboss.ejb3.proxy.handle.HomeHandleImpl;
 
@@ -43,12 +50,17 @@
  * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
  * @version $Revision$
  */
-public abstract class BaseSessionProxyFactory implements ProxyFactory
+public abstract class BaseSessionProxyFactory implements ProxyFactory, Externalizable
 {
    private static final Logger log = Logger.getLogger(BaseSessionProxyFactory.class);
    
-   protected Container container;
-   protected Advisor advisor;
+   private transient Container container;
+   protected String containerGuid;
+   protected String containerClusterUid;
+   protected boolean isClustered = false;
+   protected String jndiName;
+   protected Class proxyClass;
+   protected transient Constructor proxyConstructor;
   
    public Object createHomeProxy()
    {
@@ -58,18 +70,31 @@
    public void setContainer(Container container)
    {
       this.container = container;
-      this.advisor = (Advisor) container;
+      this.containerGuid = Ejb3Registry.guid(container);
+      this.containerClusterUid = Ejb3Registry.clusterUid(container);
+      this.isClustered = container.isClustered();
    }
    
+   protected Container getContainer()
+   {
+      if (container == null)
+      {
+         container = Ejb3Registry.findContainer(containerGuid);
+         
+         if (container == null && isClustered)
+            container = Ejb3Registry.getClusterContainer(containerClusterUid);
+      }
+      
+      return container;
+   }
+   
    protected void setEjb21Objects(BaseSessionRemoteProxy proxy)
    {
       proxy.setHandle(getHandle());
       proxy.setHomeHandle(getHomeHandle());
       proxy.setEjbMetaData(getEjbMetaData());
    }
-   
-   abstract protected Handle getHandle();
-   
+     
    protected HomeHandle getHomeHandle()
    {
       EJBContainer ejbContainer = (EJBContainer)container;
@@ -106,4 +131,44 @@
       
       return metadata;
    }
+   
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      containerGuid = in.readUTF();
+      containerClusterUid = in.readUTF();
+      isClustered = in.readBoolean();
+      jndiName = in.readUTF();
+      proxyClass = (Class)in.readObject();
+      
+      try
+      {
+         if (getContainer() == null)
+            throw new EJBException("Invalid (i.e. remote) invocation of local interface (null container) for " + containerGuid);
+         else
+         {
+            Class[] interfaces = getInterfaces();
+            Class proxyClass = java.lang.reflect.Proxy.getProxyClass(getContainer().getBeanClass().getClassLoader(), interfaces);
+            final Class[] constructorParams = {InvocationHandler.class};
+            proxyConstructor = proxyClass.getConstructor(constructorParams);
+         }
+         
+      }
+      catch (NoSuchMethodException e)
+      {
+         throw new RuntimeException("Unable to read Externalized proxy " + e);
+      }
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      out.writeUTF(containerGuid);
+      out.writeUTF(containerClusterUid);
+      out.writeBoolean(isClustered);
+      out.writeUTF(jndiName);
+      out.writeObject(proxyClass);
+   }
+   
+   protected abstract Class[] getInterfaces();
+   
+   abstract protected Handle getHandle();
 }

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -21,6 +21,9 @@
  */
 package org.jboss.ejb3.stateful;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import javax.naming.Context;
@@ -44,18 +47,13 @@
 {
    private static final Logger log = Logger.getLogger(BaseStatefulProxyFactory.class);
 
-   protected Class proxyClass;
-   protected Constructor proxyConstructor;
-   protected Context proxyFactoryContext;
-   protected String jndiName;
-
    public static final String PROXY_FACTORY_NAME = "StatefulProxyFactory";
 
    public void init() throws Exception
    {
       initializeJndiName();
       Class[] interfaces = getInterfaces();
-      Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
+      Class proxyClass = java.lang.reflect.Proxy.getProxyClass(getContainer().getBeanClass().getClassLoader(), interfaces);
       final Class[] constructorParams =
               {InvocationHandler.class};
       proxyConstructor = proxyClass.getConstructor(constructorParams);
@@ -65,7 +63,7 @@
    {
       init();
 
-      Context ctx = container.getInitialContext();
+      Context ctx = getContainer().getInitialContext();
       Name name = ctx.getNameParser("").parse(jndiName);
       ctx = Util.createSubcontext(ctx, name.getPrefix(name.size() - 1));
       String atom = name.get(name.size() - 1);
@@ -76,7 +74,7 @@
          Util.rebind(ctx, atom, ref);
       } catch (NamingException e)
       {
-         NamingException namingException = new NamingException("Could not bind stateful proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + ctx.getNameInNamespace() + "/" + atom);
+         NamingException namingException = new NamingException("Could not bind stateful proxy with ejb name " + getContainer().getEjbName() + " into JNDI under jndiName: " + ctx.getNameInNamespace() + "/" + atom);
          namingException.setRootCause(e);
          throw namingException;
       }
@@ -84,10 +82,18 @@
 
    public void stop() throws Exception
    {
-      Util.unbind(container.getInitialContext(), jndiName);
+      Util.unbind(getContainer().getInitialContext(), jndiName);
    }
 
-   protected abstract Class[] getInterfaces();
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      super.readExternal(in);
+   }
 
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      super.writeExternal(out);     
+   }
+
    protected abstract void initializeJndiName();
 }

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -80,7 +80,7 @@
 
    protected Class[] getInterfaces()
    {
-      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
+      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(getContainer());
       Class[] interfaces = new Class[remoteInterfaces.length + 1];
       System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length);
       interfaces[remoteInterfaces.length] = JBossProxy.class;
@@ -89,21 +89,21 @@
 
    protected void initializeJndiName()
    {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
+      jndiName = ProxyFactoryHelper.getRemoteJndiName(getContainer(), binding);
    }
 
    public void start() throws Exception
    {
       String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
-      Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class);
+      Clustered clustered = (Clustered) ((Advisor)getContainer()).resolveAnnotation(Clustered.class);
       if (clustered == null) throw new RuntimeException("Could not find @Clustered annotation.  Cannot deploy.");
-      String partitionName = ((StatefulContainer) container).getPartitionName();
-      proxyFamilyName = ((StatefulContainer) container).getDeploymentQualifiedName() + locator.getProtocol() + partitionName;
-      HAPartition partition = (HAPartition) container.getInitialContext().lookup("/HAPartition/" + partitionName);
+      String partitionName = ((StatefulContainer) getContainer()).getPartitionName();
+      proxyFamilyName = ((StatefulContainer) getContainer()).getDeploymentQualifiedName() + locator.getProtocol() + partitionName;
+      HAPartition partition = (HAPartition) getContainer().getInitialContext().lookup("/HAPartition/" + partitionName);
       hatarget = new HATarget(partition, proxyFamilyName, locator, HATarget.ENABLE_INVOCATIONS);
       ClusteringTargetsRepository.initTarget(proxyFamilyName, hatarget.getReplicants());
-      ((StatefulContainer) container).getClusterFamilies().put(proxyFamilyName, hatarget);
+      ((StatefulContainer) getContainer()).getClusterFamilies().put(proxyFamilyName, hatarget);
       if (clustered.loadBalancePolicy() == null || clustered.loadBalancePolicy().equals(LoadBalancePolicy.class))
       {
          lbPolicy = new FirstAvailable();
@@ -124,10 +124,10 @@
       Object factoryProxy = Remoting.createPojiProxy(targetId, interfaces, ProxyFactoryHelper.getClientBindUrl(binding));
       try
       {
-         Util.rebind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
+         Util.rebind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
       } catch (NamingException e)
       {
-         NamingException namingException = new NamingException("Could not bind stateful cluster proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
+         NamingException namingException = new NamingException("Could not bind stateful cluster proxy with ejb name " + getContainer().getEjbName() + " into JNDI under jndiName: " + getContainer().getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
          namingException.setRootCause(e);
          throw namingException;
       }
@@ -140,15 +140,15 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          String stackName = "ClusteredStatefulSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
             stackName = binding.interceptorStack();
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
-         String partitionName = ((StatefulContainer) container).getPartitionName();
-         Object[] args = {new StatefulClusteredProxy(container, stack.createInterceptors((Advisor) container, null), 
+         String partitionName = ((StatefulContainer) getContainer()).getPartitionName();
+         Object[] args = {new StatefulClusteredProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), 
                wrapper, lbPolicy, partitionName)};
          
          return proxyConstructor.newInstance(args);
@@ -181,15 +181,15 @@
       Dispatcher.singleton.unregisterTarget(getTargetId());
       hatarget.destroy();
       drm.unregisterListener(proxyFamilyName, this);
-      ((StatefulContainer) container).getClusterFamilies().remove(proxyFamilyName);
-      Util.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
+      ((StatefulContainer) getContainer()).getClusterFamilies().remove(proxyFamilyName);
+      Util.unbind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME);
       super.stop();
    }
    
    protected StatefulHandleImpl getHandle()
    {
       StatefulHandleImpl handle = new StatefulHandleImpl();
-      RemoteBinding remoteBinding = (RemoteBinding)advisor.resolveAnnotation(RemoteBinding.class);
+      RemoteBinding remoteBinding = (RemoteBinding)((Advisor)getContainer()).resolveAnnotation(RemoteBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
  
@@ -202,7 +202,7 @@
    protected String getTargetId()
    {
       assert jndiName != null : "jndiName is null";      
-      String partition = ((StatefulContainer) container).getPartitionName();
+      String partition = ((StatefulContainer) getContainer()).getPartitionName();
       return jndiName + PROXY_FACTORY_NAME + "@" + partition;
    }
    

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -47,7 +47,7 @@
    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable
    {
-      StatefulContainer sfsb = (StatefulContainer) container;
+      StatefulContainer sfsb = (StatefulContainer) getContainer();
       return sfsb.localHomeInvoke(method, args);
    }
 
@@ -58,7 +58,7 @@
 
    public String toString()
    {
-      return container.getObjectName().getCanonicalName() + ": Home Proxy";
+      return proxyName + ": Home Proxy";
    }
 
 }

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxy.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxy.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxy.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -27,13 +27,18 @@
 import java.io.ObjectInput;
 import java.io.IOException;
 import java.io.ObjectOutput;
+import java.rmi.dgc.VMID;
+
+import javax.ejb.EJBException;
+
 import org.jboss.aspects.asynch.AsynchMixin;
 import org.jboss.aspects.asynch.AsynchProvider;
 import org.jboss.aspects.asynch.FutureHolder;
 import org.jboss.ejb3.Container;
+import org.jboss.ejb3.Ejb3Registry;
 import org.jboss.ejb3.LocalProxy;
 import org.jboss.ejb3.ProxyUtils;
-import org.jboss.util.id.GUID;
+import org.jboss.logging.Logger;
 
 /**
  * Comment
@@ -47,13 +52,14 @@
    
    protected Object id;
    AsynchProvider provider;
+   protected boolean isClustered = false;
 
-
-
-   public StatefulLocalProxy(Container container, Object id)
+   public StatefulLocalProxy(Container container, Object id, VMID vmid)
    {
       super(container);
       this.id = id;
+      this.containerGuid = Ejb3Registry.guid(container, vmid);
+      isClustered = ((StatefulContainer)container).isClustered();
    }
 
    public StatefulLocalProxy(AsynchProvider provider, Container container, Object id)
@@ -61,17 +67,20 @@
       super(container);
       this.provider = provider;
       this.id = id;
+      this.containerGuid = Ejb3Registry.guid(container);
+      isClustered = ((StatefulContainer)container).isClustered();
    }
 
    public StatefulLocalProxy()
    {
    }
 
-   //@Override
+   // @Override
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
    {
       super.readExternal(in);
       id = in.readObject();
+      isClustered = in.readBoolean();
    }
 
    //@Override
@@ -79,6 +88,7 @@
    {
       super.writeExternal(out);
       out.writeObject(id);
+      out.writeBoolean(isClustered);
    }
 
    public Object invoke(Object proxy, Method method, Object[] args)
@@ -90,13 +100,20 @@
       }
 
       //Make sure we get the cache id before getting the asynchronous interface
-      StatefulContainer sfsb = (StatefulContainer) getContainer();
       Object ret = ProxyUtils.handleCallLocally(proxy, this, method, args);
       if (ret != null)
       {
          return ret;
       }
-
+      
+      Container container = Ejb3Registry.findContainer(containerGuid);
+      if (isClustered && container == null && Ejb3Registry.hasClusterContainer(containerClusterUid))
+         container = Ejb3Registry.getClusterContainer(containerClusterUid);
+       
+      if (container == null)
+         throw new EJBException("Invalid (i.e. remote) invocation of local interface (null container) for " + containerGuid);
+   
+      StatefulContainer sfsb = (StatefulContainer)container;
       return sfsb.localInvoke(id, method, args, (FutureHolder) provider);
    }
 
@@ -117,16 +134,12 @@
 
    public String toString()
    {
-      if (id != null)
+      if (getContainer() != null && id != null)
       {
          return getContainer().getEjbName().toString() + ":" + id.toString();
       }
-      else
-      {
-         //If the proxy has not been used yet, create a temporary id 
-         GUID guid = new GUID();
-         return getContainer().getEjbName().toString() + ":" + guid.toString();
-      }
+
+      return proxyName;
    }
 
 }

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -21,15 +21,24 @@
  */
 package org.jboss.ejb3.stateful;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.lang.reflect.InvocationTargetException;
+import java.rmi.dgc.VMID;
+
+import javax.ejb.EJBException;
 import javax.ejb.LocalHome;
 import javax.naming.NamingException;
 import org.jboss.annotation.ejb.LocalBinding;
+import org.jboss.aop.Advisor;
+import org.jboss.ejb3.Container;
 import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.Ejb3Registry;
 import org.jboss.ejb3.JBossProxy;
-import org.jboss.ejb3.NonSerializableFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.logging.Logger;
+import org.jboss.naming.Util;
 
 
 /**
@@ -41,12 +50,14 @@
 public class StatefulLocalProxyFactory extends BaseStatefulProxyFactory
 {
    private static final Logger log = Logger.getLogger(StatefulLocalProxyFactory.class);
+   
+   private VMID vmid = Ejb3Registry.getVMID();
 
    protected Class[] getInterfaces()
    {
       Class[] interfaces;
       
-      StatefulContainer statefulContainer = (StatefulContainer) container;
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
       LocalHome localHome = (LocalHome) statefulContainer.resolveAnnotation(LocalHome.class);
       
       boolean bindTogether = false;
@@ -54,7 +65,7 @@
       if (localHome != null && bindHomeAndBusinessTogether(statefulContainer))
          bindTogether = true;
       
-      Class[] localInterfaces = ProxyFactoryHelper.getLocalInterfaces(container);
+      Class[] localInterfaces = ProxyFactoryHelper.getLocalInterfaces(getContainer());
       if (bindTogether)
          interfaces = new Class[localInterfaces.length + 3];
       else
@@ -77,8 +88,13 @@
 
    protected void initializeJndiName()
    {
-      jndiName = ProxyFactoryHelper.getLocalJndiName(container);
+      jndiName = ProxyFactoryHelper.getLocalJndiName(getContainer());
    }
+   
+   public VMID getVMID()
+   {
+      return vmid;
+   }
 
    public void start() throws Exception
    {
@@ -86,36 +102,36 @@
 
       try
       {
-         NonSerializableFactory.rebind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, this);
+         Util.rebind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME, this);
       }
       catch (NamingException e)
       {
-         NamingException namingException = new NamingException("Could not bind stateful local proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
+         NamingException namingException = new NamingException("Could not bind stateful local proxy with ejb name " + getContainer().getEjbName() + " into JNDI under jndiName: " + getContainer().getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
          namingException.setRootCause(e);
          throw namingException;
       }
 
-      StatefulContainer statefulContainer = (StatefulContainer) container;
-      LocalHome localHome = (LocalHome) ((EJBContainer) container).resolveAnnotation(LocalHome.class);
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
+      LocalHome localHome = (LocalHome) ((EJBContainer) getContainer()).resolveAnnotation(LocalHome.class);
       if (localHome != null  && !bindHomeAndBusinessTogether(statefulContainer))
       {
          Class[] interfaces = {localHome.value()};
-         Object homeProxy = java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(),
-                                                                     interfaces, new StatefulLocalHomeProxy(container));
-         NonSerializableFactory.rebind(container.getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(container), homeProxy);
+         Object homeProxy = java.lang.reflect.Proxy.newProxyInstance(getContainer().getBeanClass().getClassLoader(),
+                                                                     interfaces, new StatefulLocalHomeProxy(getContainer()));
+         Util.rebind(getContainer().getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(getContainer()), homeProxy);
       }
    }
 
    public void stop() throws Exception
    {
       super.stop();
-      NonSerializableFactory.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
+      Util.unbind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME);
       
-      StatefulContainer statefulContainer = (StatefulContainer) container;
-      LocalHome localHome = (LocalHome) ((EJBContainer) container).resolveAnnotation(LocalHome.class);
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
+      LocalHome localHome = (LocalHome) ((EJBContainer) getContainer()).resolveAnnotation(LocalHome.class);
       if (localHome != null  && !bindHomeAndBusinessTogether(statefulContainer))
       {
-         NonSerializableFactory.unbind(container.getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(container));
+         Util.unbind(getContainer().getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(getContainer()));
       }
    }
 
@@ -123,11 +139,11 @@
    {
       try
       {
-         StatefulContainer sfsb = (StatefulContainer) container;
+         StatefulContainer sfsb = (StatefulContainer) getContainer();
          StatefulBeanContext ctx = sfsb.getCache().create();
          ctx.setInUse(false);
          Object id = ctx.getId();
-         Object[] args = {new StatefulLocalProxy(container, id)};
+         Object[] args = {new StatefulLocalProxy(getContainer(), id, vmid)};
          return proxyConstructor.newInstance(args);
       }
       catch (InstantiationException e)
@@ -152,8 +168,8 @@
    {
       try
       {
-         StatefulContainer sfsb = (StatefulContainer) container;
-         Object[] args = {new StatefulLocalProxy(container, id)};
+         StatefulContainer sfsb = (StatefulContainer) getContainer();
+         Object[] args = {new StatefulLocalProxy(getContainer(), id, vmid)};
          return proxyConstructor.newInstance(args);
       }
       catch (InstantiationException e)
@@ -177,9 +193,9 @@
    {
       try
       {
-         StatefulContainer sfsb = (StatefulContainer) container;
+         StatefulContainer sfsb = (StatefulContainer) getContainer();
          Object id = sfsb.createSession(initTypes, initValues);
-         Object[] args = {new StatefulLocalProxy(container, id)};
+         Object[] args = {new StatefulLocalProxy(getContainer(), id, vmid)};
          return proxyConstructor.newInstance(args);
       }
       catch (InstantiationException e)
@@ -203,10 +219,22 @@
    protected StatefulHandleImpl getHandle()
    {
       StatefulHandleImpl handle = new StatefulHandleImpl();
-      LocalBinding remoteBinding = (LocalBinding) advisor.resolveAnnotation(LocalBinding.class);
+      LocalBinding remoteBinding = (LocalBinding) ((Advisor)getContainer()).resolveAnnotation(LocalBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
 
       return handle;
    }
+   
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      super.readExternal(in);
+      vmid = (VMID)in.readObject();
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      super.writeExternal(out);
+      out.writeObject(vmid);
+   }
 }

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -69,7 +69,7 @@
    {
       Class[] interfaces;
       
-      StatefulContainer statefulContainer = (StatefulContainer) container;
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
       
       boolean bindTogether = false;
@@ -77,7 +77,7 @@
       if (remoteHome != null && bindHomeAndBusinessTogether(statefulContainer))
          bindTogether = true;
       
-      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
+      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(getContainer());
       if (bindTogether)
          interfaces = new Class[remoteInterfaces.length + 3];
       else
@@ -99,7 +99,7 @@
 
    protected void initializeJndiName()
    {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
+      jndiName = ProxyFactoryHelper.getRemoteJndiName(getContainer(), binding);
    }
 
    public void init() throws Exception
@@ -119,36 +119,36 @@
       Object factoryProxy = createPojiProxy(targetId, interfaces, ProxyFactoryHelper.getClientBindUrl(binding));
       try
       {
-         Util.rebind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
+         Util.rebind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
       }
       catch (NamingException e)
       {
-         NamingException namingException = new NamingException("Could not bind stateful remote proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
+         NamingException namingException = new NamingException("Could not bind stateful remote proxy with ejb name " + getContainer().getEjbName() + " into JNDI under jndiName: " + getContainer().getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
          namingException.setRootCause(e);
          throw namingException;
       }
       assert !Dispatcher.singleton.isRegistered(targetId) : targetId + " is already registered";
       Dispatcher.singleton.registerTarget(targetId, this);
 
-      StatefulContainer statefulContainer = (StatefulContainer) container;
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
       if (remoteHome != null && !bindHomeAndBusinessTogether(statefulContainer))
       {
          Object homeProxy = createHomeProxy(remoteHome.value());
-         Util.rebind(container.getInitialContext(), ProxyFactoryHelper.getHomeJndiName(container), homeProxy);
+         Util.rebind(getContainer().getInitialContext(), ProxyFactoryHelper.getHomeJndiName(getContainer()), homeProxy);
       }
    }
 
    public void stop() throws Exception
    {
-      Util.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
+      Util.unbind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME);
       Dispatcher.singleton.unregisterTarget(getTargetId());
       
-      StatefulContainer statefulContainer = (StatefulContainer) container;
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
       if (remoteHome != null && !bindHomeAndBusinessTogether(statefulContainer))
       {
-         Util.unbind(container.getInitialContext(), ProxyFactoryHelper.getHomeJndiName(container));
+         Util.unbind(getContainer().getInitialContext(), ProxyFactoryHelper.getHomeJndiName(getContainer()));
       }
       super.stop();
    }
@@ -158,7 +158,7 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          String stackName = "StatefulSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
@@ -166,12 +166,12 @@
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
          if (stack == null) throw new RuntimeException("unable to find interceptor stack: " + stackName);
-         StatefulHomeRemoteProxy proxy = new StatefulHomeRemoteProxy(container, stack.createInterceptors((Advisor) container, null), locator);
+         StatefulHomeRemoteProxy proxy = new StatefulHomeRemoteProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), locator);
 
 
          setEjb21Objects(proxy);
          Class[] intfs = {homeInterface};
-         return java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(), intfs, proxy);
+         return java.lang.reflect.Proxy.newProxyInstance(getContainer().getBeanClass().getClassLoader(), intfs, proxy);
       }
       catch (IllegalArgumentException e)
       {
@@ -182,7 +182,7 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          String stackName = "StatefulSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
@@ -190,7 +190,7 @@
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
          if (stack == null) throw new RuntimeException("unable to find interceptor stack: " + stackName);
-         StatefulRemoteProxy proxy = new StatefulRemoteProxy(container, stack.createInterceptors((Advisor) container, null), locator);
+         StatefulRemoteProxy proxy = new StatefulRemoteProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), locator);
 
 
          setEjb21Objects(proxy);
@@ -218,7 +218,7 @@
    protected StatefulHandleImpl getHandle()
    {
       StatefulHandleImpl handle = new StatefulHandleImpl();
-      RemoteBinding remoteBinding = (RemoteBinding) advisor.resolveAnnotation(RemoteBinding.class);
+      RemoteBinding remoteBinding = (RemoteBinding) ((Advisor)getContainer()).resolveAnnotation(RemoteBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
 
@@ -229,14 +229,14 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          String stackName = "StatefulSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
             stackName = binding.interceptorStack();
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
-         StatefulRemoteProxy proxy = new StatefulRemoteProxy(container, stack.createInterceptors((Advisor) container, null), locator, id);
+         StatefulRemoteProxy proxy = new StatefulRemoteProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), locator, id);
          setEjb21Objects(proxy);
          Object[] args = {proxy};
          return proxyConstructor.newInstance(args);

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -49,16 +49,7 @@
 public abstract class BaseStatelessProxyFactory extends org.jboss.ejb3.session.BaseSessionProxyFactory implements ProxyFactory
 {
    private static final Logger log = Logger.getLogger(BaseStatelessProxyFactory.class);
-
-//   protected Class proxyClass;
-//   protected Constructor proxyConstructor;
-   protected Context proxyFactoryContext;
-   protected String jndiName;
    
-   private javassist.util.proxy.ProxyFactory proxyFactory;
-   private Class proxyClass;
-   private Constructor proxyConstructor;
-   
    /**
     * Adapt the JDK to cglib.
     * 
@@ -172,7 +163,7 @@
       Class[] interfaces = getInterfaces();
       
       /* plain jdk */
-      Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
+      Class proxyClass = java.lang.reflect.Proxy.getProxyClass(getContainer().getBeanClass().getClassLoader(), interfaces);
       final Class[] constructorParams =
               {InvocationHandler.class};
       proxyConstructor = proxyClass.getConstructor(constructorParams);
@@ -227,7 +218,7 @@
 
    public void stop() throws Exception
    {
-      Util.unbind(container.getInitialContext(), jndiName);
+      Util.unbind(getContainer().getInitialContext(), jndiName);
    }
 
    protected abstract Class[] getInterfaces();
@@ -238,20 +229,14 @@
    {
       try
       {
-         log.debug("Binding proxy for " + container.getEjbName() + " in JNDI at " + jndiName);
-         Util.rebind(container.getInitialContext(), jndiName, proxy);
+         log.debug("Binding proxy for " + getContainer().getEjbName() + " in JNDI at " + jndiName);
+         Util.rebind(getContainer().getInitialContext(), jndiName, proxy);
       } catch (NamingException e)
       {
-         NamingException namingException = new NamingException("Could not bind stateless proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName);
+         NamingException namingException = new NamingException("Could not bind stateless proxy with ejb name " + getContainer().getEjbName() + " into JNDI under jndiName: " + getContainer().getInitialContext().getNameInNamespace() + "/" + jndiName);
          namingException.setRootCause(e);
          throw namingException;
       }
    }
    
-   public void setContainer(Container container)
-   {
-      this.container = container;
-      this.advisor = (Advisor) container;
-   }
-
 }

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -70,7 +70,7 @@
 
    protected Class[] getInterfaces()
    {
-      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
+      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(getContainer());
       Class[] interfaces = new Class[remoteInterfaces.length + 1];
       System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length);
       interfaces[remoteInterfaces.length] = JBossProxy.class;
@@ -79,21 +79,21 @@
 
    protected void initializeJndiName()
    {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
+      jndiName = ProxyFactoryHelper.getRemoteJndiName(getContainer(), binding);
    }
 
    public void start() throws Exception
    {
       String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
-      Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class);
+      Clustered clustered = (Clustered) ((Advisor)getContainer()).resolveAnnotation(Clustered.class);
       if (clustered == null) throw new RuntimeException("Could not find @Clustered annotation.  Cannot deploy.");
-      String partitionName = ((StatelessContainer) container).getPartitionName();
-      proxyFamilyName = ((StatelessContainer) container).getDeploymentQualifiedName() + locator.getProtocol() + partitionName;
-      HAPartition partition = (HAPartition) container.getInitialContext().lookup("/HAPartition/" + partitionName);
+      String partitionName = ((StatelessContainer) getContainer()).getPartitionName();
+      proxyFamilyName = ((StatelessContainer) getContainer()).getDeploymentQualifiedName() + locator.getProtocol() + partitionName;
+      HAPartition partition = (HAPartition) getContainer().getInitialContext().lookup("/HAPartition/" + partitionName);
       hatarget = new HATarget(partition, proxyFamilyName, locator, HATarget.ENABLE_INVOCATIONS);
       ClusteringTargetsRepository.initTarget(proxyFamilyName, hatarget.getReplicants());
-      ((StatelessContainer) container).getClusterFamilies().put(proxyFamilyName, hatarget);
+      ((StatelessContainer) getContainer()).getClusterFamilies().put(proxyFamilyName, hatarget);
       if (clustered.loadBalancePolicy() == null || clustered.loadBalancePolicy().equals(LoadBalancePolicy.class))
       {
          lbPolicy = new RandomRobin();
@@ -116,14 +116,14 @@
       proxy = null;
       hatarget.destroy();
       drm.unregisterListener(proxyFamilyName, this);
-      ((StatelessContainer) container).getClusterFamilies().remove(proxyFamilyName);
+      ((StatelessContainer) getContainer()).getClusterFamilies().remove(proxyFamilyName);
    }
 
    public Object createProxy()
    {
 //      try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          String stackName = "ClusteredStatelessSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
@@ -134,9 +134,9 @@
          Object[] args = {new StatelessClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null), wrapper, lbPolicy)};
          return proxyConstructor.newInstance(args);
          */
-         String partitionName = ((StatelessContainer) container).getPartitionName();
+         String partitionName = ((StatelessContainer) getContainer()).getPartitionName();
          
-         proxy = constructProxy(new StatelessClusteredProxy(container, stack.createInterceptors((Advisor) container, null), 
+         proxy = constructProxy(new StatelessClusteredProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), 
                wrapper, lbPolicy, partitionName));
          return proxy;
       }
@@ -163,7 +163,7 @@
    protected StatelessHandleImpl getHandle()
    {
       StatelessHandleImpl handle = new StatelessHandleImpl();
-      RemoteBinding remoteBinding = (RemoteBinding)advisor.resolveAnnotation(RemoteBinding.class);
+      RemoteBinding remoteBinding = (RemoteBinding)((Advisor)getContainer()).resolveAnnotation(RemoteBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
  

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxy.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxy.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxy.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -73,10 +73,10 @@
          return ret;
       }
       
-      if (container == null)
+      if (getContainer() == null)
          throw new EJBException("Invalid invocation of local interface (null container)");
 
-      StatelessContainer stateless = (StatelessContainer) container;
+      StatelessContainer stateless = (StatelessContainer) getContainer();
 
       return stateless.localInvoke(method, args, (FutureHolder) provider);
    }
@@ -88,7 +88,7 @@
       {
          Class[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
          AsynchMixin mixin = new AsynchMixin();
-         StatelessLocalProxy handler = new StatelessLocalProxy(mixin, container);
+         StatelessLocalProxy handler = new StatelessLocalProxy(mixin, getContainer());
          return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
       }
 
@@ -113,6 +113,9 @@
 
    public String toString()
    {
-      return container.getEjbName().toString();
+      if (getContainer() == null)
+         return proxyName;
+      else
+         return getContainer().getEjbName();
    }
 }

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -25,6 +25,7 @@
 import javax.ejb.LocalHome;
 
 import org.jboss.annotation.ejb.LocalBinding;
+import org.jboss.aop.Advisor;
 import org.jboss.ejb3.EJBContainer;
 import org.jboss.ejb3.JBossProxy;
 import org.jboss.ejb3.NonSerializableFactory;
@@ -46,7 +47,7 @@
    {
       Class[] interfaces;
       
-      EJBContainer statelessContainer = (EJBContainer) container;
+      EJBContainer statelessContainer = (EJBContainer) getContainer();
       LocalHome localHome = (LocalHome) statelessContainer.resolveAnnotation(LocalHome.class);
       
       boolean bindTogether = false;
@@ -54,7 +55,7 @@
       if (localHome != null && bindHomeAndBusinessTogether(statelessContainer))
          bindTogether = true;
       
-      Class[] localInterfaces = ProxyFactoryHelper.getLocalInterfaces(container);
+      Class[] localInterfaces = ProxyFactoryHelper.getLocalInterfaces(getContainer());
       
       if (bindTogether)
          interfaces = new Class[localInterfaces.length + 3];
@@ -77,21 +78,21 @@
 
    protected void initializeJndiName()
    {
-      jndiName = ProxyFactoryHelper.getLocalJndiName(container);
+      jndiName = ProxyFactoryHelper.getLocalJndiName(getContainer());
    }
 
    @Override
    public void start() throws Exception
    {
       super.start();
-      EJBContainer statelessContainer = (EJBContainer) container;
+      EJBContainer statelessContainer = (EJBContainer) getContainer();
       LocalHome localHome = (LocalHome) statelessContainer.resolveAnnotation(LocalHome.class);
       if (localHome != null && !bindHomeAndBusinessTogether(statelessContainer))
       {
          Class[] interfaces = {localHome.value()};
-         Object homeProxy = java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(),
-                                                                     interfaces, new StatelessLocalProxy(container));
-         NonSerializableFactory.rebind(container.getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(container), homeProxy);
+         Object homeProxy = java.lang.reflect.Proxy.newProxyInstance(getContainer().getBeanClass().getClassLoader(),
+                                                                     interfaces, new StatelessLocalProxy(getContainer()));
+         NonSerializableFactory.rebind(getContainer().getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(getContainer()), homeProxy);
       }
    }
 
@@ -99,24 +100,24 @@
    public void stop() throws Exception
    {
       super.stop();
-      EJBContainer statelessContainer = (EJBContainer) container;
+      EJBContainer statelessContainer = (EJBContainer) getContainer();
       LocalHome localHome = (LocalHome) statelessContainer.resolveAnnotation(LocalHome.class);
       if (localHome != null && !bindHomeAndBusinessTogether(statelessContainer))
       {
-         NonSerializableFactory.unbind(container.getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(container));
+         NonSerializableFactory.unbind(getContainer().getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(getContainer()));
       }
    }
 
 
    public Object createProxy()
    {
-      return constructProxy(new StatelessLocalProxy(container));
+      return constructProxy(new StatelessLocalProxy(getContainer()));
    }
 
    protected StatelessHandleImpl getHandle()
    {
       StatelessHandleImpl handle = new StatelessHandleImpl();
-      LocalBinding localBinding = (LocalBinding) advisor.resolveAnnotation(LocalBinding.class);
+      LocalBinding localBinding = (LocalBinding) ((Advisor)getContainer()).resolveAnnotation(LocalBinding.class);
       if (localBinding != null)
          handle.jndiName = localBinding.jndiBinding();
 

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -59,7 +59,7 @@
    {
       Class[] interfaces;
       
-      StatelessContainer statelessContainer = (StatelessContainer) container;
+      StatelessContainer statelessContainer = (StatelessContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statelessContainer.resolveAnnotation(RemoteHome.class);
       
       boolean bindTogether = false;
@@ -67,7 +67,7 @@
       if (remoteHome != null && bindHomeAndBusinessTogether(statelessContainer))
          bindTogether = true;
       
-      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
+      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(getContainer());
       
       if (bindTogether)
          interfaces = new Class[remoteInterfaces.length + 3];
@@ -92,7 +92,7 @@
 
    protected void initializeJndiName()
    {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
+      jndiName = ProxyFactoryHelper.getRemoteJndiName(getContainer(), binding);
    }
 
    public void init() throws Exception
@@ -105,24 +105,24 @@
    public void start() throws Exception
    {
       super.start();
-      EJBContainer statelessContainer = (EJBContainer) container;
+      EJBContainer statelessContainer = (EJBContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statelessContainer
             .resolveAnnotation(RemoteHome.class);
       if (remoteHome != null && !bindHomeAndBusinessTogether(statelessContainer))
       {
          Object homeProxy = createHomeProxy(remoteHome.value());
          try {
-            Util.rebind(container.getInitialContext(), ProxyFactoryHelper
-                  .getHomeJndiName(container), homeProxy);
+            Util.rebind(getContainer().getInitialContext(), ProxyFactoryHelper
+                  .getHomeJndiName(getContainer()), homeProxy);
          }
          catch (NamingException e)
          {
             NamingException namingException = new NamingException(
                   "Could not bind stateless home proxy with ejb name "
-                        + container.getEjbName()
+                        + getContainer().getEjbName()
                         + " into JNDI under jndiName: "
-                        + container.getInitialContext().getNameInNamespace()
-                        + "/" + ProxyFactoryHelper.getHomeJndiName(container));
+                        + getContainer().getInitialContext().getNameInNamespace()
+                        + "/" + ProxyFactoryHelper.getHomeJndiName(getContainer()));
             namingException.setRootCause(e);
             throw namingException;
          }
@@ -133,20 +133,20 @@
    public void stop() throws Exception
    {
       super.stop();
-      EJBContainer statelessContainer = (EJBContainer) container;
+      EJBContainer statelessContainer = (EJBContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statelessContainer
             .resolveAnnotation(RemoteHome.class);
       if (remoteHome != null && !bindHomeAndBusinessTogether(statelessContainer))
       {
-         Util.unbind(container.getInitialContext(), ProxyFactoryHelper
-               .getHomeJndiName(container));
+         Util.unbind(getContainer().getInitialContext(), ProxyFactoryHelper
+               .getHomeJndiName(getContainer()));
       }
    }
 
    protected StatelessHandleImpl getHandle()
    {
       StatelessHandleImpl handle = new StatelessHandleImpl();
-      RemoteBinding remoteBinding = (RemoteBinding) advisor
+      RemoteBinding remoteBinding = (RemoteBinding) ((Advisor)getContainer())
             .resolveAnnotation(RemoteBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
@@ -157,7 +157,7 @@
    public Object createHomeProxy(Class homeInterface)
    {
       try {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          ;
          String stackName = "StatelessSessionClientInterceptors";
          if (binding.interceptorStack() != null
@@ -166,11 +166,11 @@
             stackName = binding.interceptorStack();
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
-         StatelessRemoteProxy proxy = new StatelessRemoteProxy(container,
-               stack.createInterceptors((Advisor) container, null), locator);
+         StatelessRemoteProxy proxy = new StatelessRemoteProxy(getContainer(),
+               stack.createInterceptors((Advisor) getContainer(), null), locator);
          setEjb21Objects(proxy);
          Class[] interfaces = { homeInterface };
-         return java.lang.reflect.Proxy.newProxyInstance(container
+         return java.lang.reflect.Proxy.newProxyInstance(getContainer()
                .getBeanClass().getClassLoader(), interfaces, proxy);
       } catch (IllegalArgumentException e)
       {
@@ -183,7 +183,7 @@
    {
       // try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          ;
          String stackName = "StatelessSessionClientInterceptors";
          if (binding.interceptorStack() != null
@@ -192,8 +192,8 @@
             stackName = binding.interceptorStack();
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
-         StatelessRemoteProxy proxy = new StatelessRemoteProxy(container,
-               stack.createInterceptors((Advisor) container, null), locator);
+         StatelessRemoteProxy proxy = new StatelessRemoteProxy(getContainer(),
+               stack.createInterceptors((Advisor) getContainer(), null), locator);
          setEjb21Objects(proxy);
          /*
           * Object[] args = {proxy}; return proxyConstructor.newInstance(args);

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/localfromremote/unit/LocalTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/localfromremote/unit/LocalTestCase.java	2007-08-20 21:42:46 UTC (rev 64724)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/localfromremote/unit/LocalTestCase.java	2007-08-20 22:00:07 UTC (rev 64725)
@@ -21,6 +21,7 @@
  */
 package org.jboss.ejb3.test.localfromremote.unit;
 
+import javax.naming.InitialContext;
 import org.jboss.ejb3.test.localfromremote.StatefulRemote;
 import org.jboss.ejb3.test.localfromremote.StatelessRemote;
 import org.jboss.logging.Logger;
@@ -76,7 +77,8 @@
    
    public void testStatefulLocalFromRemote() throws Exception
    {
-      StatelessRemote bean = (StatelessRemote) getInitialContext().lookup("StatelessBean/remote");
+      InitialContext jndiContext = new InitialContext();
+      StatelessRemote bean = (StatelessRemote) jndiContext.lookup("StatelessBean/remote");
       assertNotNull(bean);
       
       try
@@ -84,8 +86,11 @@
          bean.localCall();
          fail("should not be allowed to call local interface remotely");
       }
-      catch (javax.ejb.EJBException e)
-      {}
+      catch (javax.naming.NamingException e)
+      {
+         if (e.getCause() == null || !(e.getCause() instanceof javax.ejb.EJBException))
+            fail("should not be allowed to call local interface remotely");
+      }
    }
    
    public static Test suite() throws Exception




More information about the jboss-cvs-commits mailing list