directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r325917 - /directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Date Mon, 17 Oct 2005 15:56:34 GMT
Author: trustin
Date: Mon Oct 17 08:56:31 2005
New Revision: 325917

URL: http://svn.apache.org/viewcvs?rev=325917&view=rev
Log:
Resolved issue: DIRMINA-90 - Provide a way to release resources for ProtocolEncoder and ProtocolDecoder
* Now all encoders and decoders are disposed whenever one message is encoded or decoded in
stateless transport types.

Modified:
    directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java

Modified: directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=325917&r1=325916&r2=325917&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Mon Oct 17 08:56:31 2005
@@ -58,9 +58,15 @@
         }
         finally
         {
+            // Dispose the decoder if this session is stateless.
+            if( session.getTransportType().isStateless() )
+            {
+                disposeDecoder( session );
+            }
+
             // Release the read buffer.
             in.release();
-            
+
             Queue queue = decoderOut.getMessageQueue();
             synchronized( queue )
             {
@@ -112,6 +118,14 @@
             }
             throw pee;
         }
+        finally
+        {
+            // Dispose the encoder if this session is stateless.
+            if( session.getTransportType().isStateless() )
+            {
+                disposeEncoder( session );
+            }
+        }
 
         encoderOut.writeRequest = writeRequest;
         encoderOut.flush();
@@ -126,28 +140,8 @@
         finally
         {
             // Dispose encoder and decoder safely.
-            // FIXME: Think what we have to do for connectionless transport types
-            ProtocolEncoder encoder = getEncoder( session );
-            ProtocolDecoder decoder = getDecoder( session );
-            try
-            {
-                encoder.dispose();
-            }
-            catch( Throwable t )
-            {
-                log.warning( "Failed to dispose: " + encoder.getClass().getName() +
-                        " (" + encoder + ')' );
-            }
-            
-            try
-            {
-                decoder.dispose();
-            }
-            catch( Throwable t )
-            {
-                log.warning( "Falied to dispose: " + decoder.getClass().getName() +
-                        " (" + decoder + ')' );
-            }
+            disposeEncoder( session );
+            disposeDecoder( session );
         }
     }
 
@@ -195,6 +189,46 @@
         return out;
     }
     
+    private void disposeEncoder( IoSession session )
+    {
+        session.removeAttribute( ENCODER_OUT );
+        ProtocolEncoder encoder = ( ProtocolEncoder ) session.removeAttribute( ENCODER );
+        if( encoder == null )
+        {
+            return;
+        }
+
+        try
+        {
+            encoder.dispose();
+        }
+        catch( Throwable t )
+        {
+            log.warning( "Failed to dispose: " + encoder.getClass().getName() +
+                    " (" + encoder + ')' );
+        }
+    }
+
+    private void disposeDecoder( IoSession session )
+    {
+        session.removeAttribute( DECODER_OUT );
+        ProtocolDecoder decoder = ( ProtocolDecoder ) session.removeAttribute( DECODER );
+        if( decoder == null )
+        {
+            return;
+        }
+
+        try
+        {
+            decoder.dispose();
+        }
+        catch( Throwable t )
+        {
+            log.warning( "Falied to dispose: " + decoder.getClass().getName() +
+                    " (" + decoder + ')' );
+        }
+    }
+
     private static class MessageByteBuffer extends ByteBufferProxy
     {
         private final Object message;



Mime
View raw message