Permalink
Browse files

FCREPO-846: Revise to use ReentrantReadWriteLock

Handle concurrency using ReentrantReadWriteLock rather than synchronizing
writes and catching errors from reads.  Also fixes issue in
TestCommandLineUtilities where one test was not cleaning up properly.

Conflicts:

	fcrepo-integrationtest/src/test/java/org/fcrepo/test/integration/TestCommandLineUtilities.java

Conflicts resolved (include new method from master, add in exception from
maintenance-3.4 commit)
  • Loading branch information...
penthes committed Jan 18, 2011
1 parent 2338fa3 commit 840d788d79b2cfe728b59d6c3ae80f52bfac227b
@@ -204,7 +204,7 @@ public void testBatchPurge() throws Exception {
System.out.println("Batch purge test succeeded");
}
- public void testExport() {
+ public void testExport() throws Exception {
System.out.println("Testing fedora-export");
System.out.println("Ingesting object test:1001");
ingestFoxmlFile(new File(RESOURCEBASE
@@ -234,6 +234,7 @@ public void testExport() {
if (outFile2.exists()) {
outFile2.delete();
}
+ purgeFast("test:1001");
System.out.println("Export test succeeded");
}
@@ -12,6 +12,8 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -70,6 +72,10 @@
public Validator validator = null;
+ private static final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
+ public static final Lock readLock = rwl.readLock();
+ public static final Lock writeLock = rwl.writeLock();
+
public DbXmlManager()
throws PolicyStoreException {
initConfig();
@@ -161,24 +167,31 @@ public DbXmlManager()
* Closes the dbxml container and manager.
*/
public void close() {
- if (container != null) {
- try {
- container.close();
- container = null;
- log.info("Closed container");
- } catch (XmlException e) {
- log.warn("close failed: " + e.getMessage(), e);
+ // getting a read lock will ensure all writes have finished
+ // if we are really closing assume that we don't care about reads
+ readLock.lock();
+ try {
+ if (container != null) {
+ try {
+ container.close();
+ container = null;
+ log.info("Closed container");
+ } catch (XmlException e) {
+ log.warn("close failed: " + e.getMessage(), e);
+ }
}
- }
- if (manager != null) {
- try {
- manager.close();
- manager = null;
- log.info("Closed manager");
- } catch (XmlException e) {
- log.warn("close failed: " + e.getMessage(), e);
+ if (manager != null) {
+ try {
+ manager.close();
+ manager = null;
+ log.info("Closed manager");
+ } catch (XmlException e) {
+ log.warn("close failed: " + e.getMessage(), e);
+ }
}
+ } finally {
+ readLock.unlock();
}
}
Oops, something went wrong.

0 comments on commit 840d788

Please sign in to comment.