PermanentAgent

open inner class PermanentAgent(name: String? = null) : ModelElement, AgentLike(source)

A setup-time agent that is a ModelElement. Use when you need KSL lifecycle hooks (initialize, warmUp, afterReplication) on the agent itself, or want to own per-agent Response/TWResponse statistics. Modeled on ksl.modeling.entity.TaskProcessingSystem.TaskProcessor: a ModelElement wrapper that holds its own POJO mailbox and statechart and drives their lifecycle through its own hooks.

Must be constructed before simulate() since ModelElements cannot be added to the model while it is running.

Constructors

Link copied to clipboard
constructor(name: String? = null)

Properties

Link copied to clipboard
open override val currentTime: Double

The current simulation time. Provided here so action handlers can log or compute durations without having to reach for the owner's outer model element.

Link copied to clipboard

Default mailbox for receiving AgentMessage traffic. Routes through the enclosing AgentModel's shared message bus.

Link copied to clipboard

Optional performance observer attached to this agent's mailbox. Created by collectPerformance; null otherwise.

Link copied to clipboard
open override var statechart: AgentModel.Statechart?

Optional statechart governing this agent's reactive behavior. Default null for AgentLike implementations that don't provide a statechart abstraction. The concrete agent types (AgentModel.Agent, AgentModel.PermanentAgent, AgentResource) each override this with their own backing field.

Functions

Link copied to clipboard
protected open override fun afterReplication()

This method should be overridden by subclasses that need actions performed after each replication. It is called after replicationEnded() has been called.

Link copied to clipboard

Build a statechart without installing it. See Agent.buildStatechart. For a PermanentAgent, alternatives are typically selected via a control parameter between runs to compare designs without reconstructing the model.

Link copied to clipboard

Opt this agent in to mailbox-traffic statistics. Must be called before simulate() runs since the returned AgentPerformance is a ModelElement. Idempotent — a second call returns the existing observer.

Link copied to clipboard
protected open override fun initialize()

This method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called

Link copied to clipboard
Link copied to clipboard

Gracefully stop this agent's statechart, if any. Idempotent.

Link copied to clipboard

Select the active statechart. Allowed only when the current chart (if any) is not started — for a PermanentAgent that means between replications / simulate() calls (the chart is stopped at afterReplication). The selected chart is started by initialize at the next replication. See Agent.useStatechart.