UNPKG

hazelcast-client

Version:

Hazelcast - open source In-Memory Data Grid - client for NodeJS

51 lines 1.8 kB
"use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var events_1 = require('events'); exports.LifecycleEvent = { name: 'lifecycleEvent', starting: 'starting', started: 'started', shuttingDown: 'shuttingDown', shutdown: 'shutdown' }; var LifecycleService = (function (_super) { __extends(LifecycleService, _super); function LifecycleService(client) { var _this = this; _super.call(this); this.setMaxListeners(0); this.client = client; var listeners = []; try { listeners = client.getConfig().listeners.lifecycle; listeners.forEach(function (listener) { _this.on(exports.LifecycleEvent.name, listener); }); } catch (err) { } this.emit(exports.LifecycleEvent.name, exports.LifecycleEvent.starting); } LifecycleService.prototype.emitLifecycleEvent = function (state) { if (!exports.LifecycleEvent.hasOwnProperty(state)) { throw new Error(state + ' is not a valid lifecycle event'); } if (state === exports.LifecycleEvent.started) { this.active = true; } else if (state === exports.LifecycleEvent.shuttingDown) { this.active = false; } this.emit(exports.LifecycleEvent.name, state); }; LifecycleService.prototype.isRunning = function () { return this.active; }; return LifecycleService; }(events_1.EventEmitter)); exports.LifecycleService = LifecycleService; //# sourceMappingURL=LifecycleService.js.map