[jboss-cvs] JBoss Messaging SVN: r7186 - in trunk/src/main/org/jboss/messaging/core: journal/impl and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 3 17:57:17 EDT 2009


Author: clebert.suconic at jboss.com
Date: 2009-06-03 17:57:16 -0400 (Wed, 03 Jun 2009)
New Revision: 7186

Modified:
   trunk/src/main/org/jboss/messaging/core/asyncio/impl/TimedBuffer.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
Log:
Few tweaks an optimizations

Modified: trunk/src/main/org/jboss/messaging/core/asyncio/impl/TimedBuffer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/asyncio/impl/TimedBuffer.java	2009-06-03 20:36:06 UTC (rev 7185)
+++ trunk/src/main/org/jboss/messaging/core/asyncio/impl/TimedBuffer.java	2009-06-03 21:57:16 UTC (rev 7186)
@@ -30,6 +30,7 @@
 
 import org.jboss.messaging.core.asyncio.AIOCallback;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.utils.VariableLatch;
 
 /**
  * A TimedBuffer
@@ -47,6 +48,11 @@
    // Attributes ----------------------------------------------------
 
    private TimedBufferObserver bufferObserver;
+   
+   
+   // This is used to pause and resume the timer
+   // This is a reusable Latch, that uses java.util.concurrent base classes
+   private final VariableLatch latchTimer = new VariableLatch();
 
    private CheckTimer timerRunnable = new CheckTimer();
 
@@ -86,6 +92,7 @@
       currentBuffer.limit(0);
       callbacks = new ArrayList<AIOCallback>();
       this.flushOnSync = flushOnSync;
+      latchTimer.up();
    }
    
    public synchronized void start()
@@ -111,6 +118,8 @@
          return;
       }
       
+      latchTimer.down();
+      
       timerRunnable.close();
 
       while (timerThread.isAlive())
@@ -191,6 +200,8 @@
       callbacks.add(callback);
 
       timeLastAdd = now;
+      
+      latchTimer.down();
 
       if (sync)
       {
@@ -218,12 +229,14 @@
    {
       if (currentBuffer.limit() > 0)
       {
+         latchTimer.up();
+         
          ByteBuffer directBuffer = bufferObserver.newBuffer(bufferSize, currentBuffer.position());
 
-         currentBuffer.flip();
+         // Putting a byteArray on a native buffer is much faster, since it will do in a single native call.
+         // Using directBuffer.put(currentBuffer) would make several append calls for each byte
+         directBuffer.put(currentBuffer.array(), 0, currentBuffer.position());
 
-         directBuffer.put(currentBuffer);
-
          bufferObserver.flushBuffer(directBuffer, callbacks);
 
          callbacks = new ArrayList<AIOCallback>();
@@ -269,11 +282,19 @@
    private class CheckTimer implements Runnable
    {
       private volatile boolean closed = false;
-
+      
       public void run()
       {
          while (!closed)
-         {            
+         {
+            try
+            {
+               latchTimer.waitCompletion();
+            }
+            catch (InterruptedException ignored)
+            {
+            }
+
             checkTimer();
 
             //TODO - this yield is temporary

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2009-06-03 20:36:06 UTC (rev 7185)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2009-06-03 21:57:16 UTC (rev 7186)
@@ -2268,7 +2268,7 @@
 
    public ByteBuffer newBuffer(final int size)
    {
-      return ByteBuffer.allocate(size);
+      return ByteBuffer.wrap(new byte[size]);
    }
 
    // Inner classes




More information about the jboss-cvs-commits mailing list