use of org.exist.collections.ManagedLocks in project exist by eXist-db.
the class NodeProxy method lock.
@Override
public ManagedLocks<ManagedDocumentLock> lock(final DBBroker broker, final boolean exclusive) throws LockException {
final LockManager lockManager = broker.getBrokerPool().getLockManager();
final ManagedDocumentLock docLock;
if (exclusive) {
docLock = lockManager.acquireDocumentWriteLock(doc.getURI());
} else {
docLock = lockManager.acquireDocumentReadLock(doc.getURI());
}
return new ManagedLocks<>(docLock);
}
use of org.exist.collections.ManagedLocks in project exist by eXist-db.
the class DefaultDocumentSet method lock.
@Override
public ManagedLocks<ManagedDocumentLock> lock(final DBBroker broker, final boolean exclusive) throws LockException {
final LockManager lockManager = broker.getBrokerPool().getLockManager();
final List<ManagedDocumentLock> managedDocumentLocks = new ArrayList<>();
final Iterator<DocumentImpl> documentIterator = getDocumentIterator();
try {
while (documentIterator.hasNext()) {
final DocumentImpl document = documentIterator.next();
final ManagedDocumentLock managedDocumentLock;
if (exclusive) {
managedDocumentLock = lockManager.acquireDocumentWriteLock(document.getURI());
} else {
managedDocumentLock = lockManager.acquireDocumentReadLock(document.getURI());
}
managedDocumentLocks.add(managedDocumentLock);
}
return new ManagedLocks<>(managedDocumentLocks);
} catch (final LockException e) {
// unlock any previously locked documents
if (!managedDocumentLocks.isEmpty()) {
new ManagedLocks<>(managedDocumentLocks).close();
}
throw e;
}
}
use of org.exist.collections.ManagedLocks in project exist by eXist-db.
the class NewArrayNodeSet method lock.
@Override
public ManagedLocks<ManagedDocumentLock> lock(final DBBroker broker, final boolean exclusive) throws LockException {
sort();
final LockManager lockManager = broker.getBrokerPool().getLockManager();
final ManagedDocumentLock[] managedDocumentLocks = new ManagedDocumentLock[documentCount];
try {
for (int idx = 0; idx < documentCount; idx++) {
final DocumentImpl doc = nodes[documentNodesOffset[idx]].getOwnerDocument();
final ManagedDocumentLock managedDocumentLock;
if (exclusive) {
managedDocumentLock = lockManager.acquireDocumentWriteLock(doc.getURI());
} else {
managedDocumentLock = lockManager.acquireDocumentReadLock(doc.getURI());
}
managedDocumentLocks[idx] = managedDocumentLock;
}
return new ManagedLocks<>(managedDocumentLocks);
} catch (final LockException e) {
// unlock any previously locked documents
new ManagedLocks<>(managedDocumentLocks).close();
throw e;
}
}
use of org.exist.collections.ManagedLocks in project exist by eXist-db.
the class ExtArrayNodeSet method lock.
@Override
public ManagedLocks<ManagedDocumentLock> lock(final DBBroker broker, final boolean exclusive) throws LockException {
final LockManager lockManager = broker.getBrokerPool().getLockManager();
final ManagedDocumentLock[] managedDocumentLocks = new ManagedDocumentLock[partCount];
try {
for (int i = 0; i < partCount; i++) {
final DocumentImpl doc = parts[i].getOwnerDocument();
final ManagedDocumentLock docLock;
if (exclusive) {
docLock = lockManager.acquireDocumentWriteLock(doc.getURI());
} else {
docLock = lockManager.acquireDocumentReadLock(doc.getURI());
}
managedDocumentLocks[i] = docLock;
}
return new ManagedLocks<>(managedDocumentLocks);
} catch (final LockException e) {
// unlock any previously locked documents
new ManagedLocks<>(managedDocumentLocks).close();
throw e;
}
}
Aggregations