geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r576633 - 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-common/sr...
Date Tue, 18 Sep 2007 00:24:47 GMT
Author: jdillon
Date: Mon Sep 17 17:24:46 2007
New Revision: 576633

URL: http://svn.apache.org/viewvc?rev=576633&view=rev
Log:
Added timestamp & correlation id to message
Changed attachment to session, changed accessor to toss ISE if not set
Added freeze to prevent unwanted message alteration
Using ReflectionToStringBuilder in MessageSupport for uniform toString() behavior for all
Message impls
Allow visitor methods to throw an Exception
And some other fluff...

Modified:
    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/HandShakeMessage.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/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/stream/IoSessionInputStream.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionOutputStream.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/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/TcpProtocolHandler.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpServerMessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/pom.xml

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -60,6 +60,7 @@
 
         client.handshake();
 
+        /*
         client.echo("READ_STREAMS");
 
         OutputStream out = client.getOutputStream();
@@ -112,9 +113,17 @@
 
         t.join();
         t2.join();
+        */
+
+        boolean running = true;
         
+        while (running) {
+            client.echo(new Date().toString());
+            Thread.sleep(1000 * 5);
+        }
+
         client.close();
-        
+
         return SUCCESS;
     }
 }

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -45,10 +45,6 @@
         return text;
     }
 
-    public String toString() {
-        return super.toString() + "{ id=" + getId() + ", text=" + text + " }";
-    }
-    
     public void readExternal(final ByteBuffer buff) throws Exception {
         assert buff != null;
 

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -51,10 +51,6 @@
         this.publicKey = publicKey;
     }
 
-    public String toString() {
-        return super.toString() + "{ id=" + getId() + ", publicKey=" + publicKey + " }";
-    }
-
     public void readExternal(final ByteBuffer buff) throws Exception {
         assert buff != null;
 

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -22,7 +22,7 @@
 import java.io.IOException;
 import java.util.UUID;
 
-import org.apache.geronimo.gshell.remote.message.MarshalAware;
+import org.apache.mina.common.IoSession;
 
 /**
  * ???
@@ -34,11 +34,21 @@
 {
     UUID getId();
 
+    UUID getCorrelationId();
+
+    void setCorrelationId(UUID id);
+
     MessageType getType() throws IOException;
 
-    void setAttachment(Object obj);
+    long getTimestamp();
+
+    void setSession(IoSession session);
 
-    Object getAttachment();
+    IoSession getSession();
 
     void process(MessageVisitor visitor) throws Exception;
+
+    void freeze();
+
+    boolean isFrozen();
 }

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -72,7 +72,7 @@
     
     public synchronized Object getRequestId(final Object message) {
         if (message instanceof Message) {
-            UUID id = ((Message)message).getId();
+            UUID id = ((Message)message).getCorrelationId();
 
             if (registeredIds.contains(id)) {
                 return id;
@@ -82,6 +82,10 @@
         return null;
     }
 
+    //
+    // TODO: Figure out wtf this is for...
+    //
+    
     public ResponseType getResponseType(final Object message) {
         return ResponseType.WHOLE;
     }

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -24,7 +24,10 @@
 import java.nio.charset.Charset;
 import java.util.UUID;
 
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
 import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
 
 /**
  * ???
@@ -37,8 +40,14 @@
     private MessageType type;
 
     private UUID id;
+
+    private UUID correlationId;
+
+    private long timestamp;
     
-    private transient Object attachment;
+    private transient IoSession session;
+
+    private transient boolean frozen;
 
     protected MessageSupport(final MessageType type) {
         assert type != null;
@@ -46,26 +55,62 @@
         this.type = type;
 
         this.id = UUID.randomUUID();
+
+        this.timestamp = System.currentTimeMillis();
     }
-    
-    public UUID getId() {
-        return id;
+
+    public String toString() {
+        return ReflectionToStringBuilder.toString(this);
     }
 
-    public void setId(final UUID id) {
-        this.id = id;
+    public UUID getId() {
+        return id;
     }
     
     public MessageType getType() throws IOException {
         return type;
     }
 
-    public void setAttachment(final Object obj) {
-        this.attachment = obj;
+    public UUID getCorrelationId() {
+        return correlationId;
+    }
+
+    public void setCorrelationId(final UUID id) {
+        ensureWritable();
+        
+        this.correlationId = id;
+    }
+
+    public long getTimestamp() {
+        return timestamp;
     }
 
-    public Object getAttachment() {
-        return attachment;
+    public void setSession(final IoSession session) {
+        ensureWritable();
+        
+        this.session = session;
+    }
+
+    public IoSession getSession() {
+        if (session == null) {
+            throw new IllegalStateException("Session has not been attached");
+        }
+        
+        return session;
+    }
+
+    protected void ensureWritable() {
+        if (frozen) {
+            throw new IllegalStateException("Message is frozen");
+        }
+    }
+
+    public void freeze() {
+        frozen = true;
+    }
+
+    public boolean isFrozen() {
+        return frozen;
     }
 
     public void process(final MessageVisitor visitor) throws Exception {
@@ -79,17 +124,25 @@
     public void readExternal(final ByteBuffer buff) throws Exception {
         assert buff != null;
 
+        type = buff.getEnum(MessageType.class);
+        
         id = (UUID) buff.getObject();
 
-        type = buff.getEnum(MessageType.class);
+        correlationId = (UUID) buff.getObject();
+
+        timestamp = buff.getLong();
     }
 
     public void writeExternal(final ByteBuffer buff) throws Exception {
         assert buff != null;
 
-        buff.putObject(id);
-        
         buff.putEnum(type);
+
+        buff.putObject(id);
+
+        buff.putObject(correlationId);
+
+        buff.putLong(timestamp);
     }
 
     //
@@ -114,5 +167,19 @@
         out.putInt(len);
         
         out.putString(str, len, UTF_8_CHARSET.newEncoder());
+    }
+
+    //
+    // Reply Helpers
+    //
+    
+    public WriteFuture reply(final MessageSupport msg) {
+        assert msg != null;
+
+        IoSession session = getSession();
+
+        msg.setCorrelationId(getId());
+
+        return session.write(msg);
     }
 }

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -26,9 +26,9 @@
  */
 public interface MessageVisitor
 {
-    void visitEcho(EchoMessage msg);
+    void visitEcho(EchoMessage msg) throws Exception;
 
-    void visitHandShake(HandShakeMessage msg);
+    void visitHandShake(HandShakeMessage msg) throws Exception;
     
-    void visitWriteStream(WriteStreamMessage msg);
+    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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -27,15 +27,15 @@
 public class MessageVisitorAdapter
     implements MessageVisitor
 {
-    public void visitEcho(EchoMessage msg) {
+    public void visitEcho(EchoMessage msg) throws Exception {
         // Empty
     }
 
-    public void visitHandShake(HandShakeMessage msg) {
+    public void visitHandShake(HandShakeMessage msg) throws Exception {
         // Empty
     }
 
-    public void visitWriteStream(WriteStreamMessage msg) {
+    public void visitWriteStream(WriteStreamMessage msg) throws Exception {
         // Empty
     }
 }

Modified: 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=576633&r1=576632&r2=576633&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionInputStream.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionInputStream.java
Mon Sep 17 17:24:46 2007
@@ -94,7 +94,7 @@
     }
 
     @Override
-    public int read(byte[] b, int off, int len) throws IOException {
+    public int read(final byte[] b, final int off, final int len) throws IOException {
         synchronized (mutex) {
             if (!waitForData()) {
                 return -1;
@@ -175,7 +175,7 @@
         }
     }
 
-    public void throwException(IOException e) {
+    public void throwException(final IOException e) {
         synchronized (mutex) {
             if (exception == null) {
                 exception = e;

Modified: 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=576633&r1=576632&r2=576633&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionOutputStream.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/IoSessionOutputStream.java
Mon Sep 17 17:24:46 2007
@@ -55,6 +55,10 @@
             flush();
         }
         finally {
+            //
+            // FIXME: This probably should not close the session...
+            //
+            
             session.close().awaitUninterruptibly();
         }
     }
@@ -74,12 +78,12 @@
     }
 
     @Override
-    public void write(byte[] b, int off, int len) throws IOException {
+    public void write(final byte[] b, final int off, final int len) throws IOException {
         write(ByteBuffer.wrap(b.clone(), off, len));
     }
 
     @Override
-    public void write(int b) throws IOException {
+    public void write(final int b) throws IOException {
         ByteBuffer buf = ByteBuffer.allocate(1);
         buf.put((byte) b);
         buf.flip();

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -21,6 +21,7 @@
 
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.geronimo.gshell.remote.message.Message;
 
@@ -40,6 +41,8 @@
     String ERROR_STREAM = STREAM_BASENAME + "ERR";
 
     void send(Message msg) throws Exception;
+
+    Message request(Message msg, long timeout, TimeUnit unit) throws Exception;
 
     Message request(Message msg) throws Exception;
 

Modified: 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-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpClientMessageVisitor.java?rev=576633&r1=576632&r2=576633&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-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpClientMessageVisitor.java
Mon Sep 17 17:24:46 2007
@@ -38,7 +38,7 @@
 public class TcpClientMessageVisitor
     extends TcpMessageVisitorSupport
 {
-    public void visitEcho(final EchoMessage msg) {
+    public void visitEcho(final EchoMessage msg) throws Exception {
         assert msg != null;
 
         log.info("ECHO: {}", msg.getText());

Modified: 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/transport/tcp/TcpMessageVisitorSupport.java?rev=576633&r1=576632&r2=576633&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/transport/tcp/TcpMessageVisitorSupport.java
Mon Sep 17 17:24:46 2007
@@ -19,12 +19,19 @@
 
 package org.apache.geronimo.gshell.remote.transport.tcp;
 
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
 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.message.Message;
 import org.apache.geronimo.gshell.remote.stream.IoSessionInputStream;
 import org.apache.geronimo.gshell.remote.transport.Transport;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.filter.reqres.Request;
+import org.apache.mina.filter.reqres.Response;
 import org.codehaus.plexus.component.annotations.Component;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,11 +46,10 @@
 {
     protected Logger log = LoggerFactory.getLogger(getClass());
 
-    public void visitWriteStream(final WriteStreamMessage msg) {
+    public void visitWriteStream(final WriteStreamMessage msg) throws Exception {
         assert msg != null;
 
-        IoSession session = (IoSession) msg.getAttachment();
-        assert session != null;
+        IoSession session = msg.getSession();
 
         // Look up the bound stream in the session context
         String key = Transport.STREAM_BASENAME + msg.getName();

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -62,27 +62,30 @@
         return responseInspector;
     }
 
-    public void messageReceived(final IoSession session, final Object message) throws Exception
{
+    public void messageReceived(final IoSession session, final Object obj) throws Exception
{
         assert session != null;
-        assert message != null;
+        assert obj != null;
 
-        if (message instanceof Message) {
-            Message msg = (Message)message;
+        log.info("Message received: {}", obj);
+
+        if (obj instanceof Message) {
+            Message msg = (Message)obj;
 
             if (visitor != null) {
-                msg.setAttachment(session);
+                msg.setSession(session);
+                msg.freeze();
                 msg.process(visitor);
             }
         }
-        else if (message instanceof Response) {
-            Response resp = (Response)message;
+        else if (obj instanceof Response) {
+            Response resp = (Response)obj;
 
             Request req = resp.getRequest();
 
             responseInspector.deregister(req);
         }
         else {
-            log.error("Unhandled message: {}", message);
+            log.error("Unhandled message: {}", obj);
         }
     }
 
@@ -141,11 +144,11 @@
         session.close();
     }
 
-    public void messageSent(final IoSession session, final Object message) throws Exception
{
-        log.info("Message sent: {}", message);
+    public void messageSent(final IoSession session, final Object obj) throws Exception {
+        log.info("Message sent: {}", obj);
 
-        if (message instanceof Request) {
-            Request req = (Request) message;
+        if (obj instanceof Request) {
+            Request req = (Request) obj;
 
             responseInspector.register(req);
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpServerMessageVisitor.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/TcpServerMessageVisitor.java?rev=576633&r1=576632&r2=576633&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpServerMessageVisitor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpServerMessageVisitor.java
Mon Sep 17 17:24:46 2007
@@ -28,15 +28,9 @@
 
 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.geronimo.gshell.remote.transport.Transport;
-import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
 import org.codehaus.plexus.component.annotations.Component;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * ???
@@ -47,12 +41,9 @@
 public class TcpServerMessageVisitor
     extends TcpMessageVisitorSupport
 {
-    public void visitEcho(final EchoMessage msg) {
+    public void visitEcho(final EchoMessage msg) throws Exception {
         assert msg != null;
 
-        final IoSession session = (IoSession) msg.getAttachment();
-        assert session != null;
-
         String text = msg.getText();
 
         //
@@ -60,6 +51,8 @@
         //
 
         if ("READ_STREAMS".equals(text)) {
+            final IoSession session = msg.getSession();
+
             OutputStream out = (OutputStream) session.getAttribute(Transport.OUTPUT_STREAM);
             final PrintWriter writer = new PrintWriter(out);
 
@@ -109,22 +102,17 @@
             t2.start();
         }
         else {
-            log.info("ECHO: {}", text);
+            log.info("ECHOING: {}", text);
+
+            msg.reply(new EchoMessage(text));
         }
     }
 
-    public void visitHandShake(final HandShakeMessage msg) {
+    public void visitHandShake(final HandShakeMessage msg) throws Exception {
         assert msg != null;
 
         log.info("HANDSHAKE");
 
-        IoSession session = (IoSession) msg.getAttachment();
-        assert session != null;
-
-        // For now just echo something back, with the same ID
-        EchoMessage resp = new EchoMessage("SUCCESS");
-        resp.setId(msg.getId());
-
-        session.write(resp);
+        msg.reply(new EchoMessage("SUCCESS"));
     }
 }

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -187,9 +187,13 @@
     }
 
     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, 1, TimeUnit.SECONDS);
+        Request req = new Request(msg.getId(), msg, timeout, unit);
 
         doSend(req);
 

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=576633&r1=576632&r2=576633&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
Mon Sep 17 17:24:46 2007
@@ -19,9 +19,9 @@
 
 package org.apache.geronimo.gshell.remote.transport.tcp;
 
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.URI;
-import java.net.InetAddress;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -29,7 +29,6 @@
 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.common.CloseFuture;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
 import org.slf4j.Logger;

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/pom.xml?rev=576633&r1=576632&r2=576633&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/pom.xml Mon Sep 17 17:24:46 2007
@@ -41,6 +41,12 @@
     
     <dependencies>
         <dependency>
+            <groupId>org.apache.geronimo.gshell.support</groupId>
+            <artifactId>gshell-common</artifactId>
+            <version>${version}</version>
+        </dependency>
+        
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>



Mime
View raw message