UNPKG

diffusion

Version:

Diffusion JavaScript client

208 lines (207 loc) 9.22 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SecondaryBuilderImpl = void 0; var errors_1 = require("./../../../errors/errors"); var remote_servers_1 = require("./../../../features/remote-servers"); var options_impl_1 = require("./../../session/options-impl"); var limit_timeouts_1 = require("./../../util/limit-timeouts"); var require_non_null_1 = require("./../../util/require-non-null"); var remote_server_builder_base_1 = require("./remote-server-builder-base"); function parseIntOptionValue(value) { var intValue = Number.parseInt(value.trim(), 10); if (Number.isNaN(intValue)) { throw new errors_1.IllegalArgumentError(value + " is not a number"); } return intValue; } /** * Implementation of {@link SecondaryBuilder}. * * @since 6.9 * * @param <B> builder type */ var SecondaryBuilderImpl = /** @class */ (function (_super) { __extends(SecondaryBuilderImpl, _super); /** * Constructor. */ function SecondaryBuilderImpl(type, topicSelectors) { var _this = _super.call(this, type) || this; _this.thePrincipal = ''; _this.theCredentials = undefined; _this.theConnectionOptions = {}; _this.theMissingTopicNotificationFilter = undefined; _this.topicSelectors = topicSelectors; return _this; } SecondaryBuilderImpl.minimumValueOption = function (option, value, minimum) { var size; try { size = parseIntOptionValue(value); } catch (err) { throw new errors_1.IllegalArgumentError("Connection Option '" + remote_servers_1.ConnectionOption[option] + "' value '" + value + "' is invalid"); } if (size < minimum) { throw new errors_1.IllegalArgumentError("Connection Option '" + remote_servers_1.ConnectionOption[option] + "' value '" + value + "' cannot be less than " + minimum); } return size.toString(); }; SecondaryBuilderImpl.timeoutOption = function (option, value) { try { return limit_timeouts_1.limitTimeout(option.toString(), parseIntOptionValue(value)).toString(); } catch (err) { throw new errors_1.IllegalArgumentError("Connection Option '" + remote_servers_1.ConnectionOption[option] + "' value '" + value + "' is invalid"); } }; SecondaryBuilderImpl.prototype.validateConnectionOption = function (option, value) { this.validateOption(option, value); switch (option) { case remote_servers_1.ConnectionOption.CONNECTION_TIMEOUT: case remote_servers_1.ConnectionOption.WRITE_TIMEOUT: case remote_servers_1.ConnectionOption.RECONNECTION_TIMEOUT: return SecondaryBuilderImpl.timeoutOption(option, value); case remote_servers_1.ConnectionOption.INPUT_BUFFER_SIZE: case remote_servers_1.ConnectionOption.OUTPUT_BUFFER_SIZE: return SecondaryBuilderImpl.minimumValueOption(option, value, options_impl_1.MIN_MAX_MESSAGE_SIZE); case remote_servers_1.ConnectionOption.MAXIMUM_QUEUE_SIZE: return SecondaryBuilderImpl.minimumValueOption(option, value, 1); case remote_servers_1.ConnectionOption.RECOVERY_BUFFER_SIZE: return SecondaryBuilderImpl.minimumValueOption(option, value, 0); case remote_servers_1.ConnectionOption.RETRY_DELAY: return SecondaryBuilderImpl.minimumValueOption(option, value, 0); default: throw new errors_1.IllegalArgumentError("Unknown option " + option); } }; SecondaryBuilderImpl.prototype.validateOption = function (option, value) { if (value === null || value === undefined) { throw new errors_1.IllegalArgumentError("Connection Option '" + remote_servers_1.ConnectionOption[option] + "' value is null"); } if (this.type === remote_servers_1.RemoteServerType.SECONDARY_ACCEPTOR && SecondaryBuilderImpl.INVALID_ACCEPTOR_OPTIONS.includes(option)) { throw new errors_1.IllegalArgumentError("Connection Option '" + remote_servers_1.ConnectionOption[option] + "' cannot be specified " + "for SECONDARY_ACCEPTOR servers"); } }; SecondaryBuilderImpl.prototype.getPrincipal = function () { return this.thePrincipal; }; SecondaryBuilderImpl.prototype.getCredentials = function () { return this.theCredentials; }; SecondaryBuilderImpl.prototype.getConnectionOptions = function () { return this.theConnectionOptions; }; SecondaryBuilderImpl.prototype.getMissingTopicNotificationFilter = function () { return this.theMissingTopicNotificationFilter; }; SecondaryBuilderImpl.prototype.principal = function (principal) { this.thePrincipal = principal !== null && principal !== void 0 ? principal : ''; return this; }; SecondaryBuilderImpl.prototype.credentials = function (credentials) { this.theCredentials = credentials || undefined; return this; }; SecondaryBuilderImpl.prototype.connectionOptions = function (connectionOptions) { var e_1, _a; var newOptions = {}; try { for (var _b = __values(Object.entries(connectionOptions)), _c = _b.next(); !_c.done; _c = _b.next()) { var _d = __read(_c.value, 2), optionStr = _d[0], entry = _d[1]; var option = parseInt(optionStr, 10); newOptions[option] = this.validateConnectionOption(option, entry); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } this.theConnectionOptions = newOptions; return this; }; SecondaryBuilderImpl.prototype.connectionOption = function (connectionOption, value) { require_non_null_1.requireNonNull(connectionOption, 'connectionOption'); if (value === null || value === undefined) { delete this.theConnectionOptions[connectionOption]; } else { this.theConnectionOptions[connectionOption] = this.validateConnectionOption(connectionOption, value); } return this; }; SecondaryBuilderImpl.prototype.missingTopicNotificationFilter = function (filter) { if (filter !== null && filter !== undefined) { try { this.topicSelectors.parse(filter); } catch (err) { throw new errors_1.IllegalArgumentError("filter is invalid: " + err); } } this.theMissingTopicNotificationFilter = filter || undefined; return this; }; SecondaryBuilderImpl.prototype.reset = function () { this.thePrincipal = ''; this.theCredentials = undefined; this.theConnectionOptions = {}; this.theMissingTopicNotificationFilter = undefined; return this; }; SecondaryBuilderImpl.INVALID_ACCEPTOR_OPTIONS = [ remote_servers_1.ConnectionOption.RECONNECTION_TIMEOUT, remote_servers_1.ConnectionOption.RETRY_DELAY, remote_servers_1.ConnectionOption.RECOVERY_BUFFER_SIZE ]; return SecondaryBuilderImpl; }(remote_server_builder_base_1.RemoteServerBuilderBaseImpl)); exports.SecondaryBuilderImpl = SecondaryBuilderImpl;