ShiftControl

class ShiftControl @JvmOverloads constructor(resource: Resource, val onShiftCapacity: Int = resource.initialCapacity)(source)

Takes a resource off shift and puts it back on, by driving its capacity to zero and back.

A shift is not a new mechanism. A resource with no capacity cannot be seized and its waiting requests queue until it has some again, which is exactly what being off shift means; the capacity change rule then decides what happens to work already under way, exactly as it does for every other capacity change. What this adds is a name for that pattern, and one piece of state the pattern needs and capacity alone cannot supply.

Why the flag is kept rather than inferred from capacity == 0. A resource legitimately constructed with, or driven to, zero capacity is not off shift, and would otherwise be refused by goOffShift and silently given capacity by goOnShift. The two are different facts and are kept apart.

Held by whatever wants a shift rather than inherited from a base class, so that adding shifts to a vehicle does not add a member to every resource in every model that already exists.

Parameters

resource

the resource whose capacity is being driven

onShiftCapacity

what to restore. The resource's initial capacity by default, which is what a shift returning to normal means

Constructors

Link copied to clipboard
constructor(resource: Resource, onShiftCapacity: Int = resource.initialCapacity)

Properties

Link copied to clipboard

True while the resource has been taken off shift.

Link copied to clipboard

Functions

Link copied to clipboard

Takes the resource off shift indefinitely.

Link copied to clipboard
fun goOnShift()

Brings the resource back on shift, restoring onShiftCapacity.

Link copied to clipboard

Every replication starts on shift. Called from the owner's initialize.

Link copied to clipboard
open override fun toString(): String