Class ConsulLockProvider
- All Implemented Interfaces:
AutoCloseable,LockProvider
public class ConsulLockProvider extends Object implements LockProvider, AutoCloseable
This lock provider registers a new session for lock and on unlock this session is removed together with all associated locks.
The main point you need to be aware about is that consul holds session for up to twice TTL. That means, even if the session TTL is set to 10 seconds, consul will hold still this session for 20 seconds. This is an expected behaviour and it's impossible to change it. This is the reason consul recommends to set the lowest possible TTL and constantly extend it. With this lock it means that even if your lockAtMostFor is less that 20 seconds, the timeout will be higher than 10 seconds and most likely will be 20.
The lock is acquired for the time specified in @SchedulerLock.lockAtMostFor. Please note that this lock provider
doesn't make any correction to the aforementioned TTL behaviour so most likely your locked session will live for
longer than specified in lockAtMostFor. In this lock provider there is no session renewal done in the background.
- Author:
- Artur Kalimullin
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConsulLockProvider.Configuration -
Constructor Summary
Constructors Constructor Description ConsulLockProvider(com.ecwid.consul.v1.ConsulClient consulClient)ConsulLockProvider(com.ecwid.consul.v1.ConsulClient consulClient, Duration minSessionTtl)ConsulLockProvider(com.ecwid.consul.v1.ConsulClient consulClient, Duration minSessionTtl, String consulLockPostfix, Duration gracefulShutdownInterval)ConsulLockProvider(ConsulLockProvider.Configuration configuration) -
Method Summary
Modifier and Type Method Description voidclose()Optional<SimpleLock>lock(LockConfiguration lockConfiguration)
-
Constructor Details
-
ConsulLockProvider
public ConsulLockProvider(com.ecwid.consul.v1.ConsulClient consulClient) -
ConsulLockProvider
-
ConsulLockProvider
-
ConsulLockProvider
-
-
Method Details
-
lock
- Specified by:
lockin interfaceLockProvider
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-