Skip to content

Instantly share code, notes, and snippets.

@cbeer
Created January 13, 2010 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbeer/276586 to your computer and use it in GitHub Desktop.
Save cbeer/276586 to your computer and use it in GitHub Desktop.
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment