directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r123329 - in incubator/directory/network/trunk/mina/src/java/org/apache/mina: common io/datagram io/socket protocol util
Date Sat, 25 Dec 2004 08:01:18 GMT
Author: trustin
Date: Sat Dec 25 00:01:17 2004
New Revision: 123329

URL: http://svn.apache.org/viewcvs?view=rev&rev=123329
Log:
 * Removed synchronization in SocketIoProcessor by reallocating ByteBuffer
 * DatagramAcceptor/Connector passes more compact buffers to less memory consumption
Modified:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java?view=diff&rev=123329&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java&r1=123328&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java&r2=123329
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
Sat Dec 25 00:01:17 2004
@@ -23,6 +23,9 @@
  * @version $Rev$, $Date$,
  */
 public final class ByteBuffer {
+	
+	public static final int MAXIMUM_CAPACITY = 8192;
+	
     private static final int[] bufferStackSizes = new int[] {
     		16,
 			32,

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java?view=diff&rev=123329&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java&r1=123328&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java&r2=123329
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
Sat Dec 25 00:01:17 2004
@@ -253,13 +253,22 @@
             {
                 readBuf.flip();
                 session.setRemoteAddress( remoteAddress );
-                filterManager.fireDataRead( session, readBuf );
+                
+                ByteBuffer newBuf = ByteBuffer.allocate(readBuf.limit());
+                newBuf.put(readBuf);
+                newBuf.flip();
+
+                filterManager.fireDataRead( session, newBuf );
             }
         }
         catch( IOException e )
         {
             filterManager.fireExceptionCaught( session, e );
         }
+        finally
+		{
+            ByteBuffer.release(readBuf);
+		}
     }
 
     private void flushSessions()

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java?view=diff&rev=123329&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java&r1=123328&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java&r2=123329
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java
Sat Dec 25 00:01:17 2004
@@ -245,13 +245,21 @@
             if( readBytes > 0 )
             {
                 readBuf.flip();
-                filterManager.fireDataRead( session, readBuf );
+                ByteBuffer newBuf = ByteBuffer.allocate(readBuf.limit());
+                newBuf.put(readBuf);
+                newBuf.flip();
+
+                filterManager.fireDataRead( session, newBuf );
             }
         }
         catch( IOException e )
         {
             filterManager.fireExceptionCaught( session, e );
         }
+        finally
+		{
+        	ByteBuffer.release( readBuf );
+		}
     }
 
     private void flushSessions()

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java?view=diff&rev=123329&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java&r1=123328&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java&r2=123329
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
Sat Dec 25 00:01:17 2004
@@ -234,42 +234,35 @@
             int readBytes = 0;
             int ret;
 
-            synchronized( buf )
-            {
-                if( buf.hasRemaining() )
-                    buf.compact();
-                else
-                    buf.clear();
+            buf.clear();
 
-                try
-                {
-                    while( ( ret = ch.read( buf.buf() ) ) > 0 )
-                    {
-                        readBytes += ret;
-                    }
-                }
-                finally
+            try
+            {
+                while( ( ret = ch.read( buf.buf() ) ) > 0 )
                 {
-                    buf.flip();
+                    readBytes += ret;
                 }
+            }
+            finally
+            {
+                buf.flip();
+            }
 
-                session.increaseReadBytes( readBytes );
+            session.increaseReadBytes( readBytes );
 
-                if( ret >= 0 )
-                {
-                    if( readBytes > 0 )
-                    {
-                        session.getFilterManager().fireDataRead( session, buf );
-                    }
-                    else
-                    {
-                        // FIXME will spin in multi-threaded env.
-                    }
-                }
-                else
+            if( ret >= 0 )
+            {
+                if( readBytes > 0 )
                 {
-                    scheduleRemove( session );
+                	ByteBuffer newBuf = ByteBuffer.allocate( readBytes );
+                	newBuf.put(buf);
+                	newBuf.flip();
+                    session.getFilterManager().fireDataRead( session, newBuf );
                 }
+            }
+            else
+            {
+                scheduleRemove( session );
             }
         }
         catch( Throwable e )

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java?view=diff&rev=123329&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java&r1=123328&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java&r2=123329
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java
Sat Dec 25 00:01:17 2004
@@ -83,7 +83,7 @@
         this.filterManager = filterManager;
         this.ch = ch;
         this.config = new SocketSessionConfig( ch );
-        this.readBuf = ByteBuffer.allocate( 4096 ).limit( 0 );
+        this.readBuf = ByteBuffer.allocate( ByteBuffer.MAXIMUM_CAPACITY ).limit( 0 );
         this.writeBufferQueue = new Queue();
         this.writeMarkerQueue = new Queue();
         this.handler = defaultHandler;

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java?view=diff&rev=123329&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r1=123328&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r2=123329
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
Sat Dec 25 00:01:17 2004
@@ -134,11 +134,10 @@
             {
                 filterManager.fireExceptionCaught( psession, t );
             }
-            
-            if (session.isStateless())
-            {
-            	ByteBuffer.release( in );
-            }
+            finally
+			{
+               	ByteBuffer.release( in );
+			}
         }
 
         public void dataWritten( IoSession session, Object marker )

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java?view=diff&rev=123329&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java&r1=123328&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java&r2=123329
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java
Sat Dec 25 00:01:17 2004
@@ -63,7 +63,7 @@
         {
         	IoHandler handler = session.getHandler();
             handler.dataRead( session, buf );
-            if (session.isStateless() && !IoAdapter.IO_HANDLER_TYPE.isAssignableFrom(
handler.getClass() )) {
+            if (!IoAdapter.IO_HANDLER_TYPE.isAssignableFrom( handler.getClass() )) {
             	ByteBuffer.release( buf );
             }
         }

Mime
View raw message