初始化

@param MSFServer $swooleServer Server实例
@param AsynPoolManager $asynManager 异步连接池管理器
@return $this
342727
public function serverInit($swooleServer, $asynManager)
    {
        $this->swooleServer = $swooleServer;
        $this->server       = $swooleServer->server;
        $this->asynManager  = $asynManager;

        return $this;
    }
902035
protected function createServer()
    {
        $config = $this->getServerInitConfig();
        $this->swooleServer = new \swoole_websocket_server($config['host'], $config['port'], $config['mode'], $config['sockType']);
    }
606054
public function onWorkerStop(SwooleServer $server, $worker_id)
    {
        //不能在这里处理 coroutine ，所以不能使用 Yii::$app
        $contexts = Yii::$context->getContextData();
        foreach ($contexts as $context){
            /** @var Application $application */
            $application = $context[Context::COROUTINE_APP] ?? null;
            if(empty($application)){
                continue;
            }
            $targets = $application->getLog()->targets;
            foreach ($targets as $target) {
                $target->export();
            }
        }

    }
59252
public final UserManagedCacheBuilder<K, V, T> withResourcePools(ResourcePools resourcePools) {
    UserManagedCacheBuilder<K, V, T> otherBuilder = new UserManagedCacheBuilder<>(this);
    otherBuilder.resourcePools = resourcePools;
    return otherBuilder;
  }
877744
public function onFinish(SwServer $server, int $taskId, $data)
    {
        // {{
        $this->get('task')->onFinish($server, $taskId, $data);
        // }}

        // {{ log
        $this->get('logger')->info('结束任务', [
            'id' => $taskId,
            'data' => is_array($data) ? json_encode($data) : $data
        ]);
        // }}
    }
321907
public static WsByteBufferPoolManager getBufferPoolManager() {
        if (cfwBundleRef.getService() != null) {
            return cfwBundleRef.getService().getBufferManager();
        }
        return ChannelFrameworkFactory.getBufferManager();
    }
593872
public function onPacket(swoole_server $server, $data, array $clientInfo)
    {
        try {
            $this->doPacket($server, $data, $clientInfo);
        } catch (\Exception $e) {
            $content = sprintf("Error: %s\nFile: %s \n Code: %s",
                $e->getMessage(),
                $e->getFile(),
                $e->getCode()
            );
            $server->sendto($clientInfo['address'], $clientInfo['port'], $content);
        }
    }
1077842
@Override
	public ThriftServer getThriftServer(String serverName, int serverPort, TProcessor processor) {
		return new ThreadPoolThriftServerImpl(serverName, serverPort, thriftServerConfiguration, processor);
	}
624646
protected function registerSwooleQueueDriver()
    {
        $this->app->afterResolving('queue', function (QueueManager $manager) {
            $manager->addConnector('swoole', function () {
                return new SwooleTaskConnector($this->app->make(Server::class));
            });
        });
    }
700081
public function doPacket(swoole_server $server, $data, $clientInfo)
    {
        $data = Json::decode($data);
        $request = new ServerRequest($data['method'], $data['path']);
        if (isset($data['args'])) {
            if ('GET' === $request->getMethod()) {
                $request->withQueryParams($data['args']);
            } else {
                $request->withParsedBody($data['args']);
            }
        }
        $response = app()->handleRequest($request);
        $server->sendto($clientInfo['address'], $clientInfo['port'], (string) $response->getBody());
        app()->shutdown($request, $response);

        return 0;
    }
471445
public static Schedulers newThreadPoolScheduler(int poolSize) {
        createSingleton();
        Schedulers.increaseNoOfSchedullers();
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        CustomizableThreadFactory factory = new CustomizableThreadFactory();
        scheduler.initializeExecutor(factory, new RejectedExecutionHandler() {
            @Override
            public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                System.out.println("asdsa");
            }
        });
        scheduler.setPoolSize(poolSize);
        instance.setCurrentScheduler(scheduler);
        return instance;
    }
287992
public function onWorkerStop(SwServer $server, int $workerId)
    {
        $workerType = $server->taskworker ? 'task' : 'worker';

        // {{ log
        $this->get('logger')->info('结束 Worker 进程', [
            'id' => $workerId,
            'type' => ucfirst($workerType)
        ]);
        // }}

        if ($workerType === 'worker') {
            $this->shutdownWorkerStartItems();
            $this->callProtocolMethod('onStop', $server, $workerId);
        }

        unset($workerType);
    }
228888
public function onManagerStart(swoole_server $server)
    {
        process_rename($this->getName() . ' manager');

        $this->console(sprintf('Server Manager[<info>%s</info>] is started', $server->manager_pid), OutputInterface::VERBOSITY_DEBUG);
    }
837981
@Override
	public synchronized ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
    {
        checkNotClosed();
        throw new FFMQException("Unsupported feature","UNSUPPORTED_FEATURE");
    }
1027104
function setServiceManagerConfig(array $smConfig)
    {
        if ($this->sm instanceof ServiceLocatorInterface)
            throw new \Exception(
                'Service Config is used on first time instancing, '
                .'Service Manager is configured for now you must use "getServiceManager()"'
            );

        $this->def_sm_config = Core\array_merge(
            $this->def_sm_config
            , $smConfig
        );

        return $this;
    }
459136
protected function setSwooleServerListeners()
    {
        foreach ($this->events as $event) {
            $listener = Str::camel("on_$event");
            $callback = method_exists($this, $listener) ? [$this, $listener] : function () use ($event) {
                $this->container->event->trigger("swoole.$event", func_get_args());
            };

            $this->container->make(Server::class)->on($event, $callback);
        }
    }
642924
protected function createSubServer()
    {
        $config = $this->getServerInitConfig();
        $this->swooleServer = ServerManage::getServer('main')->getSwooleServer();
        $this->swoolePort = $this->swooleServer->addListener($config['host'], $config['port'], $config['sockType']);
    }