jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [4/6] jena git commit: JENA-1542: Allow TransactionComponents to be added.
Date Fri, 11 May 2018 11:45:18 GMT
JENA-1542: Allow TransactionComponents to be added.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/27ad5b74
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/27ad5b74
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/27ad5b74

Branch: refs/heads/master
Commit: 27ad5b74d8322d35e203cab41024f32a7b0eda24
Parents: 06f713d
Author: Andy Seaborne <andy@apache.org>
Authored: Fri May 4 17:06:54 2018 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri May 4 17:06:54 2018 +0100

----------------------------------------------------------------------
 .../transaction/txn/TransactionCoordinator.java | 64 ++++++++++++--------
 .../org/apache/jena/tdb2/sys/TDBInternal.java   | 12 ++++
 2 files changed, 51 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/27ad5b74/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
index e4431cb..cf99afe 100644
--- a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
+++ b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
@@ -66,7 +66,8 @@ public class TransactionCoordinator {
     private static Logger log = Sys.syslog ;
     
     private final Journal journal ;
-    private boolean coordinatorStarted = false ;
+    // Lock on configuration changes. 
+    private boolean configurable = true ;
 
     private final ComponentGroup components = new ComponentGroup() ;
     // Components 
@@ -130,10 +131,8 @@ public class TransactionCoordinator {
      * This must be setup before recovery is attempted. 
      */
     public TransactionCoordinator add(TransactionalComponent elt) {
-        checkSetup() ;
-        synchronized(coordinatorLock) {
-            components.add(elt) ;
-        }
+        checklAllowModication() ;
+        components.add(elt) ;
         return this ;
     }
 
@@ -142,41 +141,56 @@ public class TransactionCoordinator {
      * @see #add 
      */
     public TransactionCoordinator remove(TransactionalComponent elt) {
-        checkSetup() ;
-        synchronized(coordinatorLock) {
-            components.remove(elt.getComponentId()) ;
-        }
+        checklAllowModication() ;
+        components.remove(elt.getComponentId()) ;
         return this ;
     }
+    
+    /** 
+     * Perform modification of this {@code TransaxctionCoordiator} after it has been started.
+     * <p>
+     * This operation enters {@linkplain #startExclusiveMode() exclusive mode}, allows configurations,

+     * carries out the {@code action}, reset the cofiguration lock, and exits exclusive mode.
+     * <p>
+     * Do not call inside a transaction, it may cause a deadlock.  
+     * <p>
+     * Use with care!  
+     */
+    public void modify(Runnable action) {
+        try {
+            startExclusiveMode();
+            configurable = true;
+            action.run();
+        } finally {
+            configurable = false;
+            finishExclusiveMode();
+        }
+    }
 
     /**
      * Add a shutdown hook. Shutdown is not guaranteed to be called
      * and hence hooks may not get called.
      */
     public void add(TransactionCoordinator.ShutdownHook hook) {
-        checkSetup() ;
-        synchronized(coordinatorLock) {
-            shutdownHooks.add(hook) ;
-        }
+        checklAllowModication() ;
+        shutdownHooks.add(hook) ;
     }
 
     /** Remove a shutdown hook */
     public void remove(TransactionCoordinator.ShutdownHook hook) {
-        checkSetup() ;
-        synchronized(coordinatorLock) {
-            shutdownHooks.remove(hook) ;
-        }
+        checklAllowModication() ;
+        shutdownHooks.remove(hook) ;
     }
     
     public void setQuorumGenerator(QuorumGenerator qGen) {
-        checkSetup() ;
+        checklAllowModication() ;
         this.quorumGenerator = qGen ;
     }
 
     public void start() {
-        checkSetup() ;
+        checklAllowModication() ;
         recovery() ;
-        coordinatorStarted = true ;
+        configurable = false ;
     }
 
     private /*public*/ void recovery() {
@@ -268,15 +282,15 @@ public class TransactionCoordinator {
         journal.close(); 
     }
 
-    // Are we in the initialization phase?
-    private void checkSetup() {
-        if ( coordinatorStarted )
-            throw new TransactionException("TransactionCoordinator has already been started")
;
+    // Can modifications be made? 
+    private void checklAllowModication() {
+        if ( ! configurable )
+            throw new TransactionException("TransactionCoordinator configuration is locked")
;
     }
 
     // Is this TransactionCoordinator up and running?
     private void checkActive() {
-        if ( ! coordinatorStarted )
+        if ( configurable )
             throw new TransactionException("TransactionCoordinator has not been started")
;
         checkNotShutdown();
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/27ad5b74/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/TDBInternal.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/TDBInternal.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/TDBInternal.java
index c98998f..8957185 100644
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/TDBInternal.java
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/TDBInternal.java
@@ -19,6 +19,7 @@
 package org.apache.jena.tdb2.sys;
 
 import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.dboe.transaction.txn.TransactionCoordinator;
 import org.apache.jena.graph.Node;
 import org.apache.jena.query.Dataset;
 import org.apache.jena.sparql.core.DatasetGraph;
@@ -114,6 +115,17 @@ public class TDBInternal {
     }
     
     /**
+     * Return the {@link TransactionCoordinator} for a TDB2-backed DatasetGraph
+     * or null, if not backed by TDB2.
+     */
+    public static TransactionCoordinator getTransactionCoordinator(DatasetGraph dsg) {
+        DatasetGraphTDB dsgtdb = getDatasetGraphTDB(dsg);
+        if ( dsgtdb == null )
+            return null;
+        return dsgtdb.getTxnSystem().getTxnMgr();
+    }
+
+    /**
      * Return the DatasetGraphTDB for a DatasetGraph, or null.
      * Use the {@link DatasetGraphTDB} with care.
      */


Mime
View raw message