JBoss Remoting SVN: r4611 - in remoting3/trunk: api/src/main/java/org/jboss/remoting/spi/remote and 4 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-10-22 20:10:17 -0400 (Wed, 22 Oct 2008)
New Revision: 4611
Modified:
remoting3/trunk/api/src/main/java/org/jboss/remoting/Client.java
remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/remote/RequestHandler.java
remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/wrapper/ClientWrapper.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandler.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java
remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MessageType.java
remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexHandler.java
Log:
Remove one-way request type... for now
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/Client.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/Client.java 2008-10-23 00:04:24 UTC (rev 4610)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/Client.java 2008-10-23 00:10:17 UTC (rev 4611)
@@ -85,19 +85,6 @@
IoFuture<O> send(I request) throws IOException;
/**
- * Send a request asynchronously, ignoring the reply.
- * </p>
- * Uses the default invocation policy for handling remote invocations. If the remote side manipulates a stream, it
- * MAY fail with an exception (e.g. if this method is called on a client with no threads to handle streaming).
- * <p/>
- * Returns immediately.
- *
- * @param request the request to send
- * @throws IOException if the request could not be sent
- */
- void sendOneWay(I request) throws IOException;
-
- /**
* Get the attribute map. This map holds metadata about the current clinet.
*
* @return the attribute map
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/remote/RequestHandler.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/remote/RequestHandler.java 2008-10-23 00:04:24 UTC (rev 4610)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/remote/RequestHandler.java 2008-10-23 00:10:17 UTC (rev 4611)
@@ -34,14 +34,6 @@
public interface RequestHandler extends HandleableCloseable<RequestHandler> {
/**
- * Receive a one-way request from a remote system. This method is intended to be called by protocol handlers. No
- * reply will be sent back to the client.
- *
- * @param request the request
- */
- void receiveRequest(Object request);
-
- /**
* Receive a request from a remote system. This method is intended to be called by protocol handlers. If the
* request cannot be accepted for some reason, the
* {@link ReplyHandler#handleException(java.io.IOException)}
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/wrapper/ClientWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/wrapper/ClientWrapper.java 2008-10-23 00:04:24 UTC (rev 4610)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/wrapper/ClientWrapper.java 2008-10-23 00:10:17 UTC (rev 4611)
@@ -59,13 +59,6 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void sendOneWay(final I request) throws IOException {
- delegate.sendOneWay(request);
- }
-
- /**
- * {@inheritDoc} This implementation calls the same method on the delegate object.
- */
public ConcurrentMap<Object, Object> getAttributes() {
return delegate.getAttributes();
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java 2008-10-23 00:04:24 UTC (rev 4610)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java 2008-10-23 00:10:17 UTC (rev 4611)
@@ -87,13 +87,6 @@
return futureReply;
}
- public void sendOneWay(final I request) throws IOException {
- if (! isOpen()) {
- throw new IOException("Client is not open");
- }
- handle.getResource().receiveRequest(request);
- }
-
public String toString() {
return "client instance <" + Integer.toString(hashCode()) + ">";
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandler.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandler.java 2008-10-23 00:04:24 UTC (rev 4610)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandler.java 2008-10-23 00:10:17 UTC (rev 4611)
@@ -58,20 +58,6 @@
this(executor, requestListener, new ClientContextImpl(executor));
}
- public void receiveRequest(final Object request) {
- final RequestContextImpl<O> context = new RequestContextImpl<O>(clientContext);
- context.execute(new Runnable() {
- @SuppressWarnings({ "unchecked" })
- public void run() {
- try {
- requestListener.handleRequest(context, (I) request);
- } catch (Throwable t) {
- log.error(t, "Unexpected exception in request listener");
- }
- }
- });
- }
-
public RemoteRequestContext receiveRequest(final Object request, final ReplyHandler replyHandler) {
final RequestContextImpl<O> context = new RequestContextImpl<O>(replyHandler, clientContext);
context.execute(new Runnable() {
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java 2008-10-23 00:04:24 UTC (rev 4610)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java 2008-10-23 00:10:17 UTC (rev 4611)
@@ -59,20 +59,6 @@
requestSequence = new AtomicInteger();
}
- public void receiveRequest(final Object request) {
- reqLock.lock();
- try {
- marshaller.write(1);
- marshaller.writeObject(request);
- marshaller.flush();
- } catch (IOException e) {
- log.error(e, "Error receiving request");
- IoUtils.safeClose(this);
- } finally {
- reqLock.unlock();
- }
- }
-
public RemoteRequestContext receiveRequest(final Object request, final ReplyHandler replyHandler) {
reqLock.lock();
try {
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java 2008-10-23 00:04:24 UTC (rev 4610)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java 2008-10-23 00:10:17 UTC (rev 4611)
@@ -64,12 +64,6 @@
// done.
return;
}
- case 1: {
- // one-way request
- final Object request = unmarshaller.readObject();
- requestHandler.receiveRequest(request);
- break;
- }
case 2: {
// two-way request
final int requestId = requestSequence++;
Modified: remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MessageType.java
===================================================================
--- remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MessageType.java 2008-10-23 00:04:24 UTC (rev 4610)
+++ remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MessageType.java 2008-10-23 00:10:17 UTC (rev 4611)
@@ -28,7 +28,6 @@
public enum MessageType {
// One-way request, no return value may be sent
- REQUEST_ONEWAY(1),
// Two-way request, return value is expected
REQUEST(2),
// Reply
@@ -72,7 +71,6 @@
*/
public static MessageType getMessageType(final int id) {
switch (id) {
- case 1: return REQUEST_ONEWAY;
case 2: return REQUEST;
case 3: return REPLY;
case 4: return CANCEL_REQUEST;
Modified: remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexHandler.java
===================================================================
--- remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexHandler.java 2008-10-23 00:04:24 UTC (rev 4610)
+++ remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexHandler.java 2008-10-23 00:10:17 UTC (rev 4611)
@@ -49,8 +49,6 @@
import org.jboss.remoting.SimpleCloseable;
import org.jboss.remoting.RemoteExecutionException;
import org.jboss.remoting.IndeterminateOutcomeException;
-import org.jboss.remoting.ReplyException;
-import org.jboss.remoting.RemoteReplyException;
import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Unmarshaller;
import org.jboss.marshalling.ByteOutput;
@@ -169,40 +167,6 @@
}
log.trace("Received message %s, type %s", buffer, msgType);
switch (msgType) {
- case REQUEST_ONEWAY: {
- final int clientId = buffer.getInt();
- final Handle<RequestHandler> handle = forwardedClients.get(clientId);
- if (handle == null) {
- log.trace("Request on invalid client ID %d", Integer.valueOf(clientId));
- return;
- }
- final Object payload;
- try {
- final Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(marshallingConfiguration);
- try {
- unmarshaller.start(Marshalling.createByteInput(buffer));
- try {
- payload = unmarshaller.readObject();
- unmarshaller.finish();
- } catch (ClassNotFoundException e) {
- log.trace("Class not found in one-way request for client ID %d", Integer.valueOf(clientId));
- break;
- }
- } finally {
- IoUtils.safeClose(unmarshaller);
- }
- } catch (IOException ex) {
- log.error(ex, "Failed to unmarshal a one-way request");
- break;
- }
- final RequestHandler requestHandler = handle.getResource();
- try {
- requestHandler.receiveRequest(payload);
- } catch (Throwable t) {
- log.error(t, "One-way request handler unexpectedly threw an exception");
- }
- break;
- }
case REQUEST: {
final int clientId = buffer.getInt();
final Handle<RequestHandler> handle = forwardedClients.get(clientId);
@@ -630,40 +594,6 @@
});
}
- public void receiveRequest(final Object request) {
- log.trace("Sending outbound one-way request of type %s", request == null ? "null" : request.getClass());
- try {
- final List<ByteBuffer> bufferList;
- final Marshaller marshaller = marshallerFactory.createMarshaller(marshallingConfiguration);
- try {
- bufferList = new ArrayList<ByteBuffer>();
- final ByteOutput output = createByteOutput(allocator, bufferList);
- try {
- marshaller.write(MessageType.REQUEST_ONEWAY.getId());
- marshaller.writeInt(identifier);
- marshaller.writeObject(request);
- marshaller.close();
- output.close();
- } finally {
- IoUtils.safeClose(output);
- }
- } finally {
- IoUtils.safeClose(marshaller);
- }
- try {
- registerWriter(channel, new SimpleWriteHandler(allocator, bufferList));
- } catch (InterruptedException e) {
- log.trace(e, "receiveRequest was interrupted");
- Thread.currentThread().interrupt();
- return;
- }
- } catch (Throwable t) {
- // ignore
- log.trace(t, "receiveRequest failed with an exception");
- return;
- }
- }
-
public RemoteRequestContext receiveRequest(final Object request, final ReplyHandler handler) {
log.trace("Sending outbound request of type %s", request == null ? "null" : request.getClass());
try {
16 years, 2 months
JBoss Remoting SVN: r4610 - in remoting3/trunk: samples/src/main/java/org/jboss/remoting/samples/simple and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-10-22 20:04:24 -0400 (Wed, 22 Oct 2008)
New Revision: 4610
Removed:
remoting3/trunk/http-se6/
remoting3/trunk/http-servlet/
remoting3/trunk/http-urlconnection/
remoting3/trunk/http/
remoting3/trunk/sasl-null/
remoting3/trunk/srp/
remoting3/trunk/transaction/
Modified:
remoting3/trunk/build.xml
remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/LocalBasicExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/LocalStreamExampleMain.java
Log:
Remove old/obsolete code
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2008-10-23 00:00:34 UTC (rev 4609)
+++ remoting3/trunk/build.xml 2008-10-23 00:04:24 UTC (rev 4610)
@@ -1107,7 +1107,7 @@
</jar>
</target>
- <target name="standalone-jar" description="Build the standalone JAR" depends="api,core,standalone,util,version">
+ <target name="standalone-jar" description="Build the standalone JAR" depends="api,core,standalone,transporter,util,version">
<delete file="jboss-remoting-standalone.jar"/>
<jar jarfile="jboss-remoting-standalone.jar">
<manifest>
@@ -1127,10 +1127,10 @@
<zipfileset dir="core/target/main/classes">
<include name="**/*.class"/>
</zipfileset>
- <zipfileset dir="srp/target/main/classes">
+ <zipfileset dir="standalone/target/main/classes">
<include name="**/*.class"/>
</zipfileset>
- <zipfileset dir="standalone/target/main/classes">
+ <zipfileset dir="transporter/target/main/classes">
<include name="**/*.class"/>
</zipfileset>
<zipfileset dir="util/target/main/classes">
Modified: remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/LocalBasicExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/LocalBasicExampleMain.java 2008-10-23 00:00:34 UTC (rev 4609)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/LocalBasicExampleMain.java 2008-10-23 00:04:24 UTC (rev 4610)
@@ -1,12 +1,9 @@
package org.jboss.remoting.samples.simple;
import java.io.IOException;
-import java.security.Security;
import org.jboss.remoting.Client;
import org.jboss.remoting.Endpoint;
-import org.jboss.remoting.RemoteExecutionException;
import org.jboss.remoting.Remoting;
-import org.jboss.remoting.core.security.sasl.Provider;
import org.jboss.xnio.IoUtils;
/**
@@ -14,8 +11,10 @@
*/
public final class LocalBasicExampleMain {
- public static void main(String[] args) throws IOException, RemoteExecutionException {
- Security.addProvider(new Provider());
+ private LocalBasicExampleMain() {
+ }
+
+ public static void main(String[] args) throws IOException {
final StringRot13RequestListener listener = new StringRot13RequestListener();
final Endpoint endpoint = Remoting.createEndpoint("simple");
try {
Modified: remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/LocalStreamExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/LocalStreamExampleMain.java 2008-10-23 00:00:34 UTC (rev 4609)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting/samples/simple/LocalStreamExampleMain.java 2008-10-23 00:04:24 UTC (rev 4610)
@@ -4,12 +4,9 @@
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
-import java.security.Security;
import org.jboss.remoting.Client;
import org.jboss.remoting.Endpoint;
-import org.jboss.remoting.RemoteExecutionException;
import org.jboss.remoting.Remoting;
-import org.jboss.remoting.core.security.sasl.Provider;
import org.jboss.xnio.IoUtils;
/**
@@ -20,8 +17,7 @@
private LocalStreamExampleMain() {
}
- public static void main(String[] args) throws IOException, RemoteExecutionException {
- Security.addProvider(new Provider());
+ public static void main(String[] args) throws IOException {
final StreamingRot13RequestListener listener = new StreamingRot13RequestListener();
final Endpoint endpoint = Remoting.createEndpoint("simple");
try {
16 years, 2 months
JBoss Remoting SVN: r4609 - remoting3/trunk/transporter.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-10-22 20:00:34 -0400 (Wed, 22 Oct 2008)
New Revision: 4609
Modified:
remoting3/trunk/transporter/
Log:
svn:ignore
Property changes on: remoting3/trunk/transporter
___________________________________________________________________
Name: svn:ignore
+ *.iml
target
16 years, 2 months
JBoss Remoting SVN: r4608 - in remoting3/trunk: transporter and 7 other directories.
by jboss-remoting-commits@lists.jboss.org
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;
16 years, 2 months
JBoss Remoting SVN: r4607 - in remoting3/trunk: api/src/main/java/org/jboss/remoting/spi and 4 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-10-22 18:01:55 -0400 (Wed, 22 Oct 2008)
New Revision: 4607
Added:
remoting3/trunk/api/src/main/java/org/jboss/remoting/RemoteReplyException.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestListenerExecutor.java
Removed:
remoting3/trunk/api/src/main/java/org/jboss/remoting/RemotingExceptionCarrier.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/util/TaggingExecutor.java
Modified:
remoting3/trunk/api/src/main/java/org/jboss/remoting/Client.java
remoting3/trunk/api/src/main/java/org/jboss/remoting/RemotingException.java
remoting3/trunk/api/src/main/java/org/jboss/remoting/RequestContext.java
remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/SpiUtils.java
remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/remote/ReplyHandler.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientExternalizer.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientSourceExternalizer.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientSourceImpl.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandler.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandlerSource.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestContextImpl.java
remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexHandler.java
Log:
Update semantics of exception handling for client/handler/listener chains, as per 10/21 discussion
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/Client.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/Client.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/Client.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -1,7 +1,9 @@
package org.jboss.remoting;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CancellationException;
import java.io.IOException;
+import java.io.ObjectStreamException;
import org.jboss.xnio.IoFuture;
/**
@@ -12,29 +14,67 @@
*/
public interface Client<I, O> extends HandleableCloseable<Client<I, O>> {
/**
- * Send a request and block until a reply is received.
+ * Send a request and block until a reply is received. If the remote side manipulates a stream, the
+ * current thread may be used to handle it.
* <p/>
- * Uses the default invocation policy for handling remote invocations. If the remote side manipulates a stream, the
- * current thread will be used to handle it by default.
+ * If the operation is cancelled asynchronously, a {@code CancellationException} is thrown. This exception indicates
+ * that the request was received and was executed, but a cancellation request was received and handled before the
+ * reply was able to be sent. The remote service will have cleanly cancelled the operation. This exception type
+ * is a {@code RuntimeException}; thus direct handling of this exception is optional (depending on your use case).
* <p/>
- * If the remote session cannot handle the request, a {@code RemotingException} will be thrown.
+ * If the request is sent but the remote side sends an exception back, a {@code RemoteExecutionException} is thrown
+ * with the cause and message initialized by the remote service. This exception indicates an error in the execution
+ * of the service's {@code RequestListener}. The service will have cleanly recovered from such an exception.
+ * <p/>
+ * If the request is sent and the remote side tries to reply, but sending the reply fails, a
+ * {@code RemoteReplyException} is thrown, possibly with the cause initialized to the reason of the failure. Typically
+ * this exception is thrown when serialization of the reply failed for some reason. This exception type extends
+ * {@code RemoteExecutionException} and can be treated similarly in most cases.
+ * <p/>
+ * If the request is sent and the remote side sends the reply successfully but there is an error reading the reply
+ * locally, a {@code ReplyException} is thrown. In this case the operation is known to have completed without error
+ * but the actual detailed reply cannot be known. In cases where the reply would be ignored anyway, this exception
+ * type may be safely ignored (possibly logging it for informational purposes). This exception is typically caused
+ * by an {@code ObjectStreamException} thrown while marshalling the reply, though other causes are also possible.
+ * <p/>
+ * If the result of the operation is known to be impossible to ascertain, then an {@code IndeterminateOutcomeException}
+ * is thrown. Possible causes of this condition include (but are not limited to) the connection to the remote side
+ * being unexpectedly broken, or the current thread being interrupted before the reply can be read. In the latter
+ * case, a best effort is automatically made to attempt to cancel the outstanding operation, though there is no
+ * guarantee.
+ * <p/>
+ * If the request cannot be sent, some other {@code IOException} will be thrown with the reason, including (but not limited to)
+ * attempting to call this method on a closed client, or {@code ObjectStreamException}s related to marshalling the
+ * request locally or unmarshalling it remotely. Such an exception indicates that the remote side did not receive
+ * the request.
+ * <p/>
+ * All these exceptions (apart from {@code CancellationException}) extend {@code IOException} which makes it easier
+ * to selectively catch only those exceptions that you need to implement special policy for, while relegating the
+ * rest to common handlers.
*
* @param request the request to send
*
* @return the result of the request
*
- * @throws RemotingException if the request could not be sent
+ * @throws CancellationException if the operation was cancelled asynchronously
* @throws RemoteExecutionException if the remote handler threw an exception
+ * @throws RemoteReplyException if the remote side was unable to send the response
+ * @throws ReplyException if the operation succeeded but the reply cannot be read for some reason
+ * @throws IndeterminateOutcomeException if the result of the operation cannot be ascertained
+ * @throws ObjectStreamException if marshalling or unmarshalling some part of the request failed
+ * @throws IOException if some I/O error occurred while sending the request
*/
- O invoke(I request) throws IOException;
+ O invoke(I request) throws IOException, CancellationException;
/**
- * Send a request asynchronously.
+ * Send a request asynchronously. If the remote side manipulates a stream, it
+ * may use a local policy to assign one or more thread(s) to handle the local end of that stream, or it may
+ * fail with an exception (e.g. if this method is called on a client with no threads to handle streaming).
* <p/>
- * Uses the default invocation policy for handling remote invocations. If the remote side manipulates a stream, it
- * MAY fail with an exception (e.g. if this method is called on a client with no threads to handle streaming).
- * <p/>
- * Returns immediately.
+ * Returns immediately. The returned {@code IoFuture} object can be queried at a later time to determine the result
+ * of the operation. If the operation fails, one of the conditions described on the {@link #invoke(Object) invoke(I)}
+ * method will result. This condition can be determined by reading the status of the {@code IoFuture} object or
+ * by attempting to read the result.
*
* @param request the request to send
*
Added: remoting3/trunk/api/src/main/java/org/jboss/remoting/RemoteReplyException.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/RemoteReplyException.java (rev 0)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/RemoteReplyException.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -0,0 +1,71 @@
+/*
+ * 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;
+
+/**
+ * An exception indicating that a the remote side tried and failed to send a reply message; the remote side would be
+ * aware of this type of failure, so the outcome is determinate; thus it extends {@code RemoteExecutionException}.
+ */
+public class RemoteReplyException extends RemoteExecutionException {
+
+ private static final long serialVersionUID = -8572480018652753441L;
+
+ /**
+ * Constructs a <tt>RemoteReplyException</tt> with no detail message. The cause is not initialized, and may subsequently
+ * be initialized by a call to {@link #initCause(Throwable) initCause}.
+ */
+ public RemoteReplyException() {
+ }
+
+ /**
+ * Constructs a <tt>RemoteReplyException</tt> with the specified detail message. The cause is not initialized, and may
+ * subsequently be initialized by a call to {@link #initCause(Throwable) initCause}.
+ *
+ * @param msg the detail message
+ */
+ public RemoteReplyException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs a <tt>RemoteReplyException</tt> with the specified cause. The detail message is set to:
+ * <pre>
+ * (cause == null ? null : cause.toString())</pre>
+ * (which typically contains the class and detail message of <tt>cause</tt>).
+ *
+ * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
+ */
+ public RemoteReplyException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructs a <tt>RemoteReplyException</tt> with the specified detail message and cause.
+ *
+ * @param msg the detail message
+ * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
+ */
+ public RemoteReplyException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+}
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/RemotingException.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/RemotingException.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/RemotingException.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -3,9 +3,10 @@
import java.io.IOException;
/**
- * A general Remoting exception.
+ * A general Remoting exception. Used as a base class in order to provide constructors which accept any combination
+ * of {@code cause} and {@code message}.
*/
-public class RemotingException extends IOException {
+public abstract class RemotingException extends IOException {
private static final long serialVersionUID = 1540716301579397423L;
@@ -13,7 +14,7 @@
* Constructs a <tt>RemotingException</tt> with no detail message. The cause is not initialized, and may subsequently be
* initialized by a call to {@link #initCause(Throwable) initCause}.
*/
- public RemotingException() {
+ protected RemotingException() {
}
/**
@@ -22,7 +23,7 @@
*
* @param msg the detail message
*/
- public RemotingException(String msg) {
+ protected RemotingException(String msg) {
super(msg);
}
@@ -34,7 +35,7 @@
*
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
*/
- public RemotingException(Throwable cause) {
+ protected RemotingException(Throwable cause) {
initCause(cause);
}
@@ -44,7 +45,7 @@
* @param msg the detail message
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
*/
- public RemotingException(String msg, Throwable cause) {
+ protected RemotingException(String msg, Throwable cause) {
super(msg);
initCause(cause);
}
Deleted: remoting3/trunk/api/src/main/java/org/jboss/remoting/RemotingExceptionCarrier.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/RemotingExceptionCarrier.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/RemotingExceptionCarrier.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -1,27 +0,0 @@
-package org.jboss.remoting;
-
-/**
- * A runtime exception that carries a {@link org.jboss.remoting.RemotingException} as a cause.
- */
-public class RemotingExceptionCarrier extends IOExceptionCarrier {
-
- private static final long serialVersionUID = -1326735788761007331L;
-
- /**
- * Construct a new carrier.
- *
- * @param cause the nested cause
- */
- public RemotingExceptionCarrier(RemotingException cause) {
- super(cause);
- }
-
- /**
- * Get the cause.
- *
- * @return the cause
- */
- public RemotingException getCause() {
- return (RemotingException) super.getCause();
- }
-}
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/RequestContext.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/RequestContext.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/RequestContext.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -4,7 +4,8 @@
import java.io.IOException;
/**
- * The context of a single request.
+ * The context of a single request. A request listener is obligated to call exactly one of the three {@code send} methods
+ * specified in this interface.
*
* @param <O> the reply type
*/
@@ -24,30 +25,38 @@
boolean isCancelled();
/**
- * Send a reply back to the caller.
+ * Send a reply back to the caller. If transmission fails, an {@code IOException} is thrown from this method
+ * and a reply is sent back to the client which will trigger a {@link RemoteReplyException} to be thrown. If the
+ * client connection is interrupted in such a way that the reply cannot reach the client, the client will (eventually)
+ * receive an {@link IndeterminateOutcomeException}.
*
* @param reply the reply to send
* @throws IOException if the transmission failed
- * @throws IllegalStateException if a reply was already sent
+ * @throws IllegalStateException if this or another of the {@code sendXXX()} methods was already invoked for this request
*/
void sendReply(O reply) throws IOException, IllegalStateException;
/**
- * Send a failure message back to the caller.
+ * Send a failure message back to the caller. If the transmission succeeds, the client will receive a
+ * {@link RemoteExecutionException} with the message initialized to {@code msg} and the cause initialized to
+ * {@code cause}. If the transmission fails, an {@code IOException} is thrown from this
+ * method and the client will (eventually) receive an {@link IndeterminateOutcomeException}.
*
* @param msg a message describing the failure, if any (can be {@code null})
* @param cause the failure cause, if any (can be {@code null})
*
* @throws IOException if the transmission failed
- * @throws IllegalStateException if a reply was already sent
+ * @throws IllegalStateException if this or another of the {@code sendXXX()} methods was already invoked for this request
*/
void sendFailure(String msg, Throwable cause) throws IOException, IllegalStateException;
/**
- * Send a cancellation message back to the client.
+ * Send a cancellation message back to the client. If the transmission succeeds, the client result will be an
+ * acknowledgement of cancellation. If the transmission fails, an {@code IOException} is thrown from this
+ * method and the client will (eventually) receive an {@link IndeterminateOutcomeException}.
*
* @throws IOException if the message could not be sent (the client could not be notified about the cancellation)
- * @throws IllegalStateException if a reply was already sent
+ * @throws IllegalStateException if this or another of the {@code sendXXX()} methods was already invoked for this request
*/
void sendCancelled() throws IOException, IllegalStateException;
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/SpiUtils.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/SpiUtils.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/SpiUtils.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -48,7 +48,7 @@
try {
replyHandler.handleException(exception);
} catch (Throwable t) {
- log.error(t, "Failed to properly handle exception");
+ log.debug(t, "Failed to properly handle exception");
}
}
@@ -63,7 +63,7 @@
try {
replyHandler.handleReply(reply);
} catch (Throwable t) {
- log.error(t, "Failed to properly handle reply");
+ log.debug(t, "Failed to properly handle reply");
}
}
@@ -76,7 +76,7 @@
try {
replyHandler.handleCancellation();
} catch (Throwable t) {
- log.error(t, "Failed to properly handle cancellation");
+ log.debug(t, "Failed to properly handle cancellation");
}
}
@@ -90,7 +90,7 @@
try {
handler.notifyCancel(requestContext);
} catch (Throwable t) {
- log.error(t, "Request cancel handler threw an exception when calling notifyCancel()");
+ log.error(t, "Request cancel handler threw an exception");
}
}
@@ -105,7 +105,7 @@
try {
handler.handleClose(closed);
} catch (Throwable t) {
- log.error(t, "Close handler failed unexpectedly");
+ log.error(t, "Close handler threw an exception");
}
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/remote/ReplyHandler.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/remote/ReplyHandler.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/remote/ReplyHandler.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -31,21 +31,22 @@
public interface ReplyHandler {
/**
- * Handle a successful reply.
+ * Handle a successful reply. If the reply could not be forwarded, an exception is thrown.
*
* @param reply the reply
*/
- void handleReply(Object reply);
+ void handleReply(Object reply) throws IOException;
/**
- * Handle an exception.
+ * Handle an exception. If the exception could not be forwarded, a (different) {@code IOException} is thrown.
*
* @param exception an exception which describes the problem
*/
- void handleException(IOException exception);
+ void handleException(IOException exception) throws IOException;
/**
- * Handle a cancellation request.
+ * Handle a cancellation acknowledgement. If the cancellation acknowledgement could not be forwarded, an
+ * exception is thrown.
*/
- void handleCancellation();
+ void handleCancellation() throws IOException;
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientExternalizer.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientExternalizer.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientExternalizer.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -42,10 +42,12 @@
this.endpoint = endpoint;
}
+ @SuppressWarnings({ "unchecked" })
public void writeExternal(final Object o, final ObjectOutput output) throws IOException {
output.writeObject(((ClientImpl)o).getRequestHandlerHandle().getResource());
}
+ @SuppressWarnings({ "unchecked" })
public Object createExternal(final Class<?> aClass, final ObjectInput input, final Creator creator) throws IOException, ClassNotFoundException {
final RequestHandler handler = (RequestHandler) input.readObject();
return new ClientImpl(handler.getHandle(), endpoint.getExecutor());
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -23,7 +23,7 @@
package org.jboss.remoting.core;
import org.jboss.remoting.Client;
-import org.jboss.remoting.RemotingException;
+import org.jboss.remoting.IndeterminateOutcomeException;
import org.jboss.remoting.core.util.QueueExecutor;
import org.jboss.remoting.spi.remote.RequestHandler;
import org.jboss.remoting.spi.remote.ReplyHandler;
@@ -51,7 +51,7 @@
public O invoke(final I request) throws IOException {
if (! isOpen()) {
- throw new RemotingException("Client is not open");
+ throw new IOException("Client is not open");
}
final QueueExecutor executor = new QueueExecutor();
final FutureReplyImpl<O> futureReply = new FutureReplyImpl<O>(executor);
@@ -64,12 +64,21 @@
}
});
executor.runQueue();
- return futureReply.get();
+ try {
+ return futureReply.getInterruptibly();
+ } catch (InterruptedException e) {
+ try {
+ futureReply.cancel();
+ throw new IndeterminateOutcomeException("The current thread was interrupted before the result could be read");
+ } finally {
+ Thread.currentThread().interrupt();
+ }
+ }
}
public IoFuture<O> send(final I request) throws IOException {
if (! isOpen()) {
- throw new RemotingException("Client is not open");
+ throw new IOException("Client is not open");
}
final FutureReplyImpl<O> futureReply = new FutureReplyImpl<O>(executor);
final ReplyHandler replyHandler = futureReply.getReplyHandler();
@@ -78,9 +87,9 @@
return futureReply;
}
- public void sendOneWay(final I request) throws RemotingException {
+ public void sendOneWay(final I request) throws IOException {
if (! isOpen()) {
- throw new RemotingException("Client is not open");
+ throw new IOException("Client is not open");
}
handle.getResource().receiveRequest(request);
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientSourceExternalizer.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientSourceExternalizer.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientSourceExternalizer.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -42,10 +42,12 @@
this.endpoint = endpoint;
}
+ @SuppressWarnings({ "unchecked" })
public void writeExternal(final Object o, final ObjectOutput output) throws IOException {
output.writeObject(((ClientSourceImpl) o).getRequestHandlerSourceHandle().getResource());
}
+ @SuppressWarnings({ "unchecked" })
public Object createExternal(final Class<?> aClass, final ObjectInput input, final Creator creator) throws IOException, ClassNotFoundException {
final RequestHandlerSource handler = (RequestHandlerSource) input.readObject();
return new ClientSourceImpl(handler.getHandle(), endpoint);
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientSourceImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientSourceImpl.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientSourceImpl.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -24,7 +24,6 @@
import org.jboss.remoting.ClientSource;
import org.jboss.remoting.Client;
-import org.jboss.remoting.RemotingException;
import org.jboss.remoting.Endpoint;
import org.jboss.remoting.spi.remote.RequestHandler;
import org.jboss.remoting.spi.remote.RequestHandlerSource;
@@ -53,7 +52,7 @@
public Client<I, O> createClient() throws IOException {
if (! isOpen()) {
- throw new RemotingException("Client source is not open");
+ throw new IOException("Client source is not open");
}
final Handle<RequestHandler> clientHandle = handle.getResource().createRequestHandler();
try {
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandler.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandler.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandler.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -27,12 +27,12 @@
import org.jboss.remoting.spi.remote.ReplyHandler;
import org.jboss.remoting.spi.SpiUtils;
import org.jboss.remoting.spi.AbstractAutoCloseable;
-import org.jboss.remoting.RemotingException;
import org.jboss.remoting.RequestListener;
import org.jboss.remoting.RemoteExecutionException;
import org.jboss.remoting.CloseHandler;
import org.jboss.xnio.log.Logger;
import java.util.concurrent.Executor;
+import java.io.IOException;
/**
*
@@ -40,14 +40,12 @@
public final class LocalRequestHandler<I, O> extends AbstractAutoCloseable<RequestHandler> implements RequestHandler {
private final RequestListener<I, O> requestListener;
- private final Executor executor;
private final ClientContextImpl clientContext;
private static final Logger log = Logger.getLogger(LocalRequestHandler.class);
private LocalRequestHandler(final Executor executor, final RequestListener<I, O> requestListener, final ClientContextImpl clientContext) {
super(executor);
- this.executor = executor;
this.requestListener = requestListener;
this.clientContext = clientContext;
}
@@ -62,7 +60,7 @@
public void receiveRequest(final Object request) {
final RequestContextImpl<O> context = new RequestContextImpl<O>(clientContext);
- executor.execute(new Runnable() {
+ context.execute(new Runnable() {
@SuppressWarnings({ "unchecked" })
public void run() {
try {
@@ -76,7 +74,7 @@
public RemoteRequestContext receiveRequest(final Object request, final ReplyHandler replyHandler) {
final RequestContextImpl<O> context = new RequestContextImpl<O>(replyHandler, clientContext);
- executor.execute(new Runnable() {
+ context.execute(new Runnable() {
@SuppressWarnings({ "unchecked" })
public void run() {
try {
@@ -95,7 +93,7 @@
};
}
- void open() throws RemotingException {
+ void open() throws IOException {
try {
requestListener.handleClientOpen(clientContext);
addCloseHandler(new CloseHandler<RequestHandler>() {
@@ -108,7 +106,9 @@
}
});
} catch (Throwable t) {
- throw new RemotingException("Failed to open client context", t);
+ final IOException ioe = new IOException("Failed to open client context");
+ ioe.initCause(t);
+ throw ioe;
}
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandlerSource.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandlerSource.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/LocalRequestHandlerSource.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -27,7 +27,6 @@
import org.jboss.remoting.spi.remote.Handle;
import org.jboss.remoting.spi.AbstractAutoCloseable;
import org.jboss.remoting.RequestListener;
-import org.jboss.remoting.RemotingException;
import org.jboss.remoting.CloseHandler;
import org.jboss.xnio.log.Logger;
import java.util.concurrent.Executor;
@@ -57,11 +56,11 @@
localRequestHandler.open();
return localRequestHandler.getHandle();
} else {
- throw new RemotingException("LocalRequestHandlerSource is closed");
+ throw new IOException("LocalRequestHandlerSource is closed");
}
}
- void open() throws RemotingException {
+ void open() throws IOException {
try {
requestListener.handleServiceOpen(serviceContext);
addCloseHandler(new CloseHandler<RequestHandlerSource>() {
@@ -74,7 +73,9 @@
}
});
} catch (Throwable t) {
- throw new RemotingException("Failed to open client context", t);
+ final IOException ioe = new IOException("Failed to open client context");
+ ioe.initCause(t);
+ throw ioe;
}
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestContextImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestContextImpl.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestContextImpl.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -24,15 +24,17 @@
import org.jboss.remoting.RequestContext;
import org.jboss.remoting.ClientContext;
-import org.jboss.remoting.RemotingException;
import org.jboss.remoting.RequestCancelHandler;
import org.jboss.remoting.RemoteExecutionException;
-import org.jboss.remoting.core.util.TaggingExecutor;
+import org.jboss.remoting.RemoteReplyException;
+import org.jboss.remoting.IndeterminateOutcomeException;
import org.jboss.remoting.spi.remote.ReplyHandler;
import org.jboss.remoting.spi.SpiUtils;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.Set;
import java.util.HashSet;
+import java.io.IOException;
/**
*
@@ -43,21 +45,26 @@
private final Object cancelLock = new Object();
private final ReplyHandler replyHandler;
private final ClientContextImpl clientContext;
+ private final AtomicInteger taskCount = new AtomicInteger();
- private final AtomicBoolean cancelled = new AtomicBoolean();
// @protectedby cancelLock
+ private boolean cancelled;
+ // @protectedby cancelLock
private Set<RequestCancelHandler<O>> cancelHandlers;
- private final TaggingExecutor executor;
+ private final RequestListenerExecutor executor;
RequestContextImpl(final ReplyHandler replyHandler, final ClientContextImpl clientContext) {
this.replyHandler = replyHandler;
this.clientContext = clientContext;
- executor = new TaggingExecutor(clientContext.getExecutor());
+ //noinspection ThisEscapedInObjectConstruction
+ executor = new RequestListenerExecutor(clientContext.getExecutor(), this);
}
+ // todo - used by one-way requests... :|
RequestContextImpl(final ClientContextImpl clientContext) {
this.clientContext = clientContext;
- executor = new TaggingExecutor(clientContext.getExecutor());
+ //noinspection ThisEscapedInObjectConstruction
+ executor = new RequestListenerExecutor(clientContext.getExecutor(), this);
replyHandler = null;
}
@@ -66,34 +73,42 @@
}
public boolean isCancelled() {
- return cancelled.get();
+ synchronized (cancelLock) {
+ return cancelled;
+ }
}
- public void sendReply(final O reply) throws RemotingException, IllegalStateException {
+ public void sendReply(final O reply) throws IOException, IllegalStateException {
if (! closed.getAndSet(true)) {
- if (replyHandler != null) {
+ if (replyHandler != null) try {
replyHandler.handleReply(reply);
- }
+ } catch (IOException e) {
+ SpiUtils.safeHandleException(replyHandler, new RemoteReplyException("Remote reply failed", e));
+ throw e;
+ } else throw new IllegalStateException("Cannot send a reply to a one-way invocation");
} else {
throw new IllegalStateException("Reply already sent");
}
}
- public void sendFailure(final String msg, final Throwable cause) throws RemotingException, IllegalStateException {
+ public void sendFailure(final String msg, final Throwable cause) throws IOException, IllegalStateException {
if (! closed.getAndSet(true)) {
if (replyHandler != null) {
replyHandler.handleException(new RemoteExecutionException(msg, cause));
- }
+ } else throw new IllegalStateException("Cannot send a reply to a one-way invocation");
} else {
throw new IllegalStateException("Reply already sent");
}
}
- public void sendCancelled() throws RemotingException, IllegalStateException {
+ public void sendCancelled() throws IOException, IllegalStateException {
if (! closed.getAndSet(true)) {
- if (replyHandler != null) {
+ if (replyHandler != null) try {
replyHandler.handleCancellation();
- }
+ } catch (IOException e) {
+ // this is highly unlikely to succeed
+ SpiUtils.safeHandleException(replyHandler, new RemoteReplyException("Remote cancellation acknowledgement failed", e));
+ } else throw new IllegalStateException("Cannot send a reply to a one-way invocation");
} else {
throw new IllegalStateException("Reply already sent");
}
@@ -101,7 +116,7 @@
public void addCancelHandler(final RequestCancelHandler<O> handler) {
synchronized (cancelLock) {
- if (cancelled.get()) {
+ if (cancelled) {
SpiUtils.safeNotifyCancellation(handler, this);
} else {
if (cancelHandlers == null) {
@@ -117,8 +132,9 @@
}
protected void cancel() {
- if (! cancelled.getAndSet(true)) {
- synchronized (cancelLock) {
+ synchronized (cancelLock) {
+ if (! cancelled) {
+ cancelled = true;
if (cancelHandlers != null) {
for (final RequestCancelHandler<O> handler : cancelHandlers) {
executor.execute(new Runnable() {
@@ -129,8 +145,19 @@
}
cancelHandlers = null;
}
+ executor.interruptAll();
}
- executor.interruptAll();
}
}
+
+ void startTask() {
+ taskCount.incrementAndGet();
+ }
+
+ void finishTask() {
+ if (taskCount.decrementAndGet() == 0 && closed.getAndSet(true)) {
+ // no response sent! send back IndeterminateOutcomeException
+ SpiUtils.safeHandleException(replyHandler, new IndeterminateOutcomeException("No reply was sent by the request listener"));
+ }
+ }
}
Copied: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestListenerExecutor.java (from rev 4601, remoting3/trunk/core/src/main/java/org/jboss/remoting/core/util/TaggingExecutor.java)
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestListenerExecutor.java (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestListenerExecutor.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -0,0 +1,80 @@
+/*
+ * 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.core;
+
+import java.util.concurrent.Executor;
+import java.util.Set;
+import org.jboss.remoting.util.CollectionUtil;
+
+/**
+ *
+ */
+public final class RequestListenerExecutor implements Executor {
+
+ private final Set<Task> tasks = CollectionUtil.synchronizedHashSet();
+ private final Executor executor;
+ private final RequestContextImpl requestContext;
+
+ public RequestListenerExecutor(final Executor executor, final RequestContextImpl context) {
+ this.executor = executor;
+ requestContext = context;
+ }
+
+ private final class Task implements Runnable {
+ private volatile Thread thread;
+ private final Runnable runnable;
+
+ private Task(final Runnable runnable) {
+ this.runnable = runnable;
+ }
+
+ public void run() {
+ requestContext.startTask();
+ thread = Thread.currentThread();
+ tasks.add(this);
+ try {
+ runnable.run();
+ } finally {
+ requestContext.finishTask();
+ tasks.remove(this);
+ thread = null;
+ }
+ }
+ }
+
+ public void execute(final Runnable command) {
+ executor.execute(new Task(command));
+ }
+
+ public void interruptAll() {
+ synchronized (tasks) {
+ final Thread currentThread = Thread.currentThread();
+ for (Task task : tasks) {
+ final Thread thread = task.thread;
+ if (thread != null && thread != currentThread) {
+ thread.interrupt();
+ }
+ }
+ }
+ }
+}
Deleted: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/util/TaggingExecutor.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/util/TaggingExecutor.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/util/TaggingExecutor.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -1,75 +0,0 @@
-/*
- * 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.core.util;
-
-import java.util.concurrent.Executor;
-import java.util.Set;
-import org.jboss.remoting.util.CollectionUtil;
-
-/**
- *
- */
-public final class TaggingExecutor implements Executor {
-
- private final Set<Task> tasks = CollectionUtil.synchronizedHashSet();
- private final Executor executor;
-
- public TaggingExecutor(final Executor executor) {
- this.executor = executor;
- }
-
- private final class Task implements Runnable {
- private volatile Thread thread;
- private final Runnable runnable;
-
- private Task(final Runnable runnable) {
- this.runnable = runnable;
- }
-
- public void run() {
- thread = Thread.currentThread();
- tasks.add(this);
- try {
- runnable.run();
- } finally {
- tasks.remove(this);
- thread = null;
- }
- }
- }
-
- public void execute(final Runnable command) {
- executor.execute(new Task(command));
- }
-
- public void interruptAll() {
- synchronized (tasks) {
- for (Task task : tasks) {
- final Thread thread = task.thread;
- if (thread != null) {
- thread.interrupt();
- }
- }
- }
- }
-}
Modified: remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexHandler.java
===================================================================
--- remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexHandler.java 2008-10-21 05:35:10 UTC (rev 4606)
+++ remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexHandler.java 2008-10-22 22:01:55 UTC (rev 4607)
@@ -49,6 +49,8 @@
import org.jboss.remoting.SimpleCloseable;
import org.jboss.remoting.RemoteExecutionException;
import org.jboss.remoting.IndeterminateOutcomeException;
+import org.jboss.remoting.ReplyException;
+import org.jboss.remoting.RemoteReplyException;
import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Unmarshaller;
import org.jboss.marshalling.ByteOutput;
@@ -66,6 +68,7 @@
import java.nio.BufferUnderflowException;
import java.io.IOException;
import java.io.InvalidClassException;
+import java.io.InterruptedIOException;
/**
* Protocol handler for the basic message-oriented Remoting protocol.
@@ -257,7 +260,7 @@
IoUtils.safeClose(unmarshaller);
}
} catch (IOException ex) {
- log.trace("Failed to unmarshal a reply (%s), sending a ReplyException");
+ log.trace("Failed to unmarshal a reply (%s), sending a ReplyException", ex);
// todo
SpiUtils.safeHandleException(replyHandler, ex);
break;
@@ -276,8 +279,10 @@
case CANCEL_ACK: {
final int requestId = buffer.getInt();
final ReplyHandler replyHandler = remoteRequests.get(requestId);
- if (replyHandler != null) {
+ if (replyHandler != null) try {
replyHandler.handleCancellation();
+ } catch (IOException e) {
+ log.trace("Failed to forward a cancellation acknowledgement (%s)", e);
}
break;
}
@@ -458,7 +463,7 @@
this.allocator = allocator;
}
- public void handleReply(final Object reply) {
+ public void handleReply(final Object reply) throws IOException {
ByteBuffer buffer = allocator.allocate();
buffer.put((byte) MessageType.REPLY.getId());
buffer.putInt(requestId);
@@ -479,15 +484,13 @@
} finally {
IoUtils.safeClose(marshaller);
}
- } catch (IOException e) {
- log.error(e, "Failed to send a reply to the remote side");
} catch (InterruptedException e) {
- log.error(e, "Reply handler thread interrupted before a reply could be sent");
Thread.currentThread().interrupt();
+ throw new InterruptedIOException("Reply handler thread interrupted before a reply could be sent");
}
}
- public void handleException(final IOException exception) {
+ public void handleException(final IOException exception) throws IOException {
ByteBuffer buffer = allocator.allocate();
buffer.put((byte) MessageType.REQUEST_FAILED.getId());
buffer.putInt(requestId);
@@ -508,15 +511,13 @@
} finally {
IoUtils.safeClose(marshaller);
}
- } catch (IOException e) {
- log.error(e, "Failed to send an exception to the remote side");
} catch (InterruptedException e) {
- log.error(e, "Reply handler thread interrupted before an exception could be sent");
Thread.currentThread().interrupt();
+ throw new InterruptedIOException("Reply handler thread interrupted before an exception could be sent");
}
}
- public void handleCancellation() {
+ public void handleCancellation() throws InterruptedIOException {
final ByteBuffer buffer = allocator.allocate();
buffer.put((byte) MessageType.CANCEL_ACK.getId());
buffer.putInt(requestId);
@@ -524,8 +525,8 @@
try {
registerWriter(channel, new SimpleWriteHandler(allocator, buffer));
} catch (InterruptedException e) {
- // todo log
Thread.currentThread().interrupt();
+ throw new InterruptedIOException("Reply handler thread interrupted before cancellation could be sent");
}
}
}
16 years, 2 months
JBoss Remoting SVN: r4606 - in remoting3/trunk: protocol/basic/src/test/java/org/jboss/remoting/protocol/basic and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-10-21 01:35:10 -0400 (Tue, 21 Oct 2008)
New Revision: 4606
Modified:
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java
Log:
Minor cleanups
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java 2008-10-21 05:32:25 UTC (rev 4605)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/ClientImpl.java 2008-10-21 05:35:10 UTC (rev 4606)
@@ -30,12 +30,8 @@
import org.jboss.remoting.spi.remote.RemoteRequestContext;
import org.jboss.remoting.spi.remote.Handle;
import org.jboss.xnio.IoFuture;
-import org.jboss.marshalling.Externalizer;
-import org.jboss.marshalling.Creator;
import java.util.concurrent.Executor;
import java.io.IOException;
-import java.io.ObjectOutput;
-import java.io.ObjectInput;
/**
*
Modified: remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java
===================================================================
--- remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java 2008-10-21 05:32:25 UTC (rev 4605)
+++ remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java 2008-10-21 05:35:10 UTC (rev 4606)
@@ -45,6 +45,7 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ExecutorService;
import java.io.IOException;
/**
@@ -56,7 +57,7 @@
}
public static void testConnect() throws Throwable {
- Executor executor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ ExecutorService executor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
Xnio xnio = NioXnio.create(executor, 2, 2, 2);
final BasicConfiguration configuration = new BasicConfiguration();
configuration.setExecutor(executor);
@@ -103,6 +104,6 @@
final Handle<RequestHandler> clientHandlerHandle = BasicProtocol.createClient(futureChannel.get(), configuration);
final Client<Object,Object> client = endpoint.createClient(clientHandlerHandle.getResource());
System.out.println("Reply is:" + client.invoke("GORBA!"));
-
+
}
}
16 years, 2 months
JBoss Remoting SVN: r4605 - in remoting3/trunk: protocol/basic/src/main/java/org/jboss/remoting/protocol/basic and 7 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-10-21 01:32:25 -0400 (Tue, 21 Oct 2008)
New Revision: 4605
Added:
remoting3/trunk/protocol/basic/src/test/java/org/
remoting3/trunk/protocol/basic/src/test/java/org/jboss/
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java
Modified:
remoting3/trunk/build.xml
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java
remoting3/trunk/testing-support/src/main/resources/testing.policy
Log:
Add substatial logging, get test working (sort of)
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2008-10-21 04:56:10 UTC (rev 4604)
+++ remoting3/trunk/build.xml 2008-10-21 05:32:25 UTC (rev 4605)
@@ -922,6 +922,7 @@
<path refid="api.classpath"/>
<path refid="core.classpath"/>
<path refid="protocol.basic.classpath"/>
+ <path refid="standalone.classpath"/>
<path refid="util.classpath"/>
<path refid="testing-support.classpath"/>
<pathelement location="${lib.junit.local}"/>
@@ -944,6 +945,7 @@
<sysproperty key="ant.library.dir" value="${ant.home}/lib"/>
<sysproperty key="lib.junit.local" value="${lib.junit.local}"/>
<sysproperty key="lib.marshalling-api.local" value="${lib.marshalling-api.local}"/>
+ <sysproperty key="lib.river.local" value="${lib.river.local}"/>
<sysproperty key="lib.xnio-api.local" value="${lib.xnio-api.local}"/>
<sysproperty key="lib.xnio-nio.local" value="${lib.xnio-nio.local}"/>
<jvmarg line="${test.jvmargs}"/>
@@ -952,6 +954,7 @@
<path refid="api.classpath"/>
<path refid="core.classpath"/>
<path refid="protocol.basic.classpath"/>
+ <path refid="standalone.classpath"/>
<path refid="testing-support.classpath"/>
<path refid="util.classpath"/>
<pathelement location="protocol/basic/target/test/classes"/>
@@ -970,7 +973,7 @@
</junit>
</target>
- <target name="protocol.basic.test" depends="lib.xnio-nio,api,core,protocol.basic,testing-support,util,protocol.basic.test.compile">
+ <target name="protocol.basic.test" depends="lib.river,lib.xnio-nio,api,core,protocol.basic,standalone,testing-support,util,protocol.basic.test.compile">
<antcall inheritall="true" inheritrefs="true" target="protocol.basic.test.pseudotarget">
<param name="extension" value=".txt"/>
<param name="message" value="Running with no security manager"/>
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java 2008-10-21 04:56:10 UTC (rev 4604)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java 2008-10-21 05:32:25 UTC (rev 4605)
@@ -29,6 +29,7 @@
import org.jboss.marshalling.Unmarshaller;
import org.jboss.xnio.channels.StreamChannel;
import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
import org.jboss.remoting.spi.remote.ReplyHandler;
import org.jboss.remoting.spi.SpiUtils;
import org.jboss.remoting.RemoteExecutionException;
@@ -40,6 +41,8 @@
*/
final class BasicHandlerReplyConsumer implements Runnable {
+ private static final Logger log = Logger.getLogger(BasicHandlerReplyConsumer.class);
+
private final AtomicInteger replySequence;
private final Unmarshaller unmarshaller;
private final StreamChannel streamChannel;
@@ -124,7 +127,7 @@
}
}
} catch (Exception e) {
- // todo log it
+ log.error(e, "Error receiving reply");
} finally {
IoUtils.safeClose(streamChannel);
reqLock.lock();
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java 2008-10-21 04:56:10 UTC (rev 4604)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java 2008-10-21 05:32:25 UTC (rev 4605)
@@ -30,6 +30,7 @@
import org.jboss.marshalling.Marshaller;
import org.jboss.xnio.channels.StreamChannel;
import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.Executor;
@@ -41,6 +42,8 @@
*/
final class BasicRequestHandler extends AbstractAutoCloseable<RequestHandler> implements RequestHandler {
+ private static final Logger log = Logger.getLogger(BasicRequestHandler.class);
+
private final AtomicInteger requestSequence;
private final Lock reqLock;
private final Marshaller marshaller;
@@ -63,7 +66,7 @@
marshaller.writeObject(request);
marshaller.flush();
} catch (IOException e) {
- // todo log it
+ log.error(e, "Error receiving request");
IoUtils.safeClose(this);
} finally {
reqLock.unlock();
@@ -86,7 +89,7 @@
marshaller.writeInt(id);
marshaller.flush();
} catch (IOException e) {
- // todo log it
+ log.error(e, "Error writing cancel request");
IoUtils.safeClose(BasicRequestHandler.this);
}
}
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java 2008-10-21 04:56:10 UTC (rev 4604)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java 2008-10-21 05:32:25 UTC (rev 4605)
@@ -26,6 +26,7 @@
import org.jboss.marshalling.Marshaller;
import org.jboss.xnio.channels.StreamChannel;
import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
import org.jboss.remoting.spi.remote.RequestHandler;
import org.jboss.remoting.spi.remote.Handle;
@@ -34,6 +35,8 @@
*/
final class BasicServerReplyTransmitter implements Runnable {
+ private static final Logger log = Logger.getLogger(BasicServerReplyTransmitter.class);
+
private final BlockingQueue<FutureBasicReply> replyQueue;
private final Marshaller marshaller;
private final StreamChannel streamChannel;
@@ -49,7 +52,7 @@
public void run() {
try {
for (;;) {
- final FutureBasicReply futureBasicReply = replyQueue.remove();
+ final FutureBasicReply futureBasicReply = replyQueue.take();
OUT: for (;;) switch (futureBasicReply.awaitInterruptibly()) {
case DONE: {
marshaller.write(1);
@@ -77,9 +80,9 @@
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
- // todo log it
+ log.trace(e, "Interrupted");
} catch (Exception e) {
- // todo log it
+ log.error(e, "Error in reply transmitter");
} finally {
IoUtils.safeClose(streamChannel);
IoUtils.safeClose(requestHandlerHandle);
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java 2008-10-21 04:56:10 UTC (rev 4604)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java 2008-10-21 05:32:25 UTC (rev 4605)
@@ -29,6 +29,7 @@
import org.jboss.remoting.spi.remote.ReplyHandler;
import org.jboss.xnio.channels.StreamChannel;
import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
import java.util.concurrent.BlockingQueue;
import java.io.IOException;
@@ -37,6 +38,8 @@
*/
final class BasicServerRequestConsumer implements Runnable {
+ private static final Logger log = Logger.getLogger(BasicServerRequestConsumer.class);
+
private final Unmarshaller unmarshaller;
private final RequestHandler requestHandler;
private final BlockingQueue<FutureBasicReply> replyQueue;
@@ -112,7 +115,7 @@
}
}
} catch (Exception e) {
- // todo log it
+ log.error(e, "Connection failed");
} finally {
IoUtils.safeClose(streamChannel);
IoUtils.safeClose(requestHandlerHandle);
Added: remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java
===================================================================
--- remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java 2008-10-21 05:32:25 UTC (rev 4605)
@@ -0,0 +1,108 @@
+/*
+ * 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.protocol.basic;
+
+import junit.framework.TestCase;
+import org.jboss.xnio.Xnio;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.IoHandler;
+import org.jboss.xnio.ChannelSource;
+import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.nio.NioXnio;
+import org.jboss.xnio.channels.StreamChannel;
+import org.jboss.river.RiverMarshallerFactory;
+import org.jboss.remoting.Endpoint;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.AbstractRequestListener;
+import org.jboss.remoting.RequestContext;
+import org.jboss.remoting.RemoteExecutionException;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.test.support.LoggingHelper;
+import org.jboss.remoting.spi.remote.RequestHandler;
+import org.jboss.remoting.spi.remote.Handle;
+import org.jboss.marshalling.Configuration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.io.IOException;
+
+/**
+ *
+ */
+public final class BasicTestCase extends TestCase {
+ static {
+ LoggingHelper.init();
+ }
+
+ public static void testConnect() throws Throwable {
+ Executor executor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ Xnio xnio = NioXnio.create(executor, 2, 2, 2);
+ final BasicConfiguration configuration = new BasicConfiguration();
+ configuration.setExecutor(executor);
+ configuration.setMarshallerFactory(new RiverMarshallerFactory());
+ final Configuration marshallingConfiguration = new Configuration();
+ configuration.setMarshallingConfiguration(marshallingConfiguration);
+ final Endpoint endpoint = Remoting.createEndpoint("test");
+ final Handle<RequestHandler> requestHandlerHandle = endpoint.createRequestHandler(new AbstractRequestListener<Object, Object>() {
+ public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
+ System.out.println("Got a request! " + request.toString());
+ try {
+ context.sendReply("GOOMBA");
+ } catch (IOException e) {
+ try {
+ context.sendFailure("Failed", e);
+ } catch (IOException e1) {
+ // buh
+ }
+ }
+ }
+ });
+ final ChannelSource<StreamChannel> channelSource = xnio.createPipeServer(executor, IoUtils.singletonHandlerFactory(new IoHandler<StreamChannel>() {
+ public void handleOpened(final StreamChannel channel) {
+ try {
+ System.out.println("Opening channel");
+ BasicProtocol.createServer(requestHandlerHandle, channel, configuration);
+ } catch (IOException e) {
+ e.printStackTrace();
+ IoUtils.safeClose(channel);
+ }
+ }
+
+ public void handleReadable(final StreamChannel channel) {
+ }
+
+ public void handleWritable(final StreamChannel channel) {
+ }
+
+ public void handleClosed(final StreamChannel channel) {
+ System.out.println("Closing channel");
+ }
+ }));
+ final IoFuture<StreamChannel> futureChannel = channelSource.open(IoUtils.nullHandler());
+ final Handle<RequestHandler> clientHandlerHandle = BasicProtocol.createClient(futureChannel.get(), configuration);
+ final Client<Object,Object> client = endpoint.createClient(clientHandlerHandle.getResource());
+ System.out.println("Reply is:" + client.invoke("GORBA!"));
+
+ }
+}
Modified: remoting3/trunk/testing-support/src/main/resources/testing.policy
===================================================================
--- remoting3/trunk/testing-support/src/main/resources/testing.policy 2008-10-21 04:56:10 UTC (rev 4604)
+++ remoting3/trunk/testing-support/src/main/resources/testing.policy 2008-10-21 05:32:25 UTC (rev 4605)
@@ -17,6 +17,12 @@
permission java.net.SocketPermission "*:*", "accept, connect, resolve";
};
+grant codeBase "file:${build.home}/protocol/multiplex/target/test/classes/-"
+{
+ permission java.lang.RuntimePermission "modifyThread"; // for executor control
+ permission java.net.SocketPermission "*:*", "accept, connect, resolve";
+};
+
// Permissions for Remoting itself
grant codeBase "file:${build.home}/api/target/main/classes/-"
@@ -71,3 +77,8 @@
{
permission java.security.AllPermission;
};
+
+grant codeBase "file:${lib.river.local}"
+{
+ permission java.security.AllPermission;
+};
16 years, 2 months
JBoss Remoting SVN: r4604 - in remoting3/trunk: protocol and 10 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-10-21 00:56:10 -0400 (Tue, 21 Oct 2008)
New Revision: 4604
Added:
remoting3/trunk/protocol/basic/
remoting3/trunk/protocol/basic/src/
remoting3/trunk/protocol/basic/src/main/
remoting3/trunk/protocol/basic/src/main/java/
remoting3/trunk/protocol/basic/src/main/java/org/
remoting3/trunk/protocol/basic/src/main/java/org/jboss/
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicConfiguration.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicProtocol.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/FutureBasicReply.java
remoting3/trunk/protocol/basic/src/test/
remoting3/trunk/protocol/basic/src/test/java/
Modified:
remoting3/trunk/build.xml
Log:
Cleanup; add *really* basic protocol
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2008-10-21 02:44:31 UTC (rev 4603)
+++ remoting3/trunk/build.xml 2008-10-21 04:56:10 UTC (rev 4604)
@@ -761,7 +761,6 @@
<compilerarg value="-Xlint:unchecked"/>
<classpath>
<path refid="api.classpath"/>
- <!-- TODO: marshallers should be moved to their own module -->
<path refid="core.classpath"/>
<path refid="util.classpath"/>
<pathelement location="${lib.marshalling-api.local}"/>
@@ -866,7 +865,135 @@
</path>
</target>
+ <!-- protocol.basic module -->
+ <target name="protocol.basic.compile.depcheck">
+ <mkdir dir="protocol/basic/target/main"/>
+ <uptodate property="protocol/basic.compile.uptodate" targetfile="protocol/basic/target/main/.lastcompile">
+ <srcfiles dir="protocol/basic/src/main/java">
+ <include name="**/"/>
+ <include name="**/*.java"/>
+ <exclude name="**/.*"/>
+ </srcfiles>
+ </uptodate>
+ </target>
+
+ <target name="protocol.basic.compile" depends="protocol.basic.compile.depcheck" unless="protocol.basic.compile.uptodate">
+ <mkdir dir="protocol/basic/target/main/classes"/>
+ <javac
+ source="${javac.source}"
+ target="${javac.target}"
+ srcdir="protocol/basic/src/main/java"
+ destdir="protocol/basic/target/main/classes"
+ debug="true">
+ <compilerarg value="-Xlint:unchecked"/>
+ <classpath>
+ <path refid="api.classpath"/>
+ <path refid="core.classpath"/>
+ <path refid="util.classpath"/>
+ <pathelement location="${lib.marshalling-api.local}"/>
+ <pathelement location="${lib.xnio-api.local}"/>
+ </classpath>
+ </javac>
+ <touch file="protocol/basic/target/main/.lastcompile" verbose="false"/>
+ </target>
+
+ <target name="protocol.basic.test.compile.depcheck">
+ <mkdir dir="protocol/basic/target/test"/>
+ <uptodate property="protocol.basic.compile.uptodate" targetfile="protocol/basic/target/test/.lastcompile">
+ <srcfiles dir="protocol/basic/src/test/java">
+ <include name="**/"/>
+ <include name="**/*.java"/>
+ <exclude name="**/.*"/>
+ </srcfiles>
+ </uptodate>
+ </target>
+
+ <target name="protocol.basic.test.compile" depends="lib.junit,protocol.basic.compile,protocol.basic.test.compile.depcheck" unless="protocol.basic.test.compile.uptodate">
+ <mkdir dir="protocol/basic/target/test/classes"/>
+ <javac
+ source="${javac.source}"
+ target="${javac.target}"
+ srcdir="protocol/basic/src/test/java"
+ destdir="protocol/basic/target/test/classes"
+ debug="true">
+ <compilerarg value="-Xlint:unchecked"/>
+ <classpath>
+ <path refid="api.classpath"/>
+ <path refid="core.classpath"/>
+ <path refid="protocol.basic.classpath"/>
+ <path refid="util.classpath"/>
+ <path refid="testing-support.classpath"/>
+ <pathelement location="${lib.junit.local}"/>
+ <pathelement location="${lib.marshalling-api.local}"/>
+ <pathelement location="${lib.river.local}"/>
+ <pathelement location="${lib.xnio-api.local}"/>
+ <pathelement location="${lib.xnio-nio.local}"/>
+ </classpath>
+ </javac>
+ <touch file="protocol/basic/target/test/.lastcompile" verbose="false"/>
+ </target>
+
+ <target name="protocol.basic.test.pseudotarget">
+ <echo message="============================================="/>
+ <echo message="${message}"/>
+ <echo message="============================================="/>
+ <mkdir dir="protocol/basic/target/test-results"/>
+ <junit printsummary="true" fork="yes" includeantruntime="true">
+ <sysproperty key="build.home" value="${basedir}"/>
+ <sysproperty key="ant.library.dir" value="${ant.home}/lib"/>
+ <sysproperty key="lib.junit.local" value="${lib.junit.local}"/>
+ <sysproperty key="lib.marshalling-api.local" value="${lib.marshalling-api.local}"/>
+ <sysproperty key="lib.xnio-api.local" value="${lib.xnio-api.local}"/>
+ <sysproperty key="lib.xnio-nio.local" value="${lib.xnio-nio.local}"/>
+ <jvmarg line="${test.jvmargs}"/>
+ <formatter type="plain" extension="${extension}"/>
+ <classpath>
+ <path refid="api.classpath"/>
+ <path refid="core.classpath"/>
+ <path refid="protocol.basic.classpath"/>
+ <path refid="testing-support.classpath"/>
+ <path refid="util.classpath"/>
+ <pathelement location="protocol/basic/target/test/classes"/>
+ <pathelement location="${lib.junit.local}"/>
+ <pathelement location="${lib.marshalling-api.local}"/>
+ <pathelement location="${lib.river.local}"/>
+ <pathelement location="${lib.xnio-api.local}"/>
+ <pathelement location="${lib.xnio-nio.local}"/>
+ </classpath>
+ <batchtest fork="yes" todir="protocol/basic/target/test-results"
+ haltonfailure="no">
+ <fileset dir="protocol/basic/target/test/classes">
+ <include name="**/*TestCase.class"/>
+ </fileset>
+ </batchtest>
+ </junit>
+ </target>
+
+ <target name="protocol.basic.test" depends="lib.xnio-nio,api,core,protocol.basic,testing-support,util,protocol.basic.test.compile">
+ <antcall inheritall="true" inheritrefs="true" target="protocol.basic.test.pseudotarget">
+ <param name="extension" value=".txt"/>
+ <param name="message" value="Running with no security manager"/>
+ <param name="test.jvmargs" value="-Ddummy=dummy"/>
+ </antcall>
+ <antcall inheritall="true" inheritrefs="true" target="protocol.basic.test.pseudotarget">
+ <param name="extension" value="-security.txt"/>
+ <param name="message" value="Running with security manager"/>
+ <param name="test.jvmargs" value="-Djava.security.manager=org.jboss.remoting.test.support.LoggingSecurityManager -Djava.security.policy=${basedir}/testing-support/src/main/resources/testing.policy -Dsecurity.debug=policy"/>
+ </antcall>
+ </target>
+
+ <target name="protocol.basic.clean">
+ <delete dir="protocol/basic/target"/>
+ </target>
+
+ <target name="protocol.basic" description="Build the protocol.basic module" depends="lib.xnio-api,api,core,util,protocol.basic.compile">
+ <path id="protocol.basic.classpath">
+ <pathelement location="protocol/basic/target/main/classes"/>
+ </path>
+ </target>
+
+
<!-- samples module -->
<target name="samples.compile.depcheck">
@@ -1173,6 +1300,7 @@
debug="true">
<compilerarg value="-Xlint:unchecked"/>
<classpath>
+ <pathelement location="${lib.xnio-api.local}"/>
</classpath>
</javac>
<touch file="util/target/main/.lastcompile" verbose="false"/>
@@ -1182,7 +1310,7 @@
<delete dir="util/target"/>
</target>
- <target name="util" description="Build the utilities module" depends="util.compile">
+ <target name="util" description="Build the utilities module" depends="lib.xnio-api,util.compile">
<path id="util.classpath">
<pathelement location="util/target/main/classes"/>
</path>
@@ -1222,7 +1350,7 @@
<path id="version.classpath">
<pathelement location="version/target/main/classes"/>
</path>
- <java classpathref="version.classpath" classname="org.jboss.cx.remoting.version.Version" outputproperty="version"/>
+ <java classpathref="version.classpath" classname="org.jboss.remoting.version.Version" outputproperty="version"/>
<property name="version" value="UNKNOWN"/>
</target>
@@ -1341,9 +1469,9 @@
<!-- core -->
- <target name="all-core" description="Build all core targets" depends="api,compat,core,mc-deployers,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,tools,util"/>
- <target name="clean-core" description="Clean all core targets" depends="api.clean,compat.clean,core.clean,mc-deployers.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,tools.clean,util.clean"/>
<!-- http -->
@@ -1365,6 +1493,6 @@
<target name="clean" description="Clean out all build files" depends="clean-core,clean-http,version.clean,srp.clean"/>
- <target name="test" description="Run all tests" depends="api.test,core.test,protocol.multiplex.test"/>
+ <target name="test" description="Run all tests" depends="api.test,core.test,protocol.basic.test,protocol.multiplex.test"/>
</project>
Property changes on: remoting3/trunk/protocol/basic
___________________________________________________________________
Name: svn:ignore
+ target
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicConfiguration.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicConfiguration.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicConfiguration.java 2008-10-21 04:56:10 UTC (rev 4604)
@@ -0,0 +1,90 @@
+/*
+ * 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.protocol.basic;
+
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.Configuration;
+import org.jboss.xnio.BufferAllocator;
+import org.jboss.remoting.spi.stream.StreamDetector;
+import java.util.concurrent.Executor;
+import java.nio.ByteBuffer;
+
+/**
+ *
+ */
+public final class BasicConfiguration {
+ private MarshallerFactory marshallerFactory;
+ private Configuration marshallingConfiguration;
+ private int linkMetric;
+ private Executor executor;
+ private BufferAllocator<ByteBuffer> allocator;
+ private StreamDetector streamDetector;
+
+ public MarshallerFactory getMarshallerFactory() {
+ return marshallerFactory;
+ }
+
+ public void setMarshallerFactory(final MarshallerFactory marshallerFactory) {
+ this.marshallerFactory = marshallerFactory;
+ }
+
+ public Configuration getMarshallingConfiguration() {
+ return marshallingConfiguration;
+ }
+
+ public void setMarshallingConfiguration(final Configuration marshallingConfiguration) {
+ this.marshallingConfiguration = marshallingConfiguration;
+ }
+
+ public int getLinkMetric() {
+ return linkMetric;
+ }
+
+ public void setLinkMetric(final int linkMetric) {
+ this.linkMetric = linkMetric;
+ }
+
+ public Executor getExecutor() {
+ return executor;
+ }
+
+ public void setExecutor(final Executor executor) {
+ this.executor = executor;
+ }
+
+ public BufferAllocator<ByteBuffer> getAllocator() {
+ return allocator;
+ }
+
+ public void setAllocator(final BufferAllocator<ByteBuffer> allocator) {
+ this.allocator = allocator;
+ }
+
+ public StreamDetector getStreamDetector() {
+ return streamDetector;
+ }
+
+ public void setStreamDetector(final StreamDetector streamDetector) {
+ this.streamDetector = streamDetector;
+ }
+}
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java 2008-10-21 04:56:10 UTC (rev 4604)
@@ -0,0 +1,141 @@
+/*
+ * 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.protocol.basic;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Lock;
+import java.util.Queue;
+import java.io.IOException;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.xnio.channels.StreamChannel;
+import org.jboss.xnio.IoUtils;
+import org.jboss.remoting.spi.remote.ReplyHandler;
+import org.jboss.remoting.spi.SpiUtils;
+import org.jboss.remoting.RemoteExecutionException;
+import org.jboss.remoting.ReplyException;
+import org.jboss.remoting.IndeterminateOutcomeException;
+
+/**
+ *
+ */
+final class BasicHandlerReplyConsumer implements Runnable {
+
+ private final AtomicInteger replySequence;
+ private final Unmarshaller unmarshaller;
+ private final StreamChannel streamChannel;
+ private final Lock reqLock;
+ private final Queue<ReplyHandler> replyQueue;
+
+ public BasicHandlerReplyConsumer(final Unmarshaller unmarshaller, final StreamChannel streamChannel, final Lock reqLock, final Queue<ReplyHandler> replyQueue) {
+ this.unmarshaller = unmarshaller;
+ this.streamChannel = streamChannel;
+ this.reqLock = reqLock;
+ this.replyQueue = replyQueue;
+ replySequence = new AtomicInteger();
+ }
+
+ public void run() {
+ try {
+ for (;;) {
+ final int type = unmarshaller.read();
+ switch (type) {
+ case -1: {
+ // done.
+ return;
+ }
+ case 1: {
+ // reply - success
+ reqLock.lock();
+ try {
+ replySequence.getAndIncrement();
+ final ReplyHandler replyHandler = replyQueue.remove();
+ final Object reply;
+ try {
+ reply = unmarshaller.readObject();
+ } catch (Exception e) {
+ SpiUtils.safeHandleException(replyHandler, new ReplyException("Failed to read reply from server", e));
+ return;
+ }
+ SpiUtils.safeHandleReply(replyHandler, reply);
+ break;
+ } finally {
+ reqLock.unlock();
+ }
+ }
+ case 2: {
+ // reply - cancelled
+ reqLock.lock();
+ try {
+ final int id = unmarshaller.readInt();
+ if (id != replySequence.getAndIncrement()) {
+ replySequence.decrementAndGet();
+ break;
+ }
+ final ReplyHandler replyHandler = replyQueue.remove();
+ SpiUtils.safeHandleCancellation(replyHandler);
+ break;
+ } finally {
+ reqLock.unlock();
+ }
+ }
+ case 3: {
+ // reply - exception
+ reqLock.lock();
+ try {
+ replySequence.getAndIncrement();
+ final ReplyHandler replyHandler = replyQueue.remove();
+ final Throwable e;
+ try {
+ e = (Throwable) unmarshaller.readObject();
+ } catch (Exception e2) {
+ SpiUtils.safeHandleException(replyHandler, new RemoteExecutionException("Failed to read exception from server", e2));
+ return;
+ }
+ SpiUtils.safeHandleException(replyHandler, new RemoteExecutionException("Remote execution failed", e));
+ break;
+ } finally {
+ reqLock.unlock();
+ }
+ }
+ default: {
+ // invalid byte
+ throw new IOException("Read an invalid byte from the server");
+ }
+ }
+ }
+ } catch (Exception e) {
+ // todo log it
+ } finally {
+ IoUtils.safeClose(streamChannel);
+ reqLock.lock();
+ try {
+ while (replyQueue.size() > 0) {
+ ReplyHandler replyHandler = replyQueue.remove();
+ SpiUtils.safeHandleException(replyHandler, new IndeterminateOutcomeException("Connection terminated; operation outcome unknown"));
+ }
+ } finally {
+ reqLock.unlock();
+ }
+ }
+ }
+}
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicProtocol.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicProtocol.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicProtocol.java 2008-10-21 04:56:10 UTC (rev 4604)
@@ -0,0 +1,80 @@
+/*
+ * 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.protocol.basic;
+
+import org.jboss.remoting.spi.remote.RequestHandler;
+import org.jboss.remoting.spi.remote.ReplyHandler;
+import org.jboss.remoting.spi.remote.Handle;
+import org.jboss.xnio.channels.StreamChannel;
+import org.jboss.xnio.channels.ChannelOutputStream;
+import org.jboss.xnio.channels.ChannelInputStream;
+import org.jboss.marshalling.Configuration;
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.Marshalling;
+import java.io.IOException;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.Executor;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.Queue;
+import java.util.LinkedList;
+
+/**
+ * A very basic example protocol.
+ */
+public final class BasicProtocol {
+
+ private BasicProtocol() {
+ }
+
+ public static final void createServer(final Handle<RequestHandler> requestHandlerHandle, final StreamChannel streamChannel, final BasicConfiguration configuration) throws IOException {
+ final RequestHandler requestHandler = requestHandlerHandle.getResource();
+ final Configuration marshallerConfiguration = configuration.getMarshallingConfiguration();
+ final MarshallerFactory marshallerFactory = configuration.getMarshallerFactory();
+ final Marshaller marshaller = marshallerFactory.createMarshaller(marshallerConfiguration);
+ final Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(marshallerConfiguration);
+ final Executor executor = configuration.getExecutor();
+ marshaller.start(Marshalling.createByteOutput(new ChannelOutputStream(streamChannel)));
+ unmarshaller.start(Marshalling.createByteInput(new ChannelInputStream(streamChannel)));
+ final BlockingQueue<FutureBasicReply> replyQueue = new LinkedBlockingQueue<FutureBasicReply>();
+ executor.execute(new BasicServerReplyTransmitter(replyQueue, marshaller, streamChannel, requestHandlerHandle));
+ executor.execute(new BasicServerRequestConsumer(unmarshaller, requestHandler, replyQueue, streamChannel, requestHandlerHandle));
+ }
+
+ public static final Handle<RequestHandler> createClient(final StreamChannel streamChannel, final BasicConfiguration configuration) throws IOException {
+ final Configuration marshallerConfiguration = configuration.getMarshallingConfiguration();
+ final MarshallerFactory marshallerFactory = configuration.getMarshallerFactory();
+ final Marshaller marshaller = marshallerFactory.createMarshaller(marshallerConfiguration);
+ final Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(marshallerConfiguration);
+ final Executor executor = configuration.getExecutor();
+ marshaller.start(Marshalling.createByteOutput(new ChannelOutputStream(streamChannel)));
+ unmarshaller.start(Marshalling.createByteInput(new ChannelInputStream(streamChannel)));
+ final Lock reqLock = new ReentrantLock();
+ final Queue<ReplyHandler> replyQueue = new LinkedList<ReplyHandler>();
+ executor.execute(new BasicHandlerReplyConsumer(unmarshaller, streamChannel, reqLock, replyQueue));
+ return new BasicRequestHandler(reqLock, marshaller, replyQueue, streamChannel, executor).getHandle();
+ }
+}
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java 2008-10-21 04:56:10 UTC (rev 4604)
@@ -0,0 +1,110 @@
+/*
+ * 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.protocol.basic;
+
+import org.jboss.remoting.spi.remote.RequestHandler;
+import org.jboss.remoting.spi.remote.ReplyHandler;
+import org.jboss.remoting.spi.remote.RemoteRequestContext;
+import org.jboss.remoting.spi.SpiUtils;
+import org.jboss.remoting.spi.AbstractAutoCloseable;
+import org.jboss.marshalling.Marshaller;
+import org.jboss.xnio.channels.StreamChannel;
+import org.jboss.xnio.IoUtils;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.Executor;
+import java.util.Queue;
+import java.io.IOException;
+
+/**
+ *
+ */
+final class BasicRequestHandler extends AbstractAutoCloseable<RequestHandler> implements RequestHandler {
+
+ private final AtomicInteger requestSequence;
+ private final Lock reqLock;
+ private final Marshaller marshaller;
+ private final Queue<ReplyHandler> replyQueue;
+ private final StreamChannel streamChannel;
+
+ public BasicRequestHandler(final Lock reqLock, final Marshaller marshaller, final Queue<ReplyHandler> replyQueue, final StreamChannel streamChannel, final Executor executor) {
+ super(executor);
+ this.reqLock = reqLock;
+ this.marshaller = marshaller;
+ this.replyQueue = replyQueue;
+ this.streamChannel = streamChannel;
+ requestSequence = new AtomicInteger();
+ }
+
+ public void receiveRequest(final Object request) {
+ reqLock.lock();
+ try {
+ marshaller.write(1);
+ marshaller.writeObject(request);
+ marshaller.flush();
+ } catch (IOException e) {
+ // todo log it
+ IoUtils.safeClose(this);
+ } finally {
+ reqLock.unlock();
+ }
+ }
+
+ public RemoteRequestContext receiveRequest(final Object request, final ReplyHandler replyHandler) {
+ reqLock.lock();
+ try {
+ marshaller.write(2);
+ marshaller.writeObject(request);
+ marshaller.flush();
+ final int id = requestSequence.getAndIncrement();
+ replyQueue.add(replyHandler);
+ return new RemoteRequestContext() {
+ public void cancel() {
+ reqLock.lock();
+ try {
+ marshaller.write(3);
+ marshaller.writeInt(id);
+ marshaller.flush();
+ } catch (IOException e) {
+ // todo log it
+ IoUtils.safeClose(BasicRequestHandler.this);
+ }
+ }
+ };
+ } catch (IOException e) {
+ SpiUtils.safeHandleException(replyHandler, e);
+ IoUtils.safeClose(this);
+ return SpiUtils.getBlankRemoteRequestContext();
+ } finally {
+ reqLock.unlock();
+ }
+ }
+
+ protected void closeAction() throws IOException {
+ streamChannel.close();
+ }
+
+ public String toString() {
+ return "basic protocol handler <" + Integer.toString(hashCode(), 16) + ">";
+ }
+}
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java 2008-10-21 04:56:10 UTC (rev 4604)
@@ -0,0 +1,88 @@
+/*
+ * 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.protocol.basic;
+
+import java.util.concurrent.BlockingQueue;
+import org.jboss.marshalling.Marshaller;
+import org.jboss.xnio.channels.StreamChannel;
+import org.jboss.xnio.IoUtils;
+import org.jboss.remoting.spi.remote.RequestHandler;
+import org.jboss.remoting.spi.remote.Handle;
+
+/**
+ *
+ */
+final class BasicServerReplyTransmitter implements Runnable {
+
+ private final BlockingQueue<FutureBasicReply> replyQueue;
+ private final Marshaller marshaller;
+ private final StreamChannel streamChannel;
+ private final Handle<RequestHandler> requestHandlerHandle;
+
+ public BasicServerReplyTransmitter(final BlockingQueue<FutureBasicReply> replyQueue, final Marshaller marshaller, final StreamChannel streamChannel, final Handle<RequestHandler> requestHandlerHandle) {
+ this.replyQueue = replyQueue;
+ this.marshaller = marshaller;
+ this.streamChannel = streamChannel;
+ this.requestHandlerHandle = requestHandlerHandle;
+ }
+
+ public void run() {
+ try {
+ for (;;) {
+ final FutureBasicReply futureBasicReply = replyQueue.remove();
+ OUT: for (;;) switch (futureBasicReply.awaitInterruptibly()) {
+ case DONE: {
+ marshaller.write(1);
+ marshaller.writeObject(futureBasicReply.get());
+ marshaller.flush();
+ break OUT;
+ }
+ case CANCELLED: {
+ marshaller.write(2);
+ marshaller.writeInt(futureBasicReply.id);
+ marshaller.flush();
+ break OUT;
+ }
+ case FAILED: {
+ marshaller.write(3);
+ marshaller.writeObject(futureBasicReply.getException());
+ marshaller.flush();
+ break OUT;
+ }
+ case WAITING: {
+ // spurious wakeup, try again
+ continue;
+ }
+ }
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ // todo log it
+ } catch (Exception e) {
+ // todo log it
+ } finally {
+ IoUtils.safeClose(streamChannel);
+ IoUtils.safeClose(requestHandlerHandle);
+ }
+ }
+}
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java 2008-10-21 04:56:10 UTC (rev 4604)
@@ -0,0 +1,121 @@
+/*
+ * 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.protocol.basic;
+
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.remoting.spi.remote.RequestHandler;
+import org.jboss.remoting.spi.remote.Handle;
+import org.jboss.remoting.spi.remote.RemoteRequestContext;
+import org.jboss.remoting.spi.remote.ReplyHandler;
+import org.jboss.xnio.channels.StreamChannel;
+import org.jboss.xnio.IoUtils;
+import java.util.concurrent.BlockingQueue;
+import java.io.IOException;
+
+/**
+ *
+ */
+final class BasicServerRequestConsumer implements Runnable {
+
+ private final Unmarshaller unmarshaller;
+ private final RequestHandler requestHandler;
+ private final BlockingQueue<FutureBasicReply> replyQueue;
+ private final StreamChannel streamChannel;
+ private final Handle<RequestHandler> requestHandlerHandle;
+
+ public BasicServerRequestConsumer(final Unmarshaller unmarshaller, final RequestHandler requestHandler, final BlockingQueue<FutureBasicReply> replyQueue, final StreamChannel streamChannel, final Handle<RequestHandler> requestHandlerHandle) {
+ this.unmarshaller = unmarshaller;
+ this.requestHandler = requestHandler;
+ this.replyQueue = replyQueue;
+ this.streamChannel = streamChannel;
+ this.requestHandlerHandle = requestHandlerHandle;
+ }
+
+ public void run() {
+ try {
+ int requestSequence = 0;
+ for (;;) {
+ final int id = unmarshaller.read();
+ switch (id) {
+ case -1: {
+ // done.
+ return;
+ }
+ case 1: {
+ // one-way request
+ final Object request = unmarshaller.readObject();
+ requestHandler.receiveRequest(request);
+ break;
+ }
+ case 2: {
+ // two-way request
+ final int requestId = requestSequence++;
+ final Object request = unmarshaller.readObject();
+ final FutureBasicReply future = new FutureBasicReply(requestId);
+ replyQueue.add(future);
+ final RemoteRequestContext requestContext = requestHandler.receiveRequest(request, new ReplyHandler() {
+
+ public void handleReply(final Object reply) {
+ future.setResult(reply);
+ }
+
+ public void handleException(final IOException exception) {
+ future.setException(exception);
+ }
+
+ public void handleCancellation() {
+ future.finishCancel();
+ }
+ });
+ future.requestContext = requestContext;
+ break;
+ }
+ case 3: {
+ // cancel request
+ final int requestId = unmarshaller.readInt();
+ // simply iterate over the outstanding requests until we match or are past it...
+ for (FutureBasicReply future : replyQueue) {
+ final int queuedId = future.id;
+ if (queuedId == requestId) {
+ future.cancel();
+ break;
+ } else if (queuedId > requestId) {
+ break;
+ }
+ }
+ break;
+ }
+ default: {
+ // invalid byte
+ throw new IOException("Read an invalid byte from the client");
+ }
+ }
+ }
+ } catch (Exception e) {
+ // todo log it
+ } finally {
+ IoUtils.safeClose(streamChannel);
+ IoUtils.safeClose(requestHandlerHandle);
+ }
+ }
+}
Added: remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/FutureBasicReply.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/FutureBasicReply.java (rev 0)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/FutureBasicReply.java 2008-10-21 04:56:10 UTC (rev 4604)
@@ -0,0 +1,58 @@
+/*
+ * 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.protocol.basic;
+
+import org.jboss.xnio.AbstractIoFuture;
+import org.jboss.xnio.IoFuture;
+import org.jboss.remoting.spi.remote.RemoteRequestContext;
+import java.io.IOException;
+
+/**
+ *
+ */
+final class FutureBasicReply extends AbstractIoFuture<Object> {
+
+ final int id;
+ RemoteRequestContext requestContext;
+
+ public FutureBasicReply(final int id) {
+ this.id = id;
+ }
+
+ protected boolean setException(final IOException exception) {
+ return super.setException(exception);
+ }
+
+ protected boolean setResult(final Object result) {
+ return super.setResult(result);
+ }
+
+ protected boolean finishCancel() {
+ return super.finishCancel();
+ }
+
+ public IoFuture<Object> cancel() {
+ requestContext.cancel();
+ return this;
+ }
+}
16 years, 2 months
JBoss Remoting SVN: r4603 - remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-10-20 22:44:31 -0400 (Mon, 20 Oct 2008)
New Revision: 4603
Modified:
remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java
Log:
generics nit
Modified: remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java
===================================================================
--- remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java 2008-10-21 02:40:49 UTC (rev 4602)
+++ remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java 2008-10-21 02:44:31 UTC (rev 4603)
@@ -84,7 +84,7 @@
configuration.setAllocator(allocator);
configuration.setExecutor(executor);
// todo marshaller factory... etc
- final MultiplexHandler multiplexHandler = new MultiplexHandler<A>(endpoint, configuration, streamProvider);
+ final MultiplexHandler<A> multiplexHandler = new MultiplexHandler<A>(endpoint, configuration, streamProvider);
final IoFuture<AllocatedMessageChannel> futureChannel = channelSource.open(multiplexHandler);
return new AbstractConvertingIoFuture<SimpleCloseable, AllocatedMessageChannel>(futureChannel) {
protected SimpleCloseable convert(final AllocatedMessageChannel channel) throws RemotingException {
16 years, 2 months
JBoss Remoting SVN: r4602 - remoting3/trunk.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-10-20 22:40:49 -0400 (Mon, 20 Oct 2008)
New Revision: 4602
Modified:
remoting3/trunk/build.xml
Log:
The basic protocol is really a multiplex protocol. Make room for a *real* basic protocol. (2)
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2008-10-21 02:39:24 UTC (rev 4601)
+++ remoting3/trunk/build.xml 2008-10-21 02:40:49 UTC (rev 4602)
@@ -737,12 +737,12 @@
</path>
</target>
- <!-- protocol.basic module -->
+ <!-- protocol.multiplex module -->
- <target name="protocol.basic.compile.depcheck">
- <mkdir dir="protocol/basic/target/main"/>
- <uptodate property="protocol/basic.compile.uptodate" targetfile="protocol/basic/target/main/.lastcompile">
- <srcfiles dir="protocol/basic/src/main/java">
+ <target name="protocol.multiplex.compile.depcheck">
+ <mkdir dir="protocol/multiplex/target/main"/>
+ <uptodate property="protocol/multiplex.compile.uptodate" targetfile="protocol/multiplex/target/main/.lastcompile">
+ <srcfiles dir="protocol/multiplex/src/main/java">
<include name="**/"/>
<include name="**/*.java"/>
<exclude name="**/.*"/>
@@ -750,13 +750,13 @@
</uptodate>
</target>
- <target name="protocol.basic.compile" depends="protocol.basic.compile.depcheck" unless="protocol.basic.compile.uptodate">
- <mkdir dir="protocol/basic/target/main/classes"/>
+ <target name="protocol.multiplex.compile" depends="protocol.multiplex.compile.depcheck" unless="protocol.multiplex.compile.uptodate">
+ <mkdir dir="protocol/multiplex/target/main/classes"/>
<javac
source="${javac.source}"
target="${javac.target}"
- srcdir="protocol/basic/src/main/java"
- destdir="protocol/basic/target/main/classes"
+ srcdir="protocol/multiplex/src/main/java"
+ destdir="protocol/multiplex/target/main/classes"
debug="true">
<compilerarg value="-Xlint:unchecked"/>
<classpath>
@@ -768,13 +768,13 @@
<pathelement location="${lib.xnio-api.local}"/>
</classpath>
</javac>
- <touch file="protocol/basic/target/main/.lastcompile" verbose="false"/>
+ <touch file="protocol/multiplex/target/main/.lastcompile" verbose="false"/>
</target>
- <target name="protocol.basic.test.compile.depcheck">
- <mkdir dir="protocol/basic/target/test"/>
- <uptodate property="protocol.basic.compile.uptodate" targetfile="protocol/basic/target/test/.lastcompile">
- <srcfiles dir="protocol/basic/src/test/java">
+ <target name="protocol.multiplex.test.compile.depcheck">
+ <mkdir dir="protocol/multiplex/target/test"/>
+ <uptodate property="protocol.multiplex.compile.uptodate" targetfile="protocol/multiplex/target/test/.lastcompile">
+ <srcfiles dir="protocol/multiplex/src/test/java">
<include name="**/"/>
<include name="**/*.java"/>
<exclude name="**/.*"/>
@@ -782,19 +782,19 @@
</uptodate>
</target>
- <target name="protocol.basic.test.compile" depends="lib.junit,protocol.basic.compile,protocol.basic.test.compile.depcheck" unless="protocol.basic.test.compile.uptodate">
- <mkdir dir="protocol/basic/target/test/classes"/>
+ <target name="protocol.multiplex.test.compile" depends="lib.junit,protocol.multiplex.compile,protocol.multiplex.test.compile.depcheck" unless="protocol.multiplex.test.compile.uptodate">
+ <mkdir dir="protocol/multiplex/target/test/classes"/>
<javac
source="${javac.source}"
target="${javac.target}"
- srcdir="protocol/basic/src/test/java"
- destdir="protocol/basic/target/test/classes"
+ srcdir="protocol/multiplex/src/test/java"
+ destdir="protocol/multiplex/target/test/classes"
debug="true">
<compilerarg value="-Xlint:unchecked"/>
<classpath>
<path refid="api.classpath"/>
<path refid="core.classpath"/>
- <path refid="protocol.basic.classpath"/>
+ <path refid="protocol.multiplex.classpath"/>
<path refid="util.classpath"/>
<path refid="testing-support.classpath"/>
<pathelement location="${lib.junit.local}"/>
@@ -804,14 +804,14 @@
<pathelement location="${lib.xnio-nio.local}"/>
</classpath>
</javac>
- <touch file="protocol/basic/target/test/.lastcompile" verbose="false"/>
+ <touch file="protocol/multiplex/target/test/.lastcompile" verbose="false"/>
</target>
- <target name="protocol.basic.test.pseudotarget">
+ <target name="protocol.multiplex.test.pseudotarget">
<echo message="============================================="/>
<echo message="${message}"/>
<echo message="============================================="/>
- <mkdir dir="protocol/basic/target/test-results"/>
+ <mkdir dir="protocol/multiplex/target/test-results"/>
<junit printsummary="true" fork="yes" includeantruntime="true">
<sysproperty key="build.home" value="${basedir}"/>
<sysproperty key="ant.library.dir" value="${ant.home}/lib"/>
@@ -824,45 +824,45 @@
<classpath>
<path refid="api.classpath"/>
<path refid="core.classpath"/>
- <path refid="protocol.basic.classpath"/>
+ <path refid="protocol.multiplex.classpath"/>
<path refid="testing-support.classpath"/>
<path refid="util.classpath"/>
- <pathelement location="protocol/basic/target/test/classes"/>
+ <pathelement location="protocol/multiplex/target/test/classes"/>
<pathelement location="${lib.junit.local}"/>
<pathelement location="${lib.marshalling-api.local}"/>
<pathelement location="${lib.river.local}"/>
<pathelement location="${lib.xnio-api.local}"/>
<pathelement location="${lib.xnio-nio.local}"/>
</classpath>
- <batchtest fork="yes" todir="protocol/basic/target/test-results"
+ <batchtest fork="yes" todir="protocol/multiplex/target/test-results"
haltonfailure="no">
- <fileset dir="protocol/basic/target/test/classes">
+ <fileset dir="protocol/multiplex/target/test/classes">
<include name="**/*TestCase.class"/>
</fileset>
</batchtest>
</junit>
</target>
- <target name="protocol.basic.test" depends="lib.xnio-nio,api,core,protocol.basic,testing-support,util,protocol.basic.test.compile">
- <antcall inheritall="true" inheritrefs="true" target="protocol.basic.test.pseudotarget">
+ <target name="protocol.multiplex.test" depends="lib.xnio-nio,api,core,protocol.multiplex,testing-support,util,protocol.multiplex.test.compile">
+ <antcall inheritall="true" inheritrefs="true" target="protocol.multiplex.test.pseudotarget">
<param name="extension" value=".txt"/>
<param name="message" value="Running with no security manager"/>
<param name="test.jvmargs" value="-Ddummy=dummy"/>
</antcall>
- <antcall inheritall="true" inheritrefs="true" target="protocol.basic.test.pseudotarget">
+ <antcall inheritall="true" inheritrefs="true" target="protocol.multiplex.test.pseudotarget">
<param name="extension" value="-security.txt"/>
<param name="message" value="Running with security manager"/>
<param name="test.jvmargs" value="-Djava.security.manager=org.jboss.remoting.test.support.LoggingSecurityManager -Djava.security.policy=${basedir}/testing-support/src/main/resources/testing.policy -Dsecurity.debug=policy"/>
</antcall>
</target>
- <target name="protocol.basic.clean">
- <delete dir="protocol/basic/target"/>
+ <target name="protocol.multiplex.clean">
+ <delete dir="protocol/multiplex/target"/>
</target>
- <target name="protocol.basic" description="Build the protocol.basic module" depends="lib.xnio-api,api,core,util,protocol.basic.compile">
- <path id="protocol.basic.classpath">
- <pathelement location="protocol/basic/target/main/classes"/>
+ <target name="protocol.multiplex" description="Build the protocol.multiplex module" depends="lib.xnio-api,api,core,util,protocol.multiplex.compile">
+ <path id="protocol.multiplex.classpath">
+ <pathelement location="protocol/multiplex/target/main/classes"/>
</path>
</target>
@@ -1341,9 +1341,9 @@
<!-- core -->
- <target name="all-core" description="Build all core targets" depends="api,compat,core,mc-deployers,protocol.basic,samples,standalone,testing-support,tools,util"/>
+ <target name="all-core" description="Build all core targets" depends="api,compat,core,mc-deployers,protocol.multiplex,samples,standalone,testing-support,tools,util"/>
- <target name="clean-core" description="Clean all core targets" depends="api.clean,compat.clean,core.clean,mc-deployers.clean,protocol.basic.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.multiplex.clean,samples.clean,standalone.clean,testing-support.clean,tools.clean,util.clean"/>
<!-- http -->
@@ -1365,6 +1365,6 @@
<target name="clean" description="Clean out all build files" depends="clean-core,clean-http,version.clean,srp.clean"/>
- <target name="test" description="Run all tests" depends="api.test,core.test,protocol.basic.test"/>
+ <target name="test" description="Run all tests" depends="api.test,core.test,protocol.multiplex.test"/>
</project>
16 years, 2 months