eee
This commit is contained in:
@@ -46,10 +46,7 @@ class AsyncServer implements ServerInterface
|
||||
* @param array $service
|
||||
* @param int $daemon
|
||||
* @return void
|
||||
* @throws ConfigException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFindClassException
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws
|
||||
*/
|
||||
public function initCoreServers(array $service, int $daemon = 0): void
|
||||
{
|
||||
@@ -67,7 +64,7 @@ class AsyncServer implements ServerInterface
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ReflectionException
|
||||
* @throws
|
||||
*/
|
||||
public function shutdown(): bool
|
||||
{
|
||||
@@ -83,10 +80,7 @@ class AsyncServer implements ServerInterface
|
||||
* @param SConfig $config
|
||||
* @param int $daemon
|
||||
* @return void
|
||||
* @throws ConfigException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFindClassException
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws
|
||||
*/
|
||||
private function createBaseServer(SConfig $config, int $daemon = 0): void
|
||||
{
|
||||
@@ -106,9 +100,7 @@ class AsyncServer implements ServerInterface
|
||||
* @param $config
|
||||
* @param $daemon
|
||||
* @return void
|
||||
* @throws ConfigException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws
|
||||
*/
|
||||
private function initServer($match, $config, $daemon): void
|
||||
{
|
||||
@@ -139,8 +131,7 @@ class AsyncServer implements ServerInterface
|
||||
* @param SConfig $config
|
||||
* @param int $daemon
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
* @throws
|
||||
*/
|
||||
protected function systemConfig(SConfig $config, int $daemon): array
|
||||
{
|
||||
@@ -158,9 +149,7 @@ class AsyncServer implements ServerInterface
|
||||
/**
|
||||
* @param SConfig $config
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws
|
||||
*/
|
||||
public function addListener(SConfig $config): void
|
||||
{
|
||||
@@ -177,8 +166,7 @@ class AsyncServer implements ServerInterface
|
||||
/**
|
||||
* @param SConfig $config
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws
|
||||
*/
|
||||
protected function _listenDump(SConfig $config): void
|
||||
{
|
||||
@@ -220,8 +208,7 @@ class AsyncServer implements ServerInterface
|
||||
* @param Server\Port|Server $base
|
||||
* @param array $events
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws
|
||||
*/
|
||||
private function onEventListen(Server\Port|Server $base, array $events): void
|
||||
{
|
||||
|
||||
+128
-129
@@ -26,29 +26,28 @@ class ProcessManager extends Component
|
||||
public StdoutLogger $logger;
|
||||
|
||||
|
||||
/** @var array<string, BaseProcess> */
|
||||
private array $_process = [];
|
||||
/** @var array<string, BaseProcess> */
|
||||
private array $_process = [];
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
on(OnServerBeforeStart::class, [$this, 'OnServerBeforeStart']);
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
on(OnServerBeforeStart::class, [$this, 'OnServerBeforeStart']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param OnServerBeforeStart $beforeStart
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function OnServerBeforeStart(OnServerBeforeStart $beforeStart): void
|
||||
{
|
||||
$server = Kiri::getDi()->get(ServerInterface::class);
|
||||
foreach ($this->_process as $custom) {
|
||||
public function OnServerBeforeStart(OnServerBeforeStart $beforeStart): void
|
||||
{
|
||||
$server = Kiri::getDi()->get(ServerInterface::class);
|
||||
foreach ($this->_process as $custom) {
|
||||
$server->addProcess(new Process(function (Process $process) use ($custom) {
|
||||
$this->extracted($custom, $process);
|
||||
},
|
||||
@@ -56,139 +55,139 @@ class ProcessManager extends Component
|
||||
$custom->getPipeType(),
|
||||
$custom->isEnableCoroutine()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Process[]
|
||||
*/
|
||||
public function getProcesses(): array
|
||||
{
|
||||
return $this->_process;
|
||||
}
|
||||
/**
|
||||
* @return Process[]
|
||||
*/
|
||||
public function getProcesses(): array
|
||||
{
|
||||
return $this->_process;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string|OnProcessInterface|BaseProcess $custom
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add(string|OnProcessInterface|BaseProcess $custom): void
|
||||
{
|
||||
if (is_string($custom)) {
|
||||
$custom = Kiri::getDi()->get($custom);
|
||||
}
|
||||
/**
|
||||
* @param string|OnProcessInterface|BaseProcess $custom
|
||||
* @throws
|
||||
*/
|
||||
public function add(string|OnProcessInterface|BaseProcess $custom): void
|
||||
{
|
||||
if (is_string($custom)) {
|
||||
$custom = Kiri::getDi()->get($custom);
|
||||
}
|
||||
|
||||
if (isset($this->_process[$custom->getName()])) {
|
||||
throw new Exception('Process(' . $custom->getName() . ') is exists.');
|
||||
}
|
||||
if (isset($this->_process[$custom->getName()])) {
|
||||
throw new Exception('Process(' . $custom->getName() . ') is exists.');
|
||||
}
|
||||
|
||||
$this->_process[$custom->getName()] = $custom;
|
||||
}
|
||||
$this->_process[$custom->getName()] = $custom;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function shutdown(): void
|
||||
{
|
||||
foreach ($this->_process as $process) {
|
||||
Process::kill($process->pid, 0) && Process::kill($process->pid, 15);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function shutdown(): void
|
||||
{
|
||||
foreach ($this->_process as $process) {
|
||||
Process::kill($process->pid, 0) && Process::kill($process->pid, 15);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param BaseProcess $customProcess
|
||||
* @return Closure
|
||||
*/
|
||||
public function resolve(BaseProcess $customProcess): Closure
|
||||
{
|
||||
return static function (Process $process) use ($customProcess) {
|
||||
$this->extracted($customProcess, $process);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @param BaseProcess $customProcess
|
||||
* @return Closure
|
||||
*/
|
||||
public function resolve(BaseProcess $customProcess): Closure
|
||||
{
|
||||
return static function (Process $process) use ($customProcess) {
|
||||
$this->extracted($customProcess, $process);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string|null $name
|
||||
* @param string $tag
|
||||
* @return array|Process|null
|
||||
*/
|
||||
public function get(?string $name = null, string $tag = 'default'): array|Process|null
|
||||
{
|
||||
$process = $this->_process[$tag] ?? null;
|
||||
if (empty($process)) {
|
||||
return null;
|
||||
}
|
||||
if (!empty($name)) {
|
||||
if (!isset($process[$name])) {
|
||||
return null;
|
||||
}
|
||||
return $process[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param string|null $name
|
||||
* @param string $tag
|
||||
* @return array|Process|null
|
||||
*/
|
||||
public function get(?string $name = null, string $tag = 'default'): array|Process|null
|
||||
{
|
||||
$process = $this->_process[$tag] ?? null;
|
||||
if (empty($process)) {
|
||||
return null;
|
||||
}
|
||||
if (!empty($name)) {
|
||||
if (!isset($process[$name])) {
|
||||
return null;
|
||||
}
|
||||
return $process[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function stop(): void
|
||||
{
|
||||
foreach ($this->_process as $process) {
|
||||
Process::kill($process->pid, 0) && Process::kill($process->pid, 15);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function stop(): void
|
||||
{
|
||||
foreach ($this->_process as $process) {
|
||||
Process::kill($process->pid, 0) && Process::kill($process->pid, 15);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array|null $processes
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function batch(?array $processes): void
|
||||
{
|
||||
if (empty($processes)) {
|
||||
return;
|
||||
}
|
||||
foreach ($processes as $process) {
|
||||
$this->add($process);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param array|null $processes
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function batch(?array $processes): void
|
||||
{
|
||||
if (empty($processes)) {
|
||||
return;
|
||||
}
|
||||
foreach ($processes as $process) {
|
||||
$this->add($process);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function push(string $name, string $message): void
|
||||
{
|
||||
if (!isset($this->_process[$name])) {
|
||||
return;
|
||||
}
|
||||
$process = $this->_process[$name];
|
||||
$process->write($message);
|
||||
}
|
||||
/**
|
||||
* @param string $message
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function push(string $name, string $message): void
|
||||
{
|
||||
if (!isset($this->_process[$name])) {
|
||||
return;
|
||||
}
|
||||
$process = $this->_process[$name];
|
||||
$process->write($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $custom
|
||||
* @param Process $process
|
||||
* @return void
|
||||
* @throws Kiri\Exception\ConfigException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function extracted(mixed $custom, Process $process): void
|
||||
{
|
||||
set_env('environmental', Kiri::PROCESS);
|
||||
$system = sprintf('[%s].Custom Process', \config('id', 'system-service'));
|
||||
$this->logger->alert($system . ' ' . $custom->getName() . ' start.');
|
||||
if (Kiri::getPlatform()->isLinux()) {
|
||||
$process->name($system . '[' . $process->pid . '].' . $custom->getName());
|
||||
}
|
||||
$custom->onSigterm()->process($process);
|
||||
}
|
||||
/**
|
||||
* @param mixed $custom
|
||||
* @param Process $process
|
||||
* @return void
|
||||
* @throws Kiri\Exception\ConfigException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function extracted(mixed $custom, Process $process): void
|
||||
{
|
||||
set_env('environmental', Kiri::PROCESS);
|
||||
$system = sprintf('[%s].Custom Process', \config('id', 'system-service'));
|
||||
$this->logger->alert($system . ' ' . $custom->getName() . ' start.');
|
||||
if (Kiri::getPlatform()->isLinux()) {
|
||||
$process->name($system . '[' . $process->pid . '].' . $custom->getName());
|
||||
}
|
||||
$custom->onSigterm()->process($process);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+7
-11
@@ -4,10 +4,6 @@
|
||||
namespace Kiri\Server\Abstracts;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Kiri;
|
||||
|
||||
|
||||
/**
|
||||
* Class Server
|
||||
* @package Server\Abstracts
|
||||
@@ -15,12 +11,12 @@ use Kiri;
|
||||
abstract class Server
|
||||
{
|
||||
|
||||
/**
|
||||
* Server constructor.
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Server constructor.
|
||||
* @throws
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ trait TraitServer
|
||||
private array $_process = [];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var StdoutLogger
|
||||
*/
|
||||
@@ -32,7 +31,7 @@ trait TraitServer
|
||||
/**
|
||||
* @param string|array|BaseProcess $class
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws
|
||||
*/
|
||||
public function addProcess(string|array|BaseProcess $class): void
|
||||
{
|
||||
@@ -69,7 +68,7 @@ trait TraitServer
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws
|
||||
*/
|
||||
public function onSignal(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user