Author: trustin
Date: Mon Nov  5 04:06:46 2007
New Revision: 591966

URL: http://svn.apache.org/viewvc?rev=591966&view=rev
Log:
Replaced IoBuffer.preferDirectBuffers with IoBuffer.useDirectBuffer; 
preferDirectBuffers leads unpredictable application behavior because the 
application doesn't know what type of buffer will be allocated when the 
application is under load.


Modified:
    
mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java
    mina/trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java
    mina/trunk/core/src/main/java/org/apache/mina/filter/ssl/SslBufferUtil.java

Modified: 
mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java
URL: 
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java?rev=591966&r1=591965&r2=591966&view=diff
==============================================================================
--- 
mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java 
(original)
+++ 
mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java 
Mon Nov  5 04:06:46 2007
@@ -152,6 +152,7 @@
             this.buf = newBuf;
             
             free(oldBuf);
+            free(buf);
         }
 
         @Override

Modified: mina/trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java
URL: 
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java?rev=591966&r1=591965&r2=591966&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java 
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java Mon Nov  
5 04:06:46 2007
@@ -136,7 +136,7 @@
 public abstract class IoBuffer implements Comparable<IoBuffer> {
     private static IoBufferAllocator allocator = new SimpleBufferAllocator();
 
-    private static boolean preferDirectBuffers = false;
+    private static boolean useDirectBuffer = false;
 
     /**
      * An immutable empty buffer.
@@ -172,8 +172,8 @@
      * by default when the type of the new buffer is not specified.  The
      * default value is <tt>false</tt>.
      */
-    public static boolean isPreferDirectBuffers() {
-        return preferDirectBuffers;
+    public static boolean isUseDirectBuffer() {
+        return useDirectBuffer;
     }
 
     /**
@@ -181,30 +181,20 @@
      * type of the new buffer is not specified.  The default value is
      * <tt>false</tt>.
      */
-    public static void setPreferDirectBuffers(boolean preferDirectBuffers) {
-        IoBuffer.preferDirectBuffers = preferDirectBuffers;
+    public static void setUseDirectBuffer(boolean useDirectBuffer) {
+        IoBuffer.useDirectBuffer = useDirectBuffer;
     }
 
     /**
-     * Returns the direct or heap buffer which is capable of the specified
-     * size.  This method tries to allocate a buffer of the preferred type
-     * first, and then tries the other type of buffer if the buffer memory
-     * of the preferred type is exhausted.  Please use
-     * [EMAIL PROTECTED] #allocate(int, boolean)} to allocate buffers of 
specific type.
+     * Returns the direct or heap buffer which is capable to store the
+     * specified amount of bytes.
      *
      * @param capacity the capacity of the buffer
      *
-     * @see #setPreferDirectBuffers(boolean)
+     * @see #setUseDirectBuffer(boolean)
      */
     public static IoBuffer allocate(int capacity) {
-        try {
-            // first try to allocate a buffer of the preferred type.
-            return allocate(capacity, preferDirectBuffers);
-        } catch (OutOfMemoryError e) {
-            // fall through to the alternative type.
-        }
-
-        return allocate(capacity, !preferDirectBuffers);
+        return allocate(capacity, useDirectBuffer);
     }
 
     /**

Modified: 
mina/trunk/core/src/main/java/org/apache/mina/filter/ssl/SslBufferUtil.java
URL: 
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/ssl/SslBufferUtil.java?rev=591966&r1=591965&r2=591966&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/ssl/SslBufferUtil.java 
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/ssl/SslBufferUtil.java 
Mon Nov  5 04:06:46 2007
@@ -107,7 +107,7 @@
     }
 
     private static ByteBuffer createBuffer(int capacity) {
-        if (org.apache.mina.common.IoBuffer.isPreferDirectBuffers()) {
+        if (org.apache.mina.common.IoBuffer.isUseDirectBuffer()) {
             try {
                 return ByteBuffer.allocateDirect(capacity);
             } catch (OutOfMemoryError e) {


Reply via email to