[jboss-cvs] JBossAS SVN: r64591 - in branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3: deployers and 13 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 14 20:33:04 EDT 2007


Author: bdecoste
Date: 2007-08-14 20:33:04 -0400 (Tue, 14 Aug 2007)
New Revision: 64591

Modified:
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/EJB3StandaloneDeployer.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JaasSecurityManagerService.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JavaCompInitializer.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JndiBinder.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/mdb/ProducerManagerImpl.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/naming/SimpleMultiplexer.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/proxy/handle/HomeHandleImpl.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/BaseRemoteProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/session/BaseSessionRemoteProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusteredProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHandleImpl.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHomeRemoteProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusteredProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessHandleImpl.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxy.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java
Log:
[EJBTHREE-1019] merged from Branch_4_2

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -35,13 +35,13 @@
 
 import javax.annotation.PostConstruct;
 import javax.naming.Context;
-import javax.naming.InitialContext;
 import javax.naming.NameClassPair;
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
 
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.DependencyPolicy;
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.ejb3.entity.PersistenceUnitDeployment;
 import org.jboss.ejb3.metamodel.ApplicationClientDD;
 import org.jboss.ejb3.metamodel.LifecycleCallback;
@@ -93,7 +93,7 @@
       this.applicationClientName = applicationClientName;
       
       //Context ctx = getInitialContext();
-      Context ctx = new InitialContext();
+      Context ctx = InitialContextFactory.getInitialContext();
       enc = (Context) ctx.lookup(applicationClientName);
       NamingEnumeration<NameClassPair> e = enc.list("");
       while(e.hasMore())

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -24,6 +24,7 @@
 import org.jboss.deployers.plugins.deployers.helpers.AbstractSimpleRealDeployer;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.ejb3.KernelAbstraction;
 import org.jboss.ejb3.MCKernelAbstraction;
 import org.jboss.ejb3.clientmodule.ClientENCInjectionContainer;
@@ -72,7 +73,7 @@
       try
       {
          // I create the namespace here, because I destroy it in undeploy
-         InitialContext iniCtx = new InitialContext();
+         InitialContext iniCtx = InitialContextFactory.getInitialContext();
          Context encCtx = Util.createSubcontext(iniCtx, appClientName);
          log.debug("Creating client ENC binding under: " + appClientName);
 
@@ -204,7 +205,7 @@
       log.debug("Removing client ENC from: " + jndiName);
       try
       {
-         InitialContext iniCtx = new InitialContext();
+         InitialContext iniCtx = InitialContextFactory.getInitialContext();
          Util.unbind(iniCtx, jndiName);
       }
       catch(NameNotFoundException e)

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/EJB3StandaloneDeployer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/EJB3StandaloneDeployer.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/EJB3StandaloneDeployer.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -45,6 +45,7 @@
 
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.ejb3.DeploymentUnit;
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
 import org.jboss.kernel.Kernel;
 import org.jboss.logging.Logger;
@@ -316,7 +317,6 @@
 
    public void setArchives(Set archives)
    {
-      new Exception().printStackTrace();
       this.archives = archives;
    }
 
@@ -547,7 +547,7 @@
    {
       System.out.println("lookup " + name);
       try {
-         InitialContext jndiContext = new InitialContext();
+         InitialContext jndiContext = InitialContextFactory.getInitialContext();
          NamingEnumeration names = jndiContext.list(name);
          if (names != null){
             while (names.hasMore()){

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JaasSecurityManagerService.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JaasSecurityManagerService.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JaasSecurityManagerService.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -22,6 +22,7 @@
 package org.jboss.ejb3.embedded;
 
 
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.ejb3.naming.BrainlessContext;
 import org.jboss.logging.Logger;
 import org.jboss.security.auth.callback.SecurityAssociationHandler;
@@ -63,8 +64,7 @@
 
    private InitialContext getInitialContext() throws NamingException
    {
-      if (initialContextProperties != null) return new InitialContext(initialContextProperties);
-      else return new InitialContext();
+      return InitialContextFactory.getInitialContext(initialContextProperties);
    }
 
    public void start() throws Exception

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JavaCompInitializer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JavaCompInitializer.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JavaCompInitializer.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -25,6 +25,7 @@
 import javax.naming.InitialContext;
 import org.jboss.ejb3.EJB3Deployer;
 import org.jboss.ejb3.EJB3Util;
+import org.jboss.ejb3.InitialContextFactory;
 
 /**
  * Initializes java:comp
@@ -49,7 +50,7 @@
 
    public void start() throws Exception
    {
-      InitialContext ctx = EJB3Util.getInitialContext(jndiProperties);
+      InitialContext ctx = InitialContextFactory.getInitialContext(jndiProperties);
       EJB3Deployer.initializeJavaComp(ctx);
    }
 }

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JndiBinder.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JndiBinder.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/embedded/JndiBinder.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -26,6 +26,7 @@
 import javax.naming.NamingException;
 
 import org.jboss.ejb3.EJB3Util;
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.ejb3.NonSerializableFactory;
 import org.jboss.naming.Util;
 
@@ -64,7 +65,7 @@
 
    public void start() throws Exception
    {
-      InitialContext ctx = EJB3Util.getInitialContext(properties);
+      InitialContext ctx = InitialContextFactory.getInitialContext(properties);
       
       try
       {
@@ -86,7 +87,7 @@
 
    public void stop() throws Exception
    {
-      InitialContext ctx = EJB3Util.getInitialContext(properties);
+      InitialContext ctx = InitialContextFactory.getInitialContext(properties);
       if (serializable)
       {
          Util.unbind(ctx, bindTo);

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -37,6 +37,7 @@
 import org.jboss.annotation.ejb.RemoteBinding;
 import org.jboss.aop.Advisor;
 import org.jboss.ejb3.Container;
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.ejb3.NonSerializableFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.SessionContainer;
@@ -269,13 +270,13 @@
       
       // Get orb and irPoa references
       try {
-         orb = (ORB)new InitialContext().lookup("java:/" + CorbaORBService.ORB_NAME);
+         orb = (ORB)InitialContextFactory.getInitialContext().lookup("java:/" + CorbaORBService.ORB_NAME);
       }
       catch (NamingException e) {
          throw new Exception("Cannot lookup java:/" + CorbaORBService.ORB_NAME + ": " + e);
       }
       try {
-         irPoa = (POA)new InitialContext().lookup("java:/" + CorbaORBService.IR_POA_NAME);
+         irPoa = (POA)InitialContextFactory.getInitialContext().lookup("java:/" + CorbaORBService.IR_POA_NAME);
       }
       catch (NamingException e) {
          throw new Exception("Cannot lookup java:/" + CorbaORBService.IR_POA_NAME + ": " + e);
@@ -373,7 +374,7 @@
       }
       
       // bind HandleDelegate stuff
-      Context compCtx = (Context) new InitialContext().lookup("java:comp");
+      Context compCtx = (Context) InitialContextFactory.getInitialContext().lookup("java:comp");
       NonSerializableFactory.rebind(compCtx, "ORB", orb);
       NonSerializableFactory.rebind(compCtx, "HandleDelegate", new HandleDelegateImpl());
    }
@@ -435,7 +436,7 @@
 
    private NamingContextExt getNamingContextExt() throws NamingException
    {
-      Context initialContext = new InitialContext();
+      Context initialContext = InitialContextFactory.getInitialContext();
       
       // NOTE: eclipse editor parser crashes silently on this line (because of org.jboss.iiop.CorbaNamingService) with unknown reason
       // that's why this method is at the end

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -147,7 +147,7 @@
          
       innerStart();
 
-      timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
+      timerService = TimerServiceFactory.getInstance().createTimerService(this, this);
 
       startProxies();
       

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/mdb/ProducerManagerImpl.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/mdb/ProducerManagerImpl.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/mdb/ProducerManagerImpl.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -44,6 +44,7 @@
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.ejb3.EJB3Util;
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.logging.Logger;
 
 /**
@@ -106,7 +107,7 @@
       initialContextProperties = (Hashtable)in.readObject();
       try
       {
-         initialContext = EJB3Util.getInitialContext(initialContextProperties);
+         initialContext = InitialContextFactory.getInitialContext(initialContextProperties);
       }
       catch (NamingException e)
       {
@@ -134,7 +135,7 @@
       this.initialContextProperties = initialContextProperties;
       try
       {
-         this.initialContext = EJB3Util.getInitialContext(initialContextProperties);
+         this.initialContext = InitialContextFactory.getInitialContext(initialContextProperties);
       }
       catch (NamingException e)
       {
@@ -164,7 +165,7 @@
       this.initialContextProperties = initialContextProperties;
       try
       {
-         this.initialContext = EJB3Util.getInitialContext(initialContextProperties);
+         this.initialContext = InitialContextFactory.getInitialContext(initialContextProperties);
       }
       catch (NamingException e)
       {

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/naming/SimpleMultiplexer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/naming/SimpleMultiplexer.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/naming/SimpleMultiplexer.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -31,6 +31,7 @@
 import javax.naming.NamingException;
 import javax.naming.spi.ObjectFactory;
 
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.logging.Logger;
 
 /**
@@ -81,7 +82,7 @@
    {
       if(nameCtx == null)
       {
-         nameCtx = (Context) new InitialContext().lookup("java:");
+         nameCtx = (Context) InitialContextFactory.getInitialContext().lookup("java:");
          try
          {
             return createMultiplexer(nameCtx);

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/proxy/handle/HomeHandleImpl.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/proxy/handle/HomeHandleImpl.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/proxy/handle/HomeHandleImpl.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -33,6 +33,8 @@
 import java.io.IOException;
 import java.io.ObjectOutputStream;
 import java.util.Hashtable;
+
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.naming.NamingContextFactory;
 
 
@@ -97,11 +99,8 @@
    {
       try
       {
-         InitialContext ic = null;
-         if( jndiEnv != null )
-            ic = new InitialContext(jndiEnv);
-         else
-            ic = new InitialContext();
+         InitialContext ic = InitialContextFactory.getInitialContext(jndiEnv);
+        
          EJBHome home = (EJBHome) ic.lookup(jndiName);
          return home;
       }

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/BaseRemoteProxy.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/BaseRemoteProxy.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/BaseRemoteProxy.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/ClusteredIsLocalInterceptor.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -147,7 +147,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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxy.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -73,7 +73,7 @@
          return ret;
       }
 
-      ServiceContainer sc = (ServiceContainer) container;
+      ServiceContainer sc = (ServiceContainer) getContainer();
       return sc.localInvoke(method, args, (FutureHolder) provider);
    }
 
@@ -84,7 +84,7 @@
       {
          Class[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
          AsynchMixin mixin = new AsynchMixin();
-         ServiceLocalProxy handler = new ServiceLocalProxy(mixin, container);
+         ServiceLocalProxy handler = new ServiceLocalProxy(mixin, getContainer());
          return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
       }
 
@@ -108,7 +108,7 @@
 
    public String toString()
    {
-      return container.getEjbName().toString();
+      return proxyName;
    }
 
 }

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

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/session/BaseSessionRemoteProxy.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/session/BaseSessionRemoteProxy.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/session/BaseSessionRemoteProxy.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -27,6 +27,8 @@
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.proxy.ejb.handle.StatefulHandleImpl;
 
+import org.jboss.ejb3.Container;
+
 /**
  * Comment
  *
@@ -41,11 +43,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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -21,6 +21,9 @@
  */
 package org.jboss.ejb3.stateful;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import javax.naming.Context;
@@ -44,18 +47,13 @@
 {
    private static final Logger log = Logger.getLogger(BaseStatefulProxyFactory.class);
 
-   protected Class proxyClass;
-   protected Constructor proxyConstructor;
-   protected Context proxyFactoryContext;
-   protected String jndiName;
-
    public static final String PROXY_FACTORY_NAME = "StatefulProxyFactory";
 
    public void init() throws Exception
    {
       initializeJndiName();
       Class[] interfaces = getInterfaces();
-      Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
+      Class proxyClass = java.lang.reflect.Proxy.getProxyClass(getContainer().getBeanClass().getClassLoader(), interfaces);
       final Class[] constructorParams =
               {InvocationHandler.class};
       proxyConstructor = proxyClass.getConstructor(constructorParams);
@@ -65,7 +63,7 @@
    {
       init();
 
-      Context ctx = container.getInitialContext();
+      Context ctx = getContainer().getInitialContext();
       Name name = ctx.getNameParser("").parse(jndiName);
       ctx = Util.createSubcontext(ctx, name.getPrefix(name.size() - 1));
       String atom = name.get(name.size() - 1);
@@ -76,7 +74,7 @@
          Util.rebind(ctx, atom, ref);
       } catch (NamingException e)
       {
-         NamingException namingException = new NamingException("Could not bind stateful proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + ctx.getNameInNamespace() + "/" + atom);
+         NamingException namingException = new NamingException("Could not bind stateful proxy with ejb name " + getContainer().getEjbName() + " into JNDI under jndiName: " + ctx.getNameInNamespace() + "/" + atom);
          namingException.setRootCause(e);
          throw namingException;
       }
@@ -84,10 +82,19 @@
 
    public void stop() throws Exception
    {
-      Util.unbind(container.getInitialContext(), jndiName);
+      Util.unbind(getContainer().getInitialContext(), jndiName);
    }
 
-   protected abstract Class[] getInterfaces();
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      super.readExternal(in);
+   }
 
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      super.writeExternal(out);     
+   }
+   
    protected abstract void initializeJndiName();
+
 }

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -30,6 +30,8 @@
 import javax.persistence.EntityManager;
 import org.jboss.aop.metadata.SimpleMetaData;
 
+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
@@ -47,8 +49,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);
@@ -62,8 +66,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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -88,7 +88,9 @@
 
    protected boolean removed;
 
-   protected String containerName;
+   protected String containerClusterUid;
+   protected String containerGuid;
+   protected boolean isClustered = false;
    
    protected boolean replicationIsPassivation = true;
    
@@ -308,8 +310,10 @@
          containedIn = propagatedContainedIn.get();
          NestedStatefulBeanContext nested = new NestedStatefulBeanContext();
          nested.id = id;
+         nested.isClustered = isClustered;
          nested.container = getContainer();
-         nested.containerName = containerName;
+         nested.containerClusterUid = containerClusterUid;
+         nested.containerGuid = containerGuid;
          nested.bean = bean;
          nested.replicationIsPassivation = replicationIsPassivation;
          containedIn.addContains(nested);
@@ -720,16 +724,23 @@
    public void setContainer(Container container)
    {
       super.setContainer(container);
-      containerName = container.getObjectName().getCanonicalName();
+      containerClusterUid = Ejb3Registry.clusterUid(container);
+      containerGuid = Ejb3Registry.guid(container);
+      isClustered = ((StatefulContainer)container).isClustered();
    }
 
    public Container getContainer()
    {
       if (container == null)
       {
-         container = Ejb3Registry.getContainer(containerName);
+         container = Ejb3Registry.findContainer(containerGuid);
+          
+         if (isClustered && container == null)
+            container = Ejb3Registry.getClusterContainer(containerClusterUid);
       }
+      
       return container;
+
    }
 
    @Override
@@ -816,10 +827,12 @@
 
    public void writeExternal(ObjectOutput out) throws IOException
    {
-      out.writeUTF(containerName);
+      out.writeUTF(containerClusterUid);
+      out.writeUTF(containerGuid);
       out.writeObject(id);
       out.writeObject(metadata);
       out.writeLong(lastUsed);
+      out.writeBoolean(isClustered);
       
       if (beanMO == null)
       {
@@ -859,10 +872,12 @@
    public void readExternal(ObjectInput in) throws IOException,
            ClassNotFoundException
    {
-      containerName = in.readUTF();
+      containerClusterUid = in.readUTF();
+      containerGuid = in.readUTF();
       id = in.readObject();
       metadata = (SimpleMetaData) in.readObject();
       lastUsed = in.readLong();
+      isClustered = in.readBoolean();
       
       beanMO = (MarshalledObject) in.readObject();
       removed = in.readBoolean();

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -40,9 +40,9 @@
    
    private transient StatefulBeanContext beanContext;
    private Object oid;
-   private String containerId;
-   
-   
+   private String containerGuid;
+   private String containerClusterUid;
+   private boolean isClustered = false;
 
    public StatefulBeanContextReference()
    {
@@ -52,26 +52,36 @@
    {
       this.beanContext = beanContext;
       oid = beanContext.getId();
-      containerId = beanContext.getContainer().getObjectName().getCanonicalName();
+      
+      StatefulContainer statefulContainer = (StatefulContainer)beanContext.getContainer();
+      containerGuid = Ejb3Registry.guid(statefulContainer);
+      containerClusterUid = Ejb3Registry.clusterUid(statefulContainer);
+      isClustered = statefulContainer.isClustered();
    }
 
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
    {
-      containerId = in.readUTF();
+      containerGuid = in.readUTF();
+      containerClusterUid = in.readUTF();
       oid = in.readObject();
+      isClustered = in.readBoolean();
    }
 
    public void writeExternal(ObjectOutput out) throws IOException
    {
-      out.writeUTF(containerId);
+      out.writeUTF(containerGuid);
+      out.writeUTF(containerClusterUid);
       out.writeObject(oid);
+      out.writeBoolean(isClustered);
    }
 
    public StatefulBeanContext getBeanContext()
    {
       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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -80,7 +80,7 @@
 
    protected Class[] getInterfaces()
    {
-      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
+      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(getContainer());
       Class[] interfaces = new Class[remoteInterfaces.length + 1];
       System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length);
       interfaces[remoteInterfaces.length] = JBossProxy.class;
@@ -89,21 +89,21 @@
 
    protected void initializeJndiName()
    {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
+      jndiName = ProxyFactoryHelper.getRemoteJndiName(getContainer(), binding);
    }
 
    public void start() throws Exception
    {
       String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
-      Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class);
+      Clustered clustered = (Clustered) ((Advisor)getContainer()).resolveAnnotation(Clustered.class);
       if (clustered == null) throw new RuntimeException("Could not find @Clustered annotation.  Cannot deploy.");
-      String partitionName = ((StatefulContainer) container).getPartitionName();
-      proxyFamilyName = ((StatefulContainer) container).getDeploymentQualifiedName() + locator.getProtocol() + partitionName;
-      HAPartition partition = (HAPartition) container.getInitialContext().lookup("/HAPartition/" + partitionName);
+      String partitionName = ((StatefulContainer) getContainer()).getPartitionName();
+      proxyFamilyName = ((StatefulContainer) getContainer()).getDeploymentQualifiedName() + locator.getProtocol() + partitionName;
+      HAPartition partition = (HAPartition) getContainer().getInitialContext().lookup("/HAPartition/" + partitionName);
       hatarget = new HATarget(partition, proxyFamilyName, locator, HATarget.ENABLE_INVOCATIONS);
       ClusteringTargetsRepository.initTarget(proxyFamilyName, hatarget.getReplicants());
-      ((StatefulContainer) container).getClusterFamilies().put(proxyFamilyName, hatarget);
+      ((StatefulContainer) getContainer()).getClusterFamilies().put(proxyFamilyName, hatarget);
       if (clustered.loadBalancePolicy() == null || clustered.loadBalancePolicy().equals(LoadBalancePolicy.class))
       {
          lbPolicy = new FirstAvailable();
@@ -124,10 +124,10 @@
       Object factoryProxy = Remoting.createPojiProxy(targetId, interfaces, ProxyFactoryHelper.getClientBindUrl(binding));
       try
       {
-         Util.rebind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
+         Util.rebind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
       } catch (NamingException e)
       {
-         NamingException namingException = new NamingException("Could not bind stateful cluster proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
+         NamingException namingException = new NamingException("Could not bind stateful cluster proxy with ejb name " + getContainer().getEjbName() + " into JNDI under jndiName: " + getContainer().getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
          namingException.setRootCause(e);
          throw namingException;
       }
@@ -139,16 +139,16 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          String stackName = "ClusteredStatefulSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
             stackName = binding.interceptorStack();
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
-         String partitionName = ((StatefulContainer) container).getPartitionName();
-         Object[] args = {new StatefulClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null), 
-                                                     wrapper, lbPolicy, partitionName)};
+         String partitionName = ((StatefulContainer) getContainer()).getPartitionName();
+         Object[] args = {new StatefulClusteredProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), 
+               wrapper, lbPolicy, partitionName)};
          
          return proxyConstructor.newInstance(args);
       }
@@ -180,15 +180,15 @@
       Dispatcher.singleton.unregisterTarget(getTargetId());
       hatarget.destroy();
       drm.unregisterListener(proxyFamilyName, this);
-      ((StatefulContainer) container).getClusterFamilies().remove(proxyFamilyName);
-      Util.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
+      ((StatefulContainer) getContainer()).getClusterFamilies().remove(proxyFamilyName);
+      Util.unbind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME);
       super.stop();
    }
    
    protected StatefulHandleImpl getHandle()
    {
       StatefulHandleImpl handle = new StatefulHandleImpl();
-      RemoteBinding remoteBinding = (RemoteBinding)advisor.resolveAnnotation(RemoteBinding.class);
+      RemoteBinding remoteBinding = (RemoteBinding)((Advisor)getContainer()).resolveAnnotation(RemoteBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
  
@@ -197,8 +197,8 @@
    
    protected String getTargetId()
    {  
-      String partition = ((StatefulContainer) container).getPartitionName();
-      return container.getObjectName().getCanonicalName() + FACTORY_ATTRIBUTE + partition;
+      String partition = ((StatefulContainer) getContainer()).getPartitionName();
+      return getContainer().getObjectName().getCanonicalName() + FACTORY_ATTRIBUTE + partition;
    }
    
    public synchronized void replicantsChanged (String key, 

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusteredProxy.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusteredProxy.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusteredProxy.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -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.framework.interfaces.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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -656,6 +656,11 @@
       else
          return factory.createProxy();
    }
+   
+   public boolean isClustered()
+   {
+      return hasAnnotation(getBeanClass(), org.jboss.annotation.ejb.Clustered.class.getName());
+   }
 
    protected InvocationResponse invokeHomeMethod(MethodInfo info,
                                                  StatefulRemoteInvocation statefulInvocation) throws Throwable

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHandleImpl.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHandleImpl.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHandleImpl.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -33,6 +33,7 @@
 import javax.ejb.Handle;
 import javax.naming.InitialContext;
 
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.invocation.Invoker;
 import org.jboss.logging.Logger;
 import org.jboss.naming.NamingContextFactory;
@@ -164,11 +165,7 @@
    {
       try
       {
-         InitialContext ic = null;
-         if( jndiEnv != null )
-            ic = new InitialContext(jndiEnv);
-         else
-            ic = new InitialContext();
+         InitialContext ic = InitialContextFactory.getInitialContext(jndiEnv);
     
          Proxy proxy = (Proxy) ic.lookup(jndiName);
 

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHomeRemoteProxy.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHomeRemoteProxy.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulHomeRemoteProxy.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -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,7 +106,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);
+      
       return sri.invokeNext();
    }
 

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalHomeProxy.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -47,7 +47,7 @@
    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable
    {
-      StatefulContainer sfsb = (StatefulContainer) container;
+      StatefulContainer sfsb = (StatefulContainer) getContainer();
       return sfsb.localHomeInvoke(method, args);
    }
 
@@ -58,7 +58,7 @@
 
    public String toString()
    {
-      return container.getObjectName().getCanonicalName() + ": Home Proxy";
+      return proxyName + ": Home Proxy";
    }
 
 }

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

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

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxy.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxy.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxy.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -33,8 +33,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;
 import org.jboss.util.id.GUID;
@@ -58,22 +60,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,7 +127,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)
       {
          sri.getMetaData().addMetaData(AsynchronousInterceptor.ASYNCH, AsynchronousInterceptor.INVOKE_ASYNCH, "YES", PayloadKey.AS_IS);
@@ -157,7 +160,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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -69,7 +69,7 @@
    {
       Class[] interfaces;
       
-      StatefulContainer statefulContainer = (StatefulContainer) container;
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
       
       boolean bindTogether = false;
@@ -77,7 +77,7 @@
       if (remoteHome != null && bindHomeAndBusinessTogether(statefulContainer))
          bindTogether = true;
       
-      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
+      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(getContainer());
       if (bindTogether)
          interfaces = new Class[remoteInterfaces.length + 3];
       else
@@ -99,7 +99,7 @@
 
    protected void initializeJndiName()
    {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
+      jndiName = ProxyFactoryHelper.getRemoteJndiName(getContainer(), binding);
    }
 
    public void init() throws Exception
@@ -119,35 +119,35 @@
       Object factoryProxy = createPojiProxy(targetId, interfaces, ProxyFactoryHelper.getClientBindUrl(binding));
       try
       {
-         Util.rebind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
+         Util.rebind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
       }
       catch (NamingException e)
       {
-         NamingException namingException = new NamingException("Could not bind stateful remote proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
+         NamingException namingException = new NamingException("Could not bind stateful remote proxy with ejb name " + getContainer().getEjbName() + " into JNDI under jndiName: " + getContainer().getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
          namingException.setRootCause(e);
          throw namingException;
       }
       Dispatcher.singleton.registerTarget(targetId, this);
 
-      StatefulContainer statefulContainer = (StatefulContainer) container;
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
       if (remoteHome != null && !bindHomeAndBusinessTogether(statefulContainer))
       {
          Object homeProxy = createHomeProxy(remoteHome.value());
-         Util.rebind(container.getInitialContext(), ProxyFactoryHelper.getHomeJndiName(container), homeProxy);
+         Util.rebind(getContainer().getInitialContext(), ProxyFactoryHelper.getHomeJndiName(getContainer()), homeProxy);
       }
    }
 
    public void stop() throws Exception
    {
-      Util.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
+      Util.unbind(getContainer().getInitialContext(), jndiName + PROXY_FACTORY_NAME);
       Dispatcher.singleton.unregisterTarget(getTargetId());
       
-      StatefulContainer statefulContainer = (StatefulContainer) container;
+      StatefulContainer statefulContainer = (StatefulContainer) getContainer();
       RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
       if (remoteHome != null && !bindHomeAndBusinessTogether(statefulContainer))
       {
-         Util.unbind(container.getInitialContext(), ProxyFactoryHelper.getHomeJndiName(container));
+         Util.unbind(getContainer().getInitialContext(), ProxyFactoryHelper.getHomeJndiName(getContainer()));
       }
       super.stop();
    }
@@ -157,7 +157,7 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          String stackName = "StatefulSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
@@ -165,12 +165,12 @@
          }
          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)
       {
@@ -181,7 +181,7 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          String stackName = "StatefulSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
@@ -189,7 +189,7 @@
          }
          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);
@@ -217,7 +217,7 @@
    protected StatefulHandleImpl getHandle()
    {
       StatefulHandleImpl handle = new StatefulHandleImpl();
-      RemoteBinding remoteBinding = (RemoteBinding) advisor.resolveAnnotation(RemoteBinding.class);
+      RemoteBinding remoteBinding = (RemoteBinding) ((Advisor)getContainer()).resolveAnnotation(RemoteBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
 
@@ -228,14 +228,14 @@
    {
       try
       {
-         Object containerId = container.getObjectName().getCanonicalName();
+         Object containerId = getContainer().getObjectName().getCanonicalName();
          String stackName = "StatefulSessionClientInterceptors";
          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
          {
             stackName = binding.interceptorStack();
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
-         StatefulRemoteProxy proxy = new StatefulRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator, id);
+         StatefulRemoteProxy proxy = new StatefulRemoteProxy(getContainer(), stack.createInterceptors((Advisor) getContainer(), null), locator, id);
          setEjb21Objects(proxy);
          Object[] args = {proxy};
          return proxyConstructor.newInstance(args);
@@ -260,7 +260,7 @@
    
    protected String getTargetId()
    {  
-      return container.getObjectName().getCanonicalName() + FACTORY_ATTRIBUTE;
+      return getContainer().getObjectName().getCanonicalName() + FACTORY_ATTRIBUTE;
    }
    
    protected Object createPojiProxy(Object oid, Class[] interfaces, String uri) throws Exception

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -50,15 +50,6 @@
 {
    private static final Logger log = Logger.getLogger(BaseStatelessProxyFactory.class);
 
-//   protected Class proxyClass;
-//   protected Constructor proxyConstructor;
-   protected Context proxyFactoryContext;
-   protected String jndiName;
-   
-   private javassist.util.proxy.ProxyFactory proxyFactory;
-   private Class proxyClass;
-   private Constructor proxyConstructor;
-   
    /**
     * Adapt the JDK to cglib.
     * 
@@ -172,7 +163,7 @@
       Class[] interfaces = getInterfaces();
       
       /* plain jdk */
-      Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
+      Class proxyClass = java.lang.reflect.Proxy.getProxyClass(getContainer().getBeanClass().getClassLoader(), interfaces);
       final Class[] constructorParams =
               {InvocationHandler.class};
       proxyConstructor = proxyClass.getConstructor(constructorParams);
@@ -227,31 +218,24 @@
 
    public void stop() throws Exception
    {
-      Util.unbind(container.getInitialContext(), jndiName);
+      Util.unbind(getContainer().getInitialContext(), jndiName);
    }
 
-   protected abstract Class[] getInterfaces();
-
    protected abstract void initializeJndiName();
 
    protected void bindProxy(Object proxy) throws NamingException
    {
       try
       {
-         log.debug("Binding proxy for " + container.getEjbName() + " in JNDI at " + jndiName);
-         Util.rebind(container.getInitialContext(), jndiName, proxy);
+         log.debug("Binding proxy for " + getContainer().getEjbName() + " in JNDI at " + jndiName);
+         Util.rebind(getContainer().getInitialContext(), jndiName, proxy);
       } catch (NamingException e)
       {
-         NamingException namingException = new NamingException("Could not bind stateless proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName);
+         NamingException namingException = new NamingException("Could not bind stateless proxy with ejb name " + getContainer().getEjbName() + " into JNDI under jndiName: " + getContainer().getInitialContext().getNameInNamespace() + "/" + jndiName);
          namingException.setRootCause(e);
          throw namingException;
       }
    }
    
-   public void setContainer(Container container)
-   {
-      this.container = container;
-      this.advisor = (Advisor) container;
-   }
 
 }

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

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusteredProxy.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusteredProxy.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusteredProxy.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -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.framework.interfaces.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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -93,7 +93,7 @@
       {
          super.start();
          
-         timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
+         timerService = TimerServiceFactory.getInstance().createTimerService(this, this);
          
          TimerServiceFactory.getInstance().restoreTimerService(timerService);
       }

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessHandleImpl.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessHandleImpl.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessHandleImpl.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -36,6 +36,7 @@
 import javax.ejb.EJBObject;
 import javax.ejb.EJBHome;
 
+import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.naming.NamingContextFactory;
 
 /**
@@ -89,11 +90,7 @@
    {
       try
       {
-         InitialContext ic = null;
-         if( jndiEnv != null )
-            ic = new InitialContext(jndiEnv);
-         else
-            ic = new InitialContext();
+         InitialContext ic = InitialContextFactory.getInitialContext(jndiEnv);
     
          Proxy proxy = (Proxy) ic.lookup(jndiName);
 

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

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

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

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -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: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -53,7 +53,7 @@
    //private String jobGroup;
    private String triggerName;
    private String triggerGroup;
-   private ObjectName objectName;
+   private String containerGuid;
    
    private Serializable info;
    
@@ -64,14 +64,14 @@
       
       this.triggerName = trigger.getName();
       this.triggerGroup = trigger.getGroup();
-      this.objectName = objectName;
+      this.containerGuid = containerGuid;
       this.info = info;
    }
    
    protected TimedObjectInvoker getTimedObjectInvoker()
    {
-      // TODO: a hack to get back the container. This needs thinking.
-      TimedObjectInvoker invoker = (TimedObjectInvoker) Ejb3Registry.getContainer(objectName.getCanonicalName());
+//    TODO: a hack to get back the container. This needs thinking.
+      TimedObjectInvoker invoker = (TimedObjectInvoker) Ejb3Registry.getContainer(containerGuid);
       assert invoker != null;
       return invoker;
    }

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -37,6 +37,8 @@
 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;
 import org.jboss.logging.Logger;
@@ -152,12 +154,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
@@ -243,7 +245,7 @@
       
       log.debug("properties = " + properties);
       
-      InitialContext ctx = new InitialContext();
+      InitialContext ctx = InitialContextFactory.getInitialContext();
       tm = (TransactionManager) ctx.lookup(TransactionManagerService.JNDI_NAME);
       
       createSchema();

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java	2007-08-14 22:02:50 UTC (rev 64590)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java	2007-08-15 00:33:04 UTC (rev 64591)
@@ -30,6 +30,7 @@
 import javax.ejb.TimerService;
 import javax.management.ObjectName;
 
+import org.jboss.ejb3.Container;
 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
 import org.jboss.logging.Logger;
 import org.quartz.JobDetail;
@@ -51,18 +52,20 @@
    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();
    }
    




More information about the jboss-cvs-commits mailing list