function Document(options) { EventEmitter.apply(this) this.id this.options = { mergeQueue: true , storageAdapter: new MemoryAdapter } for (var prop in options) this.options[prop] = options[prop] this.storage = this.options.storageAdapter this.ottype = this.options.ottype this.content = null this.initialized = false this.slaves = [] this.links = [] this.master = null this.queue = queue() this.queue.concurrency = 1 this.queue.start() if(!this.ottype) throw new Error('Document: No ottype specified') if(!this.storage) throw new Error('Document: No adapter specified') this.on('error', console.log) }
var PubSub = module.exports = function(){ var self = this; events.EventEmitter.apply(this); self.model = Bozuko.models.Message; self.cursor = null; self.timestamp = new Date(); self.running = false; self.last_id = false; self.max = 100; self.threshold = Bozuko.cfg( 'pubsub.cleanup.threshold', 1000 * 60 * 60 * 2 ); // 2 hours self.poll_timeout = null; self.poll_interval = Bozuko.cfg( 'pubsub.poll.interval', 1000 ); self.cleanup_interval = Bozuko.cfg( 'pubsub.cleanup.interval', 1000 * 60 * 10 ); // 10 minutes self.cleanup_timeout = null; /** * Hack to stagger the listeners */ self.startup_timeout = setTimeout(function(){ if( Bozuko.isMaster ) return; if( !process.title.match(/[0-9]+/) ) return; var stagger = self.poll_interval / 4, id = parseInt(process.title.match(/[0-9]+/)[0], 10); setTimeout( function(){ self.start(); }, id * stagger ); }, 500); };
var Config = module.exports = function(callback) { EventEmitter.apply(this); this._obj = {}; this._state = 'end'; // parsing | end; var that = this; var queue = this._queue = async.queue(function(parseHandler, callback) { that._parse(); parseHandler.call(that, callback); }, 1); queue.unshift = function(task) { queue.tasks.unshift({ data: task, callback: _.isFunction(callback) ? callback : null }); }; queue.drain = function() { that._over(); that.emit('end', that); callback && callback(); // only run once; callback = function() {}; }; this._parseRule = {}; };
function Slave () { this.id = undefined; this.channel = new events.EventEmitter(); this.heartbeatFrequency = 1000; this.slaves = {}; events.EventEmitter.apply(this); }
/** * @class ServerEngine * @extends EventEmitter * @uses ServerSidePublishEngine * @constructor */ function ServerEngine(options) { options = options || {}; options.buildInfo = options.buildInfo || {}; EventEmitter.apply(this, arguments); this._session_counter = 0; this._sessions = {}; this._closedSessions = {}; this.startTime = new Date(); this.status = "creating"; this.setServerState(ServerState.NoConfiguration); this.address_space = null; this.buildInfo = new BuildInfo(options.buildInfo); this._cumulatedSubscriptionCount = 0; this._rejectedSessionCount = 0; this._rejectedRequestsCount = 0; this._sessionAbortCount = 0; this._publishingIntervalCount = 0; this._sessionTimeoutCount = 0; this.serverCapabilities = new ServerCapabilities(options.serverCapabilities); this._shutdownTask = []; this._applicationUri = options.applicationUri || "<unset _applicationUri>"; }
function Submodules(options) { if (typeof options === 'string' || options instanceof String) { if (/[*+!?]/.test(options)) { options = {pattern: options}; } else { options = {path: options}; } } else { options = options || {}; } if (!(this instanceof Submodules)) { return new Submodules(options); } if (options.pattern && !options.filter) { options.filter = minimatch.filter(options.pattern); } EventEmitter.apply(this); this.on('gitdir', onGitdir(this, options)); this.on('commit', onCommit(this, options)); this.on('entry', onEntry(this, options)); if (options.gitdir) { this.emit('gitdir', options.gitdir); } if (options.commit) { this.emit('commit', options.commit); } }
function Socket(options) { if (!(this instanceof Socket)) { return new Socket(options); } EventEmitter.apply(this); options = options || {}; if (options.proto === 'https') { this.authorized = true; } this.writable = true; this.readable = true; this.destroyed = false; this.setNoDelay = noop; this.setKeepAlive = noop; this.resume = noop; // totalDelay that has already been applied to the current // request/connection, timeout error will be generated if // it is timed-out. this.totalDelayMs = 0; // Maximum allowed delay. Null means unlimited. this.timeoutMs = null; }
/** * * Actor * * The Actor is responsible of managing a flow * it links and it's nodes. * * A node contains the actual programming logic. * * @api public * @author Rob Halff <*****@*****.**> * @constructor */ function Actor() { EventEmitter.apply(this, arguments); this.ioHandler = undefined; this.processManager = undefined; this.nodes = {}; this.links = {}; this.iips = {}; this.view = []; this.status = undefined; this.type = 'flow'; /** * * Added by default. * * If others need to be used they should be set before addMap(); * */ this.addIoHandler(new IoMapHandler()); this.addProcessManager(new DefaultProcessManager()); }
function Scope(basePath, options) { if (!(this instanceof Scope)) { return new Scope(basePath, options); } EventEmitter.apply(this); this.keyedInterceptors = {}; this.interceptors = []; this.transformPathFunction = null; this.transformRequestBodyFunction = null; this.matchHeaders = []; this.logger = debug; this.scopeOptions = options || {}; this.urlParts = {}; this._persist = false; this.contentLen = false; this.date = null; this.basePath = basePath; this.basePathname = ''; this.port = null; if (!(basePath instanceof RegExp)) { this.urlParts = url.parse(basePath); this.port = this.urlParts.port || ((this.urlParts.protocol === 'http:') ? 80 : 443); this.basePathname = this.urlParts.pathname.replace(/\/$/, ''); this.basePath = this.urlParts.protocol + '//' + this.urlParts.hostname + ':' + this.port; } }
var Parser = HTML5.Parser = function HTML5Parser(options) { events.EventEmitter.apply(this); this.strict = false; this.errors = []; var phase; this.__defineSetter__('phase', function(p) { phase = p; if(!p) throw( new Error("Can't leave phase undefined")); if(!p instanceof Function) throw( new Error("Not a function")); }); this.__defineGetter__('phase', function() { return phase; }); if(options) for(o in options) { this[o] = options[o]; } if(!this.document) { var l3, jsdom jsdom = require('jsdom') l3 = jsdom.dom.level3.core var DOM = jsdom.browserAugmentation(l3) this.document = new DOM.Document('html'); } this.tree = new HTML5.TreeBuilder(this.document); }
var LolClient = function(options) { EventEmitter.apply(this, arguments); this.options = options; this._rtmpHosts = { na: 'prod.na2.lol.riotgames.com', euw: 'prod.eu.lol.riotgames.com', eune: 'prod.eun1.lol.riotgames.com', kr: 'prod.kr.lol.riotgames.com', br: 'prod.br.lol.riotgames.com', tr: 'prod.tr.lol.riotgames.com', ru: 'prod.ru.lol.riotgames.com', lan: 'prod.la1.lol.riotgames.com', las: 'prod.la2.lol.riotgames.com', oce: 'prod.oc1.lol.riotgames.com', pbe: 'prod.pbe1.lol.riotgames.com', tw: 'prodtw.lol.garenanow.com' }; this._loginQueueHosts = { na: 'lq.na2.lol.riotgames.com', euw: 'lq.eu.lol.riotgames.com', eune: 'lq.eun1.lol.riotgames.com', kr: 'lq.kr.lol.riotgames.com', br: 'lq.br.lol.riotgames.com', tr: 'lq.tr.lol.riotgames.com', lan: 'lq.la1.lol.riotgames.com', las: 'lq.la2.lol.riotgames.com', oce: 'lq.oc1.lol.riotgames.com', pbe: 'lq.pbe1.lol.riotgames.com', tw: 'loginqueuetw.lol.garenanow.com' }; if (this.options.region) { this.options.host = this._rtmpHosts[this.options.region]; this.options.lqHost = this._loginQueueHosts[this.options.region]; } else { this.options.host = this.options.host; this.options.lqHost = this.options.lqHost; } this.options.port = this.options.port || 2099; this.options.username = this.options.username; this.options.password = this.options.password; this.options.useGarena = this.options.useGarena || false; this.options.garenaToken = this.options.garenaToken || ''; if (this.options.useGarena) { this.options.password = ''; this.options.username = ''; this.options.userId = ''; } this.options.version = this.options.version || '5.10.0.365'; this.options.debug = this.options.debug || false; if (this.options.debug) { console.log(this.options); } };
/** * a server side monitored item * * - Once created, the MonitoredItem will raised an "samplingEvent" event every "samplingInterval" millisecond * until {{#crossLink "MonitoredItem/terminate:method"}}{{/crossLink}} is called. * * - It is up to the event receiver to call {{#crossLink "MonitoredItem/recordValue:method"}}{{/crossLink}}. * * @class MonitoredItem * @param options the options * @param options.clientHandle {Number} - the client handle * @param options.samplingInterval {Number} - the sampling Interval * @param options.discardOldest {boolean} - if discardOldest === true, older items are removed from the queue * when * @param options.queueSize {Number} - the size of the queue. * @constructor */ function MonitoredItem(options) { EventEmitter.apply(this, arguments); assert(options.hasOwnProperty("clientHandle")); assert(options.hasOwnProperty("samplingInterval")); assert(_.isFinite(options.clientHandle)); assert(_.isFinite(options.samplingInterval)); assert(_.isBoolean(options.discardOldest)); assert(_.isFinite(options.queueSize)); assert(options.queueSize > 0); var self = this; self.clientHandle = options.clientHandle; self.samplingInterval = options.samplingInterval; self.discardOldest = options.discardOldest; self.queueSize = options.queueSize; self.queue = []; self.overflow = false; self._samplingId = setInterval(function () { self._on_sampling_timer(); }, self.samplingInterval); self.oldValue = new Variant({dataType: DataType.Null, value: null}); }
/** * * A Server session object. * * **from OPCUA Spec 1.02:** * * * Sessions are created to be independent of the underlying communications connection. Therefore, if a communication * connection fails, the Session is not immediately affected. The exact mechanism to recover from an underlying * communication connection error depends on the SecureChannel mapping as described in Part 6. * * * Sessions are terminated by the Server automatically if the Client fails to issue a Service request on the Session * within the timeout period negotiated by the Server in the CreateSession Service response. This protects the Server * against Client failures and against situations where a failed underlying connection cannot be re-established. * * * Clients shall be prepared to submit requests in a timely manner to prevent the Session from closing automatically. * * * Clients may explicitly terminate Sessions using the CloseSession Service. * * * When a Session is terminated, all outstanding requests on the Session are aborted and Bad_SessionClosed StatusCodes * are returned to the Client. In addition, the Server deletes the entry for the Client from its * SessionDiagnosticsArray Variable and notifies any other Clients who were subscribed to this entry. * * @class ServerSession * * @param parent {SessionEngine} * @param sessionId {Number} * @param sessionTimeout {Number} * @private * @constructor */ function ServerSession(parent,sessionId,sessionTimeout) { this.parent = parent; // SessionEngine EventEmitter.apply(this, arguments); assert(_.isFinite(sessionId)); assert(sessionId !== 0, " sessionId is null/empty. this is not allowed"); assert(_.isFinite(sessionTimeout)); assert(sessionTimeout >= 0, " sessionTimeout"); this.sessionTimeout = sessionTimeout; this.authenticationToken = new NodeId(NodeIdType.BYTESTRING, crypto.randomBytes(16)); this.nodeId = new NodeId(NodeIdType.NUMERIC, sessionId, 0); assert(this.authenticationToken instanceof NodeId); assert(this.nodeId instanceof NodeId); this._subscription_counter = 0; this.publishEngine = new ServerSidePublishEngine(); this.publishEngine.setMaxListeners(100); theWatchDog.addSubscriber(this,this.sessionTimeout); }
var RingBuffer = function(options) { EventEmitter.apply(this, arguments); options = options || {}; this.limit = options.limit || 16; this.json = options.json || false; this.records = options.records || []; }
/** * Create a new `IOAdapter` with the given `options`. * * @constructor * @param {RemoteObjects} remotes * @param server */ function IOAdapter(remotes, server) { EventEmitter.apply(this, arguments); this.remotes = remotes; this.server = server; this.Context = IOContext; }
/** * a server side monitored item * * - Once created, the MonitoredItem will raised an "samplingEvent" event every "samplingInterval" millisecond * until {{#crossLink "MonitoredItem/terminate:method"}}{{/crossLink}} is called. * * - It is up to the event receiver to call {{#crossLink "MonitoredItem/recordValue:method"}}{{/crossLink}}. * * @class MonitoredItem * @param options the options * @param options.clientHandle {Number} - the client handle * @param options.samplingInterval {Number} - the sampling Interval * @param options.discardOldest {boolean} - if discardOldest === true, older items are removed from the queue * when * @param options.queueSize {Number} - the size of the queue. * @param options.monitoredItemId {Number} the monitoredItem Id assigned by the server to this monitoredItem. * @constructor */ function MonitoredItem(options) { EventEmitter.apply(this, arguments); var self = this; self._samplingId = null; self._set_parameters(options); assert(options.hasOwnProperty("monitoredItemId")); self.monitoredItemId = options.monitoredItemId; //( known as serverHandle) self.queue = []; self.overflow = false; self._samplingId = 0; self.oldDataValue = null; // unset initially // user has to call setMonitoringMode assert(!options.monitoringMode," use setMonitoring mode explicitly to activate the monitored item"); self.monitoringMode = MonitoringMode.Invalid; self.timestampsToReturn = options.timestampsToReturn || TimestampsToReturn.Neither; }
function GridFSBucket(db, options) { Emitter.apply(this); this.setMaxListeners(11); if (options && typeof options === 'object') { options = shallowClone(options); var keys = Object.keys(DEFAULT_GRIDFS_BUCKET_OPTIONS); for (var i = 0; i < keys.length; ++i) { if (!options[keys[i]]) { options[keys[i]] = DEFAULT_GRIDFS_BUCKET_OPTIONS[keys[i]]; } } } else { options = DEFAULT_GRIDFS_BUCKET_OPTIONS; } this.s = { db: db, options: options, _chunksCollection: db.collection(options.bucketName + '.chunks'), _filesCollection: db.collection(options.bucketName + '.files'), checkedIndexes: false, calledOpenUploadStream: false, promiseLibrary: db.s.promiseLibrary || (typeof global.Promise == 'function' ? global.Promise : require('es6-promise').Promise) }; };
/** * A JS Class for all spotify object * of which we don't own the pointer to in C++ * so that we have to register refs for it */ function SpObject () { EventEmitter.apply(this); var self = this; // if our reference is already loaded // populate attributes and trigger ready event as // soon as possible if(this.isReady()) { this._populateAttributes(); setTimeout(function() {self.emit('ready')}, 1); } else { // We could be doing this with the updated_metadata callback // but it doesn't tell us which metadata has been updated // so we test it regularly to check if our object is loaded yet var bo = backoff.fibonacci({ initialDelay: 10, maxDelay: 1000 }); bo.failAfter(10); bo.on('ready', function(number, delay) { if(!self.isReady()) { bo.backoff(); } else { self._populateAttributes(); self.emit('ready'); } }); bo.on('fail', function() { self._loadingTimeout(); }); bo.backoff(); } }
function Chunk(dl, number){ var self = this; EventEmitter.apply(self); self.offset = dl._options.start + (number * dl._options.chunkSize); self.size = Math.min(dl._options.chunkSize, dl.size - (number * dl._options.chunkSize)); self.position = 0; self._dl = dl; self._buffers = []; var req_options = _.clone(dl._options, true); req_options.headers = req_options.headers || {}; req_options.headers.range = 'bytes=' + (self.offset+self.position) + '-' + (self.offset+self.size-1); self._req = request(dl._url, req_options); self._req.on('error', function(error){self.emit('error', error);}); self._req.on('end', function(){ console.log('request end count : ', end_count); end_count++; if (self.position!=self.size){self.emit('error', new Error('http request ended prematurely')); return;} self.emit('end'); }); //commet: data may not be received in completed and cause no data event is emitted. self._req.on('data', function(data){ self.position += data.length; dl.downloaded += data.length; if (self._buffers){ self._buffers.push(data); } else { dl._buffers.push(data); dl.read(0); } }); }
function ConfigChain () { EE.apply(this) ProtoList.apply(this, arguments) this._awaiting = 0 this._saving = 0 this.sources = {} }
/** * @class ServerEngine * @extends EventEmitter * @uses ServerSidePublishEngine * @constructor */ function ServerEngine() { EventEmitter.apply(this, arguments); this._private_namespace = 1; this._internal_id_counter = 1000; this._session_counter = 0; this._sessions = {}; this.startTime = new Date(); this.status = "creating"; this.address_space = null; this.buildInfo = new BuildInfo({ productName: "NODEOPCUA-SERVER", productUri: "URI:NODEOPCUA-SERVER", manufacturerName: "<Manufacturer>", softwareVersion: "1.0", buildDate: new Date() }); this._cumulatedSubscriptionCount = 0; }
function Parted (parts) { Emitter.apply(this, arguments); function call () { var part; if ( 0 === parts.length ) { this.emit('end'); return; } part = parts.shift(); setTimeout(function () { this.emit('data', part); call.call(this); }.bind(this), 0); } this.on('newListener', function newListener (type) { if ( 'data' === type ) { call.call(this); this.removeListener('newListener', newListener); } }); }
var MongoStore = function(options) { Store.apply(this, arguments); EventEmitter.apply(this, arguments); options = options || {}; this.host = options.host || "localhost"; this.port = options.port || 27017; this.user = options.user; this.passord = options.password; this.poolSize = typeof argv.poolSize === 'number' ? argv.poolSize : options.poolSize || 100; this.registers = { 0: 0, 1: null, 2: null }; this.cache = {}; this.locks = {}; vrt.Api.IPC.define('MONGOSTORE_INSERT_EVENT'); vrt.Api.IPC.define('MONGOSTORE_UPDATE_EVENT'); vrt.Api.IPC.define('MONGOSTORE_LOCK_PUSH_EVENT'); vrt.Api.IPC.define('MONGOSTORE_LOCK_POP_EVENT'); var context = this; this.tree.connect = this.connect.bind(this); this.on('insert', function(collectionName, data, ipc) { var n, c = context.cache[n = collectionName + '.stats']; c&&context._cache_drop(n); }); function handle_ipc_event(target, args, packet) { var args_ = []; for(var i in args) args_[i] = args[i]; if( target === MONGOSTORE_INSERT_EVENT) args_.unshift('insert'); else if( target === MONGOSTORE_UPDATE_EVENT) args_.unshift('update'); else if ( target === MONGOSTORE_LOCK_PUSH_EVENT) return context._lock.apply(context, args_); else if ( target === MONGOSTORE_LOCK_POP_EVENT) return context._unlock.apply(context, args_); args_.push(packet); return context.emit.apply(context, args_); } vrt.ipc.on(MONGOSTORE_INSERT_EVENT, handle_ipc_event.bind(context, MONGOSTORE_INSERT_EVENT)); vrt.ipc.on(MONGOSTORE_UPDATE_EVENT, handle_ipc_event.bind(context, MONGOSTORE_UPDATE_EVENT)); vrt.ipc.on(MONGOSTORE_LOCK_PUSH_EVENT, handle_ipc_event.bind(context, MONGOSTORE_LOCK_PUSH_EVENT)); vrt.ipc.on(MONGOSTORE_LOCK_POP_EVENT, handle_ipc_event.bind(context, MONGOSTORE_LOCK_POP_EVENT)); };
function Logger(app){ EventEmitter.apply(this, arguments) this._logging = null this._client = null this.setAppName(app) this._verbosity = VL.warn this._state = 'closed' }
function Tcp(options) { EventEmitter.apply(this); this._host = options.host; this._port = options.port || 5222; this._parser = new StreamParser(); this._socket = null; this._connected = false; }
function PendingTransactionFilter(){ // console.log('PendingTransactionFilter - new') const self = this EventEmitter.apply(self) self.type = 'pendingTx' self.updates = [] self.allResults = [] }
/** * @constructor Palette * Represents a collection of colors * * @extends {EventEmitter} */ function Palette(colors){ this._colors = {}; EventEmitter.apply(this); _.bindAll(this, ['_onColorUpdate']); this.addColors(colors, true); }
function Tokenizer (check_token_cb) { EventEmitter.apply(this); this._buffered = ""; // we buffer untokenized data between writes this._regexes = []; // should contain objects // with regex[RegExp] and type[String] this._ignored = {} // a hash of ignored token types // these will be parsed but not emitted this._checkToken = check_token_cb || noop; }
function BlockFilter(opts) { // console.log('BlockFilter - new') const self = this EventEmitter.apply(self) self.type = 'block' self.engine = opts.engine self.blockNumber = opts.blockNumber self.updates = [] }
/** * Constructor */ function SimpleTokenizer() { EventEmitter.apply(this); this.rules = []; //list of rules to check this.speed = 20; //Speed to iterete on async calls (function init(){ //Constructor initiliazaer })(); }