geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r578361 - in /geronimo/sandbox/gshell/trunk: gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/ gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/ gshell-remot...
Date Sat, 22 Sep 2007 03:31:47 GMT
Author: jdillon
Date: Fri Sep 21 20:31:46 2007
New Revision: 578361

URL: http://svn.apache.org/viewvc?rev=578361&view=rev
Log:
Added helper for nested IO exceptions
Adding helper for session attribute binding
Cleaned up some threading muck and tidy up logging fluff

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/SessionAttributeBinder.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-support/gshell-common/src/main/java/org/apache/geronimo/gshell/common/NestedIOException.java
      - copied, changed from r578321, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionInputStream.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionOutputStream.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionStreamFilter.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-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java?rev=578361&r1=578360&r2=578361&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
Fri Sep 21 20:31:46 2007
@@ -26,7 +26,7 @@
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 
-import org.apache.mina.common.IoSession;
+import org.apache.geronimo.gshell.remote.util.SessionAttributeBinder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,7 +37,9 @@
  */
 public class RequestManager
 {
-    private static final Logger log = LoggerFactory.getLogger(RequestManager.class);
+    public static final SessionAttributeBinder<RequestManager> BINDER = new SessionAttributeBinder<RequestManager>(RequestManager.class);
+
+    private transient final Logger log = LoggerFactory.getLogger(getClass());
 
     private transient final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors()
+ 1);
 
@@ -46,7 +48,7 @@
     private final Map<Request,TimeoutTask> timeouts = Collections.synchronizedMap(new
HashMap<Request,TimeoutTask>());
     
     //
-    // TODO: Lock on Request.getMutex()
+    // TODO: Lock on Request.getMutex(), and/or change the mutex to a read/write lock?
     //
 
     /**
@@ -265,46 +267,5 @@
         public ScheduledFuture<?> getTimeoutFuture() {
             return timeoutFuture;
         }
-    }
-
-    //
-    // Session Access
-    //
-    
-    public static RequestManager lookup(final IoSession session) {
-        assert session != null;
-
-        RequestManager manager = (RequestManager) session.getAttribute(RequestManager.class.getName());
-
-        if (manager == null) {
-            throw new IllegalStateException("Request manager not bound");
-        }
-
-        log.trace("Looked up: {}", manager);
-        
-        return manager;
-    }
-
-    public static void bind(final IoSession session, final RequestManager manager) {
-        assert session != null;
-        assert manager != null;
-
-        if (session.containsAttribute(RequestManager.class.getName())) {
-            throw new IllegalStateException("Request manager already bound");
-        }
-        
-        session.setAttribute(RequestManager.class.getName(), manager);
-
-        log.trace("Bound: {}", manager);
-    }
-
-    public static RequestManager unbind(final IoSession session) {
-        assert session != null;
-
-        RequestManager manager = (RequestManager) session.removeAttribute(RequestManager.class.getName());
-
-        log.trace("Unbound: {}", manager);
-
-        return manager;
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java?rev=578361&r1=578360&r2=578361&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
Fri Sep 21 20:31:46 2007
@@ -19,9 +19,6 @@
 
 package org.apache.geronimo.gshell.remote.request;
 
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
 import org.apache.geronimo.gshell.remote.message.Message;
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoSession;
@@ -39,26 +36,11 @@
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     /**
-     * Executor used to queue request signal operations.
-     */
-    private final ExecutorService executor;
-
-    public RequestResponseFilter(final ExecutorService executor) {
-        assert executor != null;
-
-        this.executor = executor;
-    }
-
-    public RequestResponseFilter() {
-        this(Executors.newCachedThreadPool());
-    }
-
-    /**
      * Set up the request manager instance for the session.
      */
     @Override
     public void sessionCreated(final NextFilter nextFilter, final IoSession session) throws
Exception {
-        RequestManager.bind(session, new RequestManager());
+        RequestManager.BINDER.bind(session, new RequestManager());
 
         nextFilter.sessionCreated(session);
     }
@@ -68,7 +50,7 @@
      */
     @Override
     public void sessionClosed(final NextFilter nextFilter, final IoSession session) throws
Exception {
-        RequestManager manager = RequestManager.unbind(session);
+        RequestManager manager = RequestManager.BINDER.unbind(session);
 
         manager.close();
         
@@ -86,7 +68,7 @@
             // Register the request with the manager
             Request request = (Request) message;
 
-            RequestManager manager = RequestManager.lookup(session);
+            RequestManager manager = RequestManager.BINDER.lookup(session);
             manager.add(request);
         }
 
@@ -110,24 +92,15 @@
 
         // If we have a correlation id, then we can process the response
         if (id != null) {
-            RequestManager manager = RequestManager.lookup(session);
-
-            final Request request = manager.get(id);
+            RequestManager manager = RequestManager.BINDER.lookup(session);
+            Request request = manager.get(id);
 
             // Cancel the timeout
             manager.cancel(request);
 
             // Setup the response and signal the request
-            final Response response = new Response(request, msg, Response.Type.WHOLE);
-
-            // Signal could block so queue it
-            Runnable task = new Runnable() {
-                public void run() {
-                    request.signal(response);
-                }
-            };
-
-            executor.execute(task);
+            Response response = new Response(request, msg, Response.Type.WHOLE);
+            request.signal(response);
 
             // Do not pass on the response
         }
@@ -144,7 +117,7 @@
         if (message instanceof Request) {
             Request request = (Request) message;
 
-            RequestManager manager = RequestManager.lookup(session);
+            RequestManager manager = RequestManager.BINDER.lookup(session);
 
             manager.schedule(request);
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionInputStream.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/SessionInputStream.java?rev=578361&r1=578360&r2=578361&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionInputStream.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionInputStream.java
Fri Sep 21 20:31:46 2007
@@ -26,10 +26,11 @@
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.geronimo.gshell.common.NestedIOException;
 import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
 import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.remote.util.SessionAttributeBinder;
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoSession;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,8 +42,10 @@
 public class SessionInputStream
     extends InputStream
 {
-    private static final Logger log = LoggerFactory.getLogger(SessionInputStream.class);
-    
+    public static final SessionAttributeBinder<SessionInputStream> BINDER = new SessionAttributeBinder<SessionInputStream>(SessionInputStream.class);
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
     private final Object mutex = new Object();
 
     private final ByteBuffer buff;
@@ -130,9 +133,7 @@
                     mutex.wait();
                 }
                 catch (InterruptedException e) {
-                    IOException n = new IOException("Interrupted while waiting for more data");
-                    n.initCause(e);
-                    throw n;
+                    throw new NestedIOException("Interrupted while waiting for more data");
                 }
             }
         }
@@ -161,10 +162,6 @@
     }
 
     public void write(final WriteStreamMessage msg) {
-        assert msg != null;
-
-        log.debug("Writing...");
-
         synchronized (mutex) {
             if (closed) {
                 return;
@@ -172,11 +169,9 @@
 
             ByteBuffer src = msg.getBuffer();
 
-            log.debug("Filling {} byte(s) into stream from: {}", src.remaining(), src);
+            log.debug("Writing {} bytes", src.remaining());
 
             if (buff.hasRemaining()) {
-                log.debug("Buffer has remaining: {} byte(s)", buff.remaining());
-
                 buff.compact();
                 buff.put(src);
                 buff.flip();
@@ -189,8 +184,6 @@
                 mutex.notifyAll();
             }
         }
-
-        log.debug("Done");
     }
 
     public void throwException(final IOException e) {
@@ -201,42 +194,5 @@
                 mutex.notifyAll();
             }
         }
-    }
-
-    //
-    // Session Access
-    //
-
-    public static SessionInputStream lookup(final IoSession session) {
-        assert session != null;
-
-        SessionInputStream in = (SessionInputStream) session.getAttribute(SessionInputStream.class.getName());
-
-        if (in == null) {
-            throw new IllegalStateException("Input stream not bound");
-        }
-
-        return in;
-    }
-
-    public static void bind(final IoSession session, final SessionInputStream in) {
-        assert session != null;
-        assert in != null;
-
-        Object obj = session.getAttribute(SessionInputStream.class.getName());
-
-        if (obj != null) {
-            throw new IllegalStateException("Input stream already bound");
-        }
-
-        session.setAttribute(SessionInputStream.class.getName(), in);
-
-        log.trace("Bound input stream: {}", in);
-    }
-
-    public static SessionInputStream unbind(final IoSession session) {
-        assert session != null;
-
-        return (SessionInputStream) session.removeAttribute(SessionInputStream.class.getName());
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionOutputStream.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/SessionOutputStream.java?rev=578361&r1=578360&r2=578361&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionOutputStream.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionOutputStream.java
Fri Sep 21 20:31:46 2007
@@ -29,10 +29,10 @@
 import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
 import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
 import org.apache.geronimo.gshell.remote.message.Message;
+import org.apache.geronimo.gshell.remote.util.SessionAttributeBinder;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
-import org.apache.mina.util.NewThreadExecutor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,10 +44,10 @@
 public class SessionOutputStream
     extends OutputStream
 {
-    private static final Logger log = LoggerFactory.getLogger(SessionOutputStream.class);
-
-    private final Object mutex = new Object();
+    public static final SessionAttributeBinder<SessionOutputStream> BINDER = new SessionAttributeBinder<SessionOutputStream>(SessionOutputStream.class);
 
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
     private final IoSession session;
 
     private WriteFuture lastWriteFuture;
@@ -87,9 +87,7 @@
 
     public void write(final int b) throws IOException {
         ByteBuffer buff = ByteBuffer.allocate(1);
-
         buff.put((byte) b);
-
         buff.flip();
 
         write(buff);
@@ -100,95 +98,33 @@
             throw new IOException("The session has been closed.");
         }
     }
+    
+    private synchronized void write(final ByteBuffer buff) throws IOException {
+        ensureOpened();
 
-    private void write(final ByteBuffer buff) throws IOException {
-        synchronized (mutex) {
-            ensureOpened();
-
-            log.debug("Writing: {}", buff);
-
-            Message msg = new WriteStreamMessage(buff);
-
-            //
-            // TODO: See if we should hold on to each of the write futures what we go through
before flushing?
-            //
-            
-            final WriteFuture wf = session.write(msg);
-
-            lastWriteFuture = wf;
-
-            log.debug("Done");
-            
-            new NewThreadExecutor().execute(new Runnable() {
-                public void run() {
-                    log.debug("Waiting for full write");
-
-                    wf.join();
-
-                    log.debug("Completed; written: {}", wf.isWritten());
-                }
-            });
-        }
-    }
-
-    public void flush() throws IOException {
-        synchronized (mutex) {
-            ensureOpened();
-
-            if (lastWriteFuture == null) {
-                return;
-            }
+        log.debug("Writing {} bytes", buff.remaining());
 
-            log.debug("Flushing");
+        Message msg = new WriteStreamMessage(buff);
 
-            // Process the last write future and clear it
-            WriteFuture wf = lastWriteFuture;
-            lastWriteFuture = null;
+        WriteFuture wf = session.write(msg);
 
-            wf.join();
+        lastWriteFuture = wf;
 
-            if (!wf.isWritten()) {
-                throw new IOException("Failed to fully write bytes to the session");
-            }
-
-            log.debug("Flushed");
-        }
+        wf.join();
     }
 
-    //
-    // Session Access
-    //
+    public synchronized void flush() throws IOException {
+        ensureOpened();
 
-    public static SessionOutputStream lookup(final IoSession session) {
-        assert session != null;
-
-        SessionOutputStream out = (SessionOutputStream) session.getAttribute(SessionOutputStream.class.getName());
-
-        if (out == null) {
-            throw new IllegalStateException("Output stream not bound");
+        if (lastWriteFuture == null) {
+            return;
         }
+        
+        // Process the last write future and clear it
+        lastWriteFuture.join();
 
-        return out;
-    }
-
-    public static void bind(final IoSession session, final SessionOutputStream out) {
-        assert session != null;
-        assert out != null;
-
-        Object obj = session.getAttribute(SessionOutputStream.class.getName());
-
-        if (obj != null) {
-            throw new IllegalStateException("Output stream already bound");
+        if (!lastWriteFuture.isWritten()) {
+            throw new IOException("Failed to fully write bytes to the session");
         }
-
-        session.setAttribute(SessionOutputStream.class.getName(), out);
-
-        log.trace("Bound output stream: {}", out);
-    }
-
-    public static SessionOutputStream unbind(final IoSession session) {
-        assert session != null;
-
-        return (SessionOutputStream) session.removeAttribute(SessionOutputStream.class.getName());
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionStreamFilter.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/SessionStreamFilter.java?rev=578361&r1=578360&r2=578361&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionStreamFilter.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionStreamFilter.java
Fri Sep 21 20:31:46 2007
@@ -19,10 +19,6 @@
 
 package org.apache.geronimo.gshell.remote.stream;
 
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoSession;
 import org.codehaus.plexus.util.IOUtil;
@@ -30,7 +26,7 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * ???
+ * Provides stream I/O handling.
  *
  * @version $Rev$ $Date$
  */
@@ -39,96 +35,44 @@
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private final ExecutorService executor;
-
-    public SessionStreamFilter(final ExecutorService executor) {
-        assert executor != null;
-
-        this.executor = executor;
-    }
-
-    public SessionStreamFilter() {
-        this(Executors.newCachedThreadPool());
-    }
-
-    //
-    // TODO: See if we need to put the executor into the session context
-    //
-
-    @Override
-    public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception
{
-        log.debug("Binding session streams");
-
-        SessionInputStream.bind(session, new SessionInputStream());
-
-        SessionOutputStream.bind(session, new SessionOutputStream(session));
+    /**
+     * Setup the input and output streams for the session.
+     */
+    @Override
+    public void sessionCreated(final NextFilter nextFilter, final IoSession session) throws
Exception {
+        SessionInputStream.BINDER.bind(session, new SessionInputStream());
+        SessionOutputStream.BINDER.bind(session, new SessionOutputStream(session));
 
         nextFilter.sessionCreated(session);
     }
 
-    @Override
-    public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception
{
-        log.debug("Unbinding session streams");
-
-        IOUtil.close(SessionInputStream.unbind(session));
-        
-        IOUtil.close(SessionOutputStream.unbind(session));
+    /**
+     * Close the input and output streams for the session.
+     */
+    @Override
+    public void sessionClosed(final NextFilter nextFilter, final IoSession session) throws
Exception {
+        IOUtil.close(SessionInputStream.BINDER.unbind(session));
+        IOUtil.close(SessionOutputStream.BINDER.unbind(session));
 
         nextFilter.sessionClosed(session);
     }
 
-    @Override
-    public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status)
throws Exception {
-        log.debug("Session idle: {}, status: {}", session, status);
-
-        nextFilter.sessionIdle(session, status);
-    }
-
-    @Override
-    public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause)
throws Exception {
-        log.debug("Exception caught: " + session + ", cause: " + cause, cause);
-
-        nextFilter.exceptionCaught(session, cause);
-    }
-
+    /**
+     * Handles write stream messages.
+     */
     @Override
     public void messageReceived(final NextFilter nextFilter, final IoSession session, final
Object message) throws Exception {
         if (message instanceof WriteStreamMessage) {
-            final WriteStreamMessage msg = (WriteStreamMessage) message;
-
-            final SessionInputStream in = SessionInputStream.lookup(session);
-
-            Runnable task = new Runnable() {
-                public void run() {
-                    log.debug("Writing stream...");
-
-                    in.write(msg);
+            WriteStreamMessage msg = (WriteStreamMessage) message;
 
-                    log.debug("Done");
-                }
-            };
+            SessionInputStream in = SessionInputStream.BINDER.lookup(session);
 
-            task.run();
-
-            // executor.execute(task);
+            in.write(msg);
 
             // There is no need to pass on this message to any other filters, they have no
use for it...
         }
         else {
             nextFilter.messageReceived(session, message);
         }
-    }
-
-    @Override
-    public void messageSent(NextFilter nextFilter, IoSession session, Object message) throws
Exception {
-        if (message instanceof WriteStreamMessage) {
-            log.debug("Message sent: {}, msg: {}", session, message);
-
-            //
-            // TODO: Check the future's status?
-            //
-        }
-
-        nextFilter.messageSent(session, message);
     }
 }

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=578361&r1=578360&r2=578361&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
Fri Sep 21 20:31:46 2007
@@ -52,8 +52,6 @@
     extends TransportCommon
     implements Transport
 {
-    private static final int CONNECT_TIMEOUT = 5;
-
     protected final URI remoteLocation;
 
     protected final SocketAddress remoteAddress;
@@ -181,10 +179,10 @@
     }
     
     public InputStream getInputStream() {
-        return SessionInputStream.lookup(session);
+        return SessionInputStream.BINDER.lookup(session);
     }
 
     public OutputStream getOutputStream() {
-        return SessionOutputStream.lookup(session);
+        return SessionOutputStream.BINDER.lookup(session);
     }
 }

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/SessionAttributeBinder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/SessionAttributeBinder.java?rev=578361&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/SessionAttributeBinder.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/SessionAttributeBinder.java
Fri Sep 21 20:31:46 2007
@@ -0,0 +1,79 @@
+/*
+ * 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.util;
+
+import org.apache.mina.common.IoSession;
+
+/**
+ * Helper to manage binding operations for typed session attribute objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SessionAttributeBinder<T>
+{
+    private final String key;
+
+    public SessionAttributeBinder(final String key) {
+        assert key != null;
+        
+        this.key = key;
+    }
+
+    public SessionAttributeBinder(final Class type) {
+        this(type.getName());
+    }
+
+    public SessionAttributeBinder(final Class type, final String suffix) {
+        this(type.getName() + "." + suffix);
+    }
+    
+    @SuppressWarnings({"unchecked"})
+    public T lookup(final IoSession session) {
+        assert session != null;
+
+        T obj = (T) session.getAttribute(key);
+
+        if (obj == null) {
+            throw new IllegalStateException(key + " not bound");
+        }
+
+        return obj;
+    }
+
+    public void bind(final IoSession session, final T obj) {
+        assert session != null;
+        assert obj != null;
+
+        Object prev = session.getAttribute(key);
+
+        if (prev != null) {
+            throw new IllegalStateException(key + " already bound");
+        }
+
+        session.setAttribute(key, obj);
+    }
+
+    @SuppressWarnings({"unchecked"})
+    public T unbind(final IoSession session) {
+        assert session != null;
+
+        return (T) session.removeAttribute(key);
+    }
+}
\ No newline at end of file

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

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

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java?rev=578361&r1=578360&r2=578361&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java
Fri Sep 21 20:31:46 2007
@@ -81,7 +81,7 @@
         session.setAttribute(PlexusContainer.class.getName(), container);
 
         // Setup the I/O context (w/o auto-flushing)
-        IO io = new IO(SessionInputStream.lookup(session), SessionOutputStream.lookup(session),
false);
+        IO io = new IO(SessionInputStream.BINDER.lookup(session), SessionOutputStream.BINDER.lookup(session),
false);
 
         //
         // FIXME: We need to set the verbosity of this I/O context as specified by the client
@@ -162,7 +162,7 @@
             log.info("Making noise...");
             
             final IoSession session = msg.getSession();
-            final PrintWriter out = new PrintWriter(SessionOutputStream.lookup(session),
false);
+            final PrintWriter out = new PrintWriter(SessionOutputStream.BINDER.lookup(session),
false);
 
             new Thread("NOISE MAKER") {
                 public void run() {
@@ -172,7 +172,8 @@
                         
                         try {
                             Thread.sleep(5000);
-                        } catch (InterruptedException e) {
+                        }
+                        catch (InterruptedException e) {
                             e.printStackTrace();
                         }
                     }

Copied: geronimo/sandbox/gshell/trunk/gshell-support/gshell-common/src/main/java/org/apache/geronimo/gshell/common/NestedIOException.java
(from r578321, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-support/gshell-common/src/main/java/org/apache/geronimo/gshell/common/NestedIOException.java?p2=geronimo/sandbox/gshell/trunk/gshell-support/gshell-common/src/main/java/org/apache/geronimo/gshell/common/NestedIOException.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java&r1=578321&r2=578361&rev=578361&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-support/gshell-common/src/main/java/org/apache/geronimo/gshell/common/NestedIOException.java
Fri Sep 21 20:31:46 2007
@@ -17,31 +17,35 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.request;
+package org.apache.geronimo.gshell.common;
+
+import java.io.IOException;
 
 /**
- * Thrown to indicate a request operation failed.
+ * Nested {@link IOException}.
  *
- * @version $Rev$ $Date$
+ * @version $Rev: 577545 $ $Date: 2007-09-19 21:55:19 -0700 (Wed, 19 Sep 2007) $
  */
-public class RequestException
-    extends RuntimeException
+public class NestedIOException
+    extends IOException
 {
     private static final long serialVersionUID = 1;
 
-    public RequestException(final String msg, final Throwable cause) {
-        super(msg, cause);
+    public NestedIOException(final String msg, final Throwable cause) {
+        super(msg);
+
+        initCause(cause);
     }
 
-    public RequestException(final String msg) {
+    public NestedIOException(final String msg) {
         super(msg);
     }
 
-    public RequestException(final Throwable cause) {
-        super(cause);
+    public NestedIOException(final Throwable cause) {
+        initCause(cause);
     }
 
-    public RequestException() {
+    public NestedIOException() {
         super();
     }
 }



Mime
View raw message