QueuedResource¶
Base class combining a queue with processing logic. Override handle_queued_event().
Composite entity combining queue buffering with worker logic.
QueuedResource is a convenience base class that wires together the Queue + QueueDriver + Worker pattern into a single entity. Users subclass QueuedResource and implement handle_queued_event() to define the work processing logic.
Internal structure: - Queue: Buffers incoming events according to the configured policy - QueueDriver: Polls the queue and feeds work to the worker - Worker Adapter: Internal entity that delegates to handle_queued_event()
This composition is transparent to external code. Events sent to the QueuedResource are automatically buffered and processed in order.
QueuedResource ¶
QueuedResource(
name: str,
*,
policy: QueuePolicy | None = None,
queue_name: str | None = None,
driver_name: str | None = None,
worker_name: str | None = None,
)
Bases: Entity, ABC
An entity fronted by a queue.
External events should target the resource instance directly; the resource enqueues them and processes them via its internal queue/driver.
Subclasses implement :meth:handle_queued_event as the resource's work logic.
depth
property
¶
Current queue depth (useful for :class:~happysimulator.data.probe.Probe).
set_clock ¶
Attach a simulation clock to this resource and its internal components.
handle_queued_event
abstractmethod
¶
handle_queued_event(
event: Event,
) -> (
Generator[
float | tuple[float, list[Event] | Event | None],
None,
list[Event] | Event | None,
]
| list[Event]
| Event
| None
)
Handle a dequeued work item.
Subclasses implement their server behavior here.