activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r829890 - in /activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page: HawtPageFile.java HawtPageFileFactory.java
Date Mon, 26 Oct 2009 18:24:36 GMT
Author: chirino
Date: Mon Oct 26 18:24:35 2009
New Revision: 829890

URL: http://svn.apache.org/viewvc?rev=829890&view=rev
Log:
starting to add bit to allow for async worker to perform updates.


Modified:
    activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page/HawtPageFile.java
    activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page/HawtPageFileFactory.java

Modified: activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page/HawtPageFile.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page/HawtPageFile.java?rev=829890&r1=829889&r2=829890&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page/HawtPageFile.java
(original)
+++ activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page/HawtPageFile.java
Mon Oct 26 18:24:35 2009
@@ -24,6 +24,9 @@
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
 import java.util.zip.CRC32;
 
 import javolution.io.Struct;
@@ -159,6 +162,7 @@
      * tracked in the page file allocator.
      */
     private Ranges storedFreeList = new Ranges();
+    private final ExecutorService worker;
     
     public HawtPageFile(HawtPageFileFactory factory) {
         this.pageFile = factory.getPageFile();
@@ -167,6 +171,20 @@
         this.allocator = pageFile.allocator();
         ByteBuffer slice = file.slice(false, 0, FILE_HEADER_SIZE);
         this.header.setByteBuffer(slice, slice.position());
+        
+        if( factory.isUseWorkerThread() ) {
+            worker = Executors.newSingleThreadExecutor(new ThreadFactory() {
+                public Thread newThread(Runnable r) {
+                    Thread rc = new Thread(r);
+                    rc.setName("HawtDB Worker");
+                    rc.setDaemon(true);
+                    rc.start();
+                    return rc;
+                }
+            });
+        } else {
+            worker = null;
+        }
     }
     
     @Override
@@ -264,13 +282,23 @@
         }
         
         if( fullBatch ) {
-            flushBatch();
+            synchronized (HOUSE_KEEPING_MUTEX) {
+                storeBatches(false);
+            }
+            if( worker!=null ) {
+                worker.execute(new Runnable() {
+                    public void run() {
+                        flushBatch();
+                    }
+                });
+            } else {
+                flushBatch();
+            }
         }
     }
 
     private void flushBatch() {
         synchronized (HOUSE_KEEPING_MUTEX) {
-            storeBatches(false);
             // TODO: do the following actions async.
             syncBatches();
             performBatches();
@@ -615,7 +643,7 @@
     // /////////////////////////////////////////////////////////////////
     // TODO:
     // /////////////////////////////////////////////////////////////////
-
+    
     /**
      * The quiesce method is used to pause/stop access to the concurrent page file.
      * access can be restored using the {@link #resume()} method.    

Modified: activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page/HawtPageFileFactory.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page/HawtPageFileFactory.java?rev=829890&r1=829889&r2=829890&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page/HawtPageFileFactory.java
(original)
+++ activemq/sandbox/activemq-apollo/hawtdb/src/main/java/org/apache/hawtdb/internal/page/HawtPageFileFactory.java
Mon Oct 26 18:24:35 2009
@@ -26,11 +26,8 @@
     
     protected boolean drainOnClose;
     protected boolean sync = true;
+    protected boolean useWorkerThread;
 
-    public HawtPageFile getConcurrentPageFile() {
-        return concurrentPageFile;
-    }
-    
     public HawtPageFileFactory() {
         super.setHeaderSize(HawtPageFile.FILE_HEADER_SIZE);
     }
@@ -74,6 +71,24 @@
         this.sync = sync;
     }
     
-    
+    public HawtPageFile getConcurrentPageFile() {
+        return concurrentPageFile;
+    }
+
+    public boolean isDrainOnClose() {
+        return drainOnClose;
+    }
+
+    public void setDrainOnClose(boolean drainOnClose) {
+        this.drainOnClose = drainOnClose;
+    }
+
+    public boolean isUseWorkerThread() {
+        return useWorkerThread;
+    }
+
+    public void setUseWorkerThread(boolean useWorkerThread) {
+        this.useWorkerThread = useWorkerThread;
+    }
     
 }



Mime
View raw message