geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r576852 [1/2] - in /geronimo/sandbox/gshell/trunk/gshell-remote: ./ gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/ gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/ gshell-remote-com...
Date Tue, 18 Sep 2007 11:25:20 GMT
Author: jdillon
Date: Tue Sep 18 04:25:18 2007
New Revision: 576852

URL: http://svn.apache.org/viewvc?rev=576852&view=rev
Log:
Adding more guts to the remote shell muck... almost have something functional

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteShellProxy.java
      - copied, changed from r576671, 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-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java   (contents, props changed)
      - copied, changed from r576656, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpClientMessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CloseShellMessage.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java   (contents, props changed)
      - copied, changed from r576656, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpMessageVisitorSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/OpenShellMessage.java
      - copied, changed from r576652, 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/transport/tcp/TcpTransportSupport.java
      - copied, changed from r576656, 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-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShell.java
      - copied, changed from r576639, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java   (contents, props changed)
      - copied, changed from r576671, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpServerMessageVisitor.java
Removed:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpClientMessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpMessageVisitorSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpServerMessageVisitor.java
Modified:
    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/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/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/message/WriteStreamMessage.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/TransportFactory.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/TcpProtocolHandler.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/TcpTransportFactory.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-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerCommand.java
    geronimo/sandbox/gshell/trunk/gshell-remote/pom.xml

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteShellProxy.java (from r576671, 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/RemoteShellProxy.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RemoteShellProxy.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java&r1=576671&r2=576852&rev=576852&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/RemoteShellProxy.java Tue Sep 18 04:25:18 2007
@@ -19,58 +19,142 @@
 
 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.net.URI;
-import java.util.Date;
-
-import org.apache.geronimo.gshell.command.CommandSupport;
-import org.apache.geronimo.gshell.command.annotation.CommandComponent;
-import org.apache.geronimo.gshell.clp.Argument;
-import org.apache.geronimo.gshell.console.Console;
-import org.apache.geronimo.gshell.console.JLineConsole;
+import java.util.concurrent.atomic.AtomicReference;
+
+import jline.Terminal;
 import org.apache.geronimo.gshell.ExitNotification;
 import org.apache.geronimo.gshell.ansi.Renderer;
-import org.codehaus.plexus.component.annotations.Requirement;
-import jline.Terminal;
+import org.apache.geronimo.gshell.command.IO;
+import org.apache.geronimo.gshell.console.Console;
+import org.apache.geronimo.gshell.console.JLineConsole;
+import org.apache.geronimo.gshell.shell.Environment;
+import org.apache.geronimo.gshell.shell.InteractiveShell;
+import org.apache.geronimo.gshell.shell.ShellInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Command to connect to a remote shell server.
+ * Provides a shell interface which will proxy to a remote shell instance.
  *
  * @version $Rev$ $Date$
  */
-@CommandComponent(id="rsh")
-public class RshCommand
-    extends CommandSupport
+public class RemoteShellProxy
+    implements InteractiveShell
 {
-    @Argument(required=true)
-    private URI location;
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    private RshClient client;
+
+    private IO io;
 
-    @Requirement
     private Terminal terminal;
 
-    @Requirement
-    private RshClientFactory factory;
+    private boolean opened;
 
-    private RshClient client;
+    public RemoteShellProxy(final RshClient client, final IO io, final Terminal terminal) {
+        assert client != null;
+        assert io != null;
+        assert terminal != null;
+
+        this.client = client;
+        this.io = io;
+        this.terminal = terminal;
+
+        //
+        // TODO: Send OPEN_SHELL (send over some client-side details, like the terminal features, etc)
+        //       If any problem or denial occurs, throw an exception, once created the proxy is considered valid.
+        //
+
+        this.opened = true;
+    }
+
+    public Environment getEnvironment() {
+        ensureOpened();
 
-    protected Object doExecute() throws Exception {
-        io.out.println("Connecting to: " + location);
+        throw new Error("TODO");
+    }
 
-        client = factory.connect(location);
+    public ShellInfo getShellInfo() {
+        ensureOpened();
 
-        io.out.println("Connected");
+        throw new Error("TODO");
+    }
 
-        client.handshake();
+    private void ensureOpened() {
+        if (!opened) {
+            throw new IllegalStateException("Remote shell proxy has been closed");
+        }
+    }
+
+    public boolean isOpened() {
+        return opened;
+    }
+
+    public void close() {
+        //
+        // TODO: Send CLOSE_SHELL
+        //
+
+        opened = false;
+        
+        log.info("Closed");
+    }
+
+    //
+    // Command Execution
+    //
+
+    public Object execute(final String line) throws Exception {
+        ensureOpened();
+
+        return client.execute(line);
+    }
+
+    public Object execute(final Object... args) throws Exception {
+        ensureOpened();
+
+        return client.execute((Object[])args);
+    }
+
+    public Object execute(final String path, final Object[] args) throws Exception {
+        ensureOpened();
+
+        return client.execute(path, args);
+    }
+
+    //
+    // Interactive Shell
+    //
+
+    public void run(final Object... args) throws Exception {
+        assert args != null;
+
+        ensureOpened();
+
+        log.debug("Starting interactive console; args: {}", args);
+
+        //
+        // TODO: Request server to load...
+        //
+        // loadUserScript(branding.getInteractiveScriptName());
+
+        final AtomicReference<ExitNotification> exitNotifHolder = new AtomicReference<ExitNotification>();
+        final AtomicReference<Object> lastResultHolder = new AtomicReference<Object>();
 
         Console.Executor executor = new Console.Executor() {
             public Result execute(final String line) throws Exception {
                 assert line != null;
 
-                client.execute(line);
+                try {
+                    Object result = RemoteShellProxy.this.execute(line);
+
+                    lastResultHolder.set(result);
+                }
+                catch (ExitNotification n) {
+                    exitNotifHolder.set(n);
+
+                    return Result.STOP;
+                }
 
                 return Result.CONTINUE;
             }
@@ -82,8 +166,12 @@
             Renderer renderer = new Renderer();
 
             public String prompt() {
-                String userName = "user";
-                String hostName = "remote";
+                //
+                // FIXME:
+                //
+
+                String userName = "user"; // shellInfo.getUserName();
+                String hostName = "remote"; // shellInfo.getLocalHost().getHostName();
                 String path = "/";
 
                 return renderer.render("@|bold " + userName + "|@" + hostName + ":@|bold " + path + "|> ");
@@ -94,16 +182,44 @@
             public Result handleError(final Throwable error) {
                 assert error != null;
 
-                log.error("Communication error: " + error, error);
+                //
+                // FIXME:
+                //
 
                 return Result.CONTINUE;
             }
         });
 
+        //
+        // TODO: What are we to do with history here?  Really should be history on the server...
+        //
+
+        /*
+        // Hook up a nice history file (we gotta hold on to the history object at some point so the 'history' command can get to it)
+        History history = new History();
+        console.setHistory(history);
+        console.setHistoryFile(new File(branding.getUserDirectory(), branding.getHistoryFileName()));
+        */
+
+        // Unless the user wants us to shut up, then display a nice welcome banner
+        /*
+        if (!io.isQuiet()) {
+            io.out.println(branding.getWelcomeBanner());
+        }
+        */
+
+        // Check if there are args, and run them and then enter interactive
+        if (args.length != 0) {
+            execute(args);
+        }
+
+        // And then spin up the console and go for a jog
         console.run();
-        
-        client.close();
 
-        return SUCCESS;
+        // If any exit notification occured while running, then puke it up
+        ExitNotification n = exitNotifHolder.get();
+        if (n != null) {
+            throw n;
+        }
     }
 }

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=576852&r1=576851&r2=576852&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 Tue Sep 18 04:25:18 2007
@@ -66,7 +66,9 @@
         log.info("Response: {}", resp);
     }
 
-    public void execute(final String line) throws Exception {
+    public Object execute(final String line) throws Exception {
+        assert line != null;
+
         log.info("Executing: {}", line);
 
         transport.send(new ExecuteMessage(line));
@@ -74,6 +76,37 @@
         //
         // TODO: Need to handle the command result
         //
+
+        return null;
+    }
+
+    public Object execute(final Object... args) throws Exception {
+        assert args != null;
+
+        log.info("Executing: {}", args);
+
+        transport.send(new ExecuteMessage(args));
+
+        //
+        // TODO: Need to handle the command result
+        //
+
+        return null;
+    }
+
+    public Object execute(final String path, final Object[] args) throws Exception {
+        assert path != null;
+        assert args != null;
+
+        log.info("Executing: {}, {}", path, args);
+
+        transport.send(new ExecuteMessage(path, args));
+
+        //
+        // TODO: Need to handle the command result
+        //
+
+        return null;
     }
 
     public InputStream getInputStream() {

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java (from r576656, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpClientMessageVisitor.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?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpClientMessageVisitor.java&r1=576656&r2=576852&rev=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpClientMessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java Tue Sep 18 04:25:18 2007
@@ -17,9 +17,11 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.transport.tcp;
+package org.apache.geronimo.gshell.remote.client;
 
 import org.apache.geronimo.gshell.remote.message.EchoMessage;
+import org.apache.geronimo.gshell.remote.message.MessageVisitor;
+import org.apache.geronimo.gshell.remote.message.MessageVisitorSupport;
 import org.codehaus.plexus.component.annotations.Component;
 
 /**
@@ -27,9 +29,9 @@
  *
  * @version $Rev$ $Date$
  */
-@Component(role=TcpClientMessageVisitor.class)
-public class TcpClientMessageVisitor
-    extends TcpMessageVisitorSupport
+@Component(role=MessageVisitor.class, hint="client")
+public class RshClientMessageVisitor
+    extends MessageVisitorSupport
 {
     public void visitEcho(final EchoMessage msg) throws Exception {
         assert msg != null;

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.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/RshClientMessageVisitor.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/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=576852&r1=576851&r2=576852&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 Tue Sep 18 04:25:18 2007
@@ -19,21 +19,14 @@
 
 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.net.URI;
-import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
 
+import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.command.CommandSupport;
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
-import org.apache.geronimo.gshell.clp.Argument;
-import org.apache.geronimo.gshell.console.Console;
-import org.apache.geronimo.gshell.console.JLineConsole;
-import org.apache.geronimo.gshell.ExitNotification;
-import org.apache.geronimo.gshell.ansi.Renderer;
+import org.apache.geronimo.gshell.remote.client.RemoteShellProxy;
 import org.codehaus.plexus.component.annotations.Requirement;
 import jline.Terminal;
 
@@ -46,9 +39,16 @@
 public class RshCommand
     extends CommandSupport
 {
-    @Argument(required=true)
+    //
+    // TODO: Add support to bind to a local address, also look at man pages for rsh and ssh for more options which might want to support.
+    //
+    
+    @Argument(metaVar="LOCATION", required=true, index=0)
     private URI location;
 
+    @Argument(metaVar="COMMAND", index=1)
+    private List<String> command = new ArrayList<String>();
+
     @Requirement
     private Terminal terminal;
 
@@ -58,52 +58,30 @@
     private RshClient client;
 
     protected Object doExecute() throws Exception {
-        io.out.println("Connecting to: " + location);
+        io.info("Connecting to: {}", location);
 
         client = factory.connect(location);
 
-        io.out.println("Connected");
+        io.info("Connected");
 
+        client.echo("TESTING");
+        
         client.handshake();
 
-        Console.Executor executor = new Console.Executor() {
-            public Result execute(final String line) throws Exception {
-                assert line != null;
-
-                client.execute(line);
-
-                return Result.CONTINUE;
-            }
-        };
+        /*
+        RemoteShellProxy shell = new RemoteShellProxy(client, io, terminal);
 
-        JLineConsole console = new JLineConsole(executor, io, terminal);
+        shell.run(command.toArray());
 
-        console.setPrompter(new Console.Prompter() {
-            Renderer renderer = new Renderer();
+        shell.close();
+        */
 
-            public String prompt() {
-                String userName = "user";
-                String hostName = "remote";
-                String path = "/";
+        io.verbose("Disconnecting");
 
-                return renderer.render("@|bold " + userName + "|@" + hostName + ":@|bold " + path + "|> ");
-            }
-        });
-
-        console.setErrorHandler(new Console.ErrorHandler() {
-            public Result handleError(final Throwable error) {
-                assert error != null;
-
-                log.error("Communication error: " + error, error);
-
-                return Result.CONTINUE;
-            }
-        });
-
-        console.run();
-        
         client.close();
 
+        io.verbose("Disconnected");
+        
         return SUCCESS;
     }
 }

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CloseShellMessage.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/CloseShellMessage.java?rev=576852&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CloseShellMessage.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CloseShellMessage.java Tue Sep 18 04:25:18 2007
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+/**
+ * Close the remote shell instance.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CloseShellMessage
+    extends MessageSupport
+{
+    public CloseShellMessage() {
+        super(MessageType.CLOSE_SHELL);
+    }
+
+    public void readExternal(final ByteBuffer in) throws Exception {
+        assert in != null;
+
+        super.readExternal(in);
+    }
+
+    public void writeExternal(final ByteBuffer out) throws Exception {
+        assert out != null;
+
+        super.writeExternal(out);
+    }
+
+    public void process(final MessageVisitor visitor) throws Exception {
+        assert visitor != null;
+
+        visitor.visitCloseShell(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/CloseShellMessage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CloseShellMessage.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/CloseShellMessage.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/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=576852&r1=576851&r2=576852&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 Tue Sep 18 04:25:18 2007
@@ -45,20 +45,20 @@
         return text;
     }
 
-    public void readExternal(final ByteBuffer buff) throws Exception {
-        assert buff != null;
+    public void readExternal(final ByteBuffer in) throws Exception {
+        assert in != null;
 
-        super.readExternal(buff);
+        super.readExternal(in);
 
-        text = readString(buff);
+        text = readString(in);
     }
 
-    public void writeExternal(final ByteBuffer buff) throws Exception {
-        assert buff != null;
+    public void writeExternal(final ByteBuffer out) throws Exception {
+        assert out != null;
 
-        super.writeExternal(buff);
+        super.writeExternal(out);
 
-        writeString(buff, text);
+        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=576852&r1=576851&r2=576852&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 Tue Sep 18 04:25:18 2007
@@ -19,51 +19,115 @@
 
 package org.apache.geronimo.gshell.remote.message;
 
+import org.apache.geronimo.gshell.command.CommandExecutor;
 import org.apache.mina.common.ByteBuffer;
 
 /**
- * Execute a command-line.
+ * Execute a command.  This supports all flavors of the {@link CommandExecutor} execution methods.
  *
  * @version $Rev$ $Date$
  */
 public class ExecuteMessage
     extends MessageSupport
 {
-    private String line;
+    private Flavor flavor;
+    
+    private String path;
 
-    public ExecuteMessage(final String line) {
+    private Object[] args;
+
+    private ExecuteMessage(final Flavor flavor, final String path, final Object[] args) {
         super(MessageType.EXECUTE);
 
-        this.line = line;
+        this.flavor = flavor;
+        this.path = path;
+        this.args = args;
+    }
+
+    public ExecuteMessage(final String commandLine) {
+        this(Flavor.STRING, null, new Object[] { commandLine });
+    }
+
+    public ExecuteMessage(final Object[] args) {
+        this(Flavor.OBJECTS, null, args);
+    }
+
+    public ExecuteMessage(final String path, final Object[] args) {
+        this(Flavor.STRING_OBJECTS, path, args);
     }
 
     public ExecuteMessage() {
-        this(null);
+        this(null, null, null);
     }
 
-    public String getLine() {
-        return line;
+    public Object execute(final CommandExecutor executor) throws Exception {
+        assert executor != null;
+
+        return flavor.execute(this, executor);
     }
 
-    public void readExternal(final ByteBuffer buff) throws Exception {
-        assert buff != null;
+    //
+    // TODO: Optimize this
+    //
+    
+    public void readExternal(final ByteBuffer in) throws Exception {
+        assert in != null;
+
+        super.readExternal(in);
+
+        this.flavor = in.getEnum(Flavor.class);
 
-        super.readExternal(buff);
+        this.path = readString(in);
 
-        line = readString(buff);
+        this.args = (Object[]) in.getObject();
     }
 
-    public void writeExternal(final ByteBuffer buff) throws Exception {
-        assert buff != null;
+    public void writeExternal(final ByteBuffer out) throws Exception {
+        assert out != null;
 
-        super.writeExternal(buff);
+        super.writeExternal(out);
 
-        writeString(buff, line);
+        out.putEnum(flavor);
+
+        writeString(out, path);
+        
+        out.putObject(args);
     }
 
     public void process(final MessageVisitor visitor) throws Exception {
         assert visitor != null;
 
         visitor.visitExecute(this);
+    }
+
+    //
+    // Flavor
+    //
+    
+    private enum Flavor
+    {
+        STRING,         // execute(String)
+        OBJECTS,        // execute(Object[])
+        STRING_OBJECTS  // execute(String, Object[])
+        ;
+
+        public Object execute(final ExecuteMessage msg, final CommandExecutor executor) throws Exception {
+            assert msg != null;
+            assert executor != null;
+
+            switch (this) {
+                case STRING:
+                    return executor.execute((String)msg.args[0]);
+                
+                case OBJECTS:
+                    return executor.execute(msg.args);
+
+                case STRING_OBJECTS:
+                    return executor.execute(msg.path, msg.args);
+            }
+
+            // This should never happen
+            throw new Error();
+        }
     }
 }

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=576852&r1=576851&r2=576852&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 Tue Sep 18 04:25:18 2007
@@ -51,20 +51,20 @@
         this.publicKey = publicKey;
     }
 
-    public void readExternal(final ByteBuffer buff) throws Exception {
-        assert buff != null;
+    public void readExternal(final ByteBuffer in) throws Exception {
+        assert in != null;
 
-        super.readExternal(buff);
+        super.readExternal(in);
 
-        publicKey = (PublicKey) buff.getObject();
+        publicKey = (PublicKey) in.getObject();
     }
 
-    public void writeExternal(final ByteBuffer buff) throws Exception {
-        assert buff != null;
+    public void writeExternal(final ByteBuffer out) throws Exception {
+        assert out != null;
 
-        super.writeExternal(buff);
+        super.writeExternal(out);
 
-        buff.putObject(publicKey);
+        out.putObject(publicKey);
     }
 
     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/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=576852&r1=576851&r2=576852&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 Tue Sep 18 04:25:18 2007
@@ -27,6 +27,7 @@
 import org.apache.mina.filter.reqres.Request;
 import org.apache.mina.filter.reqres.ResponseInspector;
 import org.apache.mina.filter.reqres.ResponseType;
+import org.codehaus.plexus.component.annotations.Component;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -35,6 +36,7 @@
  *
  * @version $Rev$ $Date$
  */
+@Component(role=MessageResponseInspector.class)
 public class MessageResponseInspector
     implements ResponseInspector
 {

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=576852&r1=576851&r2=576852&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 Tue Sep 18 04:25:18 2007
@@ -133,33 +133,48 @@
     }
 
     //
-    // MarshalAware
+    // Reply Helpers
     //
 
-    public void readExternal(final ByteBuffer buff) throws Exception {
-        assert buff != null;
+    public WriteFuture reply(final MessageSupport msg) {
+        assert msg != null;
 
-        id = readUuid(buff);
+        IoSession session = getSession();
 
-        correlationId = readUuid(buff);
+        msg.setCorrelationId(getId());
+        msg.freeze();
 
-        timestamp = buff.getLong();
+        return session.write(msg);
+    }
+    
+    //
+    // Serialization
+    //
 
-        sequence = buff.getLong();
+    public void readExternal(final ByteBuffer in) throws Exception {
+        assert in != null;
+
+        id = readUuid(in);
+
+        correlationId = readUuid(in);
+
+        timestamp = in.getLong();
+
+        sequence = in.getLong();
     }
 
-    public void writeExternal(final ByteBuffer buff) throws Exception {
-        assert buff != null;
+    public void writeExternal(final ByteBuffer out) throws Exception {
+        assert out != null;
 
-        writeUuid(buff, id);
+        writeUuid(out, id);
 
-        writeUuid(buff, correlationId);
+        writeUuid(out, correlationId);
 
-        buff.putLong(timestamp);
+        out.putLong(timestamp);
 
         sequence = SEQUENCE_COUNTER.getAndIncrement();
         
-        buff.putLong(sequence);
+        out.putLong(sequence);
     }
 
     //
@@ -173,17 +188,26 @@
 
         int len = in.getInt();
 
-        return in.getString(len, UTF_8_CHARSET.newDecoder());
+        if (len == -1) {
+            return null;
+        }
+        else {
+            return in.getString(len, UTF_8_CHARSET.newDecoder());
+        }
     }
 
     protected void writeString(final ByteBuffer out, final String str) throws CharacterCodingException {
         assert out != null;
-        assert str != null;
 
-        int len = str.length();
-        out.putInt(len);
-        
-        out.putString(str, len, UTF_8_CHARSET.newEncoder());
+        if (str == null) {
+            out.putInt(-1);
+        }
+        else {
+            int len = str.length();
+            out.putInt(len);
+
+            out.putString(str, len, UTF_8_CHARSET.newEncoder());
+        }
     }
 
     private void writeUuid(final ByteBuffer out, final UUID uuid) throws Exception {
@@ -213,20 +237,5 @@
         else {
             return null;
         }
-    }
-
-    //
-    // Reply Helpers
-    //
-    
-    public WriteFuture reply(final MessageSupport msg) {
-        assert msg != null;
-
-        IoSession session = getSession();
-
-        msg.setCorrelationId(getId());
-        msg.freeze();
-        
-        return session.write(msg);
     }
 }

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=576852&r1=576851&r2=576852&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 Tue Sep 18 04:25:18 2007
@@ -28,8 +28,10 @@
 {
     ECHO            (EchoMessage.class),
     HANDSHAKE       (HandShakeMessage.class),
-    WRITE_STREAM    (WriteStreamMessage.class),
+    OPEN_SHELL      (OpenShellMessage.class),
+    CLOSE_SHELL     (CloseShellMessage.class),
     EXECUTE         (ExecuteMessage.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=576852&r1=576851&r2=576852&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 Tue Sep 18 04:25:18 2007
@@ -29,8 +29,12 @@
     void visitEcho(EchoMessage msg) throws Exception;
 
     void visitHandShake(HandShakeMessage msg) throws Exception;
-    
-    void visitWriteStream(WriteStreamMessage msg) throws Exception;
+
+    void visitOpenShell(OpenShellMessage msg) throws Exception;
+
+    void visitCloseShell(CloseShellMessage msg) throws Exception;
 
     void visitExecute(ExecuteMessage msg) throws Exception;
+
+    void visitWriteStream(WriteStreamMessage msg) throws Exception;
 }

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=576852&r1=576851&r2=576852&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 Tue Sep 18 04:25:18 2007
@@ -27,19 +27,15 @@
 public class MessageVisitorAdapter
     implements MessageVisitor
 {
-    public void visitEcho(EchoMessage msg) throws Exception {
-        // Empty
-    }
+    public void visitEcho(EchoMessage msg) throws Exception {}
 
-    public void visitHandShake(HandShakeMessage msg) throws Exception {
-        // Empty
-    }
+    public void visitHandShake(HandShakeMessage msg) throws Exception {}
 
-    public void visitWriteStream(WriteStreamMessage msg) throws Exception {
-        // Empty
-    }
+    public void visitOpenShell(OpenShellMessage msg) throws Exception {}
 
-    public void visitExecute(ExecuteMessage msg) throws Exception {
-        // Empty
-    }
+    public void visitCloseShell(CloseShellMessage msg) throws Exception {}
+
+    public void visitExecute(ExecuteMessage msg) throws Exception {}
+    
+    public void visitWriteStream(WriteStreamMessage msg) throws Exception {}
 }

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java (from r576656, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpMessageVisitorSupport.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?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpMessageVisitorSupport.java&r1=576656&r2=576852&rev=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpMessageVisitorSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java Tue Sep 18 04:25:18 2007
@@ -17,7 +17,10 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.transport.tcp;
+package org.apache.geronimo.gshell.remote.message;
+
+import java.io.InputStream;
+import java.io.OutputStream;
 
 import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.geronimo.gshell.remote.message.MessageVisitorAdapter;
@@ -29,15 +32,48 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * Provides support for TCP-oriented {@link MessageVisitor} implementations.
+ * Provides support for {@link MessageVisitor} implementations.
  *
  * @version $Rev$ $Date$
  */
-public abstract class TcpMessageVisitorSupport
+public abstract class MessageVisitorSupport
     extends MessageVisitorAdapter
 {
     protected Logger log = LoggerFactory.getLogger(getClass());
 
+    //
+    // 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;
+    }
+
+    //
+    // MessageVisitor
+    //
+    
     public void visitWriteStream(final WriteStreamMessage msg) throws Exception {
         assert msg != null;
 

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.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/MessageVisitorSupport.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/OpenShellMessage.java (from r576652, 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/OpenShellMessage.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/OpenShellMessage.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java&r1=576652&r2=576852&rev=576852&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/OpenShellMessage.java Tue Sep 18 04:25:18 2007
@@ -22,48 +22,32 @@
 import org.apache.mina.common.ByteBuffer;
 
 /**
- * Echo text.
+ * Open a remote shell instance.
  *
  * @version $Rev$ $Date$
  */
-public class EchoMessage
+public class OpenShellMessage
     extends MessageSupport
 {
-    private String text;
-    
-    public EchoMessage(final String text) {
-        super(MessageType.ECHO);
-        
-        this.text = text;
+    public OpenShellMessage() {
+        super(MessageType.OPEN_SHELL);
     }
 
-    public EchoMessage() {
-        this(null);
-    }
-
-    public String getText() {
-        return text;
-    }
+    public void readExternal(final ByteBuffer in) throws Exception {
+        assert in != null;
 
-    public void readExternal(final ByteBuffer buff) throws Exception {
-        assert buff != null;
-
-        super.readExternal(buff);
-
-        text = readString(buff);
+        super.readExternal(in);
     }
 
-    public void writeExternal(final ByteBuffer buff) throws Exception {
-        assert buff != null;
-
-        super.writeExternal(buff);
+    public void writeExternal(final ByteBuffer out) throws Exception {
+        assert out != null;
 
-        writeString(buff, text);
+        super.writeExternal(out);
     }
 
     public void process(final MessageVisitor visitor) throws Exception {
         assert visitor != null;
 
-        visitor.visitEcho(this);
+        visitor.visitOpenShell(this);
     }
 }

Modified: 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=576852&r1=576851&r2=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/WriteStreamMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/WriteStreamMessage.java Tue Sep 18 04:25:18 2007
@@ -70,10 +70,6 @@
         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;
 
@@ -81,9 +77,9 @@
 
         name = readString(in);
 
-        int l = in.getInt();
+        int len = in.getInt();
 
-        byte[] bytes = new byte[l];
+        byte[] bytes = new byte[len];
         in.get(bytes);
 
         buffer = ByteBuffer.wrap(bytes);

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java?rev=576852&r1=576851&r2=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java Tue Sep 18 04:25:18 2007
@@ -38,8 +38,6 @@
 
     String OUTPUT_STREAM = STREAM_BASENAME + "OUT";
 
-    String ERROR_STREAM = STREAM_BASENAME + "ERR";
-
     void send(Message msg) throws Exception;
 
     Message request(Message msg, long timeout, TimeUnit unit) throws Exception;

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportFactory.java?rev=576852&r1=576851&r2=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportFactory.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportFactory.java Tue Sep 18 04:25:18 2007
@@ -28,7 +28,9 @@
  */
 public interface TransportFactory
 {
-    Transport connect(final URI location) throws Exception;
+    Transport connect(final URI remote, final URI local) throws Exception;
+
+    Transport connect(final URI remote) throws Exception;
 
     TransportServer bind(final URI location) throws Exception;
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransport.java?rev=576852&r1=576851&r2=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransport.java Tue Sep 18 04:25:18 2007
@@ -21,10 +21,10 @@
 
 import java.net.URI;
 
-import org.apache.geronimo.gshell.remote.ssl.BogusSSLContextFactory;
+import org.apache.geronimo.gshell.remote.ssl.SSLContextFactory;
 import org.apache.geronimo.gshell.remote.transport.tcp.TcpTransport;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
-import org.apache.mina.filter.ssl.SSLFilter;
+import org.apache.mina.filter.ssl.SslFilter;
 
 /**
  * Provides TCP+SSL client-side support.
@@ -34,6 +34,8 @@
 public class SslTransport
     extends TcpTransport
 {
+    private SSLContextFactory sslContextFactory;
+
     public SslTransport(final URI remote, final URI local) throws Exception {
         super(remote, local);
     }
@@ -43,13 +45,19 @@
 
         DefaultIoFilterChainBuilder filterChain = connector.getFilterChain();
 
-        //
-        // TODO: Get the SSL context factory injected
-        //
-        
-        SSLFilter sslFilter = new SSLFilter(BogusSSLContextFactory.getInstance(false));
+        SslFilter sslFilter = new SslFilter(sslContextFactory.createClientContext());
         sslFilter.setUseClientMode(true);
 
         filterChain.addFirst("ssl", sslFilter);
+    }
+
+    //
+    // NOTE: Setters exposed to support Plexus autowire()
+    //
+
+    public void setSslContextFactory(final SSLContextFactory factory) {
+        log.debug("Using SSL Context Factory: {}", factory);
+
+        this.sslContextFactory = factory;
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportServer.java?rev=576852&r1=576851&r2=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportServer.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportServer.java Tue Sep 18 04:25:18 2007
@@ -21,10 +21,10 @@
 
 import java.net.URI;
 
-import org.apache.geronimo.gshell.remote.ssl.BogusSSLContextFactory;
+import org.apache.geronimo.gshell.remote.ssl.SSLContextFactory;
 import org.apache.geronimo.gshell.remote.transport.tcp.TcpTransportServer;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
-import org.apache.mina.filter.ssl.SSLFilter;
+import org.apache.mina.filter.ssl.SslFilter;
 
 /**
  * Provides TCP+SSL server-side support.
@@ -34,6 +34,8 @@
 public class SslTransportServer
     extends TcpTransportServer
 {
+    private SSLContextFactory sslContextFactory;
+
     public SslTransportServer(final URI location) throws Exception {
         super(location);
     }
@@ -43,11 +45,17 @@
         
         DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
 
-        //
-        // TODO: Get the SSL context factory injected
-        //
-        
-        SSLFilter sslFilter = new SSLFilter(BogusSSLContextFactory.getInstance(true));
+        SslFilter sslFilter = new SslFilter(sslContextFactory.createServerContext());
         filterChain.addFirst("ssl", sslFilter);
+    }
+    
+    //
+    // NOTE: Setters exposed to support Plexus autowire()
+    //
+
+    public void setSslContextFactory(final SSLContextFactory factory) {
+        log.debug("Using SSL Context Factory: {}", factory);
+
+        this.sslContextFactory = factory;
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpProtocolHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpProtocolHandler.java?rev=576852&r1=576851&r2=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpProtocolHandler.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpProtocolHandler.java Tue Sep 18 04:25:18 2007
@@ -19,6 +19,9 @@
 
 package org.apache.geronimo.gshell.remote.transport.tcp;
 
+import java.io.InputStream;
+import java.io.OutputStream;
+
 import org.apache.geronimo.gshell.remote.message.Message;
 import org.apache.geronimo.gshell.remote.message.MessageResponseInspector;
 import org.apache.geronimo.gshell.remote.message.MessageVisitor;
@@ -31,6 +34,7 @@
 import org.apache.mina.filter.reqres.Request;
 import org.apache.mina.filter.reqres.Response;
 import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.util.IOUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,9 +50,14 @@
 {
     protected Logger log = LoggerFactory.getLogger(getClass());
 
-    protected MessageVisitor visitor;
+    @Requirement
+    protected MessageResponseInspector responseInspector;
 
-    protected MessageResponseInspector responseInspector = new MessageResponseInspector();
+    //
+    // TODO: Might be able to get this puppy injected...
+    //
+    
+    protected MessageVisitor visitor;
 
     public MessageVisitor getVisitor() {
         return visitor;
@@ -62,31 +71,75 @@
         return responseInspector;
     }
 
-    public void messageReceived(final IoSession session, final Object obj) throws Exception {
+    //
+    // Stream Access
+    //
+
+    private void setInputStream(final IoSession session, final InputStream in) {
         assert session != null;
-        assert obj != null;
+        assert in != null;
 
-        log.info("Message received: {}", obj);
+        Object obj = session.getAttribute(Transport.INPUT_STREAM);
 
-        if (obj instanceof Message) {
-            Message msg = (Message)obj;
+        if (obj != null) {
+            throw new IllegalStateException("Input stream already bound");
+        }
 
-            if (visitor != null) {
-                msg.setSession(session);
-                msg.freeze();
-                msg.process(visitor);
-            }
+        session.setAttribute(Transport.INPUT_STREAM, in);
+
+        log.debug("Bound input stream: {}", in);
+    }
+
+    private 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");
         }
-        else if (obj instanceof Response) {
-            Response resp = (Response)obj;
 
-            Request req = resp.getRequest();
+        return in;
+    }
 
-            responseInspector.deregister(req);
+    private InputStream removeInputStream(final IoSession session) {
+        assert session != null;
+
+        return (InputStream) session.removeAttribute(Transport.INPUT_STREAM);
+    }
+
+    private void setOutputStream(final IoSession session, final OutputStream out) {
+        assert session != null;
+        assert out != null;
+
+        Object obj = session.getAttribute(Transport.OUTPUT_STREAM);
+
+        if (obj != null) {
+            throw new IllegalStateException("Output stream already bound");
         }
-        else {
-            log.error("Unhandled message: {}", obj);
+
+        session.setAttribute(Transport.OUTPUT_STREAM, out);
+
+        log.debug("Bound output stream: {}", out);
+    }
+
+    private 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;
+    }
+
+    private OutputStream removeOutputStream(final IoSession session) {
+        assert session != null;
+
+        return (OutputStream) session.removeAttribute(Transport.OUTPUT_STREAM);
     }
 
     //
@@ -98,59 +151,100 @@
     }
 
     public void sessionOpened(final IoSession session) throws Exception {
-        log.info("Session opened: {}", session);
-
-        IoSessionInputStream in = new IoSessionInputStream();
-        session.setAttribute(Transport.INPUT_STREAM, in);
+        assert session != null;
 
-        IoSessionOutputStream out = new IoSessionOutputStream(session);
-        session.setAttribute(Transport.OUTPUT_STREAM, out);
+        log.info("Session opened: {}", session);
 
         //
-        // TODO: Add err
+        // Once the session has been opened, bind streams to the session context.
         //
+
+        setInputStream(session, new IoSessionInputStream());
+        setOutputStream(session, new IoSessionOutputStream(session));
     }
 
     public void sessionClosed(final IoSession session) throws Exception {
-        log.info("Session closed: {}", session);
-
-        IoSessionInputStream in = (IoSessionInputStream) session.getAttribute(Transport.INPUT_STREAM);
-        IOUtil.close(in);
+        assert session != null;
 
-        IoSessionOutputStream out = (IoSessionOutputStream) session.getAttribute(Transport.OUTPUT_STREAM);
-        IOUtil.close(out);
+        log.info("Session closed: {}", session);
 
-        //
-        // TODO: Add err
-        //
+        IOUtil.close(removeInputStream(session));
+        
+        IOUtil.close(removeOutputStream(session));
     }
 
     public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception {
+        assert session != null;
+
         log.info("Session idle: {}, status: {}", session, status);
 
-        /*
         if (status == IdleStatus.READER_IDLE) {
-            throw new SocketTimeoutException("Read timeout");
+            log.warn("Read timeout");
         }
-        */
     }
 
-    public void exceptionCaught(final IoSession session, final Throwable cause) throws Exception {
+    public void messageReceived(final IoSession session, final Object obj) throws Exception {
         assert session != null;
-        assert cause != null;
+        assert obj != null;
 
-        log.error("Unhandled error: " + cause, cause);
+        log.info("Message received: {}", obj);
 
-        session.close();
+        if (obj instanceof Message) {
+            //
+            // This is the main protocol action, set the session, freeze the message and
+            // then process the message with our visitor
+            //
+
+            Message msg = (Message)obj;
+
+            if (visitor != null) {
+                msg.setSession(session);
+                msg.freeze();
+                msg.process(visitor);
+            }
+            else {
+                log.warn("Unable to process message because vistor has not been bound; ignoring");
+            }
+        }
+        else if (obj instanceof Response) {
+            //
+            // Secondardy is to handle deregistration of request/resposne messages
+            //
+
+            Response resp = (Response)obj;
+
+            Request req = resp.getRequest();
+
+            responseInspector.deregister(req);
+        }
+        else {
+            log.error("Unhandled message: {}", obj);
+        }
     }
 
     public void messageSent(final IoSession session, final Object obj) throws Exception {
+        assert session != null;
+
         log.info("Message sent: {}", obj);
 
         if (obj instanceof Request) {
+            //
+            // When request messages are sent, we need to register them with the response inspector
+            // so that when a resposne comes back we know how to correlate it with its request.
+            //
+
             Request req = (Request) obj;
 
             responseInspector.register(req);
         }
+    }
+
+    public void exceptionCaught(final IoSession session, final Throwable cause) throws Exception {
+        assert session != null;
+        assert cause != null;
+
+        log.error("Unhandled error: " + cause, cause);
+
+        session.close();
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java?rev=576852&r1=576851&r2=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java Tue Sep 18 04:25:18 2007
@@ -27,25 +27,18 @@
 import java.net.URI;
 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.filter.LoggingFilter;
 import org.apache.geronimo.gshell.remote.message.Message;
-import org.apache.geronimo.gshell.remote.message.MessageCodecFactory;
+import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.geronimo.gshell.remote.transport.Transport;
 import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.ConnectFuture;
-import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
-import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.mina.filter.reqres.Request;
-import org.apache.mina.filter.reqres.RequestResponseFilter;
 import org.apache.mina.filter.reqres.Response;
 import org.apache.mina.transport.socket.nio.SocketConnector;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Provides TCP client-side support.
@@ -53,23 +46,18 @@
  * @version $Rev$ $Date$
  */
 public class TcpTransport
+    extends TcpTransportSupport
     implements Transport
 {
     private static final int CONNECT_TIMEOUT = 3000;
 
-    protected Logger log = LoggerFactory.getLogger(getClass());
+    protected final URI remoteLocation;
 
-    protected TcpClientMessageVisitor messageVisitor;
+    protected final InetSocketAddress remoteAddress;
 
-    protected TcpProtocolHandler protocolHandler;
+    protected final URI localLocation;
 
-    protected URI remoteLocation;
-
-    protected InetSocketAddress remoteAddress;
-
-    protected URI localLocation;
-
-    protected InetSocketAddress localAddress;
+    protected final InetSocketAddress localAddress;
 
     protected SocketConnector connector;
 
@@ -88,52 +76,29 @@
             this.localLocation = local;
             this.localAddress = new InetSocketAddress(InetAddress.getByName(local.getHost()), local.getPort());
         }
-    }
-
-    protected void init() throws Exception {
-        if (protocolHandler == null) {
-            throw new IllegalStateException("Protocol handler not injected");
-        }
-        if (messageVisitor == null) {
-            throw new IllegalStateException("Message visitor not injected");
+        else {
+            // These are final, so make sure to mark them null if we have no local address
+            this.localLocation = null;
+            this.localAddress = null;
         }
-        
-        protocolHandler.setVisitor(messageVisitor);
+    }
 
+    protected synchronized void init() throws Exception {
         ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
 
         connector = new SocketConnector(Runtime.getRuntime().availableProcessors(), executor);
         connector.setConnectTimeout(30);
-        connector.setHandler(protocolHandler);
-
-        DefaultIoFilterChainBuilder filterChain = connector.getFilterChain();
-
-        filterChain.addLast("logger", new LoggingFilter());
-
-        filterChain.addLast("protocol", new ProtocolCodecFilter(new MessageCodecFactory()));
-
-        ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
-
-        filterChain.addLast("reqres", new RequestResponseFilter(protocolHandler.getResponseInspector(), scheduler));
-    }
-
-    //
-    // NOTE: Setters exposed to support Plexus autowire()
-    //
 
-    public void setMessageVisitor(final TcpClientMessageVisitor messageVisitor) {
-        log.debug("Using message visitor: {}", messageVisitor);
+        //
+        // HACK: Need to manually wire in the visitor impl for now... :-(
+        //
 
-        this.messageVisitor = messageVisitor;
-    }
-
-    public void setProtocolHandler(final TcpProtocolHandler protocolHandler) {
-        log.debug("Using protocol handler: {}", protocolHandler);
-
-        this.protocolHandler = protocolHandler;
+        setMessageVisitor((MessageVisitor) getContainer().lookup(MessageVisitor.class, "client"));
+        
+        configure(connector);
     }
 
-    public void connect() throws Exception {
+    public synchronized void connect() throws Exception {
         if (connected) {
             throw new IllegalStateException("Already connected");
         }
@@ -156,6 +121,14 @@
         log.info("Connected");
     }
 
+    public synchronized void close() {
+        CloseFuture cf = session.close();
+
+        cf.awaitUninterruptibly();
+
+        log.info("Closed");
+    }
+
     public URI getRemoteLocation() {
         return remoteLocation;
     }
@@ -164,10 +137,6 @@
         return localLocation;
     }
 
-    //
-    // Transport
-    //
-
     private void doSend(final Object msg) throws Exception {
         assert msg != null;
 
@@ -208,11 +177,5 @@
 
     public OutputStream getOutputStream() {
         return (OutputStream) session.getAttribute(Transport.OUTPUT_STREAM);
-    }
-
-    public void close() {
-        CloseFuture cf = session.close();
-
-        cf.awaitUninterruptibly();
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportFactory.java?rev=576852&r1=576851&r2=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportFactory.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportFactory.java Tue Sep 18 04:25:18 2007
@@ -40,10 +40,15 @@
     @Requirement
     private PlexusContainer container;
 
-    public Transport connect(final URI location) throws Exception {
-        assert location != null;
+    //
+    // NOTE: We use autowire() here to get a few components injected.  These are injected via setters.
+    //
+    
+    public Transport connect(final URI remote, final URI local) throws Exception {
+        assert remote != null;
+        // local can be null
 
-        TcpTransport transport = createTcpTransport(location);
+        TcpTransport transport = createTcpTransport(remote, local);
 
         container.autowire(transport);
 
@@ -52,8 +57,15 @@
         return transport;
     }
 
-    protected TcpTransport createTcpTransport(final URI location) throws Exception {
-        return new TcpTransport(location, null);
+    protected TcpTransport createTcpTransport(final URI remote, final URI local) throws Exception {
+        assert remote != null;
+        // local can be null
+        
+        return new TcpTransport(remote, local);
+    }
+
+    public Transport connect(final URI remote) throws Exception {
+        return connect(remote, null);
     }
 
     public TransportServer bind(final URI location) throws Exception {

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java?rev=576852&r1=576851&r2=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java Tue Sep 18 04:25:18 2007
@@ -25,14 +25,9 @@
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
-import org.apache.geronimo.gshell.remote.filter.LoggingFilter;
-import org.apache.geronimo.gshell.remote.message.MessageCodecFactory;
 import org.apache.geronimo.gshell.remote.transport.TransportServer;
-import org.apache.mina.common.DefaultIoFilterChainBuilder;
-import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Provides TCP server-side support.
@@ -40,17 +35,12 @@
  * @version $Rev$ $Date$
  */
 public class TcpTransportServer
+    extends TcpTransportSupport
     implements TransportServer
 {
-    protected Logger log = LoggerFactory.getLogger(getClass());
+    protected final URI location;
 
-    protected TcpServerMessageVisitor messageVisitor;
-    
-    protected TcpProtocolHandler protocolHandler;
-
-    protected URI location;
-
-    protected InetSocketAddress address;
+    protected final InetSocketAddress address;
 
     protected SocketAcceptor acceptor;
 
@@ -63,48 +53,28 @@
         this.address = new InetSocketAddress(InetAddress.getByName(location.getHost()), location.getPort());
     }
 
-    protected void init() throws Exception {
-        if (protocolHandler == null) {
-            throw new IllegalStateException("Protocol handler not injected");
-        }
-        if (messageVisitor == null) {
-            throw new IllegalStateException("Message visitor not injected");
-        }
-
-        protocolHandler.setVisitor(messageVisitor);
-        
+    protected synchronized void init() throws Exception {
         ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
-        
         acceptor = new SocketAcceptor(Runtime.getRuntime().availableProcessors(), executor);
         acceptor.setLocalAddress(address);
-        acceptor.setHandler(protocolHandler);
 
-        DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
+        //
+        // HACK: Need to manually wire in the visitor impl for now... :-(
+        //
 
-        filterChain.addLast("logger", new LoggingFilter());
+        setMessageVisitor((MessageVisitor) getContainer().lookup(MessageVisitor.class, "server"));
 
-        filterChain.addLast("protocol", new ProtocolCodecFilter(new MessageCodecFactory()));
+        configure(acceptor);
 
+        //
+        // TODO: Setup the authentication validation handler filter
+        //
+        
+        // DefaultIoFilterChainBuilder filterChain = service.getFilterChain();
         // filterChain.addLast("auth", new AuthenticationFilter());
     }
 
-    //
-    // NOTE: Setters exposed to support Plexus autowire()
-    //
-
-    public void setMessageVisitor(final TcpServerMessageVisitor messageVisitor) {
-        log.debug("Using message visitor: {}", messageVisitor);
-
-        this.messageVisitor = messageVisitor;
-    }
-
-    public void setProtocolHandler(final TcpProtocolHandler protocolHandler) {
-        log.debug("Using protocol handler: {}", protocolHandler);
-
-        this.protocolHandler = protocolHandler;
-    }
-
-    public void bind() throws Exception {
+    public synchronized void bind() throws Exception {
         if (bound) {
             throw new IllegalStateException("Already bound");
         }
@@ -118,15 +88,13 @@
         log.info("Listening on: {}", address);
     }
 
-    public URI getLocation() {
-        return location;
-    }
+    public synchronized void close() {
+        acceptor.unbind();
 
-    //
-    // TransportServer
-    //
+        log.info("Closed");
+    }
 
-    public void close() {
-        acceptor.unbind();
+    public URI getLocation() {
+        return location;
     }
 }

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportSupport.java (from r576656, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportSupport.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportSupport.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java&r1=576656&r2=576852&rev=576852&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportSupport.java Tue Sep 18 04:25:18 2007
@@ -19,200 +19,109 @@
 
 package org.apache.geronimo.gshell.remote.transport.tcp;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.URI;
-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.common.tostring.ReflectionToStringBuilder;
 import org.apache.geronimo.gshell.remote.filter.LoggingFilter;
-import org.apache.geronimo.gshell.remote.message.Message;
 import org.apache.geronimo.gshell.remote.message.MessageCodecFactory;
+import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.geronimo.gshell.remote.transport.Transport;
-import org.apache.mina.common.CloseFuture;
-import org.apache.mina.common.ConnectFuture;
+import org.apache.geronimo.gshell.remote.transport.TransportServer;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.WriteFuture;
+import org.apache.mina.common.IoService;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
-import org.apache.mina.filter.reqres.Request;
 import org.apache.mina.filter.reqres.RequestResponseFilter;
-import org.apache.mina.filter.reqres.Response;
-import org.apache.mina.transport.socket.nio.SocketConnector;
+import org.codehaus.plexus.PlexusContainer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Provides TCP client-side support.
+ * Support for TCP {@link Transport} and {@link TransportServer} instances.
  *
  * @version $Rev$ $Date$
  */
-public class TcpTransport
-    implements Transport
+public class TcpTransportSupport
 {
-    private static final int CONNECT_TIMEOUT = 3000;
-
     protected Logger log = LoggerFactory.getLogger(getClass());
 
-    protected TcpClientMessageVisitor messageVisitor;
-
-    protected TcpProtocolHandler protocolHandler;
-
-    protected URI remoteLocation;
-
-    protected InetSocketAddress remoteAddress;
-
-    protected URI localLocation;
-
-    protected InetSocketAddress localAddress;
-
-    protected SocketConnector connector;
+    private PlexusContainer container;
 
-    protected IoSession session;
+    private MessageVisitor messageVisitor;
 
-    protected boolean connected;
+    private TcpProtocolHandler protocolHandler;
 
-    public TcpTransport(final URI remote, final URI local) throws Exception {
-        assert remote != null;
-        // local may be null
-
-        this.remoteLocation = remote;
-        this.remoteAddress = new InetSocketAddress(InetAddress.getByName(remote.getHost()), remote.getPort());
-
-        if (local != null) {
-            this.localLocation = local;
-            this.localAddress = new InetSocketAddress(InetAddress.getByName(local.getHost()), local.getPort());
-        }
+    public String toString() {
+        return ReflectionToStringBuilder.toString(this);
     }
 
-    protected void init() throws Exception {
-        if (protocolHandler == null) {
-            throw new IllegalStateException("Protocol handler not injected");
-        }
-        if (messageVisitor == null) {
-            throw new IllegalStateException("Message visitor not injected");
-        }
-        
-        protocolHandler.setVisitor(messageVisitor);
-
-        ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
+    protected void configure(final IoService service) throws Exception {
+        assert service != null;
 
-        connector = new SocketConnector(Runtime.getRuntime().availableProcessors(), executor);
-        connector.setConnectTimeout(30);
-        connector.setHandler(protocolHandler);
+        TcpProtocolHandler handler = getProtocolHandler();
+        MessageVisitor visitor = getMessageVisitor();
+        handler.setVisitor(visitor);
+        service.setHandler(handler);
 
-        DefaultIoFilterChainBuilder filterChain = connector.getFilterChain();
-
-        filterChain.addLast("logger", new LoggingFilter());
+        DefaultIoFilterChainBuilder filterChain = service.getFilterChain();
+        
+        if (log.isDebugEnabled()) {
+            filterChain.addLast("logging", new LoggingFilter());
+        }
 
         filterChain.addLast("protocol", new ProtocolCodecFilter(new MessageCodecFactory()));
 
         ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
 
-        filterChain.addLast("reqres", new RequestResponseFilter(protocolHandler.getResponseInspector(), scheduler));
+        filterChain.addLast("reqresp", new RequestResponseFilter(protocolHandler.getResponseInspector(), scheduler));
     }
 
     //
-    // NOTE: Setters exposed to support Plexus autowire()
+    // NOTE: Setters exposed to support Plexus autowire()  Getters exposed to handle state checking.
     //
 
-    public void setMessageVisitor(final TcpClientMessageVisitor messageVisitor) {
+    public void setMessageVisitor(final MessageVisitor messageVisitor) {
         log.debug("Using message visitor: {}", messageVisitor);
 
         this.messageVisitor = messageVisitor;
     }
 
+    protected MessageVisitor getMessageVisitor() {
+        if (messageVisitor == null) {
+            throw new IllegalStateException("Message visitor not bound");
+        }
+
+        return messageVisitor;
+    }
+
     public void setProtocolHandler(final TcpProtocolHandler protocolHandler) {
         log.debug("Using protocol handler: {}", protocolHandler);
 
         this.protocolHandler = protocolHandler;
     }
 
-    public void connect() throws Exception {
-        if (connected) {
-            throw new IllegalStateException("Already connected");
-        }
-        
-        init();
-
-        log.info("Connecting to: {}", remoteAddress);
-
-        ConnectFuture cf = connector.connect(remoteAddress, localAddress);
-
-        if (cf.awaitUninterruptibly(CONNECT_TIMEOUT)) {
-             session = cf.getSession();
-        }
-        else {
-            throw new Exception("Failed to connect");
+    protected TcpProtocolHandler getProtocolHandler() {
+        if (protocolHandler == null) {
+            throw new IllegalStateException("Protocol handler not bound");
         }
 
-        connected = true;
-        
-        log.info("Connected");
-    }
-
-    public URI getRemoteLocation() {
-        return remoteLocation;
-    }
-
-    public URI getLocalLocation() {
-        return localLocation;
+        return protocolHandler;
     }
 
     //
-    // Transport
+    // HACK: Added for manual wiring of the message visitor, autowire() can't seem to handle it... :-(
     //
 
-    private void doSend(final Object msg) throws Exception {
-        assert msg != null;
-
-        WriteFuture wf = session.write(msg);
-
-        wf.awaitUninterruptibly();
+    public void setContainer(final PlexusContainer container) {
+        log.debug("Using plexus container: {}", container);
 
-        if (!wf.isWritten()) {
-            throw new IOException("Session did not fully write the message");
-        }
+        this.container = container;
     }
 
-    public void send(final Message msg) throws Exception {
-        assert msg != null;
-
-        doSend(msg);
-    }
-
-    public Message request(final Message msg) throws Exception {
-        return request(msg, 5, TimeUnit.SECONDS);
-    }
-    
-    public Message request(final Message msg, final long timeout, final TimeUnit unit) throws Exception {
-        assert msg != null;
-
-        Request req = new Request(msg.getId(), msg, timeout, unit);
-
-        doSend(req);
-
-        Response resp = req.awaitResponse();
-
-        return (Message) resp.getMessage();
-    }
-
-    public InputStream getInputStream() {
-        return (InputStream) session.getAttribute(Transport.INPUT_STREAM);
-    }
-
-    public OutputStream getOutputStream() {
-        return (OutputStream) session.getAttribute(Transport.OUTPUT_STREAM);
-    }
-
-    public void close() {
-        CloseFuture cf = session.close();
+    protected PlexusContainer getContainer() {
+        if (container == null) {
+            throw new IllegalStateException("Container not bound");
+        }
 
-        cf.awaitUninterruptibly();
+        return container;
     }
 }



Mime
View raw message