directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r371290 [2/2] - in /directory/sandbox/trustin/mina-spi/core/src: main/java/org/apache/mina/common/support/discovery/ main/java/org/apache/mina/common/support/discovery/jdk/ main/java/org/apache/mina/common/support/discovery/tools/ main/java...
Date Sun, 22 Jan 2006 13:52:59 GMT
Modified: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSession.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSession.java?rev=371290&r1=371289&r2=371290&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSession.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSession.java
Sun Jan 22 05:52:31 2006
@@ -32,6 +32,7 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.BaseIoSession;
+import org.apache.mina.common.support.IoSessionAttributeOverrider;
 import org.apache.mina.util.Queue;
 
 /**
@@ -42,8 +43,18 @@
  */
 class SocketSession extends BaseIoSession
 {
-    private static final int DEFAULT_READ_BUFFER_SIZE = 1024;
-
+    private static final IoSessionAttributeOverrider[] OVERRIDERS =
+    {
+        new KeepAliveOverrider(),
+        new OOBInlineOverrider(),
+        new ReuseAddressOverrider(),
+        new LingerOverrider(),
+        new NoDelayOverrider(),
+        new TrafficClassOverrider(),
+        new SendBufferSizeOverrider(),
+        new ReceiveBufferSizeOverrider(),
+    };
+    
     private final SocketIoProcessor ioProcessor;
     private final SocketFilterChain filterChain;
     private final SocketChannel ch;
@@ -53,14 +64,15 @@
     private final IoAddress localAddress;
     private final Set managedSessions;    
     private SelectionKey key;
-    private int readBufferSize = DEFAULT_READ_BUFFER_SIZE;
+    private int readBufferSize;
 
     /**
      * Creates a new instance.
+     * @throws SocketException 
      */
     public SocketSession(
             Set managedSessions,
-            SocketChannel ch, IoHandler defaultHandler )
+            SocketChannel ch, IoHandler defaultHandler ) throws SocketException
     {
         this.managedSessions = managedSessions;
         this.ioProcessor = SocketIoProcessor.getInstance();
@@ -70,6 +82,8 @@
         this.handler = defaultHandler;
         this.remoteAddress = SocketAddresses.compose( "socket", ch.socket().getRemoteSocketAddress()
);
         this.localAddress = SocketAddresses.compose( "socket", ch.socket().getLocalSocketAddress()
);
+        this.readBufferSize = ch.socket().getReceiveBufferSize();
+        this.attributeOverriders = OVERRIDERS;
     }
     
     SocketIoProcessor getIoProcessor()
@@ -144,104 +158,196 @@
     {
         return localAddress;
     }
-
-    public boolean getKeepAlive() throws SocketException
+    
+    protected void updateTrafficMask()
     {
-        return ch.socket().getKeepAlive();
+        this.ioProcessor.updateTrafficMask( this );
     }
-
-    public void setKeepAlive( boolean on ) throws SocketException
+    
+    int getReadBufferSize()
     {
-        ch.socket().setKeepAlive( on );
+        return readBufferSize;
     }
 
-    public boolean getOOBInline() throws SocketException
+    private static class KeepAliveOverrider implements IoSessionAttributeOverrider
     {
-        return ch.socket().getOOBInline();
-    }
+        public String getKey()
+        {
+            return Constants.KEEP_ALIVE;
+        }
 
-    public void setOOBInline( boolean on ) throws SocketException
-    {
-        ch.socket().setOOBInline( on );
-    }
+        public Object getValue( IoSession session ) throws Exception
+        {
+            return ( ( SocketSession ) session ).getChannel().socket().getKeepAlive()? Boolean.TRUE
: Boolean.FALSE;
+        }
 
-    public boolean getReuseAddress() throws SocketException
-    {
-        return ch.socket().getReuseAddress();
+        public Object setValue( IoSession session, Object value ) throws Exception
+        {
+            Object oldValue = getValue( session );
+            ( ( SocketSession ) session ).getChannel().socket().setKeepAlive(
+                    ( ( Boolean ) value ).equals( Boolean.TRUE ) );
+            return oldValue;
+        }
+        
     }
 
-    public void setReuseAddress( boolean on ) throws SocketException
+    private static class OOBInlineOverrider implements IoSessionAttributeOverrider
     {
-        ch.socket().setReuseAddress( on );
-    }
+        public String getKey()
+        {
+            return Constants.OOB_INLINE;
+        }
 
-    public int getSoLinger() throws SocketException
-    {
-        return ch.socket().getSoLinger();
-    }
+        public Object getValue( IoSession session ) throws Exception
+        {
+            return ( ( SocketSession ) session ).getChannel().socket().getOOBInline()? Boolean.TRUE
: Boolean.FALSE;
+        }
 
-    public void setSoLinger( boolean on, int linger ) throws SocketException
-    {
-        ch.socket().setSoLinger( on, linger );
+        public Object setValue( IoSession session, Object value ) throws Exception
+        {
+            Object oldValue = getValue( session );
+            ( ( SocketSession ) session ).getChannel().socket().setOOBInline(
+                    ( ( Boolean ) value ).equals( Boolean.TRUE ) );
+            return oldValue;
+        }
+        
     }
 
-    public boolean getTcpNoDelay() throws SocketException
+    private static class ReuseAddressOverrider implements IoSessionAttributeOverrider
     {
-        return ch.socket().getTcpNoDelay();
-    }
+        public String getKey()
+        {
+            return Constants.REUSE_ADDRESS;
+        }
 
-    public void setTcpNoDelay( boolean on ) throws SocketException
-    {
-        ch.socket().setTcpNoDelay( on );
-    }
+        public Object getValue( IoSession session ) throws Exception
+        {
+            return ( ( SocketSession ) session ).getChannel().socket().getReuseAddress()?
Boolean.TRUE : Boolean.FALSE;
+        }
 
-    public int getTrafficClass() throws SocketException
-    {
-        return ch.socket().getTrafficClass();
+        public Object setValue( IoSession session, Object value ) throws Exception
+        {
+            Object oldValue = getValue( session );
+            ( ( SocketSession ) session ).getChannel().socket().setReuseAddress(
+                    ( ( Boolean ) value ).equals( Boolean.TRUE ) );
+            return oldValue;
+        }
+        
     }
-
-    public void setTrafficClass( int tc ) throws SocketException
+    
+    private static class LingerOverrider implements IoSessionAttributeOverrider
     {
-        ch.socket().setTrafficClass( tc );
-    }
+        public String getKey()
+        {
+            return Constants.LINGER;
+        }
 
-    public int getSendBufferSize() throws SocketException
-    {
-        return ch.socket().getSendBufferSize();
-    }
+        public Object getValue( IoSession session ) throws Exception
+        {
+            return new Integer( ( ( SocketSession ) session ).getChannel().socket().getSoLinger()
);
+        }
 
-    public void setSendBufferSize( int size ) throws SocketException
-    {
-        ch.socket().setSendBufferSize( size );
+        public Object setValue( IoSession session, Object value ) throws Exception
+        {
+            Object oldValue = getValue( session );
+            Integer linger = ( Integer ) value;
+            if( linger.intValue() < 0 )
+            {
+                ( ( SocketSession ) session ).getChannel().socket().setSoLinger( false, 0
);
+            }
+            else
+            {
+                ( ( SocketSession ) session ).getChannel().socket().setSoLinger( true, linger.intValue()
);
+            }
+            return oldValue;
+        }
+        
     }
 
-    public int getReceiveBufferSize() throws SocketException
+    private static class NoDelayOverrider implements IoSessionAttributeOverrider
     {
-        return ch.socket().getReceiveBufferSize();
-    }
+        public String getKey()
+        {
+            return Constants.NO_DELAY;
+        }
 
-    public void setReceiveBufferSize( int size ) throws SocketException
-    {
-        ch.socket().setReceiveBufferSize( size );
+        public Object getValue( IoSession session ) throws Exception
+        {
+            return ( ( SocketSession ) session ).getChannel().socket().getTcpNoDelay()? Boolean.TRUE
: Boolean.FALSE;
+        }
+
+        public Object setValue( IoSession session, Object value ) throws Exception
+        {
+            Object oldValue = getValue( session );
+            ( ( SocketSession ) session ).getChannel().socket().setTcpNoDelay(
+                    ( ( Boolean ) value ).equals( Boolean.TRUE ) );
+            return oldValue;
+        }
+        
     }
     
-    public int getSessionReceiveBufferSize()
+    private static class TrafficClassOverrider implements IoSessionAttributeOverrider
     {
-        return readBufferSize;
+        public String getKey()
+        {
+            return Constants.TRAFFIC_CLASS;
+        }
+
+        public Object getValue( IoSession session ) throws Exception
+        {
+            return new Integer( ( ( SocketSession ) session ).getChannel().socket().getTrafficClass()
);
+        }
+
+        public Object setValue( IoSession session, Object value ) throws Exception
+        {
+            Object oldValue = getValue( session );
+            Integer trafficClass = ( Integer ) value;
+            ( ( SocketSession ) session ).getChannel().socket().setTrafficClass( trafficClass.intValue()
);
+            return oldValue;
+        }
+        
     }
-    
-    public void setSessionReceiveBufferSize( int size )
+
+    private static class SendBufferSizeOverrider implements IoSessionAttributeOverrider
     {
-        if( size <= 0 )
+        public String getKey()
         {
-            throw new IllegalArgumentException( "Invalid session receive buffer size: " +
size );
+            return Constants.SEND_BUFFER_SIZE;
+        }
+
+        public Object getValue( IoSession session ) throws Exception
+        {
+            return new Integer( ( ( SocketSession ) session ).getChannel().socket().getSendBufferSize()
);
+        }
+
+        public Object setValue( IoSession session, Object value ) throws Exception
+        {
+            Object oldValue = getValue( session );
+            Integer sendBufferSize = ( Integer ) value;
+            ( ( SocketSession ) session ).getChannel().socket().setSendBufferSize( sendBufferSize.intValue()
);
+            return oldValue;
         }
-        
-        this.readBufferSize = size;
     }
 
-    protected void updateTrafficMask()
+    private static class ReceiveBufferSizeOverrider implements IoSessionAttributeOverrider
     {
-        this.ioProcessor.updateTrafficMask( this );
+        public String getKey()
+        {
+            return Constants.RECEIVE_BUFFER_SIZE;
+        }
+
+        public Object getValue( IoSession session ) throws Exception
+        {
+            return new Integer( ( ( SocketSession ) session ).getChannel().socket().getReceiveBufferSize()
);
+        }
+
+        public Object setValue( IoSession session, Object value ) throws Exception
+        {
+            Object oldValue = getValue( session );
+            Integer receiveBufferSize = ( Integer ) value;
+            ( ( SocketSession ) session ).getChannel().socket().setReceiveBufferSize( receiveBufferSize.intValue()
);
+            ( ( SocketSession ) session ).readBufferSize = receiveBufferSize.intValue();
+            return oldValue;
+        }
     }
 }

Modified: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/util/SessionUtil.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/util/SessionUtil.java?rev=371290&r1=371289&r2=371290&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/util/SessionUtil.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/util/SessionUtil.java
Sun Jan 22 05:52:31 2006
@@ -18,8 +18,6 @@
  */
 package org.apache.mina.util;
 
-import java.net.SocketException;
-
 import org.apache.mina.common.IoSession;
 
 /**
@@ -30,22 +28,17 @@
  */
 public class SessionUtil
 {
-    public static void initialize( IoSession session ) throws SocketException
+    public static void initialize( IoSession session )
     {
-    	// FIXME Apply new configuration API
-    	/*
-        if( session instanceof SocketSession )
+        if( session.containsAttribute( "reuseAddress" ) )
         {
-            SocketSession ss = ( SocketSession ) session;
-            ss.setReuseAddress( true );
-            ss.setKeepAlive( true );
+            session.setAttribute( "reuseAddress", Boolean.TRUE );
         }
-        else if( session instanceof DatagramSession )
+        
+        if( session.containsAttribute( "keepAlive" ) )
         {
-            DatagramSession ds = ( DatagramSession ) session;
-            ds.setReuseAddress( true );
+            session.setAttribute( "keepAlive", Boolean.TRUE );
         }
-        */
     }
 
     private SessionUtil()

Modified: directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java?rev=371290&r1=371289&r2=371290&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
Sun Jan 22 05:52:31 2006
@@ -161,13 +161,7 @@
 
         public void sessionCreated( IoSession session )
         {
-            /* FIXME when configuration interface is ready...
-            if( session instanceof SocketSession )
-            {
-                ( ( SocketSession ) session ).setSessionReceiveBufferSize( 2048 );
-            }
-            */
-
+            session.setAttribute( "receiveBufferSize", new Integer( 2048 ) );
             session.setIdleTime( IdleStatus.BOTH_IDLE, 10 );
         }
 

Modified: directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramTrafficControlTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramTrafficControlTest.java?rev=371290&r1=371289&r2=371290&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramTrafficControlTest.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramTrafficControlTest.java
Sun Jan 22 05:52:31 2006
@@ -23,7 +23,7 @@
 
 /**
  * Tests suspending and resuming reads and writes for the
- * {@link org.apache.mina.common.TransportType#DATAGRAM} transport type. 
+ * UDP/IP Datagram transport type. 
  *
  * @author The Apache Directory Project (dev@directory.apache.org)
  * @version $Id$

Modified: directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/socket/nio/SocketTrafficControlTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/socket/nio/SocketTrafficControlTest.java?rev=371290&r1=371289&r2=371290&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/socket/nio/SocketTrafficControlTest.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/socket/nio/SocketTrafficControlTest.java
Sun Jan 22 05:52:31 2006
@@ -23,7 +23,7 @@
 
 /**
  * Tests suspending and resuming reads and writes for the
- * {@link org.apache.mina.common.TransportType#SOCKET} transport type. 
+ * TCP/IP Socket transport type. 
  *
  * @author The Apache Directory Project (dev@directory.apache.org)
  * @version $Id$

Modified: directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeTrafficControlTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeTrafficControlTest.java?rev=371290&r1=371289&r2=371290&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeTrafficControlTest.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeTrafficControlTest.java
Sun Jan 22 05:52:31 2006
@@ -23,7 +23,7 @@
 
 /**
  * Tests suspending and resuming reads and writes for the
- * {@link org.apache.mina.common.TransportType#VM_PIPE} transport type. 
+ * In-VM Pipe transport type. 
  *
  * @author The Apache Directory Project (dev@directory.apache.org)
  * @version $Id$



Mime
View raw message