UNPKG

raas-client

Version:
88 lines 4.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const raas_core_1 = require("raas-core"); const common_1 = require("./common"); class ServerLauncher { constructor(connection, emitter) { this.connection = connection; this.emitter = emitter; this.listenToServerChanges(); } listenToServerChanges() { // this.connection.onNotification(Messages.Client.ServerProcessCreatedNotification.type, process => { // this.emitter.emit('serverProcessCreated', process); // }); this.connection.onNotification(raas_core_1.Messages.Client.ServerStartedNotification.type, process => { this.emitter.emit('serverStarted', process); }); this.connection.onNotification(raas_core_1.Messages.Client.ServerProcessOutputAppendedNotification.type, output => { this.emitter.emit('serverOutputAppended', output); }); // this.connection.onNotification(Messages.Client.ServerProcessTerminatedNotification.type, process => { // this.emitter.emit('serverProcessTerminated', process); // }); this.connection.onNotification(raas_core_1.Messages.Client.ServerStoppedNotification.type, process => { this.emitter.emit('serverStopped', process); }); // this.connection.onNotification(Messages.Client.ServerStateChangedNotification.type, state => { // this.emitter.emit('serverStateChanged', state); // }); this.connection.onNotification(raas_core_1.Messages.Client.AnalysisMessageNotification.type, out => { this.emitter.emit('analysisMessage', out); }); } startServerAsync(config, timeout = 2000) { return common_1.Common.sendSimpleRequest(this.connection, raas_core_1.Messages.Server.StartServerRequest.type, config, timeout, common_1.ErrorMessages.STARTSERVER_TIMEOUT); } startServerSync(config, timeout = 60000) { return new Promise((resolve, reject) => { const timer = setTimeout(() => { return reject(new Error(common_1.ErrorMessages.STARTSERVER_TIMEOUT)); }, timeout); let result; const listener = (server) => { if (server.id === config.id && server.state === raas_core_1.Protocol.ServerState.STARTED) { result.then(() => { clearTimeout(timer); // this.emitter.removeListener('serverStateChanged', listener); this.emitter.removeListener('serverStarted', listener); resolve(server); }); } }; // this.emitter.prependListener('serverStateChanged', listener); this.emitter.prependListener('serverStarted', listener); result = this.connection.sendRequest(raas_core_1.Messages.Server.StartServerRequest.type, config); }); } stopServerAsync(config, timeout = 2000) { return common_1.Common.sendSimpleRequest(this.connection, raas_core_1.Messages.Server.StopServerRequest.type, config, timeout, common_1.ErrorMessages.STOPSERVER_TIMEOUT); } stopServerSync(config, timeout = 60000) { return new Promise((resolve, reject) => { const timer = setTimeout(() => { return reject(new Error(common_1.ErrorMessages.STOPSERVER_TIMEOUT)); }, timeout); let result; const listener = (server) => { if (server.id === config.id && server.state === raas_core_1.Protocol.ServerState.STOPPED) { result.then(() => { clearTimeout(timer); this.emitter.removeListener('serverStopped', listener); resolve(server); }); } }; this.emitter.prependListener('serverStopped', listener); result = this.connection.sendRequest(raas_core_1.Messages.Server.StopServerRequest.type, config); }); } startAnalysis(runConfig, serverConfig, timeout = 60000) { return common_1.Common.sendSimpleRequest(this.connection, raas_core_1.Messages.Server.StartAnalaysisRequest.type, { runConfig, serverConfig }, timeout, common_1.ErrorMessages.STARTANALYSIS_TIMEOUT); } cancelAnalysis(runConfig, timeout = 60000) { return common_1.Common.sendSimpleRequest(this.connection, raas_core_1.Messages.Server.CancelAnalaysisRequest.type, { runConfig, serverConfig }, timeout, common_1.ErrorMessages.CANCELANALYSIS_TIMEOUT); } } exports.ServerLauncher = ServerLauncher; //# sourceMappingURL=serverLauncher.js.map