Kraken\Root\Runtime\Provider\RuntimeManagerProvider::registerRuntimeSupervision PHP Method

registerRuntimeSupervision() private method

private registerRuntimeSupervision ( Kraken\Runtime\RuntimeContainerInterface $runtime, Kraken\Channel\ChannelCompositeInterface $composite, Kraken\Config\ConfigInterface $config )
$runtime Kraken\Runtime\RuntimeContainerInterface
$composite Kraken\Channel\ChannelCompositeInterface
$config Kraken\Config\ConfigInterface
    private function registerRuntimeSupervision(RuntimeContainerInterface $runtime, ChannelCompositeInterface $composite, ConfigInterface $config)
    {
        $timerCollection = new TimerCollection();
        $channel = $composite->getBus('slave');
        $keepalive = $config->get('project.tolerance.child.keepalive');
        $channel->on('disconnect', function ($alias) use($runtime, $keepalive, $timerCollection) {
            if ($keepalive <= 0) {
                return;
            }
            $timer = $runtime->getLoop()->addTimer($keepalive, function () use($alias, $runtime, $timerCollection) {
                $timerCollection->removeTimer($alias);
                $runtime->fail(new ChildUnresponsiveException("Child runtime [{$alias}] is unresponsive."), ['origin' => $alias]);
            });
            $timerCollection->addTimer($alias, $timer);
        });
        $channel->on('connect', function ($alias) use($timerCollection) {
            if (($timer = $timerCollection->getTimer($alias)) !== null) {
                $timer->cancel();
                $timerCollection->removeTimer($alias);
            }
        });
        $channel = $composite->getBus('master');
        $keepalive = $config->get('project.tolerance.parent.keepalive');
        $channel->on('disconnect', function ($alias) use($runtime, $keepalive, $timerCollection) {
            if ($keepalive <= 0) {
                return;
            }
            $timer = $runtime->getLoop()->addTimer($keepalive, function () use($alias, $runtime, $timerCollection) {
                $timerCollection->removeTimer($alias);
                $runtime->fail(new ParentUnresponsiveException("Parent runtime [{$alias}] is unresponsive."), ['origin' => $alias]);
            });
            $timerCollection->addTimer($alias, $timer);
        });
        $channel->on('connect', function ($alias) use($timerCollection) {
            if (($timer = $timerCollection->getTimer($alias)) !== null) {
                $timer->cancel();
                $timerCollection->removeTimer($alias);
            }
        });
    }