View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.fulcrum.yaafi.framework.locking;
21  
22  /**
23   *
24   * A multi level lock. Depending on the implementation more than one owner may own a certain lock level on the same lock.
25   *
26   * @version $Revision: 1.2 $
27   */
28  public interface MultiLevelLock {
29  
30      /**
31       * Tries to acquire a certain lock level on this lock.
32       *
33       * @param ownerId a unique id identifying the entity that wants to acquire a certain lock level on this lock
34       * @param targetLockLevel the lock level to acquire
35       * @param wait <code>true</code> if this method shall block when the desired lock level can not be acquired
36       * @param reentrant <code>true</code> if lock levels of the same entity acquired earlier
37       * should not restrict compatibility with the lock level desired now
38       * @param timeoutMSecs if blocking is enabled by the <code>wait</code> parameter this specifies the maximum wait time in milliseconds
39       * @return <code>true</code> if the lock actually was acquired
40       * @throws InterruptedException when the thread waiting on this method is interrupted
41       */
42      public boolean acquire(Object ownerId, int targetLockLevel, boolean wait, boolean reentrant, long timeoutMSecs)
43          throws InterruptedException;
44  
45      /**
46       * Releases any lock levels the specified owner may hold on this lock.
47       *
48       * @param ownerId a unique id identifying the entity that wants to release all lock levels
49       * @return <code>true</code> if the lock actually was released, <code>false</code> in case
50       * there was no lock held by the owner
51       */
52      public boolean release(Object ownerId);
53  
54     /**
55      * Retuns the highest lock level the specified owner holds on this lock or <code>0</code> if it holds no locks at all.
56      *
57      * @param ownerId a unique id identifying the entity that wants to know its highest lock level
58      * @return the highest lock level
59      */
60      public int getLockLevel(Object ownerId);
61  }