Search in sources :

Example 1 with ManagedLocks

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);
}
Also used : ManagedLocks(org.exist.collections.ManagedLocks) LockManager(org.exist.storage.lock.LockManager) ManagedDocumentLock(org.exist.storage.lock.ManagedDocumentLock)

Example 2 with ManagedLocks

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;
    }
}
Also used : ManagedLocks(org.exist.collections.ManagedLocks) LockManager(org.exist.storage.lock.LockManager) ManagedDocumentLock(org.exist.storage.lock.ManagedDocumentLock) LockException(org.exist.util.LockException)

Example 3 with ManagedLocks

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;
    }
}
Also used : ManagedLocks(org.exist.collections.ManagedLocks) LockManager(org.exist.storage.lock.LockManager) ManagedDocumentLock(org.exist.storage.lock.ManagedDocumentLock) LockException(org.exist.util.LockException)

Example 4 with ManagedLocks

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;
    }
}
Also used : ManagedLocks(org.exist.collections.ManagedLocks) LockManager(org.exist.storage.lock.LockManager) ManagedDocumentLock(org.exist.storage.lock.ManagedDocumentLock) LockException(org.exist.util.LockException)

Aggregations

ManagedLocks (org.exist.collections.ManagedLocks)4 LockManager (org.exist.storage.lock.LockManager)4 ManagedDocumentLock (org.exist.storage.lock.ManagedDocumentLock)4 LockException (org.exist.util.LockException)3