   'phpDocumentor\Descriptor\FileDescriptor * hash b228701a03895c5f54ccf2ba8e5f0be2 * pathPools/AsynPoolManager.php	 * source<?php
/**
 * 异步连接池管理器
 *
 * @author tmtbe
 * @author camera360_server@camera360.com
 * @copyright Chengdu pinguo Technology Co.,Ltd.
 */

namespace PG\MSF\Pools;

use PG\MSF\Marco;
use PG\MSF\MSFServer;

/**
 * Class AsynPoolManager
 * @package PG\MSF\Pools
 */
class AsynPoolManager
{
    /**
     * @var MSFServer server运行实例
     */
    protected $swooleServer;

    /**
     * @var \swoole_process 连接池进程
     */
    protected $process;

    /**
     * @var array 已注册连接池
     */
    protected $registerDir = [];

    /**
     * @var bool 采用进程通讯，默认每个进程都启用进程池
     */
    protected $notEventAdd = false;

    /**
     * AsynPoolManager constructor.
     *
     * @param \swoole_process $process 进程对象
     * @param MSFServer $swooleServer Server运行实例
     */
    public function __construct($process, $swooleServer)
    {
        $this->process      = $process;
        $this->swooleServer = $swooleServer;
    }

    /**
     * 采用额外进程的方式
     *
     * @return $this
     */
    public function eventAdd()
    {
        $this->notEventAdd = false;
        swoole_event_add($this->process->pipe, [$this, 'getPipeMessage']);

        return $this;
    }

    /**
     * 不采用进程通讯，每个进程都启用进程池
     *
     * @return $this
     */
    public function noEventAdd()
    {
        $this->notEventAdd = true;

        return $this;
    }

    /**
     * 算是管道消息
     *
     * @param int $pipe 管道文件描述符号
     * @return $this
     */
    public function getPipeMessage($pipe)
    {
        $read = $this->process->read();
        $data = unserialize($read);
        $asyn = $this->registerDir[$data['asyn_name']];
        $asyn->execute($data);

        return $this;
    }

    /**
     * 分发消息
     *
     * @param array $data 待分发数据
     * @return $this
     */
    public function distribute($data)
    {
        $asyn = $this->registerDir[$data['asyn_name']];
        $asyn->distribute($data);

        return $this;
    }

    /**
     * 注册异步连接池
     *
     * @param IAsynPool $asyn 连接池对象
     * @return $this
     */
    public function registerAsyn(IAsynPool $asyn)
    {
        $this->registerDir[$asyn->getAsynName()] = $asyn;
        $asyn->serverInit($this->swooleServer, $this);

        return $this;
    }

    /**
     * 写入管道
     *
     * @param IAsynPool $asyn 连接池对象
     * @param mixed $data 写入数据
     * @param int $workerId worker进程ID
     * @return $this
     */
    public function writePipe(IAsynPool $asyn, $data, $workerId)
    {
        if ($this->notEventAdd) {
            $asyn->execute($data);
        } else {
            $data['asyn_name'] = $asyn->getAsynName();
            $data['worker_id'] = $workerId;
            //写入管道
            $this->process->write(serialize($data));
        }

        return $this;
    }

    /**
     * 分发消息给worker
     *
     * @param IAsynPool $asyn 连接池对象
     * @param mixed $data 待分发数据
     * @return $this
     */
    public function sendMessageToWorker(IAsynPool $asyn, $data)
    {
        if ($this->notEventAdd) {
            $asyn->distribute($data);
        } else {
            $workerID = $data['worker_id'];
            $message  = $this->swooleServer->packSerevrMessageBody(Marco::MSG_TYPR_ASYN, $data);
            $this->swooleServer->server->sendMessage($message, $workerID);
        }

        return $this;
    }
}
 * namespaceAliases#phpDocumentor\Descriptor\Collection * itemsMarco\PG\MSF\Marco	MSFServer\PG\MSF\MSFServer * includes	  * constants	  * functions	 
 * classes	\PG\MSF\Pools\AsynPoolManager(phpDocumentor\Descriptor\ClassDescriptor	 * parent * implements	  * abstract * final	  * properties	swooleServer+phpDocumentor\Descriptor\PropertyDescriptor" * types 
 * default 	 * static * visibility	protected * fqsen+\PG\MSF\Pools\AsynPoolManager::swooleServer * name * namespace 
 * package
 * summary * description * fileDescriptor  * line * tags	var	 *phpDocumentor\Descriptor\Tag\VarDescriptor * variableName	 3phpDocumentor\Descriptor\Type\UnknownTypeDescriptor""*&server运行实例	 * errors	 /	  * inheritedElement process"   &\PG\MSF\Pools\AsynPoolManager::process"1# $%&' ()	*	 +,	 -"\swoole_process"*&连接池进程/	 /	 0 registerDir" array() *\PG\MSF\Pools\AsynPoolManager::registerDir"5# $%&' (")	*	 +,	 -"array"*&已注册连接池/	 /	 0 notEventAdd" false *\PG\MSF\Pools\AsynPoolManager::notEventAdd":# $%&' (')	*	 +,	 /phpDocumentor\Descriptor\Type\BooleanDescriptor "*&9采用进程通讯，默认每个进程都启用进程池/	 /	 0 
 * methods	__construct)phpDocumentor\Descriptor\MethodDescriptor"public * arguments	$process+phpDocumentor\Descriptor\ArgumentDescriptor	 * method"H	 -"3  * byReference * isVariadic "D# $%&进程对象' ( )	 /	 0 $swooleServerEF"H	 -" GH "J# $%&Server运行实例' ( )	 /	 0  ,\PG\MSF\Pools\AsynPoolManager::__construct()"@# $%AsynPoolManager constructor.&' (/)	param	 ,phpDocumentor\Descriptor\Tag\ParamDescriptor,D"L"N&I/	 O,J"T"N&K/	 return	 /	 0 eventAddA"BC	  )\PG\MSF\Pools\AsynPoolManager::eventAdd()"Q# $%采用额外进程的方式&' (:)	P	 -phpDocumentor\Descriptor\Tag\ReturnDescriptor	 -"$this"P&/	 N	 /	 0 
noEventAddA"BC	  +\PG\MSF\Pools\AsynPoolManager::noEventAdd()"V# $%6不采用进程通讯，每个进程都启用进程池&' (G)	P	 T	 -"U"P&/	 N	 /	 0 getPipeMessageA"BC	$pipeEF"	 /phpDocumentor\Descriptor\Type\IntegerDescriptor  GH "Z# $%&管道文件描述符号' ( )	 /	 0  /\PG\MSF\Pools\AsynPoolManager::getPipeMessage()"Y# $%算是管道消息&' (T)	N	 O,Z""N&\/	 P	 T	 -"U"P&/	 /	 0 
distributeA"BC	$dataEF"	 -"8 GH "`# $%&待分发数据' ( )	 /	 0  +\PG\MSF\Pools\AsynPoolManager::distribute()"_# $%分发消息&' (d)	N	 O,`""N&a/	 P	 T	 -"U"P&/	 /	 0 registerAsynA"BC	$asynEF"	 -"\PG\MSF\Pools\IAsynPool GH "e# $%&连接池对象' ( )	 /	 0  -\PG\MSF\Pools\AsynPoolManager::registerAsyn()"d# $%注册异步连接池&' (r)	N	 O,e""N&g/	 P	 T	 -"U"P&/	 /	 0 	writePipeA"BC	eEF"	 -"f GH "e# $%&g' ( )	 /	 0 `EF"	 -"mixed GH "`# $%&写入数据' ( )	 /	 0 	$workerIdEF"	 [  GH "m# $%&worker进程ID' ( )	 /	 0  *\PG\MSF\Pools\AsynPoolManager::writePipe()"j# $%写入管道&' ()	N	 O,e""N&g/	 O,`""N&l/	 O,m""N&n/	 P	 T	 -"U"P&/	 /	 0 sendMessageToWorkerA"BC	eEF#	 -"f GH "e# $%&g' ( )	 /	 0 `EF#	 -"k GH "`# $%&a' ( )	 /	 0  4\PG\MSF\Pools\AsynPoolManager::sendMessageToWorker()"q# $%分发消息给worker&' ()	N	 O,e#"N&g/	 O,`#"N&a/	 P	 T	 -"U"P&/	 /	 0  * usedTraits	  "AsynPoolManager#\PG\MSF\Pools$PG\MSF\Pools%Class AsynPoolManager&'" ()	package	 &phpDocumentor\Descriptor\TagDescriptor"y&w/	 
subpackage	 /	 0  * interfaces	 	 * traits	 
 * markers	  "AsynPoolManager.php# $Default%异步连接池管理器&' ( )	author	 -phpDocumentor\Descriptor\Tag\AuthorDescriptor"&tmtbe/	 "&camera360_server@camera360.com/	 	copyright	 z"&"Chengdu pinguo Technology Co.,Ltd./	 y	 z"y&/	 {	 /	 0 