0922cc1d68
- Struktur gemäß §8 (Eigentumsgrenzen), PLAN.md als normative Basis - Pflichtdokumente: STATUS.md, ERRORS.md, TEST_REPORT.md, CHANGELOG.md, ADRs - ADR-0001 Python 3.13-Pin, ADR-0002 GStreamer 1.28.6-Pin (Windows), ADR-0003 IPC TCP+MessagePack v1 - Kernpakete: hms_protocol, hms_domain, hms_parameter, hms_artnet, hms_adaptive, hms_capabilities, hms_plugin_sdk - Renderer-Spike: D3D11-Primärpfad + Dev-GL-Pfad (§36 Nr. 4-5) - Control Core: FastAPI REST + WebSocket (§36 Nr. 9) - Beispielplugins: Passthrough + Gaussian Blur (3 Adaptive-Quality- Varianten, HLSL/GLSL/GLES) - Tools: Art-Net-Emulator, Fixture-Generator (Master32/Layer64-CSV), Capability-Probe - JSON-Schemas: IPC, Plugin, Projekt, Cluster - 121 Unit-/Integrationstests grün, Ruff grün Gate 0 bleibt offen: Hardwaremessungen nur auf echter Windows-Referenz- hardware gültig (§29.7, §33).
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
"""Idempotency-Registry für wiederholbare Commands (§6.2, §23.2)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections import OrderedDict
|
|
from typing import Any
|
|
|
|
|
|
class IdempotencyRegistry:
|
|
"""Merkt sich command_id → Ergebnis; Wiederholungen liefern dasselbe Ack."""
|
|
|
|
def __init__(self, capacity: int = 4096) -> None:
|
|
if capacity <= 0:
|
|
raise ValueError("capacity must be positive")
|
|
self._capacity = capacity
|
|
self._entries: OrderedDict[str, Any] = OrderedDict()
|
|
|
|
def register(self, command_id: str) -> bool:
|
|
"""False, wenn die command_id bereits bekannt ist (Duplikat)."""
|
|
if command_id in self._entries:
|
|
self._entries.move_to_end(command_id)
|
|
return False
|
|
self._entries[command_id] = None # Ergebnis folgt mit complete()
|
|
if len(self._entries) > self._capacity:
|
|
self._entries.popitem(last=False)
|
|
return True
|
|
|
|
def complete(self, command_id: str, result: Any) -> None:
|
|
if command_id in self._entries:
|
|
self._entries[command_id] = result
|
|
self._entries.move_to_end(command_id)
|
|
|
|
def result(self, command_id: str) -> Any | None:
|
|
return self._entries.get(command_id)
|
|
|
|
def __len__(self) -> int:
|
|
return len(self._entries)
|