版权声明:转载请注明来源 https://blog.csdn.net/u013702678/article/details/82725147
这篇文章我们继续分析BaseServer的启动相关的方法,这里先分析BaseServer的initRunTime方法,这里很多都是前面配置信息设置到BaseServer对象的属性中,字段也比较明确,不再展开太具体的分析。
//初始化运行环境,runPath值为/var/fsof/provider
public function initRunTime($runPath)
{
if (!empty($runPath))
{
$this->runPath = $runPath;
}
//记录master进程号和manager进程号
$this->masterPidFile = $this->runPath.DIRECTORY_SEPARATOR.$this->processName.'.master.pid';
$this->managerPidFile = $this->runPath.DIRECTORY_SEPARATOR.$this->processName.'.manager.pid';
FileSystemUtil::makeDir(dirname($this->masterPidFile));
//获取app的服务信息
$services = isset($this->config['service_providers']) ? $this->config['service_providers'] : array();
if (empty($services))
{
$this->logger->error($this->processName.".provider's service_providers is empty");
exit(1);
}
foreach($services as $interface => $serviceInfo)
{
$this->serverProviders[$interface] = $serviceInfo;
}
$this->logger->info("services list:" . json_encode($this->serverProviders));
//增加application, language, environment, set, owner, group信息等信息
$this->config["service_properties"]["application"] = $this->processName;
$this->config["service_properties"]["language"] = "php";
//$this->config["service_properties"]["application_version"] = $this->deployVersion;
if (empty($this->config["service_properties"]["owner"]))
{
$this->config["service_properties"]["owner"] = $this->processName;
}
//swoole setting
$runSetting = isset($this->config['setting']) ? $this->config['setting'] : array();
$this->setting = array_merge($this->setting, $runSetting);
//过载保护配置
//是否加载provider过载机制
if (isset($this->setting['overload_mode']))
{
$this->config['fsof_setting']['overload_mode'] = $this->setting['overload_mode'];
}
else
{
$this->config['fsof_setting']['overload_mode'] = isset($this->config['fsof_setting']['overload_mode'])?$this->config['fsof_setting']['overload_mode']:true;
}
//加载provider过载时间
if (isset($this->setting['waiting_time']))
{
$this->config['fsof_setting']['waiting_time'] = $this->setting['waiting_time'];
}
else
{
$this->config['fsof_setting']['waiting_time'] = isset($this->config['fsof_setting']['waiting_time'])?$this->config['fsof_setting']['waiting_time']:self::FSOF_SWOOLE_WAITING_TIME_MS;
}
//加载连续过载次数
if (isset($this->setting['overload_number']))
{
$this->config['fsof_setting']['overload_number'] = $this->setting['overload_number'];
}
else
{
$this->config['fsof_setting']['overload_number'] = isset($this->config['fsof_setting']['overload_number'])?$this->config['fsof_setting']['overload_number']:self::FSOF_SWOOLE_OVERLOAD_NUM_INAROW;
}
//加载连续过载后,开启丢消息模式的次数
if (isset($this->setting['loss_number']))
{
$this->config['fsof_setting']['loss_number'] = $this->setting['loss_number'];
}
else
{
$this->config['fsof_setting']['loss_number'] = isset($this->config['fsof_setting']['loss_number'])?$this->config['fsof_setting']['loss_number']:self::FSOF_SWOOLE_LOSS_NUM_INAROW;
}
if (isset($this->config["service_properties"]["p2p_mode"]))
{
$this->start_without_registry = $this->config['service_properties']['p2p_mode'];
}
else
{
if (isset($this->config['fsof_setting']['p2p_mode']))
{
$this->start_without_registry = $this->config['fsof_setting']['p2p_mode'];
}
}
//main setting
$mainSetting = isset($this->config['server']) ? $this->config['server'] : array();
// trans listener
if (isset($mainSetting['listen']))
{
$this->transListener($mainSetting['listen']);
}
if (isset($this->listen[0]))
{
$this->host = $this->listen[0]['host'] ? $this->listen[0]['host'] : $this->host;
$this->port = $this->listen[0]['port'] ? $this->listen[0]['port'] : $this->port;
unset($this->listen[0]);
}
// set user
$globalSetting = isset($this->config['fsof_container_setting']) ? $this->config['fsof_container_setting'] : array();
if (isset($globalSetting['user']))
{
$this->user = $globalSetting['user'];
}
}