public
Created

  • Download Gist
DefaultDOManager.java.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
Index: src/main/java/fedora/server/storage/DefaultDOManager.java
===================================================================
--- src/main/java/fedora/server/storage/DefaultDOManager.java (revision 8470)
+++ src/main/java/fedora/server/storage/DefaultDOManager.java (working copy)
@@ -77,6 +77,10 @@
import fedora.server.validation.DOValidatorImpl;
import fedora.server.validation.ValidationUtility;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
/**
* Manages the reading and writing of digital objects by instantiating an
* appropriate object reader or writer. Also, manages the object ingest process
@@ -125,7 +129,8 @@
private DOReaderCache m_readerCache;
- private final Set<String> m_lockedPIDs;
+//private final Set<String> m_lockedPIDs;
+ private final HashMap<String, Lock> m_lockedPIDs;
protected ConnectionPool m_connectionPool;
@@ -139,7 +144,8 @@
public DefaultDOManager(Map<String, String> moduleParameters, Server server, String role)
throws ModuleInitializationException {
super(moduleParameters, server, role);
- m_lockedPIDs = new HashSet<String>();
+//m_lockedPIDs = new HashSet<String>();
+ m_lockedPIDs = new HashMap<String, Lock>();
}
/**
@@ -576,7 +582,7 @@
.warn("Error releasing object lock; Unable to obtain pid from writer.");
}
}
-
+/*
private void releaseWriteLock(String pid) {
synchronized (m_lockedPIDs) {
m_lockedPIDs.remove(pid);
@@ -593,6 +599,35 @@
}
}
}
+ */
+ private void releaseWriteLock(String pid) {
+ synchronized (m_lockedPIDs) {
+ //m_lockedPIDs.remove(pid);
+ m_lockedPIDs.remove(pid).unlock();
+ }
+ }
+
+ private void getWriteLock(String pid) throws ObjectLockedException {
+ synchronized (m_lockedPIDs) {
+ if ( m_lockedPIDs.containsKey(pid)) {
+ Lock w1 = m_lockedPIDs.get(pid);
+ try {
+ if( !w1.tryLock(5000, TimeUnit.SECONDS)) {
+ throw new ObjectLockedException(pid + " is currently being "
+ + "modified by another thread");
+ }
+ } catch (InterruptedException e) {
+ throw new ObjectLockedException(pid + " is currently being "
+ + "modified by another thread");
+ }
+ }
+
+ ReentrantReadWriteLock lck = new ReentrantReadWriteLock();
+ Lock w = lck.writeLock();
+ w.lock();
+ m_lockedPIDs.put(pid, w);
+ }
+ }
public ConnectionPool getConnectionPool() {
return m_connectionPool;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.