Author: david.lloyd(a)jboss.com
Date: 2008-10-22 19:47:56 -0400 (Wed, 22 Oct 2008)
New Revision: 4608
Added:
remoting3/trunk/transporter/
remoting3/trunk/transporter/src/
remoting3/trunk/transporter/src/main/
remoting3/trunk/transporter/src/main/java/
remoting3/trunk/transporter/src/main/java/org/
remoting3/trunk/transporter/src/main/java/org/jboss/
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/Transporter.java
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterInvocation.java
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterInvocationHandler.java
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterRequestListener.java
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/package-info.java
Modified:
remoting3/trunk/build.xml
Log:
Add transporters (for Ron:)
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2008-10-22 22:01:55 UTC (rev 4607)
+++ remoting3/trunk/build.xml 2008-10-22 23:47:56 UTC (rev 4608)
@@ -503,189 +503,6 @@
</path>
</target>
- <!-- http module -->
-
- <target name="http.compile.depcheck">
- <mkdir dir="http/target/main"/>
- <uptodate property="http.compile.uptodate"
targetfile="http/target/main/.lastcompile">
- <srcfiles dir="http/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="http.compile" depends="http.compile.depcheck"
unless="http.compile.uptodate">
- <mkdir dir="http/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="http/src/main/java"
- destdir="http/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <path refid="api.classpath"/>
- <path refid="util.classpath"/>
- </classpath>
- </javac>
- <touch file="http/target/main/.lastcompile"
verbose="false"/>
- </target>
-
- <target name="http.clean">
- <delete dir="http/target"/>
- </target>
-
- <target name="http" description="Build the http module"
depends="api,util,http.compile">
- <path id="http.classpath">
- <pathelement location="http/target/main/classes"/>
- </path>
- </target>
-
- <!-- http-se6 module -->
-
- <target name="http-se6.httpserver.builtin-check">
- <condition property="http-se6.httpserver.builtin">
- <available classname="com.sun.http.HttpServer"/>
- </condition>
- </target>
-
- <target name="http-se6.httpserver.classpath.false"
depends="http-se6.httpserver.builtin-check"
unless="http-se6.httpserver.builtin">
- <path id="httpserver.classpath">
- <pathelement location="${lib.sun-httpserver.local}"/>
- </path>
- </target>
-
- <target name="http-se6.httpserver.classpath.true"
depends="http-se6.httpserver.builtin-check"
if="http-se6.httpserver.builtin">
- <path id="httpserver.classpath"/>
- </target>
-
- <target name="http-se6.httpserver.classpath"
depends="http-se6.httpserver.classpath.false,http-se6.httpserver.classpath.true"/>
-
- <target name="http-se6.compile.depcheck">
- <mkdir dir="http-se6/target/main"/>
- <uptodate property="http-se6.compile.uptodate"
targetfile="http-se6/target/main/.lastcompile">
- <srcfiles dir="http-se6/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="http-se6.compile"
depends="http-se6.compile.depcheck,http-se6.httpserver.classpath"
unless="http-se6.compile.uptodate">
- <mkdir dir="http-se6/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="http-se6/src/main/java"
- destdir="http-se6/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <path refid="api.classpath"/>
- <path refid="http.classpath"/>
- <path refid="util.classpath"/>
- <path refid="httpserver.classpath"/>
- </classpath>
- </javac>
- <touch file="http-se6/target/main/.lastcompile"
verbose="false"/>
- </target>
-
- <target name="http-se6.clean">
- <delete dir="http-se6/target"/>
- </target>
-
- <target name="http-se6" description="Build the http-se6
module" depends="lib.sun-httpserver,api,http,util,http-se6.compile">
- <path id="http-se6.classpath">
- <pathelement location="http-se6/target/main/classes"/>
- </path>
- </target>
-
- <!-- http-servlet module -->
-
- <target name="http-servlet.compile.depcheck">
- <mkdir dir="http-servlet/target/main"/>
- <uptodate property="http-servlet.compile.uptodate"
targetfile="http-servlet/target/main/.lastcompile">
- <srcfiles dir="http-servlet/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="http-servlet.compile"
depends="http-servlet.compile.depcheck"
unless="http-servlet.compile.uptodate">
- <mkdir dir="http-servlet/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="http-servlet/src/main/java"
- destdir="http-servlet/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <path refid="api.classpath"/>
- <path refid="http.classpath"/>
- <path refid="util.classpath"/>
- <pathelement location="${lib.servlet.local}"/>
- </classpath>
- </javac>
- <touch file="http-servlet/target/main/.lastcompile"
verbose="false"/>
- </target>
-
- <target name="http-servlet.clean">
- <delete dir="http-servlet/target"/>
- </target>
-
- <target name="http-servlet" description="Build the http-servlet
module" depends="api,http,util,lib.servlet,http-servlet.compile">
- <path id="http-servlet.classpath">
- <pathelement location="http-servlet/target/main/classes"/>
- </path>
- </target>
-
- <!-- http-urlconnection module -->
-
- <target name="http-urlconnection.compile.depcheck">
- <mkdir dir="http-urlconnection/target/main"/>
- <uptodate property="http-urlconnection.compile.uptodate"
targetfile="http-urlconnection/target/main/.lastcompile">
- <srcfiles dir="http-urlconnection/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="http-urlconnection.compile"
depends="http-urlconnection.compile.depcheck"
unless="http-urlconnection.compile.uptodate">
- <mkdir dir="http-urlconnection/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="http-urlconnection/src/main/java"
- destdir="http-urlconnection/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <path refid="api.classpath"/>
- <path refid="http.classpath"/>
- <path refid="util.classpath"/>
- </classpath>
- </javac>
- <touch file="http-urlconnection/target/main/.lastcompile"
verbose="false"/>
- </target>
-
- <target name="http-urlconnection.clean">
- <delete dir="http-urlconnection/target"/>
- </target>
-
- <target name="http-urlconnection" description="Build the
http-urlconnection module"
depends="api,http,util,http-urlconnection.compile">
- <path id="http-urlconnection.classpath">
- <pathelement
location="http-urlconnection/target/main/classes"/>
- </path>
- </target>
-
<!-- mc-deployers module -->
<target name="mc-deployers.compile.depcheck">
@@ -996,7 +813,6 @@
</path>
</target>
-
<!-- samples module -->
<target name="samples.compile.depcheck">
@@ -1021,7 +837,6 @@
<compilerarg value="-Xlint:unchecked"/>
<classpath>
<path refid="api.classpath"/>
- <path refid="srp.classpath"/>
<path refid="standalone.classpath"/>
<path refid="util.classpath"/>
<pathelement location="${lib.xnio-api.local}"/>
@@ -1034,88 +849,12 @@
<delete dir="samples/target"/>
</target>
- <target name="samples" description="Build the samples module"
depends="api,srp,standalone,util,samples.compile">
+ <target name="samples" description="Build the samples module"
depends="api,standalone,util,samples.compile">
<path id="samples.classpath">
<pathelement location="samples/target/main/classes"/>
</path>
</target>
- <!-- sasl-null module -->
-
- <target name="sasl-null.compile.depcheck">
- <mkdir dir="sasl-null/target/main"/>
- <uptodate property="sasl-null.compile.uptodate"
targetfile="sasl-null/target/main/.lastcompile">
- <srcfiles dir="sasl-null/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="sasl-null.compile"
depends="sasl-null.compile.depcheck"
unless="sasl-null.compile.uptodate">
- <mkdir dir="sasl-null/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="sasl-null/src/main/java"
- destdir="sasl-null/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- </javac>
- <touch file="sasl-null/target/main/.lastcompile"
verbose="false"/>
- </target>
-
- <target name="sasl-null.clean">
- <delete dir="sasl-null/target"/>
- </target>
-
- <target name="sasl-null" description="Build the sasl-null
module" depends="sasl-null.compile">
- <path id="sasl-null.classpath">
- <pathelement location="sasl-null/target/main/classes"/>
- </path>
- </target>
-
- <!-- srp module -->
-
- <target name="srp.compile.depcheck">
- <mkdir dir="srp/target/main"/>
- <uptodate property="srp.compile.uptodate"
targetfile="srp/target/main/.lastcompile">
- <srcfiles dir="srp/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="srp.compile" depends="srp.compile.depcheck"
unless="srp.compile.uptodate">
- <mkdir dir="srp/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="srp/src/main/java"
- destdir="srp/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
- <path refid="util.classpath"/>
- <pathelement location="${lib.xnio-api.local}"/>
- </classpath>
- </javac>
- <touch file="srp/target/main/.lastcompile"
verbose="false"/>
- </target>
-
- <target name="srp.clean">
- <delete dir="srp/target"/>
- </target>
-
- <target name="srp" description="Build the SRP SASL module"
depends="util,srp.compile">
- <path id="srp.classpath">
- <pathelement location="srp/target/main/classes"/>
- </path>
- </target>
-
<!-- standalone module -->
<target name="standalone.compile.depcheck">
@@ -1198,85 +937,43 @@
</path>
</target>
- <!-- tools module -->
+ <!-- transporter module -->
- <target name="tools.compile.depcheck">
- <mkdir dir="tools/target/main"/>
- <uptodate property="tools.compile.uptodate"
targetfile="tools/target/main/.lastcompile">
- <srcfiles dir="tools/src/main/java">
+ <target name="transporter.compile.depcheck">
+ <mkdir dir="transporter/target/main"/>
+ <uptodate property="transporter.compile.uptodate"
targetfile="transporter/target/main/.lastcompile">
+ <srcfiles dir="transporter/src/main/java">
<include name="**/"/>
<include name="**/*.java"/>
<exclude name="**/.*"/>
</srcfiles>
</uptodate>
- <condition property="tools.supported">
- <available classname="java.io.Console"/>
- </condition>
</target>
- <target name="tools.compile" depends="tools.compile.depcheck"
unless="tools.compile.uptodate" if="tools.supported">
- <mkdir dir="tools/target/main/classes"/>
+ <target name="transporter.compile"
depends="transporter.compile.depcheck"
unless="transporter.compile.uptodate">
+ <mkdir dir="transporter/target/main/classes"/>
<javac
source="${javac.source}"
target="${javac.target}"
- srcdir="tools/src/main/java"
- destdir="tools/target/main/classes"
+ srcdir="transporter/src/main/java"
+ destdir="transporter/target/main/classes"
debug="true">
<compilerarg value="-Xlint:unchecked"/>
<classpath>
- <path refid="srp.classpath"/>
- <path refid="util.classpath"/>
- </classpath>
- </javac>
- <touch file="tools/target/main/.lastcompile"
verbose="false"/>
- </target>
-
- <target name="tools.clean">
- <delete dir="tools/target"/>
- </target>
-
- <target name="tools" description="Build the tools module"
depends="srp,util,tools.compile">
- <path id="tools.classpath">
- <pathelement location="tools/target/main/classes"/>
- </path>
- </target>
-
- <!-- transaction module -->
-
- <target name="transaction.compile.depcheck">
- <mkdir dir="transaction/target/main"/>
- <uptodate property="transaction.compile.uptodate"
targetfile="transaction/target/main/.lastcompile">
- <srcfiles dir="transaction/src/main/java">
- <include name="**/"/>
- <include name="**/*.java"/>
- <exclude name="**/.*"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="transaction.compile"
depends="transaction.compile.depcheck"
unless="transaction.compile.uptodate">
- <mkdir dir="transaction/target/main/classes"/>
- <javac
- source="${javac.source}"
- target="${javac.target}"
- srcdir="transaction/src/main/java"
- destdir="transaction/target/main/classes"
- debug="true">
- <compilerarg value="-Xlint:unchecked"/>
- <classpath>
<path refid="api.classpath"/>
+ <pathelement location="${lib.xnio-api.local}"/>
</classpath>
</javac>
- <touch file="transaction/target/main/.lastcompile"
verbose="false"/>
+ <touch file="transporter/target/main/.lastcompile"
verbose="false"/>
</target>
- <target name="transaction.clean">
- <delete dir="transaction/target"/>
+ <target name="transporter.clean">
+ <delete dir="transporter/target"/>
</target>
- <target name="transaction" description="Build the transaction
module" depends="api,transaction.compile">
- <path id="transaction.classpath">
- <pathelement location="transaction/target/main/classes"/>
+ <target name="transporter" description="Build the transporter
module" depends="api,lib.xnio-api,transporter.compile">
+ <path id="transporter.classpath">
+ <pathelement location="transporter/target/main/classes"/>
</path>
</target>
@@ -1361,7 +1058,7 @@
<!-- JARS - Keep in alpha order by jar name -->
<!-- ============================================== -->
- <target name="api-jar" description="Build the API JAR"
depends="api,util,version">
+ <target name="api-jar" description="Build the API JAR"
depends="api,transporter,util,version">
<delete file="jboss-remoting-api.jar"/>
<jar jarfile="jboss-remoting-api.jar">
<manifest>
@@ -1378,6 +1075,9 @@
<zipfileset dir="api/target/main/classes">
<include name="**/*.class"/>
</zipfileset>
+ <zipfileset dir="transporter/target/main/classes">
+ <include name="**/*.class"/>
+ </zipfileset>
<zipfileset dir="util/target/main/classes">
<include name="**/*.class"/>
</zipfileset>
@@ -1407,7 +1107,7 @@
</jar>
</target>
- <target name="standalone-jar" description="Build the standalone
JAR" depends="api,core,srp,standalone,util,version">
+ <target name="standalone-jar" description="Build the standalone
JAR" depends="api,core,standalone,util,version">
<delete file="jboss-remoting-standalone.jar"/>
<jar jarfile="jboss-remoting-standalone.jar">
<manifest>
@@ -1450,6 +1150,7 @@
<doclet name="${lib.apiviz.doclet}"
path="${lib.apiviz.local}"/>
<packageset dir="api/src/main/java"/>
<packageset dir="standalone/src/main/java"/>
+ <packageset dir="transporter/src/main/java"/>
<packageset dir="util/src/main/java"/>
<doctitle><![CDATA[<h1>JBoss Remoting
3</h1>]]></doctitle>
<bottom><![CDATA[<i>Copyright © 2008 JBoss, a
division of Red Hat, Inc.</i>]]></bottom>
@@ -1460,6 +1161,7 @@
<path refid="core.classpath"/>
<path refid="api.classpath"/>
<path refid="standalone.classpath"/>
+ <path refid="transporter.classpath"/>
<path refid="util.classpath"/>
<pathelement location="${lib.xnio-api.local}"/>
<pathelement location="${lib.marshalling-api.local}"/>
@@ -1472,16 +1174,10 @@
<!-- core -->
- <target name="all-core" description="Build all core targets"
depends="api,compat,core,mc-deployers,protocol.basic,protocol.multiplex,samples,standalone,testing-support,tools,util"/>
+ <target name="all-core" description="Build all core targets"
depends="api,compat,core,mc-deployers,protocol.basic,protocol.multiplex,samples,standalone,testing-support,transporter,util"/>
- <target name="clean-core" description="Clean all core targets"
depends="api.clean,compat.clean,core.clean,mc-deployers.clean,protocol.basic.clean,protocol.multiplex.clean,samples.clean,standalone.clean,testing-support.clean,tools.clean,util.clean"/>
+ <target name="clean-core" description="Clean all core targets"
depends="api.clean,compat.clean,core.clean,mc-deployers.clean,protocol.basic.clean,protocol.multiplex.clean,samples.clean,standalone.clean,testing-support.clean,transporter.clean,util.clean"/>
- <!-- http -->
-
- <target name="all-http" description="Build all HTTP targets"
depends="http,http-se6,http-servlet,http-urlconnection"/>
-
- <target name="clean-http" description="Clean all HTTP targets"
depends="http.clean,http-se6.clean,http-servlet.clean,http-urlconnection.clean"/>
-
<!-- JARs: These should be the third-to-last targets in the file -->
<target name="all-jars" description="Build all the JARs"
depends="api-jar,core-jar,standalone-jar"/>
@@ -1494,7 +1190,7 @@
<target name="all" description="Build everything"
depends="all-core,all-jars,api-javadoc"/>
- <target name="clean" description="Clean out all build files"
depends="clean-core,clean-http,version.clean,srp.clean"/>
+ <target name="clean" description="Clean out all build files"
depends="clean-core,version.clean"/>
<target name="test" description="Run all tests"
depends="api.test,core.test,protocol.basic.test,protocol.multiplex.test"/>
Added:
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/Transporter.java
===================================================================
---
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/Transporter.java
(rev 0)
+++
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/Transporter.java 2008-10-22
23:47:56 UTC (rev 4608)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.remoting.transporter;
+
+import org.jboss.remoting.Endpoint;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.spi.remote.RequestHandler;
+import org.jboss.remoting.spi.remote.Handle;
+import org.jboss.xnio.IoUtils;
+import java.io.IOException;
+import java.lang.reflect.Proxy;
+
+/**
+ * A static class which can be used to create transporter proxies.
+ */
+public final class Transporter {
+
+ private Transporter() {
+ }
+
+ /**
+ * Create a transporter for an object instance. The given type must be an interface
type. The returned object
+ * is a serializable proxy that can be sent to other endpoints as a part of a request
or a reply.
+ *
+ * @param endpoint the endpoint to anchor the transporter to
+ * @param interfaceType the type of the interface to use
+ * @param instance the instance to which invocations will be sent
+ * @return a transporter proxy
+ * @throws IOException if an error occurs
+ */
+ public static <T> T createTransporter(Endpoint endpoint, Class<T>
interfaceType, T instance) throws IOException {
+ boolean ok = false;
+ final Handle<RequestHandler> requestHandlerHandle =
endpoint.createRequestHandler(new TransporterRequestListener<T>(instance));
+ try {
+ final Client<TransporterInvocation,Object> client =
endpoint.createClient(requestHandlerHandle.getResource());
+ try {
+ requestHandlerHandle.close();
+ final T proxy = createProxy(interfaceType, client);
+ ok = true;
+ return proxy;
+ } finally {
+ if (! ok) {
+ IoUtils.safeClose(client);
+ }
+ }
+ } finally {
+ IoUtils.safeClose(requestHandlerHandle);
+ }
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ private static <T> T createProxy(final Class<T> interfaceType, final
Client<TransporterInvocation, Object> client) {
+ return (T) Proxy.newProxyInstance(interfaceType.getClassLoader(), new
Class<?>[] { interfaceType }, new TransporterInvocationHandler(client));
+ }
+}
Added:
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterInvocation.java
===================================================================
---
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterInvocation.java
(rev 0)
+++
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterInvocation.java 2008-10-22
23:47:56 UTC (rev 4608)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.remoting.transporter;
+
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+
+/**
+ *
+ */
+public final class TransporterInvocation implements Externalizable {
+
+ private static final long serialVersionUID = -1643169469978213945L;
+ private String name;
+ private Class<?>[] parameterTypes;
+ private Object[] args;
+
+ public TransporterInvocation() {
+ }
+
+ public TransporterInvocation(final String name, final Class<?>[]
parameterTypes, final Object[] args) {
+ if (parameterTypes.length != args.length) {
+ throw new IllegalArgumentException("parameter type array length differs
from arg array length");
+ }
+ this.name = name;
+ this.parameterTypes = parameterTypes;
+ this.args = args;
+ }
+
+ public void writeExternal(final ObjectOutput out) throws IOException {
+ out.writeObject(name);
+ final Class<?>[] parameterTypes = this.parameterTypes;
+ final Object[] args = this.args;
+ final int len = parameterTypes.length;
+ if (len != args.length) {
+ throw new IllegalStateException("parameter types and/or args length
changed");
+ }
+ out.writeShort(len);
+ for (Class<?> type : parameterTypes) {
+ out.writeObject(type);
+ }
+ for (Object arg : args) {
+ out.writeObject(arg);
+ }
+ }
+
+ public void readExternal(final ObjectInput in) throws IOException,
ClassNotFoundException {
+ name = (String) in.readObject();
+ final short cnt = in.readShort();
+ final Class<?>[] parameterTypes = new Class<?>[cnt];
+ for (short i = 0; i < cnt; i ++) {
+ parameterTypes[i] = (Class<?>) in.readObject();
+ }
+ final Object[] args = new Object[cnt];
+ for (short i = 0; i < cnt; i ++) {
+ args[i] = in.readObject();
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Class<?>[] getParameterTypes() {
+ return parameterTypes;
+ }
+
+ public Object[] getArgs() {
+ return args;
+ }
+}
Added:
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterInvocationHandler.java
===================================================================
---
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterInvocationHandler.java
(rev 0)
+++
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterInvocationHandler.java 2008-10-22
23:47:56 UTC (rev 4608)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.remoting.transporter;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.io.IOException;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.RemoteExecutionException;
+
+/**
+ *
+ */
+public final class TransporterInvocationHandler implements InvocationHandler {
+ private final Client<TransporterInvocation, Object> client;
+
+ public TransporterInvocationHandler(final Client<TransporterInvocation, Object>
client) {
+ this.client = client;
+ }
+
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable {
+ try {
+ return client.invoke(new TransporterInvocation(method.getName(),
method.getParameterTypes(), args));
+ } catch (RemoteExecutionException e) {
+ throw e.getCause();
+ } catch (IOException e) {
+ throw new IllegalStateException("Method invocation failed", e);
+ }
+ }
+}
Added:
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterRequestListener.java
===================================================================
---
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterRequestListener.java
(rev 0)
+++
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/TransporterRequestListener.java 2008-10-22
23:47:56 UTC (rev 4608)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.remoting.transporter;
+
+import org.jboss.remoting.RequestContext;
+import org.jboss.remoting.RemoteExecutionException;
+import org.jboss.remoting.AbstractRequestListener;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.io.IOException;
+
+/**
+ *
+ */
+public final class TransporterRequestListener<T> extends
AbstractRequestListener<TransporterInvocation,Object> {
+ private final T target;
+
+ public TransporterRequestListener(final T target) {
+ this.target = target;
+ }
+
+ public void handleRequest(final RequestContext<Object> context, final
TransporterInvocation request) throws RemoteExecutionException {
+ try {
+ final Method method = target.getClass().getMethod(request.getName(),
request.getParameterTypes());
+ method.invoke(target, request.getArgs());
+ } catch (NoSuchMethodException e) {
+ doSendFailure(context, new NoSuchMethodError("No such method on the
remote side: " + e.getMessage()));
+ } catch (InvocationTargetException e) {
+ doSendFailure(context, e.getCause());
+ } catch (IllegalAccessException e) {
+ doSendFailure(context, new IllegalAccessError("Illegal access in remote
method invocation: " + e.getMessage()));
+ }
+ }
+
+ private void doSendFailure(final RequestContext<Object> context, final
Throwable throwable) {
+ try {
+ context.sendFailure(null, throwable);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
Added:
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/package-info.java
===================================================================
---
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/package-info.java
(rev 0)
+++
remoting3/trunk/transporter/src/main/java/org/jboss/remoting/transporter/package-info.java 2008-10-22
23:47:56 UTC (rev 4608)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.
+ */
+/**
+ * Transporters provide a simple mechanism to access objects remotely. Transporters use
Java reflection proxies to
+ * transparently forward method invocations on an interface to the remote server.
+ */
+package org.jboss.remoting.transporter;