directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r446591 - /directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Date Fri, 15 Sep 2006 12:22:41 GMT
Author: trustin
Date: Fri Sep 15 05:22:40 2006
New Revision: 446591

URL: http://svn.apache.org/viewvc?view=rev&rev=446591
Log:
Fixed issue: DIRMINA-265 (messageSent event is fired multiple times if ProrotocolEncoder calls
ProtocolEncoderOutput.write() multiple times for one message.)
* Made sure that MessageByteBuffer is sent only once.

Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?view=diff&rev=446591&r1=446590&r2=446591
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Fri Sep 15 05:22:40 2006
@@ -46,6 +46,7 @@
     public static final String DECODER = ProtocolCodecFilter.class.getName() + ".decoder";
     
     private static final Class[] EMPTY_PARAMS = new Class[0];
+    private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.wrap( new byte[0] );
 
     private final ProtocolCodecFactory factory;
     
@@ -187,21 +188,18 @@
 
     public void messageSent( NextFilter nextFilter, IoSession session, Object message ) throws
Exception
     {
-        if( ! ( message instanceof MessageByteBuffer ) )
+        if( message instanceof HiddenByteBuffer )
         {
-            nextFilter.messageSent( session, message );
             return;
         }
 
-        MessageByteBuffer buf = ( MessageByteBuffer ) message;
-        try
+        if( !( message instanceof MessageByteBuffer ) )
         {
-            buf.release();
-        }
-        finally
-        {
-            nextFilter.messageSent( session, buf.message );
+            nextFilter.messageSent( session, message );
+            return;
         }
+
+        nextFilter.messageSent( session, ( ( MessageByteBuffer ) message ).message );
     }
     
     public void filterWrite( NextFilter nextFilter, IoSession session, WriteRequest writeRequest
) throws Exception
@@ -219,6 +217,13 @@
         try
         {
             encoder.encode( session, message, encoderOut );
+            encoderOut.flush();
+            nextFilter.filterWrite(
+                    session,
+                    new WriteRequest(
+                            new MessageByteBuffer( writeRequest.getMessage() ),
+                            writeRequest.getFuture(), writeRequest.getDestination() ) );
+
             if( session instanceof BaseIoSession )
             {
                 ( ( BaseIoSession ) session ).increaseWrittenMessages();
@@ -239,8 +244,6 @@
         }
         finally
         {
-            encoderOut.flush();
-
             // Dispose the encoder if this session is connectionless.
             if( session.getTransportType().isConnectionless() )
             {
@@ -357,13 +360,21 @@
         }
     }
 
+    private static class HiddenByteBuffer extends ByteBufferProxy
+    {
+        private HiddenByteBuffer( ByteBuffer buf )
+        {
+            super( buf );
+        }
+    }
+    
     private static class MessageByteBuffer extends ByteBufferProxy
     {
         private final Object message;
         
-        private MessageByteBuffer( ByteBuffer buf, Object message )
+        private MessageByteBuffer( Object message )
         {
-            super( buf );
+            super( EMPTY_BUFFER );
             this.message = message;
         }
     }
@@ -383,21 +394,12 @@
 
         protected WriteFuture doFlush( ByteBuffer buf )
         {
-            WriteFuture future;
-            if( writeRequest != null )
-            {
-                future = writeRequest.getFuture();
-                nextFilter.filterWrite(
-                        session,
-                        new WriteRequest(
-                                new MessageByteBuffer(
-                                        buf, writeRequest.getMessage() ), future, writeRequest.getDestination()
) );
-            }
-            else
-            {
-                future = new DefaultWriteFuture( session );
-                nextFilter.filterWrite( session, new WriteRequest( buf, future ) );
-            }
+            WriteFuture future = new DefaultWriteFuture( session );
+            nextFilter.filterWrite(
+                    session,
+                    new WriteRequest(
+                            new HiddenByteBuffer( buf ),
+                            future, writeRequest.getDestination() ) );
             return future;
         }
     }



Mime
View raw message