/** * @param SupervisorInterface $supervisor * @param ConfigInterface $config * @throws Exception */ private function bootRemoteSupervision(SupervisorInterface $supervisor, ConfigInterface $config) { $handlers = (array) $config->get('supervision.remote.handlers'); $default = [$this->systemError('FatalError') => 'RuntimeDestroyHard', 'Error' => 'RuntimeContinue', 'Exception' => 'RuntimeContinue']; $plugins = (array) $config->get('supervision.remote.plugins'); $this->bootBaseOrRemote($supervisor, $default, $handlers, $plugins); }
/** * @param ConfigInterface $config * @param CommandFactoryInterface $factory * @param RuntimeContainerInterface $runtime * @return CommandInterface[] */ protected function getAppCommands(ConfigInterface $config, CommandFactoryInterface $factory, RuntimeContainerInterface $runtime) { $cmds = (array) $config->get('command.commands'); $commands = []; foreach ($cmds as $name => $command) { $commands[$name] = $factory->create($command, [['runtime' => $runtime]]); } return $commands; }
/** * @param RuntimeContainerInterface $runtime * @param ChannelCompositeInterface $composite * @param ConfigInterface $config */ 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); } }); }
/** * @param ConfigInterface $config * @param string $level * @param int $loggerLevel * @return HandlerInterface */ private function createHandler(ConfigInterface $config, $level, $loggerLevel) { $factory = new LoggerFactory(); $formatter = $factory->createFormatter('LineFormatter', [$config->get('log.config.messagePattern'), $config->get('log.config.datePattern'), true]); $filePermission = $config->get('log.config.filePermission'); $fileLocking = (bool) $config->get('log.config.fileLocking'); $filePath = $config->get('log.config.filePattern'); $loggerHandler = $factory->createHandler('StreamHandler', [$this->filePath($filePath, $level), $loggerLevel, false, $filePermission, $fileLocking]); $loggerHandler->setFormatter($formatter); return $loggerHandler; }
/** * @param ConfigInterface $config */ private function configure(ConfigInterface $config) { if ($config->exists('imports')) { $resources = (array) $config->get('imports'); } else { $resources = []; } foreach ($resources as $resource) { $handler = isset($resource['mode']) ? $this->getOverwriteHandler($resource['mode']) : null; $path = StringSupport::parametrize($resource['resource'], $this->getDefaultVariables()); $current = $this->createConfig($path); $this->configure($current); $config->merge($current->getAll(), $handler); } }
/** * Create Config. * * @param ConfigInterface|null $config * @return Config */ protected function createConfig(ConfigInterface $config = null) { return new Config($config === null ? [] : $config->get('project.config')); }