clearRequireCache(path: string) { const moduleObj = require.cache[path]; if (!moduleObj) { logger.warn('can not find module of truepath', path); return; } if (moduleObj.parent) { // console.log('has parent ',moduleObj.parent); moduleObj.parent.children.splice(moduleObj.parent.children.indexOf(moduleObj), 1); } delete require.cache[path]; }
// ----------------- monitor request methods ------------------------- let addServer = function (self: MonitorWatcherModule, agent: MonitorAgent, msg: any, cb: MonitorCallback) { logger.debug('[%s] receive addServer signal: %j', self.app.serverId, msg); if (!msg || !msg.server) { logger.warn('monitorwatcher addServer receive empty message: %j', msg); utils.invokeCallback(cb, Constants.SIGNAL.FAIL); return; } addServers(self, [msg.server]); utils.invokeCallback(cb, Constants.SIGNAL.OK); }
manualReloadProxies() { let servers = []; for (let k in this.client._station.servers) { servers.push(this.client._station.servers[k]) } logger.warn('manualReloadProxies servers:', servers); genProxies(this.client, this.app, servers); }
record(id: string) { if (!this.isStarted && --this.count < 0) { let usedTime = Date.now() - this.app.startTime; this.notify({ action: 'startOver' }); this.isStarted = true; logger.warn('all servers startup in %s ms', usedTime); } }
masterHandler(agent: MasterAgent, msg: any, cb: MasterCallback) { if (!msg) { logger.warn('masterwatcher receive empty message.'); return; } let func = (masterMethods as any)[msg.action]; if (!func) { logger.info('masterwatcher unknown action: %j', msg.action); return; } func(this, agent, msg, cb); }
export function manualReloadProxies(app: Application) { if (!app.components.__proxy__) { return; } if (app.components.__proxy__.manualReloadProxies) { app.components.__proxy__.manualReloadProxies(); } else { logger.warn('manualReloadProxies not method'); } }
onServerReconnect(record: any) { logger.debug('masterwatcher receive reconnect server event, with server: %j', record); if (!record || record.type === 'client' || !record.serverType) { logger.warn('onServerReconnect receive wrong message: %j', record); return; } this.watchdog.reconnectServer(record); }
clearCbTimeout(id: number) { if (!this.timeout[id]) { logger.warn('timer is not exsits, serverId: %s remote: %s, host: %s, port: %s', this.serverId, id, this.host, this.port); return; } clearTimeout(this.timeout[id]); delete this.timeout[id]; }
onServerLeave(id: string, type: string) { logger.debug('masterwatcher receive remove server event, with server: %s, type: %s', id, type); if (!id) { logger.warn('onServerLeave receive server id is empty.'); return; } if (type !== 'client') { this.watchdog.removeServer(id); } }
let replaceServer = function (self: MonitorWatcherModule, agent: MonitorAgent, msg: any, cb: MonitorCallback) { logger.debug('%s receive replaceServer signal: %j', self.app.serverId, msg); if (!msg || !msg.servers) { logger.warn('monitorwatcher replaceServer receive empty message: %j', msg); utils.invokeCallback(cb, Constants.SIGNAL.FAIL); return; } replaceServers(self, msg.servers); utils.invokeCallback(cb, Constants.SIGNAL.OK); }
onServerLeave(id: string, type: string) { logger.debug('masterwatcher receive remove server event, with server: %s, type: %s', id, type); if (!id) { logger.warn('onServerLeave receive server id is empty.'); return; } if (type !== 'client') { this.watchdog.removeServer(id); } }
masterHandler(agent: MasterAgent, msg: any, cb: MasterCallback) { if (!msg) { logger.warn('masterwatcher receive empty message.'); return; } let func = (masterMethods as any)[msg.action]; if (!func) { logger.info('masterwatcher unknown action: %j', msg.action); return; } func(this, agent, msg, cb); }
clearCbTimeout(id: number) { if (!this.timeout[id]) { logger.warn('timer is not exsits, serverId: %s remote: %s, host: %s, port: %s', this.serverId, id, this.host, this.port); return; } clearTimeout(this.timeout[id]); delete this.timeout[id]; }
record(id: string) { if (!this.isStarted && --this.count < 0) { let usedTime = Date.now() - this.app.startTime; this.notify({ action: 'startOver' }); this.isStarted = true; logger.warn('all servers startup in %s ms', usedTime); } }
clearRequireCache(path: string) { const moduleObj = require.cache[path]; if (!moduleObj) { logger.warn('can not find module of truepath', path); return; } if (moduleObj.parent) { // console.log('has parent ',moduleObj.parent); moduleObj.parent.children.splice(moduleObj.parent.children.indexOf(moduleObj), 1); } delete require.cache[path]; }