[jboss-cvs] JBoss Messaging SVN: r4865 - in branches/Branch_JBMESSAGING-1314: src/main/org/jboss/messaging/core/paging/impl and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 22 17:40:00 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-08-22 17:40:00 -0400 (Fri, 22 Aug 2008)
New Revision: 4865

Modified:
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PageTransaction.java
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/Pager.java
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PageTransactionImpl.java
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
   branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageTransactionImplTest.java
Log:
Few Tweaks

Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PageTransaction.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PageTransaction.java	2008-08-22 17:50:24 UTC (rev 4864)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PageTransaction.java	2008-08-22 21:40:00 UTC (rev 4865)
@@ -52,6 +52,6 @@
    
    int decrement(int elements);
    
-   int getSize();
+   int getNumberOfMessages();
 
 }

Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/Pager.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/Pager.java	2008-08-22 17:50:24 UTC (rev 4864)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/Pager.java	2008-08-22 21:40:00 UTC (rev 4865)
@@ -79,7 +79,7 @@
    /**
     * Page, only if destination is in page mode.
     * 
-    * page is an atomic operation. It's better to call page and get test the return.
+    * page is an atomic operation. It's better to call page and test the return.
     * 
     * @param message
     * @return false if destination is not on page mode

Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PageTransactionImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PageTransactionImpl.java	2008-08-22 17:50:24 UTC (rev 4864)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PageTransactionImpl.java	2008-08-22 21:40:00 UTC (rev 4865)
@@ -112,7 +112,7 @@
       return value;
    }
    
-   public int getSize()
+   public int getNumberOfMessages()
    {
       return numberOfMessages.get();
    }

Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java	2008-08-22 17:50:24 UTC (rev 4864)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java	2008-08-22 21:40:00 UTC (rev 4865)
@@ -30,12 +30,11 @@
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-import org.jboss.messaging.core.journal.EncodingSupport;
 import org.jboss.messaging.core.journal.SequentialFile;
 import org.jboss.messaging.core.journal.SequentialFileFactory;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.paging.Page;
 import org.jboss.messaging.core.paging.Pager;
-import org.jboss.messaging.core.paging.Page;
 import org.jboss.messaging.core.paging.PagingStoreFactory;
 import org.jboss.messaging.util.SimpleString;
 
@@ -73,7 +72,8 @@
    private volatile Page currentPage;
 
    // This is supposed to perform better than synchronized methods
-   private final Semaphore globalLock = new Semaphore(1);
+   // globalLock protects opening/closing and messing up with IDs
+   private final Semaphore globalLock = new Semaphore(1); 
 
    private final ReadWriteLock lock = new ReentrantReadWriteLock();
    private volatile boolean initialized = false;
@@ -121,14 +121,19 @@
       return storeName;
    }
    
-   /** It returns one of the Pages. It doesn't perform reading by itself. */
+   /** 
+    *  It returns a Page out of the Page System without reading it. 
+    *  The method calling this method will remove the page and will start reading it outside of any locks. 
+    *  
+    * */
    public Page depage() throws Exception
    {
       validateInit();
       
       // Read needs both global and writeLock
-      globalLock.acquire();
-      lock.writeLock().lock();
+      globalLock.acquire(); // This is a replacement synchronized.
+                            // Can't change any IDs while depaging.
+      lock.writeLock().lock();  // Wait pending writes to finish before depage.
       
       try
       {
@@ -210,6 +215,7 @@
          
          if ((pageUsedSize.addAndGet(bytesToWrite) > maxPageSize && currentPage.getNumberOfMessages() > 0))
          {
+            // Wait any pending transaction on the current page to finish before we can open another page.
             lock.writeLock().lock();
             try
             {

Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java	2008-08-22 17:50:24 UTC (rev 4864)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java	2008-08-22 21:40:00 UTC (rev 4865)
@@ -510,7 +510,7 @@
          
          for (PageTransaction pageTrans: pageTransactionsToUpdate)
          {
-            if (pageTrans.getSize() == 0)
+            if (pageTrans.getNumberOfMessages() == 0)
             {
                storageManager.storeDelete(pageTrans.getRecordID());
                transactions.remove(pageTrans.getTransactionID());

Modified: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageTransactionImplTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageTransactionImplTest.java	2008-08-22 17:50:24 UTC (rev 4864)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageTransactionImplTest.java	2008-08-22 21:40:00 UTC (rev 4865)
@@ -71,7 +71,7 @@
       }
       
       
-      assertEquals(nr1, trans.getSize());
+      assertEquals(nr1, trans.getNumberOfMessages());
       
       ByteBuffer buffer = ByteBuffer.allocate(trans.getEncodeSize());
       MessagingBuffer wrapper = new ByteBufferWrapper(buffer);
@@ -85,11 +85,11 @@
       assertEquals(id1, trans2.getRecordID());
       assertEquals(id2, trans2.getTransactionID());
       
-      assertEquals(nr1, trans2.getSize());
+      assertEquals(nr1, trans2.getNumberOfMessages());
       
       trans.decrement(nr1);
       
-      assertEquals(0, trans.getSize());
+      assertEquals(0, trans.getNumberOfMessages());
       
       try
       {




More information about the jboss-cvs-commits mailing list