This repository has been archived by the owner on Jul 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
DistributedLock.java
66 lines (60 loc) · 2.72 KB
/
DistributedLock.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.budjb.spring.distributed.lock;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
public interface DistributedLock extends Lock {
/**
* Attempts to acquire a lock with and a lock timeout iff the lock is available.
*
* @param leaseTime The amount of time to wait for the lock to become available.
* @param timeUnit The time unit of waitTime.
* @throws InterruptedException if the current thread is
* interrupted while acquiring the lock (and interruption
* of lock acquisition is supported)
*/
void lock(long leaseTime, TimeUnit timeUnit) throws InterruptedException;
/**
* Attempts to acquire a lock with a wait timeout and a lock timeout.
* <p>
* If the lock becomes available within the wait timeout, the lock will be acquired and the method
* will return {@code true}. If the wait timeout is reached, the lock is not acquired.
*
* @param waitTime The amount of time to wait for the lock to become available.
* @param waitTimeUnit The time unit of waitTime.
* @param leaseTime The amount of time that lock should be considered valid.
* @param leaseTimeUnit The time unit of lockTime.
* @return Whether the lock was acquired.
* @throws InterruptedException if the current thread is
* interrupted while acquiring the lock (and interruption
* of lock acquisition is supported)
*/
boolean tryLock(long waitTime, TimeUnit waitTimeUnit, long leaseTime, TimeUnit leaseTimeUnit) throws InterruptedException;
/**
* Returns whether the lock instance believes is currently owns the lock.
*
* @return Whether the lock instance believes is currently owns the lock.
*/
boolean isLocked();
/**
* Returns whether the distributed lock implementation support leases.
* <p>
* If {@code false}, the behavior of the lease-aware methods is undefined.
*
* @return Whether leases are supported.
*/
boolean supportsLeases();
}