qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ritch...@apache.org
Subject svn commit: r466082 - /incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/framing/ContentBody.java
Date Fri, 20 Oct 2006 12:02:10 GMT
Author: ritchiem
Date: Fri Oct 20 05:02:09 2006
New Revision: 466082

URL: http://svn.apache.org/viewvc?view=rev&rev=466082
Log:
QPID-48
Addition to be used from DeliveryManager.java to reduce the size of the ByteBuffer when queuing
messages to reduce overall memory footprint.

Modified:
    incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/framing/ContentBody.java

Modified: incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/framing/ContentBody.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/framing/ContentBody.java?view=diff&rev=466082&r1=466081&r2=466082
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/framing/ContentBody.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/framing/ContentBody.java Fri
Oct 20 05:02:09 2006
@@ -32,7 +32,7 @@
 
     public int getSize()
     {
-        return (payload == null?0:payload.limit());
+        return (payload == null ? 0 : payload.limit());
     }
 
     public void writePayload(ByteBuffer buffer)
@@ -49,8 +49,27 @@
         if (size > 0)
         {
             payload = buffer.slice();
-            payload.limit((int)size);
-            buffer.skip((int)size);            
+            payload.limit((int) size);
+            buffer.skip((int) size);
+        }
+
+    }
+
+    public void reduceBufferToFit()
+    {
+        if (payload != null && (payload.remaining() < payload.capacity() / 2))
+        {
+            int size = payload.limit();
+            ByteBuffer newPayload = ByteBuffer.allocate(size);
+
+            newPayload.put(payload);
+            newPayload.position(0);
+            newPayload.limit(size);
+
+            //reduce reference count on payload
+            payload.release();
+
+            payload = newPayload;
         }
     }
 



Mime
View raw message