1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.transaction.locking;
18
19 /**
20 * A manager for multi level locks on resources. Encapsulates creation, removal, and retrieval of locks.
21 * Each resource can have at most a single lock. However, it may be possible for more than one
22 * accessing entity to have influence on this lock via different lock levels that may be
23 * provided by the according implementation of {@link MultiLevelLock}.
24 *
25 * @version $Id: LockManager.java 493628 2007-01-07 01:42:48Z joerg $
26 * @see MultiLevelLock
27 */
28 public interface LockManager {
29
30 /**
31 * Either gets an existing lock on the specified resource or creates one if none exists.
32 * This methods guarantees to do this atomically.
33 *
34 * @param resourceId the resource to get or create the lock on
35 * @return the lock for the specified resource
36 */
37 public MultiLevelLock atomicGetOrCreateLock(Object resourceId);
38
39 /**
40 * Gets an existing lock on the specified resource. If none exists it returns <code>null</code>.
41 *
42 * @param resourceId the resource to get the lock for
43 * @return the lock on the specified resource
44 */
45 public MultiLevelLock getLock(Object resourceId);
46
47 /**
48 * Removes the specified lock from the associated resource.
49 *
50 * @param lock the lock to be removed
51 */
52 public void removeLock(MultiLevelLock lock);
53 }