[jboss-cvs] JBossAS SVN: r86113 - in projects/ejb3/trunk: remoting2 and 25 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 19 14:08:21 EDT 2009


Author: wolfc
Date: 2009-03-19 14:08:21 -0400 (Thu, 19 Mar 2009)
New Revision: 86113

Added:
   projects/ejb3/trunk/remoting2/
   projects/ejb3/trunk/remoting2/.classpath
   projects/ejb3/trunk/remoting2/.project
   projects/ejb3/trunk/remoting2/.settings/
   projects/ejb3/trunk/remoting2/.settings/org.eclipse.jdt.core.prefs
   projects/ejb3/trunk/remoting2/.settings/org.maven.ide.eclipse.prefs
   projects/ejb3/trunk/remoting2/pom.xml
   projects/ejb3/trunk/remoting2/src/
   projects/ejb3/trunk/remoting2/src/main/
   projects/ejb3/trunk/remoting2/src/main/java/
   projects/ejb3/trunk/remoting2/src/main/java/org/
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/
   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/
   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/spi/
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/spi/Remotable.java
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/EJB3ServerInvocationHandler.java
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/client/
   projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/client/RemoteInvocationHandler.java
   projects/ejb3/trunk/remoting2/src/test/
   projects/ejb3/trunk/remoting2/src/test/java/
   projects/ejb3/trunk/remoting2/src/test/java/org/
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/
   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/simple/
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/
   projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/SimpleRemotingTestCase.java
   projects/ejb3/trunk/remoting2/src/test/resources/
   projects/ejb3/trunk/remoting2/src/test/resources/META-INF/
   projects/ejb3/trunk/remoting2/src/test/resources/META-INF/jboss-beans.xml
   projects/ejb3/trunk/remoting2/src/test/resources/log4j.xml
Log:
EJBTHREE-1779: initial setup of a remoting2 component and a remoting spi


Property changes on: projects/ejb3/trunk/remoting2
___________________________________________________________________
Name: svn:ignore
   + eclipse-target
target


Added: projects/ejb3/trunk/remoting2/.classpath
===================================================================
--- projects/ejb3/trunk/remoting2/.classpath	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/.classpath	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,8 @@
+<classpath>
+  <classpathentry kind="src" path="src/main/java"/>
+  <classpathentry kind="src" path="src/test/java" output="eclipse-target/tests-classes"/>
+  <classpathentry kind="src" path="src/test/resources" output="eclipse-target/tests-classes" excluding="**/*.java"/>
+  <classpathentry kind="output" path="eclipse-target/classes"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+  <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+</classpath>
\ No newline at end of file

Added: projects/ejb3/trunk/remoting2/.project
===================================================================
--- projects/ejb3/trunk/remoting2/.project	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/.project	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,18 @@
+<projectDescription>
+  <name>jboss-ejb3-remoting2</name>
+  <comment>The JBoss EJB 3 Remoting 2 component creates remote proxies
+    using JBoss Remoting 2.</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+    <buildCommand>
+      <name>org.maven.ide.eclipse.maven2Builder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+    <nature>org.maven.ide.eclipse.maven2Nature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Added: projects/ejb3/trunk/remoting2/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/ejb3/trunk/remoting2/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/.settings/org.eclipse.jdt.core.prefs	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,5 @@
+#Thu Mar 19 13:09:51 CET 2009
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5

Added: projects/ejb3/trunk/remoting2/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- projects/ejb3/trunk/remoting2/.settings/org.maven.ide.eclipse.prefs	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/.settings/org.maven.ide.eclipse.prefs	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,8 @@
+#Thu Mar 19 13:11:58 CET 2009
+activeProfiles=eclipse
+eclipse.preferences.version=1
+fullBuildGoals=
+includeModules=false
+resolveWorkspaceProjects=false
+resourceFilterGoals=
+version=1

Added: projects/ejb3/trunk/remoting2/pom.xml
===================================================================
--- projects/ejb3/trunk/remoting2/pom.xml	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/pom.xml	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,91 @@
+<!-- 
+  vi:ts=2:sw=2:expandtab 
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.jboss.ejb3</groupId>
+    <artifactId>jboss-ejb3-build</artifactId>
+    <version>1.0.1</version>
+    <relativePath>../build/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-ejb3-remoting2</artifactId>
+  <version>0.1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>JBoss EJB 3.0 Remoting2</name>
+  <url>http://www.jboss.org</url>
+  <description>
+    The JBoss EJB 3 Remoting 2 component creates remote proxies
+    using JBoss Remoting 2.
+  </description>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <!-- SUREFIRE-510: surefire.test.class.path is not set when forkMode is always -->
+        <version>2.4.3</version>
+        <configuration>
+          <forkMode>always</forkMode>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  
+  <dependencies>
+    <dependency>
+      <groupId>sun.jdk</groupId>
+      <artifactId>tools</artifactId>
+      <version>1.5.0</version>
+      <scope>system</scope>
+      <systemPath>${java.home}/../lib/tools.jar</systemPath>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-common</artifactId>
+      <version>1.0.1-SNAPSHOT</version>
+    </dependency>    
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-endpoint</artifactId>
+      <version>0.1.0-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-log4j</artifactId>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-kernel</artifactId>
+      <version>2.0.4.GA</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.remoting</groupId>
+      <artifactId>jboss-remoting</artifactId>
+      <version>2.5.0.SP2</version>
+    </dependency>
+    
+    <!-- for remoting 2 -->
+    <dependency>
+      <groupId>jboss</groupId>
+      <artifactId>jboss-serialization</artifactId>
+      <version>1.0.3.GA</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>oswego-concurrent</groupId>
+      <artifactId>concurrent</artifactId>
+      <version>1.3.4-jboss-update1</version>
+      <scope>runtime</scope>
+    </dependency>
+  </dependencies>
+</project>

Added: 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	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpoint.java	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,38 @@
+/*
+ * 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.Serializable;
+import java.util.Map;
+
+import org.jboss.ejb3.common.lang.SerializableMethod;
+
+/**
+ * An endpoint that only takes serializable parameters.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface RemotableEndpoint
+{
+   Object invoke(Serializable session, Map<?, ?> context, Class<?> invokedBusinessInterface, SerializableMethod method, Object args[]) throws Throwable;
+}

Added: 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	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteInvocationHandlerInvocationHandler.java	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,58 @@
+/*
+ * 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 java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.remoting.endpoint.RemotableEndpoint;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RemoteInvocationHandlerInvocationHandler implements InvocationHandler
+{
+   private InvocationHandler delegate;
+   private Serializable session;
+   private Class<?> invokedBusinessInterface;
+
+   public RemoteInvocationHandlerInvocationHandler(InvocationHandler delegate, Serializable session, Class<?> invokedBusinessInterface)
+   {
+      this.delegate = delegate;
+      this.session = session;
+      this.invokedBusinessInterface = invokedBusinessInterface;
+   }
+   
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      // FIXME: associate the necessary thread locals to the invocation
+      Map<?, ?> context = null;
+      Method invokeMethod = RemotableEndpoint.class.getDeclaredMethod("invoke", Serializable.class, Map.class, Class.class, SerializableMethod.class, Object[].class);
+      SerializableMethod businessMethod = new SerializableMethod(method);
+      Object invokeArgs[] = { session, context, invokedBusinessInterface, businessMethod, args };
+      return delegate.invoke(proxy, invokeMethod, invokeArgs);
+   }
+}

Added: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/spi/Remotable.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/spi/Remotable.java	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/spi/Remotable.java	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,37 @@
+/*
+ * 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.spi;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface Remotable
+{
+   ClassLoader getClassLoader();
+   
+   Serializable getId();
+   
+   Object getTarget();
+}

Added: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/EJB3ServerInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/EJB3ServerInvocationHandler.java	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/EJB3ServerInvocationHandler.java	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,134 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.management.MBeanServer;
+
+import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.remoting.spi.Remotable;
+import org.jboss.ejb3.remoting2.client.RemoteInvocationHandler;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class EJB3ServerInvocationHandler implements ServerInvocationHandler
+{
+   private static final Logger log = Logger.getLogger(EJB3ServerInvocationHandler.class);
+
+   public static final Object OID = RemoteInvocationHandler.OID;
+   
+   private Map<Object, Remotable> remotables = new ConcurrentHashMap<Object, Remotable>();
+   
+   private ServerInvoker invoker;
+   private MBeanServer mbeanServer;
+   
+   /* (non-Javadoc)
+    * @see org.jboss.remoting.ServerInvocationHandler#addListener(org.jboss.remoting.callback.InvokerCallbackHandler)
+    */
+   public void addListener(InvokerCallbackHandler callbackHandler)
+   {
+      // TODO Auto-generated method stub
+      //
+      throw new RuntimeException("NYI");
+   }
+
+   public void addRemotable(Remotable remotable)
+   {
+      log.debug("addRemotable " + remotable);
+      Remotable previous = remotables.put(remotable.getId(), remotable);
+      assert previous == null : "there was a previous remotable under " + remotable.getId();
+   }
+   
+   /* (non-Javadoc)
+    * @see org.jboss.remoting.ServerInvocationHandler#invoke(org.jboss.remoting.InvocationRequest)
+    */
+   public Object invoke(InvocationRequest invocation) throws Throwable
+   {
+      Serializable key = (Serializable) invocation.getRequestPayload().get(OID);
+      Remotable remotable = remotables.get(key);
+      
+      Object parameters[] = (Object[]) invocation.getParameter();
+      SerializableMethod method = (SerializableMethod) parameters[0];
+      Object args[] = (Object[]) parameters[1];
+      ClassLoader loader = remotable.getClassLoader();
+      Method realMethod = method.toMethod(loader);
+      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+      try
+      {
+         Thread.currentThread().setContextClassLoader(loader);
+         return realMethod.invoke(remotable.getTarget(), args);
+      }
+      catch(InvocationTargetException e)
+      {
+         throw e.getCause();
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(oldLoader);
+      }
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.remoting.ServerInvocationHandler#removeListener(org.jboss.remoting.callback.InvokerCallbackHandler)
+    */
+   public void removeListener(InvokerCallbackHandler callbackHandler)
+   {
+      // TODO Auto-generated method stub
+      //
+      throw new RuntimeException("NYI");
+   }
+
+   public void removeRemotable(Remotable remotable)
+   {
+      log.debug("removeRemotable " + remotable);
+      Remotable previous = remotables.remove(remotable.getId());
+      assert previous == remotable : "there was a different remotable under " + remotable.getId() + " (" + previous + " != " + remotable + ")";
+   }
+   
+   /* (non-Javadoc)
+    * @see org.jboss.remoting.ServerInvocationHandler#setInvoker(org.jboss.remoting.ServerInvoker)
+    */
+   public void setInvoker(ServerInvoker invoker)
+   {
+      this.invoker = invoker;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.remoting.ServerInvocationHandler#setMBeanServer(javax.management.MBeanServer)
+    */
+   public void setMBeanServer(MBeanServer server)
+   {
+      this.mbeanServer = server;
+   }
+}

Added: 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	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/client/RemoteInvocationHandler.java	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,58 @@
+/*
+ * 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.client;
+
+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.remoting.Client;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RemoteInvocationHandler implements InvocationHandler
+{
+   public static final String OID = "OID";
+   
+   private Client client;
+   private Serializable oid;
+   
+   public RemoteInvocationHandler(Client client, Serializable oid)
+   {
+      this.client = client;
+      this.oid = oid;
+   }
+   
+   public Object invoke(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);
+   }
+}

Added: 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	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockInterface.java	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,31 @@
+/*
+ * 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.common;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface MockInterface
+{
+   String sayHi(String name);
+}

Added: 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	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockRemotable.java	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,75 @@
+/*
+ * 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.common;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.remoting.endpoint.RemotableEndpoint;
+import org.jboss.ejb3.remoting.spi.Remotable;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockRemotable implements MockInterface, Remotable, RemotableEndpoint
+{
+   public ClassLoader getClassLoader()
+   {
+      return MockRemotable.class.getClassLoader();
+   }
+   
+   public Serializable getId()
+   {
+      return "MockRemotableID";
+   }
+   
+   public Object getTarget()
+   {
+      return this;
+   }
+   
+   public String sayHi(String name)
+   {
+      return "Hi " + name;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.endpoint.Endpoint#invoke(java.io.Serializable, java.lang.Class, java.lang.reflect.Method, java.lang.Object[])
+    */
+   public Object invoke(Serializable session, Map<?, ?> context, Class<?> invokedBusinessInterface, SerializableMethod method, Object[] args)
+      throws Throwable
+   {
+      Method realMethod = method.toMethod(getClassLoader());
+      try
+      {
+         return realMethod.invoke(this, args);
+      }
+      catch(InvocationTargetException e)
+      {
+         throw e.getCause();
+      }
+   }
+}

Added: 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	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/SimpleRemotingTestCase.java	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,261 @@
+/*
+ * 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.simple.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.net.ConnectException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.remoting.endpoint.RemotableEndpoint;
+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.common.MockInterface;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.sun.jdi.Bootstrap;
+import com.sun.jdi.VirtualMachine;
+import com.sun.jdi.VirtualMachineManager;
+import com.sun.jdi.connect.LaunchingConnector;
+import com.sun.jdi.connect.Connector.Argument;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleRemotingTestCase
+{
+   private static final Logger log = Logger.getLogger(SimpleRemotingTestCase.class);
+   
+   private static VirtualMachine vm;
+   
+   @AfterClass
+   public static void afterClass()
+   {
+      vm.exit(0);
+   }
+   
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      VirtualMachineManager manager = Bootstrap.virtualMachineManager();
+      LaunchingConnector connector = manager.defaultConnector();
+      Map<String, ? extends Argument> args = connector.defaultArguments();
+      for(Argument arg : args.values())
+      {
+         System.out.println("  " + arg);
+      }
+      args.get("options").setValue("-classpath " + getClassPath());
+      args.get("main").setValue("org.jboss.kernel.plugins.bootstrap.standalone.StandaloneBootstrap");
+      System.out.println(args);
+      vm = connector.launch(args);
+      
+      Process p = vm.process();
+      final InputStream in = p.getInputStream();
+      Thread inputStreamReader = new Thread()
+      {
+         @Override
+         public void run()
+         {
+            try
+            {
+               int b;
+               while((b = in.read()) != -1)
+                  System.out.write(b);
+            }
+            catch(IOException e)
+            {
+               e.printStackTrace();
+            }
+         }
+      };
+      inputStreamReader.setDaemon(true);
+      inputStreamReader.start();
+      
+      final InputStream err = p.getErrorStream();
+      Thread errorStreamReader = new Thread()
+      {
+         @Override
+         public void run()
+         {
+            try
+            {
+               int b;
+               while((b = err.read()) != -1)
+                  System.err.write(b);
+            }
+            catch(IOException e)
+            {
+               e.printStackTrace();
+            }
+         }
+      };
+      errorStreamReader.setDaemon(true);
+      errorStreamReader.start();
+      
+      vm.resume();
+      
+      // This causes an EOFException, which can be ignored.
+      waitForSocket(5783, 10, TimeUnit.SECONDS);
+   }
+   
+   private static String getClassPath()
+   {
+      String sureFireTestClassPath = System.getProperty("surefire.test.class.path");
+      log.debug("sureFireTestClassPath = " + sureFireTestClassPath);
+      String javaClassPath = System.getProperty("java.class.path");
+      log.debug("javaClassPath = " + javaClassPath);
+      // make sure we can run under surefire 
+      String classPath = sureFireTestClassPath;
+      if(classPath == null)
+         classPath = javaClassPath;
+      log.debug("classPath = " + classPath);
+      return classPath;
+   }
+   
+   @Test
+   public void testRaw() throws Throwable
+   {
+      System.out.println("Hello world");
+      
+      InvokerLocator locator = new InvokerLocator("socket://localhost:5783");
+      String subsystem = "EJB3_R2D2";
+      
+      Client client = new Client(locator, subsystem);
+      client.setDisconnectTimeout(1);
+      client.connect();
+      Map<Object, Object> metadata = new HashMap<Object, Object>();
+      metadata.put(EJB3ServerInvocationHandler.OID, "MockRemotableID");
+      
+      // the target of MockRemotable is RemotableEndpoint
+      Method realMethod = RemotableEndpoint.class.getDeclaredMethod("invoke", Serializable.class, Map.class, Class.class, SerializableMethod.class, Object[].class);
+      SerializableMethod method = new SerializableMethod(realMethod);
+      Serializable session = null;
+      Map<?, ?> context = null;
+      // the remotable endpoint delegates to a MockInterface endpoint
+      SerializableMethod businessMethod = new SerializableMethod(MockInterface.class.getDeclaredMethod("sayHi", String.class));
+      Object args[] = { session, context, null, businessMethod, new Object[] { "y" } };
+      Object param = new Object[] { method, args };
+      String result = (String) client.invoke(param, metadata);
+      client.disconnect();
+      
+      assertEquals("Hi y", result);
+   }
+   
+   @Test
+   public void testRealEndpoint() throws Throwable
+   {
+      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);
+      
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      Class<?> interfaces[] = { businessInterface };
+      MockInterface proxy = (MockInterface) Proxy.newProxyInstance(loader, interfaces, handler);
+      String result = proxy.sayHi("there");
+      assertEquals("Hi there", result);
+   }
+   
+   @Test
+   public void testRemotableEndpoint() throws Throwable
+   {
+      InvokerLocator locator = new InvokerLocator("socket://localhost:5783");
+      String subsystem = "EJB3_R2D2";
+      
+      Client client = new Client(locator, subsystem);
+      client.setDisconnectTimeout(1);
+      client.connect();
+      
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      Class<?> interfaces[] = { RemotableEndpoint.class };
+      InvocationHandler handler = new RemoteInvocationHandler(client, "MockRemotableID");
+      RemotableEndpoint endpoint = (RemotableEndpoint) Proxy.newProxyInstance(loader, interfaces, handler);
+      
+      Serializable session = null;
+      Map<?, ?> context = null;
+      // the remotable endpoint delegates to a MockInterface endpoint
+      SerializableMethod businessMethod = new SerializableMethod(MockInterface.class.getDeclaredMethod("sayHi", String.class));
+      Object args[] = { "me" };
+      String result = (String) endpoint.invoke(session, context, null, businessMethod, args);
+      assertEquals("Hi me", result);
+   }
+   
+   private static void waitForSocket(int port, long duration, TimeUnit unit)
+   {
+      long end = System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(duration, unit);
+      while(System.currentTimeMillis() < end)
+      {
+         try
+         {
+            Socket socket = new Socket("localhost", port);
+            socket.close();
+            return;
+         }
+         catch(ConnectException e)
+         {
+            // ignore
+         }
+         catch (UnknownHostException e)
+         {
+            throw new RuntimeException(e);
+         }
+         catch (IOException e)
+         {
+            throw new RuntimeException(e);
+         }
+         try
+         {
+            Thread.sleep(1000);
+         }
+         catch (InterruptedException e)
+         {
+            return;
+         }
+      }
+   }
+}

Added: projects/ejb3/trunk/remoting2/src/test/resources/META-INF/jboss-beans.xml
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/resources/META-INF/jboss-beans.xml	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/resources/META-INF/jboss-beans.xml	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+   <bean name="EJB3ServerInvocationHandler" class="org.jboss.ejb3.remoting2.EJB3ServerInvocationHandler">
+      <incallback method="addRemotable"/>
+      <uncallback method="removeRemotable"/>
+   </bean>
+   
+   <bean name="EJB3ServerConfiguration" class="org.jboss.remoting.ServerConfiguration">
+      <property name="invocationHandlers">
+         <map keyClass="java.lang.String" valueClass="java.lang.Object">
+            <entry>
+               <key>EJB3_R2D2</key>
+               <value><inject bean="EJB3ServerInvocationHandler"/></value>
+            </entry>
+         </map>
+      </property>
+   </bean>
+   
+   <bean name="EJB3RemotingConnector" class="org.jboss.remoting.transport.Connector">
+      <property name="invokerLocator">socket://0.0.0.0:5783</property>
+      <property name="serverConfiguration"><inject bean="EJB3ServerConfiguration"/></property>
+   </bean>
+   
+   <bean name="MockRemotable" class="org.jboss.ejb3.remoting2.test.common.MockRemotable"/>
+</deployment>
\ No newline at end of file

Added: projects/ejb3/trunk/remoting2/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/resources/log4j.xml	                        (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/resources/log4j.xml	2009-03-19 18:08:21 UTC (rev 86113)
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!--                                                                       -->
+<!--  Log4j Configuration                                                  -->
+<!--                                                                       -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 68671 2008-01-08 10:04:25Z wolfc $ -->
+
+<!--
+   | For more configuration infromation and examples see the Jakarta Log4j
+   | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+  <!-- ================================= -->
+  <!-- Preserve messages in a local file -->
+  <!-- ================================= -->
+
+  <!-- A time/date based rolling appender -->
+  <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
+    <param name="File" value="target/test.log"/>
+    <param name="Append" value="false"/>
+
+    <!-- Rollover at midnight each day -->
+    <param name="DatePattern" value="'.'yyyy-MM-dd"/>
+
+    <!-- Rollover at the top of each hour
+    <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
+    -->
+
+    <layout class="org.apache.log4j.PatternLayout">
+      <!-- The default pattern: Date Priority [Category] Message\n -->
+      <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+
+      <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
+      <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+       -->
+    </layout>	    
+  </appender>
+
+  <!-- A size based file rolling appender
+  <appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
+    <param name="File" value="${jboss.server.home.dir}/log/server.log"/>
+    <param name="Append" value="false"/>
+    <param name="MaxFileSize" value="500KB"/>
+    <param name="MaxBackupIndex" value="1"/>
+
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+    </layout>	    
+  </appender>
+  -->
+
+  <!-- ============================== -->
+  <!-- Append messages to the console -->
+  <!-- ============================== -->
+
+  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out"/>
+    <param name="Threshold" value="DEBUG"/>
+
+    <layout class="org.apache.log4j.PatternLayout">
+      <!-- The default pattern: Date Priority [Category] Message\n -->
+      <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+    </layout>
+  </appender>
+
+
+  <!-- ================ -->
+  <!-- Limit categories -->
+  <!-- ================ -->
+
+  <!-- Limit JBoss categories to INFO
+  <category name="org.jboss">
+    <priority value="INFO" class="org.jboss.logging.XLevel"/>
+  </category>
+  -->
+
+  <!-- Increase the priority threshold for the DefaultDS category
+  <category name="DefaultDS">
+    <priority value="FATAL"/>
+  </category>
+  -->
+
+  <!-- Decrease the priority threshold for the org.jboss.varia category
+  <category name="org.jboss.varia">
+    <priority value="DEBUG"/>
+  </category>
+  -->
+
+  <!--
+     | An example of enabling the custom TRACE level priority that is used
+     | by the JBoss internals to diagnose low level details. This example
+     | turns on TRACE level msgs for the org.jboss.ejb.plugins package and its
+     | subpackages. This will produce A LOT of logging output.
+  <category name="org.jboss.system">
+    <priority value="TRACE" class="org.jboss.logging.XLevel"/>
+  </category>
+  -->
+
+  <category name="org.jboss.aop">
+    <priority value="WARN"/>
+  </category>
+  
+  <category name="org.jboss">
+    <priority value="ALL"/>
+  </category>
+  
+  <!-- 
+  Unnecessary, EJB3 is exposed as DEBUG
+  <category name="org.jboss.ejb3.interceptors.aop.DomainClassLoader">
+    <priority value="DEBUG"/>
+  </category>   -->
+  
+  <!-- ======================= -->
+  <!-- Setup the Root category -->
+  <!-- ======================= -->
+
+  <root>
+    <priority value="INFO" />
+    <appender-ref ref="CONSOLE"/>
+    <appender-ref ref="FILE"/>
+  </root>
+  
+</log4j:configuration>




More information about the jboss-cvs-commits mailing list