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/15 18:31:44 UTC

svn commit: r575934 - 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/geron...

Author: jdillon
Date: Sat Sep 15 09:31:39 2007
New Revision: 575934

URL: http://svn.apache.org/viewvc?rev=575934&view=rev
Log:
Some work getting stream i/o working over mina bits, but still allowing other messages to be handled too

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MagicNumber.java   (contents, props changed)
      - copied, changed from r575500, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MagicNumber.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MarshalAware.java   (contents, props changed)
      - copied, changed from r575500, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MarshalAware.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java   (contents, props changed)
      - copied, changed from r575500, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MessageCodecFactory.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/WriteStreamMessage.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionInputStream.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionOutputStream.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamIoHandler.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/package-info.java   (with props)
Removed:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/
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/RshClient.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientProtocolHandler.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/RshProtocolHandlerSupport.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/MessageResponseInspector.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/MessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorAdapter.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerProtocolHandler.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=575934&r1=575933&r2=575934&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 Sat Sep 15 09:31:39 2007
@@ -36,6 +36,5 @@
 log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
 log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} %-5p (%t) [%c] %m%n
 
-log4j.logger.org.springframework=WARN
-log4j.logger.org.apache.xbean.spring=WARN
-
+log4j.logger.org.apache.geronimo.gshell.remote.server.RshServerProtocolHandler.IoSessionLogger=INFO
+log4j.logger.org.apache.geronimo.gshell.remote.client.RshClientProtocolHandler.IoSessionLogger=INFO

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=575934&r1=575933&r2=575934&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 Sat Sep 15 09:31:39 2007
@@ -19,20 +19,23 @@
 
 package org.apache.geronimo.gshell.remote.client;
 
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.InetSocketAddress;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.geronimo.gshell.remote.RshProtocolHandlerSupport;
 import org.apache.geronimo.gshell.remote.message.EchoMessage;
 import org.apache.geronimo.gshell.remote.message.HandShakeMessage;
 import org.apache.geronimo.gshell.remote.message.Message;
-import org.apache.geronimo.gshell.remote.message.MessageResponseInspector;
-import org.apache.geronimo.gshell.remote.message.codec.MessageCodecFactory;
+import org.apache.geronimo.gshell.remote.message.MessageCodecFactory;
 import org.apache.geronimo.gshell.remote.ssl.BogusSSLContextFactory;
 import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
+import org.apache.mina.common.IoEventType;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
@@ -44,6 +47,7 @@
 import org.apache.mina.filter.ssl.SSLFilter;
 import org.apache.mina.transport.socket.nio.SocketConnector;
 import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.InstantiationStrategy;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -53,7 +57,7 @@
  *
  * @version $Rev$ $Date$
  */
-@Component(role=RshClient.class)
+@Component(role=RshClient.class, instantiationStrategy=InstantiationStrategy.PER_LOOKUP)
 public class RshClient
 {
     public static final int CONNECT_TIMEOUT = 3000;
@@ -89,11 +93,23 @@
         connector.setHandler(handler);
 
         DefaultIoFilterChainBuilder filterChain = connector.getFilterChain();
-        filterChain.addLast("logger", new LoggingFilter());
+
+        LoggingFilter loggingFilter = new LoggingFilter();
+        loggingFilter.setLogLevel(IoEventType.EXCEPTION_CAUGHT, LoggingFilter.WARN);
+        loggingFilter.setLogLevel(IoEventType.WRITE, LoggingFilter.TRACE);
+        loggingFilter.setLogLevel(IoEventType.MESSAGE_RECEIVED, LoggingFilter.TRACE);
+        loggingFilter.setLogLevel(IoEventType.MESSAGE_SENT, LoggingFilter.TRACE);
+        loggingFilter.setLogLevel(IoEventType.SESSION_CLOSED, LoggingFilter.DEBUG);
+        loggingFilter.setLogLevel(IoEventType.SESSION_CREATED, LoggingFilter.DEBUG);
+        loggingFilter.setLogLevel(IoEventType.SESSION_IDLE, LoggingFilter.DEBUG);
+        loggingFilter.setLogLevel(IoEventType.SESSION_OPENED, LoggingFilter.DEBUG);
+        filterChain.addLast("logger", loggingFilter);
+
         filterChain.addLast("protocol", new ProtocolCodecFilter(new MessageCodecFactory()));
 
         ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
-        filterChain.addLast("reqres", new RequestResponseFilter(new MessageResponseInspector(), scheduler));
+
+        filterChain.addLast("reqres", new RequestResponseFilter(handler.getResponseInspector(), scheduler));
 
         if (ssl) {
             SSLFilter sslFilter = new SSLFilter(BogusSSLContextFactory.getInstance(false));
@@ -172,5 +188,25 @@
         Response resp = request(msg, 5, TimeUnit.SECONDS);
 
         log.info("Response: {}", resp.getMessage());
+    }
+
+    public InputStream getInputStream() {
+        return (InputStream) session.getAttribute(RshProtocolHandlerSupport.INPUT_STREAM);
+    }
+
+    public OutputStream getOutputStream() {
+        return (OutputStream) session.getAttribute(RshProtocolHandlerSupport.OUTPUT_STREAM);
+    }
+
+    public void close() {
+        if (isConnected()) {
+            session.close().awaitUninterruptibly();
+            
+            session = null;
+            connector = null;
+            address = null;
+            
+            connected = false;
+        }
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.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/RshClientMessageVisitor.java?rev=575934&r1=575933&r2=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java Sat Sep 15 09:31:39 2007
@@ -19,8 +19,12 @@
 
 package org.apache.geronimo.gshell.remote.client;
 
-import org.apache.geronimo.gshell.remote.message.MessageVisitorAdapter;
+import org.apache.geronimo.gshell.remote.RshProtocolHandlerSupport;
 import org.apache.geronimo.gshell.remote.message.EchoMessage;
+import org.apache.geronimo.gshell.remote.message.MessageVisitorAdapter;
+import org.apache.geronimo.gshell.remote.message.WriteStreamMessage;
+import org.apache.geronimo.gshell.remote.stream.IoSessionInputStream;
+import org.apache.mina.common.IoSession;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -38,5 +42,28 @@
         assert msg != null;
 
         log.info("ECHO: {}", msg.getText());
+    }
+
+    public void visitWriteStream(final WriteStreamMessage msg) {
+        assert msg != null;
+
+        IoSession session = (IoSession) msg.getAttachment();
+        assert session != null;
+
+        // Look up the bound stream in the session context
+        String key = RshProtocolHandlerSupport.STREAM_BASENAME + msg.getName();
+        Object stream = session.getAttribute(key);
+
+        // For now lets not toss any exceptions or send back any fault messages
+        if (stream == null) {
+            log.error("Stream is not registered: {}", key);
+        }
+        else if (!(stream instanceof IoSessionInputStream)) {
+            log.error("Stream is not for input: {}", key);
+        }
+        else {
+            IoSessionInputStream in = (IoSessionInputStream)stream;
+            in.write(msg.getBuffer());
+        }
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientProtocolHandler.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/RshClientProtocolHandler.java?rev=575934&r1=575933&r2=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientProtocolHandler.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientProtocolHandler.java Sat Sep 15 09:31:39 2007
@@ -20,61 +20,17 @@
 package org.apache.geronimo.gshell.remote.client;
 
 import org.apache.geronimo.gshell.remote.RshProtocolHandlerSupport;
-import org.apache.geronimo.gshell.remote.message.Message;
-import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.reqres.Response;
 import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.InstantiationStrategy;
 
 /**
  * ???
  *
  * @version $Rev$ $Date$
  */
-@Component(role=IoHandler.class, hint="rsh-client")
+@Component(role=IoHandler.class, hint="rsh-client", instantiationStrategy= InstantiationStrategy.PER_LOOKUP)
 public class RshClientProtocolHandler
     extends RshProtocolHandlerSupport
 {
-    private MessageVisitor visitor;
-
-    public MessageVisitor getVisitor() {
-        return visitor;
-    }
-
-    public void setVisitor(final MessageVisitor visitor) {
-        this.visitor = visitor;
-    }
-
-    public void messageReceived(final IoSession session, final Object message) throws Exception {
-        assert session != null;
-        assert message != null;
-
-        super.messageReceived(session, message);
-
-        if (message instanceof Message) {
-            Message msg = (Message)message;
-
-            log.info("MSG: {}", msg);
-
-            msg.setAttachment(session);
-
-            msg.setAttachment(session);
-
-            if (visitor != null) {
-                msg.process(visitor);
-            }
-        }
-        else if (message instanceof Response) {
-            Response resp = (Response)message;
-
-            Message reqMsg = (Message)resp.getRequest().getMessage();
-            Message respMsg = (Message)resp.getMessage();
-
-            log.info("RX respose; req={}, resp={}", reqMsg, respMsg);
-        }
-        else {
-            log.error("Unhandled message: {}", message);
-        }
-    }
 }

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=575934&r1=575933&r2=575934&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 Sat Sep 15 09:31:39 2007
@@ -19,6 +19,13 @@
 
 package org.apache.geronimo.gshell.remote.client;
 
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.Date;
+
 import org.apache.geronimo.gshell.command.CommandSupport;
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
 import org.codehaus.plexus.component.annotations.Requirement;
@@ -32,6 +39,10 @@
 public class RshCommand
     extends CommandSupport
 {
+    //
+    // TODO: Use a URI
+    //
+    
     private String hostname = "localhost";
 
     private int port = 9999;
@@ -45,6 +56,61 @@
         client.echo("TESTING");
 
         client.handshake();
+
+        client.echo("READ_STREAMS");
+
+        OutputStream out = client.getOutputStream();
+        final PrintWriter writer = new PrintWriter(out);
+
+        InputStream in = client.getInputStream();
+        final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+
+        Thread t = new Thread("Stream Consumer") {
+            public void run() {
+                try {
+                    log.debug("Consumer running...");
+
+                    String line;
+                    while ((line = reader.readLine()) != null) {
+                        System.err.println(line);
+                    }
+
+                    log.debug("Consumer stopped");
+                }
+                catch (Exception e) {
+                    log.error(e.getMessage(), e);
+                }
+            }
+        };
+
+        t.start();
+
+        Thread t2 = new Thread("Noise Maker") {
+            public void run() {
+                try {
+                    log.debug("Noise Maker...");
+
+                    while (true) {
+                        writer.println("FROM CLIENT: " + new Date());
+                        writer.flush();
+
+                        Thread.sleep(1000 * 5);
+                    }
+
+                    // log.debug("Noise Maker stopped");
+                }
+                catch (Exception e) {
+                    log.error(e.getMessage(), e);
+                }
+            }
+        };
+
+        t2.start();
+
+        t.join();
+        t2.join();
+        
+        client.close();
         
         return SUCCESS;
     }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/RshProtocolHandlerSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/RshProtocolHandlerSupport.java?rev=575934&r1=575933&r2=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/RshProtocolHandlerSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/RshProtocolHandlerSupport.java Sat Sep 15 09:31:39 2007
@@ -19,9 +19,18 @@
 
 package org.apache.geronimo.gshell.remote;
 
+import org.apache.geronimo.gshell.remote.message.Message;
+import org.apache.geronimo.gshell.remote.message.MessageResponseInspector;
+import org.apache.geronimo.gshell.remote.message.MessageVisitor;
+import org.apache.geronimo.gshell.remote.stream.IoSessionInputStream;
+import org.apache.geronimo.gshell.remote.stream.IoSessionOutputStream;
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.reqres.Request;
+import org.apache.mina.filter.reqres.Response;
+import org.apache.mina.filter.reqres.ResponseInspector;
+import org.codehaus.plexus.util.IOUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -33,22 +42,100 @@
 public abstract class RshProtocolHandlerSupport
     implements IoHandler
 {
+    public static final String STREAM_BASENAME = "org.apache.geronimo.gshell.remote.stream.";
+
+    public static final String INPUT_STREAM = STREAM_BASENAME + "IN";
+
+    public static final String OUTPUT_STREAM = STREAM_BASENAME + "OUT";
+
+    public static final String ERROR_STREAM = STREAM_BASENAME + "ERR";
+
     protected Logger log = LoggerFactory.getLogger(getClass());
 
+    protected MessageVisitor visitor;
+
+    protected MessageResponseInspector responseInspector = new MessageResponseInspector(); 
+
+    public MessageVisitor getVisitor() {
+        return visitor;
+    }
+
+    public void setVisitor(final MessageVisitor visitor) {
+        this.visitor = visitor;
+    }
+
+    public MessageResponseInspector getResponseInspector() {
+        return responseInspector;
+    }
+    
+    public void messageReceived(final IoSession session, final Object message) throws Exception {
+        assert session != null;
+        assert message != null;
+
+        if (message instanceof Message) {
+            Message msg = (Message)message;
+
+            if (visitor != null) {
+                msg.setAttachment(session);
+                msg.process(visitor);
+            }
+        }
+        else if (message instanceof Response) {
+            Response resp = (Response)message;
+
+            Request req = resp.getRequest();
+
+            responseInspector.deregister(req);
+        }
+        else {
+            log.error("Unhandled message: {}", message);
+        }
+    }
+
+    //
+    // IoHandler
+    //
+
     public void sessionCreated(final IoSession session) throws Exception {
         log.info("Session created: {}", session);
     }
 
     public void sessionOpened(final IoSession session) throws Exception {
         log.info("Session opened: {}", session);
+
+        IoSessionInputStream in = new IoSessionInputStream();
+        session.setAttribute(INPUT_STREAM, in);
+
+        IoSessionOutputStream out = new IoSessionOutputStream(session);
+        session.setAttribute(OUTPUT_STREAM, out);
+
+        //
+        // TODO: Add err
+        //
     }
 
     public void sessionClosed(final IoSession session) throws Exception {
         log.info("Session closed: {}", session);
+
+        IoSessionInputStream in = (IoSessionInputStream) session.getAttribute(INPUT_STREAM);
+        IOUtil.close(in);
+
+        IoSessionOutputStream out = (IoSessionOutputStream) session.getAttribute(OUTPUT_STREAM);
+        IOUtil.close(out);
+
+        //
+        // TODO: Add err
+        //
     }
 
     public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception {
         log.info("Session idle: {}, status: {}", session, status);
+
+        /*
+        if (status == IdleStatus.READER_IDLE) {
+            throw new SocketTimeoutException("Read timeout");
+        }
+        */
     }
 
     public void exceptionCaught(final IoSession session, final Throwable cause) throws Exception {
@@ -60,11 +147,13 @@
         session.close();
     }
 
-    public void messageReceived(final IoSession session, final Object message) throws Exception {
-        log.info("Message received: {}", message);
-    }
-
     public void messageSent(final IoSession session, final Object message) throws Exception {
         log.info("Message sent: {}", message);
+
+        if (message instanceof Request) {
+            Request req = (Request) message;
+
+            responseInspector.register(req);
+        }
     }
 }

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MagicNumber.java (from r575500, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MagicNumber.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/MagicNumber.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MagicNumber.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MagicNumber.java&r1=575500&r2=575934&rev=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MagicNumber.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MagicNumber.java Sat Sep 15 09:31:39 2007
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.message.codec;
+package org.apache.geronimo.gshell.remote.message;
 
 import java.util.Arrays;
 

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MagicNumber.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/message/MagicNumber.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MarshalAware.java (from r575500, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MarshalAware.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/MarshalAware.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MarshalAware.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MarshalAware.java&r1=575500&r2=575934&rev=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MarshalAware.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MarshalAware.java Sat Sep 15 09:31:39 2007
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.message.codec;
+package org.apache.geronimo.gshell.remote.message;
 
 import org.apache.mina.common.ByteBuffer;
 
@@ -28,7 +28,7 @@
  */
 public interface MarshalAware
 {
-    void readExternal(ByteBuffer buff) throws Exception;
+    void readExternal(ByteBuffer in) throws Exception;
 
-    void writeExternal(ByteBuffer buff) throws Exception;
+    void writeExternal(ByteBuffer out) throws Exception;
 }

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MarshalAware.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/message/MarshalAware.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=575934&r1=575933&r2=575934&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 Sat Sep 15 09:31:39 2007
@@ -20,8 +20,9 @@
 package org.apache.geronimo.gshell.remote.message;
 
 import java.io.IOException;
+import java.util.UUID;
 
-import org.apache.geronimo.gshell.remote.message.codec.MarshalAware;
+import org.apache.geronimo.gshell.remote.message.MarshalAware;
 
 /**
  * ???
@@ -31,7 +32,7 @@
 public interface Message
     extends MarshalAware
 {
-    long getId();
+    UUID getId();
 
     MessageType getType() throws IOException;
 

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java (from r575500, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/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/message/MessageCodecFactory.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MessageCodecFactory.java&r1=575500&r2=575934&rev=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/codec/MessageCodecFactory.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java Sat Sep 15 09:31:39 2007
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.message.codec;
+package org.apache.geronimo.gshell.remote.message;
 
 import org.apache.geronimo.gshell.remote.message.Message;
 import org.apache.geronimo.gshell.remote.message.MessageType;
@@ -80,6 +80,8 @@
             
             Message msg = (Message)message;
 
+            log.debug("Serializing: {}", msg);
+
             ByteBuffer buff = ByteBuffer.allocate(256, false);
             buff.setAutoExpand(true);
 
@@ -120,6 +122,7 @@
             MagicNumber.read(in);
 
             byte version = in.get();
+
             if (version != VERSION) {
                 throw new ProtocolDecoderException("Invalid version: " + version);
             }
@@ -129,6 +132,8 @@
             Message msg = MessageType.create(type);
 
             msg.readExternal(in);
+
+            log.debug("Deserialized: {}", msg);
 
             out.write(msg);
 

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.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/message/MessageCodecFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageResponseInspector.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/MessageResponseInspector.java?rev=575934&r1=575933&r2=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageResponseInspector.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageResponseInspector.java Sat Sep 15 09:31:39 2007
@@ -19,8 +19,15 @@
 
 package org.apache.geronimo.gshell.remote.message;
 
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.mina.filter.reqres.Request;
 import org.apache.mina.filter.reqres.ResponseInspector;
 import org.apache.mina.filter.reqres.ResponseType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * ???
@@ -30,9 +37,46 @@
 public class MessageResponseInspector
     implements ResponseInspector
 {
-    public Object getRequestId(final Object message) {
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    private Set<UUID> registeredIds = new HashSet<UUID>();
+
+    public synchronized void register(final Request req) {
+        assert req != null;
+
+        UUID id = (UUID) req.getId();
+
+        if (registeredIds.contains(id)) {
+            log.warn("Ignoring attempt to re-register request ID: {}", id);
+        }
+        else {
+            registeredIds.add(id);
+
+            log.debug("Registered request for ID: {}", id);
+        }
+    }
+
+    public synchronized void deregister(final Request req) {
+        assert req != null;
+
+        UUID id = (UUID) req.getId();
+
+        if (registeredIds.remove(id)) {
+            log.debug("Dereegistered request for ID: {}", id);
+        }
+    }
+    
+    //
+    // ResponseInspector
+    //
+    
+    public synchronized Object getRequestId(final Object message) {
         if (message instanceof Message) {
-            return ((Message)message).getId();
+            UUID id = ((Message)message).getId();
+
+            if (registeredIds.contains(id)) {
+                return id;
+            }
         }
 
         return null;

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=575934&r1=575933&r2=575934&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 Sat Sep 15 09:31:39 2007
@@ -22,7 +22,7 @@
 import java.io.IOException;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.Charset;
-import java.util.concurrent.atomic.AtomicLong;
+import java.util.UUID;
 
 import org.apache.mina.common.ByteBuffer;
 
@@ -34,11 +34,9 @@
 public abstract class MessageSupport
     implements Message
 {
-    private static final AtomicLong ID_COUNTER = new AtomicLong(0);
-
     private MessageType type;
 
-    private long id;
+    private UUID id;
     
     private transient Object attachment;
 
@@ -47,16 +45,14 @@
         
         this.type = type;
 
-        this.id = ID_COUNTER.incrementAndGet();
+        this.id = UUID.randomUUID();
     }
     
-    public long getId() {
+    public UUID getId() {
         return id;
     }
 
-    public void setId(final long id) {
-        assert id > -1;
-        
+    public void setId(final UUID id) {
         this.id = id;
     }
     
@@ -83,15 +79,15 @@
     public void readExternal(final ByteBuffer buff) throws Exception {
         assert buff != null;
 
-        id = buff.getLong();
-        
+        id = (UUID) buff.getObject();
+
         type = buff.getEnum(MessageType.class);
     }
 
     public void writeExternal(final ByteBuffer buff) throws Exception {
         assert buff != null;
 
-        buff.putLong(id);
+        buff.putObject(id);
         
         buff.putEnum(type);
     }
@@ -102,16 +98,21 @@
 
     private static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
 
-    protected String readString(final ByteBuffer buff) throws CharacterCodingException {
-        assert buff != null;
+    protected String readString(final ByteBuffer in) throws CharacterCodingException {
+        assert in != null;
+
+        int len = in.getInt();
 
-        return buff.getString(UTF_8_CHARSET.newDecoder());
+        return in.getString(len, UTF_8_CHARSET.newDecoder());
     }
 
-    protected void writeString(final ByteBuffer buff, final String str) throws CharacterCodingException {
-        assert buff != null;
+    protected void writeString(final ByteBuffer out, final String str) throws CharacterCodingException {
+        assert out != null;
         assert str != null;
 
-        buff.putString(str, UTF_8_CHARSET.newEncoder());
+        int len = str.length();
+        out.putInt(len);
+        
+        out.putString(str, len, UTF_8_CHARSET.newEncoder());
     }
 }

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=575934&r1=575933&r2=575934&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 Sat Sep 15 09:31:39 2007
@@ -26,8 +26,9 @@
  */
 public enum MessageType
 {
-    ECHO        (EchoMessage.class),
-    HANDSHAKE   (HandShakeMessage.class),
+    ECHO            (EchoMessage.class),
+    HANDSHAKE       (HandShakeMessage.class),
+    WRITE_STREAM    (WriteStreamMessage.class),
     ;
 
     private final Class<? extends Message> type;

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.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/MessageVisitor.java?rev=575934&r1=575933&r2=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java Sat Sep 15 09:31:39 2007
@@ -29,4 +29,6 @@
     void visitEcho(EchoMessage msg);
 
     void visitHandShake(HandShakeMessage msg);
+    
+    void visitWriteStream(WriteStreamMessage msg);
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorAdapter.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/MessageVisitorAdapter.java?rev=575934&r1=575933&r2=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorAdapter.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorAdapter.java Sat Sep 15 09:31:39 2007
@@ -34,4 +34,8 @@
     public void visitHandShake(HandShakeMessage msg) {
         // Empty
     }
+
+    public void visitWriteStream(WriteStreamMessage msg) {
+        // Empty
+    }
 }

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/WriteStreamMessage.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/WriteStreamMessage.java?rev=575934&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/WriteStreamMessage.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/WriteStreamMessage.java Sat Sep 15 09:31:39 2007
@@ -0,0 +1,109 @@
+/*
+ * 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.message;
+
+import org.apache.mina.common.ByteBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class WriteStreamMessage
+    extends MessageSupport
+{
+    public final Logger log = LoggerFactory.getLogger(getClass());
+
+    private String name;
+
+    private ByteBuffer buffer;
+
+    public WriteStreamMessage(final String name, final ByteBuffer buffer) {
+        super(MessageType.WRITE_STREAM);
+
+        this.name = name;
+
+        if (buffer != null) {
+            ByteBuffer tmp = ByteBuffer.allocate(buffer.remaining());
+            tmp.put(buffer);
+            tmp.flip();
+            this.buffer = tmp;
+        }
+    }
+
+    public WriteStreamMessage() {
+        this(null, null);
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(final String name) {
+        this.name = name;
+    }
+
+    public ByteBuffer getBuffer() {
+        return buffer;
+    }
+
+    public void setBuffer(final ByteBuffer buffer) {
+        this.buffer = buffer;
+    }
+
+    public String toString() {
+        return super.toString() + "{ id=" + getId() + ", name=" + name + ", buffer=" + buffer + " }";
+    }
+
+    public void readExternal(final ByteBuffer in) throws Exception {
+        assert in != null;
+
+        super.readExternal(in);
+
+        name = readString(in);
+
+        int l = in.getInt();
+
+        byte[] bytes = new byte[l];
+        in.get(bytes);
+
+        buffer = ByteBuffer.wrap(bytes);
+    }
+
+    public void writeExternal(final ByteBuffer out) throws Exception {
+        assert out != null;
+
+        super.writeExternal(out);
+
+        writeString(out, name);
+
+        out.putInt(buffer.remaining());
+
+        out.put(buffer);
+    }
+
+    public void process(final MessageVisitor visitor) throws Exception {
+        assert visitor != null;
+
+        visitor.visitWriteStream(this);
+    }
+}
\ No newline at end of file

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/WriteStreamMessage.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/message/WriteStreamMessage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java?rev=575934&r1=575933&r2=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java Sat Sep 15 09:31:39 2007
@@ -26,7 +26,6 @@
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.Socket;
-import java.net.UnknownHostException;
 import java.security.GeneralSecurityException;
 
 import javax.net.SocketFactory;

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionInputStream.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionInputStream.java?rev=575934&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionInputStream.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionInputStream.java Sat Sep 15 09:31:39 2007
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+
+//
+// NOTE: Snatched from Apache Mina
+//
+
+package org.apache.geronimo.gshell.remote.stream;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+
+/**
+ * An {@link InputStream} that buffers data read from
+ * {@link IoHandler#messageReceived(IoSession,Object)} events.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class IoSessionInputStream
+    extends InputStream
+{
+    private final Object mutex = new Object();
+
+    private final ByteBuffer buff;
+
+    private volatile boolean closed;
+
+    private volatile boolean released;
+
+    private IOException exception;
+
+    public IoSessionInputStream() {
+        buff = ByteBuffer.allocate(16);
+        buff.setAutoExpand(true);
+        buff.limit(0);
+    }
+
+    @Override
+    public int available() {
+        if (released) {
+            return 0;
+        }
+        else {
+            synchronized (mutex) {
+                return buff.remaining();
+            }
+        }
+    }
+
+    @Override
+    public void close() {
+        if (closed) {
+            return;
+        }
+
+        synchronized (mutex) {
+            closed = true;
+            releaseBuffer();
+
+            mutex.notifyAll();
+        }
+    }
+
+    @Override
+    public int read() throws IOException {
+        synchronized (mutex) {
+            if (!waitForData()) {
+                return -1;
+            }
+
+            return buff.get() & 0xff;
+        }
+    }
+
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException {
+        synchronized (mutex) {
+            if (!waitForData()) {
+                return -1;
+            }
+
+            int readBytes;
+
+            if (len > buff.remaining()) {
+                readBytes = buff.remaining();
+            }
+            else {
+                readBytes = len;
+            }
+
+            buff.get(b, off, readBytes);
+
+            return readBytes;
+        }
+    }
+
+    private boolean waitForData() throws IOException {
+        if (released) {
+            return false;
+        }
+
+        synchronized (mutex) {
+            while (!released && buff.remaining() == 0 && exception == null) {
+                try {
+                    mutex.wait();
+                }
+                catch (InterruptedException e) {
+                    IOException n = new IOException("Interrupted while waiting for more data");
+                    n.initCause(e);
+                    throw n;
+                }
+            }
+        }
+
+        if (exception != null) {
+            releaseBuffer();
+            throw exception;
+        }
+
+        if (closed && buff.remaining() == 0) {
+            releaseBuffer();
+
+            return false;
+        }
+
+        return true;
+    }
+
+    private void releaseBuffer() {
+        if (released) {
+            return;
+        }
+
+        released = true;
+    }
+
+    public void write(final ByteBuffer src) {
+        synchronized (mutex) {
+            if (closed) {
+                return;
+            }
+
+            if (buff.hasRemaining()) {
+                this.buff.compact();
+                this.buff.put(src);
+                this.buff.flip();
+            }
+            else {
+                this.buff.clear();
+                this.buff.put(src);
+                this.buff.flip();
+                mutex.notifyAll();
+            }
+        }
+    }
+
+    public void throwException(IOException e) {
+        synchronized (mutex) {
+            if (exception == null) {
+                exception = e;
+
+                mutex.notifyAll();
+            }
+        }
+    }
+}
\ No newline at end of file

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionInputStream.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/stream/IoSessionInputStream.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionOutputStream.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionOutputStream.java?rev=575934&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionOutputStream.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionOutputStream.java Sat Sep 15 09:31:39 2007
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+//
+// NOTE: Snatched from Apache Mina
+//
+
+package org.apache.geronimo.gshell.remote.stream;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.geronimo.gshell.remote.message.WriteStreamMessage;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
+
+/**
+ * An {@link OutputStream} that forwards all write operations to
+ * the associated {@link IoSession}.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class IoSessionOutputStream
+    extends OutputStream
+{
+    private final IoSession session;
+
+    private WriteFuture lastWriteFuture;
+
+    public IoSessionOutputStream(final IoSession session) {
+        this.session = session;
+    }
+
+    @Override
+    public void close() throws IOException {
+        try {
+            flush();
+        }
+        finally {
+            session.close().awaitUninterruptibly();
+        }
+    }
+
+    private void ensureOpened() throws IOException {
+        if (!session.isConnected()) {
+            throw new IOException("The session has been closed.");
+        }
+    }
+
+    private synchronized void write(final ByteBuffer buff) throws IOException {
+        ensureOpened();
+
+        WriteStreamMessage msg = new WriteStreamMessage("IN", buff);
+        
+        lastWriteFuture = session.write(msg);
+    }
+
+    @Override
+    public void write(byte[] b, int off, int len) throws IOException {
+        write(ByteBuffer.wrap(b.clone(), off, len));
+    }
+
+    @Override
+    public void write(int b) throws IOException {
+        ByteBuffer buf = ByteBuffer.allocate(1);
+        buf.put((byte) b);
+        buf.flip();
+        write(buf);
+    }
+
+    @Override
+    public synchronized void flush() throws IOException {
+        if (lastWriteFuture == null) {
+            return;
+        }
+
+        lastWriteFuture.awaitUninterruptibly();
+        
+        if (!lastWriteFuture.isWritten()) {
+            throw new IOException("The bytes could not be written to the session");
+        }
+    }
+}

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionOutputStream.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/stream/IoSessionOutputStream.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamIoHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamIoHandler.java?rev=575934&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamIoHandler.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamIoHandler.java Sat Sep 15 09:31:39 2007
@@ -0,0 +1,186 @@
+/*
+ * 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.
+ */
+
+//
+// NOTE: Snatched from Apache Mina
+//
+
+package org.apache.geronimo.gshell.remote.stream;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.SocketTimeoutException;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionLogger;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * A {@link IoHandler} that adapts asynchronous MINA events to stream I/O.
+ * <p/>
+ * Please extend this class and implement
+ * {@link #processStreamIo(IoSession,InputStream,OutputStream)} to
+ * execute your stream I/O logic; <b>please note that you must forward
+ * the process request to other thread or thread pool.</b>
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class StreamIoHandler
+    extends IoHandlerAdapter
+{
+    private static final String KEY_IN = StreamIoHandler.class.getName() + ".in";
+
+    private static final String KEY_OUT = StreamIoHandler.class.getName() + ".out";
+
+    private int readTimeout;
+
+    private int writeTimeout;
+
+    protected StreamIoHandler() {
+        // empty
+    }
+
+    /**
+     * Implement this method to execute your stream I/O logic;
+     * <b>please note that you must forward the process request to other
+     * thread or thread pool.</b>
+     */
+    protected abstract void processStreamIo(IoSession session, InputStream in, OutputStream out);
+
+    /**
+     * Returns read timeout in seconds.
+     * The default value is <tt>0</tt> (disabled).
+     */
+    public int getReadTimeout() {
+        return readTimeout;
+    }
+
+    /**
+     * Sets read timeout in seconds.
+     * The default value is <tt>0</tt> (disabled).
+     */
+    public void setReadTimeout(int readTimeout) {
+        this.readTimeout = readTimeout;
+    }
+
+    /**
+     * Returns write timeout in seconds.
+     * The default value is <tt>0</tt> (disabled).
+     */
+    public int getWriteTimeout() {
+        return writeTimeout;
+    }
+
+    /**
+     * Sets write timeout in seconds.
+     * The default value is <tt>0</tt> (disabled).
+     */
+    public void setWriteTimeout(int writeTimeout) {
+        this.writeTimeout = writeTimeout;
+    }
+
+    /**
+     * Initializes streams and timeout settings.
+     */
+    @Override
+    public void sessionOpened(IoSession session) {
+        // Set timeouts
+        session.getConfig().setWriteTimeout(writeTimeout);
+        session.getConfig().setIdleTime(IdleStatus.READER_IDLE, readTimeout);
+
+        // Create streams
+        InputStream in = new IoSessionInputStream();
+        OutputStream out = new IoSessionOutputStream(session);
+
+        session.setAttribute(KEY_IN, in);
+        session.setAttribute(KEY_OUT, out);
+
+        processStreamIo(session, in, out);
+    }
+
+    /**
+     * Closes streams
+     */
+    @Override
+    public void sessionClosed(IoSession session) throws Exception {
+        final InputStream in = (InputStream) session.getAttribute(KEY_IN);
+        final OutputStream out = (OutputStream) session.getAttribute(KEY_OUT);
+
+        IOUtil.close(in);
+        IOUtil.close(out);
+    }
+
+    /**
+     * Forwards read data to input stream.
+     */
+    @Override
+    public void messageReceived(IoSession session, Object buf) {
+        final IoSessionInputStream in = (IoSessionInputStream) session.getAttribute(KEY_IN);
+
+        in.write((ByteBuffer) buf);
+    }
+
+    /**
+     * Forwards caught exceptions to input stream.
+     */
+    @Override
+    public void exceptionCaught(IoSession session, Throwable cause) {
+        final IoSessionInputStream in = (IoSessionInputStream) session.getAttribute(KEY_IN);
+
+        IOException e = null;
+        if (cause instanceof StreamIoException) {
+            e = (IOException) cause.getCause();
+        }
+        else if (cause instanceof IOException) {
+            e = (IOException) cause;
+        }
+
+        if (e != null && in != null) {
+            in.throwException(e);
+        }
+        else {
+            IoSessionLogger.warn(session, "Unexpected exception.", cause);
+            session.close();
+        }
+    }
+
+    /**
+     * Handles read timeout.
+     */
+    @Override
+    public void sessionIdle(IoSession session, IdleStatus status) {
+        if (status == IdleStatus.READER_IDLE) {
+            throw new StreamIoException(new SocketTimeoutException("Read timeout"));
+        }
+    }
+
+    private static class StreamIoException extends RuntimeException {
+        private static final long serialVersionUID = 1;
+
+        public StreamIoException(IOException cause) {
+            super(cause);
+        }
+    }
+}

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamIoHandler.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/stream/StreamIoHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/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/stream/package-info.java?rev=575934&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/package-info.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/package-info.java Sat Sep 15 09:31:39 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.
+ */
+
+/**
+ * Support for remote input and output streaming.
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.geronimo.gshell.remote.stream;
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/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/stream/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/stream/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java?rev=575934&r1=575933&r2=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java Sat Sep 15 09:31:39 2007
@@ -23,15 +23,17 @@
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
-import org.apache.geronimo.gshell.remote.message.codec.MessageCodecFactory;
+import org.apache.geronimo.gshell.remote.message.MessageCodecFactory;
 import org.apache.geronimo.gshell.remote.ssl.BogusSSLContextFactory;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
+import org.apache.mina.common.IoEventType;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.mina.filter.logging.LoggingFilter;
 import org.apache.mina.filter.ssl.SSLFilter;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
 import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.InstantiationStrategy;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -41,7 +43,7 @@
  *
  * @version $Rev$ $Date$
  */
-@Component(role=RshServer.class)
+@Component(role=RshServer.class, instantiationStrategy=InstantiationStrategy.PER_LOOKUP)
 public class RshServer
 {
     private Logger log = LoggerFactory.getLogger(getClass());
@@ -69,8 +71,20 @@
         acceptor.setHandler(handler);
 
         DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
-        filterChain.addLast("logger", new LoggingFilter());
+
+        LoggingFilter loggingFilter = new LoggingFilter();
+        loggingFilter.setLogLevel(IoEventType.EXCEPTION_CAUGHT, LoggingFilter.WARN);
+        loggingFilter.setLogLevel(IoEventType.WRITE, LoggingFilter.TRACE);
+        loggingFilter.setLogLevel(IoEventType.MESSAGE_RECEIVED, LoggingFilter.TRACE);
+        loggingFilter.setLogLevel(IoEventType.MESSAGE_SENT, LoggingFilter.TRACE);
+        loggingFilter.setLogLevel(IoEventType.SESSION_CLOSED, LoggingFilter.DEBUG);
+        loggingFilter.setLogLevel(IoEventType.SESSION_CREATED, LoggingFilter.DEBUG);
+        loggingFilter.setLogLevel(IoEventType.SESSION_IDLE, LoggingFilter.DEBUG);
+        loggingFilter.setLogLevel(IoEventType.SESSION_OPENED, LoggingFilter.DEBUG);
+        filterChain.addLast("logger", loggingFilter);
+
         filterChain.addLast("protocol", new ProtocolCodecFilter(new MessageCodecFactory()));
+
         filterChain.addLast("auth", new AuthenticationFilter());
 
         if (ssl) {

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java?rev=575934&r1=575933&r2=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java Sat Sep 15 09:31:39 2007
@@ -19,11 +19,21 @@
 
 package org.apache.geronimo.gshell.remote.server;
 
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.Date;
+
+import org.apache.geronimo.gshell.remote.RshProtocolHandlerSupport;
 import org.apache.geronimo.gshell.remote.message.EchoMessage;
 import org.apache.geronimo.gshell.remote.message.HandShakeMessage;
 import org.apache.geronimo.gshell.remote.message.MessageVisitorAdapter;
+import org.apache.geronimo.gshell.remote.message.WriteStreamMessage;
+import org.apache.geronimo.gshell.remote.stream.IoSessionInputStream;
+import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.reqres.Response;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,11 +46,71 @@
     extends MessageVisitorAdapter
 {
     private Logger log = LoggerFactory.getLogger(getClass());
-    
+
     public void visitEcho(final EchoMessage msg) {
         assert msg != null;
 
-        log.info("ECHO: {}", msg.getText());
+        final IoSession session = (IoSession) msg.getAttachment();
+        assert session != null;
+        
+        String text = msg.getText();
+
+        //
+        // HACK: This is just here to test out the stream io muck
+        //
+
+        if ("READ_STREAMS".equals(text)) {
+            OutputStream out = (OutputStream) session.getAttribute(RshProtocolHandlerSupport.OUTPUT_STREAM);
+            final PrintWriter writer = new PrintWriter(out);
+
+            InputStream in = (InputStream) session.getAttribute(RshProtocolHandlerSupport.INPUT_STREAM);
+            final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+
+            Thread t = new Thread("Stream Consumer") {
+                public void run() {
+                    try {
+                        log.debug("Consumer running...");
+
+                        String line;
+                        while ((line = reader.readLine()) != null) {
+                            System.err.println(line);
+                        }
+                        
+                        log.debug("Consumer stopped");
+                    }
+                    catch (Exception e) {
+                        log.error(e.getMessage(), e);
+                    }
+                }
+            };
+
+            t.start();
+
+            Thread t2 = new Thread("Noise Maker") {
+                public void run() {
+                    try {
+                        log.debug("Noise Maker...");
+
+                        while (true) {
+                            writer.println("FROM SERVER: " + new Date());
+                            writer.flush();
+
+                            Thread.sleep(1000 * 5);
+                        }
+
+                        // log.debug("Noise Maker stopped");
+                    }
+                    catch (Exception e) {
+                        log.error(e.getMessage(), e);
+                    }
+                }
+            };
+
+            t2.start();
+        }
+        else {
+            log.info("ECHO: {}", text);
+        }
     }
 
     public void visitHandShake(final HandShakeMessage msg) {
@@ -52,9 +122,33 @@
         assert session != null;
 
         // For now just echo something back, with the same ID
-        EchoMessage resp = new EchoMessage("HELLO");
+        EchoMessage resp = new EchoMessage("SUCCESS");
         resp.setId(msg.getId());
 
         session.write(resp);
+    }
+
+    public void visitWriteStream(final WriteStreamMessage msg) {
+        assert msg != null;
+
+        IoSession session = (IoSession) msg.getAttachment();
+        assert session != null;
+
+        // Look up the bound stream in the session context
+        String key = RshProtocolHandlerSupport.STREAM_BASENAME + msg.getName();
+        Object stream = session.getAttribute(key);
+
+        // For now lets not toss any exceptions or send back any fault messages
+        if (stream == null) {
+            log.error("Stream is not registered: {}", key);
+        }
+        else if (!(stream instanceof IoSessionInputStream)) {
+            log.error("Stream is not for input: {}", key);
+        }
+        else {
+            IoSessionInputStream in = (IoSessionInputStream)stream;
+            ByteBuffer buff = msg.getBuffer();
+            in.write(buff);
+        }
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerProtocolHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerProtocolHandler.java?rev=575934&r1=575933&r2=575934&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerProtocolHandler.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerProtocolHandler.java Sat Sep 15 09:31:39 2007
@@ -20,50 +20,18 @@
 package org.apache.geronimo.gshell.remote.server;
 
 import org.apache.geronimo.gshell.remote.RshProtocolHandlerSupport;
-import org.apache.geronimo.gshell.remote.message.Message;
-import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoSession;
 import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.InstantiationStrategy;
 
 /**
  * ???
  *
  * @version $Rev$ $Date$
  */
-@Component(role=IoHandler.class, hint="rsh-server")
+@Component(role=IoHandler.class, hint="rsh-server", instantiationStrategy=InstantiationStrategy.PER_LOOKUP)
 public class RshServerProtocolHandler
     extends RshProtocolHandlerSupport
 {
-    private MessageVisitor visitor;
-
-    public MessageVisitor getVisitor() {
-        return visitor;
-    }
-
-    public void setVisitor(final MessageVisitor visitor) {
-        this.visitor = visitor;
-    }
-
-    public void messageReceived(final IoSession session, final Object message) throws Exception {
-        assert session != null;
-        assert message != null;
-
-        super.messageReceived(session, message);
-
-        if (message instanceof Message) {
-            Message msg = (Message)message;
-
-            msg.setAttachment(session);
-
-            msg.setAttachment(session);
-
-            if (visitor != null) {
-                msg.process(visitor);
-            }
-        }
-        else {
-            log.error("Unhandled message: {}", message);
-        }
-    }
+    // ???
 }