/** * @param RuntimeContainerInterface $runtime * @param ChannelInterface $channel * @param string[] $context * @param SystemInterface $system * @param FilesystemInterface $fs * @throws InstantiationException */ public function __construct(RuntimeContainerInterface $runtime, ChannelInterface $channel, $context, SystemInterface $system, FilesystemInterface $fs) { $this->runtime = $runtime; $this->channel = $channel; $this->system = $system; $this->fs = $fs; $this->context = $context; $this->scriptRoot = $runtime->getCore()->getDataPath() . '/autorun'; $this->fsPath = $runtime->getCore()->getDataDir() . '/storage/process/' . $runtime->getAlias() . '/manager/processes.json'; $this->processes = []; try { $this->processes = $this->selectFromStorage(); } catch (Error $ex) { throw new InstantiationException('ProcessManagerBase could not be initialized.', $ex); } catch (Exception $ex) { throw new InstantiationException('ProcessManagerBase could not be initialized.', $ex); } }
/** * @override * @inheritDoc */ public function createThread($alias, $name, $flags = Runtime::CREATE_DEFAULT, $params = []) { if (isset($this->threads[$alias])) { if ($name === null) { $name = $this->threads[$alias]->name; } $manager = $this; if ($flags === Runtime::CREATE_FORCE_SOFT) { return $this->destroyThread($alias, Runtime::DESTROY_FORCE_SOFT, $params)->then(function () use($manager, $alias, $name, $params) { return $manager->createThread($alias, $name, $params); }); } else { if ($flags === Runtime::CREATE_FORCE_HARD) { return $this->destroyThread($alias, Runtime::DESTROY_FORCE_HARD, $params)->then(function () use($manager, $alias, $name, $params) { return $manager->createThread($alias, $name, $params); }); } else { if ($flags === Runtime::CREATE_FORCE) { return $this->destroyThread($alias, Runtime::DESTROY_FORCE, $params)->then(function () use($manager, $alias, $name, $params) { return $manager->createThread($alias, $name, $params); }); } else { return Promise::doReject(new ResourceOccupiedException('Thread with such alias already exists.')); } } } } else { if ($name === null) { return Promise::doReject(new InvalidArgumentException('Name of new thread cannot be null.')); } } global $loader; $controller = new ThreadController($loader); $wrapper = new ThreadWrapper($controller, $this->runtime->getCore()->getDataPath(), $this->runtime->getAlias(), $alias, $name, $this->context); $wrapper->start(PTHREADS_INHERIT_ALL); $this->allocateThread($alias, $wrapper); $req = $this->createRequest($this->channel, $alias, new RuntimeCommand('cmd:ping', $params)); return $req->call()->then(function () { return 'Thread has been created.'; }, function ($reason) use($alias) { $this->freeThread($alias); return $reason; }, function ($reason) use($alias) { $this->freeThread($alias); return $reason; }); }
/** * @param RuntimeContainerInterface $runtime * @param ChannelInterface $channel * @param SystemInterface $system * @param FilesystemInterface $fs * @throws InstantiationException */ public function __construct(RuntimeContainerInterface $runtime, ChannelInterface $channel, SystemInterface $system, FilesystemInterface $fs) { $this->runtime = $runtime; $this->channel = $channel; $this->system = $system; $this->fs = $fs; $core = $runtime->getCore(); $this->scriptRoot = $core->getDataPath() . '/autorun'; $this->fsPath = $core->getDataDir() . '/storage/project/project.json'; $this->projectRoot = 'Main'; $this->projectName = 'Main'; $this->data = $this->getEmptyStorage(); try { $this->data = $this->selectFromStorage(); } catch (Error $ex) { throw new InstantiationException('ProjectManager could not be initialized.', $ex); } catch (Exception $ex) { throw new InstantiationException('ProjectManager could not be initialized.', $ex); } }