GenericMonitor

abstract class GenericMonitor

Abstract base class providing thread-blocking wait methods backed by a Guava Monitor.

Subclasses must implement monitorSatisfied to define when the monitor's condition is met. Methods are provided to wait until the condition is true or false, with optional timeouts, interruptibility, and retry callbacks.

Guava re-evaluates monitorSatisfied only when a thread leaves the monitor or starts waiting, so a subclass must change the state that monitorSatisfied reads inside the monitor, for example with mutate. A change made outside the monitor can leave waiting threads blocked.

The retrying waits make attempts of timeout, which must be at least 1 ms, and no attempt waits past maxWait. For maxWait, Duration.INFINITE waits without limit and Duration.ZERO checks the condition once. A negative value also waits without limit, but that is deprecated and logs a warning: a computed deadline - now that has passed would otherwise block forever. Pass Duration.INFINITE for no limit; a later release will treat a negative maxWait like Duration.ZERO, as a negative waitTime already is.

Inheritors

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Whether the monitor's condition is currently satisfied. Implemented by subclasses.

Functions

Link copied to clipboard
fun waitUntil(value: Boolean)

Blocks indefinitely until the condition matches value.

fun waitUntil(value: Boolean, waitTime: Duration): Boolean

Blocks until the condition matches value or the timeout expires.

Link copied to clipboard

Blocks the current thread until monitorSatisfied returns false. This method is not interruptible.

Blocks the current thread until monitorSatisfied returns false or the timeout expires. This method is not interruptible.

Repeatedly waits for the condition to become false, invoking block on each timeout.

fun waitUntilFalse(timeout: Duration, maxWait: Duration, block: MonitorAction?): Boolean

Repeatedly waits for the condition to become false, invoking block on each timeout, up to an overall maximum wait duration.

Link copied to clipboard

Blocks the current thread until monitorSatisfied returns true. This method is not interruptible.

Blocks the current thread until monitorSatisfied returns true or the timeout expires. This method is not interruptible.

Repeatedly waits for the condition to become true, invoking block on each timeout.

fun waitUntilTrue(timeout: Duration, maxWait: Duration, block: MonitorAction?): Boolean

Repeatedly waits for the condition to become true, invoking block on each timeout, up to an overall maximum wait duration.

Link copied to clipboard

Blocks the current thread until monitorSatisfied returns true. This method can be interrupted.

Blocks the current thread until monitorSatisfied returns true or the timeout expires. This method can be interrupted.

Repeatedly waits (interruptibly) for the condition to become true, invoking block on each timeout.

Repeatedly waits (interruptibly) for the condition to become true, invoking block on each timeout, up to an overall maximum wait duration.