geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r582034 [2/2] - in /geronimo/sandbox/gshell/trunk: gshell-remote/gshell-remote-client/ gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/ gshell-remote/gshell-remote-client/src/main/java/org/apache/ge...
Date Fri, 05 Oct 2007 00:08:21 GMT
Modified: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/BaseTransport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/BaseTransport.java?rev=582034&r1=582033&r2=582034&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/BaseTransport.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/BaseTransport.java
Thu Oct  4 17:08:17 2007
@@ -19,19 +19,14 @@
 
 package org.apache.geronimo.gshell.whisper.transport.base;
 
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.net.SocketAddress;
 import java.net.URI;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.geronimo.gshell.common.Duration;
-import org.apache.geronimo.gshell.whisper.message.Message;
-import org.apache.geronimo.gshell.whisper.request.Requestor;
-import org.apache.geronimo.gshell.whisper.session.SessionAttributeBinder;
-import org.apache.geronimo.gshell.whisper.session.ThreadPoolModel;
-import org.apache.geronimo.gshell.whisper.stream.SessionInputStream;
-import org.apache.geronimo.gshell.whisper.stream.SessionOutputStream;
+import org.apache.geronimo.gshell.whisper.util.SessionAttributeBinder;
+import org.apache.geronimo.gshell.whisper.transport.base.ThreadPoolModel;
+import org.apache.geronimo.gshell.whisper.transport.Session;
+import org.apache.geronimo.gshell.whisper.transport.base.SessionAdapter;
 import org.apache.geronimo.gshell.whisper.transport.Transport;
 import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.ConnectFuture;
@@ -39,7 +34,6 @@
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.ThreadModel;
-import org.apache.mina.common.WriteFuture;
 
 /**
  * Support for {@link Transport} implementations.
@@ -64,7 +58,7 @@
 
     protected T connector;
 
-    protected IoSession session;
+    protected Session session;
 
     protected BaseTransport(final AddressFactory addressFactory) {
         super(addressFactory);
@@ -145,16 +139,18 @@
         cf.join();
 
         // And fetch session so we can talk
-        session = cf.getSession();
+        IoSession s = cf.getSession();
+        session = new SessionAdapter(s);
+
         log.debug("Session: ", session);
 
         // Maybe configure something
-        configure(session);
+        configure(s);
 
         // Stuff the transport instance into the session's context so we can find ourself
later
-        TRANSPORT.bind(session, this);
+        TRANSPORT.bind(s, this);
 
-        log.info("Connected to: {}", session.getRemoteAddress());
+        log.info("Connected to: {}", s.getRemoteAddress());
     }
 
     public synchronized void close() {
@@ -164,9 +160,12 @@
         }
 
         try {
-            TRANSPORT.unbind(session);
+            IoSession s = session.getSession();
+
+            TRANSPORT.unbind(s);
+            
+            CloseFuture cf = s.close();
             
-            CloseFuture cf = session.close();
             cf.join();
         }
         finally {
@@ -186,51 +185,8 @@
         return connector;
     }
 
-    public IoSession getSession() {
+    public Session getSession() {
         return session;
-    }
-
-    //
-    // Streams
-    //
-
-    public InputStream getInputStream() {
-        return SessionInputStream.BINDER.lookup(session);
-    }
-
-    public OutputStream getOutputStream() {
-        return SessionOutputStream.BINDER.lookup(session);
-    }
-
-    public OutputStream getErrorStream() {
-        throw new UnsupportedOperationException("TODO");
-    }
-
-    //
-    // Sending Messages
-    //
-
-    public WriteFuture send(final Object msg) throws Exception {
-        assert msg != null;
-
-        return session.write(msg);
-    }
-
-    public Message request(final Message msg) throws Exception {
-        assert msg != null;
-
-        Requestor requestor = new Requestor(this);
-
-        return requestor.request(msg);
-    }
-
-    public Message request(final Message msg, final Duration timeout) throws Exception {
-        assert msg != null;
-        assert timeout != null;
-
-        Requestor requestor = new Requestor(this);
-
-        return requestor.request(msg, timeout);
     }
 
     //

Modified: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/BaseTransportServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/BaseTransportServer.java?rev=582034&r1=582033&r2=582034&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/BaseTransportServer.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/BaseTransportServer.java
Thu Oct  4 17:08:17 2007
@@ -23,7 +23,7 @@
 import java.net.URI;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.geronimo.gshell.whisper.session.ThreadPoolModel;
+import org.apache.geronimo.gshell.whisper.transport.base.ThreadPoolModel;
 import org.apache.geronimo.gshell.whisper.transport.TransportServer;
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoHandler;

Copied: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionAdapter.java
(from r580765, geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/TransportAdapter.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionAdapter.java?p2=geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionAdapter.java&p1=geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/TransportAdapter.java&r1=580765&r2=582034&rev=582034&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/TransportAdapter.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionAdapter.java
Thu Oct  4 17:08:17 2007
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.whisper.transport;
+package org.apache.geronimo.gshell.whisper.transport.base;
 
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -30,6 +30,7 @@
 import org.apache.geronimo.gshell.whisper.request.Requestor;
 import org.apache.geronimo.gshell.whisper.stream.SessionInputStream;
 import org.apache.geronimo.gshell.whisper.stream.SessionOutputStream;
+import org.apache.geronimo.gshell.whisper.transport.Session;
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
@@ -39,12 +40,14 @@
  *
  * @version $Rev$ $Date$
  */
-public class TransportAdapter
-    implements Transport
+public class SessionAdapter
+    implements Session
 {
     private final IoSession session;
 
-    public TransportAdapter(final IoSession session) {
+    private boolean closed;
+
+    public SessionAdapter(final IoSession session) {
         assert session != null;
 
         this.session = session;
@@ -54,49 +57,31 @@
         return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
     }
 
-    public URI getRemote() {
-        throw new UnsupportedOperationException();
-    }
-
-    public URI getLocal() {
-        throw new UnsupportedOperationException();
-    }
-
-    public IoConnector getConnector() {
-        throw new UnsupportedOperationException();
-    }
-
     public IoSession getSession() {
         ensureOpened();
 
         return session;
     }
 
-    //
-    // Streams
-    //
-
-    public InputStream getInputStream() {
-        ensureOpened();
-
-        return SessionInputStream.BINDER.lookup(session);
+    public synchronized boolean isClosed() {
+        return closed;
     }
 
-    public OutputStream getOutputStream() {
-        ensureOpened();
-
-        return SessionOutputStream.BINDER.lookup(session);
+    protected void ensureOpened() {
+        if (isClosed()) {
+            throw new IllegalStateException("Closed");
+        }
     }
 
-    public OutputStream getErrorStream() {
-        ensureOpened();
+    public synchronized void close() {
+        if (isClosed()) {
+            return;
+        }
 
-        throw new UnsupportedOperationException();
-    }
+        session.close();
 
-    //
-    // Sending Messages
-    //
+        closed = true;
+    }
 
     public WriteFuture send(final Object msg) throws Exception {
         assert msg != null;
@@ -127,57 +112,21 @@
         return requestor.request(msg, timeout);
     }
 
-    //
-    // Closeable
-    //
-
-    private boolean closed;
-
-    public synchronized boolean isClosed() {
-        return closed;
-    }
-
-    protected void ensureOpened() {
-        if (isClosed()) {
-            throw new IllegalStateException("Closed");
-        }
-    }
-
-    public synchronized void close() {
-        if (isClosed()) {
-            return;
-        }
-
-        session.close();
-        
-        closed = true;
-    }
-
-    //
-    // Listeners
-    //
-
-    public void addListener(final Listener listener) {
-        assert listener != null;
+    public InputStream getInputStream() {
+        ensureOpened();
 
-        throw new UnsupportedOperationException();
+        return SessionInputStream.BINDER.lookup(session);
     }
 
-    public void removeListener(final Listener listener) {
-        assert listener != null;
+    public OutputStream getOutputStream() {
+        ensureOpened();
 
-        throw new UnsupportedOperationException();
+        return SessionOutputStream.BINDER.lookup(session);
     }
 
-    //
-    // Configuration
-    //
-
-    public void setConfiguration(final Configuration config) {
-        throw new UnsupportedOperationException();
-    }
+    public OutputStream getErrorStream() {
+        ensureOpened();
 
-    public Configuration getConfiguration() {
         throw new UnsupportedOperationException();
     }
 }

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionBindingFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionBindingFilter.java?rev=582034&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionBindingFilter.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionBindingFilter.java
Thu Oct  4 17:08:17 2007
@@ -0,0 +1,56 @@
+/*
+ * 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.whisper.transport.base;
+
+import org.apache.geronimo.gshell.whisper.transport.Session;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A simple filter which handles binding and unbinding the Whisper {@link Session} instance
+ * when Mina creates and closes its native session.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SessionBindingFilter
+    extends IoFilterAdapter
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Override
+    public void sessionCreated(final NextFilter nextFilter, final IoSession session) throws
Exception {
+        Session s = Session.BINDER.bind(session, new SessionAdapter(session));
+
+        log.debug("Bound: {}", s);
+
+        nextFilter.sessionCreated(session);
+    }
+
+    @Override
+    public void sessionClosed(final NextFilter nextFilter, final IoSession session) throws
Exception {
+        Session s = Session.BINDER.unbind(session);
+
+        log.debug("Unbound: {}", s);
+
+        nextFilter.sessionClosed(session);
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionBindingFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionBindingFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/SessionBindingFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/ThreadPoolModel.java
(from r580765, geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/session/ThreadPoolModel.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/ThreadPoolModel.java?p2=geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/ThreadPoolModel.java&p1=geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/session/ThreadPoolModel.java&r1=580765&r2=582034&rev=582034&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/session/ThreadPoolModel.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/ThreadPoolModel.java
Thu Oct  4 17:08:17 2007
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.whisper.session;
+package org.apache.geronimo.gshell.whisper.transport.base;
 
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadFactory;

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/ThreadPoolModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/ThreadPoolModel.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/transport/base/ThreadPoolModel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/util/SessionAttributeBinder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/util/SessionAttributeBinder.java?rev=582034&r1=580765&r2=582034&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/util/SessionAttributeBinder.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/util/SessionAttributeBinder.java
Thu Oct  4 17:08:17 2007
@@ -17,9 +17,11 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.whisper.session;
+package org.apache.geronimo.gshell.whisper.util;
 
 import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Helper to manage binding operations for typed session attribute objects.
@@ -28,6 +30,8 @@
  */
 public class SessionAttributeBinder<T>
 {
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
     private final String key;
 
     public SessionAttributeBinder(final String key) {
@@ -88,6 +92,8 @@
 
         session.setAttribute(key, obj);
 
+        log.trace("Bound {} ", obj);
+
         return obj;
     }
     
@@ -100,6 +106,8 @@
 
         session.setAttribute(key, obj);
 
+        log.trace("Rebound {}", obj);
+
         return prev;
     }
 
@@ -107,7 +115,11 @@
     public T unbind(final IoSession session) {
         assert session != null;
 
-        return (T) session.removeAttribute(key);
+        T obj = (T) session.removeAttribute(key);
+
+        log.trace("Unbound {}", obj);
+
+        return obj;
     }
 
     public static class NotBoundException

Modified: geronimo/sandbox/gshell/trunk/gshell-whisper/src/test/java/org/apache/geronimo/gshell/whisper/message/PingPongProtocolTester.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/test/java/org/apache/geronimo/gshell/whisper/message/PingPongProtocolTester.java?rev=582034&r1=582033&r2=582034&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/test/java/org/apache/geronimo/gshell/whisper/message/PingPongProtocolTester.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/test/java/org/apache/geronimo/gshell/whisper/message/PingPongProtocolTester.java
Thu Oct  4 17:08:17 2007
@@ -22,6 +22,7 @@
 import java.net.URI;
 import java.util.Map;
 
+import org.apache.geronimo.gshell.whisper.transport.Session;
 import org.apache.geronimo.gshell.whisper.transport.Transport;
 import org.apache.geronimo.gshell.whisper.transport.TransportFactory;
 import org.apache.geronimo.gshell.whisper.transport.TransportFactoryLocator;
@@ -156,9 +157,11 @@
 
         log("Client: " + client);
 
+        Session session = client.getSession();
+
         Thread.sleep(5 * 1000);
 
-        client.send(new PingMessage()).join();
+        session.send(new PingMessage()).join();
         
         Thread.sleep(30 * 1000);
 



Mime
View raw message