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 */
017package org.apache.commons.transaction.locking;
018
019/**
020 * A multi level lock. Depending on the implementation more than one owner may own a certain lock level on the same lock.
021 * 
022 * @version $Id: MultiLevelLock.java 493628 2007-01-07 01:42:48Z joerg $
023 * @see LockManager
024 */
025public interface MultiLevelLock {
026
027    /**
028     * Tries to acquire a certain lock level on this lock.
029     * 
030     * @param ownerId a unique id identifying the entity that wants to acquire a certain lock level on this lock
031     * @param targetLockLevel the lock level to acquire
032     * @param wait <code>true</code> if this method shall block when the desired lock level can not be acquired
033     * @param reentrant <code>true</code> if lock levels of the same entity acquired earlier 
034     * should not restrict compatibility with the lock level desired now   
035     * @param timeoutMSecs if blocking is enabled by the <code>wait</code> parameter this specifies the maximum wait time in milliseconds
036     * @return <code>true</code> if the lock actually was acquired 
037     * @throws InterruptedException when the thread waiting on this method is interrupted
038     */
039    public boolean acquire(Object ownerId, int targetLockLevel, boolean wait, boolean reentrant, long timeoutMSecs)
040        throws InterruptedException;
041
042    /**
043     * Releases any lock levels the specified owner may hold on this lock.
044     * 
045     * @param ownerId a unique id identifying the entity that wants to release all lock levels
046     * @return <code>true</code> if the lock actually was released, <code>false</code> in case
047     * there was no lock held by the owner
048     */
049    public boolean release(Object ownerId);
050
051   /**
052    * Retuns the highest lock level the specified owner holds on this lock or <code>0</code> if it holds no locks at all. 
053    * 
054    * @param ownerId a unique id identifying the entity that wants to know its highest lock level
055    * @return the highest lock level
056    */
057    public int getLockLevel(Object ownerId);
058}