directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r171076 - in /directory/network: branches/0.7/src/java/org/apache/mina/common/ByteBuffer.java trunk/src/java/org/apache/mina/common/ByteBuffer.java
Date Fri, 20 May 2005 08:03:24 GMT
Author: trustin
Date: Fri May 20 01:03:23 2005
New Revision: 171076

URL: http://svn.apache.org/viewcvs?rev=171076&view=rev
Log:
Added more documentation about wrapping NIO buffers and byte arrays regarding to DIRMINA-41



Modified:
    directory/network/branches/0.7/src/java/org/apache/mina/common/ByteBuffer.java
    directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.java

Modified: directory/network/branches/0.7/src/java/org/apache/mina/common/ByteBuffer.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/0.7/src/java/org/apache/mina/common/ByteBuffer.java?rev=171076&r1=171075&r2=171076&view=diff
==============================================================================
--- directory/network/branches/0.7/src/java/org/apache/mina/common/ByteBuffer.java (original)
+++ directory/network/branches/0.7/src/java/org/apache/mina/common/ByteBuffer.java Fri May
20 01:03:23 2005
@@ -87,6 +87,36 @@
  *   <li>You called {@link #acquire()} to prevent the buffer from being released.</li>
  * </ul>
  * 
+ * <h2>Wrapping existing NIO buffers and arrays</h2>
+ * <p>
+ * This class provides a few <tt>wrap(...)</tt> methods that wraps
+ * any NIO buffers and byte arrays.  But please be careful and use these
+ * methods at your own risk.  Using those methods can cause memory leakage
+ * if you keep wrapping new NIO buffers and arrays because even wrapped
+ * MINA buffers are going to be pooled when they are released by MINA.
+ * <p>
+ * To resolve this issue, please do not keeping wrapping NIO buffers if
+ * possible.  If you're working with any third party component that keeps
+ * creating NIO buffers, please call {@link #acquire()} once more and
+ * don't call {@link #release()} for it, then it will not be returned to
+ * the pool and GC'd eventually.  Here's the example:
+ * <pre>
+ * import org.apache.mina.common.*;
+ * import org.apache.mina.io.*;
+ *
+ * IoSession session = ...;
+ * for (;;) {
+ *     // readData() returns a newly allocate NIO buffer.
+ *     java.nio.ByteBuffer newBuffer = otherApplication.readData();
+ *     
+ *     // Wrap it.
+ *     ByteBuffer wrappedBuffer = ByteBuffer.wrap(newBuffer);
+ *     // Acquire once and don't call release to prevent MINA from pooling it. 
+ *     wrappedBuffer.acquire();
+ *     session.write(wrappedBuffer, marker);
+ * }
+ * </pre>
+ * 
  * <h2>AutoExpand</h2>
  * <p>
  * Writing variable-length data using NIO <tt>ByteBuffers</tt> is not really
@@ -224,9 +254,6 @@
     
     /**
      * Wraps the specified NIO {@link java.nio.ByteBuffer} into MINA buffer.
-     * Please note that MINA buffers are going to be pooled, and
-     * therefore there can be waste of memory if you specified
-     * a sliced buffer.
      */
     public static ByteBuffer wrap( java.nio.ByteBuffer nioBuffer )
     {

Modified: directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.java?rev=171076&r1=171075&r2=171076&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.java Fri May 20 01:03:23
2005
@@ -87,6 +87,35 @@
  *   <li>You called {@link #acquire()} to prevent the buffer from being released.</li>
  * </ul>
  * 
+ * <h2>Wrapping existing NIO buffers and arrays</h2>
+ * <p>
+ * This class provides a few <tt>wrap(...)</tt> methods that wraps
+ * any NIO buffers and byte arrays.  But please be careful and use these
+ * methods at your own risk.  Using those methods can cause memory leakage
+ * if you keep wrapping new NIO buffers and arrays because even wrapped
+ * MINA buffers are going to be pooled when they are released by MINA.
+ * <p>
+ * To resolve this issue, please do not keeping wrapping NIO buffers if
+ * possible.  If you're working with any third party component that keeps
+ * creating NIO buffers, please call {@link #acquire()} once more and
+ * don't call {@link #release()} for it, then it will not be returned to
+ * the pool and GC'd eventually.  Here's the example:
+ * <pre>
+ * import org.apache.mina.common.*;
+ * 
+ * IoSession session = ...;
+ * for (;;) {
+ *     // readData() returns a newly allocate NIO buffer.
+ *     java.nio.ByteBuffer newBuffer = otherApplication.readData();
+ *     
+ *     // Wrap it.
+ *     ByteBuffer wrappedBuffer = ByteBuffer.wrap(newBuffer);
+ *     // Acquire once and don't call release to prevent MINA from pooling it. 
+ *     wrappedBuffer.acquire();
+ *     session.write(wrappedBuffer);
+ * }
+ * </pre>
+ * 
  * <h2>AutoExpand</h2>
  * <p>
  * Writing variable-length data using NIO <tt>ByteBuffers</tt> is not really
@@ -222,9 +251,6 @@
     
     /**
      * Wraps the specified NIO {@link java.nio.ByteBuffer} into MINA buffer.
-     * Please note that MINA buffers are going to be pooled, and
-     * therefore there can be waste of memory if you specified
-     * a sliced buffer.
      */
     public static ByteBuffer wrap( java.nio.ByteBuffer nioBuffer )
     {



Mime
View raw message