Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*!
* Pinus -- consoleModule nodeInfo processInfo
* Copyright(c) 2012 fantasyni
* MIT Licensed
*/
import * as monitor from 'pinus-monitor';
import { getLogger } from 'pinus-logger'; import { IModule, ModuleType, MonitorCallback, MasterCallback } from '../consoleService';
import { MonitorAgent } from '../monitor/monitorAgent';
import { MasterAgent } from '../master/masterAgent';
import { PsParam } from 'pinus-monitor';
import * as path from 'path';
let logger = getLogger('pinus-admin', path.basename(__filename));
let DEFAULT_INTERVAL = 5 * 60; // in second
let DEFAULT_DELAY = 10; // in second
export class NodeInfoModule implements IModule {
type: ModuleType;
interval: number;
delay: number;
static moduleId = 'nodeInfo';
constructor(opts ?: {type?: ModuleType , interval?: number, delay?: number}) {
opts = opts || {};
this.type = opts.type || ModuleType.pull;
this.interval = opts.interval || DEFAULT_INTERVAL;
this.delay = opts.delay || DEFAULT_DELAY;
}
/*!
* Pinus -- consoleModule systemInfo
* Copyright(c) 2012 fantasyni
* MIT Licensed
*/
import * as monitor from 'pinus-monitor';
import { getLogger } from 'pinus-logger';
import { IModule, ModuleType, MonitorCallback, MasterCallback } from '../consoleService';
import { MonitorAgent } from '../monitor/monitorAgent';
import { MasterAgent } from '../master/masterAgent';
import * as path from 'path';
let logger = getLogger('pinus-admin', path.basename(__filename));
let DEFAULT_INTERVAL = 5 * 60; // in second
let DEFAULT_DELAY = 10; // in second
export class SystemInfoModule implements IModule {
static moduleId = 'systemInfo';
type: ModuleType;
interval: number;
delay: number;
constructor(opts ?: {type ?: ModuleType , interval?: number; delay ?: number}) {
opts = opts || {};
this.type = opts.type || ModuleType.pull;
this.interval = opts.interval || DEFAULT_INTERVAL;
this.delay = opts.delay || DEFAULT_DELAY;
require('source-map-support/register');
import {preload} from './preload';
preload();
import {createServer, createTcpAcceptor} from '../index';
import { configure } from 'pinus-logger';
import {getLogger} from 'pinus-logger';
configure('./config/log4js.json');
let logger = getLogger('pinus-rpc', 'sample-server');
// remote service path info list
let paths = [
{
serverType: 'test',
namespace: 'user', path: __dirname + '/remote/test'}
];
function runServer(port: number) {
let server = createServer({paths: paths, port: port, rpcDebugLog: true,
rpcLogger: logger,
acceptorFactory: createTcpAcceptor
});
import {TCPMailBox} from '../lib/rpc-client/mailboxes/tcp-mailbox';
require('source-map-support/register');
import {preload} from './preload';
preload();
import * as pinusrpc from '..';
import {configure} from 'pinus-logger';
import {getLogger} from 'pinus-logger';
import {createTcpMailBox} from '../';
// configure('./config/log4js.json');
let logger = getLogger('pinus-rpc', 'sample-client');
// remote service interface path info list
const records = [
{namespace: 'user', serverType: 'test', path: __dirname + '/remote/test'}
];
const context = {
serverId: 'test-server-1'
};
// server info list
const servers = [
{id: 'test-server-1', serverType: 'test', host: '127.0.0.1', port: 3333},
{id: 'test-server-2', serverType: 'test', host: '127.0.0.1', port: 3334},
{id: 'test-server-3', serverType: 'test', host: '127.0.0.1', port: 3335},
{id: 'unuse-server-1', serverType: 'unuse', host: '127.0.0.1', port: 3336}
constructor(private app: Application, opts?: RemoteComponentOptions) {
opts = opts || {};
this.opts = opts;
// cacheMsg is deprecated, just for compatibility here.
opts.bufferMsg = opts.bufferMsg || opts.cacheMsg || false;
opts.interval = opts.interval || 30;
if (app.enabled('rpcDebugLog')) {
opts.rpcDebugLog = true;
opts.rpcLogger = getLogger('rpc-debug', path.basename(__filename));
}
opts.paths = this.getRemotePaths();
opts.context = this.app;
let remoters: Remoters = {};
opts.services = {};
opts.services['user'] = remoters;
let info = this.app.getCurrentServer();
// 添加插件中的remoter到ServerInfo中
for(let plugin of this.app.usedPlugins) {
if(plugin.remoterPath) {
opts.paths.push({
namespace: 'user',
constructor(app: Application, opts: ProxyComponentOptions) {
opts = opts || {};
// proxy default config
// cacheMsg is deprecated, just for compatibility here.
opts.bufferMsg = opts.bufferMsg || opts.cacheMsg || false;
opts.interval = opts.interval || 30;
opts.router = genRouteFun();
opts.context = app;
opts.routeContext = app;
if (app.enabled('rpcDebugLog')) {
opts.rpcDebugLog = true;
opts.rpcLogger = getLogger('rpc-debug', path.basename(__filename));
}
this.app = app;
this.opts = opts;
this.client = genRpcClient(this.app, opts);
this.app.event.on(events.ADD_SERVERS, this.addServers.bind(this));
this.app.event.on(events.REMOVE_SERVERS, this.removeServers.bind(this));
this.app.event.on(events.REPLACE_SERVERS, this.replaceServers.bind(this));
}
import { Message } from 'pinus-protocol';
import * as Constants from '../../util/constants';
import { getLogger } from 'pinus-logger';
import { IConnector } from '../../interfaces/IConnector';
import * as path from 'path';
let logger = getLogger('pinus', path.basename(__filename));
let encode = function (this: IConnector , reqId: number, route: string, msg: any) {
if (!!reqId) {
return composeResponse(this, reqId, route, msg);
} else {
return composePush(this, route, msg);
}
};
let decode = function (this: any , msg: any) {
msg = Message.decode(msg.body);
let route = msg.route;
// decode use dictionary
if (!!msg.compressRoute) {
import { Package , Protocol } from 'pinus-protocol';
import { getLogger } from 'pinus-logger';
import { ISocket } from '../../interfaces/ISocket';
import * as path from 'path';
let logger = getLogger('pinus', path.basename(__filename));
let handlers: {[packageType: number]: (socket: ISocket , pkg: any) => void} = {};
let ST_INITED = 0;
let ST_WAIT_ACK = 1;
let ST_WORKING = 2;
let ST_CLOSED = 3;
let handleHandshake = function (socket: ISocket , pkg: any) {
if (socket.state !== ST_INITED) {
return;
}
try {
socket.emit('handshake', JSON.parse(Protocol.strdecode(pkg.body)));
} catch (ex) {
/**
* Scheduler component to schedule message sending.
*/
import {DirectPushScheduler as DefaultScheduler} from '../pushSchedulers/direct';
import { getLogger } from 'pinus-logger';
import { Application } from '../application';
import { IComponent } from '../interfaces/IComponent';
import { IPushScheduler, ScheduleOptions, IPushSchedulerOrCtor, IPushSchedulerOptions, MultiPushSchedulerOptions } from '../interfaces/IPushScheduler';
import { MultiPushScheduler } from '../pushSchedulers/multi';
import { SID } from '../util/constants';
import * as path from 'path';
let logger = getLogger('pinus', path.basename(__filename));
export class PushSchedulerComponent implements IComponent {
scheduler: IPushScheduler;
constructor(private app: Application, opts ?: IPushSchedulerOptions) {
opts = opts || {};
this.scheduler = getScheduler(this, app, opts);
}
name = '__pushScheduler__';
/**
* Component lifecycle callback
*
* @param {Function} cb
* @return {Void}
* Pinus -- consoleModule watchServer
* Copyright(c) 2013 fantasyni
* MIT Licensed
*/
import { getLogger } from 'pinus-logger';
import * as countDownLatch from '../util/countDownLatch';
import * as monitor from 'pinus-monitor';
import * as utils from '../util/utils';
import * as util from 'util';
import * as fs from 'fs';
import * as vm from 'vm';
import { IModule, MonitorCallback, MasterCallback, ModuleType , MonitorAgent, MasterAgent } from 'pinus-admin';
import { ServerInfo } from '../util/constants';
import { Application } from '../application';
import * as path from 'path';
let logger = getLogger('pinus', path.basename(__filename));
enum HandleType {
client = 'client',
monitor = 'monitor'
}
export class WatchServerModule implements IModule {
static moduleId = 'watchServer';
app: Application;
constructor(opts ?: {app ?: Application}) {
opts = opts || {};
this.app = opts.app;
}