You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2007/09/20 06:55:22 UTC

svn commit: r577545 [1/3] - in /geronimo/sandbox/gshell/trunk: gshell-assembly/src/main/underlay/etc/ gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/ gshell-remote/gshell-remote-common/src/main/java/org/apache...

Author: jdillon
Date: Wed Sep 19 21:55:19 2007
New Revision: 577545

URL: http://svn.apache.org/viewvc?rev=577545&view=rev
Log:
Checking in the work I've done all day to try and get the damn stream and request/response stuff working...
its still not happy... going to see if Mina 1.1.2 works any better

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteExecuteException.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/package-info.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/package-info.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionStreamFilter.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/WriteStreamMessage.java   (contents, props changed)
      - copied, changed from r577140, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/WriteStreamMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ConnectionException.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportCommon.java   (contents, props changed)
      - copied, changed from r577140, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportException.java   (with props)
Removed:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageResponseInspector.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/WriteStreamMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportSupport.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-assembly/src/main/underlay/etc/gsh-log4j.properties
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteShellProxy.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MarshallingUtil.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MessageCodecFactory.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/logging/LoggingFilter.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CryptoAwareMessageSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/ExecuteMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/LoginMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionInputStream.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionOutputStream.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamFeeder.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ProtocolHandler.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportFactoryLocator.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransportServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/DefaultRemoteShell.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java

Modified: geronimo/sandbox/gshell/trunk/gshell-assembly/src/main/underlay/etc/gsh-log4j.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-assembly/src/main/underlay/etc/gsh-log4j.properties?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-assembly/src/main/underlay/etc/gsh-log4j.properties (original)
+++ geronimo/sandbox/gshell/trunk/gshell-assembly/src/main/underlay/etc/gsh-log4j.properties Wed Sep 19 21:55:19 2007
@@ -27,7 +27,8 @@
 log4j.appender.CONSOLE.Target=System.out
 log4j.appender.CONSOLE.Threshold=${gshell.log.console.level}
 log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
-log4j.appender.CONSOLE.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}] %m%n
+log4j.appender.CONSOLE.layout.ConversionPattern=%-5p %-25.30c{1} [%t] %m%n
+#log4j.appender.CONSOLE.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}] %m%n
 
 log4j.appender.FILE=org.apache.log4j.FileAppender
 log4j.appender.FILE.File=${gshell.home}/log/gshell.log
@@ -35,6 +36,3 @@
 log4j.appender.FILE.Threshold=DEBUG
 log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
 log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} %-5p (%t) [%c] %m%n
-
-log4j.logger.org.apache.geronimo.gshell.remote.server.RshServerProtocolHandler.IoSessionLogger=INFO
-log4j.logger.org.apache.geronimo.gshell.remote.client.RshClientProtocolHandler.IoSessionLogger=INFO

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteExecuteException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteExecuteException.java?rev=577545&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteExecuteException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteExecuteException.java Wed Sep 19 21:55:19 2007
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.client;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class RemoteExecuteException
+    extends RuntimeException
+{
+    private static final long serialVersionUID = 1;
+
+    public RemoteExecuteException(final String msg, final Throwable cause) {
+        super(msg, cause);
+    }
+
+    public RemoteExecuteException(final String msg) {
+        super(msg);
+    }
+
+    public RemoteExecuteException(final Throwable cause) {
+        super(cause);
+    }
+
+    public RemoteExecuteException() {
+        super();
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteExecuteException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteExecuteException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteExecuteException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteShellProxy.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteShellProxy.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteShellProxy.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteShellProxy.java Wed Sep 19 21:55:19 2007
@@ -43,7 +43,7 @@
 public class RemoteShellProxy
     implements RemoteShell, InteractiveShell
 {
-    private Logger log = LoggerFactory.getLogger(getClass());
+    private final Logger log = LoggerFactory.getLogger(getClass());
 
     private RshClient client;
 
@@ -71,11 +71,15 @@
         
         client.openShell();
 
+        //
+        // HACK: Turn this off for the moment to test more...
+        //
+        
         // Copy the client's input stream to our outputstream so users see command output
-        outputFeeder = new StreamFeeder(client.getInputStream(), io.outputStream);
-        outputFeeder.createThread().start();
+        // outputFeeder = new StreamFeeder(client.getInputStream(), io.outputStream);
+        // outputFeeder.createThread().start();
 
-        this.opened = true;             
+        opened = true;
     }
 
     public Environment getEnvironment() {
@@ -101,9 +105,9 @@
     }
 
     public void close() {
-        try {
-            outputFeeder.close();
+        // outputFeeder.close();
 
+        try {
             client.closeShell();
         }
         catch (Exception e) {
@@ -186,7 +190,7 @@
 
             public String prompt() {
                 //
-                // FIXME:
+                // TODO: Get the real details and ue them...
                 //
 
                 String userName = "user"; // shellInfo.getUserName();
@@ -202,11 +206,8 @@
                 assert error != null;
 
                 //
-                // FIXME:
+                // TODO: Do something here...
                 //
-                
-                log.error("FIXME: " + error, error);
-
 
                 return Result.CONTINUE;
             }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java Wed Sep 19 21:55:19 2007
@@ -63,8 +63,8 @@
         this.crypto = crypto;
 
         // And then lets connect to the remote server
-        transport = factory.connect(remote, local);
-
+        this.transport = factory.connect(remote, local);
+        
         log.debug("Connected to: {}", remote);
     }
 
@@ -72,17 +72,17 @@
         assert username != null;
         assert password != null;
 
-        log.info("Starting handshake", username);
+        log.debug("Starting handshake", username);
 
         HandShakeMessage.Result handShakeResult = (HandShakeMessage.Result) transport.request(new HandShakeMessage(crypto.getPublicKey()));
         
         PublicKey serverKey = handShakeResult.getPublicKey();
 
-        log.info("Logging in: {}", username);
+        log.debug("Logging in: {}", username);
 
         LoginMessage.Result loginResult = (LoginMessage.Result) transport.request(new LoginMessage(serverKey, username, password));
 
-        log.info("Login Result: {}", loginResult);
+        log.debug("Login Result: {}", loginResult);
     }
     
     public void echo(final String text) throws Exception {
@@ -92,19 +92,27 @@
     }
 
     public void openShell() throws Exception {
-        log.info("Opening remote shell");
+        log.debug("Opening remote shell");
 
         Message resp = transport.request(new OpenShellMessage());
 
-        log.info("Response: {}", resp);
+        //
+        // TODO: Need some context from the response
+        //
+
+        // log.debug("Response: {}", resp);
     }
 
     public void closeShell() throws Exception {
-        log.info("Closing remote shell");
+        log.debug("Closing remote shell");
 
         Message resp = transport.request(new CloseShellMessage());
 
-        log.info("Response: {}", resp);
+        //
+        // TODO: Need some context from the response
+        //
+        
+        // log.debug("Response: {}", resp);
     }
 
     private Object doExecute(final ExecuteMessage msg) throws Exception {
@@ -112,17 +120,6 @@
 
         ExecuteMessage.Result result = (ExecuteMessage.Result) transport.request(msg);
 
-        // Handle result faults
-        if (result instanceof ExecuteMessage.Fault) {
-            ExecuteMessage.Fault fault = (ExecuteMessage.Fault)result;
-
-            //
-            // FIXME: Use better exception type here
-            //
-            
-            throw new Exception("Remote command execution fault", fault.getCause());
-        }
-
         // Handle result notifications
         if (result instanceof ExecuteMessage.Notification) {
             ExecuteMessage.Notification n = (ExecuteMessage.Notification)result;
@@ -130,9 +127,16 @@
             throw n.getNotification();
         }
 
+        // Handle result faults
+        if (result instanceof ExecuteMessage.Fault) {
+            ExecuteMessage.Fault fault = (ExecuteMessage.Fault)result;
+
+            throw new RemoteExecuteException(fault.getCause());
+        }
+
         Object rv = result.getResult();
 
-        log.info("Command result: {}", rv);
+        log.debug("Command result: {}", rv);
 
         return rv;
     }
@@ -140,24 +144,18 @@
     public Object execute(final String line) throws Exception {
         assert line != null;
 
-        log.info("Executing (String): {}", line);
-
         return doExecute(new ExecuteMessage(line));
     }
 
     public Object execute(final Object... args) throws Exception {
         assert args != null;
 
-        log.info("Executing (Object[]): {}", args);
-
         return doExecute(new ExecuteMessage(args));
     }
 
     public Object execute(final String path, final Object[] args) throws Exception {
         assert path != null;
         assert args != null;
-
-        log.info("Executing (String,Object[]): {}, {}", path, args);
 
         return doExecute(new ExecuteMessage(path, args));
     }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java Wed Sep 19 21:55:19 2007
@@ -45,7 +45,7 @@
     @Argument(metaVar="URI", required=true, index=0)
     private URI remote;
 
-    @Argument(metaVar="COMMAND", index=1)
+    @Argument(metaVar="COMMAND", index=1, multiValued=true)
     private List<String> command = new ArrayList<String>();
 
     @Requirement
@@ -65,6 +65,8 @@
 
         client.login("jason", "password");
 
+        // client.echo("NOISE MAKER");
+        
         RemoteShellProxy shell = new RemoteShellProxy(client, io, terminal);
 
         shell.run(command.toArray());

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MarshallingUtil.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MarshallingUtil.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MarshallingUtil.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MarshallingUtil.java Wed Sep 19 21:55:19 2007
@@ -19,13 +19,13 @@
 
 package org.apache.geronimo.gshell.remote.codec;
 
-import java.io.IOException;
 import java.io.ByteArrayInputStream;
-import java.io.ObjectInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.nio.charset.Charset;
 import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
 import java.util.UUID;
 
 import org.apache.mina.common.ByteBuffer;

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MessageCodecFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MessageCodecFactory.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MessageCodecFactory.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MessageCodecFactory.java Wed Sep 19 21:55:19 2007
@@ -22,26 +22,29 @@
 import java.io.ByteArrayOutputStream;
 import java.nio.channels.Channels;
 import java.nio.channels.WritableByteChannel;
-import java.util.Set;
 import java.util.Arrays;
+import java.util.Set;
 
-import org.apache.geronimo.gshell.remote.message.Message;
-import org.apache.geronimo.gshell.remote.message.MessageType;
 import org.apache.geronimo.gshell.remote.crypto.CryptoContext;
 import org.apache.geronimo.gshell.remote.crypto.CryptoContextAware;
+import org.apache.geronimo.gshell.remote.message.Message;
+import org.apache.geronimo.gshell.remote.message.MessageType;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecException;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.apache.mina.filter.codec.ProtocolEncoderOutput;
-import org.apache.mina.filter.codec.ProtocolCodecException;
 import org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory;
+import org.apache.mina.filter.codec.demux.MessageDecoder;
 import org.apache.mina.filter.codec.demux.MessageDecoderAdapter;
+import org.apache.mina.filter.codec.demux.MessageDecoderFactory;
 import org.apache.mina.filter.codec.demux.MessageDecoderResult;
 import org.apache.mina.filter.codec.demux.MessageEncoder;
+import org.apache.mina.filter.codec.demux.MessageEncoderFactory;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.component.annotations.Component;
 
 /**
  * Provides encoding and decoding support for {@link Message} instances.
@@ -68,16 +71,15 @@
     private CryptoContext crypto;
 
     public MessageCodecFactory() {
-        register(new Decoder());
+        register(new DecoderFactory());
 
-        //noinspection unchecked
-        register(new Encoder());
+        register(new EncoderFactory());
     }
 
     private void attachCryptoContext(final Message msg) {
         // We need to do a little bit of extra fluff to hook up support for encrypted messages
         if (msg instanceof CryptoContextAware) {
-            log.debug("Attaching crypto context to: {}", msg);
+            log.trace("Attaching crypto context to: {}", msg);
 
             ((CryptoContextAware)msg).setCryptoContext(crypto);
         }
@@ -124,7 +126,7 @@
     private byte[] marshal(final Message msg) throws Exception {
         assert msg != null;
 
-        log.debug("Marshalling: {}", msg);
+        log.trace("Marshalling: {}", msg);
         
         ByteBuffer out = ByteBuffer.allocate(256, false);
         out.setAutoExpand(true);
@@ -160,7 +162,7 @@
 
         byte[] bytes = baos.toByteArray();
 
-        log.debug("Marshalled size: {} bytes", bytes.length);
+        log.trace("Marshalled size: {} bytes", bytes.length);
 
         return bytes;
     }
@@ -169,6 +171,14 @@
     // Encoder
     //
 
+    public class EncoderFactory
+        implements MessageEncoderFactory
+    {
+        public MessageEncoder getEncoder() throws Exception {
+            return new Encoder();
+        }
+    }
+
     public class Encoder
         implements MessageEncoder
     {
@@ -183,13 +193,13 @@
 
             Message msg = (Message)message;
 
-            log.debug("Encoding: {}", msg);
+            log.trace("Encoding: {}", msg);
 
             attachCryptoContext(msg);
 
             byte[] bytes = marshal(msg);
 
-            log.debug("Encoded {} bytes", bytes.length);
+            log.trace("Encoded {} bytes", bytes.length);
 
             out.write(ByteBuffer.wrap(bytes));
         }
@@ -199,6 +209,14 @@
     // Decoder
     //
 
+    public class DecoderFactory
+        implements MessageDecoderFactory
+    {
+        public MessageDecoder getDecoder() throws Exception {
+            return new Decoder();
+        }
+    }
+
     public class Decoder
         extends MessageDecoderAdapter
     {
@@ -252,11 +270,11 @@
 
             int len = in.getInt();
 
-            log.debug("Decoding {} bytes", len);
+            log.trace("Decoding {} bytes", len);
 
             msg.readExternal(in);
 
-            log.debug("Decoded: {}", msg);
+            log.trace("Decoded: {}", msg);
 
             out.write(msg);
 

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/package-info.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/package-info.java?rev=577545&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/package-info.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/package-info.java Wed Sep 19 21:55:19 2007
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Encoding and decoding fluff.
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.geronimo.gshell.remote.codec;
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/logging/LoggingFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/logging/LoggingFilter.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/logging/LoggingFilter.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/logging/LoggingFilter.java Wed Sep 19 21:55:19 2007
@@ -29,16 +29,15 @@
 public class LoggingFilter
     extends org.apache.mina.filter.logging.LoggingFilter
 {
-    public static final String NAME = "logging";
-    
     public LoggingFilter() {
-        setLogLevel(IoEventType.EXCEPTION_CAUGHT, WARN);
-        setLogLevel(IoEventType.WRITE, TRACE);
-        setLogLevel(IoEventType.MESSAGE_RECEIVED, TRACE);
-        setLogLevel(IoEventType.MESSAGE_SENT, TRACE);
-        setLogLevel(IoEventType.SESSION_CLOSED, DEBUG);
-        setLogLevel(IoEventType.SESSION_CREATED, DEBUG);
-        setLogLevel(IoEventType.SESSION_IDLE, DEBUG);
-        setLogLevel(IoEventType.SESSION_OPENED, DEBUG);
+        setLogLevel(IoEventType.EXCEPTION_CAUGHT,   WARN);
+        setLogLevel(IoEventType.MESSAGE_RECEIVED,   DEBUG);
+        setLogLevel(IoEventType.MESSAGE_SENT,       DEBUG);
+        setLogLevel(IoEventType.SESSION_CLOSED,     DEBUG);
+        setLogLevel(IoEventType.SESSION_CREATED,    DEBUG);
+        setLogLevel(IoEventType.SESSION_IDLE,       DEBUG);
+        setLogLevel(IoEventType.SESSION_OPENED,     DEBUG);
+        setLogLevel(IoEventType.WRITE,              DEBUG);
+        setLogLevel(IoEventType.CLOSE,              DEBUG);
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CryptoAwareMessageSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CryptoAwareMessageSupport.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CryptoAwareMessageSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CryptoAwareMessageSupport.java Wed Sep 19 21:55:19 2007
@@ -21,6 +21,7 @@
 
 import java.security.Key;
 
+import org.apache.geronimo.gshell.remote.codec.MarshallingUtil;
 import org.apache.geronimo.gshell.remote.crypto.CryptoContext;
 import org.apache.geronimo.gshell.remote.crypto.CryptoContextAware;
 import org.apache.mina.common.ByteBuffer;
@@ -57,7 +58,7 @@
     protected String decryptString(final ByteBuffer in) throws Exception {
         assert in != null;
 
-        byte[] bytes = readBytes(in);
+        byte[] bytes = MarshallingUtil.readBytes(in);
         
         if (bytes == null) {
             return null;
@@ -78,7 +79,7 @@
             bytes = getCryptoContext().encrypt(key, str.getBytes());
         }
 
-        writeBytes(out, bytes);
+        MarshallingUtil.writeBytes(out, bytes);
     }
 
     protected void encryptString(final ByteBuffer out, final String str) throws Exception {

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java Wed Sep 19 21:55:19 2007
@@ -19,6 +19,7 @@
 
 package org.apache.geronimo.gshell.remote.message;
 
+import org.apache.geronimo.gshell.remote.codec.MarshallingUtil;
 import org.apache.mina.common.ByteBuffer;
 
 /**
@@ -50,7 +51,7 @@
 
         super.readExternal(in);
 
-        text = readString(in);
+        text = MarshallingUtil.readString(in);
     }
 
     public void writeExternal(final ByteBuffer out) throws Exception {
@@ -58,7 +59,7 @@
 
         super.writeExternal(out);
 
-        writeString(out, text);
+        MarshallingUtil.writeString(out, text);
     }
 
     public void process(final MessageVisitor visitor) throws Exception {

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/ExecuteMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/ExecuteMessage.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/ExecuteMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/ExecuteMessage.java Wed Sep 19 21:55:19 2007
@@ -20,6 +20,7 @@
 package org.apache.geronimo.gshell.remote.message;
 
 import org.apache.geronimo.gshell.command.CommandExecutor;
+import org.apache.geronimo.gshell.remote.codec.MarshallingUtil;
 import org.apache.mina.common.ByteBuffer;
 
 /**
@@ -73,9 +74,9 @@
 
         this.flavor = in.getEnum(Flavor.class);
 
-        this.path = readString(in);
+        this.path = MarshallingUtil.readString(in);
 
-        this.args = (Object[]) readObject(in);
+        this.args = (Object[]) MarshallingUtil.readObject(in);
     }
 
     public void writeExternal(final ByteBuffer out) throws Exception {
@@ -85,9 +86,9 @@
 
         out.putEnum(flavor);
 
-        writeString(out, path);
+        MarshallingUtil.writeString(out, path);
 
-        writeObject(out, args);
+        MarshallingUtil.writeObject(out, args);
     }
 
     public void process(final MessageVisitor visitor) throws Exception {
@@ -160,7 +161,7 @@
 
             super.readExternal(in);
 
-            result = readObject(in);
+            result = MarshallingUtil.readObject(in);
         }
 
         public void writeExternal(final ByteBuffer out) throws Exception {
@@ -168,7 +169,7 @@
 
             super.writeExternal(out);
 
-            writeObject(out, result);
+            MarshallingUtil.writeObject(out, result);
         }
     }
 

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java Wed Sep 19 21:55:19 2007
@@ -21,6 +21,7 @@
 
 import java.security.PublicKey;
 
+import org.apache.geronimo.gshell.remote.codec.MarshallingUtil;
 import org.apache.mina.common.ByteBuffer;
 
 //
@@ -69,7 +70,7 @@
 
         super.readExternal(in);
 
-        byte[] bytes = readBytes(in);
+        byte[] bytes = MarshallingUtil.readBytes(in);
         
         if (bytes == null) {
             throw new IllegalStateException();
@@ -83,7 +84,7 @@
 
         super.writeExternal(out);
 
-        writeBytes(out, getPublicKey().getEncoded());
+        MarshallingUtil.writeBytes(out, getPublicKey().getEncoded());
     }
 
     /**

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/LoginMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/LoginMessage.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/LoginMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/LoginMessage.java Wed Sep 19 21:55:19 2007
@@ -52,6 +52,7 @@
         this.serverKey = serverKey;
 
         this.username = username;
+        
         this.password = password;
     }
 

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java Wed Sep 19 21:55:19 2007
@@ -20,9 +20,8 @@
 package org.apache.geronimo.gshell.remote.message;
 
 import java.io.IOException;
-import java.util.UUID;
 
-import org.apache.mina.common.ByteBuffer;
+import org.apache.geronimo.gshell.remote.codec.Externalizable;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
 
@@ -32,12 +31,13 @@
  * @version $Rev$ $Date$
  */
 public interface Message
+    extends Externalizable
 {
-    UUID getId();
+    Object getId();
 
-    UUID getCorrelationId();
+    Object getCorrelationId();
 
-    void setCorrelationId(UUID id);
+    void setCorrelationId(Object id);
 
     MessageType getType() throws IOException;
 
@@ -56,8 +56,4 @@
     boolean isFrozen();
 
     WriteFuture reply(Message msg);
-
-    void readExternal(ByteBuffer in) throws Exception;
-
-    void writeExternal(ByteBuffer out) throws Exception;
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java Wed Sep 19 21:55:19 2007
@@ -19,17 +19,12 @@
 
 package org.apache.geronimo.gshell.remote.message;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.util.UUID;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.remote.codec.MarshallingUtil;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
@@ -42,13 +37,15 @@
 public abstract class MessageSupport
     implements Message
 {
+    private static final AtomicLong ID_COUNTER = new AtomicLong(0);
+
     private static final AtomicLong SEQUENCE_COUNTER = new AtomicLong(0);
 
-    private transient MessageType type;
+    private MessageType type;
 
-    private UUID id;
+    private Object id;
 
-    private UUID correlationId;
+    private Object correlationId;
 
     private Long sequence;
 
@@ -63,32 +60,32 @@
         
         this.type = type;
 
-        this.id = UUID.randomUUID();
+        this.id = ID_COUNTER.getAndIncrement();
 
         this.timestamp = System.currentTimeMillis();
     }
 
     public String toString() {
-        return ReflectionToStringBuilder.toString(this);
+        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
     }
 
     public MessageType getType() throws IOException {
         return type;
     }
 
-    public UUID getId() {
+    public Object getId() {
         return id;
     }
     
-    public UUID getCorrelationId() {
+    public Object getCorrelationId() {
         return correlationId;
     }
 
-    public void setCorrelationId(final UUID id) {
-        assert id != null;
-        
+    public void setCorrelationId(final Object id) {
         ensureWritable();
-        
+
+        assert id != null;
+
         this.correlationId = id;
     }
 
@@ -148,15 +145,15 @@
     }
     
     //
-    // Serialization
+    // Externalization
     //
 
     public void readExternal(final ByteBuffer in) throws Exception {
         assert in != null;
 
-        id = readUuid(in);
+        id = MarshallingUtil.readObject(in);
 
-        correlationId = readUuid(in);
+        correlationId = MarshallingUtil.readObject(in);
 
         timestamp = in.getLong();
 
@@ -166,221 +163,14 @@
     public void writeExternal(final ByteBuffer out) throws Exception {
         assert out != null;
 
-        writeUuid(out, id);
+        MarshallingUtil.writeObject(out, id);
 
-        writeUuid(out, correlationId);
+        MarshallingUtil.writeObject(out, correlationId);
 
         out.putLong(timestamp);
 
         sequence = SEQUENCE_COUNTER.getAndIncrement();
         
         out.putLong(sequence);
-    }
-
-    //
-    // Boolean Serialization
-    //
-
-    private static final byte TRUE = 1;
-
-    private static final byte FALSE = 0;
-
-    protected boolean readBoolean(final ByteBuffer in) {
-        assert in != null;
-
-        byte b = in.get();
-
-        if (b == TRUE) {
-            return true;
-        }
-        else if (b == FALSE) {
-            return false;
-        }
-        else {
-            throw new Error();
-        }
-    }
-
-    protected void writeBoolean(final ByteBuffer out, final boolean bool) {
-        assert out != null;
-
-        if (bool) {
-            out.put(TRUE);
-        }
-        else {
-            out.put(FALSE);
-        }
-    }
-
-    //
-    // Byte[] Serialization
-    //
-
-    protected byte[] readBytes(final ByteBuffer in) {
-        assert in != null;
-
-        boolean isNull = readBoolean(in);
-
-        if (isNull) {
-            return null;
-        }
-
-        int len = in.getInt();
-
-        byte[] bytes = new byte[len];
-
-        in.get(bytes);
-
-        return bytes;
-    }
-
-    protected void writeBytes(final ByteBuffer out, final byte[] bytes) {
-        assert out != null;
-
-        if (bytes == null) {
-            writeBoolean(out, true);
-        }
-        else {
-            writeBoolean(out, false);
-
-            out.putInt(bytes.length);
-
-            out.put(bytes);
-        }
-    }
-
-    //
-    // ByteBuffer Serialization
-    //
-
-    protected ByteBuffer readBuffer(final ByteBuffer in) {
-        assert in != null;
-
-        byte[] bytes = readBytes(in);
-
-        if (bytes == null) {
-            return null;
-        }
-
-        return ByteBuffer.wrap(bytes);
-    }
-
-    protected void writeBuffer(final ByteBuffer out, final ByteBuffer buffer) {
-        assert out != null;
-
-        if (buffer == null) {
-            writeBytes(out, null);
-        }
-        else {
-            writeBoolean(out, false);
-            
-            out.putInt(buffer.remaining());
-
-            out.put(buffer);
-        }
-    }
-
-    //
-    // Object Serialization
-    //
-
-    protected Object readObject(final ByteBuffer in) throws IOException, ClassNotFoundException {
-        assert in != null;
-
-        byte[] bytes = readBytes(in);
-
-        if (bytes == null) {
-            return null;
-        }
-        
-        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-        ObjectInputStream ois = new ObjectInputStream(bais);
-
-        return ois.readObject();
-    }
-
-    protected void writeObject(final ByteBuffer out, final Object obj) throws IOException {
-        assert out != null;
-
-        byte[] bytes = null;
-
-        if (obj != null) {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            ObjectOutputStream oos = new ObjectOutputStream(baos);
-
-            oos.writeObject(obj);
-            oos.flush();
-
-            bytes = baos.toByteArray();
-        }
-
-        writeBytes(out, bytes);
-    }
-
-    //
-    // String Serialization
-    //
-
-    private static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
-
-    protected String readString(final ByteBuffer in) throws CharacterCodingException {
-        assert in != null;
-
-        int len = in.getInt();
-
-        if (len == -1) {
-            return null;
-        }
-
-        return in.getString(len, UTF_8_CHARSET.newDecoder());
-    }
-
-    protected void writeString(final ByteBuffer out, final String str) throws CharacterCodingException {
-        assert out != null;
-
-        if (str == null) {
-            out.putInt(-1);
-        }
-        else {
-            int len = str.length();
-            out.putInt(len);
-
-            out.putString(str, len, UTF_8_CHARSET.newEncoder());
-        }
-    }
-
-    //
-    // UUID Serialization
-    //
-
-    protected UUID readUuid(final ByteBuffer in) throws Exception {
-        assert in != null;
-
-        boolean isNull = readBoolean(in);
-
-        if (isNull) {
-            return null;
-        }
-
-        long msb = in.getLong();
-        
-        long lsb = in.getLong();
-
-        return new UUID(msb, lsb);
-    }
-
-    protected void writeUuid(final ByteBuffer out, final UUID uuid) throws Exception {
-        assert out != null;
-
-        if (uuid == null) {
-            writeBoolean(out, true);
-        }
-        else {
-            writeBoolean(out, false);
-
-            out.putLong(uuid.getMostSignificantBits());
-            
-            out.putLong(uuid.getLeastSignificantBits());
-        }
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java Wed Sep 19 21:55:19 2007
@@ -19,9 +19,11 @@
 
 package org.apache.geronimo.gshell.remote.message;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
-import java.util.Collections;
+
+import org.apache.geronimo.gshell.remote.stream.WriteStreamMessage;
 
 /**
  * Enumeration of supported message types and factory for message instances.

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java?rev=577545&r1=577544&r2=577545&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java Wed Sep 19 21:55:19 2007
@@ -19,12 +19,6 @@
 
 package org.apache.geronimo.gshell.remote.message;
 
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.apache.geronimo.gshell.remote.stream.SessionInputStream;
-import org.apache.geronimo.gshell.remote.transport.Transport;
-import org.apache.mina.common.IoSession;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,33 +43,4 @@
     public void visitCloseShell(CloseShellMessage msg) throws Exception {}
 
     public void visitExecute(ExecuteMessage msg) throws Exception {}
-
-    //
-    // Stream Access
-    //
-
-    protected InputStream getInputStream(final IoSession session) {
-        assert session != null;
-
-        InputStream in = (InputStream) session.getAttribute(Transport.INPUT_STREAM);
-
-        if (in == null) {
-            throw new IllegalStateException("Input stream not bound");
-        }
-
-        return in;
-    }
-
-    protected OutputStream getOutputStream(final IoSession session) {
-        assert session != null;
-
-        OutputStream out = (OutputStream) session.getAttribute(Transport.OUTPUT_STREAM);
-
-        if (out == null) {
-            throw new IllegalStateException("Output stream not bound");
-        }
-
-
-        return out;
-    }
 }

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java?rev=577545&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java Wed Sep 19 21:55:19 2007
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.request;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateRequestException
+    extends RequestException
+{
+    public DuplicateRequestException(final Request req) {
+        super("Duplicate request for ID: " + req.getId(), req);
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java?rev=577545&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java Wed Sep 19 21:55:19 2007
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.request;
+
+//
+// NOTE: Snatched and massaged from Apache Mina
+//
+
+import java.util.NoSuchElementException;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.remote.message.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class Request
+{
+    private transient final Logger log = LoggerFactory.getLogger(getClass());
+
+    private transient final Object mutex = new Object();
+
+    private final BlockingQueue<Object> responses = new LinkedBlockingQueue<Object>();
+
+    private final Message message;
+
+    private final long timeout;
+
+    private final TimeUnit timeoutUnit;
+
+    private volatile boolean endOfResponses;
+
+    private boolean signaled;
+
+    public Request(final Message message, long timeout, final TimeUnit timeoutUnit) {
+        assert message != null;
+        assert timeoutUnit != null;
+
+        this.message = message;
+        this.timeout = timeout;
+        this.timeoutUnit = timeoutUnit;
+    }
+
+    public int hashCode() {
+        return getId().hashCode();
+    }
+
+    public boolean equals(final Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        else if (obj == null) {
+            return false;
+        }
+        else if (!(obj instanceof Request)) {
+            return false;
+        }
+
+        Request request = (Request) obj;
+
+        return getId().equals(request.getId());
+    }
+
+    public String toString() {
+        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+    }
+
+    public Message getMessage() {
+        return message;
+    }
+
+    public Object getId() {
+        return getMessage().getId();
+    }
+
+    public long getTimeout() {
+        return timeout;
+    }
+
+    public TimeUnit getTimeoutUnit() {
+        return timeoutUnit;
+    }
+
+    public boolean hasResponse() {
+        return !responses.isEmpty();
+    }
+
+    public Response awaitResponse() throws RequestTimeoutException, InterruptedException {
+        chechEndOfResponses();
+
+        log.debug("Waiting for the response...");
+
+        Response resp = decodeResponse(responses.take());
+
+        log.debug("Got response: {}", resp);
+
+        return resp;
+    }
+
+    public Response awaitResponse(final long timeout, final TimeUnit unit) throws RequestTimeoutException, InterruptedException {
+        chechEndOfResponses();
+
+        log.debug("Polling for the response...");
+
+        Response resp = decodeResponse(responses.poll(timeout, unit));
+
+        if (resp != null) {
+            log.debug("Got response: {}", resp);
+        }
+        else {
+            log.debug("Operation timed out before the response was signaled");
+        }
+
+        return resp;
+    }
+
+    public Response awaitResponseUninterruptibly() throws RequestTimeoutException {
+        while (true) {
+            try {
+                return awaitResponse();
+            }
+            catch (InterruptedException ignore) {}
+        }
+    }
+
+    private Response decodeResponse(final Object obj) {
+        if (obj instanceof Response) {
+            return (Response) obj;
+        }
+        else if (obj == null) {
+            return null;
+        }
+        else if (obj instanceof RequestTimeoutException) {
+            throw (RequestTimeoutException) obj;
+        }
+
+        // This should never happen
+        throw new InternalError();
+    }
+
+    private void chechEndOfResponses() {
+        if (endOfResponses && responses.isEmpty()) {
+            throw new NoSuchElementException("All responses has been retrieved already.");
+        }
+    }
+
+    Object getMutex() {
+        return mutex;
+    }
+
+    private void setResponse(final Object answer) {
+        signaled = true;
+
+        responses.add(answer);
+    }
+
+    void signal(final Response response) {
+        assert response != null;
+
+        synchronized (mutex) {
+            log.debug("Signal response: {}", response);
+
+            setResponse(response);
+
+            if (response.getType() != Response.Type.PARTIAL) {
+                endOfResponses = true;
+            }
+        }
+    }
+
+    void signal(final RequestTimeoutException e) {
+        assert e != null;
+
+        synchronized (mutex) {
+            log.debug("Signal timeout: " + e, e);
+
+            setResponse(e);
+
+            endOfResponses = true;
+        }
+    }
+
+    boolean isSignaled() {
+        synchronized (mutex) {
+            return signaled;
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java?rev=577545&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java Wed Sep 19 21:55:19 2007
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.request;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestException
+    extends RuntimeException
+{
+    private static final long serialVersionUID = 1;
+    
+    private final Request req;
+
+    public RequestException(final String msg, final Request req) {
+        super(msg);
+
+        assert req != null;
+        
+        this.req = req;
+    }
+
+    public Request Request() {
+        return req;
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java?rev=577545&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java Wed Sep 19 21:55:19 2007
@@ -0,0 +1,291 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.request;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+
+import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestManager
+{
+    private static final Logger log = LoggerFactory.getLogger(RequestManager.class);
+
+    private transient final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() + 1);
+
+    private final Map<Object,Request> requests = Collections.synchronizedMap(new HashMap<Object, Request>());
+
+    private final Map<Request,TimeoutTask> timeouts = Collections.synchronizedMap(new HashMap<Request,TimeoutTask>());
+    
+    //
+    // TODO: Lock on Request.getMutex()
+    //
+
+    public boolean contains(final Object id) {
+        assert id != null;
+
+        if (id instanceof Request) {
+            throw new IllegalArgumentException("Expecting a request ID, not a request");
+        }
+
+        return requests.containsKey(id);
+    }
+
+    public boolean contains(final Request req) {
+        assert req != null;
+
+        return contains(req.getId());
+    }
+
+    public void add(final Request req) {
+        assert req != null;
+
+        if (contains(req)) {
+            throw new DuplicateRequestException(req);
+        }
+
+        Object id = req.getId();
+
+        log.debug("Adding request for ID: {}", id);
+
+        requests.put(id, req);
+    }
+
+    public Request get(final Object id) {
+        assert id != null;
+
+        if (id instanceof Request) {
+            throw new IllegalArgumentException("Expecting a request ID, not a request");
+        }
+
+        return requests.get(id);
+    }
+
+    public Request remove(final Object id) {
+        assert id != null;
+
+        if (id instanceof Request) {
+            throw new IllegalArgumentException("Expecting a request ID, not a request");
+        }
+
+        log.debug("Removing request for ID: {}", id);
+
+        return requests.remove(id);
+    }
+
+    public void clear() {
+        int l;
+
+        l = requests.size();
+
+        if (l > 0) {
+            log.warn("Clearing requests; purging " + l + " request(s)");
+        }
+
+        requests.clear();
+
+        l = timeouts.size();
+
+        if (l > 0) {
+            log.warn("Clearing timeouts; purging " + l + " timeouts(s)");
+        }
+
+        timeouts.clear();
+    }
+
+    //
+    // Timeouts
+    //
+
+    public void schedule(final Request request) {
+        assert request != null;
+
+        if (timeouts.containsKey(request)) {
+            throw new DuplicateRequestException(request);
+        }
+
+        Object id = request.getId();
+
+        if (request != get(id)) {
+            throw new IllegalStateException("Found invalid request mapping for ID: " + id);
+        }
+
+        log.debug("Scheduling timeout for request ID: {}", id);
+
+        TimeoutTask task = new TimeoutTask(request);
+
+        ScheduledFuture<?> tf = scheduler.schedule(task, request.getTimeout(), request.getTimeoutUnit());
+
+        task.setTimeoutFuture(tf);
+
+        timeouts.put(request, task);
+    }
+
+    public void cancel(final Request request) {
+        assert request != null;
+
+        Object id = request.getId();
+
+        TimeoutTask task = timeouts.remove(request);
+
+        if (task == null) {
+            throw new IllegalStateException("Request ID has no timeout bound: " + id);
+        }
+
+        if (remove(id) != request) {
+            throw new IllegalStateException("Found invalid request mapping for ID: " + id);
+        }
+
+        log.debug("Canceling timeout for request ID: {}", id);
+
+        ScheduledFuture<?> sf = task.getTimeoutFuture();
+
+        if (sf != null) {
+            sf.cancel(false);
+        }
+    }
+
+    private void timeout(final Request request) {
+        assert request != null;
+
+        Object id = request.getId();
+
+        log.debug("Triggering timeout for request ID: {}", id);
+
+        TimeoutTask task = timeouts.remove(request);
+
+        if (task == null) {
+            throw new IllegalStateException("Request ID has no timeout bound: " + id);
+        }
+
+        if (remove(id) != request) {
+            throw new IllegalStateException("Found invalid request mapping for ID: " + id);
+        }
+
+        log.debug("Canceling timeout for request ID: {}", id);
+
+        // If the request has not been signaled, then its a timeout :-(
+        if (!request.isSignaled()) {
+            // noinspection ThrowableInstanceNeverThrown
+            request.signal(new RequestTimeoutException(request));
+        }
+    }
+
+    public void timeoutAll() {
+        log.debug("Timing out all pending tasks");
+
+        Request[] requests = timeouts.keySet().toArray(new Request[timeouts.size()]);
+
+        for (Request request : requests) {
+            timeout(request);
+        }
+    }
+
+    public void close() {
+        log.debug("Closing");
+
+        timeoutAll();
+        clear();
+    }
+
+    //
+    // TimeoutTask
+    //
+
+    private class TimeoutTask
+        implements Runnable
+    {
+        private final Request request;
+
+        private ScheduledFuture<?> timeoutFuture;
+
+        private TimeoutTask(final Request request) {
+            assert request != null;
+
+            this.request = request;
+        }
+
+        public void run() {
+            timeout(request);
+        }
+
+        public void setTimeoutFuture(final ScheduledFuture<?> timeoutFuture) {
+            assert timeoutFuture != null;
+
+            this.timeoutFuture = timeoutFuture;
+        }
+
+        public ScheduledFuture<?> getTimeoutFuture() {
+            return timeoutFuture;
+        }
+    }
+
+    //
+    // Session Access
+    //
+    
+    public static RequestManager lookup(final IoSession session) {
+        assert session != null;
+
+        RequestManager manager = (RequestManager) session.getAttribute(RequestManager.class.getName());
+
+        if (manager == null) {
+            throw new IllegalStateException("Request manager not bound");
+        }
+
+        log.trace("Looked up: {}", manager);
+        
+        return manager;
+    }
+
+    public static void bind(final IoSession session, final RequestManager manager) {
+        assert session != null;
+        assert manager != null;
+
+        if (session.containsAttribute(RequestManager.class.getName())) {
+            throw new IllegalStateException("Request manager already bound");
+        }
+        
+        session.setAttribute(RequestManager.class.getName(), manager);
+
+        log.trace("Bound: {}", manager);
+    }
+
+    public static RequestManager unbind(final IoSession session) {
+        assert session != null;
+
+        RequestManager manager = (RequestManager) session.removeAttribute(RequestManager.class.getName());
+
+        log.trace("Unbound: {}", manager);
+
+        return manager;
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java?rev=577545&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java Wed Sep 19 21:55:19 2007
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.request;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.geronimo.gshell.remote.message.Message;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteRequest;
+import org.apache.mina.common.WriteRequestWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestResponseFilter
+    extends IoFilterAdapter
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final ExecutorService executor;
+
+    public RequestResponseFilter(final ExecutorService executor) {
+        assert executor != null;
+
+        this.executor = executor;
+    }
+
+    public RequestResponseFilter() {
+        this(Executors.newCachedThreadPool());
+    }
+
+    public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception {
+        log.debug("Creating request manager");
+
+        RequestManager.bind(session, new RequestManager());
+
+        nextFilter.sessionCreated(session);
+    }
+
+    public void sessionClosed(final NextFilter nextFilter, final IoSession session) throws Exception {
+        log.debug("Closing request manager");
+
+        final RequestManager manager = RequestManager.unbind(session);
+
+        manager.close();
+        
+        nextFilter.sessionClosed(session);
+    }
+
+    public void messageReceived(final NextFilter nextFilter, final IoSession session, final Object message) throws Exception {
+        Message msg = null;
+
+        Object id = null;
+
+        if (message instanceof Message) {
+            msg = (Message)message;
+            
+            id = msg.getCorrelationId();
+        }
+
+        // If we have a correlation id, then we can process the response
+        if (id != null) {
+            RequestManager manager = RequestManager.lookup(session);
+
+            final Request request = manager.get(id);
+
+            // Cancel the timeout
+            manager.cancel(request);
+
+            // Setup the response and signal the request
+            final Response response = new Response(request, msg, Response.Type.WHOLE);
+
+            // Signal could block so queue it
+            Runnable task = new Runnable() {
+                public void run() {
+                    request.signal(response);
+                }
+            };
+
+            executor.execute(task);
+
+            // Do not pass on the response
+        }
+        else {
+            nextFilter.messageReceived(session, message);
+        }
+    }
+
+    public void filterWrite(final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest) throws Exception {
+        Object message = writeRequest.getMessage();
+
+        if (message instanceof Request) {
+            // Register the request with the manager
+            Request request = (Request) message;
+
+            RequestManager manager = RequestManager.lookup(session);
+            manager.add(request);
+
+            nextFilter.filterWrite(session, new RequestWriteRequest(writeRequest));
+        }
+        else {
+            nextFilter.filterWrite(session, writeRequest);
+        }
+    }
+
+    public void messageSent(final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest) throws Exception {
+        if (writeRequest instanceof RequestWriteRequest) {
+            // Setup a timeout for the request now that its been sent
+            RequestWriteRequest wr = (RequestWriteRequest) writeRequest;
+            Request request = wr.getRequest();
+
+            RequestManager manager = RequestManager.lookup(session);
+            manager.schedule(request);
+
+            // And forward the original write request
+            nextFilter.messageSent(session, wr.getWriteRequest());
+        }
+        else {
+            nextFilter.messageSent(session, writeRequest);
+        }
+    }
+
+    private static class RequestWriteRequest
+        extends WriteRequestWrapper
+    {
+        public RequestWriteRequest(final WriteRequest wr) {
+            super(wr);
+        }
+
+        public Object getMessage() {
+            return ((Request) super.getMessage()).getMessage();
+        }
+
+        public Request getRequest() {
+            return (Request) super.getWriteRequest().getMessage();
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java?rev=577545&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java Wed Sep 19 21:55:19 2007
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.request;
+
+//
+// NOTE: Snatched and massaged from Apache Mina
+//
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestTimeoutException
+    extends RequestException
+{
+    private static final long serialVersionUID = 1;
+
+    public RequestTimeoutException(final Request request) {
+        super("Request timed out: " + request, request);
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain