2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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=========================================================
22 package org.openecomp.appc.lockmanager.api;
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.
28 public interface LockManager {
31 * Lock resource without timeout. Lock never expires.
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
38 boolean acquireLock(String resource, String owner) throws LockException;
41 * Lock resource with timeout. After the timeout resource becomes unlocked.
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
50 boolean acquireLock(String resource, String owner, long timeout) throws LockException;
55 * @param resource resource id
56 * @param owner lock owner id
57 * @throws LockException thrown if resource is locked by other owner
59 void releaseLock(String resource, String owner) throws LockException;
62 * check resource lock status.
64 * @param resource resource id
67 boolean isLocked(String resource);