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 */ 006package org.fcrepo.kernel.api.lock; 007 008import org.fcrepo.kernel.api.identifiers.FedoraId; 009 010/** 011 * A simple lock with a type, transaction and resource. 012 * <p> 013 * It is essential that implementations of this interface implement {@link Object#equals(Object)} and 014 * {@link Object#hashCode()} so that all locks with the same transaction id and resource id are considered equal. 015 * 016 * @author whikloj 017 * @since 6.3.1 018 */ 019public interface ResourceLock { 020 021 /** 022 * @return the resource ID that is locked. 023 */ 024 FedoraId getResourceId(); 025 026 /** 027 * Does this lock hold the mentioned item? 028 * @param resourceId the FedoraId of the resource to check this lock for. 029 * @return true if this lock holds it. 030 */ 031 boolean hasResource(final FedoraId resourceId); 032 033 /** 034 * @return the lock type 035 */ 036 ResourceLockType getLockType(); 037 038 /** 039 * Does this lock type match the provided one. 040 * @param lockType the provided lock type 041 * @return true if matches. 042 */ 043 boolean hasLockType(final ResourceLockType lockType); 044 045 /** 046 * If an exclusive lock is requested, returns true only if this lock is exclusive. If non-exclusive is requested, 047 * then true is always returned. 048 * 049 * @param lockType the type of lock requested 050 * @return true if this lock is adequate 051 */ 052 boolean isAdequate(final ResourceLockType lockType); 053 054 /** 055 * @return the transaction ID for this lock. 056 */ 057 String getTransactionId(); 058}