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