This commit is contained in:
2021-10-19 15:07:02 +08:00
parent ea5b473638
commit 95b4a3e80b
5 changed files with 69 additions and 35 deletions
+1
View File
@@ -13,6 +13,7 @@ class Constant
const START = 'Start';
const SHUTDOWN = 'Shutdown';
const BEFORE_SHUTDOWN = 'beforeShutdown';
const WORKER_START = 'WorkerStart';
const WORKER_STOP = 'WorkerStop';
const WORKER_EXIT = 'WorkerExit';
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace Server\Events;
use Swoole\Server;
class OnBeforeShutdown
{
/**
* @param Server|null $server
*/
public function __construct(?Server $server = null)
{
}
}
+18 -10
View File
@@ -3,11 +3,12 @@
namespace Server\Manager;
use Annotation\Inject;
use Server\Abstracts\Server;
use Server\Events\OnShutdown;
use Server\Events\OnStart;
use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException;
use Server\Abstracts\Server;
use Server\Events\OnBeforeShutdown;
use Server\Events\OnShutdown;
use Server\Events\OnStart;
/**
@@ -25,18 +26,26 @@ class OnServer extends Server
/**
* @param \Swoole\Server $server
* @throws ConfigException
*/
* @param \Swoole\Server $server
* @throws ConfigException
*/
public function onStart(\Swoole\Server $server)
{
$this->setProcessName(sprintf('start[%d].server', $server->master_pid));
$this->setProcessName(sprintf('start[%d].server', $server->master_pid));
$this->eventDispatch->dispatch(new OnStart($server));
$this->eventDispatch->dispatch(new OnStart($server));
}
/**
* @param \Swoole\Server $server
*/
public function onBeforeShutdown(\Swoole\Server $server)
{
$this->eventDispatch->dispatch(new OnBeforeShutdown($server));
}
/**
* @param \Swoole\Server $server
*/
@@ -46,5 +55,4 @@ class OnServer extends Server
}
}
@@ -0,0 +1,8 @@
<?php
namespace Server\SInterface;
interface OnBeforeShutdown
{
}
+24 -25
View File
@@ -14,13 +14,13 @@ use Server\Manager\OnPipeMessage;
use Server\Manager\OnServer;
use Server\Manager\OnServerManager;
use Server\Manager\OnServerReload;
use Server\SInterface\OnProcessInterface;
use Server\SInterface\OnCloseInterface;
use Server\SInterface\OnConnectInterface;
use Server\SInterface\OnDisconnectInterface;
use Server\SInterface\OnHandshakeInterface;
use Server\SInterface\OnMessageInterface;
use Server\SInterface\OnPacketInterface;
use Server\SInterface\OnProcessInterface;
use Server\SInterface\OnReceiveInterface;
use Server\SInterface\OnTaskInterface;
use Server\Task\OnServerTask;
@@ -62,30 +62,29 @@ class ServerManager
const DEFAULT_EVENT = [
Constant::WORKER_START => [OnServerWorker::class, 'onWorkerStart'],
Constant::WORKER_EXIT => [OnServerWorker::class, 'onWorkerExit'],
Constant::WORKER_STOP => [OnServerWorker::class, 'onWorkerStop'],
Constant::WORKER_ERROR => [OnServerWorker::class, 'onWorkerError'],
Constant::MANAGER_START => [OnServerManager::class, 'onManagerStart'],
Constant::MANAGER_STOP => [OnServerManager::class, 'onManagerStop'],
Constant::BEFORE_RELOAD => [OnServerReload::class, 'onBeforeReload'],
Constant::AFTER_RELOAD => [OnServerReload::class, 'onAfterReload'],
Constant::START => [OnServer::class, 'onStart'],
Constant::SHUTDOWN => [OnServer::class, 'onShutdown'],
Constant::WORKER_START => [OnServerWorker::class, 'onWorkerStart'],
Constant::WORKER_EXIT => [OnServerWorker::class, 'onWorkerExit'],
Constant::WORKER_STOP => [OnServerWorker::class, 'onWorkerStop'],
Constant::WORKER_ERROR => [OnServerWorker::class, 'onWorkerError'],
Constant::MANAGER_START => [OnServerManager::class, 'onManagerStart'],
Constant::MANAGER_STOP => [OnServerManager::class, 'onManagerStop'],
Constant::BEFORE_RELOAD => [OnServerReload::class, 'onBeforeReload'],
Constant::AFTER_RELOAD => [OnServerReload::class, 'onAfterReload'],
Constant::START => [OnServer::class, 'onStart'],
Constant::BEFORE_SHUTDOWN => [OnServer::class, 'onBeforeShutdown'],
Constant::SHUTDOWN => [OnServer::class, 'onShutdown'],
];
private array $eventInterface = [
OnReceiveInterface::class => 'receive',
OnPacketInterface::class =>'packet',
OnHandshakeInterface::class => 'handshake',
OnMessageInterface::class =>'message',
OnConnectInterface::class =>'connect',
OnCloseInterface::class =>'close',
OnDisconnectInterface::class =>'disconnect'
];
private array $eventInterface = [
OnReceiveInterface::class => 'receive',
OnPacketInterface::class => 'packet',
OnHandshakeInterface::class => 'handshake',
OnMessageInterface::class => 'message',
OnConnectInterface::class => 'connect',
OnCloseInterface::class => 'close',
OnDisconnectInterface::class => 'disconnect'
];
/**
@@ -189,9 +188,9 @@ class ServerManager
}
$name = $customProcess->getProcessName($soloProcess);
if (is_enable_file_modification_listening()) {
scan_directory(directory('app'), 'App');
}
if (is_enable_file_modification_listening()) {
scan_directory(directory('app'), 'App');
}
$system = sprintf('%s.process[%d]', Config::get('id', 'system-service'), $soloProcess->pid);
if (Kiri::getPlatform()->isLinux()) {