001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006
007package org.fcrepo.kernel.api.lock;
008
009import org.fcrepo.kernel.api.exception.ConcurrentUpdateException;
010import org.fcrepo.kernel.api.identifiers.FedoraId;
011
012/**
013 * Responsible for managing write locks on Fedora resources
014 *
015 * @author pwinckles
016 */
017public interface ResourceLockManager {
018
019    /**
020     * Acquires an exclusive lock on the resource, associating it to the txId. If the lock is held by a different
021     * transaction, an exception is thrown. If the lock is already held by the same transaction, then it returns
022     * successfully.
023     *
024     * @param txId the transaction id to associate the lock to
025     * @param resourceId the resource to lock
026     * @throws ConcurrentUpdateException when lock cannot be acquired
027     */
028    void acquireExclusive(final String txId, final FedoraId resourceId);
029
030    /**
031     * Acquires a non-exclusive lock on the resource, associating it to the txId. If an exclusive lock is held by a
032     * different transaction, an exception is thrown. Otherwise, a non-exclusive lock on the resource is acquired.
033     *
034     * @param txId the transaction id to associate the lock to
035     * @param resourceId the resource to lock
036     * @throws ConcurrentUpdateException when lock cannot be acquired
037     */
038    void acquireNonExclusive(final String txId, final FedoraId resourceId);
039
040    /**
041     * Releases all of the locks held by the transaction
042     *
043     * @param txId the transaction id
044     */
045    void releaseAll(final String txId);
046
047}