Base service implementation
stateDiagram-v2
stopped --> starting [1]
starting --> failed: [2]
starting --> running: [3]
running --> stopping: [4]
running --> failed: [5]
stopping --> failed: [6]
stopping --> stopped: [7]
The transitions are:
| Number | From | To | Condition |
|---|---|---|---|
| 1 | ~stopped~ |
~starting~ |
|
| 2 | ~starting~ |
~failed~ |
|
| 3 | ~starting~ |
~running~ |
|
| 4 | ~running~ |
~stopping~ |
|
| 5 | ~running~ |
~failed~ |
|
| 6 | ~stopping~ |
~failed~ |
|
| 7 | ~stopping~ |
~stopped~ |
- EndpointsMixin
- endpoints
- ServiceConfig
- merge
- defineServiceConsumerProperties
- ServiceLogger
- Service
- Parameters
- Properties
- extendetName
- stateChanged
- rejectWrongState
- timeoutForTransition
- _start
- _stop
- _restart
- restartIfRunning
- toStringAttributes
- isServiceProvider
- toString
- toJSONWithOptions
- name
- autostart
- _configure
- configure
- getCredential
- getCredentials
- storePersistentCredentials
- log
- attributes
- endpoints
- StandaloneServiceProvider
Endpoint accessor mixin. Manages endpoints in a container.
superclass
Default set of endpoints to create.
Returns Object {} empty set
Extends Service
Config providing service. Dispatches config requests to services. Also preserves them until a maching service becomes avaliable.
Deliver configuration for a given service.
Forget about preserved config of a service.
namestring service name
Set config entry.
keystring path to the valuevalueany
We always start immediate.
Returns boolean true
Returns string 'config'
Merge from b into a. When a and b are arrays of values only the none duplicates are appendend to a.
aanybany
Returns any merged b into a
Assign services based on a configuration.
targetObject objectconfigObject service defintionproviderObject service providerwaitUntilFactoryPresentboolean
Extends Service
Log receiving service.
We always start immediate.
Returns boolean true
Returns string 'logger'
Adds a log input endpoint to the set of Service endpoints.
Returns Object predefined endpoints
Extends EndpointsMixin(StateTransitionMixin(LogLevelMixin(class {}), prepareActions({ start: { stopped: rsfDefault }, restart: { stopped: rsfDefault, running: { target: "running", during: "restarting", timeout } }, stop: { running: ssfDefault, starting: ssfDefault, failed: ssfDefault } }), "stopped"))
Service The initial state is 'stopped'. All services have at least three endpoints:
- log out: log events
- config in: configuration request
- command in: administrative actions to be executed by the step
configObjecticInitializationContext
endpointsObject
Used in human readable state messages. Besides the actual service name it may contain additional short hints.
Returns string
Called when the service state changes. Emits a serviceStateChanged event to the owner.
Called when state transition is not allowed.
actionstring originating action name
- Throws any always
Deliver transition timeout.
transitionObject
Returns number milliseconds before throwing for a long running transition
Opens all endpoint connections.
Closes all endpoint connections.
Restart action. default implementation does a _stop() and a _start()
Returns Promise<any> fulfills after start
Restarts if in running mode. Otherwise does nothing.
Returns Promise<any> resolves when restart is done (or immediate if no restart triggered)
Mapping of properties used in toString.
Returns Object
Base service is not a provider.
Returns boolean false
Returns the string representation of this service.
Returns string human readable name
Deliver json representation.
-
optionsObjectoptions.includeRuntimeInfoboolean include runtime informtion like stateoptions.includeDefaultsboolean include default endpointsoptions.includeNameboolean include name of the serviceoptions.includeConfigboolean include config attributesoptions.includePrivateboolean include private config attributes
Returns Object json representation
Defaults to the type.
Returns string type
Should we start when beeing registered.
Returns boolean false
Takes attribute values from config parameters and copies them over to the object. Copying is done according to attributes. Which means we loop over all configuration attributes. and then for each attribute decide if we use the default, call a setter function or simply assign the attribute value.
configObject
Returns Set<string> of modified attributes
Use new configuration. Internally calls _configure(config) as the constructor does. If attribute with needsRestart are touched the restartIfRunning method will be called.
configObject
Returns Promise<undefined> fillfills when config is applied
keystring
Returns Promise<(string | Uint8Array)>
Retrieve all (filtered) credential attribute values.
filterFunction (optional, default(name,attribute)=>attribute.credential)
Load and store persistent credentials in the service attributes.
Adds service name to the log event.
Meta information for the config attributes.
- default optional default value of the attribute
- needsRestart optional modification requires a service restart
- setter(newValue,attribute) optional function to be used if simple value assignment is not enough The Service class only defines the logLevel, and start/stop/restart timeout attribute
Returns Object
Definition of the predefined endpoints.
- log out
- config in
Returns Object predefined endpoints
Extends ServiceProviderMixin(Service)
Simple service manager (for examples and testing only).
Returns string 'standalone-provider'
With npm do:
npm install @kronos-integration/serviceBSD-2-Clause