Lease

interface Lease

A Lease is a cluster-wide, time-based lock on a given resource. Leases are retrieved via LeaseManager.requestLease.

It should be assumed that calls to checkHeld, acquire and release could invoke remote calls, so consider usage carefully.

Inheritors

Types

Link copied to clipboard

Properties

Link copied to clipboard
abstract val name: String

Functions

Link copied to clipboard
abstract fun acquire(): Boolean

Attempts to acquire the lock on the lease. If the lock was not already held and the lock was successfully obtained, listeners should be notified.

open fun acquire(options: AcquireOptions): Boolean

Attempts to acquire the lock on the lease with options. Implementations that do not support the requested options should fail rather than silently falling back to weaker acquire semantics, unless AcquireOptions.unsupportedWaitBehavior allows fallback.

Link copied to clipboard
abstract fun addListener(listener: Lease.StateChangeListener)

Registers a listener that is called on lease state changes.

Link copied to clipboard
abstract fun isHeld(): Boolean

Check if this process owns the lease.

Link copied to clipboard
abstract fun release(): Boolean

Release the lock on the lease. This will return true if released. Note that it will return false if the lease was not held. Listeners should be notified before the lock is released.

abstract fun release(lazy: Boolean): Boolean

Release the lock on the lease, with the option of doing it lazily if possible. This should return false if the lease was not held or if the release is lazy. Listeners should be notified before the lock is released.

Link copied to clipboard
abstract fun shouldHold(): Boolean

Check if this process should own the lease. For example, if a lease is first-come first-serve, then this process should try to own the lease, whereas a lease that uses consistent hashing should try to own if and only if it is assigned the lease.