AgentMailbox

open inner class AgentMailbox<M : AgentMessage>(source)

A typed mailbox that holds AgentMessage values for a single AgentLike owner.

This is a POJO inner class — not a ModelElement, not backed by a BlockingQueue. Storage is a plain ArrayDeque; suspending receives use ksl.modeling.entity.ProcessModel.Entity.Suspension directly, which is KSL's per-entity custom-suspension primitive. This means a mailbox can be constructed at any time (notably, when its owning Agent is created during a replication).

Per-mailbox queue statistics are not collected. If you need them, register a Response/TWResponse observer at setup time via PermanentAgent and update it from your own send/receive call sites.

The mailbox is unbounded: deliver never blocks. Capacity-based back-pressure can be added later if needed.

Types

Link copied to clipboard
inner class Reservation

A scoped capture of messages matching predicate. While active, a matching message delivered to this mailbox is routed into the reservation's private buffer with priority over waiters, the pending queue, and arrival listeners — so a reserved conversation (e.g. a Contract-Net round) is never seen or consumed by an unrelated receiver on the same mailbox (a statechart onMessage handler, another receiveMessage). Call release when done.

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Number of currently-registered MailboxObservers (for diagnostics).

Link copied to clipboard
Link copied to clipboard
val size: Int

Number of messages currently in the mailbox awaiting consumption.

Functions

Link copied to clipboard

Register a MailboxObserver to receive notifications on every delivery and consumption.

Link copied to clipboard
fun deliver(message: M)

Non-suspending message insertion. If a process is currently suspended in receiveMessage with a matching predicate, hand the message directly to that waiter and resume it. Otherwise queue the message in pending and fire any registered arrival listeners.

Link copied to clipboard
fun onArrival(listener: (M) -> Unit): () -> Unit

Register listener to be invoked whenever a new message is delivered to this mailbox (after queueing — i.e., not for messages that were immediately handed off to a waiter). Returns a deregister function. Used by the statechart runtime.

Link copied to clipboard

Remove a previously-registered MailboxObserver. No-op if not attached.

Link copied to clipboard
fun snapshot(): List<M>

Snapshot of the messages currently in this mailbox awaiting consumption, in arrival order. Does not remove anything. Used by the statechart runtime to re-scan when entering a new state.