001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.http.api; 019 020import org.fcrepo.kernel.api.FedoraSession; 021import org.fcrepo.kernel.api.services.NodeService; 022 023/** 024 * An interface representing a utility whose locking methods can enforce 025 * the kinds of concurrency restrictions appropriate for an otherwise 026 * concurrency-naive application that operates on hierarchical resources 027 * represented by paths (as in URIs or filesystems). 028 * 029 * @author Mike Durbin 030 */ 031public interface PathLockManager { 032 033 /** 034 * An interface representing a lock (comparable to that defined in 035 * java.util.concurrent.locks) that has been acquired. Memory management 036 * for instances of this lock is handled by LockManager instances and 037 * anyone else receiving one of these such locks from a LockManager 038 * should not retain a reference to the used lock after releasing it. 039 */ 040 interface AcquiredLock { 041 042 /** 043 * Releases the lock, after which it's useless. 044 */ 045 void release(); 046 } 047 048 /** 049 * Locks the necessary resources affected in order to safely view a resource 050 * at the given path. A successful return from this method should guarantee 051 * that until release() is invoked on the returned Lock that no changes are made 052 * to the resource that would affect its display. 053 * 054 * @param path the path to a resource to be viewed 055 * @return an acquired Lock on the relevant resources 056 */ 057 AcquiredLock lockForRead(String path); 058 059 /** 060 * Locks the necessary resources affected in order to safely write to a resource 061 * at the given path. A successful return from this method should guarantee 062 * that until release() is invoked on the returned Lock that no other callers 063 * may be granted locks necessary to add, modify or delete the resource at the 064 * provided path. 065 * 066 * @param path the path to a resource to be created (may involve implicitly created 067 * resources at parent paths) 068 * @param session the current session 069 * @param nodeService the repository NodeService implementation 070 * @return an acquired Lock on the relevant resources 071 */ 072 AcquiredLock lockForWrite(String path, FedoraSession session, NodeService nodeService); 073 074 /** 075 * Locks the necessary resources affected in order to safely delete a resource 076 * at the given path. A successful return from this method should guarantee 077 * that until release() is invoked on the returned Lock that no other callers 078 * may be granted locks necessary to add, modify or delete the resource at the 079 * provided path or any child path (because deletes cascade). 080 * 081 * @param path the path to a resource to be deleted (may imply the deletion of 082 * all descendant resources) 083 * @return an acquired Lock on the relevant resources 084 */ 085 AcquiredLock lockForDelete(String path); 086 087}