directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r165118 - in /directory/network/trunk/src/java/org/apache/mina/protocol: io/IoAdapter.java io/IoProtocolFilterChain.java io/IoProtocolSession.java vmpipe/VmPipeSession.java
Date Thu, 28 Apr 2005 08:49:49 GMT
Author: trustin
Date: Thu Apr 28 01:49:48 2005
New Revision: 165118

URL: http://svn.apache.org/viewcvs?rev=165118&view=rev
Log:
* Added JavaDoc to VmPipeSession
* Extracted IoProtocolSession from IoAdapter so that users can downcast it

Added:
    directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolSession.java  
(with props)
Modified:
    directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
    directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolFilterChain.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java?rev=165118&r1=165117&r2=165118&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java Thu Apr 28
01:49:48 2005
@@ -18,20 +18,14 @@
  */
 package org.apache.mina.protocol.io;
 
-import java.net.SocketAddress;
-import java.util.Set;
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.SessionConfig;
-import org.apache.mina.common.TransportType;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoSession;
 import org.apache.mina.protocol.ProtocolCodecFactory;
 import org.apache.mina.protocol.ProtocolDecoder;
-import org.apache.mina.protocol.ProtocolDecoderOutput;
 import org.apache.mina.protocol.ProtocolEncoder;
-import org.apache.mina.protocol.ProtocolEncoderOutput;
 import org.apache.mina.protocol.ProtocolHandler;
 import org.apache.mina.protocol.ProtocolHandlerFilterChain;
 import org.apache.mina.protocol.ProtocolProvider;
@@ -51,11 +45,11 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public class IoAdapter
+class IoAdapter
 {
     private static final String KEY = "IoAdapter.ProtocolSession";
 
-    private final IoProtocolFilterChain filters = new IoProtocolFilterChain();
+    final IoProtocolFilterChain filters = new IoProtocolFilterChain();
 
     IoAdapter()
     {
@@ -96,8 +90,8 @@
 
     class SessionHandlerAdapter implements IoHandler
     {
-        private final ProtocolCodecFactory codecFactory;
-        private final ProtocolHandler handler;
+        final ProtocolCodecFactory codecFactory;
+        final ProtocolHandler handler;
 
         public SessionHandlerAdapter( ProtocolProvider protocolProvider )
         {
@@ -127,7 +121,7 @@
 
         public void dataRead( IoSession session, ByteBuffer in )
         {
-            ProtocolSessionImpl psession = getProtocolSession( session );
+            IoProtocolSession psession = getProtocolSession( session );
             ProtocolDecoder decoder = psession.decoder;
             try
             {
@@ -170,7 +164,7 @@
 
         void doWrite( IoSession session )
         {
-            ProtocolSessionImpl psession = getProtocolSession( session );
+            IoProtocolSession psession = getProtocolSession( session );
             ProtocolEncoder encoder = psession.encoder;
             Queue writeQueue = psession.writeQueue;
 
@@ -209,238 +203,25 @@
             }
         }
 
-        private ProtocolSessionImpl getProtocolSession( IoSession session )
+        private IoProtocolSession getProtocolSession( IoSession session )
         {
-            ProtocolSessionImpl psession =
-                ( ProtocolSessionImpl ) session.getAttribute( KEY );
+            IoProtocolSession psession =
+                ( IoProtocolSession ) session.getAttribute( KEY );
             if( psession == null )
             {
                 synchronized( session )
                 {
                     psession =
-                        ( ProtocolSessionImpl ) session.getAttribute( KEY );
+                        ( IoProtocolSession ) session.getAttribute( KEY );
                     if( psession == null )
                     {
-                        psession = new ProtocolSessionImpl( session, this );
+                        psession = new IoProtocolSession( IoAdapter.this, session, this );
                         session.setAttribute( KEY, psession );
                     }
                 }
             }
 
             return psession;
-        }
-    }
-
-    class ProtocolSessionImpl implements ProtocolSession
-    {
-        final IoSession session;
-
-        final SessionHandlerAdapter adapter;
-
-        final Queue writeQueue = new Queue();
-        
-        private final ProtocolEncoder encoder;
-        
-        private final ProtocolDecoder decoder;
-
-        private final ProtocolEncoderOutputImpl encOut;
-
-        private final ProtocolDecoderOutputImpl decOut;
-
-        private ProtocolSessionImpl( IoSession session,
-                                    SessionHandlerAdapter adapter )
-        {
-            this.session = session;
-            this.adapter = adapter;
-            this.encoder = adapter.codecFactory.newEncoder();
-            this.decoder = adapter.codecFactory.newDecoder();
-            this.encOut = new ProtocolEncoderOutputImpl();
-            this.decOut = new ProtocolDecoderOutputImpl();
-        }
-
-        public ProtocolHandler getHandler()
-        {
-            return adapter.handler;
-        }
-
-        public ProtocolEncoder getEncoder()
-        {
-            return encoder;
-        }
-
-        public ProtocolDecoder getDecoder()
-        {
-            return decoder;
-        }
-
-        public void close()
-        {
-            session.close();
-        }
-        
-        public void close( boolean wait )
-        {
-            session.close( wait );
-        }
-
-        public Object getAttachment()
-        {
-            return session.getAttachment();
-        }
-
-        public Object setAttachment( Object attachment )
-        {
-            return session.setAttachment( attachment );
-        }
-
-        public Object getAttribute( String key )
-        {
-            return session.getAttribute( key );
-        }
-
-        public Object setAttribute( String key, Object value )
-        {
-            return session.setAttribute( key, value );
-        }
-        
-        public Object removeAttribute( String key )
-        {
-            return session.removeAttribute( key );
-        }
-
-        public Set getAttributeKeys()
-        {
-            return session.getAttributeKeys();
-        }
-
-        public void write( Object message )
-        {
-            filters.filterWrite( this, message );
-        }
-
-        public TransportType getTransportType()
-        {
-            return session.getTransportType();
-        }
-
-        public boolean isConnected()
-        {
-            return session.isConnected();
-        }
-
-        public SessionConfig getConfig()
-        {
-            return session.getConfig();
-        }
-
-        public SocketAddress getRemoteAddress()
-        {
-            return session.getRemoteAddress();
-        }
-
-        public SocketAddress getLocalAddress()
-        {
-            return session.getLocalAddress();
-        }
-
-        public long getReadBytes()
-        {
-            return session.getReadBytes();
-        }
-
-        public long getWrittenBytes()
-        {
-            return session.getWrittenBytes();
-        }
-
-        public long getLastIoTime()
-        {
-            return session.getLastIoTime();
-        }
-
-        public long getLastReadTime()
-        {
-            return session.getLastReadTime();
-        }
-
-        public long getLastWriteTime()
-        {
-            return session.getLastWriteTime();
-        }
-
-        public boolean isIdle( IdleStatus status )
-        {
-            return session.isIdle( status );
-        }
-    }
-
-    private static class ProtocolEncoderOutputImpl implements
-            ProtocolEncoderOutput
-    {
-
-        private final Queue queue = new Queue();
-
-        private ProtocolEncoderOutputImpl()
-        {
-        }
-
-        public void write( ByteBuffer buf )
-        {
-            queue.push( buf );
-        }
-        
-        public void mergeAll()
-        {
-            int sum = 0;
-            final int size = queue.size();
-            
-            if( size < 2 )
-            {
-                // no need to merge!
-                return;
-            }
-            
-            // Get the size of merged BB
-            for( int i = size - 1; i >= 0; i -- )
-            {
-                sum += ( ( ByteBuffer ) queue.get( i ) ).remaining();
-            }
-            
-            // Allocate a new BB that will contain all fragments
-            ByteBuffer newBuf = ByteBuffer.allocate( sum );
-            
-            // and merge all.
-            for( ;; )
-            {
-                ByteBuffer buf = ( ByteBuffer ) queue.pop();
-                if( buf == null )
-                {
-                    break;
-                }
-
-                newBuf.put( buf );
-                buf.release();
-            }
-            
-            // Push the new buffer finally.
-            newBuf.flip();
-            queue.push(newBuf);
-        }
-    }
-
-    private static class ProtocolDecoderOutputImpl implements
-            ProtocolDecoderOutput
-    {
-
-        private final Queue messageQueue = new Queue();
-
-        private ProtocolDecoderOutputImpl()
-        {
-        }
-
-        public void write( Object message )
-        {
-            messageQueue.push( message );
         }
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolFilterChain.java?rev=165118&r1=165117&r2=165118&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolFilterChain.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolFilterChain.java
Thu Apr 28 01:49:48 2005
@@ -2,7 +2,6 @@
 
 import org.apache.mina.protocol.AbstractProtocolHandlerFilterChain;
 import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.protocol.io.IoAdapter.ProtocolSessionImpl;
 import org.apache.mina.util.Queue;
 
 class IoProtocolFilterChain extends AbstractProtocolHandlerFilterChain {
@@ -13,13 +12,13 @@
 
     protected void doWrite( ProtocolSession session, Object message )
     {
-        ProtocolSessionImpl s = ( ProtocolSessionImpl ) session;
+        IoProtocolSession s = ( IoProtocolSession ) session;
         Queue writeQueue = s.writeQueue;
         synchronized( writeQueue )
         {
             writeQueue.push( message );
         }
 
-        s.adapter.doWrite( s.session );
+        s.shAdapter.doWrite( s.session );
     }
 }

Added: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolSession.java?rev=165118&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolSession.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolSession.java Thu
Apr 28 01:49:48 2005
@@ -0,0 +1,248 @@
+/**
+ * 
+ */
+package org.apache.mina.protocol.io;
+
+import java.net.SocketAddress;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.SessionConfig;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.io.IoSession;
+import org.apache.mina.protocol.ProtocolDecoder;
+import org.apache.mina.protocol.ProtocolDecoderOutput;
+import org.apache.mina.protocol.ProtocolEncoder;
+import org.apache.mina.protocol.ProtocolEncoderOutput;
+import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.protocol.io.IoAdapter.SessionHandlerAdapter;
+import org.apache.mina.util.Queue;
+
+/**
+ * A {@link ProtocolSession} that is backed by {@link IoSession}.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class IoProtocolSession implements ProtocolSession
+{
+    private final IoAdapter ioAdapter;
+
+    final IoSession session;
+
+    final SessionHandlerAdapter shAdapter;
+
+    final Queue writeQueue = new Queue();
+    
+    final ProtocolEncoder encoder;
+    
+    final ProtocolDecoder decoder;
+
+    final ProtocolEncoderOutputImpl encOut;
+
+    final ProtocolDecoderOutputImpl decOut;
+
+    IoProtocolSession( IoAdapter ioAdapter, IoSession session,
+                       SessionHandlerAdapter shAdapter )
+    {
+        this.ioAdapter = ioAdapter;
+        this.session = session;
+        this.shAdapter = shAdapter;
+        this.encoder = shAdapter.codecFactory.newEncoder();
+        this.decoder = shAdapter.codecFactory.newDecoder();
+        this.encOut = new ProtocolEncoderOutputImpl();
+        this.decOut = new ProtocolDecoderOutputImpl();
+    }
+    
+    /**
+     * Returns the {@link IoSession} this session is backed by.
+     */
+    public IoSession getIoSession()
+    {
+        return session;   
+    }
+
+    public ProtocolHandler getHandler()
+    {
+        return shAdapter.handler;
+    }
+
+    public ProtocolEncoder getEncoder()
+    {
+        return encoder;
+    }
+
+    public ProtocolDecoder getDecoder()
+    {
+        return decoder;
+    }
+
+    public void close()
+    {
+        session.close();
+    }
+    
+    public void close( boolean wait )
+    {
+        session.close( wait );
+    }
+
+    public Object getAttachment()
+    {
+        return session.getAttachment();
+    }
+
+    public Object setAttachment( Object attachment )
+    {
+        return session.setAttachment( attachment );
+    }
+
+    public Object getAttribute( String key )
+    {
+        return session.getAttribute( key );
+    }
+
+    public Object setAttribute( String key, Object value )
+    {
+        return session.setAttribute( key, value );
+    }
+    
+    public Object removeAttribute( String key )
+    {
+        return session.removeAttribute( key );
+    }
+
+    public Set getAttributeKeys()
+    {
+        return session.getAttributeKeys();
+    }
+
+    public void write( Object message )
+    {
+        this.ioAdapter.filters.filterWrite( this, message );
+    }
+
+    public TransportType getTransportType()
+    {
+        return session.getTransportType();
+    }
+
+    public boolean isConnected()
+    {
+        return session.isConnected();
+    }
+
+    public SessionConfig getConfig()
+    {
+        return session.getConfig();
+    }
+
+    public SocketAddress getRemoteAddress()
+    {
+        return session.getRemoteAddress();
+    }
+
+    public SocketAddress getLocalAddress()
+    {
+        return session.getLocalAddress();
+    }
+
+    public long getReadBytes()
+    {
+        return session.getReadBytes();
+    }
+
+    public long getWrittenBytes()
+    {
+        return session.getWrittenBytes();
+    }
+
+    public long getLastIoTime()
+    {
+        return session.getLastIoTime();
+    }
+
+    public long getLastReadTime()
+    {
+        return session.getLastReadTime();
+    }
+
+    public long getLastWriteTime()
+    {
+        return session.getLastWriteTime();
+    }
+
+    public boolean isIdle( IdleStatus status )
+    {
+        return session.isIdle( status );
+    }
+
+    static class ProtocolEncoderOutputImpl implements ProtocolEncoderOutput
+    {
+    
+        final Queue queue = new Queue();
+        
+        private ProtocolEncoderOutputImpl()
+        {
+        }
+        
+        public void write( ByteBuffer buf )
+        {
+            queue.push( buf );
+        }
+        
+        public void mergeAll()
+        {
+            int sum = 0;
+            final int size = queue.size();
+            
+            if( size < 2 )
+            {
+                // no need to merge!
+                return;
+            }
+            
+            // Get the size of merged BB
+            for( int i = size - 1; i >= 0; i -- )
+            {
+                sum += ( ( ByteBuffer ) queue.get( i ) ).remaining();
+            }
+            
+            // Allocate a new BB that will contain all fragments
+            ByteBuffer newBuf = ByteBuffer.allocate( sum );
+            
+            // and merge all.
+            for( ;; )
+            {
+                ByteBuffer buf = ( ByteBuffer ) queue.pop();
+                if( buf == null )
+                {
+                    break;
+                }
+        
+                newBuf.put( buf );
+                buf.release();
+            }
+            
+            // Push the new buffer finally.
+            newBuf.flip();
+            queue.push(newBuf);
+        }
+    }
+        
+    static class ProtocolDecoderOutputImpl implements ProtocolDecoderOutput
+    {
+        final Queue messageQueue = new Queue();
+        
+        private ProtocolDecoderOutputImpl()
+        {
+        }
+        
+        public void write( Object message )
+        {
+            messageQueue.push( message );
+        }
+    }
+}
\ No newline at end of file

Propchange: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolSession.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java?rev=165118&r1=165117&r2=165118&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java Thu
Apr 28 01:49:48 2005
@@ -17,7 +17,7 @@
 import org.apache.mina.util.BaseSession;
 
 /**
- * TODO Document me.
+ * A {@link ProtocolSession} for in-VM transport (VM_PIPE).
  * 
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$



Mime
View raw message