Updating licenses in all files
[appc.git] / 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  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.lockmanager.api;
24
25 /**
26  * Enables locking and unlocking of a resource by id.
27  * If the resource is locked, only lock owner can reacquire the lock or unlock the resource.
28  */
29 public interface LockManager {
30
31     /**
32      * Lock resource without timeout. Lock never expires.
33      *
34      * @param resource resource id
35      * @param owner lock owner id
36      * @return true - if lock is acquired, false - if the resource was already locked by the owner
37      * @throws LockException thrown if resource is already locked by other owner
38      */
39     boolean acquireLock(String resource, String owner) throws LockException;
40
41     /**
42      * Lock resource with timeout. After the timeout resource becomes unlocked.
43      *
44      * @param resource resource id
45      * @param owner lock owner id
46      * @param timeout in milliseconds, after this timeout lock will expire and resource becomes unlocked,
47      *  timeout == 0 means that the lock never expires - same as call acquireLock() without timeout parameter
48      * @return true - if lock is acquired, false - if the resource was already locked by the owner
49      * @throws LockException thrown if resource is already locked by other owner
50      */
51     boolean acquireLock(String resource, String owner, long timeout) throws LockException;
52
53     /**
54      * Unlock resource.
55      *
56      * @param resource resource id
57      * @param owner lock owner id
58      * @throws LockException thrown if resource is locked by other owner
59      */
60     void releaseLock(String resource, String owner) throws LockException;
61
62     /**
63      * check resource lock status.
64      *
65      * @param resource resource id
66      */
67
68     boolean isLocked(String resource);
69
70 }