2023-08-28 12:01:30 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Kiri\Actor;
|
|
|
|
|
|
2024-09-03 14:47:30 +08:00
|
|
|
use Kiri\Server\Processes\BaseProcess;
|
2023-08-28 12:01:30 +08:00
|
|
|
use Swoole\Coroutine;
|
|
|
|
|
use Swoole\Process;
|
|
|
|
|
|
|
|
|
|
class ActorProcess extends BaseProcess
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
protected bool $enable_coroutine = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getName(): string
|
|
|
|
|
{
|
|
|
|
|
// TODO: Change the autogenerated stub
|
2024-08-29 18:06:58 +08:00
|
|
|
return 'Actor Manager';
|
2023-08-28 12:01:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function process(?Process $process): void
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement process() method.
|
|
|
|
|
while ($this->isStop() === false) {
|
|
|
|
|
$read = $process->read();
|
|
|
|
|
|
|
|
|
|
ActorManager::exec(json_decode($read, true));
|
|
|
|
|
|
|
|
|
|
Coroutine::sleep(1000 / 120);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function onSigterm(): static
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement onSigterm() method.
|
|
|
|
|
Coroutine::create(function () {
|
|
|
|
|
$sign = Coroutine::waitSignal(SIGINT | SIGTERM);
|
|
|
|
|
if ($sign) {
|
|
|
|
|
$this->onShutdown(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
}
|