directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r156494 - in incubator/directory/network/mina/trunk/src/java/org/apache/mina: protocol/ProtocolEncoderOutput.java protocol/io/IoAdapter.java util/Queue.java
Date Tue, 08 Mar 2005 04:14:42 GMT
Author: trustin
Date: Mon Mar  7 20:14:41 2005
New Revision: 156494

URL: http://svn.apache.org/viewcvs?view=rev&rev=156494
Log:
Added ProtocolEncoderOutput.mergeAll() to let users control how MINA generates network packets.
 This will help to resolve DIR-108.

Modified:
    incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java
    incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
    incubator/directory/network/mina/trunk/src/java/org/apache/mina/util/Queue.java

Modified: incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java
URL: http://svn.apache.org/viewcvs/incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java?view=diff&r1=156493&r2=156494
==============================================================================
--- incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java
(original)
+++ incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java
Mon Mar  7 20:14:41 2005
@@ -38,4 +38,12 @@
      * @param buf the buffer which contains encoded data
      */
     void write( ByteBuffer buf );
+    
+    /**
+     * Merges all buffers you wrote via {@link #write(ByteBuffer)} into
+     * one {@link ByteBuffer} and replaces the old fragmented ones with it.
+     * This method is useful when you want to control the way MINA generates
+     * network packets.
+     */
+    void mergeAll();
 }

Modified: incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java?view=diff&r1=156493&r2=156494
==============================================================================
--- incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
(original)
+++ incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
Mon Mar  7 20:14:41 2005
@@ -423,6 +423,38 @@
         {
             queue.push( buf );
         }
+        
+        public void mergeAll()
+        {
+            int sum = 0;
+            final int size = queue.size();
+            
+            // Get the size of merged BB
+            for( int i = size - 1; i >= 0; i -- )
+            {
+                sum += ( ( ByteBuffer ) queue.get( i ) ).remaining();
+            }
+            
+            // Allocate a new BB that will contain all fragments
+            ByteBuffer newBuf = ByteBuffer.allocate( sum );
+            
+            // and merge all.
+            for( ;; )
+            {
+                ByteBuffer buf = ( ByteBuffer ) queue.pop();
+                if( buf == null )
+                {
+                    break;
+                }
+
+                newBuf.put( buf );
+                ByteBuffer.release( buf );
+            }
+            
+            // Push the new buffer finally.
+            newBuf.flip();
+            queue.push(newBuf);
+        }
     }
 
     private static class ProtocolDecoderOutputImpl implements

Modified: incubator/directory/network/mina/trunk/src/java/org/apache/mina/util/Queue.java
URL: http://svn.apache.org/viewcvs/incubator/directory/network/mina/trunk/src/java/org/apache/mina/util/Queue.java?view=diff&r1=156493&r2=156494
==============================================================================
--- incubator/directory/network/mina/trunk/src/java/org/apache/mina/util/Queue.java (original)
+++ incubator/directory/network/mina/trunk/src/java/org/apache/mina/util/Queue.java Mon Mar
 7 20:14:41 2005
@@ -144,6 +144,11 @@
 
         return items[ ( last + items.length - 1 ) & mask ];
     }
+    
+    public Object get( int idx )
+    {
+        return items[ ( first + idx ) & mask ];
+    }
 
     /**
      * Returns <code>true</code> if the queue is empty.



Mime
View raw message