Agent Resource
A resource that is also an agent. Behaves like an ordinary ResourceWithQ from the seizing entity's perspective — entities pass it to seize / release from inside a process — and on top of that exposes the agent capabilities the user might want for a forklift, repair worker, or nurse:
a mailbox for receiving AgentMessage traffic, routed via the enclosing AgentModel's shared bus,
an optional AgentModel.Statechart for reactive autonomous behavior,
convenience helpers for taking the resource off-shift (goOffShift) and back on-shift (goOnShift).
AgentResource sits in the permanent tier of agents — it is a ResourceWithQ, which is a ksl.simulation.ModelElement, so instances must be constructed before simulate() runs. Its statechart lifecycle is driven by its own initialize() / afterReplication() hooks rather than by AgentModel's registry.
Note that AgentResource is intentionally not an AgentModel.Agent subclass — it's-a Resource first. The AgentLike interface gives it the same mailbox/statechart capabilities without forcing the inheritance.
Per-request decisions (shouldGrant / refuse) are not in this version: the cleanest hook for that intercepts inside ProcessModel's seize implementation, which is out of scope. The on/off-shift pattern (capacity manipulation) covers most of the practical refusal use cases — an off-shift resource cannot be newly seized, and in-flight allocations finish naturally.
Parameters
the enclosing AgentModel (needed for mailbox / statechart machinery; passed explicitly so AgentResource can be parented to it)
optional name for the resource
initial capacity (also the on-shift capacity to restore after returning from a break)
optional shared request queue; if null a private one is created
Inheritors
Constructors
Types
Mutable global defaults for AgentResource construction.
Properties
The current simulation time, exposed via AgentLike so statechart actions can read it without reaching for time on the outer model element.
Whether the resource is currently off-shift (taken off via goOffShift).
Default mailbox for receiving AgentMessage traffic. Routes via the enclosing AgentModel's shared bus.
The capacity this resource has when on-shift. Captured at construction so goOnShift can restore it after a break.
Optional performance observer attached to this resource's mailbox (and statechart, if one is configured). Created by collectPerformance; null otherwise.
Optional statechart governing this resource's reactive behavior. Configured via statechart and started automatically at replication initialization by this resource's own initialize() hook.
Functions
It is essential that subclasses that override this function call the super. This ensures that suspended entities are cleaned up after a replication
Build a statechart without installing it. See AgentModel.Agent.buildStatechart.
Opt this resource in to mailbox-traffic and (if a statechart was configured before this call) statechart-state statistics. Must be called before simulate() runs since the returned AgentModel.AgentPerformance is a ksl.simulation.ModelElement. Idempotent — a second call returns the existing observer.
Take the resource off-shift indefinitely. New seize requests wait in the request queue until goOnShift; in-flight allocations finish normally under the current ksl.modeling.entity.Resource.capacityChangeRule (IGNORE by default).
Bring the resource back on-shift, restoring its onShiftCapacity. Any requests waiting in the resource's request queue are notified per the capacity-change rule.
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
Declare and install this resource's statechart in one step. May be called at most once; a second call throws. Use buildStatechart + useStatechart for the multi-variant / design-comparison case. See AgentModel.Statechart for the DSL and semantics.
Gracefully stop this resource's statechart, if any. Idempotent.
Select the active statechart. Allowed only when the current chart (if any) is not started — between replications for a setup-time resource. The selected chart is started by this resource's initialize at the next replication. See AgentModel.Agent.useStatechart.