[jboss-remoting-commits] JBoss Remoting SVN: r4797 - in remoting3/trunk/compat/src/main/java: org and 3 other directories.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Fri Jan 9 15:44:28 EST 2009


Author: david.lloyd at jboss.com
Date: 2009-01-09 15:44:27 -0500 (Fri, 09 Jan 2009)
New Revision: 4797

Added:
   remoting3/trunk/compat/src/main/java/org/
   remoting3/trunk/compat/src/main/java/org/jboss/
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityClassResolver.java
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityInvocationRequest.java
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityInvocationResponse.java
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatibilityHome.java
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatibilityInvokerLocator.java
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/Request.java
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/UnwrappingReplyHandler.java
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/UnwrappingRequestHandler.java
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/WrappingReplyHandler.java
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/WrappingRequestHandler.java
   remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/package-info.java
Log:
A start on the basic stuff for compatibility layer

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityClassResolver.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityClassResolver.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityClassResolver.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -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.compat;
+
+import org.jboss.marshalling.AbstractClassResolver;
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+
+/**
+ *
+ */
+public abstract class CompatabilityClassResolver extends AbstractClassResolver {
+
+    private static final Map<Class<?>, String> CLASS_WRITE_MAP;
+    private static final Map<String, Class<?>> CLASS_READ_MAP;
+
+    static {
+        final Map<Class<?>, String> classWriteMap = new HashMap<Class<?>, String>();
+        classWriteMap.put(CompatabilityInvocationRequest.class, "org.jboss.remoting.InvocationRequest");
+        classWriteMap.put(CompatabilityInvocationResponse.class, "org.jboss.remoting.InvocationReply");
+        classWriteMap.put(CompatibilityInvokerLocator.class, "org.jboss.remoting.InvokerLocator");
+        classWriteMap.put(CompatibilityHome.class, "org.jboss.remoting.Home");
+        CLASS_WRITE_MAP = Collections.unmodifiableMap(classWriteMap);
+        final Map<String, Class<?>> classReadMap = new HashMap<String, Class<?>>();
+        for (Map.Entry<Class<?>, String> entry : classWriteMap.entrySet()) {
+            classReadMap.put(entry.getValue(), entry.getKey());
+        }
+        CLASS_READ_MAP = Collections.unmodifiableMap(classReadMap);
+    }
+
+    public String getClassName(final Class<?> clazz) throws IOException {
+        final String name = CLASS_WRITE_MAP.get(clazz);
+        return name == null ? clazz.getName() : name;
+    }
+
+    protected Class<?> loadClass(final String name) throws ClassNotFoundException {
+        final Class<?> clazz = CLASS_READ_MAP.get(name);
+        return clazz == null ? super.loadClass(name) : clazz;
+    }
+}

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityInvocationRequest.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityInvocationRequest.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityInvocationRequest.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -0,0 +1,112 @@
+/*
+ * 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.compat;
+
+import java.io.Serializable;
+import java.io.ObjectStreamField;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.Map;
+
+/**
+ *
+ */
+public final class CompatabilityInvocationRequest implements Serializable {
+    private static final long serialVersionUID = -6719842238864057289L;
+
+    private static final ObjectStreamField[] serialPersistentFields = {
+            new ObjectStreamField("sessionId", String.class),
+            new ObjectStreamField("subsystem", String.class),
+            new ObjectStreamField("arg", Object.class),
+            new ObjectStreamField("requestPayload", Map.class),
+            new ObjectStreamField("returnPayload", Map.class),
+            new ObjectStreamField("locator", CompatibilityInvokerLocator.class),
+    };
+
+    private String sessionId;
+    private String subsystem;
+    private Object arg;
+    private Map<Object, Object> requestPayload;
+    private Map<Object, Object> returnPayload;
+
+    public String getSessionId() {
+        return sessionId;
+    }
+
+    public void setSessionId(final String sessionId) {
+        this.sessionId = sessionId;
+    }
+
+    public String getSubsystem() {
+        return subsystem;
+    }
+
+    public void setSubsystem(final String subsystem) {
+        this.subsystem = subsystem;
+    }
+
+    public Object getArg() {
+        return arg;
+    }
+
+    public void setArg(final Object arg) {
+        this.arg = arg;
+    }
+
+    public Map<Object, Object> getRequestPayload() {
+        return requestPayload;
+    }
+
+    public void setRequestPayload(final Map<Object, Object> requestPayload) {
+        this.requestPayload = requestPayload;
+    }
+
+    public Map<Object, Object> getReturnPayload() {
+        return returnPayload;
+    }
+
+    public void setReturnPayload(final Map<Object, Object> returnPayload) {
+        this.returnPayload = returnPayload;
+    }
+
+    @SuppressWarnings({ "unchecked" })
+    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
+        final ObjectInputStream.GetField fields = stream.readFields();
+        sessionId = (String) fields.get("sessionId", "");
+        subsystem = (String) fields.get("subsystem", "");
+        arg = fields.get("arg", "");
+        requestPayload = (Map<Object, Object>) fields.get("requestPayload", null);
+        returnPayload = (Map<Object, Object>) fields.get("returnPayload", null);
+    }
+
+    private void writeObject(ObjectOutputStream stream) throws IOException {
+        final ObjectOutputStream.PutField fields = stream.putFields();
+        fields.put("sessionId", sessionId);
+        fields.put("subsystem", subsystem);
+        fields.put("arg", arg);
+        fields.put("requestPayload", requestPayload);
+        fields.put("returnPayload", returnPayload);
+        stream.writeFields();
+    }
+}

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityInvocationResponse.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityInvocationResponse.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatabilityInvocationResponse.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -0,0 +1,78 @@
+/*
+ * 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.compat;
+
+import java.io.Serializable;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.Map;
+
+/**
+ *
+ */
+public final class CompatabilityInvocationResponse<T> implements Serializable {
+    private static final long serialVersionUID = 1324503813652865685L;
+
+    private final String sessionId;
+    private final Object result;
+    private final boolean isException;
+    private Map<Object, Object> payload;
+
+    public CompatabilityInvocationResponse(final String sessionId, final Object result, final boolean isException, final Map<Object, Object> payload) {
+        this.sessionId = sessionId;
+        this.result = result;
+        this.isException = isException;
+        this.payload = payload;
+    }
+
+    public String getSessionId() {
+        return sessionId;
+    }
+
+    public Object getResult() {
+        return result;
+    }
+
+    public boolean isException() {
+        return isException;
+    }
+
+    public Map<Object, Object> getPayload() {
+        return payload;
+    }
+
+    public void setPayload(final Map<Object, Object> payload) {
+        this.payload = payload;
+    }
+
+    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
+        final ObjectInputStream.GetField fields = stream.readFields();
+    }
+
+    private void writeObject(ObjectOutputStream stream) throws IOException {
+        final ObjectOutputStream.PutField fields = stream.putFields();
+
+        stream.writeFields();
+    }
+}

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatibilityHome.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatibilityHome.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatibilityHome.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -0,0 +1,60 @@
+/*
+ * 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.compat;
+
+import java.io.Serializable;
+
+/**
+ *
+ */
+public final class CompatibilityHome implements Serializable {
+
+    private static final long serialVersionUID = 8267821565540095027L;
+
+    public String host;
+    public int port;
+
+    public CompatibilityHome() {
+    }
+
+    public CompatibilityHome(final String host, final int port) {
+        this.host = host;
+        this.port = port;
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(final String host) {
+        this.host = host;
+    }
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(final int port) {
+        this.port = port;
+    }
+}

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatibilityInvokerLocator.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatibilityInvokerLocator.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/CompatibilityInvokerLocator.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -0,0 +1,89 @@
+/*
+ * 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.compat;
+
+import java.net.URI;
+import java.io.Serializable;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.util.ArrayList;
+import java.util.Map;
+
+/**
+ *
+ */
+public final class CompatibilityInvokerLocator implements Serializable {
+
+    private static final long serialVersionUID = -4977622166779282521L;
+
+    private static final ObjectStreamField[] serialPersistentFields = {
+            new ObjectStreamField("protocol", String.class),
+            new ObjectStreamField("host", String.class),
+            new ObjectStreamField("connectHomes", ArrayList.class),
+            new ObjectStreamField("homes", ArrayList.class),
+            new ObjectStreamField("port", int.class),
+            new ObjectStreamField("path", String.class),
+            new ObjectStreamField("query", String.class),
+            new ObjectStreamField("parameters", Map.class),
+            new ObjectStreamField("uri", String.class),
+            new ObjectStreamField("originalURL", String.class),
+            new ObjectStreamField("homeInUse", CompatibilityHome.class),
+    };
+
+    private transient URI uri;
+
+    public CompatibilityInvokerLocator() {
+    }
+
+    public CompatibilityInvokerLocator(final URI uri) {
+        this.uri = uri;
+    }
+
+    public URI getUri() {
+        return uri;
+    }
+
+    public void setUri(final URI uri) {
+        this.uri = uri;
+    }
+
+    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
+        final ObjectInputStream.GetField fields = stream.readFields();
+
+    }
+
+    private void writeObject(ObjectOutputStream stream) throws IOException {
+        final ObjectOutputStream.PutField fields = stream.putFields();
+        fields.put("protocol", uri.getScheme());
+        fields.put("host", uri.getHost());
+        fields.put("port", uri.getPort());
+        fields.put("path", uri.getPath());
+        fields.put("query", uri.getQuery());
+        fields.put("uri", uri.toString());
+        fields.put("originalURL", uri.toString());
+        
+        stream.writeFields();
+    }
+}

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/Request.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/Request.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/Request.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -0,0 +1,57 @@
+/*
+ * 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.compat;
+
+import java.util.Map;
+
+/**
+ * A request wrapper object, used to issue a Remoting 2.x invocation with a metadata map.
+ */
+public final class Request<I> {
+    private I body;
+    private Map<Object, Object> metadata;
+
+    public Request() {
+    }
+
+    public Request(final I body, final Map<Object, Object> metadata) {
+        this.body = body;
+        this.metadata = metadata;
+    }
+
+    public I getBody() {
+        return body;
+    }
+
+    public void setBody(final I body) {
+        this.body = body;
+    }
+
+    public Map<Object, Object> getMetadata() {
+        return metadata;
+    }
+
+    public void setMetadata(final Map<Object, Object> metadata) {
+        this.metadata = metadata;
+    }
+}

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/UnwrappingReplyHandler.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/UnwrappingReplyHandler.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/UnwrappingReplyHandler.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -0,0 +1,63 @@
+/*
+ * 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.compat;
+
+import org.jboss.remoting.spi.ReplyHandler;
+import org.jboss.remoting.RemoteExecutionException;
+import java.io.IOException;
+
+/**
+ * A reply handler which unwraps a Remoting 2-style invocation response to a Remoting 3-style plain object.
+ */
+public final class UnwrappingReplyHandler implements ReplyHandler {
+
+    private final ReplyHandler replyHandler;
+
+    public UnwrappingReplyHandler(final ReplyHandler replyHandler) {
+        this.replyHandler = replyHandler;
+    }
+
+    public void handleReply(final Object reply) throws IOException {
+        if (reply instanceof CompatabilityInvocationResponse) {
+            final CompatabilityInvocationResponse response = (CompatabilityInvocationResponse) reply;
+            if (response.isException()) {
+                final Object result = response.getResult();
+                if (result instanceof Throwable) {
+                    replyHandler.handleException(new RemoteExecutionException("Remote execution failed", (Throwable) result));
+                } else {
+                    replyHandler.handleException(new RemoteExecutionException("Remote execution failed: " + result));
+                }
+            } else {
+                replyHandler.handleReply(response.getPayload());
+            }
+        }
+    }
+
+    public void handleException(final IOException exception) throws IOException {
+        replyHandler.handleException(exception);
+    }
+
+    public void handleCancellation() throws IOException {
+        replyHandler.handleCancellation();
+    }
+}

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/UnwrappingRequestHandler.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/UnwrappingRequestHandler.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/UnwrappingRequestHandler.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -0,0 +1,76 @@
+/*
+ * 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.compat;
+
+import org.jboss.remoting.spi.AbstractAutoCloseable;
+import org.jboss.remoting.spi.RequestHandler;
+import org.jboss.remoting.spi.RemoteRequestContext;
+import org.jboss.remoting.spi.ReplyHandler;
+import org.jboss.remoting.spi.SpiUtils;
+import org.jboss.remoting.RemoteRequestException;
+import org.jboss.xnio.log.Logger;
+import java.util.concurrent.Executor;
+import java.util.Map;
+import java.io.IOException;
+
+/**
+ * A request handler which unwraps a Remoting 2-style invocation request to a Remoting 3-style plain object
+ * or {@link org.jboss.remoting.compat.Request} instance.
+ */
+public final class UnwrappingRequestHandler extends AbstractAutoCloseable<RequestHandler> implements RequestHandler {
+
+    private static final Logger log = Logger.getLogger("org.jboss.remoting.compat");
+
+    private final RequestHandler next;
+
+    /**
+     * Basic constructor.
+     *
+     * @param executor the executor used to execute the close notification handlers
+     * @param next
+     */
+    protected UnwrappingRequestHandler(final Executor executor, final RequestHandler next) {
+        super(executor);
+        this.next = next;
+    }
+
+    public RemoteRequestContext receiveRequest(final Object request, final ReplyHandler replyHandler) {
+        if (request instanceof CompatabilityInvocationRequest) {
+            final CompatabilityInvocationRequest invocationRequest = (CompatabilityInvocationRequest) request;
+            final Map<Object,Object> map = invocationRequest.getRequestPayload();
+            if (map == null) {
+                return next.receiveRequest(invocationRequest.getArg(), new WrappingReplyHandler(replyHandler));
+            }
+            return null;
+        } else {
+            final RemoteRequestException nex = new RemoteRequestException("Expected a Remoting-2 InvocationRequest instance");
+            try {
+                replyHandler.handleException(nex);
+            } catch (IOException e) {
+                log.error(e, "Failed to forward an exception to the requesting party");
+                log.error(nex, "The original exception follows");
+            }
+            return SpiUtils.getBlankRemoteRequestContext();
+        }
+    }
+}

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/WrappingReplyHandler.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/WrappingReplyHandler.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/WrappingReplyHandler.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -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.compat;
+
+import org.jboss.remoting.spi.ReplyHandler;
+import java.io.IOException;
+
+/**
+ * A request handler which wraps a Remoting 3-style reply with a Remoting 2-style invocation response.
+ */
+public final class WrappingReplyHandler implements ReplyHandler {
+
+    private final ReplyHandler replyHandler;
+
+    public WrappingReplyHandler(final ReplyHandler replyHandler) {
+        this.replyHandler = replyHandler;
+    }
+
+    public void handleReply(final Object reply) throws IOException {
+        replyHandler.handleReply(new CompatabilityInvocationResponse(null, reply,  false, null));
+    }
+
+    public void handleException(final IOException exception) throws IOException {
+        replyHandler.handleReply(new CompatabilityInvocationResponse(null, exception, true, null));
+    }
+
+    public void handleCancellation() throws IOException {
+        replyHandler.handleCancellation();
+    }
+}

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/WrappingRequestHandler.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/WrappingRequestHandler.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/WrappingRequestHandler.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -0,0 +1,57 @@
+/*
+ * 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.compat;
+
+import org.jboss.remoting.spi.RequestHandler;
+import org.jboss.remoting.spi.RemoteRequestContext;
+import org.jboss.remoting.spi.ReplyHandler;
+import org.jboss.remoting.spi.AbstractAutoCloseable;
+import java.util.concurrent.Executor;
+
+/**
+ * A request handler which wraps a Remoting 3-style plain request (or an instance of {@link org.jboss.remoting.compat.Request Request}
+ * with a Remoting 2-style invocation request.
+ */
+public final class WrappingRequestHandler extends AbstractAutoCloseable<RequestHandler> implements RequestHandler {
+
+    private final RequestHandler next;
+
+    public WrappingRequestHandler(final RequestHandler next, final Executor executor) {
+        super(executor);
+        this.next = next;
+    }
+
+    public RemoteRequestContext receiveRequest(final Object obj, final ReplyHandler replyHandler) {
+        final CompatabilityInvocationRequest cir = new CompatabilityInvocationRequest();
+        if (obj instanceof Request) {
+            final Request request = (Request) obj;
+            cir.setArg(request.getBody());
+            // wtf?
+            //noinspection unchecked
+            cir.setRequestPayload(request.getMetadata());
+        } else {
+            cir.setArg(obj);
+        }
+        return next.receiveRequest(cir, new UnwrappingReplyHandler(replyHandler));
+    }
+}

Added: remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/package-info.java
===================================================================
--- remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/package-info.java	                        (rev 0)
+++ remoting3/trunk/compat/src/main/java/org/jboss/remoting/compat/package-info.java	2009-01-09 20:44:27 UTC (rev 4797)
@@ -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.
+ */
+
+/**
+ * Classes that represent the Remoting 3 end of a relationship with a legacy Remoting 2 service or client.
+ */
+package org.jboss.remoting.compat;
\ No newline at end of file




More information about the jboss-remoting-commits mailing list