2022-01-09 03:49:02 +08:00
|
|
|
<?php
|
|
|
|
|
|
2022-01-10 11:39:55 +08:00
|
|
|
namespace Kiri\Server\Handler;
|
2022-01-09 03:49:02 +08:00
|
|
|
|
2022-06-16 17:38:22 +08:00
|
|
|
use Kiri;
|
2022-01-09 03:49:02 +08:00
|
|
|
use Kiri\Annotation\Inject;
|
|
|
|
|
use Kiri\Events\EventDispatch;
|
2022-06-16 17:38:22 +08:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2022-01-09 03:49:02 +08:00
|
|
|
use ReflectionException;
|
2022-01-10 11:39:55 +08:00
|
|
|
use Kiri\Server\Abstracts\Server;
|
2022-01-09 03:49:02 +08:00
|
|
|
use Kiri\Exception\ConfigException;
|
2022-01-10 11:39:55 +08:00
|
|
|
use Kiri\Server\Events\OnManagerStart;
|
|
|
|
|
use Kiri\Server\Events\OnManagerStop;
|
2022-01-09 03:49:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class OnServerManager
|
|
|
|
|
* @package Server\Manager
|
|
|
|
|
*/
|
|
|
|
|
class OnServerManager extends Server
|
|
|
|
|
{
|
|
|
|
|
|
2022-06-16 17:38:22 +08:00
|
|
|
/**
|
|
|
|
|
* @param EventDispatch $dispatch
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(public EventDispatch $dispatch)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
2022-01-09 03:49:02 +08:00
|
|
|
|
|
|
|
|
/**
|
2022-06-16 17:38:22 +08:00
|
|
|
* @param \Swoole\Server $server
|
|
|
|
|
* @throws ConfigException
|
|
|
|
|
* @throws ContainerExceptionInterface
|
2022-09-23 18:55:45 +08:00
|
|
|
* @throws NotFoundExceptionInterface|ReflectionException
|
2022-01-09 03:49:02 +08:00
|
|
|
*/
|
|
|
|
|
public function onManagerStart(\Swoole\Server $server)
|
|
|
|
|
{
|
2022-06-23 01:18:19 +08:00
|
|
|
Kiri::setProcessName(sprintf('manger process[%d]', $server->manager_pid));
|
2022-01-09 03:49:02 +08:00
|
|
|
|
2022-06-16 17:38:22 +08:00
|
|
|
$this->dispatch->dispatch(new OnManagerStart($server));
|
2022-01-09 03:49:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \Swoole\Server $server
|
2022-09-23 18:55:45 +08:00
|
|
|
* @return void
|
2022-06-16 17:38:22 +08:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
|
* @throws NotFoundExceptionInterface
|
2022-09-23 18:55:45 +08:00
|
|
|
* @throws ReflectionException
|
2022-01-09 03:49:02 +08:00
|
|
|
*/
|
2022-09-23 18:55:45 +08:00
|
|
|
public function onManagerStop(\Swoole\Server $server): void
|
2022-01-09 03:49:02 +08:00
|
|
|
{
|
2022-06-16 17:38:22 +08:00
|
|
|
$this->dispatch->dispatch(new OnManagerStop($server));
|
2022-01-09 03:49:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|