UNPKG

nope-js-node

Version:

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

99 lines (98 loc) 6.27 kB
"use strict"; /** * @module dispatcher * @author Martin Karkowski * @email m.karkowski@zema.de * # NoPE - Dispatcher * *The NoPE-Dispatcher is designed as Layer between the different Modules / Dispatchers. They allow distributed computing or just a simple ***Service oriented Architecture*** (*SOA*). A dispatcher is used to link the modules, share data and events and provide a remote procedure call (rpc) interface. * *## Building Blocks of a Dispatcher: * *| element | description | *|-|-| *| `connectivityManager`: {@link connectivityManager} | establishes a connection to other dispatchers and manages the status of the remotely connected dispatchers. It checks their health and removes dead dispatchers. | *| `eventDistributor`: {@link PubSubSystem} | shares events accross the network (or internally). You can use this element to listen for specific events. The subscription to those events allows `mqtt`-patterns. Additionaly, you are allowed to emit event on specific topics, or pattern based topics | *| `dataDistributor`: {@link DataPubSubSystem} | shares data accross the network (or internally). In comperisson to events, data is persistent and is available all the time. You can use this sub-module to listen for specific data-changes (install data-hooks), pull specific data or push data. You can pull / push data using a `mqtt`-pattern based path. | *| `rpcManager`: {@link rpcManager} | Used to perform `remote procedure calls` (see [here](https://de.wikipedia.org/wiki/Remote_Procedure_Call)). The manager keeps track of the available services. You must use the sub-module to register/unregister (new) services. | *| `instanceManager`: {@link instanceManager} | Used to create/dispose (remote) instances. The manager keeps track of the available instances in the network, allows to create `wrappers` for those instances. You must use the sub-module to register/unregister (new) instances. To allow the system to provide a service for creating instances of as specific type, you can provide a generator and provide it as `service`. | * *## Create a Dispatcher * *To start exploring the capabilities of the dispatcher we will firstly create a dispatcher with the code below: * * *```javascript * // First lets install nope using npm * const nope = require("../dist-nodejs/index.nodejs") * * // Lets create our dispatcher * const dispatcher = nope.dispatcher.getDispatcher({ * // We will use the event layer (which just runs internally) * communicator: nope.getLayer("event"), * * // We will adapt the timings (normally, we send a hartbeat and check for dead dispatchers) * timings: { * * // Interval for the alive message given in [ms]. If "0" is provided, * // no alive messages are provided * sendAliveInterval: 0, * * // Interval, to check the other dispatcher for being slow, dead, etc.. * // should be lager then the "sendAliveInterval". The value is given in [ms] * // If "0" is provided, no alive messages are provided * checkInterval: 0 * * } * }); *``` * *## Settings for creating: * *The relevant Settings are described by the {@link INopeDispatcherOptions}. This options allows to define: * * the communication bridge. (use `getLayer` to receive a bridge with the specified layer) * * define a specific `id` * * provide a logger (otherwise the dispatcher wont log anything) * * define the timings for `heartbeats` and `checks` (see {@link INopeINopeConnectivityTimeOptions} for more details) * * a `defaultSelector` which is used as selector for a service provide * *## Playing with the dispatcher: * *To play with a dispatcher, you can use the `nope-js` repl tool. this tool creates a `dispatcher` and you are able to interact with the dispatcher in an interactive console. * * */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.rpcManager = exports.instanceManager = exports.connectivityManager = exports.baseServices = exports.getDispatcher = exports.nopeProperty = exports.nopeMethod = exports.nopeEmitter = exports.exportAsNopeService = exports.generateSelector = void 0; const baseServices = require("./baseServices"); exports.baseServices = baseServices; const connectivityManager = require("./ConnectivityManager"); exports.connectivityManager = connectivityManager; const instanceManager = require("./InstanceManager"); exports.instanceManager = instanceManager; const rpcManager = require("./RpcManager"); exports.rpcManager = rpcManager; var RpcManager_1 = require("./RpcManager"); Object.defineProperty(exports, "generateSelector", { enumerable: true, get: function () { return RpcManager_1.generateSelector; } }); var index_1 = require("../decorators/index"); Object.defineProperty(exports, "exportAsNopeService", { enumerable: true, get: function () { return index_1.exportAsNopeService; } }); Object.defineProperty(exports, "nopeEmitter", { enumerable: true, get: function () { return index_1.nopeEmitter; } }); Object.defineProperty(exports, "nopeMethod", { enumerable: true, get: function () { return index_1.nopeMethod; } }); Object.defineProperty(exports, "nopeProperty", { enumerable: true, get: function () { return index_1.nopeProperty; } }); __exportStar(require("../types/nope/nopeDispatcher.interface"), exports); var getDispatcher_1 = require("./getDispatcher"); Object.defineProperty(exports, "getDispatcher", { enumerable: true, get: function () { return getDispatcher_1.getDispatcher; } });