@mdf.js/openc2
Version:
MMS - API - Observability
65 lines • 3.05 kB
JavaScript
"use strict";
/**
* Copyright 2024 Mytra Control S.L. All rights reserved.
*
* Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
* or at https://opensource.org/licenses/MIT.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProducerFactory = void 0;
const tslib_1 = require("tslib");
const crash_1 = require("@mdf.js/crash");
const openc2_core_1 = require("@mdf.js/openc2-core");
const cluster_1 = tslib_1.__importDefault(require("cluster"));
const Adapters = tslib_1.__importStar(require("../adapters"));
class ProducerFactory {
/**
* Create an instance of OpenC2 Producer with Redis interface
* @param options - Producer configuration options
* @param redisOptions - Redis configuration options
*/
static Redis(options, redisOptions) {
var _a;
if (cluster_1.default.isWorker) {
throw new crash_1.Crash('OpenC2 Producer can not be instantiated in a worker process');
}
else {
const adapter = new Adapters.Redis.RedisProducerAdapter({ id: options.id }, redisOptions);
const register = (_a = options.registry) !== null && _a !== void 0 ? _a : new openc2_core_1.Registry(options.id, options.maxInactivityTime, options.registerLimit);
return new openc2_core_1.Producer(adapter, { ...options, registry: register });
}
}
/**
* Create an instance of OpenC2 Producer with SocketIO interface
* @param options - Producer configuration options
* @param socketOptions - SocketIO configuration options
*/
static SocketIO(options, socketOptions) {
var _a;
if (cluster_1.default.isWorker) {
throw new crash_1.Crash('OpenC2 Producer can not be instantiated in a worker process');
}
else {
const adapter = new Adapters.SocketIO.SocketIOProducerAdapter({ id: options.id }, socketOptions);
const register = (_a = options.registry) !== null && _a !== void 0 ? _a : new openc2_core_1.Registry(options.id, options.maxInactivityTime, options.registerLimit);
return new openc2_core_1.Producer(adapter, { ...options, registry: register });
}
}
/**
* Create an instance of OpenC2 Producer with Dummy interface
* @param options - Producer configuration options
*/
static Dummy(options) {
var _a;
if (cluster_1.default.isWorker) {
throw new crash_1.Crash('OpenC2 Producer can not be instantiated in a worker process');
}
else {
const adapter = new Adapters.Dummy.DummyProducerAdapter({ id: options.id });
const register = (_a = options.registry) !== null && _a !== void 0 ? _a : new openc2_core_1.Registry(options.id, options.maxInactivityTime, options.registerLimit);
return new openc2_core_1.Producer(adapter, { ...options, registry: register });
}
}
}
exports.ProducerFactory = ProducerFactory;
//# sourceMappingURL=ProducerFactory.js.map