directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nik...@apache.org
Subject svn commit: r416303 - in /directory/trunks/mina/core/src: main/java/org/apache/mina/filter/codec/ main/java/org/apache/mina/filter/codec/support/ test/java/org/apache/mina/filter/codec/ test/java/org/apache/mina/filter/codec/textline/
Date Thu, 22 Jun 2006 09:07:22 GMT
Author: niklas
Date: Thu Jun 22 02:07:21 2006
New Revision: 416303

URL: http://svn.apache.org/viewvc?rev=416303&view=rev
Log:
Added the flush() method to ProtocolDecoderOutput.
Changed ProtocolCodecFilter to call flush() on the ProtocolDecoderOutput after decoding messages.
Added the flush() method to SimpleProtocolDecoderOutput.

Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/support/SimpleProtocolDecoderOutput.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.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?rev=416303&r1=416302&r2=416303&view=diff
==============================================================================
--- 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
Thu Jun 22 02:07:21 2006
@@ -28,7 +28,6 @@
 import org.apache.mina.common.support.DefaultWriteFuture;
 import org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput;
 import org.apache.mina.filter.codec.support.SimpleProtocolEncoderOutput;
-import org.apache.mina.util.Queue;
 import org.apache.mina.util.SessionLog;
 
 /**
@@ -44,7 +43,6 @@
     public static final String ENCODER = ProtocolCodecFilter.class.getName() + ".encoder";
     public static final String DECODER = ProtocolCodecFilter.class.getName() + ".decoder";
     public static final String ENCODER_OUT = ProtocolCodecFilter.class.getName() + ".encoderOutput";
-    public static final String DECODER_OUT = ProtocolCodecFilter.class.getName() + ".decoderOutput";
     
     private static final Class[] EMPTY_PARAMS = new Class[0];
 
@@ -151,7 +149,7 @@
 
         ByteBuffer in = ( ByteBuffer ) message;
         ProtocolDecoder decoder = getDecoder( session );
-        SimpleProtocolDecoderOutput decoderOut = getDecoderOut( session );
+        ProtocolDecoderOutput decoderOut = createDecoderOut( nextFilter, session );
         
         try
         {
@@ -182,11 +180,7 @@
             // Release the read buffer.
             in.release();
 
-            Queue queue = decoderOut.getMessageQueue();
-            while( !queue.isEmpty() )
-            {
-                nextFilter.messageReceived( session, queue.pop() );
-            }
+            decoderOut.flush();
         }
     }
 
@@ -293,15 +287,9 @@
         return decoder;
     }
     
-    private SimpleProtocolDecoderOutput getDecoderOut( IoSession session )
+    protected ProtocolDecoderOutput createDecoderOut( NextFilter nextFilter, IoSession session
)
     {
-        SimpleProtocolDecoderOutput out = ( SimpleProtocolDecoderOutput ) session.getAttribute(
DECODER_OUT );
-        if( out == null )
-        {
-            out = new SimpleProtocolDecoderOutput();
-            session.setAttribute( DECODER_OUT, out );
-        }
-        return out;
+        return new SimpleProtocolDecoderOutput( nextFilter, session );
     }
     
     private void disposeEncoder( IoSession session )
@@ -328,7 +316,6 @@
 
     private void disposeDecoder( IoSession session )
     {
-        session.removeAttribute( DECODER_OUT );
         ProtocolDecoder decoder = ( ProtocolDecoder ) session.removeAttribute( DECODER );
         if( decoder == null )
         {

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java?rev=416303&r1=416302&r2=416303&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java
Thu Jun 22 02:07:21 2006
@@ -18,6 +18,7 @@
  */
 package org.apache.mina.filter.codec;
 
+
 /**
  * Callback for {@link ProtocolDecoder} to generate decoded messages.
  * {@link ProtocolDecoder} must call {@link #write(Object)} for each decoded
@@ -36,4 +37,10 @@
      * @param message the decoded message
      */
     void write( Object message );
-}
\ No newline at end of file
+
+    /**
+     * Flushes all messages you wrote via {@link #write(Object)} to
+     * the next filter.
+     */    
+    void flush();
+}

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/support/SimpleProtocolDecoderOutput.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/support/SimpleProtocolDecoderOutput.java?rev=416303&r1=416302&r2=416303&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/support/SimpleProtocolDecoderOutput.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/support/SimpleProtocolDecoderOutput.java
Thu Jun 22 02:07:21 2006
@@ -3,6 +3,8 @@
  */
 package org.apache.mina.filter.codec.support;
 
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoFilter.NextFilter;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.apache.mina.util.Queue;
 
@@ -15,19 +17,27 @@
  */
 public class SimpleProtocolDecoderOutput implements ProtocolDecoderOutput
 {
+    private final NextFilter nextFilter;
+    private final IoSession session;
     private final Queue messageQueue = new Queue();
     
-    public SimpleProtocolDecoderOutput()
+    public SimpleProtocolDecoderOutput( NextFilter nextFilter, IoSession session )
     {
-    }
-    
-    public Queue getMessageQueue()
-    {
-        return messageQueue;
+        this.nextFilter = nextFilter;
+        this.session = session;
     }
     
     public void write( Object message )
     {
         messageQueue.push( message );
     }
-}
\ No newline at end of file
+
+    public void flush()
+    {
+        while( !messageQueue.isEmpty() )
+        {
+            nextFilter.messageReceived( session, messageQueue.pop() );
+        }
+        
+    }
+}

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java?rev=416303&r1=416302&r2=416303&view=diff
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java
Thu Jun 22 02:07:21 2006
@@ -156,6 +156,10 @@
         {
             values.clear();
         }
+
+        public void flush()
+        {
+        }
     }
     
     private static class WrongDecoder extends CumulativeProtocolDecoder

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java?rev=416303&r1=416302&r2=416303&view=diff
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java
Thu Jun 22 02:07:21 2006
@@ -28,12 +28,13 @@
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionConfig;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.common.support.BaseIoSession;
-import org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.util.Queue;
 
 /**
  * Tests {@link TextLineDecoder}.
@@ -56,7 +57,7 @@
         
         CharsetEncoder encoder = Charset.forName( "UTF-8" ).newEncoder();
         IoSession session = new DummySession();
-        SimpleProtocolDecoderOutput out = new SimpleProtocolDecoderOutput();
+        TestDecoderOutput out = new TestDecoderOutput();
         ByteBuffer in = ByteBuffer.allocate( 16 );
      
         // Test one decode and one output
@@ -118,7 +119,7 @@
         
         CharsetEncoder encoder = Charset.forName( "UTF-8" ).newEncoder();
         IoSession session = new DummySession();
-        SimpleProtocolDecoderOutput out = new SimpleProtocolDecoderOutput();
+        TestDecoderOutput out = new TestDecoderOutput();
         ByteBuffer in = ByteBuffer.allocate( 16 );
      
         // Test one decode and one output
@@ -233,6 +234,25 @@
         public int getScheduledWriteBytes()
         {
             return 0;
+        }
+    }
+    
+    private static class TestDecoderOutput implements ProtocolDecoderOutput
+    {
+        private Queue messageQueue = new Queue();
+
+        public void write( Object message )
+        {
+            messageQueue.push( message );
+        }
+        
+        public Queue getMessageQueue()
+        {
+            return messageQueue;
+        }
+
+        public void flush()
+        {
         }
     }
 }



Mime
View raw message