public class Lock
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected java.time.LocalDateTime |
expiresAt
It should never be null(after acquisition), just acquired(after now) or expired(before now)
|
protected long |
leaseMillis |
protected LockKey |
lockKey |
protected LockService |
lockService |
static java.lang.String |
LOG_EXPIRED_TEMPLATE |
protected io.flamingock.internal.util.id.RunnerId |
owner |
protected long |
retryFrequencyMillis |
protected long |
stopTryingAfterMillis |
protected io.flamingock.internal.util.TimeService |
timeService |
| Constructor and Description |
|---|
Lock(io.flamingock.internal.util.id.RunnerId owner,
LockKey lockKey,
long leaseMillis,
long stopTryingAfterMillis,
long retryFrequencyMillis,
LockService lockService,
io.flamingock.internal.util.TimeService timeService) |
| Modifier and Type | Method and Description |
|---|---|
void |
ensure()
Ensures the lock is safely acquired(safely here means it's acquired with enough margin to operate),
or throws an exception otherwise.
|
java.time.LocalDateTime |
expiresAt() |
boolean |
extend()
Refreshes the lock if it's already taken.
|
protected void |
handleLockException(boolean acquiringLock,
java.time.Instant shouldStopTryingAt,
LockServiceException ex) |
boolean |
isExpired() |
void |
release()
This should be called once all the process guarded by the lock(those who assumed the lock is ensured) has finished.
|
java.lang.String |
toString() |
protected void |
updateLease(long leaseMillis) |
protected void |
waitForLock(java.time.LocalDateTime expiresAt) |
public static final java.lang.String LOG_EXPIRED_TEMPLATE
protected final LockKey lockKey
protected final LockService lockService
protected final io.flamingock.internal.util.TimeService timeService
protected final io.flamingock.internal.util.id.RunnerId owner
protected final long leaseMillis
protected final long retryFrequencyMillis
protected final long stopTryingAfterMillis
protected volatile java.time.LocalDateTime expiresAt
public Lock(io.flamingock.internal.util.id.RunnerId owner,
LockKey lockKey,
long leaseMillis,
long stopTryingAfterMillis,
long retryFrequencyMillis,
LockService lockService,
io.flamingock.internal.util.TimeService timeService)
public final void ensure()
throws LockException
LockException - if it cannot be ensured. Either is expired or, close to be expired and cannot be extended.public final boolean extend()
throws LockException
LockException - if there is any problem refreshing the lock or it's not acquired at all.public final void release()
public java.time.LocalDateTime expiresAt()
protected final void updateLease(long leaseMillis)
public final boolean isExpired()
public java.lang.String toString()
toString in class java.lang.Objectprotected void handleLockException(boolean acquiringLock,
java.time.Instant shouldStopTryingAt,
LockServiceException ex)
protected void waitForLock(java.time.LocalDateTime expiresAt)