modify plugin name

This commit is contained in:
2022-06-08 17:19:32 +08:00
parent 2a6b2a1979
commit 8f9de7a508
4 changed files with 39 additions and 13 deletions
+32 -3
View File
@@ -3,12 +3,14 @@
namespace Kiri\Rpc;
use Exception;
use Kiri\Abstracts\Component;
use Kiri\Context;
use Kiri\Exception\ConfigException;
use Kiri;
use Kiri\Abstracts\Component;
use Kiri\Annotation\Inject;
use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException;
use Kiri\Pool\Alias;
use Kiri\Pool\Pool;
use Kiri\Server\Events\OnBeforeShutdown;
use Swoole\Client;
@@ -32,6 +34,31 @@ class ClientPool extends Component
public int $waite;
#[Inject(EventProvider::class)]
public EventProvider $provider;
private array $names = [];
public function init()
{
$this->provider->on(OnBeforeShutdown::class, [$this, 'onBeforeShutdown']);
}
/**
* @return void
* @throws Exception
*/
public function onBeforeShutdown()
{
foreach ($this->names as $name) {
$this->getPool()->clean($name);
}
}
/**
* @param $config
* @param callable $callback
@@ -45,6 +72,8 @@ class ClientPool extends Component
$pool = $config['pool'] ?? ['min' => 1, 'max' => 100];
$this->names[] = $coroutineName;
return $this->getPool()->get($coroutineName, $callback, $pool['min'] ?? 1);
}
+1 -1
View File
@@ -44,7 +44,7 @@ class JsonRpcPoolTransporter implements RpcClientInterface
$client = $this->getClient();
$response = $this->request($client, $content, false);
$response = $this->request($client, $content);
$this->pool->push($client, $this->config['Address'], $this->config['Port']);
+4 -2
View File
@@ -28,9 +28,11 @@ class JsonRpcTransporter implements RpcClientInterface
{
$content = $request->getBody()->getContents();
$response = $this->request($this->newClient(), $content, true);
$body = $this->request($this->newClient(), $content);
return (new Response())->withBody(new Stream($response));
$response = \Kiri::getDi()->get(ResponseInterface::class);
return $response->withBody(new Stream($body));
}
+2 -7
View File
@@ -32,17 +32,12 @@ trait TraitTransporter
/**
* @param Client|Coroutine\Client $client
* @param $content
* @param bool $isClose
* @return mixed
*/
private function request(Client|Coroutine\Client $client, $content, bool $isClose): mixed
private function request(Client|Coroutine\Client $client, $content): mixed
{
$client->send($content);
$read = $client->recv();
if ($isClose) {
$client->close();
}
return $read;
return $client->recv();
}