directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r161436 - directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java
Date Fri, 15 Apr 2005 10:44:09 GMT
Author: trustin
Date: Fri Apr 15 03:44:07 2005
New Revision: 161436

URL: http://svn.apache.org/viewcvs?view=rev&rev=161436
Log:
Improved SocketSession memory usage.

Modified:
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java?view=diff&r1=161435&r2=161436
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java Fri
Apr 15 03:44:07 2005
@@ -190,7 +190,6 @@
 
             SocketChannel ch = session.getChannel();
             session.getSelectionKey().cancel();
-            session.dispose();
 
             try
             {
@@ -232,12 +231,10 @@
 
     private void read( SocketSession session )
     {
-        ByteBuffer buf = session.getReadBuffer();
+        ByteBuffer buf = ByteBuffer.allocate(
+                (( SocketSessionConfig ) session.getConfig()).getSessionReceiveBufferSize()
); 
         SocketChannel ch = session.getChannel();
 
-        // Acquire buffer to prevent buffer is released by
-        // SocketSession.setReadBuffer()
-        buf.acquire(); 
         try
         {
             int readBytes = 0;

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java?view=diff&r1=161435&r2=161436
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java Fri Apr
15 03:44:07 2005
@@ -38,16 +38,12 @@
  */
 class SocketSession implements IoSession
 {
-    private static final int DEFAULT_READ_BUFFER_SIZE = 1024;
-
     private final SocketFilterChain filters;
 
     private final SocketChannel ch;
 
     private final SocketSessionConfig config;
 
-    private ByteBuffer readBuf;
-
     private final Queue writeBufferQueue;
 
     private final Queue writeMarkerQueue;
@@ -75,8 +71,6 @@
     private boolean idleForRead;
 
     private boolean idleForWrite;
-    
-    private boolean disposed;
 
     /**
      * Creates a new instance.
@@ -87,7 +81,6 @@
         this.filters = filters;
         this.ch = ch;
         this.config = new SocketSessionConfig( this );
-        this.readBuf = ByteBuffer.allocate( DEFAULT_READ_BUFFER_SIZE ).limit( 0 );
         this.writeBufferQueue = new Queue();
         this.writeMarkerQueue = new Queue();
         this.handler = defaultHandler;
@@ -115,16 +108,6 @@
         this.key = key;
     }
 
-    void dispose()
-    {
-        if (disposed)
-        {
-            return;
-        }
-        disposed = true;
-        readBuf.release();
-    }
-
     public IoHandler getHandler()
     {
         return handler;
@@ -143,18 +126,6 @@
     public void setAttachment( Object attachment )
     {
         this.attachment = attachment;
-    }
-
-    synchronized ByteBuffer getReadBuffer()
-    {
-        return readBuf;
-    }
-    
-    synchronized void setReadBuffer( ByteBuffer readBuf )
-    {
-        ByteBuffer oldBuf = this.readBuf;
-        this.readBuf = readBuf;
-        oldBuf.release(); // release old buffer
     }
 
     Queue getWriteBufferQueue()

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java?view=diff&r1=161435&r2=161436
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java Fri
Apr 15 03:44:07 2005
@@ -20,7 +20,6 @@
 
 import java.net.SocketException;
 
-import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.io.IoSession;
 import org.apache.mina.protocol.ProtocolSession;
@@ -38,7 +37,11 @@
  */
 public class SocketSessionConfig extends BasicSessionConfig
 {
+    private static final int DEFAULT_READ_BUFFER_SIZE = 1024;
+
     private final SocketSession session;
+    
+    private int readBufferSize = DEFAULT_READ_BUFFER_SIZE;
 
     SocketSessionConfig( SocketSession session )
     {
@@ -125,13 +128,18 @@
         session.getChannel().socket().setReceiveBufferSize( size );
     }
     
-    public void getSessionReceiveBufferSize()
+    public int getSessionReceiveBufferSize()
     {
-        session.getReadBuffer().capacity();
+        return readBufferSize;
     }
     
     public void setSessionReceiveBufferSize( int size )
     {
-        session.setReadBuffer( ByteBuffer.allocate( size ).limit( 0 ) );
+        if( size <= 0 )
+        {
+            throw new IllegalArgumentException( "Invalid session receive buffer size: " +
size );
+        }
+        
+        this.readBufferSize = size;
     }
 }



Mime
View raw message