001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.transaction.locking;
018    
019    /**
020     * A manager for multi level locks on resources. Encapsulates creation, removal, and retrieval of locks.
021     * Each resource can have at most a single lock. However, it may be possible for more than one
022     * accessing entity to have influence on this lock via different lock levels that may be 
023     * provided by the according implementation of {@link MultiLevelLock}. 
024     * 
025     * @version $Id: LockManager.java 493628 2007-01-07 01:42:48Z joerg $
026     * @see MultiLevelLock
027     */
028    public interface LockManager {
029    
030        /**
031         * Either gets an existing lock on the specified resource or creates one if none exists. 
032         * This methods guarantees to do this atomically. 
033         * 
034         * @param resourceId the resource to get or create the lock on
035         * @return the lock for the specified resource
036         */
037        public MultiLevelLock atomicGetOrCreateLock(Object resourceId);
038    
039        /**
040         * Gets an existing lock on the specified resource. If none exists it returns <code>null</code>. 
041         * 
042         * @param resourceId the resource to get the lock for
043         * @return the lock on the specified resource
044         */
045        public MultiLevelLock getLock(Object resourceId);
046    
047        /**
048         * Removes the specified lock from the associated resource. 
049         * 
050         * @param lock the lock to be removed
051         */
052        public void removeLock(MultiLevelLock lock);
053    }