explain

fun explain(leaf: GroupId, waiting: Set<GroupId>, eligible: Set<GroupId>, reservation: Long = policy.defaultReservation): WaitExplanation

Why leaf is not, or is, what the next acquire on these same arguments picks. Changes nothing, not even the wake memory. Answered by a view of this engine's state: see LocalHeddleView.explain.

Throws

as acquire does: reservation out of range, or eligible not a subset of waiting.

when a WaitExplanation.BehindAtLevel front does not fit an exact Rational, whose numerator carries the least common multiple of the sibling weights' denominators (see "Failure surface").

Samples

val tree = twoLanes()
val root = tree.groupId()
val heavy = tree.groupId("heavy")
val light = tree.groupId("light")
val (heddle, booted) = LocalHeddle.fromTopology(tree, LocalPolicy(defaultReservation = 3L), epoch = 0L)
check(booted.refusals.isEmpty())
heddle.reconcileCapacity(totalSlots = 2L)

val queued = setOf(heavy, light)
// Light is behind at the pool: at twice the weight, heavy's turn comes due sooner.
val why = heddle.explain(light, waiting = queued, eligible = queued)
check(why is WaitExplanation.BehindAtLevel && why.parent == root && why.nextChild == heavy)
check(heddle.explain(heavy, waiting = queued, eligible = queued) == WaitExplanation.WouldBePickedNext)
check((heddle.acquire(queued, queued, startedAt = 0L) as AcquireOutcome.Acquired).lease.leaf == heavy)

// While both stay queued, heavy is owed 2 slots of every 3 and light 1.
check(heddle.entitlement(heavy, waiting = queued, totalSlots = 3L) == Rational.of(2L))
check(heddle.entitlement(light, waiting = queued, totalSlots = 3L) == Rational.ONE)
// A group with nothing queued is simply not waiting.
check(heddle.explain(light, waiting = setOf(heavy), eligible = setOf(heavy)) == WaitExplanation.NotWaiting)