directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r169269 - in /directory/network/branches/api_integration/src/java/org/apache/mina: common/ filter/ filter/codec/ transport/socket/nio/ util/
Date Mon, 09 May 2005 10:38:55 GMT
Author: trustin
Date: Mon May  9 03:38:52 2005
New Revision: 169269

URL: http://svn.apache.org/viewcvs?rev=169269&view=rev
Log:
Fixed: ByteBuffers are not reused

Added:
    directory/network/branches/api_integration/src/java/org/apache/mina/util/ByteBufferUtil.java
  (with props)
Modified:
    directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java
    directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBuffer.java
    directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java
    directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java
    directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
    directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java?rev=169269&r1=169268&r2=169269&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java
(original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java
Mon May  9 03:38:52 2005
@@ -26,6 +26,7 @@
 import java.util.Map;
 
 import org.apache.mina.common.IoFilter.NextFilter;
+import org.apache.mina.util.ByteBufferUtil;
 
 /**
  * An abstract implementation of {@link IoFilterChain} that provides
@@ -151,14 +152,27 @@
             public void messageReceived( NextFilter nextFilter, IoSession session,
                                          Object message ) throws Exception
             {
-                IoHandler handler = session.getHandler();
-                handler.messageReceived( session, message );
+                try
+                {
+                    session.getHandler().messageReceived( session, message );
+                }
+                finally
+                {
+                    ByteBufferUtil.releaseIfPossible( message );
+                }
             }
 
             public void messageSent( NextFilter nextFilter, IoSession session,
                                      Object message ) throws Exception
             {
-                session.getHandler().messageSent( session, message );
+                try
+                {
+                    session.getHandler().messageSent( session, message );
+                }
+                finally
+                {
+                    ByteBufferUtil.releaseIfPossible( message );
+                }
             }
 
             public void filterWrite( NextFilter nextFilter,

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBuffer.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBuffer.java?rev=169269&r1=169268&r2=169269&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBuffer.java
(original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBuffer.java
Mon May  9 03:38:52 2005
@@ -529,6 +529,7 @@
 
         private synchronized void init( java.nio.ByteBuffer buf )
         {
+            System.out.println("INIT: " + System.identityHashCode( this ) );
             this.buf = buf;
             buf.clear();
             buf.order( ByteOrder.BIG_ENDIAN );
@@ -538,6 +539,7 @@
         
         public synchronized void acquire()
         {
+            System.out.println("ACQUIRE: " + System.identityHashCode( this ) + ' ' + this
);
             if( refCount <= 0 )
             {
                 throw new IllegalStateException( "Already released buffer." );
@@ -548,6 +550,7 @@
 
         public void release()
         {
+            System.out.println("RELEASE: " + System.identityHashCode( this ) );
             synchronized( this )
             {
                 if( refCount <= 0 )

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java?rev=169269&r1=169268&r2=169269&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java
(original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java
Mon May  9 03:38:52 2005
@@ -23,6 +23,7 @@
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.util.BaseThreadPool;
+import org.apache.mina.util.ByteBufferUtil;
 import org.apache.mina.util.EventType;
 import org.apache.mina.util.ThreadPool;
 
@@ -72,14 +73,16 @@
     }
 
     public void messageReceived( NextFilter nextFilter,
-                                IoSession session, Object message )
+                                 IoSession session, Object message )
     {
+        ByteBufferUtil.acquireIfPossible( message );
         fireEvent( nextFilter, session, EventType.RECEIVED, message );
     }
 
     public void messageSent( NextFilter nextFilter,
-                            IoSession session, Object message )
+                             IoSession session, Object message )
     {
+        ByteBufferUtil.acquireIfPossible( message );
         fireEvent( nextFilter, session, EventType.SENT, message );
     }
 
@@ -93,10 +96,12 @@
         if( type == EventType.RECEIVED )
         {
             nextFilter.messageReceived( session, data );
+            ByteBufferUtil.releaseIfPossible( data );
         }
         else if( type == EventType.SENT )
         {
             nextFilter.messageSent( session, data );
+            ByteBufferUtil.releaseIfPossible( data );
         }
         else if( type == EventType.EXCEPTION )
         {

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=169269&r1=169268&r2=169269&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
(original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Mon May  9 03:38:52 2005
@@ -36,7 +36,16 @@
             {
                 decoder.decode( session, in, decoderOut );
             }
-
+            
+            in.release();
+        }
+        catch( ProtocolViolationException pve )
+        {
+            pve.setBuffer( in );
+            throw pve;
+        }
+        finally
+        {
             Queue queue = decoderOut.getMessageQueue();
             synchronized( queue )
             {
@@ -50,17 +59,19 @@
                 }
             }
         }
-        catch( ProtocolViolationException pve )
-        {
-            pve.setBuffer( in );
-            throw pve;
-        }
     }
 
     public void messageSent( NextFilter nextFilter, IoSession session, Object message ) throws
Exception
     {
         MessageByteBuffer buf = ( MessageByteBuffer ) message;
-        nextFilter.messageSent( session, buf.message );
+        try
+        {
+            buf.release();
+        }
+        finally
+        {
+            nextFilter.messageSent( session, buf.message );
+        }
     }
     
     public void filterWrite( NextFilter nextFilter, IoSession session, Object message ) throws
Exception

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java?rev=169269&r1=169268&r2=169269&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java
(original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java
Mon May  9 03:38:52 2005
@@ -359,7 +359,6 @@
                     writeBufferQueue.pop();
                 }
 
-                // FIXME buffer must be released after messageSent is fired.
                 session.getManagerFilterChain().messageSent( session, buf );
                 continue;
             }

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java?rev=169269&r1=169268&r2=169269&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
(original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
Mon May  9 03:38:52 2005
@@ -356,7 +356,6 @@
                     writeBufferQueue.pop();
                 }
 
-                // FIXME buffer must be released after messageSent is fired.
                 session.getManagerFilterChain().messageSent( session, buf );
                 continue;
             }

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java?rev=169269&r1=169268&r2=169269&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java
(original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java
Mon May  9 03:38:52 2005
@@ -451,7 +451,6 @@
                     writeBufferQueue.pop();
                 }
                 
-                // FIXME buffer is not released
                 session.getManagerFilterChain().messageSent( session, buf );
                 continue;
             }

Added: directory/network/branches/api_integration/src/java/org/apache/mina/util/ByteBufferUtil.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/util/ByteBufferUtil.java?rev=169269&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/util/ByteBufferUtil.java
(added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/util/ByteBufferUtil.java
Mon May  9 03:38:52 2005
@@ -0,0 +1,50 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.util;
+
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * ByteBuffer utility.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ByteBufferUtil
+{
+    public static void acquireIfPossible( Object message )
+    {
+        if( message instanceof ByteBuffer )
+        {
+            ( ( ByteBuffer ) message ).acquire();
+        }
+    }
+    
+    public static void releaseIfPossible( Object message )
+    {
+        if( message instanceof ByteBuffer )
+        {
+            ( ( ByteBuffer ) message ).release();
+        }
+    }
+    
+    private ByteBufferUtil()
+    {
+    }
+}

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/util/ByteBufferUtil.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message