2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.lockmanager.api;
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.
31 public interface LockManager {
34 * Lock resource without timeout. Lock never expires.
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
41 boolean acquireLock(String resource, String owner) throws LockException;
44 * Lock resource with timeout. After the timeout resource becomes unlocked.
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
53 boolean acquireLock(String resource, String owner, long timeout) throws LockException;
58 * @param resource resource id
59 * @param owner lock owner id
60 * @throws LockException thrown if resource is locked by other owner
62 void releaseLock(String resource, String owner) throws LockException;
65 * check resource lock status.
67 * @param resource resource id
70 boolean isLocked(String resource);