UNPKG

nope-js-node

Version:

NoPE Runtime for Nodejs. For Browser-Support please use nope-browser

255 lines (254 loc) 7.9 kB
/** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2022-01-03 21:21:45 * @modify date 2022-01-10 14:10:00 * @desc [description] */ import { ILogger } from "js-logger"; import { ICommunicationBridge, IMapBasedMergeData, INopeConnectivityManager, INopeINopeConnectivityOptions, INopeINopeConnectivityTimeOptions, INopeObservable, INopeStatusInfo } from "../../types/nope"; /** * A Modul to manage the status of other statusmanagers. * Dispatcher should have a status manager, to ensure, the * system is online etc. Its a base implemetation of the * {@link INopeConnectivityManager}. Please checkout the interface * for more details or the corresponding jupyter notebook. * * @author M.Karkowski * @export * @class NopeConnectivityManager * @implements {INopeConnectivityManager} */ export declare class NopeConnectivityManager implements INopeConnectivityManager { options: INopeINopeConnectivityOptions; protected _generateObservable: <T>() => INopeObservable<T>; readonly id: string; protected _logger: ILogger; protected _deltaTime: number; protected _connectedSince: number; /** * The used Communication interface * * @type {ICommunicationBridge} * @memberof NopeConnectivityManager */ protected readonly _communicator: ICommunicationBridge; /** * A Map holding the current Status of external dispatchers. * Key = Dispatcher-ID * Value = Last Known status of the dispatcher * * @protected * @type {Map<string, INopeStatusInfo>} * @memberof NopeConnectivityManager */ protected _externalDispatchers: Map<string, INopeStatusInfo>; /** * Timeout settings. This will define the Timers etc. * * @author M.Karkowski * @protected * @type {INopeINopeConnectivityTimeOptions} * @memberof NopeConnectivityManager */ protected _timeouts: INopeINopeConnectivityTimeOptions; protected _checkInterval: any; protected _sendInterval: any; protected _cpuInterval: any; /** * Internal var to hold the cpu-load * * @author M.Karkowski * @protected * @memberof NopeConnectivityManager */ protected _cpuLoad: number; readonly ready: INopeObservable<boolean>; readonly dispatchers: IMapBasedMergeData<string, // Dispatcher ID INopeStatusInfo, // Orginal Message string, // Dispatcher ID string>; /** * see {@link INopeConnectivityManager.info} * * @author M.Karkowski * @readonly * @type {INopeStatusInfo} * @memberof NopeConnectivityManager */ get info(): INopeStatusInfo; /** * Helper to extract the info of the dispatcher. * @returns */ protected _info(): INopeStatusInfo; /** * Creates an instance of NopeConnectivityManager. * @author M.Karkowski * @param {INopeINopeConnectivityOptions} options The Options, used by the Manager. * @param {<T>() => INopeObservable<T>} _generateObservable A Helper, to generate Observables. * @param {string} [id=null] specific id. Otherwise a ID is generated * @memberof NopeConnectivityManager */ constructor(options: INopeINopeConnectivityOptions, _generateObservable: <T>() => INopeObservable<T>, id?: string); /** * see {@link INopeConnectivityManager.upTime} * * @author M.Karkowski * @readonly * @type {number} * @memberof NopeConnectivityManager */ get upTime(): number; /** * see {@link INopeConnectivityManager.connectedSince} * * @author M.Karkowski * @readonly * @type {number} * @memberof NopeConnectivityManager */ get connectedSince(): number; /** * Internal value to store the Master. * * @author M.Karkowski * @protected * @type {boolean} * @memberof NopeConnectivityManager */ protected __isMaster: boolean; /** * see {@link INopeConnectivityManager.isMaster} * * @author M.Karkowski * @memberof NopeConnectivityManager */ set isMaster(value: boolean | null); /** * see {@link INopeConnectivityManager.isMaster} * * @author M.Karkowski * @type {boolean} * @memberof NopeConnectivityManager */ get isMaster(): boolean; /** * Helper, to extract the possible-masters * @returns */ protected _getPossibleMasterCandidates(): INopeStatusInfo[]; /** * see {@link INopeConnectivityManager.master} * * @author M.Karkowski * @readonly * @type {INopeStatusInfo} * @memberof NopeConnectivityManager */ get master(): INopeStatusInfo; /** * see {@link INopeConnectivityManager.now} * * @author M.Karkowski * @readonly * @type {number} * @memberof NopeConnectivityManager */ get now(): number; /** * Internal Function, used to initialize the Dispatcher. * It subscribes to the "Messages" of the communicator. * * @protected * @memberof NopeConnectivityManager */ protected _init(): Promise<void>; /** * Function, which will be called to update the * Status to the Dispatchers * * @author M.Karkowski * @protected * @memberof NopeConnectivityManager */ protected _checkDispatcherHealth(): void; /** * Removes a Dispatcher. * * @author M.Karkowski * @protected * @param {string} dispatcher The Id of the dispatcher * @param {boolean} [quiet=false] if set to quiet, the *dispatchers* attribute wont be udpated. * @memberof NopeConnectivityManager */ protected _removeDispatcher(dispatcher: string, quiet?: boolean): void; /** * Helper to send the current status to other statusmanagers. * * @author M.Karkowski * @protected * @memberof NopeConnectivityManager */ protected _sendStatus(forced?: boolean): Promise<void>; /** * see {@link INopeConnectivityManager.syncTime} * * @author M.Karkowski * @param {number} timestamp * @param {number} [delay=0] * @memberof NopeConnectivityManager */ syncTime(timestamp: number, delay?: number): void; /** * see {@link INopeConnectivityManager.getStatus} * * @author M.Karkowski * @param {string} id * @return {*} * @memberof NopeConnectivityManager */ getStatus(id: string): INopeStatusInfo; /** * see {@link INopeConnectivityManager.emitBonjour} * * @author M.Karkowski * @return {Promise<void>} * @memberof NopeConnectivityManager */ emitBonjour(): Promise<void>; /** * see {@link INopeConnectivityManager.reset} * * @author M.Karkowski * @memberof NopeConnectivityManager */ reset(): void; /** * see {@link INopeConnectivityManager.setTimings} * * @author M.Karkowski * @param {Partial<INopeINopeConnectivityTimeOptions>} options * @memberof NopeConnectivityManager */ setTimings(options: Partial<INopeINopeConnectivityTimeOptions>): void; /** * see {@link INopeConnectivityManager.getAllHosts} * * @author M.Karkowski * @return {*} {string[]} * @memberof NopeConnectivityManager */ getAllHosts(): string[]; /** * Will dispose the Dispatcher. Must be called on exit for a clean exit. Otherwise it is defined as dirty exits */ dispose(quiet?: boolean): Promise<void>; /** * Describes the Data. * @returns */ toDescription(): { dispatchers: string[]; }; }