From a1884668b9d18ffe44f912bb9ab142bd65488cf4 Mon Sep 17 00:00:00 2001 From: yf <291323003@qq.com> Date: Mon, 21 Jan 2019 19:20:04 +0800 Subject: [PATCH] up --- src/Pool/AbstractPool.php | 8 ++++---- src/Pool/Exception/PoolEmpty.php | 2 +- .../{PoolUnRegister.php => PoolException.php} | 2 +- .../{PoolNumError.php => PoolObjectNumError.php} | 2 +- src/Pool/PoolConf.php | 16 ++++++++-------- src/Pool/TraitObjectInvoker.php | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) rename src/Pool/Exception/{PoolUnRegister.php => PoolException.php} (77%) rename src/Pool/Exception/{PoolNumError.php => PoolObjectNumError.php} (75%) diff --git a/src/Pool/AbstractPool.php b/src/Pool/AbstractPool.php index efd2156..d674f1f 100644 --- a/src/Pool/AbstractPool.php +++ b/src/Pool/AbstractPool.php @@ -10,8 +10,8 @@ use EasySwoole\Component\Pool\Exception\PoolEmpty; -use EasySwoole\Component\Pool\Exception\PoolNumError; -use EasySwoole\Component\Pool\Exception\PoolUnRegister; +use EasySwoole\Component\Pool\Exception\PoolObjectNumError; +use EasySwoole\Component\Pool\Exception\PoolException; use EasySwoole\Utility\Random; use Swoole\Coroutine\Channel; @@ -31,7 +31,7 @@ public function __construct(PoolConf $conf) { if($conf->getMinObjectNum() >= $conf->getMaxObjectNum()){ $class = static::class; - throw new PoolNumError("pool max num is small than min num for {$class} error"); + throw new PoolObjectNumError("pool max num is small than min num for {$class} error"); } $this->conf = $conf; $this->poolChannel = new Channel($conf->getMaxObjectNum() + 1); @@ -198,7 +198,7 @@ public static function invoke(callable $call,float $timeout = null) throw new PoolEmpty(static::class." pool is empty"); } }else{ - throw new PoolUnRegister(static::class." pool is unregister"); + throw new PoolException(static::class." convert to pool error"); } } diff --git a/src/Pool/Exception/PoolEmpty.php b/src/Pool/Exception/PoolEmpty.php index 8db7d86..80ce5e3 100644 --- a/src/Pool/Exception/PoolEmpty.php +++ b/src/Pool/Exception/PoolEmpty.php @@ -9,7 +9,7 @@ namespace EasySwoole\Component\Pool\Exception; -class PoolEmpty extends \Exception +class PoolEmpty extends PoolException { } \ No newline at end of file diff --git a/src/Pool/Exception/PoolUnRegister.php b/src/Pool/Exception/PoolException.php similarity index 77% rename from src/Pool/Exception/PoolUnRegister.php rename to src/Pool/Exception/PoolException.php index 3427f73..ec32ff3 100644 --- a/src/Pool/Exception/PoolUnRegister.php +++ b/src/Pool/Exception/PoolException.php @@ -9,7 +9,7 @@ namespace EasySwoole\Component\Pool\Exception; -class PoolUnRegister extends \Exception +class PoolException extends \Exception { } \ No newline at end of file diff --git a/src/Pool/Exception/PoolNumError.php b/src/Pool/Exception/PoolObjectNumError.php similarity index 75% rename from src/Pool/Exception/PoolNumError.php rename to src/Pool/Exception/PoolObjectNumError.php index ef771bd..dc1020f 100644 --- a/src/Pool/Exception/PoolNumError.php +++ b/src/Pool/Exception/PoolObjectNumError.php @@ -9,7 +9,7 @@ namespace EasySwoole\Component\Pool\Exception; -class PoolNumError extends \Exception +class PoolObjectNumError extends PoolException { } \ No newline at end of file diff --git a/src/Pool/PoolConf.php b/src/Pool/PoolConf.php index 7850eca..bc1af50 100644 --- a/src/Pool/PoolConf.php +++ b/src/Pool/PoolConf.php @@ -9,6 +9,8 @@ namespace EasySwoole\Component\Pool; +use EasySwoole\Component\Pool\Exception\PoolObjectNumError; + class PoolConf { protected $class; @@ -83,12 +85,11 @@ public function getMaxObjectNum(): int return $this->maxObjectNum; } - /** - * @param int $maxObjectNum - * @return PoolConf - */ public function setMaxObjectNum(int $maxObjectNum): PoolConf { + if($this->minObjectNum >= $maxObjectNum){ + throw new PoolObjectNumError('min num is bigger than max'); + } $this->maxObjectNum = $maxObjectNum; return $this; } @@ -137,12 +138,11 @@ public function getMinObjectNum(): int return $this->minObjectNum; } - /** - * @param int $minObjectNum - * @return PoolConf - */ public function setMinObjectNum(int $minObjectNum): PoolConf { + if($minObjectNum >= $this->maxObjectNum){ + throw new PoolObjectNumError('min num is bigger than max'); + } $this->minObjectNum = $minObjectNum; return $this; } diff --git a/src/Pool/TraitObjectInvoker.php b/src/Pool/TraitObjectInvoker.php index f3ac903..a09531c 100644 --- a/src/Pool/TraitObjectInvoker.php +++ b/src/Pool/TraitObjectInvoker.php @@ -10,7 +10,7 @@ use EasySwoole\Component\Pool\Exception\PoolEmpty; -use EasySwoole\Component\Pool\Exception\PoolUnRegister; +use EasySwoole\Component\Pool\Exception\PoolException; trait TraitObjectInvoker { @@ -32,7 +32,7 @@ public static function invoke(callable $call,float $timeout = null) throw new PoolEmpty(static::class." pool is empty"); } }else{ - throw new PoolUnRegister(static::class." pool is unregister"); + throw new PoolException(static::class." convert to pool error"); } } } \ No newline at end of file