You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by sa...@apache.org on 2015/06/13 10:42:30 UTC

ode git commit: ODE-1033: Implemented thread safe version counter

Repository: ode
Updated Branches:
  refs/heads/ode-1.3.x 803d4ef64 -> 99d70ed56


ODE-1033: Implemented thread safe version counter


Project: http://git-wip-us.apache.org/repos/asf/ode/repo
Commit: http://git-wip-us.apache.org/repos/asf/ode/commit/99d70ed5
Tree: http://git-wip-us.apache.org/repos/asf/ode/tree/99d70ed5
Diff: http://git-wip-us.apache.org/repos/asf/ode/diff/99d70ed5

Branch: refs/heads/ode-1.3.x
Commit: 99d70ed56cb8a095035ef519039549184cc3b84e
Parents: 803d4ef
Author: sathwik <sa...@apache.org>
Authored: Sat Jun 13 14:11:58 2015 +0530
Committer: sathwik <sa...@apache.org>
Committed: Sat Jun 13 14:11:58 2015 +0530

----------------------------------------------------------------------
 .../org/apache/ode/store/ProcessStoreImpl.java  | 51 +++++++++++++++++---
 1 file changed, 45 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ode/blob/99d70ed5/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
----------------------------------------------------------------------
diff --git a/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java b/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
index 9061cbd..2e09bde 100644
--- a/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
+++ b/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
@@ -36,11 +36,13 @@ import org.w3c.dom.Node;
 
 import javax.sql.DataSource;
 import javax.xml.namespace.QName;
+
 import java.io.File;
 import java.io.IOException;
 import java.sql.SQLException;
 import java.util.*;
 import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.regex.Matcher;
@@ -101,6 +103,8 @@ public class ProcessStoreImpl implements ProcessStore {
      */
     private DataSource _inMemDs;
 
+    private AtomicLong _version = new AtomicLong(0);
+
     public ProcessStoreImpl() {
         this(null, null, "", new OdeConfigProperties(new Properties(), ""), true);
     }
@@ -126,6 +130,46 @@ public class ProcessStoreImpl implements ProcessStore {
             }
             _inMemDs = hsqlds;
         }
+
+        initializeVersionCounter();
+    }
+
+    /**
+     * Process and DU use a monotonically increased single version number by default.
+     * Reads the version number from the database and intializes the version counter which
+     * is used to assign version numbers to Deployment units and Processes. Version counter is an atomic long object.
+     * Cluster implementations need to provide a cluster wide version counter.
+     * Version counter is initialized in the constructor.
+     */
+    protected void initializeVersionCounter(){
+
+        long version = readNextVersionFromDB();
+
+        _version.compareAndSet(0, version);
+    }
+
+    /**
+     * Reads the monotonic version number from the database.
+     * @return incremented value of version.
+     */
+    protected long readNextVersionFromDB() {
+        long version = exec(new Callable<Long>() {
+            public Long call(ConfStoreConnection conn) {
+                return conn.getNextVersion();
+            }
+        });
+
+        return version;
+    }
+
+    /**
+     * Returns the current value of the version counter and increments.
+     * Cluster implementations need to override this method.
+     * @return Current value of the version counter.
+     * @see #initializeVersionCounter()
+     */
+    protected long getAndIncrementVersion(){
+        return _version.getAndIncrement();
     }
 
     /**
@@ -189,12 +233,7 @@ public class ProcessStoreImpl implements ProcessStore {
         
         long version;
         if (autoincrementVersion || du.getStaticVersion() == -1) {
-            // Process and DU use a monotonically increased single version number by default.
-            version = exec(new Callable<Long>() {
-                public Long call(ConfStoreConnection conn) {
-                    return conn.getNextVersion();
-                }
-            });
+            version = getAndIncrementVersion();
         } else {
             version = du.getStaticVersion();
         }