Lines 91.66% 11 / 12
Methods 80.00% 4 / 5
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 workerSpawned 100.00% 6 / 6 100.00% 1 / 1 2
 workerMessage 100.00% 1 / 1 100.00% 1 / 1 1
 workerGone 100.00% 3 / 3 100.00% 1 / 1 1
 workerQuarantined 0.00% 0 / 1 0.00% 0 / 1 2
14final readonly class BrokerWorkerEvents implements WorkerPoolListener
15{
16    public function __construct(
17        private HaSession $session,
18        private ExposureLink $exposures,
19        private BootstrapMessageFactory $bootstrapMessageFactory,
20        private ConnectionTracker $connection,
21        private WorkerMessageDispatcher $messages,
22        private SubscriptionRegistry $registry,
23        private ExposureReconciler $reconciler,
24        private ExposureCommandRouter $commandRouter,
25    ) {}
26
27    public function workerSpawned(WorkerHandle $handle): void
28    {
29        $snapshot = $this->session->snapshotStateCache();
30
31        $handle->send($this->bootstrapMessageFactory->createBootstrapMessage($handle, $this->session));
32        $handle->send($this->session->snapshotRegistry()->toRegistrySnapshot());
33        $handle->send(new StateSnapshot($snapshot->states, $snapshot->revision));
34
35        if ($this->connection->lastLoss !== null) {
36            $handle->send($this->connection->lastLoss);
37        }
38    }
39
40    public function workerMessage(WorkerHandle $handle, WorkerMessage $message): void
41    {
42        $this->messages->dispatch($handle, $message);
43    }
44
45    public function workerGone(WorkerHandle $handle, string $reason): void
46    {
47        $this->registry->removeWorkerSubscriptions($handle->id);
48        $this->exposures->orphanExposuresOfWorker($handle->id);
49        $this->commandRouter->failCommandsOf($handle->id);
50    }
51
52    public function workerQuarantined(WorkerSlot $slot): void
53    {
54        $this->reconciler->recordWorkerQuarantined($slot->workerId);
55    }
56}