Include impacted changes for APPC-346,APPC-348
[appc.git] / appc-dispatcher / appc-dispatcher-common / lock-manager-lib / lock-manager-api / src / main / java / org / onap / appc / lockmanager / api / LockManager.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.lockmanager.api;
26
27 /**
28  * Enables locking and unlocking of a resource by id.
29  * If the resource is locked, only lock owner can reacquire the lock or unlock the resource.
30  */
31 public interface LockManager {
32
33     /**
34      * Lock resource without timeout. Lock never expires.
35      *
36      * @param resource resource id
37      * @param owner lock owner id
38      * @return true - if lock is acquired, false - if the resource was already locked by the owner
39      * @throws LockException thrown if resource is already locked by other owner
40      */
41     boolean acquireLock(String resource, String owner) throws LockException;
42
43     /**
44      * Lock resource with timeout. After the timeout resource becomes unlocked.
45      *
46      * @param resource resource id
47      * @param owner lock owner id
48      * @param timeout in milliseconds, after this timeout lock will expire and resource becomes unlocked,
49      *  timeout == 0 means that the lock never expires - same as call acquireLock() without timeout parameter
50      * @return true - if lock is acquired, false - if the resource was already locked by the owner
51      * @throws LockException thrown if resource is already locked by other owner
52      */
53     boolean acquireLock(String resource, String owner, long timeout) throws LockException;
54
55     /**
56      * Unlock resource.
57      *
58      * @param resource resource id
59      * @param owner lock owner id
60      * @throws LockException thrown if resource is locked by other owner
61      */
62     void releaseLock(String resource, String owner) throws LockException;
63
64     /**
65      * check resource lock status.
66      *
67      * @param resource resource id
68      */
69
70     boolean isLocked(String resource);
71
72     /**
73      * returns the oner of the resource
74      * if no one owns, returns null
75      * @param resource
76      * @return owner of the resource
77      */
78
79     String getLockOwner(String resource);
80
81 }