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 javax.jcr.Session;
021
022import org.fcrepo.kernel.api.services.NodeService;
023
024/**
025 * An interface representing a utility whose locking methods can enforce
026 * the kinds of concurrency restrictions appropriate for an otherwise
027 * concurrency-naive application that operates on hierarchical resources
028 * represented by paths (as in URIs or filesystems).
029 *
030 * @author Mike Durbin
031 */
032public interface PathLockManager {
033
034    /**
035     * An interface representing a lock (comparable to that defined in
036     * java.util.concurrent.locks) that has been acquired.  Memory management
037     * for instances of this lock is handled by LockManager instances and
038     * anyone else receiving one of these such locks from a LockManager
039     * should not retain a reference to the used lock after releasing it.
040     */
041    public interface AcquiredLock {
042
043        /**
044         * Releases the lock, after which it's useless.
045         */
046        public void release();
047    }
048
049    /**
050     * Locks the necessary resources affected in order to safely view a resource
051     * at the given path.  A successful return from this method should guarantee
052     * that until release() is invoked on the returned Lock that no changes are made
053     * to the resource that would affect its display.
054     *
055     * @param path the path to a resource to be viewed
056     * @return an acquired Lock on the relevant resources
057     */
058    public AcquiredLock lockForRead(String path);
059
060    /**
061     * Locks the necessary resources affected in order to safely write to a resource
062     * at the given path.  A successful return from this method should guarantee
063     * that until release() is invoked on the returned Lock that no other callers
064     * may be granted locks necessary to add, modify or delete the resource at the
065     * provided path.
066     *
067     * @param path the path to a resource to be created (may involve implicitly created
068     *        resources at parent paths)
069     * @param session the current session
070     * @param nodeService the repository NodeService implementation
071     * @return an acquired Lock on the relevant resources
072     */
073    public AcquiredLock lockForWrite(String path, Session session, NodeService nodeService);
074
075    /**
076     * Locks the necessary resources affected in order to safely delete a resource
077     * at the given path.  A successful return from this method should guarantee
078     * that until release() is invoked on the returned Lock that no other callers
079     * may be granted locks necessary to add, modify or delete the resource at the
080     * provided path or any child path (because deletes cascade).
081     *
082     * @param path the path to a resource to be deleted (may imply the deletion of
083     *        all descendant resources)
084     * @return an acquired Lock on the relevant resources
085     */
086    public AcquiredLock lockForDelete(String path);
087
088}