//master-server
var Server = function(app, opts) {
this.app = app;
this.masterInfo = app.getMaster();
this.registered = {};
this.modules = [];
opts = opts || {};
opts.port = this.masterInfo.port;
opts.env = this.app.get(Constants.RESERVED.ENV);
this.closeWatcher = opts.closeWatcher;
this.masterConsole = admin.createMasterConsole(opts);
};
Server.prototype.start = function(cb) {
console.log('master-server-start=============>>>>>>');
moduleUtil.registerDefaultModules(true, this.app, this.closeWatcher);
moduleUtil.loadModules(this, this.masterConsole);
var self = this;
// start master console
this.masterConsole.start(function(err) {
if(err) {
process.exit(0);
}
moduleUtil.startModules(self.modules, function(err) {
if(err) {
utils.invokeCallback(cb, err);
return;
}
if(self.app.get(Constants.RESERVED.MODE) !== Constants.RESERVED.STAND_ALONE) {
starter.runServers(self.app);
}
utils.invokeCallback(cb);
});
});
.......监听事件 error, reconnect, disconnect,register,admin-log