[jboss-cvs] JBossAS SVN: r68144 - in trunk/ejb3: src/main/org/jboss/ejb3 and 10 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 11 13:47:28 EST 2007


Author: bdecoste
Date: 2007-12-11 13:47:28 -0500 (Tue, 11 Dec 2007)
New Revision: 68144

Modified:
   trunk/ejb3/build-test.xml
   trunk/ejb3/src/main/org/jboss/ejb3/Container.java
   trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/EJBContextFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java
   trunk/ejb3/src/main/org/jboss/ejb3/LocalProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/remoting/BaseRemoteProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java
   trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
   trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionRemoteProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusteredProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHomeRemoteProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulSessionContextImpl.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusteredProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/localfromremote/unit/LocalTestCase.java
Log:
[EJBTHREE-1019] calling local proxies remotely

Modified: trunk/ejb3/build-test.xml
===================================================================
--- trunk/ejb3/build-test.xml	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/build-test.xml	2007-12-11 18:47:28 UTC (rev 68144)
@@ -4478,7 +4478,7 @@
       <antcall target="invoker-test"  inheritRefs="true"/>
       <antcall target="iiop-tests"  inheritRefs="true"/>
       <antcall target="libdeployment-test"  inheritRefs="true"/>
-	  <!--antcall target="multi-instance-localfromremote-test"  inheritRefs="true"/-->
+	  <antcall target="multi-instance-localfromremote-test"  inheritRefs="true"/>
 	  <antcall target="statelesscreation-test"  inheritRefs="true"/>
 	  <antcall target="removedislocal-test"  inheritRefs="true"/>
    </target>

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Container.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Container.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Container.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -111,4 +111,6 @@
     * @return   the security manager or null if there is no manager associated
     */
    <T> T getSecurityManager(Class<T> type);
+   
+   boolean isClustered();
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -239,7 +239,8 @@
       try 
       {
          Reference ref = new Reference(EJBContext.class.getName(), EJBContextFactory.class.getName(), null);
-         ref.add(new StringRefAddr("oid", getObjectName().getCanonicalName()));
+         ref.add(new StringRefAddr("containerGuid", Ejb3Registry.guid(this)));
+         ref.add(new StringRefAddr("containerClusterUid", Ejb3Registry.clusterUid(this)));
          Util.rebind(getEnc(), "EJBContext", ref);
       }
       catch (NamingException e)
@@ -1252,6 +1253,11 @@
       return info;
    }
    
+   public boolean isClustered()
+   {
+      return false;
+   }
+   
    public JavaEEModule getModule()
    {
       return deployment;

Modified: trunk/ejb3/src/main/org/jboss/ejb3/EJBContextFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContextFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContextFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -33,7 +33,7 @@
  * Comment
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
 public class EJBContextFactory implements ObjectFactory
 {
@@ -44,7 +44,16 @@
          throws Exception
    {
       Reference ref = (Reference) obj;
-      String oid = (String) ref.get("oid").getContent();
-      return Ejb3Registry.getContainer(oid).peekContext().getEJBContext();
+      String containerGuid = (String) ref.get("containerGuid").getContent();
+      boolean isClustered = (Boolean)ref.get("isClustered").getContent();
+      
+      EJBContainer container = (EJBContainer)Ejb3Registry.getContainer(containerGuid);
+      if (container == null && isClustered)
+      {
+         String containerClusterUid = (String) ref.get("containerClusterUid").getContent();
+         container = (EJBContainer)Ejb3Registry.getClusterContainer(containerClusterUid);
+      }
+         
+      return container.peekContext().getEJBContext();
    }
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -21,6 +21,7 @@
  */
 package org.jboss.ejb3;
 
+import java.rmi.dgc.VMID;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -39,6 +40,9 @@
    private static final Logger log = Logger.getLogger(Ejb3Registry.class);
 
    private static Map<String, Container> containers = new HashMap<String, Container>();
+   private static Map<String, Container> clusterContainers = new HashMap<String, Container>();
+   
+   private static final VMID vmid = new VMID();
 
    /**
     * Find a potential container.
@@ -50,6 +54,11 @@
    {
       return containers.get(oid);
    }
+   
+   public static VMID getVMID()
+   {
+      return vmid;
+   }
 
    /**
     * Reports the existance of a container.
@@ -78,6 +87,34 @@
       return container.getObjectName().getCanonicalName();
    }
    
+   public static boolean hasClusterContainer(String oid)
+   {
+      return clusterContainers.containsKey(oid);
+   }
+   
+   public static final String guid(Container container, VMID vmid)
+   {
+      return container.getObjectName().getCanonicalName() + ",VMID=" + vmid;
+   }
+   
+   public static final String guid(Container container)
+   {
+      return guid(container, vmid);
+   }
+   
+   public static final String clusterUid(Container container)
+   {  
+      if (container.isClustered())
+        return container.getObjectName().getCanonicalName() + ",Partition=" + ((EJBContainer)container).getPartitionName();
+     
+      return container.getObjectName().getCanonicalName();
+   }
+   
+   public static final String clusterUid(String oid, String partitionName)
+   {
+      return oid + ",Partition=" + partitionName;
+   }
+   
    /**
     * Registers a container.
     * 
@@ -86,11 +123,15 @@
     */
    public static void register(Container container)
    {
-      String oid = oid(container);
-      if(hasContainer(oid))
-         throw new IllegalStateException("Container " + oid + " is already registered");
-      containers.put(oid, container);
-      log.debug("Registered container " + oid);
+      String guid = guid(container);
+      if(hasContainer(guid))
+         throw new IllegalStateException("Container " + guid + " + is already registered");
+      containers.put(guid, container);
+      
+      if (container.isClustered())
+         clusterContainers.put(clusterUid(container), container);
+      
+      log.debug("Registered container " + guid);
    }
 
    /**
@@ -101,26 +142,48 @@
     */
    public static void unregister(Container container)
    {
-      String oid = oid(container);
-      if(!hasContainer(oid))
-         throw new IllegalStateException("Container " + oid + " is not registered");
-      containers.remove(oid);
-      log.debug("Unregistered container " + oid);
+      String guid = guid(container);
+      if(!hasContainer(guid))
+         throw new IllegalStateException("Container " + guid + " + is not registered");
+      containers.remove(guid);
+      
+      if (container.isClustered())
+         clusterContainers.remove(clusterUid(container));
+      
+      log.debug("Unregistered container " + guid);
    }
 
    /**
-    * Returns the container specified by the given canonical object name.
+    * Returns the container specified by the given GUID.
     * Never returns null.
     * 
+    * @param guid                   the GUID
+    * @return                       the container
+    * @throws IllegalStateException if the container is not registered
+    */
+   public static Container getContainer(String guid)
+   {
+      if(!hasContainer(guid))
+         throw new IllegalStateException("Container " + guid + " is not registered");
+      
+      return containers.get(guid);
+   }
+   
+   /**
+    * Returns the container specified by the given canocical object name.
+    * Never returns null.
+    * 
     * @param oid                    the canonical object name of the container
     * @return                       the container
     * @throws IllegalStateException if the container is not registered
     */
-   public static Container getContainer(String oid)
+   public static Container getClusterContainer(String clusterUid)
    {
-      if(!hasContainer(oid))
-         throw new IllegalStateException("Container " + oid + " is not registered");
-      return containers.get(oid);
+      Container container = clusterContainers.get(clusterUid);
+      if(container == null)
+         throw new IllegalStateException("Container " + clusterUid + " is not registered " + clusterContainers);
+      
+      return container;
    }
 
    /**

Modified: trunk/ejb3/src/main/org/jboss/ejb3/LocalProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/LocalProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/LocalProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -40,39 +40,45 @@
 {
    private static Logger log = Logger.getLogger(LocalProxy.class);
    
-   // FIXME: should be private
-   protected transient Container container = null;
-   private String containerId;
+   private transient Container container = null;
+   protected String containerClusterUid;
+   protected String containerGuid;
+   protected String proxyName;
 
-   protected LocalProxy()
+
+   public LocalProxy()
    {
    }
 
    protected LocalProxy(Container container)
    {
       this.container = container;
-      this.containerId = container.getObjectName().getCanonicalName();
+      this.containerGuid = Ejb3Registry.guid(container);
+      this.containerClusterUid = Ejb3Registry.clusterUid(container);
+      proxyName = container.getEjbName();
    }
 
    protected Container getContainer()
    {
       if(container == null)
-         container = Ejb3Registry.findContainer(containerId);
+         container = Ejb3Registry.findContainer(containerGuid);
       if(container == null)
-         log.warn("Container " + containerId + " is not yet available");
+         log.warn("Container " + containerGuid + " is not yet available");
       return container;
    }
    
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
    {
-      this.containerId = in.readUTF();
-      // TODO: one container is private, this won't have to be done anymore
-      this.container = Ejb3Registry.findContainer(containerId);
+      this.containerGuid = in.readUTF();
+      this.containerClusterUid = in.readUTF();
+      this.proxyName = in.readUTF();
    }
 
    public void writeExternal(ObjectOutput out) throws IOException
    {
-      out.writeUTF(containerId);
+      out.writeUTF(containerGuid);
+      out.writeUTF(containerClusterUid);
+      out.writeUTF(proxyName);
    }
 
    public abstract String toString();

Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -146,7 +146,7 @@
          
       innerStart();
 
-      timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
+      timerService = TimerServiceFactory.getInstance().createTimerService(this, this);
 
       startProxies();
       

Modified: trunk/ejb3/src/main/org/jboss/ejb3/remoting/BaseRemoteProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/remoting/BaseRemoteProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/remoting/BaseRemoteProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -26,6 +26,9 @@
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.metadata.SimpleMetaData;
 
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.Ejb3Registry;
+
 /**
  * Comment
  *
@@ -34,13 +37,22 @@
  */
 public abstract class BaseRemoteProxy implements java.io.Serializable, InvocationHandler, RemoteProxy
 {
-   protected Object containerId;
+   protected String containerId;
+   protected String containerGuid;
    protected Interceptor[] interceptors;
    protected SimpleMetaData metadata;
 
-   protected BaseRemoteProxy(Object containerId, Interceptor[] interceptors)
+   protected BaseRemoteProxy(Container container, Interceptor[] interceptors)
    {
+      this.containerId = container.getObjectName().getCanonicalName();
+      this.containerGuid = Ejb3Registry.guid(container);
+      this.interceptors = interceptors;
+   }
+   
+   protected BaseRemoteProxy(String containerId, String containerGuid, Interceptor[] interceptors)
+   {
       this.containerId = containerId;
+      this.containerGuid = containerGuid;
       this.interceptors = interceptors;
    }
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -57,21 +57,27 @@
 
    private Container findLocalContainer(Invocation invocation)
    {
-      Object oid = invocation.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
+      String guid = (String)invocation.getMetaData(IS_LOCAL, GUID);
+      String partitionName = (String) invocation.getMetaData(PARTITION_NAME, PARTITION_NAME);
+      
       Container container = null;
       try
       {
-         container = Ejb3Registry.getContainer(oid.toString());
+         container = Ejb3Registry.findContainer(guid);
+         if (container == null)
+         {
+            String oid = (String)invocation.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
+            container = Ejb3Registry.getClusterContainer(Ejb3Registry.clusterUid(oid, partitionName));
+         }
       }
       catch (IllegalStateException ignored)
       {
          if (log.isTraceEnabled())
-            log.trace("Cannot find local container for " + oid);
+            log.trace("Cannot find local container for " + guid);
       }
       
       if (container != null)
       {
-         String partitionName = (String) invocation.getMetaData(PARTITION_NAME, PARTITION_NAME);
          if (partitionName != null)
          {
             if (!partitionName.equals(((EJBContainer) container).getPartitionName()))
@@ -79,7 +85,7 @@
                if (log.isTraceEnabled())
                {
                   log.trace("Partition (" + ((EJBContainer) container).getPartitionName() + 
-                            ") for local container " + oid + " does not match invocation (" +
+                            ") for local container " + guid + " does not match invocation (" +
                             partitionName + ")");
                }
                container = null;
@@ -87,7 +93,7 @@
             else if (log.isTraceEnabled())
             {
                log.trace("Partition (" + ((EJBContainer) container).getPartitionName() + 
-                     ") for local container " + oid + " matches invocation (" +
+                     ") for local container " + guid + " matches invocation (" +
                      partitionName + ")");
             }
          }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -48,6 +48,8 @@
    private static final long serialVersionUID = 337700910587744646L;
 
    private static final Logger log = Logger.getLogger(IsLocalInterceptor.class);
+   
+   public static final String GUID = "GUID";
 
    public static final String IS_LOCAL = "IS_LOCAL";
    public static final String IS_LOCAL_EXCEPTION = "IS_LOCAL_EXCEPTION";
@@ -64,8 +66,8 @@
    {
       if (isLocal())
       {
-         Object oid = invocation.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
-         Container container = Ejb3Registry.getContainer(oid.toString());
+         String guid = (String)invocation.getMetaData(IS_LOCAL, GUID);
+         Container container = Ejb3Registry.getContainer(guid);
          
          return invokeLocal(invocation, container);
       }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -198,7 +198,7 @@
          initBeanContext();
 
          // make sure the timer service is there before injection takes place
-         timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
+         timerService = TimerServiceFactory.getInstance().createTimerService(this, this);
 
          injectDependencies(beanContext);
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -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: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -31,9 +31,11 @@
 import org.jboss.aspects.asynch.AsynchMixin;
 import org.jboss.aspects.asynch.AsynchProvider;
 import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
+import org.jboss.ejb3.Container;
 import org.jboss.ejb3.JBossProxy;
 import org.jboss.ejb3.ProxyUtils;
 import org.jboss.ejb3.asynchronous.AsynchronousInterceptor;
+import org.jboss.ejb3.remoting.IsLocalInterceptor;
 import org.jboss.remoting.InvokerLocator;
 
 /**
@@ -47,15 +49,15 @@
    protected InvokerLocator uri;
    AsynchProvider provider;
 
-   public ServiceRemoteProxy(Object containerId, Interceptor[] interceptors, InvokerLocator uri)
+   public ServiceRemoteProxy(Container container, Interceptor[] interceptors, InvokerLocator uri)
    {
-      super(containerId, interceptors);
+      super(container, interceptors);
       this.uri = uri;
    }
 
-   public ServiceRemoteProxy(AsynchProvider provider, Object containerId, Interceptor[] interceptors, InvokerLocator uri)
+   public ServiceRemoteProxy(AsynchProvider provider, String containerId, String containerGuid, Interceptor[] interceptors, InvokerLocator uri)
    {
-      super(containerId, interceptors);
+      super(containerId, containerGuid, interceptors);
       this.uri = uri;
       this.provider = provider;
    }
@@ -86,6 +88,8 @@
       sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, containerId, PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, uri, PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS);
+      sri.getMetaData().addMetaData(IsLocalInterceptor.IS_LOCAL, IsLocalInterceptor.GUID, containerGuid, PayloadKey.AS_IS);
+      
 
       if (provider != null)
       {
@@ -102,7 +106,7 @@
          Class[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
          AsynchMixin mixin = new AsynchMixin();
          Interceptor[] newInterceptors = ProxyUtils.addAsynchProxyInterceptor(mixin, interceptors);
-         ServiceRemoteProxy handler = new ServiceRemoteProxy(mixin, containerId, newInterceptors, uri);
+         ServiceRemoteProxy handler = new ServiceRemoteProxy(mixin, containerId, containerGuid, newInterceptors, uri);
          return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
       }
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -83,14 +83,13 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
          String stackName = "ServiceClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
             stackName = binding.interceptorStack();
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
-         Object[] args = {new ServiceRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator)};
+         Object[] args = {new ServiceRemoteProxy(container, stack.createInterceptors((Advisor) container, null), locator)};
          return proxyConstructor.newInstance(args);
       }
       catch (InstantiationException e)

Modified: trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -21,6 +21,12 @@
  */
 package org.jboss.ejb3.session;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import javax.ejb.EJBException;
 import javax.ejb.EJBHome;
 import javax.ejb.EJBLocalHome;
 import javax.ejb.EJBLocalObject;
@@ -31,6 +37,8 @@
 import javax.ejb.Remote;
 import javax.ejb.RemoteHome;
 
+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;
@@ -45,18 +53,25 @@
  * @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
 {
    @SuppressWarnings("unused")
    private static final Logger log = Logger.getLogger(BaseSessionProxyFactory.class);
    
-   protected SessionContainer container;
+   private EJBContainer container;
+   protected String containerGuid;
+   protected String containerClusterUid;
+   protected boolean isClustered = false;
    
+   public BaseSessionProxyFactory()
+   {
+   }
+   
    protected BaseSessionProxyFactory(SessionContainer container)
    {
       assert container != null : "container is null";
       
-      this.container = container;
+      setContainer(container);
    }
    
    public Object createHomeProxy()
@@ -64,6 +79,27 @@
       throw new RuntimeException("NYI");
    }
    
+   protected void setContainer(Container container)
+   {
+      this.container = (EJBContainer)container;
+      this.containerGuid = Ejb3Registry.guid(container);
+      this.containerClusterUid = Ejb3Registry.clusterUid(container);
+      this.isClustered = container.isClustered();
+   }
+   
+   protected Container getContainer()
+   {
+      if (container == null)
+      {
+         container = (EJBContainer)Ejb3Registry.findContainer(containerGuid);
+         
+         if (container == null && isClustered)
+            container = (EJBContainer)Ejb3Registry.getClusterContainer(containerClusterUid);
+      }
+      
+      return container;
+   }
+   
    protected void setEjb21Objects(BaseSessionRemoteProxy proxy)
    {
       proxy.setHandle(getHandle());
@@ -110,6 +146,23 @@
       return metadata;
    }   
    
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      containerGuid = in.readUTF();
+      containerClusterUid = in.readUTF();
+      isClustered = in.readBoolean();
+      
+      if (getContainer() == null)
+         throw new EJBException("Invalid (i.e. remote) invocation of local interface (null container) for " + containerGuid);
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      out.writeUTF(containerGuid);
+      out.writeUTF(containerClusterUid);
+      out.writeBoolean(isClustered);
+   }
+   
    /**
     * Ensures that an EJB 2.1 view is complete; the following rules apply:
     * 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionRemoteProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionRemoteProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionRemoteProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -25,8 +25,9 @@
 import javax.ejb.Handle;
 import javax.ejb.HomeHandle;
 import org.jboss.aop.advice.Interceptor;
-import org.jboss.proxy.ejb.handle.StatefulHandleImpl;
 
+import org.jboss.ejb3.Container;
+
 /**
  * Comment
  *
@@ -41,11 +42,16 @@
    protected HomeHandle homeHandle;
    protected EJBMetaData ejbMetaData;
    
-   public BaseSessionRemoteProxy(Object containerId, Interceptor[] interceptors)
+   public BaseSessionRemoteProxy(Container container, Interceptor[] interceptors)
    {
-      super(containerId, interceptors);
+      super(container, interceptors);
    }
    
+   public BaseSessionRemoteProxy(String containerId, String containerGuid, Interceptor[] interceptors)
+   {
+      super(containerId, containerGuid, interceptors);
+   }
+   
    protected BaseSessionRemoteProxy()
    {
    }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContainer.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContainer.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -310,7 +310,7 @@
 
    public static InvocationResponse marshallException(Invocation invocation, Throwable exception, Map responseContext) throws Throwable
    {
-      if (!invocation.getMetaData().hasTag(IsLocalInterceptor.IS_LOCAL)) throw exception;
+      if (invocation.getMetaData(IsLocalInterceptor.IS_LOCAL,IsLocalInterceptor.IS_LOCAL) == null) throw exception;
 
       InvocationResponse response = new InvocationResponse();
       response.setContextInfo(responseContext);
@@ -325,7 +325,7 @@
    {
       InvocationResponse response;
       // marshall return value
-      if (rtn != null && invocation.getMetaData().hasTag(IsLocalInterceptor.IS_LOCAL))
+      if (rtn != null && invocation.getMetaData(IsLocalInterceptor.IS_LOCAL, IsLocalInterceptor.IS_LOCAL) != null)
       {
          response = new InvocationResponse(new MarshalledObjectForLocalCalls(rtn));
       }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -54,6 +54,11 @@
    protected String jndiName;
 
    public static final String PROXY_FACTORY_NAME = "StatefulProxyFactory";
+   
+   public BaseStatefulProxyFactory()
+   {
+      super();
+   }
 
    public BaseStatefulProxyFactory(SessionContainer container, String jndiName)
    {
@@ -90,7 +95,7 @@
    public void init() throws Exception
    {
       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);
       proxyConstructor = proxyClass.getConstructor(InvocationHandler.class);
    }
 
@@ -98,7 +103,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);
@@ -106,11 +111,11 @@
       Reference ref = new Reference("java.lang.Object", refAddr, JndiProxyFactory.class.getName(), null);
       try 
       {
-         log.debug("Binding reference for " + container.getEjbName() + " in JNDI at " + atom);
+         log.debug("Binding reference for " + getContainer().getEjbName() + " in JNDI at " + atom);
          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;
       }
@@ -118,7 +123,7 @@
 
    public void stop() throws Exception
    {
-      Util.unbind(container.getInitialContext(), jndiName);
+      Util.unbind(getContainer().getInitialContext(), jndiName);
    }
 
    protected abstract Class<?>[] getInterfaces();

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -32,6 +32,8 @@
 import org.jboss.aop.metadata.SimpleMetaData;
 import org.jboss.ejb3.session.SessionContainer;
 
+import org.jboss.ejb3.Ejb3Registry;
+
 /**
  * Overrides superclass to not use MarshalledValue in externalization,
  * as a nested context is meant to be serialized as part of its parent
@@ -46,6 +48,7 @@
 {   
    /** The serialVersionUID */
    private static final long serialVersionUID = 7835719320529968045L;
+   
 
    public NestedStatefulBeanContext(SessionContainer container, Object bean)
    {
@@ -54,8 +57,10 @@
    
    public void writeExternal(ObjectOutput out) throws IOException
    {
-      out.writeUTF(getContainer().getObjectName().getCanonicalName());
+      out.writeUTF(Ejb3Registry.clusterUid(getContainer()));
+      out.writeUTF(Ejb3Registry.guid(getContainer()));
       out.writeObject(id);
+      out.writeBoolean(isClustered);
       out.writeObject(metadata);
       out.writeObject(bean);
       out.writeObject(persistenceContexts);
@@ -69,8 +74,10 @@
 
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
    {
-      containerName = in.readUTF();
+      containerClusterUid = in.readUTF();
+      containerGuid = in.readUTF();
       id = in.readObject();
+      isClustered = in.readBoolean();
       metadata = (SimpleMetaData) in.readObject();
       bean = in.readObject();
       persistenceContexts = (HashMap<String, EntityManager>)  in.readObject();

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -68,7 +68,9 @@
    {
       private static final long serialVersionUID = 1L;
       
-      private String containerName;
+      private String containerClusterUid;
+      private String containerGuid;
+      private boolean isClustered = false;
       private Object id;
       private SimpleMetaData metadata;
       private long lastUsed;
@@ -78,7 +80,11 @@
       
       private Object readResolve() throws ObjectStreamException
       {
-         StatefulContainer container = Ejb3Registry.getContainer(containerName, StatefulContainer.class);
+         StatefulContainer container = (StatefulContainer)Ejb3Registry.findContainer(containerGuid);
+          
+         if (isClustered && container == null)
+            container = (StatefulContainer)Ejb3Registry.getClusterContainer(containerClusterUid);
+        
          StatefulBeanContext context = new StatefulBeanContext(container, beanMO);
          context.id = this.id;
          context.metadata = this.metadata;
@@ -117,7 +123,9 @@
 
    protected boolean removed;
 
-   protected String containerName;
+   protected String containerClusterUid;
+   protected String containerGuid;
+   protected boolean isClustered = false;
    
    protected boolean replicationIsPassivation = true;
    
@@ -135,7 +143,8 @@
       
       assert beanMO != null : "beanMO is null";
       
-      this.containerName = container.getObjectName().getCanonicalName();
+      this.containerClusterUid = Ejb3Registry.clusterUid(container);
+      this.containerGuid = Ejb3Registry.guid(container);
       this.beanMO = beanMO;
    }
    
@@ -149,7 +158,8 @@
    {
       super(container, bean);
       
-      this.containerName = container.getObjectName().getCanonicalName();
+      this.containerClusterUid = Ejb3Registry.clusterUid(container);
+      this.containerGuid = Ejb3Registry.guid(container);
       this.id = new GUID();
    }
 
@@ -370,7 +380,9 @@
          containedIn = propagatedContainedIn.get();
          NestedStatefulBeanContext nested = new NestedStatefulBeanContext(getContainer(), bean);
          nested.id = id;
-         nested.containerName = containerName;
+         nested.container = getContainer();
+         nested.containerClusterUid = containerClusterUid;
+         nested.containerGuid = containerGuid;
          nested.replicationIsPassivation = replicationIsPassivation;
          containedIn.addContains(nested);
          thisPtr = new ProxiedStatefulBeanContext(nested);
@@ -777,8 +789,12 @@
    {
       if (container == null)
       {
-         container = Ejb3Registry.getContainer(containerName, SessionContainer.class);
+         container = (SessionContainer)Ejb3Registry.findContainer(containerGuid);
+          
+         if (isClustered && container == null)
+            container = (SessionContainer)Ejb3Registry.getClusterContainer(containerClusterUid);
       }
+      
       return container;
    }
 
@@ -904,7 +920,9 @@
          // JBoss Cache state transfer to a newly deployed node.
          state.beanMO = this.beanMO;
       }
-      state.containerName = this.containerName;
+
+      state.containerClusterUid = containerClusterUid;
+      state.containerGuid = containerGuid;
       state.id = this.id;
       state.lastUsed = this.lastUsed;
       state.metadata = this.metadata;

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -42,12 +42,16 @@
    
    private transient StatefulBeanContext beanContext;
    private Object oid;
-   private String containerId;
+   private String containerGuid;
+   private String containerClusterUid;
+   private boolean isClustered = false;
    
    private static class Serialized implements Serializable
    {
       private Object oid;
-      private String containerId;
+      private String containerGuid;
+      private String containerClusterUid;
+      private boolean isClustered = false;
       
       private Serialized(StatefulBeanContextReference ref)
       {
@@ -60,7 +64,9 @@
       
       this.beanContext = beanContext;
       oid = beanContext.getId();
-      containerId = beanContext.getContainer().getObjectName().getCanonicalName();
+      containerGuid = Ejb3Registry.guid(beanContext.getContainer());
+      containerClusterUid = Ejb3Registry.clusterUid(beanContext.getContainer());
+      isClustered = beanContext.getContainer().isClustered();
    }
 
 //   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
@@ -79,7 +85,9 @@
    {
       if (beanContext == null)
       {
-         StatefulContainer container = (StatefulContainer)Ejb3Registry.getContainer(containerId);
+         StatefulContainer container = (StatefulContainer)Ejb3Registry.findContainer(containerGuid);
+         if (isClustered && container == null)
+            container = (StatefulContainer)Ejb3Registry.getClusterContainer(containerClusterUid);
          // We are willing to accept a context that has been marked as removed
          // as it can still hold nested children
          beanContext = container.getCache().get(oid, false);

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -85,7 +85,7 @@
 
    protected Class[] getInterfaces()
    {
-      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(container);
+      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(getContainer());
       Class[] interfaces = new Class[remoteInterfaces.length + 1];
       System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length);
       interfaces[remoteInterfaces.length] = JBossProxy.class;
@@ -96,12 +96,12 @@
    {
       String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
-      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();
@@ -122,10 +122,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;
       }
@@ -136,16 +136,15 @@
 
    public Object createProxy()
    {
-      Object containerId = container.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();
-      return constructProxy(new StatefulClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null), 
-                                                  wrapper, lbPolicy, partitionName));
+      String partitionName = ((StatefulContainer) getContainer()).getPartitionName();
+      return constructProxy(new StatefulClusteredProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), 
+            wrapper, lbPolicy, partitionName));
    }
 
    public Object createProxy(Object id)
@@ -158,15 +157,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)container.resolveAnnotation(RemoteBinding.class);
+      RemoteBinding remoteBinding = (RemoteBinding)((Advisor)getContainer()).resolveAnnotation(RemoteBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
  
@@ -179,7 +178,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: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusteredProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusteredProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusteredProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -32,10 +32,13 @@
 import org.jboss.aspects.remoting.ClusterConstants;
 import org.jboss.aspects.remoting.FamilyWrapper;
 import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.Ejb3Registry;
 import org.jboss.ejb3.JBossProxy;
 import org.jboss.ejb3.ProxyUtils;
 import org.jboss.ejb3.asynchronous.AsynchronousInterceptor;
 import org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor;
+import org.jboss.ejb3.remoting.IsLocalInterceptor;
 import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
 import org.jboss.util.id.GUID;
 
@@ -57,18 +60,21 @@
    protected String partitionName;
 
 
-   public StatefulClusteredProxy(Object containerId, Interceptor[] interceptors, FamilyWrapper family, LoadBalancePolicy lb, String partitionName)
+   public StatefulClusteredProxy(Container container, Interceptor[] interceptors, FamilyWrapper family, LoadBalancePolicy lb, String partitionName)
    {
-      super(containerId, interceptors);
+      super(container, interceptors);
       this.family = family;
       this.lbPolicy = lb;
       this.partitionName = partitionName;
    }
 
-   public StatefulClusteredProxy(AsynchProvider provider, Object containerId, Interceptor[] interceptors, FamilyWrapper family, LoadBalancePolicy lb, String partitionName)
+   public StatefulClusteredProxy(AsynchProvider provider, String containerId, String containerGuid, Interceptor[] interceptors, FamilyWrapper family, LoadBalancePolicy lb, String partitionName)
    {
-      this(containerId, interceptors, family, lb, partitionName);
+      super(containerId, containerGuid, interceptors);
       this.provider = provider;
+      this.family = family;
+      this.lbPolicy = lb;
+      this.partitionName = partitionName;
    }
 
    protected StatefulClusteredProxy()
@@ -98,7 +104,8 @@
       sri.getMetaData().addMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.LOADBALANCE_POLICY, lbPolicy, PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(ClusteredIsLocalInterceptor.PARTITION_NAME, ClusteredIsLocalInterceptor.PARTITION_NAME, partitionName, PayloadKey.TRANSIENT);
-
+      sri.getMetaData().addMetaData(IsLocalInterceptor.IS_LOCAL, IsLocalInterceptor.GUID, containerGuid, PayloadKey.AS_IS);
+      
       if (provider != null)
       {
          sri.getMetaData().addMetaData(AsynchronousInterceptor.ASYNCH, AsynchronousInterceptor.INVOKE_ASYNCH, "YES", PayloadKey.AS_IS);
@@ -130,7 +137,7 @@
          Class[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
          AsynchMixin mixin = new AsynchMixin();
          Interceptor[] newInterceptors = ProxyUtils.addAsynchProxyInterceptor(mixin, interceptors);
-         StatefulClusteredProxy handler = new StatefulClusteredProxy(mixin, containerId, newInterceptors, family, lbPolicy, partitionName);
+         StatefulClusteredProxy handler = new StatefulClusteredProxy(mixin, containerId, containerGuid, newInterceptors, family, lbPolicy, partitionName);
          return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
       }
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -690,6 +690,11 @@
       else
          return factory.createProxy();
    }
+   
+   public boolean isClustered()
+   {
+      return hasAnnotation(getBeanClass(), Clustered.class.getName());
+   }
 
    protected InvocationResponse invokeHomeMethod(MethodInfo info,
                                                  StatefulRemoteInvocation statefulInvocation) throws Throwable

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHomeRemoteProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHomeRemoteProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHomeRemoteProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -29,7 +29,9 @@
 import org.jboss.aop.util.MethodHashing;
 import org.jboss.aop.util.PayloadKey;
 import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
+import org.jboss.ejb3.Container;
 import org.jboss.ejb3.ProxyUtils;
+import org.jboss.ejb3.remoting.IsLocalInterceptor;
 import org.jboss.logging.Logger;
 import org.jboss.remoting.InvokerLocator;
 
@@ -49,15 +51,15 @@
    private HomeHandle homeHandle;
    private EJBMetaData ejbMetaData;
 
-   public StatefulHomeRemoteProxy(Object containerId, Interceptor[] interceptors, InvokerLocator uri)
+   public StatefulHomeRemoteProxy(Container container, Interceptor[] interceptors, InvokerLocator uri)
    {
-      super(containerId, interceptors);
+      super(container, interceptors);
       this.uri = uri;
    }
 
-   public StatefulHomeRemoteProxy(Object containerId, Interceptor[] interceptors, InvokerLocator uri, Object id)
+   public StatefulHomeRemoteProxy(Container container, Interceptor[] interceptors, InvokerLocator uri, Object id)
    {
-      super(containerId, interceptors);
+      super(container, interceptors);
       this.uri = uri;
       this.id = id;
    }
@@ -104,6 +106,7 @@
       sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, containerId, PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, uri, PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS);
+      sri.getMetaData().addMetaData(IsLocalInterceptor.IS_LOCAL, IsLocalInterceptor.GUID, containerGuid, PayloadKey.AS_IS);
 
       return sri.invokeNext();
    }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -35,8 +35,9 @@
 {
    private static final long serialVersionUID = -9026021347498876589L;
 
-   protected StatefulLocalHomeProxy()
+   public StatefulLocalHomeProxy()
    {
+      super();
    }
 
    public StatefulLocalHomeProxy(Container container)
@@ -47,7 +48,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 +59,7 @@
 
    public String toString()
    {
-      return container.getObjectName().getCanonicalName() + ": Home Proxy";
+      return proxyName + ": Home Proxy";
    }
 
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -27,10 +27,15 @@
 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;
@@ -41,19 +46,21 @@
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
  */
-public class StatefulLocalProxy extends LocalProxy implements Externalizable
+public class StatefulLocalProxy extends LocalProxy 
 {
    private static final long serialVersionUID = 206913210970415540L;
    
    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,6 +68,8 @@
       super(container);
       this.provider = provider;
       this.id = id;
+      this.containerGuid = Ejb3Registry.guid(container);
+      isClustered = ((StatefulContainer)container).isClustered();
    }
 
    public StatefulLocalProxy()
@@ -72,6 +81,7 @@
    {
       super.readExternal(in);
       id = in.readObject();
+      isClustered = in.readBoolean();
    }
 
    //@Override
@@ -79,6 +89,7 @@
    {
       super.writeExternal(out);
       out.writeObject(id);
+      out.writeBoolean(isClustered);
    }
 
    public Object invoke(Object proxy, Method method, Object[] args)
@@ -89,14 +100,21 @@
          return provider.getFuture();
       }
 
-      //Make sure we get the cache id before getting the asynchronous interface
-      StatefulContainer sfsb = (StatefulContainer) getContainer();
+      // Make sure we get the cache id before getting the asynchronous interface
       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 +135,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: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -21,19 +21,26 @@
  */
 package org.jboss.ejb3.stateful;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
+import java.rmi.dgc.VMID;
+
 import javax.ejb.LocalHome;
 import javax.naming.NamingException;
 
+import org.jboss.aop.Advisor;
+import org.jboss.ejb3.Ejb3Registry;
 import org.jboss.ejb3.EJBContainer;
 import org.jboss.ejb3.JBossProxy;
-import org.jboss.ejb3.NonSerializableFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.annotation.LocalBinding;
 import org.jboss.ejb3.session.SessionContainer;
+import org.jboss.naming.Util;
 
 
 /**
@@ -44,6 +51,13 @@
  */
 public class StatefulLocalProxyFactory extends BaseStatefulProxyFactory
 {
+   private VMID vmid = Ejb3Registry.getVMID();
+   
+   public StatefulLocalProxyFactory()
+   {
+      super();
+   }
+   
    public StatefulLocalProxyFactory(SessionContainer container, LocalBinding binding)
    {
       super(container, binding.jndiBinding());
@@ -51,7 +65,7 @@
 
    protected Class<?>[] getInterfaces()
    {      
-      StatefulContainer statefulContainer = (StatefulContainer) container;
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
       LocalHome localHome = (LocalHome) statefulContainer.resolveAnnotation(LocalHome.class);
 
       boolean bindTogether = false;
@@ -61,11 +75,11 @@
 
       // Obtain all local interfaces      
       Set<Class<?>> localInterfaces = new HashSet<Class<?>>();
-      localInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getLocalAndBusinessLocalInterfaces(container)));
+      localInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getLocalAndBusinessLocalInterfaces(getContainer())));
       
       // Ensure that if EJB 2.1 Components are defined, they're complete
       this.ensureEjb21ViewComplete(localHome == null ? null : localHome.value(), ProxyFactoryHelper
-            .getLocalInterfaces(container));
+            .getLocalInterfaces(getContainer()));
 
       // Add JBossProxy
       localInterfaces.add(JBossProxy.class);
@@ -93,67 +107,79 @@
 
       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);
-      StatefulContainer statefulContainer = (StatefulContainer) container;
-      LocalHome localHome = (LocalHome) ((EJBContainer) container).resolveAnnotation(LocalHome.class);
+      Util.unbind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME);
+      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()));
       }
    }
 
    public Object createProxy()
    {
-      StatefulContainer sfsb = (StatefulContainer) container;
+      StatefulContainer sfsb = (StatefulContainer) getContainer();
 //      StatefulBeanContext ctx = sfsb.getCache().create();
 //      ctx.setInUse(false);
 //      Object id = ctx.getId();
       Object id = sfsb.createSession();
-      return constructProxy(new StatefulLocalProxy(container, id));
+      return constructProxy(new StatefulLocalProxy(getContainer(), id, vmid));
    }
 
    public Object createProxy(Object id)
    {
-      return constructProxy(new StatefulLocalProxy(container, id));
+      return constructProxy(new StatefulLocalProxy(getContainer(), id, vmid));
    }
    
    public Object createProxy(Class[] initTypes, Object[] initValues)
    {
-      StatefulContainer sfsb = (StatefulContainer) container;
+      StatefulContainer sfsb = (StatefulContainer) getContainer();
       Object id = sfsb.createSession(initTypes, initValues);
-      return constructProxy(new StatefulLocalProxy(container, id));
+      return constructProxy(new StatefulLocalProxy(getContainer(), id, vmid));
    }
 
    protected StatefulHandleImpl getHandle()
    {
       StatefulHandleImpl handle = new StatefulHandleImpl();
-      LocalBinding remoteBinding = (LocalBinding) container.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: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -33,8 +33,11 @@
 import org.jboss.aspects.asynch.AsynchMixin;
 import org.jboss.aspects.asynch.AsynchProvider;
 import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.Ejb3Registry;
 import org.jboss.ejb3.ProxyUtils;
 import org.jboss.ejb3.asynchronous.AsynchronousInterceptor;
+import org.jboss.ejb3.remoting.IsLocalInterceptor;
 import org.jboss.logging.Logger;
 import org.jboss.remoting.InvokerLocator;
 import org.jboss.util.id.GUID;
@@ -58,22 +61,22 @@
    private HomeHandle homeHandle;
    private EJBMetaData ejbMetaData;
 
-   public StatefulRemoteProxy(Object containerId, Interceptor[] interceptors, InvokerLocator uri)
+   public StatefulRemoteProxy(Container container, Interceptor[] interceptors, InvokerLocator uri)
    {
-      super(containerId, interceptors);
+      super(container, interceptors);
       this.uri = uri;
    }
 
-   public StatefulRemoteProxy(Object containerId, Interceptor[] interceptors, InvokerLocator uri, Object id)
+   public StatefulRemoteProxy(Container container, Interceptor[] interceptors, InvokerLocator uri, Object id)
    {
-      super(containerId, interceptors);
+      super(container, interceptors);
       this.uri = uri;
       this.id = id;
    }
 
-   public StatefulRemoteProxy(AsynchProvider provider, Object containerId, Interceptor[] interceptors, InvokerLocator uri)
+   public StatefulRemoteProxy(AsynchProvider provider, String containerId, String containerGuid, Interceptor[] interceptors, InvokerLocator uri)
    {
-      super(containerId, interceptors);
+      super(containerId, containerGuid, interceptors);
       this.uri = uri;
       this.provider = provider;
    }
@@ -125,6 +128,7 @@
       sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, containerId, PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, uri, PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS);
+      sri.getMetaData().addMetaData(IsLocalInterceptor.IS_LOCAL, IsLocalInterceptor.GUID, containerGuid, PayloadKey.AS_IS);
 
       if (provider != null)
       {
@@ -157,7 +161,7 @@
          Class[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
          AsynchMixin mixin = new AsynchMixin();
          Interceptor[] newInterceptors = ProxyUtils.addAsynchProxyInterceptor(mixin, interceptors);
-         StatefulRemoteProxy handler = new StatefulRemoteProxy(mixin, containerId, newInterceptors, uri);
+         StatefulRemoteProxy handler = new StatefulRemoteProxy(mixin, containerId, containerGuid, newInterceptors, uri);
          return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
       }
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -73,7 +73,7 @@
 
    protected Class<?>[] getInterfaces()
    {     
-      StatefulContainer statefulContainer = (StatefulContainer) container;
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
 
       boolean bindTogether = false;
@@ -83,11 +83,11 @@
 
       // Obtain all remote interfaces
       Set<Class<?>> remoteInterfaces = new HashSet<Class<?>>();
-      remoteInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(container)));
+      remoteInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(getContainer())));
 
       // Ensure that if EJB 2.1 Components are defined, they're complete
       this.ensureEjb21ViewComplete(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
-            .getRemoteInterfaces(container));
+            .getRemoteInterfaces(getContainer()));
 
       // Add JBossProxy
       remoteInterfaces.add(JBossProxy.class);
@@ -124,41 +124,41 @@
       String targetId = getTargetId();
       String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       Object factoryProxy = createPojiProxy(targetId, interfaces, clientBindUrl);
-      log.debug("Binding proxy factory for " + container.getEjbName() + " in JNDI at " + jndiName + PROXY_FACTORY_NAME + " with client bind url " + clientBindUrl);
+      log.debug("Binding proxy factory for " + getContainer().getEjbName() + " in JNDI at " + jndiName + PROXY_FACTORY_NAME + " with client bind url " + clientBindUrl);
       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());
-         String homeJndiName = ProxyFactoryHelper.getHomeJndiName(container);
+         String homeJndiName = ProxyFactoryHelper.getHomeJndiName(getContainer());
          log.debug("Binding home proxy at " + homeJndiName);
-         Util.rebind(container.getInitialContext(), homeJndiName, homeProxy);
+         Util.rebind(getContainer().getInitialContext(), homeJndiName, 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();
    }
@@ -168,7 +168,7 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          String stackName = "StatefulSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
@@ -176,12 +176,11 @@
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
          if (stack == null) throw new RuntimeException("unable to find interceptor stack: " + stackName);
-         StatefulHomeRemoteProxy proxy = new StatefulHomeRemoteProxy(containerId, 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)
       {
@@ -190,7 +189,6 @@
    }
    public Object createProxy()
    {
-      Object containerId = container.getObjectName().getCanonicalName();
       String stackName = "StatefulSessionClientInterceptors";
       if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
       {
@@ -198,9 +196,8 @@
       }
       AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
       if (stack == null) throw new RuntimeException("unable to find interceptor stack: " + stackName);
-      StatefulRemoteProxy proxy = new StatefulRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator);
+      StatefulRemoteProxy proxy = new StatefulRemoteProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), locator);
 
-
       setEjb21Objects(proxy);
       return constructProxy(proxy);
    }
@@ -215,14 +212,14 @@
 
    public Object createProxy(Object id)
    {
-      Object containerId = container.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(containerId, stack.createInterceptors((Advisor) container, null), locator, id);
+      StatefulRemoteProxy proxy = new StatefulRemoteProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), locator, id);
+      
       setEjb21Objects(proxy);
       return constructProxy(proxy);
    }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulSessionContextImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulSessionContextImpl.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulSessionContextImpl.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -58,34 +58,41 @@
    /**
     * The container identifier.
     */
-   private String oid;
+   private String containerGuid;
+   private String containerClusterUid;
    /**
     * The SFSB identifier.
     */
    private Object id;
    
+   private boolean isClustered;
+   
    private transient SessionContext delegate;
    
    private static class Serialized implements Serializable
    {
       private static final long serialVersionUID = 1L;
       
-      private String oid;
       private Object id;
+      private String containerClusterUid;
+      private String containerGuid;
+      private boolean isClustered;
       
       private Object readResolve() throws ObjectStreamException
       {
-         return new StatefulSessionContextImpl(oid, id);
+         return new StatefulSessionContextImpl(containerGuid, containerClusterUid, id, isClustered);
       }
    }
    
-   public StatefulSessionContextImpl(String oid, Object id)
+   public StatefulSessionContextImpl(String containerGuid, String containerClusterUid, Object id, boolean isClustered)
    {
-      assert oid != null : "oid is null";
-      assert id != null : "id is null";
+      assert containerGuid != null : "containerGuid is null";
+      assert containerClusterUid != null : "containerClusterUid is null";
       
-      this.oid = oid;
+      this.containerGuid = containerGuid;
+      this.containerClusterUid = containerClusterUid;
       this.id = id;
+      this.isClustered = isClustered;
    }
    
    public StatefulSessionContextImpl(SessionBeanContext beanContext)
@@ -93,15 +100,19 @@
       assert beanContext != null : "beanContext is null";
       
       this.delegate = new SessionContextImpl(beanContext);
-      this.oid = beanContext.getContainer().getObjectName().getCanonicalName();
+      this.containerGuid = Ejb3Registry.guid(beanContext.getContainer());
+      this.containerClusterUid =Ejb3Registry.clusterUid(beanContext.getContainer());
       this.id = beanContext.getId();
+      this.isClustered = beanContext.getContainer().isClustered();
    }
 
    private Object writeReplace() throws ObjectStreamException
    {
       Serialized s = new Serialized();
-      s.oid = this.oid;
+      s.containerGuid = this.containerGuid;
+      s.containerClusterUid = this.containerClusterUid;
       s.id = this.id;
+      s.isClustered = this.isClustered;
       return s;
    }
 
@@ -114,7 +125,11 @@
    {
       if(delegate == null)
       {
-         delegate = new SessionContextImpl(Ejb3Registry.getContainer(oid, StatefulContainer.class).getCache().get(id, false));
+         StatefulContainer container = (StatefulContainer)Ejb3Registry.getContainer(containerGuid);
+         if (container == null && isClustered)
+            container = (StatefulContainer)Ejb3Registry.getClusterContainer(containerClusterUid);
+         
+         delegate = new SessionContextImpl(container.getCache().get(id, false));
       }
       return delegate;
    }
@@ -203,6 +218,6 @@
    
    public String toString()
    {
-      return super.toString() + "{oid=" + oid + ",id=" + id + "}";
+      return super.toString() + "{containerGuid=" + containerGuid + ",id=" + id + "}";
    }
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -181,7 +181,7 @@
       
       
       /* 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);
@@ -236,7 +236,7 @@
 
    public void stop() throws Exception
    {
-      Util.unbind(container.getInitialContext(), jndiName);
+      Util.unbind(getContainer().getInitialContext(), jndiName);
    }
 
    protected abstract Class<?>[] getInterfaces();
@@ -247,11 +247,11 @@
    {
       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;
       }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -77,7 +77,7 @@
 
    protected Class[] getInterfaces()
    {
-      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(container);
+      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(getContainer());
       Class[] interfaces = new Class[remoteInterfaces.length + 1];
       System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length);
       interfaces[remoteInterfaces.length] = JBossProxy.class;
@@ -88,12 +88,12 @@
    {
       String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
-      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,10 +134,10 @@
          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(containerId, stack.createInterceptors((Advisor) container, null), 
-                                                            wrapper, lbPolicy, partitionName));
+         proxy = constructProxy(new StatelessClusteredProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), 
+               wrapper, lbPolicy, partitionName));
          return proxy;
       }
       /*

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusteredProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusteredProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusteredProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -33,11 +33,14 @@
 import org.jboss.aspects.remoting.ClusterConstants;
 import org.jboss.aspects.remoting.FamilyWrapper;
 import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.Ejb3Registry;
 import org.jboss.ejb3.JBossProxy;
 import org.jboss.ejb3.ProxyUtils;
 import org.jboss.ejb3.asynchronous.AsynchronousInterceptor;
 import org.jboss.ejb3.remoting.BaseRemoteProxy;
 import org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor;
+import org.jboss.ejb3.remoting.IsLocalInterceptor;
 import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
 
 /**
@@ -56,18 +59,21 @@
    AsynchProvider provider;
    protected String partitionName;
 
-   public StatelessClusteredProxy(Object containerId, Interceptor[] interceptors, FamilyWrapper family, LoadBalancePolicy lbPolicy, String partitionName)
+   public StatelessClusteredProxy(Container container, Interceptor[] interceptors, FamilyWrapper family, LoadBalancePolicy lbPolicy, String partitionName)
    {
-      super(containerId, interceptors);
+      super(container, interceptors);
       this.family = family;
       this.lbPolicy = lbPolicy;
       this.partitionName = partitionName;
    }
 
-   public StatelessClusteredProxy(AsynchProvider provider, Object containerId, Interceptor[] interceptors, FamilyWrapper family, LoadBalancePolicy lbPolicy, String partitionName)
+   public StatelessClusteredProxy(AsynchProvider provider, String containerId, String containerGuid, Interceptor[] interceptors, FamilyWrapper family, LoadBalancePolicy lbPolicy, String partitionName)
    {
-      this(containerId, interceptors, family, lbPolicy, partitionName);
+      super(containerId, containerGuid, interceptors);
       this.provider = provider;
+      this.family = family;
+      this.lbPolicy = lbPolicy;
+      this.partitionName = partitionName;
    }
 
    public StatelessClusteredProxy()
@@ -97,7 +103,8 @@
       sri.getMetaData().addMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.LOADBALANCE_POLICY, lbPolicy, PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(ClusteredIsLocalInterceptor.PARTITION_NAME, ClusteredIsLocalInterceptor.PARTITION_NAME, partitionName, PayloadKey.TRANSIENT);
-
+      sri.getMetaData().addMetaData(IsLocalInterceptor.IS_LOCAL, IsLocalInterceptor.GUID, containerGuid, PayloadKey.AS_IS);
+      
       if (provider != null)
       {
          sri.getMetaData().addMetaData(AsynchronousInterceptor.ASYNCH, AsynchronousInterceptor.INVOKE_ASYNCH, "YES", PayloadKey.AS_IS);
@@ -113,7 +120,7 @@
          Class[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
          AsynchMixin mixin = new AsynchMixin();
          Interceptor[] newInterceptors = ProxyUtils.addAsynchProxyInterceptor(mixin, interceptors);
-         StatelessClusteredProxy handler = new StatelessClusteredProxy(mixin, containerId, newInterceptors, family, lbPolicy, partitionName);
+         StatelessClusteredProxy handler = new StatelessClusteredProxy(mixin, containerId, containerGuid, newInterceptors, family, lbPolicy, partitionName);
          return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
       }
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -123,7 +123,7 @@
       {
          super.start();
          
-         timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
+         timerService = TimerServiceFactory.getInstance().createTimerService(this, this);
          
          TimerServiceFactory.getInstance().restoreTimerService(timerService);
       }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -31,6 +31,7 @@
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.LocalProxy;
 import org.jboss.ejb3.ProxyUtils;
+import org.jboss.logging.Logger;
 
 /**
  * Comment
@@ -42,6 +43,8 @@
 {
    private static final long serialVersionUID = -3241008127518089831L;
    
+   private static final Logger log = Logger.getLogger(StatelessLocalProxy.class);
+   
    AsynchProvider provider;
 
    public StatelessLocalProxy()
@@ -73,12 +76,14 @@
          return ret;
       }
       
+      StatelessContainer container = (StatelessContainer) getContainer();
+       
       if (container == null)
+      {
          throw new EJBException("Invalid invocation of local interface (null container)");
-
-      StatelessContainer stateless = (StatelessContainer) container;
-
-      return stateless.localInvoke(method, args, (FutureHolder) provider);
+      }
+      
+      return container.localInvoke(method, args, (FutureHolder) provider);
    }
 
    public Object getAsynchronousProxy(Object proxy)
@@ -88,7 +93,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 +118,9 @@
 
    public String toString()
    {
-      return container.getEjbName().toString();
+      if (getContainer() == null)
+         return proxyName;
+      else
+         return getContainer().getEjbName();
    }
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -27,13 +27,14 @@
 
 import javax.ejb.LocalHome;
 
+import org.jboss.aop.Advisor;
 import org.jboss.ejb3.EJBContainer;
 import org.jboss.ejb3.JBossProxy;
-import org.jboss.ejb3.NonSerializableFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.annotation.LocalBinding;
 import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.logging.Logger;
+import org.jboss.naming.Util;
 
 
 /**
@@ -53,7 +54,7 @@
 
    protected Class<?>[] getInterfaces()
    {
-      EJBContainer statelessContainer = (EJBContainer)container;
+      EJBContainer statelessContainer = (EJBContainer)getContainer();
       LocalHome localHome = (LocalHome)statelessContainer.resolveAnnotation(LocalHome.class);
 
       boolean bindTogether = false;
@@ -63,11 +64,11 @@
 
       // Obtain all local interfaces
       Set<Class<?>> localInterfaces = new HashSet<Class<?>>();
-      localInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getLocalAndBusinessLocalInterfaces(container)));
+      localInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getLocalAndBusinessLocalInterfaces(getContainer())));
       
       // Ensure that if EJB 2.1 Components are defined, they're complete
       this.ensureEjb21ViewComplete(localHome == null ? null : localHome.value(), ProxyFactoryHelper
-            .getLocalInterfaces(container));
+            .getLocalInterfaces(getContainer()));
 
       // Ensure local interfaces defined
       if (localInterfaces.size() > 0)
@@ -101,14 +102,14 @@
    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()));
+         Util.rebind(getContainer().getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(getContainer()), homeProxy);
       }
    }
 
@@ -116,11 +117,11 @@
    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));
+         Util.unbind(getContainer().getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(getContainer()));
       }
    }
 
@@ -150,13 +151,13 @@
          throw new RuntimeException(e.getTargetException());  //To change body of catch statement use Options | File Templates.
       }
       */
-      return constructProxy(new StatelessLocalProxy(container));
+      return constructProxy(new StatelessLocalProxy(getContainer()));
    }
 
    protected StatelessHandleImpl getHandle()
    {
       StatelessHandleImpl handle = new StatelessHandleImpl();
-      LocalBinding remoteBinding = (LocalBinding) container.resolveAnnotation(LocalBinding.class);
+      LocalBinding remoteBinding = (LocalBinding) ((Advisor)getContainer()).resolveAnnotation(LocalBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxy.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxy.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -31,8 +31,10 @@
 import org.jboss.aspects.asynch.AsynchMixin;
 import org.jboss.aspects.asynch.AsynchProvider;
 import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
+import org.jboss.ejb3.Container;
 import org.jboss.ejb3.ProxyUtils;
 import org.jboss.ejb3.asynchronous.AsynchronousInterceptor;
+import org.jboss.ejb3.remoting.IsLocalInterceptor;
 import org.jboss.logging.Logger;
 import org.jboss.remoting.InvokerLocator;
 
@@ -50,19 +52,20 @@
    protected InvokerLocator uri;
    AsynchProvider provider;
 
-   public StatelessRemoteProxy(Object containerId, Interceptor[] interceptors, InvokerLocator uri)
+   public StatelessRemoteProxy(Container container, Interceptor[] interceptors, InvokerLocator uri)
    {
-      super(containerId, interceptors);
+      super(container, interceptors);
       this.uri = uri;
    }
 
-   public StatelessRemoteProxy(AsynchProvider provider, Object containerId, Interceptor[] interceptors, InvokerLocator uri)
+   public StatelessRemoteProxy(AsynchProvider provider, String containerId, String containerGuid, Interceptor[] interceptors, InvokerLocator uri)
    {
-      super(containerId, interceptors);
+      super(containerId, containerGuid, interceptors);
       this.uri = uri;
       this.provider = provider;
    }
 
+
    protected StatelessRemoteProxy()
    {
    }
@@ -95,7 +98,9 @@
       sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, containerId, PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, uri, PayloadKey.AS_IS);
       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS);
+      sri.getMetaData().addMetaData(IsLocalInterceptor.IS_LOCAL, IsLocalInterceptor.GUID, containerGuid, PayloadKey.AS_IS);
 
+
       if (provider != null)
       {
          sri.getMetaData().addMetaData(AsynchronousInterceptor.ASYNCH, AsynchronousInterceptor.INVOKE_ASYNCH, "YES", PayloadKey.AS_IS);
@@ -111,7 +116,7 @@
          Class[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
          AsynchMixin mixin = new AsynchMixin();
          Interceptor[] newInterceptors = ProxyUtils.addAsynchProxyInterceptor(mixin, interceptors);
-         StatelessRemoteProxy handler = new StatelessRemoteProxy(mixin, containerId, newInterceptors, uri);
+         StatelessRemoteProxy handler = new StatelessRemoteProxy(mixin, containerId, containerGuid, newInterceptors, uri);
          return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
       }
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -64,7 +64,7 @@
 
    protected Class<?>[] getInterfaces()
    {
-      StatelessContainer statelessContainer = (StatelessContainer) container;
+      StatelessContainer statelessContainer = (StatelessContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statelessContainer.resolveAnnotation(RemoteHome.class);
 
       boolean bindTogether = false;
@@ -74,11 +74,11 @@
 
       // Obtain all remote interfaces
       Set<Class<?>> remoteInterfaces = new HashSet<Class<?>>();
-      remoteInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(container)));
+      remoteInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(getContainer())));
       
       // Ensure that if EJB 2.1 Components are defined, they're complete
       this.ensureEjb21ViewComplete(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
-            .getRemoteInterfaces(container));
+            .getRemoteInterfaces(getContainer()));
 
       // Ensure remote interfaces defined
       if (remoteInterfaces.size() > 0)
@@ -118,20 +118,20 @@
    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());
-         String jndiName = ProxyFactoryHelper.getHomeJndiName(container);
+         String jndiName = ProxyFactoryHelper.getHomeJndiName(getContainer());
          try
          {
-            log.debug("Binding proxy for " + container.getEjbName() + " in JNDI at " + jndiName);
-            Util.rebind(container.getInitialContext(), jndiName, homeProxy);
+            log.debug("Binding proxy for " + getContainer().getEjbName() + " in JNDI at " + jndiName);
+            Util.rebind(getContainer().getInitialContext(), jndiName, homeProxy);
          }
          catch (NamingException e)
          {
-            NamingException namingException = new NamingException("Could not bind stateless home proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName);
+            NamingException namingException = new NamingException("Could not bind stateless home proxy with ejb name " + getContainer().getEjbName() + " into JNDI under jndiName: " + getContainer().getInitialContext().getNameInNamespace() + "/" + jndiName);
             namingException.setRootCause(e);
             throw namingException;
          }
@@ -142,18 +142,18 @@
    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) container.resolveAnnotation(RemoteBinding.class);
+      RemoteBinding remoteBinding = (RemoteBinding) ((Advisor)getContainer()).resolveAnnotation(RemoteBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding() ;
 
@@ -164,18 +164,17 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
-         ;
          String stackName = "StatelessSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
             stackName = binding.interceptorStack();
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
-         StatelessRemoteProxy proxy = new StatelessRemoteProxy(containerId, 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.getBeanClass().getClassLoader(), interfaces, proxy);
+         return java.lang.reflect.Proxy.newProxyInstance(getContainer().getBeanClass().getClassLoader(), interfaces, proxy);
       }
       catch (IllegalArgumentException e)
       {
@@ -187,15 +186,14 @@
    {
 //      try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
-         ;
          String stackName = "StatelessSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
             stackName = binding.interceptorStack();
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
-         StatelessRemoteProxy proxy = new StatelessRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator);
+         StatelessRemoteProxy proxy = new StatelessRemoteProxy(getContainer(),
+               stack.createInterceptors((Advisor) getContainer(), null), locator);
          setEjb21Objects(proxy);
          /*
          Object[] args = {proxy};

Modified: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -25,6 +25,8 @@
 import javax.ejb.TimerService;
 import javax.management.ObjectName;
 
+import org.jboss.ejb3.Container;
+
 /**
  * Comment
  *
@@ -64,7 +66,7 @@
       }
    }
    
-   public abstract TimerService createTimerService(ObjectName objectName, TimedObjectInvoker invoker);
+   public abstract TimerService createTimerService(Container container, TimedObjectInvoker invoker);
    
    public static TimerServiceFactory getInstance()
    {

Modified: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -25,6 +25,7 @@
 import javax.management.ObjectName;
 
 import org.jboss.ejb.txtimer.EJBTimerService;
+import org.jboss.ejb3.Container;
 import org.jboss.ejb3.EJBContainer;
 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
 import org.jboss.ejb3.timerservice.TimerServiceFactory;
@@ -46,14 +47,14 @@
     * @see org.jboss.ejb3.timerservice.TimerServiceFactory#createTimerService(javax.management.ObjectName, org.jboss.ejb3.timerservice.TimedObjectInvoker)
     */
    @Override
-   public TimerService createTimerService(ObjectName containerId, TimedObjectInvoker invoker)
+   public TimerService createTimerService(Container container, TimedObjectInvoker invoker)
    {
       TimerService timerService = null;
       try
       {
          EJBTimerService service = getEJBTimerService();
-         TimerService delegate = service.createTimerService(containerId, null, invoker);
-         timerService = new TimerServiceFacade(containerId, delegate);
+         TimerService delegate = service.createTimerService(container.getObjectName(), null, invoker);
+         timerService = new TimerServiceFacade(container, delegate);
       }
       catch (Exception e)
       {

Modified: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -30,8 +30,8 @@
 import javax.ejb.TimerService;
 import javax.management.ObjectName;
 
+import org.jboss.ejb3.Container;
 import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.Ejb3Registry;
 
 /**
  * Comment
@@ -43,11 +43,11 @@
 {
    private TimerService delegate;
    
-   private ObjectName containerId;
+   private Container container;
    
-   protected TimerServiceFacade(ObjectName containerId, TimerService delegate)
+   protected TimerServiceFacade(Container container, TimerService delegate)
    {
-      this.containerId = containerId;
+      this.container = container;
       this.delegate = delegate;
    }
 
@@ -73,12 +73,12 @@
 
    protected EJBContainer getContainer()
    {
-      return (EJBContainer) Ejb3Registry.getContainer(getContainerId().getCanonicalName());
+      return (EJBContainer) container;
    }
    
    protected ObjectName getContainerId()
    {
-      return containerId;
+      return container.getObjectName();
    }
    
    public Collection getTimers() throws IllegalStateException, EJBException

Modified: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -53,25 +53,25 @@
    //private String jobGroup;
    private String triggerName;
    private String triggerGroup;
-   private ObjectName objectName;
+   private String containerGuid;
    
    private Serializable info;
    
-   protected PersistentTimer(Trigger trigger, ObjectName objectName, Serializable info)
+   protected PersistentTimer(Trigger trigger, String containerGuid, Serializable info)
    {
       assert trigger != null;
-      assert objectName != null;
+      assert containerGuid != null;
       
       this.triggerName = trigger.getName();
       this.triggerGroup = trigger.getGroup();
-      this.objectName = objectName;
       this.info = info;
+      this.containerGuid = containerGuid;
    }
    
    protected TimedObjectInvoker getTimedObjectInvoker()
    {
       // TODO: a hack to get back the container. This needs thinking.
-      TimedObjectInvoker invoker = (TimedObjectInvoker) Ejb3Registry.getContainer(objectName.getCanonicalName());
+      TimedObjectInvoker invoker = (TimedObjectInvoker) Ejb3Registry.getContainer(containerGuid);
       assert invoker != null;
       return invoker;
    }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -37,6 +37,7 @@
 import javax.transaction.SystemException;
 import javax.transaction.TransactionManager;
 
+import org.jboss.ejb3.Container;
 import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
 import org.jboss.ejb3.timerservice.TimerServiceFactory;
@@ -152,12 +153,12 @@
     * @param invoker    the invoker to call on timeouts
     * @return           an EJB TimerService
     */
-   public TimerService createTimerService(ObjectName objectName, TimedObjectInvoker invoker)
+   public TimerService createTimerService(Container container, TimedObjectInvoker invoker)
    {
       Scheduler scheduler = getScheduler();
       if (scheduler == null) return null;
       
-      return new TimerServiceImpl(scheduler, objectName, invoker);
+      return new TimerServiceImpl(scheduler, container, invoker);
    }
    
    private boolean execute(Connection conn, String stmtName) throws SQLException

Modified: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -30,6 +30,8 @@
 import javax.ejb.TimerService;
 import javax.management.ObjectName;
 
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.Ejb3Registry;
 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
 import org.jboss.logging.Logger;
 import org.quartz.JobDetail;
@@ -51,18 +53,21 @@
    private static final Logger log = Logger.getLogger(TimerServiceImpl.class);
    
    private Scheduler scheduler;
+   private Container container;
    private ObjectName objectName;
    private String groupName;
    private long jobNum = 0;
    private long triggerNum = 0;
    
-   protected TimerServiceImpl(Scheduler scheduler, ObjectName objectName, TimedObjectInvoker invoker) {
+   protected TimerServiceImpl(Scheduler scheduler, Container container, TimedObjectInvoker invoker) {
       assert scheduler != null;
       assert objectName != null;
+      assert container != null;
       assert invoker != null;
       
       this.scheduler = scheduler;
-      this.objectName = objectName;
+      this.container = container;
+      this.objectName = container.getObjectName();
       this.groupName = objectName.getCanonicalName();
    }
    
@@ -76,7 +81,7 @@
          
          Timer timer = new TimerImpl(scheduler, trigger, info);
          
-         PersistentTimer persistentTimer = new PersistentTimer(trigger, objectName, info);
+         PersistentTimer persistentTimer = new PersistentTimer(trigger, Ejb3Registry.guid(container), info);
          
          JobDetail jobDetail = new JobDetail(name, groupName, jobClass);
          jobDetail.getJobDataMap().put("timer", persistentTimer);

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/localfromremote/unit/LocalTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/localfromremote/unit/LocalTestCase.java	2007-12-11 17:21:08 UTC (rev 68143)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/localfromremote/unit/LocalTestCase.java	2007-12-11 18:47:28 UTC (rev 68144)
@@ -21,29 +21,48 @@
  */
 package org.jboss.ejb3.test.localfromremote.unit;
 
+import javax.naming.Context;
 import javax.naming.InitialContext;
 
+import javax.management.MBeanServerConnection;
+import javax.naming.InitialContext;
+import java.util.Properties;
+
 import org.jboss.ejb3.test.localfromremote.StatefulRemote;
 import org.jboss.ejb3.test.localfromremote.StatefulRemoteHome;
 import org.jboss.ejb3.test.localfromremote.StatelessRemote;
 import org.jboss.ejb3.test.localfromremote.StatelessRemoteHome;
 import org.jboss.logging.Logger;
-import org.jboss.test.JBossTestCase;
+import org.jboss.test.JBossClusteredTestCase;
 import junit.framework.Test;
 
 /**
  * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
  */
-public class LocalTestCase extends JBossTestCase
+public class LocalTestCase extends JBossClusteredTestCase
 {
    private static final Logger log = Logger.getLogger(LocalTestCase.class);
 
    static boolean deployed = false;
    static int test = 0;
+   
+   protected MBeanServerConnection server1;
+   protected MBeanServerConnection server2;
 
    public LocalTestCase(String name)
    {
       super(name);
+      
+      try
+      {
+         String adaptorName = System.getProperty("jbosstest.server.name", "jmx/invoker/RMIAdaptor");
+         server1 = (MBeanServerConnection)getInitialContext(1099).lookup(adaptorName);
+         server2 = (MBeanServerConnection)getInitialContext(1199).lookup(adaptorName);
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+      }
    }
  
    public void testStatelessLocalFromRemote() throws Exception
@@ -148,6 +167,32 @@
       }
    }
    
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+    
+      deploy(server1, "localfromremote-test1.jar");
+      deploy(server2, "localfromremote-test2.jar");
+   }
+   
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      undeploy(server1, "localfromremote-test1.jar");
+      undeploy(server2, "localfromremote-test2.jar");
+   }
+   
+   protected InitialContext getInitialContext(int port) throws Exception
+   {
+      Properties env = new Properties();
+      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+      env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
+      env.put(Context.PROVIDER_URL, "localhost:" + port);
+      
+      return new InitialContext(env);
+   }
+   
    public static Test suite() throws Exception
    {
       return getDeploySetup(LocalTestCase.class, ""); 




More information about the jboss-cvs-commits mailing list