public class LightblueAutoPingLockStrategy extends Object implements LockStrategy
Lightblue locks without TTLs are unsafe. If a client crashes, the lock will not be released. However, locks with TTLs may expire prematurely. By pinging the lock in a separate thread periodically, we can substantially lesson the likelihood of unintentionally losing the lock.
Consumers are expected to check the lock at critical points to ensure it did not expire by
calling LockedResource.ensureAcquiredOrThrow(String).
| Constructor and Description |
|---|
LightblueAutoPingLockStrategy(com.redhat.lightblue.client.Locking locking,
java.time.Duration autoPingInterval)
Same as
LightblueAutoPingLockStrategy(Locking, Duration, Duration)
except the timeToLive duration defaults to 5 times the autoPingInterval. |
LightblueAutoPingLockStrategy(com.redhat.lightblue.client.Locking locking,
java.time.Duration autoPingInterval,
java.time.Duration timeToLive)
Validates
timeToLive is greater than the autoPingInterval. |
| Modifier and Type | Method and Description |
|---|---|
<T> LockedResource<T> |
tryAcquire(String resourceId,
T resource)
Attempts to acquire a lock by the provided
resourceId for the logical resource
provided by resource. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waittryAcquire, tryAcquirepublic LightblueAutoPingLockStrategy(com.redhat.lightblue.client.Locking locking,
java.time.Duration autoPingInterval)
LightblueAutoPingLockStrategy(Locking, Duration, Duration)
except the timeToLive duration defaults to 5 times the autoPingInterval.public LightblueAutoPingLockStrategy(com.redhat.lightblue.client.Locking locking,
java.time.Duration autoPingInterval,
java.time.Duration timeToLive)
timeToLive is greater than the autoPingInterval.locking - The locking client to use which holds knowledge of the locking domain to use.
The default clientId is ignored.autoPingInterval - Amount of time in between automatic pings of acquired locks.timeToLive - Time until locks automatically expire. Should be [much] larger than the
autoPingInterval to ensure locks do not accidentally expire.public <T> LockedResource<T> tryAcquire(String resourceId, T resource) throws LockNotAvailableException
LockStrategyresourceId for the logical resource
provided by resource.
After a resource is locked, it is expected that nothing else can acquire it again until it is released (intentionally or not), no matter if it is the same thread, another thread, or across a network.
tryAcquire in interface LockStrategyT - The type of the resource being acquired.resourceId - A string which identifies the resource and only that resource.resource - A logically locked resource as a result of the id being locked. Participants
must agree on a scheme of resourceIds to resources.LockNotAvailableException - If for whatever reason the lock could not be acquired.
Generally this is simply because another client has the lock, but it could also be due to
network failure, etc.Copyright © 2017. All rights reserved.