Jordan Halterman | 4743258 | 2018-01-25 16:56:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.store.service; |
| 17 | |
| 18 | import java.time.Duration; |
| 19 | import java.util.Optional; |
| 20 | |
| 21 | /** |
| 22 | * Asynchronous lock primitive. |
| 23 | */ |
| 24 | public interface DistributedLock extends DistributedPrimitive { |
| 25 | @Override |
| 26 | default Type primitiveType() { |
| 27 | return Type.LOCK; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Acquires the lock, blocking until it's available. |
| 32 | * |
| 33 | * @return the acquired lock version |
| 34 | */ |
| 35 | Version lock(); |
| 36 | |
| 37 | /** |
| 38 | * Attempts to acquire the lock. |
| 39 | * |
| 40 | * @return indicates whether the lock was acquired |
| 41 | */ |
| 42 | Optional<Version> tryLock(); |
| 43 | |
| 44 | /** |
| 45 | * Attempts to acquire the lock for a specified amount of time. |
| 46 | * |
| 47 | * @param timeout the timeout after which to give up attempting to acquire the lock |
| 48 | * @return indicates whether the lock was acquired |
| 49 | */ |
| 50 | Optional<Version> tryLock(Duration timeout); |
| 51 | |
| 52 | /** |
| 53 | * Unlocks the lock. |
| 54 | */ |
| 55 | void unlock(); |
| 56 | } |