UNPKG

pandora

Version:
108 lines 3.9 kB
'use strict'; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const AppletReconciler_1 = require("./AppletReconciler"); const ServiceReconciler_1 = require("../service/ServiceReconciler"); const pandora_env_1 = require("pandora-env"); const WorkerContextAccessor_1 = require("./WorkerContextAccessor"); /** * Class WorkerContext * 1. Inject the service and the applet * 2. manage the process's lifecycle, provide start() and stop() * 3. drive the lifecycle of the service and the applet */ class WorkerContext { constructor(processRepresentation) { this.processRepresentation = processRepresentation; this.appletReconciler = new AppletReconciler_1.AppletReconciler(processRepresentation, this); this.serviceReconciler = new ServiceReconciler_1.ServiceReconciler(processRepresentation, this); this.workerContextAccessor = new WorkerContextAccessor_1.WorkerContextAccessor(this); } /** * Get environment object * @returns {Environment} */ getEnvironment() { return pandora_env_1.EnvironmentUtil.getInstance().getCurrentEnvironment(); } /** * Set configurator object * @param configurator * @returns {Promise<void>} */ setConfigurator(configurator) { return __awaiter(this, void 0, void 0, function* () { this.configurator = configurator; this.configProperties = yield this.configurator.getAllProperties(); }); } /** * Get properties from configurator object * @returns {any} */ getProperties() { return this.configProperties; } /** * Get configurator object * @returns {Configurator} */ getConfigurator() { return this.configurator; } /** * Bind services * @param {ServiceRepresentation | ServiceRepresentation[]} services */ bindService(services) { if (Array.isArray(services)) { for (const service of services) { this.serviceReconciler.receiveServiceRepresentation(service); } return; } this.serviceReconciler.receiveServiceRepresentation(services); } /** * Bind applets * @param {AppletRepresentation | AppletRepresentation[]} applets */ bindApplet(applets) { if (Array.isArray(applets)) { for (const applet of applets) { this.appletReconciler.receiveAppletRepresentation(applet); } return; } this.appletReconciler.receiveAppletRepresentation(applets); } /** * Start worker, drive the lifecycle of the service and the applet * @returns {Promise<void>} */ start() { return __awaiter(this, void 0, void 0, function* () { yield this.serviceReconciler.start(); yield this.appletReconciler.start(); }); } /** * Stop worker, drive the lifecycle of the service and the applet * @returns {Promise<void>} */ stop() { return __awaiter(this, void 0, void 0, function* () { yield this.serviceReconciler.stop(); yield this.appletReconciler.stop(); }); } } exports.WorkerContext = WorkerContext; //# sourceMappingURL=WorkerContext.js.map