2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 package org.openecomp.appc.lockmanager.api;
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.
29 public interface LockManager {
32 * Lock resource without timeout. Lock never expires.
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
39 boolean acquireLock(String resource, String owner) throws LockException;
42 * Lock resource with timeout. After the timeout resource becomes unlocked.
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
51 boolean acquireLock(String resource, String owner, long timeout) throws LockException;
56 * @param resource resource id
57 * @param owner lock owner id
58 * @throws LockException thrown if resource is locked by other owner
60 void releaseLock(String resource, String owner) throws LockException;
63 * check resource lock status.
65 * @param resource resource id
68 boolean isLocked(String resource);