AgentSignal

class AgentSignal(val name: String = "AgentSignal")(source)

A broadcast trigger that statecharts can listen for. Unlike AgentMessage (point-to-point) and onCondition (a predicate tested in the C-phase), a signal is an explicit notification fired by user code — typically at the end of a transition, a phase change, or an externally-driven schedule event.

A signal is a POJO: not a ModelElement, no automatic lifecycle. Create one wherever it's convenient (typically as a property of the AgentModel), share it across as many states and statecharts as needed, and call fire when the event occurs.

Subscriptions are managed automatically by the statechart runtime: states with onSignal(s) { ... } subscribe when entered and unsubscribe on exit (including via stop() at end-of-replication). Users do not interact with the subscriber list directly.

Differences from KSL's ksl.modeling.entity.Signal:

  • That one is a ModelElement that holds suspended entities and resumes them. It's a process-view primitive.

  • This one is a statechart broadcast — observers, not coroutines. A process waits for it through its trigger in waitForFirst, alone or with other triggers and a time limit; waitFor does not take it.

To fire one later, schedule it from the AgentModel: schedule({ signal.fire() }, t).

Parameters

name

optional display name for diagnostics

Constructors

Link copied to clipboard
constructor(name: String = "AgentSignal")

Properties

Link copied to clipboard
Link copied to clipboard

Number of currently-subscribed handlers (for diagnostics).

Functions

Link copied to clipboard
fun fire()

Fire the signal. All currently-subscribed handlers run synchronously in the order they subscribed. If a handler triggers a transition that unsubscribes (or subscribes a different handler), only handlers active at the start of fire are invoked for this call. Once the replication's events have ended (a signal fired from replicationEnded()), nothing reacts: no statechart transitions and no waiting process resumes.

Link copied to clipboard

A trigger for waitForFirst that fires when this signal is next fired. It never fires at once: a signal is an event, so the wait subscribes, and the next fire claims it, resuming the process. One fire ends the wait of every process waiting for it, as it reaches every subscribed statechart. The subscription ends with the wait, whichever trigger wins, and when the waiting process is terminated. Nothing is recorded: a signal keeps no statistics.