view
Ask this snapshot what the engine that took it would answer, with no engine: who goes next, why a leaf is waiting, what share it is owed, and what share every group is owed (see LocalHeddleView). Changes nothing, here or anywhere.
policy is required because a snapshot does not keep one: pass the policy the engine ran with, and the view answers exactly as that engine did when it took this snapshot. It sizes totalSlots as LocalHeddle.restore does.
Throws
when policy cannot size totalSlots (see LocalHeddle.reconcileCapacity).
Samples
val tree = twoLanes()
val heavy = tree.groupId("heavy")
val light = tree.groupId("light")
val policy = LocalPolicy(defaultReservation = 3L)
val (heddle, booted) = LocalHeddle.fromTopology(tree, policy, epoch = 0L)
check(booted.refusals.isEmpty())
heddle.reconcileCapacity(totalSlots = 2L)
val stored = Json.encodeToString(LocalHeddleSnapshot.serializer(), heddle.persist())
// On the admin screen: decode the stored snapshot and view it with the engine's policy.
val decoded = LocalHeddle.decode(stored, Json)
check(decoded is RestoreResult.Restored)
val view = decoded.snapshot.view(policy)
val queued = setOf(heavy, light)
check(view.previewPicks(mapOf(heavy to 2, light to 1), eligible = queued, reservations = List(3) { 3L }) == listOf(heavy, light, heavy))
check(view.explain(heavy, waiting = queued, eligible = queued) == WaitExplanation.WouldBePickedNext)
check(view.entitlement(light, waiting = queued, totalSlots = 3L) == Rational.ONE)
// The engine gives the same answers, and asking either moved nothing.
check(heddle.previewPicks(mapOf(heavy to 2, light to 1), queued, List(3) { 3L }) == listOf(heavy, light, heavy))
check((heddle.acquire(queued, queued, startedAt = 0L) as AcquireOutcome.Acquired).lease.leaf == heavy)Content copied to clipboard