改名
This commit is contained in:
+33
-33
@@ -20,7 +20,7 @@ abstract class Pool extends Component
|
||||
{
|
||||
|
||||
/** @var Channel[] */
|
||||
private array $_items = [];
|
||||
private static array $_items = [];
|
||||
|
||||
public int $max = 60;
|
||||
|
||||
@@ -29,7 +29,7 @@ abstract class Pool extends Component
|
||||
public int $lastTime = 0;
|
||||
|
||||
|
||||
protected array $hasCreate = [];
|
||||
protected static array $hasCreate = [];
|
||||
|
||||
|
||||
/**
|
||||
@@ -37,10 +37,10 @@ abstract class Pool extends Component
|
||||
*/
|
||||
public function increment(string $name)
|
||||
{
|
||||
if (!isset($this->hasCreate[$name])) {
|
||||
$this->hasCreate[$name] = 0;
|
||||
if (!isset(static::$hasCreate[$name])) {
|
||||
static::$hasCreate[$name] = 0;
|
||||
}
|
||||
$this->hasCreate[$name] += 1;
|
||||
static::$hasCreate[$name] += 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,13 +49,13 @@ abstract class Pool extends Component
|
||||
*/
|
||||
public function decrement(string $name)
|
||||
{
|
||||
if (!isset($this->hasCreate[$name])) {
|
||||
if (!isset(static::$hasCreate[$name])) {
|
||||
return;
|
||||
}
|
||||
if ($this->hasCreate[$name] <= 0) {
|
||||
if (static::$hasCreate[$name] <= 0) {
|
||||
return;
|
||||
}
|
||||
$this->hasCreate[$name] -= 1;
|
||||
static::$hasCreate[$name] -= 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ abstract class Pool extends Component
|
||||
$names[] = $name;
|
||||
$this->pop($channel, $name, $retain_number);
|
||||
}
|
||||
$this->_items = [];
|
||||
static::$_items = [];
|
||||
if ($retain_number == 0) {
|
||||
Timer::clear($this->creates);
|
||||
$this->creates = -1;
|
||||
@@ -114,10 +114,10 @@ abstract class Pool extends Component
|
||||
*/
|
||||
protected function clearCreateLog($name): void
|
||||
{
|
||||
if (!isset($this->hasCreate[$name])) {
|
||||
if (!isset(static::$hasCreate[$name])) {
|
||||
return;
|
||||
}
|
||||
$this->hasCreate[$name] = 0;
|
||||
static::$hasCreate[$name] = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -151,13 +151,13 @@ abstract class Pool extends Component
|
||||
public function initConnections($driver, $name, $isMaster = false, $max = 60)
|
||||
{
|
||||
$name = $this->name($driver, $name, $isMaster);
|
||||
if (isset($this->_items[$name]) && $this->_items[$name] instanceof Channel) {
|
||||
if (isset(static::$_items[$name]) && static::$_items[$name] instanceof Channel) {
|
||||
return;
|
||||
}
|
||||
if (Coroutine::getCid() === -1) {
|
||||
return;
|
||||
}
|
||||
$this->_items[$name] = new Channel((int)$max);
|
||||
static::$_items[$name] = new Channel((int)$max);
|
||||
$this->max = (int)$max;
|
||||
}
|
||||
|
||||
@@ -173,13 +173,13 @@ abstract class Pool extends Component
|
||||
if (Coroutine::getCid() === -1) {
|
||||
return $this->createClient($name, $callback);
|
||||
}
|
||||
if (!isset($this->_items[$name])) {
|
||||
$this->_items[$name] = new Channel($this->max);
|
||||
if (!isset(static::$_items[$name])) {
|
||||
static::$_items[$name] = new Channel($this->max);
|
||||
}
|
||||
if ($this->_items[$name]->isEmpty()) {
|
||||
if (static::$_items[$name]->isEmpty()) {
|
||||
$this->createByCallback($name, $callback);
|
||||
}
|
||||
$connection = $this->_items[$name]->pop();
|
||||
$connection = static::$_items[$name]->pop();
|
||||
if (!$this->checkCanUse($name, $connection)) {
|
||||
return $this->createClient($name, $callback);
|
||||
} else {
|
||||
@@ -198,7 +198,7 @@ abstract class Pool extends Component
|
||||
if ($this->creates === -1 && !is_callable($callback)) {
|
||||
$this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection']);
|
||||
}
|
||||
$this->_items[$name]->push($this->createClient($name, $callback));
|
||||
static::$_items[$name]->push($this->createClient($name, $callback));
|
||||
}
|
||||
|
||||
|
||||
@@ -251,10 +251,10 @@ abstract class Pool extends Component
|
||||
*/
|
||||
public function canCreate(string $name): bool
|
||||
{
|
||||
if (!isset($this->hasCreate[$name])) {
|
||||
$this->hasCreate[$name] = 0;
|
||||
if (!isset(static::$hasCreate[$name])) {
|
||||
static::$hasCreate[$name] = 0;
|
||||
}
|
||||
return $this->hasCreate[$name] < $this->max;
|
||||
return static::$hasCreate[$name] < $this->max;
|
||||
}
|
||||
|
||||
|
||||
@@ -264,8 +264,8 @@ abstract class Pool extends Component
|
||||
*/
|
||||
public function hasItem(string $name): bool
|
||||
{
|
||||
if (isset($this->_items[$name])) {
|
||||
return !$this->_items[$name]->isEmpty();
|
||||
if (isset(static::$_items[$name])) {
|
||||
return !static::$_items[$name]->isEmpty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -280,10 +280,10 @@ abstract class Pool extends Component
|
||||
if (Coroutine::getCid() === -1) {
|
||||
return 0;
|
||||
}
|
||||
if (!isset($this->_items[$name])) {
|
||||
if (!isset(static::$_items[$name])) {
|
||||
return 0;
|
||||
}
|
||||
return $this->_items[$name]->length();
|
||||
return static::$_items[$name]->length();
|
||||
}
|
||||
|
||||
|
||||
@@ -296,11 +296,11 @@ abstract class Pool extends Component
|
||||
if (Coroutine::getCid() === -1) {
|
||||
return;
|
||||
}
|
||||
if (!isset($this->_items[$name])) {
|
||||
$this->_items[$name] = new Channel($this->max);
|
||||
if (!isset(static::$_items[$name])) {
|
||||
static::$_items[$name] = new Channel($this->max);
|
||||
}
|
||||
if (!$this->_items[$name]->isFull()) {
|
||||
$this->_items[$name]->push($client);
|
||||
if (!static::$_items[$name]->isFull()) {
|
||||
static::$_items[$name]->push($client);
|
||||
}
|
||||
unset($client);
|
||||
}
|
||||
@@ -312,15 +312,15 @@ abstract class Pool extends Component
|
||||
*/
|
||||
public function clean(string $name)
|
||||
{
|
||||
if (Coroutine::getCid() === -1 || !isset($this->_items[$name])) {
|
||||
if (Coroutine::getCid() === -1 || !isset(static::$_items[$name])) {
|
||||
return;
|
||||
}
|
||||
$channel = $this->_items[$name];
|
||||
$channel = static::$_items[$name];
|
||||
$this->pop($channel, $name, 0);
|
||||
if ($this->creates > -1) {
|
||||
Timer::clear($this->creates);
|
||||
}
|
||||
$this->_items[$name] = null;
|
||||
static::$_items[$name] = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ abstract class Pool extends Component
|
||||
*/
|
||||
protected function getChannels(): array
|
||||
{
|
||||
return $this->_items;
|
||||
return static::$_items;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+7
-7
@@ -20,7 +20,7 @@ class Aop extends Component
|
||||
{
|
||||
|
||||
|
||||
private array $_aop = [];
|
||||
private static array $_aop = [];
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,13 +31,13 @@ class Aop extends Component
|
||||
{
|
||||
[$class, $method] = $handler;
|
||||
$alias = $class::class . '::' . $method;
|
||||
if (!isset($this->_aop[$alias])) {
|
||||
$this->_aop[$alias] = [];
|
||||
if (!isset(static::$_aop[$alias])) {
|
||||
static::$_aop[$alias] = [];
|
||||
}
|
||||
if (in_array($aspect, $this->_aop[$alias])) {
|
||||
if (in_array($aspect, static::$_aop[$alias])) {
|
||||
return;
|
||||
}
|
||||
$this->_aop[$alias][] = $aspect;
|
||||
static::$_aop[$alias][] = $aspect;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class Aop extends Component
|
||||
return call_user_func($handler, ...$params);
|
||||
}
|
||||
$aopName = $handler[0]::class . '::' . $handler[1];
|
||||
if (!isset($this->_aop[$aopName])) {
|
||||
if (!isset(static::$_aop[$aopName])) {
|
||||
return $this->notFound($handler, $params);
|
||||
}
|
||||
return $this->invoke($handler, $params, $aopName);
|
||||
@@ -73,7 +73,7 @@ class Aop extends Component
|
||||
*/
|
||||
private function invoke($handler, $params, $aopName): mixed
|
||||
{
|
||||
$reflect = Snowflake::getDi()->getReflect(current($this->_aop[$aopName]));
|
||||
$reflect = Snowflake::getDi()->getReflect(current(static::$_aop[$aopName]));
|
||||
if (!$reflect->isInstantiable() || !$reflect->hasMethod('invoke')) {
|
||||
throw new Exception(ASPECT_ERROR . IAspect::class);
|
||||
}
|
||||
|
||||
+4
-4
@@ -17,7 +17,7 @@ class Async extends Component
|
||||
{
|
||||
|
||||
|
||||
private array $_absences = [];
|
||||
private static array $_absences = [];
|
||||
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ class Async extends Component
|
||||
*/
|
||||
public function addAsync(string $name, Task $handler)
|
||||
{
|
||||
$this->_absences[$name] = $handler::class;
|
||||
static::$_absences[$name] = $handler::class;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,12 +42,12 @@ class Async extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->_absences[$name])) {
|
||||
if (!isset(static::$_absences[$name])) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Task $class */
|
||||
$class = new $this->_absences[$name]();
|
||||
$class = Snowflake::createObject(static::$_absences[$name]);
|
||||
$class->setParams($params);
|
||||
|
||||
$randWorkerId = random_int(0, $server->setting['task_worker_num'] - 1);
|
||||
|
||||
+12
-13
@@ -18,7 +18,7 @@ class Channel extends Component
|
||||
{
|
||||
|
||||
|
||||
private array $_channels = [];
|
||||
private static array $_channels = [];
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,10 +42,10 @@ class Channel extends Component
|
||||
*/
|
||||
private function channelInit(string $name = ''): bool|SplQueue
|
||||
{
|
||||
if (!isset($this->_channels[$name]) || !($this->_channels[$name] instanceof SplQueue)) {
|
||||
$this->_channels[$name] = new SplQueue();
|
||||
if (!isset(static::$_channels[$name]) || !(static::$_channels[$name] instanceof SplQueue)) {
|
||||
static::$_channels[$name] = new SplQueue();
|
||||
}
|
||||
return $this->_channels[$name];
|
||||
return static::$_channels[$name];
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class Channel extends Component
|
||||
public function cleanAll()
|
||||
{
|
||||
/** @var SplQueue $channel */
|
||||
foreach ($this->_channels as $channel) {
|
||||
foreach (static::$_channels as $channel) {
|
||||
if (!($channel instanceof SplQueue)) {
|
||||
continue;
|
||||
}
|
||||
@@ -64,16 +64,15 @@ class Channel extends Component
|
||||
$channel->dequeue();
|
||||
}
|
||||
}
|
||||
$this->_channels = [];
|
||||
static::$_channels = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $timeout
|
||||
* @param Closure $closure
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param Closure $closure
|
||||
* @return mixed
|
||||
*/
|
||||
public function pop(string $name, Closure $closure): mixed
|
||||
{
|
||||
$channel = $this->channelInit($name);
|
||||
|
||||
Reference in New Issue
Block a user