[jboss-cvs] JBossAS SVN: r86380 - in projects/ejb3/trunk/remoting2: src/main/java/org/jboss/ejb3/remoting and 12 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 26 08:50:09 EDT 2009


Author: wolfc
Date: 2009-03-26 08:50:09 -0400 (Thu, 26 Mar 2009)
New Revision: 86380

Added:
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/client/
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/client/CurrentRemotableClient.java
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/client/RemotableClient.java
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpointReference.java
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteContextDataInterceptor.java
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/reflect/
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/reflect/AbstractInvocationHandler.java
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/remoteref/
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/remoteref/unit/
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/remoteref/unit/RemoteReferenceTestCase.java
Removed:
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/RemoteContextDataInterceptor.java
Modified:
   projects/ejb3/trunk/remoting2/pom.xml
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpoint.java
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteInvocationHandlerInvocationHandler.java
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/client/RemoteInvocationHandler.java
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/unit/ClientInterceptorTestCase.java
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/AbstractRemotingTestCaseSetup.java
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockInterface.java
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockRemotable.java
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelControllerImpl.java
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/SimpleRemotingTestCase.java
Log:
EJBTHREE-1779: added remotable endpoint reference which is transport unaware

Modified: projects/ejb3/trunk/remoting2/pom.xml
===================================================================
--- projects/ejb3/trunk/remoting2/pom.xml	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/pom.xml	2009-03-26 12:50:09 UTC (rev 86380)
@@ -61,7 +61,6 @@
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-sis</artifactId>
       <version>0.1.0-SNAPSHOT</version>
-      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.logging</groupId>

Added: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/client/CurrentRemotableClient.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/client/CurrentRemotableClient.java	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/client/CurrentRemotableClient.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting.client;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class CurrentRemotableClient
+{
+   private static ThreadLocal<RemotableClient> current = new ThreadLocal<RemotableClient>();
+   
+   public static InvocationHandler createHandler(Serializable oid)
+   {
+      return current.get().createHandler(oid);
+   }
+   
+   public static void remove()
+   {
+      RemotableClient previous = current.get();
+      if(previous == null)
+         throw new IllegalStateException("no remotable client found");
+      current.remove();
+   }
+   
+   public static void set(RemotableClient value)
+   {
+      RemotableClient previous = current.get();
+      if(previous != null)
+         throw new IllegalStateException("found previous remotable client " + previous + ", can't set " + value);
+      current.set(value);
+   }
+}

Added: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/client/RemotableClient.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/client/RemotableClient.java	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/client/RemotableClient.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting.client;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface RemotableClient
+{
+   InvocationHandler createHandler(Serializable oid);
+}

Modified: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpoint.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpoint.java	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpoint.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -26,6 +26,7 @@
 import java.util.Map;
 
 import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.remoting.spi.Remotable;
 
 /**
  * An endpoint that only takes serializable parameters. This is one level higher that a Remotable,
@@ -39,6 +40,11 @@
    Method INVOKE_METHOD = MethodHelper.getMethod(RemotableEndpoint.class, "invoke", Serializable.class, Map.class, SerializableMethod.class, Object[].class);
    
    /**
+    * The remotable which has this endpoint as target.
+    */
+   Remotable getRemotable();
+   
+   /**
     * The invokedBusinessInterface is method.actualClass
     * 
     * @param session

Added: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpointReference.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpointReference.java	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpointReference.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting.endpoint;
+
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.remoting.client.CurrentRemotableClient;
+import org.jboss.ejb3.remoting.endpoint.client.RemoteContextDataInterceptor;
+import org.jboss.ejb3.remoting.endpoint.client.RemoteInvocationHandlerInvocationHandler;
+import org.jboss.ejb3.remoting.reflect.AbstractInvocationHandler;
+import org.jboss.ejb3.sis.reflect.InterceptorInvocationHandler;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RemotableEndpointReference extends AbstractInvocationHandler
+   implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+   
+   private Serializable session;
+   private Class<?> businessInterface;
+   private Serializable oid;
+   private transient RemotableEndpoint endpoint;
+   
+   /**
+    * For serialization only.
+    */
+   public RemotableEndpointReference()
+   {
+      
+   }
+   
+   /**
+    * @param session
+    * @param mockRemotable
+    */
+   public RemotableEndpointReference(RemotableEndpoint remotableEndpoint, Serializable session, Class<?> businessInterface)
+   {
+      this.endpoint = remotableEndpoint;
+      this.session = session;
+      this.businessInterface = businessInterface;
+      this.oid = remotableEndpoint.getRemotable().getId();
+   }
+
+   protected Object innerInvoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      assert endpoint != null : "reference has crossed the wire and still exists without an endpoint";
+      
+      // this is a brand new invocation happening locally, so there is no 'remote' context data
+      Map<String, Object> contextData = new HashMap<String, Object>();
+      SerializableMethod businessMethod = new SerializableMethod(method, businessInterface);
+      return endpoint.invoke(session, contextData, businessMethod, args);
+   }
+
+   protected Object readResolve() throws ObjectStreamException
+   {
+      InvocationHandler handler = CurrentRemotableClient.createHandler(oid);
+         
+      handler = new RemoteInvocationHandlerInvocationHandler(handler, session, businessInterface);
+      
+      handler = new InterceptorInvocationHandler(handler, new RemoteContextDataInterceptor());
+      
+      return handler;
+   }
+   
+   @Override
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(super.toString());
+      sb.append("{endpoint=" + endpoint);
+      sb.append(",oid=" + oid);
+      sb.append(",session=" + session);
+      sb.append(",businessInterface=" + businessInterface);
+      sb.append("}");
+      return sb.toString();
+   }
+   
+   @Override
+   protected String toProxyString()
+   {
+      return "Proxy on " + toString();
+   }
+}

Copied: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteContextDataInterceptor.java (from rev 86203, projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/RemoteContextDataInterceptor.java)
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteContextDataInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteContextDataInterceptor.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting.endpoint.client;
+
+import javax.interceptor.InvocationContext;
+
+import org.jboss.ejb3.sis.Interceptor;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RemoteContextDataInterceptor implements Interceptor
+{
+   public Object invoke(InvocationContext context) throws Exception
+   {
+      RemoteContextData.setContextData(context.getContextData());
+      try
+      {
+         return context.proceed();
+      }
+      finally
+      {
+         RemoteContextData.cleanContextData();
+      }
+   }
+}


Property changes on: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteContextDataInterceptor.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteInvocationHandlerInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteInvocationHandlerInvocationHandler.java	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteInvocationHandlerInvocationHandler.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -28,6 +28,7 @@
 
 import org.jboss.ejb3.common.lang.SerializableMethod;
 import org.jboss.ejb3.remoting.endpoint.RemotableEndpoint;
+import org.jboss.ejb3.remoting.reflect.AbstractInvocationHandler;
 
 /**
  * An invocation handler which delegates to an invocation handler that handles invocations
@@ -39,7 +40,7 @@
  * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
-public class RemoteInvocationHandlerInvocationHandler implements InvocationHandler
+public class RemoteInvocationHandlerInvocationHandler extends AbstractInvocationHandler
 {
    private InvocationHandler delegate;
    private Serializable session;
@@ -52,12 +53,37 @@
       this.invokedBusinessInterface = invokedBusinessInterface;
    }
    
-   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   public Object innerInvoke(Object proxy, Method method, Object[] args) throws Throwable
    {
       Map<String, Object> contextData = RemoteContextData.getContextData();
-      Method invokeMethod = RemotableEndpoint.INVOKE_METHOD;
-      SerializableMethod businessMethod = new SerializableMethod(method, invokedBusinessInterface);
-      Object invokeArgs[] = { session, contextData, businessMethod, args };
-      return delegate.invoke(proxy, invokeMethod, invokeArgs);
+      try
+      {
+         // make sure we don't leak across recursive calls
+         RemoteContextData.cleanContextData();
+         Method invokeMethod = RemotableEndpoint.INVOKE_METHOD;
+         SerializableMethod businessMethod = new SerializableMethod(method, invokedBusinessInterface);
+         Object invokeArgs[] = { session, contextData, businessMethod, args };
+         return delegate.invoke(proxy, invokeMethod, invokeArgs);
+      }
+      finally
+      {
+         RemoteContextData.setContextData(contextData);
+      }
    }
+   
+   public String toProxyString()
+   {
+      return "Proxy on " + toString();
+   }
+   
+   @Override
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(super.toString());
+      sb.append("{delegate=" + delegate);
+      sb.append(",session=" + session);
+      sb.append(",invokedBusinessInterface=" + invokedBusinessInterface);
+      sb.append("}");
+      return sb.toString();
+   }
 }

Added: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/reflect/AbstractInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/reflect/AbstractInvocationHandler.java	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/reflect/AbstractInvocationHandler.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting.reflect;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractInvocationHandler implements InvocationHandler
+{
+   // subclasses might be serializable
+   private static final long serialVersionUID = 1L;
+   
+   private static final Method METHOD_EQUALS;
+   private static final Method METHOD_HASH_CODE;
+   private static final Method METHOD_TO_STRING;
+   
+   static
+   {
+      try
+      {
+         METHOD_EQUALS = Object.class.getDeclaredMethod("equals", Object.class);
+         METHOD_HASH_CODE = Object.class.getDeclaredMethod("hashCode");
+         METHOD_TO_STRING = Object.class.getDeclaredMethod("toString");
+      }
+      catch (SecurityException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (NoSuchMethodException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   protected abstract Object innerInvoke(Object proxy, Method method, Object[] args) throws Throwable;
+   
+   public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      if(method.equals(METHOD_EQUALS))
+         return equals(args[0]);
+      if(method.equals(METHOD_HASH_CODE))
+         return hashCode();
+      if(method.equals(METHOD_TO_STRING))
+         return toProxyString();
+      return innerInvoke(proxy, method, args);
+   }
+   
+   protected abstract String toProxyString();
+}

Modified: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/client/RemoteInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/client/RemoteInvocationHandler.java	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/client/RemoteInvocationHandler.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -28,13 +28,17 @@
 import java.util.Map;
 
 import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.remoting.client.CurrentRemotableClient;
+import org.jboss.ejb3.remoting.client.RemotableClient;
+import org.jboss.ejb3.remoting.reflect.AbstractInvocationHandler;
 import org.jboss.remoting.Client;
 
 /**
  * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
-public class RemoteInvocationHandler implements InvocationHandler
+public class RemoteInvocationHandler extends AbstractInvocationHandler
+   implements RemotableClient
 {
    public static final String OID = "OID";
    
@@ -47,12 +51,53 @@
       this.oid = oid;
    }
    
-   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   public InvocationHandler createHandler(Serializable oid)
    {
+      if(equals(this.oid, oid))
+         return this;
+      return new RemoteInvocationHandler(client, oid);
+   }
+   
+   private static boolean equals(Object obj1, Object obj2)
+   {
+      if(obj1 == obj2)
+         return true;
+      
+      if(obj1 == null || obj2 == null)
+         return false;
+      
+      return obj1.equals(obj2);
+   }
+   
+   public Object innerInvoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
       SerializableMethod serializableMethod = new SerializableMethod(method);
       Object param = new Object[] { serializableMethod, args };
       Map<Object, Object> metadata = new HashMap<Object, Object>();
       metadata.put(OID, oid);
-      return client.invoke(param, metadata);
+      CurrentRemotableClient.set(this);
+      try
+      {
+         return client.invoke(param, metadata);
+      }
+      finally
+      {
+         CurrentRemotableClient.remove();
+      }
    }
+   
+   public String toProxyString()
+   {
+      return "Proxy on " + toString();
+   }
+   
+   @Override
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(super.toString());
+      sb.append("{client=" + client);
+      sb.append(",oid=" + oid);
+      sb.append("}");
+      return sb.toString();
+   }
 }

Deleted: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/RemoteContextDataInterceptor.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/RemoteContextDataInterceptor.java	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/RemoteContextDataInterceptor.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.remoting2.test.clientinterceptor;
-
-import javax.interceptor.InvocationContext;
-
-import org.jboss.ejb3.remoting.endpoint.client.RemoteContextData;
-import org.jboss.ejb3.sis.Interceptor;
-
-/**
- * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public class RemoteContextDataInterceptor implements Interceptor
-{
-   public Object invoke(InvocationContext context) throws Exception
-   {
-      RemoteContextData.setContextData(context.getContextData());
-      try
-      {
-         return context.proceed();
-      }
-      finally
-      {
-         RemoteContextData.cleanContextData();
-      }
-   }
-}

Modified: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/unit/ClientInterceptorTestCase.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/unit/ClientInterceptorTestCase.java	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/unit/ClientInterceptorTestCase.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -27,11 +27,11 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
 
+import org.jboss.ejb3.remoting.endpoint.client.RemoteContextDataInterceptor;
 import org.jboss.ejb3.remoting.endpoint.client.RemoteInvocationHandlerInvocationHandler;
 import org.jboss.ejb3.remoting2.client.RemoteInvocationHandler;
 import org.jboss.ejb3.remoting2.test.clientinterceptor.Current;
 import org.jboss.ejb3.remoting2.test.clientinterceptor.InterceptedMockRemotable;
-import org.jboss.ejb3.remoting2.test.clientinterceptor.RemoteContextDataInterceptor;
 import org.jboss.ejb3.remoting2.test.clientinterceptor.SimpleInterceptorClientSide;
 import org.jboss.ejb3.remoting2.test.common.AbstractRemotingTestCaseSetup;
 import org.jboss.ejb3.remoting2.test.common.MockInterface;

Modified: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/AbstractRemotingTestCaseSetup.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/AbstractRemotingTestCaseSetup.java	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/AbstractRemotingTestCaseSetup.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -33,10 +33,10 @@
 import java.util.concurrent.TimeUnit;
 
 import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.ejb3.remoting.endpoint.client.RemoteContextDataInterceptor;
 import org.jboss.ejb3.remoting.endpoint.client.RemoteInvocationHandlerInvocationHandler;
 import org.jboss.ejb3.remoting2.client.RemoteInvocationHandler;
 import org.jboss.ejb3.remoting2.test.clientinterceptor.InterceptedMockRemotable;
-import org.jboss.ejb3.remoting2.test.clientinterceptor.RemoteContextDataInterceptor;
 import org.jboss.ejb3.sis.reflect.InterceptorInvocationHandler;
 import org.jboss.logging.Logger;
 import org.jboss.remoting.Client;

Modified: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockInterface.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockInterface.java	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockInterface.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -27,5 +27,7 @@
  */
 public interface MockInterface
 {
+   MockInterface getBusinessObject();
+   
    String sayHi(String name);
 }

Modified: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockRemotable.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockRemotable.java	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockRemotable.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -21,13 +21,19 @@
  */
 package org.jboss.ejb3.remoting2.test.common;
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
 import java.util.Map;
 
 import org.jboss.ejb3.common.lang.SerializableMethod;
 import org.jboss.ejb3.remoting.endpoint.RemotableEndpoint;
+import org.jboss.ejb3.remoting.endpoint.RemotableEndpointReference;
 import org.jboss.ejb3.remoting.spi.Remotable;
 
 /**
@@ -36,6 +42,21 @@
  */
 public class MockRemotable implements MockInterface, Remotable, RemotableEndpoint
 {
+   public MockInterface getBusinessObject()
+   {
+      Class<?> businessInterface = MockInterface.class;
+      ClassLoader loader = getClassLoader();
+      Class<?> interfaces[] = { businessInterface };
+      Serializable session = null;
+      InvocationHandler handler = new RemotableEndpointReference(this, session, businessInterface);
+      MockInterface self = (MockInterface) Proxy.newProxyInstance(loader, interfaces, handler);
+      
+      String result = self.sayHi("self");
+      assertEquals("Hi self", result);
+      
+      return self;
+   }
+   
    public ClassLoader getClassLoader()
    {
       return MockRemotable.class.getClassLoader();
@@ -46,6 +67,11 @@
       return "MockRemotableID";
    }
    
+   public Remotable getRemotable()
+   {
+      return this;
+   }
+   
    public Object getTarget()
    {
       return this;
@@ -64,6 +90,10 @@
       {
          return realMethod.invoke(this, args);
       }
+      catch(IllegalArgumentException e)
+      {
+         throw new IllegalArgumentException("failed to invoke " + realMethod + " with " + Arrays.toString(args));
+      }
       catch(InvocationTargetException e)
       {
          throw e.getCause();

Modified: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelControllerImpl.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelControllerImpl.java	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelControllerImpl.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -79,12 +79,6 @@
       }
    }
    
-   public String install(BeanMetaData beanMetaData) throws Throwable
-   {
-      KernelControllerContext context = kernel.getController().install(beanMetaData);
-      return (String) context.getName();
-   }
-
    /* (non-Javadoc)
     * @see org.jboss.ejb3.remoting.spi.Remotable#getClassLoader()
     */
@@ -101,6 +95,11 @@
       return RemoteKernelController.class.getName();
    }
 
+   public Remotable getRemotable()
+   {
+      return this;
+   }
+   
    /* (non-Javadoc)
     * @see org.jboss.ejb3.remoting.spi.Remotable#getTarget()
     */
@@ -109,6 +108,12 @@
       return this;
    }
 
+   public String install(BeanMetaData beanMetaData) throws Throwable
+   {
+      KernelControllerContext context = kernel.getController().install(beanMetaData);
+      return (String) context.getName();
+   }
+
    /* (non-Javadoc)
     * @see org.jboss.ejb3.remoting.endpoint.RemotableEndpoint#invoke(java.io.Serializable, java.util.Map, org.jboss.ejb3.common.lang.SerializableMethod, java.lang.Object[])
     */

Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/remoteref/unit/RemoteReferenceTestCase.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/remoteref/unit/RemoteReferenceTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/remoteref/unit/RemoteReferenceTestCase.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.remoteref.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+
+import org.jboss.ejb3.remoting.endpoint.client.RemoteContextDataInterceptor;
+import org.jboss.ejb3.remoting.endpoint.client.RemoteInvocationHandlerInvocationHandler;
+import org.jboss.ejb3.remoting2.client.RemoteInvocationHandler;
+import org.jboss.ejb3.remoting2.test.common.AbstractRemotingTestCaseSetup;
+import org.jboss.ejb3.remoting2.test.common.MockInterface;
+import org.jboss.ejb3.sis.reflect.InterceptorInvocationHandler;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.junit.Test;
+
+/**
+ * What happens if we obtain a reference from inside the remotable.
+ * 
+ * e.g. simulate ctx.getBusinessObject(interface);
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RemoteReferenceTestCase extends AbstractRemotingTestCaseSetup
+{
+   @Test
+   public void testRemoteReference() throws Exception
+   {
+      InvokerLocator locator = new InvokerLocator("socket://localhost:5783");
+      String subsystem = "EJB3_R2D2";
+      
+      Client client = new Client(locator, subsystem);
+      client.setDisconnectTimeout(1);
+      client.connect();
+      
+      RemoteInvocationHandler delegate = new RemoteInvocationHandler(client, "MockRemotableID");
+      
+      Serializable session = null;
+      Class<?> businessInterface = MockInterface.class;
+      InvocationHandler handler = new RemoteInvocationHandlerInvocationHandler(delegate, session, businessInterface);
+      
+      handler = new InterceptorInvocationHandler(handler, new RemoteContextDataInterceptor());
+      
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      Class<?> interfaces[] = { businessInterface };
+      MockInterface proxy = (MockInterface) Proxy.newProxyInstance(loader, interfaces, handler);
+      
+      MockInterface newProxy = proxy.getBusinessObject();
+      
+      String result = newProxy.sayHi("testRemoteReference");
+      assertEquals("Hi testRemoteReference", result);
+   }
+}

Modified: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/SimpleRemotingTestCase.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/SimpleRemotingTestCase.java	2009-03-26 12:31:59 UTC (rev 86379)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/SimpleRemotingTestCase.java	2009-03-26 12:50:09 UTC (rev 86380)
@@ -32,10 +32,10 @@
 
 import org.jboss.ejb3.common.lang.SerializableMethod;
 import org.jboss.ejb3.remoting.endpoint.RemotableEndpoint;
+import org.jboss.ejb3.remoting.endpoint.client.RemoteContextDataInterceptor;
 import org.jboss.ejb3.remoting.endpoint.client.RemoteInvocationHandlerInvocationHandler;
 import org.jboss.ejb3.remoting2.EJB3ServerInvocationHandler;
 import org.jboss.ejb3.remoting2.client.RemoteInvocationHandler;
-import org.jboss.ejb3.remoting2.test.clientinterceptor.RemoteContextDataInterceptor;
 import org.jboss.ejb3.remoting2.test.common.AbstractRemotingTestCaseSetup;
 import org.jboss.ejb3.remoting2.test.common.MockInterface;
 import org.jboss.ejb3.sis.reflect.InterceptorInvocationHandler;




More information about the jboss-cvs-commits mailing list