AnimationSink

The destination for AnimationEvents produced during a simulation run.

The model holds a single sink (reached as model.animationSink, decision D1). When animation is not configured the sink is NullAnimationSink, whose isActive is false.

Every emission site in the simulation follows the same guarded pattern so that no event object is constructed when animation is off (requirement F4):

val sink = model.animationSink
if (sink.isActive) sink.emit(AnimationEvent.DelayStarted(time, id, duration, arrival))

Because NullAnimationSink.isActive is a constant false, the JIT can elide the guarded block entirely, making disabled animation effectively free.

The lifecycle callbacks (onReplicationStart, onReplicationEnd, onExperimentEnd) let a sink manage per-run resources — for example, MemoryBufferedAnimationSink flushes accumulated events on onReplicationEnd, and an asynchronous sink closes its writer on onExperimentEnd (requirement F12). They default to no-ops so simple sinks need not implement them.

Threading note: emit is called on the simulation thread. Implementations that hand work to another thread are responsible for their own safe publication.

Inheritors

Properties

Link copied to clipboard
abstract val isActive: Boolean

Whether this sink is collecting events. Emission sites must check this before building and emitting an event. A false value must be a cheap, branch-predictable constant.

Functions

Link copied to clipboard
abstract fun emit(event: AnimationEvent)

Records event. Called only when isActive is true. Must not throw on the simulation thread; implementations should fail soft (e.g. drop and log) rather than disrupt the run.

Link copied to clipboard
open fun onExperimentEnd()

Called once after the final replication of the experiment.

Link copied to clipboard
open fun onReplicationEnd(replicationNumber: Int)

Called at the end of replication replicationNumber (1-based).

Link copied to clipboard
open fun onReplicationStart(replicationNumber: Int)

Called at the start of replication replicationNumber (1-based).