Dubbo-php-framework TcpServer parsing (five)

This begins to analyze the Run method of BaseServer, which completes the real startup of the server.

//Start the server, we assume that cmd is start, that is, analyze the initServer and start methods, where extstart and extrestart are p2p modes that do not register zk. Here you can see that only the properties are set, and the other processes are the same as start. of.
Public function run($cmd = 'help')
    {
        Switch ($cmd)
        {
            //start
Case 'extstart':
Case 'extrestart':
/ / Turn on p2p mode
$this->start_without_registry = true;
            Case 'start':
            Case 'restart':
                $this->initServer();
                $this->start();
                Break;
            Default:
                Echo 'Usage: app_admin.php start | stop | reload | restart | extstart | extrestart' . PHP_EOL;
                Break;
        }
    }
private function initServer()
    {
        // Creating a swoole server resource object
        $swooleServerName = '\swoole_server';
        $this->sw = new $swooleServerName($this->host, $this->port, $this->mode, $this->sockType);
        
        //create monitor
    $monitor = new AppMonitor($this->processName, $this->config);
        / / Set appMonitor
        $monitor->setServer($this->sw);
        $this->sw->appMonitor = $monitor;

/ / Create an overload monitor
$this->overloadMonitor = new OverloadMonitor($this->processName);

        / / Fault tolerance processing of integers
$this->setting['worker_num'] = intval($this->setting['worker_num']);
        $this->setting['dispatch_mode'] = intval($this->setting['dispatch_mode']);
        $this->setting['daemonize'] = intval($this->setting['daemonize']);

        // Setting the runtime parameters
        $this->sw->set($this->setting);

        // Set Event Server callback function
        $this->sw->on('Start', array($this, 'onMasterStart'));
        $this->sw->on('ManagerStart', array($this, 'onManagerStart'));
        $this->sw->on('ManagerStop', array($this, 'onManagerStop'));
        $this->sw->on('WorkerStart', array($this, 'onWorkerStart'));
        $this->sw->on('Connect', array($this, 'onConnect'));
        $this->sw->on('Receive', array($this, 'onReceive'));
        $this->sw->on('Close', array($this, 'onClose'));
        $this->sw->on('WorkerStop', array($this, 'onWorkerStop'));
        //$this->sw->on('timer', array($this, 'onTimer'));
        If (isset($this->setting['task_worker_num']))
        {
            $this->sw->on('Task', array($this, 'onTask'));
            $this->sw->on('Finish', array($this, 'onFinish'));
        }
$this->sw->on('WorkerError', array($this, 'onWorkerError'));

        // add listener
        If (is_array($this->listen))
        {
            Foreach($this->listen as $v)
            {
                If (empty($v['host']) || empty($v['port']))
                {
                    Continue;
                }
                $this->sw->addlistener($v['host'], $v['port'], $this->sockType);
            }
        }
        $this->logger->info("server host:".$this->host.'|'.$this->port);
    }
protected function start()
    {
       	if ($this->checkServerIsRunning()) 
       	{
            $this->logger->warn($this->processName . ": master process file " . $this->masterPidFile . " has already exists!");
            $this->logger->warn($this->processName . ": start [OK]");
          	return false;
       	}

        $this->logger->info($this->processName . ": start [OK]");
        $this->sw->start();
    }