代码拉取完成,页面将自动刷新
//
// Created by Mingliang Chen on 18/6/20.
// illuspas[a]gmail.com
// Copyright (c) 2018 Nodemedia. All rights reserved.
//
const NodeMediaServer = require('./node_media_server');
const cluster = require('cluster');
const context = require('./node_core_ctx');
const Logger = require('./node_core_logger');
class NodeMediaCluster {
constructor(config) {
this.config = config;
}
run() {
if (cluster.isMaster) {
Logger.log(`Master ${process.pid} is running`);
const messageHandler = (msg) => {
for (let id in cluster.workers) {
cluster.workers[id].send(msg);
}
}
const newWorker = () => {
let worker = cluster.fork();
worker.on('message', messageHandler);
}
for (let i = 0; i < this.config.cluster.num; i++) {
newWorker();
}
cluster.on('exit', (worker, code, signal) => {
Logger.log(`worker ${worker.process.pid} died`);
newWorker();
});
} else {
this.nms = new NodeMediaServer(this.config);
this.nms.run();
Logger.log(`worker ${process.pid} started`);
}
}
on(eventName, listener) {
if (cluster.isWorker) {
context.nodeEvent.on(eventName, listener);
}
}
stop() {
if (cluster.isWorker) {
this.nms.stop();
}
}
}
module.exports = NodeMediaCluster
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。