Base service implementation
npm install @kronos-integration/service









Base service implementation
``mermaid`
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~ | |~starting~
| 2 | | ~failed~ | |~starting~
| 3 | | ~running~ | |~running~
| 4 | | ~stopping~ | |~running~
| 5 | | ~failed~ | |~stopping~
| 6 | | ~failed~ | |~stopping~
| 7 | | ~stopped~ | |
* EndpointsMixin
* Parameters
* endpoints
* ServiceConfig
* Properties
* configFor
* Parameters
* clearPreserved
* Parameters
* configureValue
* Parameters
* configure
* Parameters
* autostart
* name
* merge
* Parameters
* defineServiceConsumerProperties
* Parameters
* ServiceLogger
* logEntry
* Parameters
* autostart
* name
* endpoints
* Service
* Parameters
* Properties
* extendetName
* stateChanged
* Parameters
* rejectWrongState
* Parameters
* timeoutForTransition
* Parameters
* \_start
* \_stop
* \_restart
* restartIfRunning
* toStringAttributes
* isServiceProvider
* toString
* toJSONWithOptions
* Parameters
* name
* autostart
* \_configure
* Parameters
* configure
* Parameters
* getCredential
* Parameters
* getCredentials
* Parameters
* storePersistentCredentials
* log
* Parameters
* attributes
* endpoints
* StandaloneServiceProvider
* name
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.
* preservedConfigs Map<string, Object> values for services not already established
Deliver configuration for a given service.
#### Parameters
* name string service nameconfig
* Object
Forget about preserved config of a service.
#### Parameters
* name string service name
Set config entry.
#### Parameters
* key string path to the valuevalue
* any
#### Parameters
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.
* a any b
* any
Returns any merged b into a
Assign services based on a configuration.
* target Object objectconfig
* Object service defintionprovider
* Object service providerwaitUntilFactoryPresent
* boolean
Extends Service
Log receiving service.
#### Parameters
* entry Object
* entry.severity string
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
* config Object ic
* InitializationContext
* endpoints Object
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.
#### Parameters
* origin any oldState
* string newState
* string
Called when state transition is not allowed.
#### Parameters
* action string originating action name
* Throws any always
Deliver transition timeout.
#### Parameters
* transition Object
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\
Restarts if in running mode.
Otherwise does nothing.
Returns Promise\
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.
#### Parameters
* options Object
* options.includeRuntimeInfo boolean include runtime informtion like stateoptions.includeDefaults
* boolean include default endpointsoptions.includeName
* boolean include name of the serviceoptions.includeConfig
* boolean include config attributesoptions.includePrivate
* boolean 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.
#### Parameters
* config Object
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.
#### Parameters
* config Object
Returns Promise<undefined> fillfills when config is applied
#### Parameters
* key string
Returns Promise<(string | Uint8Array)>
Retrieve all (filtered) credential attribute values.
#### Parameters
* filter Function (optional, default (name,attribute)=>attribute.credential)
Load and store persistent credentials in the service attributes.
Adds service name to the log event.
#### Parameters
* level string the log levelarg
* Object log content
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:
`shell``
npm install @kronos-integration/service
BSD-2-Clause