Class DefaultConfigurationWorker
java.lang.Object
io.openems.common.worker.AbstractWorker
io.openems.edge.core.componentmanager.ComponentManagerWorker
io.openems.edge.core.componentmanager.DefaultConfigurationWorker
- All Implemented Interfaces:
org.osgi.service.cm.ConfigurationListener
This Worker checks if certain OpenEMS-Components are configured and - if not
- configures them. It is used to make sure a set of standard components are
always activated by default on a deployed energy management system.
Example 1: Add JSON/REST-Api Controller by default:
if (existingConfigs.stream().noneMatch(c -> // // Check if either "Controller.Api.Rest.ReadOnly" or // "Controller.Api.Rest.ReadWrite" exist "Controller.Api.Rest.ReadOnly".equals(c.factoryPid) || "Controller.Api.Rest.ReadWrite".equals(c.factoryPid))) { // if not -> create configuration for "Controller.Api.Rest.ReadOnly" this.createConfiguration(defaultConfigurationFailed, "Controller.Api.Rest.ReadOnly", Arrays.asList(// new Property("id", "ctrlApiRest0"), // new Property("alias", ""), // new Property("enabled", true), // new Property("port", 8084), // new Property("debugMode", false) // )); }
Example 2: Add Modbus/TCP-Api Controller by default:
if (existingConfigs.stream().noneMatch(c -> // // Check if either "Controller.Api.Rest.ReadOnly" or // "Controller.Api.Rest.ReadWrite" exist "Controller.Api.ModbusTcp.ReadOnly".equals(c.factoryPid) || "Controller.Api.ModbusTcp.ReadWrite".equals(c.factoryPid))) { // if not -> create configuration for "Controller.Api.Rest.ReadOnly" this.createConfiguration(defaultConfigurationFailed, "Controller.Api.ModbusTcp.ReadOnly", Arrays.asList(// new Property("id", "ctrlApiModbusTcp0"), // new Property("alias", ""), // new Property("enabled", true), // new Property("port", 502), // new Property("component.ids", JsonUtils.buildJsonArray().add("_sum").build()), // new Property("maxConcurrentConnections", 5) // )); }
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Holds a configuration. -
Field Summary
Fields inherited from class io.openems.edge.core.componentmanager.ComponentManagerWorker
parent
Fields inherited from class io.openems.common.worker.AbstractWorker
ALWAYS_WAIT_FOR_TRIGGER_NEXT_RUN, DO_NOT_WAIT, thread
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
createConfiguration
(AtomicBoolean defaultConfigurationFailed, String factoryPid, List<UpdateComponentConfigRequest.Property> properties) Creates a Component configuration.protected void
deleteConfiguration
(AtomicBoolean defaultConfigurationFailed, String componentId) Deletes a Component configuration.protected void
forever()
This method is called in a loop forever until the Thread gets interrupted.protected int
Gets the cycleTime of this worker in [ms].protected void
updateConfiguration
(AtomicBoolean defaultConfigurationFailed, String componentId, List<UpdateComponentConfigRequest.Property> properties) Updates a Component configuration.Methods inherited from class io.openems.edge.core.componentmanager.ComponentManagerWorker
configurationEvent, debugLog
Methods inherited from class io.openems.common.worker.AbstractWorker
activate, activate, deactivate, modified, modified, setPriority, triggerNextRun
-
Constructor Details
-
DefaultConfigurationWorker
-
-
Method Details
-
forever
protected void forever()Description copied from class:AbstractWorker
This method is called in a loop forever until the Thread gets interrupted.- Specified by:
forever
in classAbstractWorker
-
createConfiguration
protected void createConfiguration(AtomicBoolean defaultConfigurationFailed, String factoryPid, List<UpdateComponentConfigRequest.Property> properties) Creates a Component configuration.- Parameters:
defaultConfigurationFailed
- the result of the last configuration, updated on errorfactoryPid
- the Factory-PIDproperties
- the Component properties
-
updateConfiguration
protected void updateConfiguration(AtomicBoolean defaultConfigurationFailed, String componentId, List<UpdateComponentConfigRequest.Property> properties) Updates a Component configuration.- Parameters:
defaultConfigurationFailed
- the result of the last configuration, updated on errorcomponentId
- the Component-IDproperties
- the Component properties
-
deleteConfiguration
Deletes a Component configuration.- Parameters:
defaultConfigurationFailed
- the result of the last configuration, updated on errorcomponentId
- the Component-ID
-
getCycleTime
protected int getCycleTime()Description copied from class:AbstractWorker
Gets the cycleTime of this worker in [ms].- > 0 sets the minimum execution time of one Cycle
- = 0 never wait between two consecutive executions of forever()
- < 0 causes the Cycle to sleep forever until 'triggerNextRun()' is called
- Specified by:
getCycleTime
in classAbstractWorker
- Returns:
- the cycleTime
-