UNPKG

deepify

Version:
138 lines (109 loc) 2.48 kB
/** * Created by CCristi on 5/16/16. */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractLauncher = undefined; var _deepCore = require('deep-core'); var _deepCore2 = _interopRequireDefault(_deepCore); var _process = require('process'); var _process2 = _interopRequireDefault(_process); var _os = require('os'); var _os2 = _interopRequireDefault(_os); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class AbstractLauncher extends _deepCore2.default.OOP.Interface { constructor() { super(['_launch', '_stop']); this._hostname = '127.0.0.1'; this._port = 9200; this._settings = {}; } /** * @todo: add more? * * @returns {AbstractLauncher} */ autoRelease() { _process2.default.on('SIGINT', () => { _process2.default.exit(0); }); _process2.default.on('uncaughtException', error => { console.error(error.toString(), _os2.default.EOL, error.stack); _process2.default.exit(1); }); _process2.default.on('exit', this.stop.bind(this)); return this; } /** * @param {Object[]} args * @returns {Number} */ launch(...args) { console.debug(`Running elasticsearch on: ${this.shortUrl}`); return this._launch(...args); } /** * @link: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html * * @param {String} setting * @param {String} value * @return {AbstractLauncher} */ setSetting(setting, value) { this._settings[setting] = value; return this; } /** * @param {String} setting * @returns {*} */ getSetting(setting) { return this._settings[setting]; } /** * @param {Object[]} args */ stop(...args) { console.debug(`Stopping elasticsearch on: ${this.shortUrl}`); this._stop(...args); } /** * @returns {String} */ get shortUrl() { return `${this.hostname}:${this.port}`; } /** * @returns {Object} */ get settings() { return this._settings; } /** * @param {Number} port */ set port(port) { this._port = port; } /** * @returns {Number} */ get port() { return this._port; } /** * @param {String} hostname */ set hostname(hostname) { this._hostname = hostname; } /** * @returns {String} */ get hostname() { return this._hostname; } } exports.AbstractLauncher = AbstractLauncher;