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
public class DefaultConfigurationWorker extends ComponentManagerWorker
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
Nested Classes Modifier and Type Class Description protected static class
DefaultConfigurationWorker.Config
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
Constructors Constructor Description DefaultConfigurationWorker(ComponentManagerImpl parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
createConfiguration(java.util.concurrent.atomic.AtomicBoolean defaultConfigurationFailed, java.lang.String factoryPid, java.util.List<UpdateComponentConfigRequest.Property> properties)
Creates a Component configuration.protected void
deleteConfiguration(java.util.concurrent.atomic.AtomicBoolean defaultConfigurationFailed, java.lang.String componentId)
Deletes a Component configuration.protected void
forever()
This method is called in a loop forever until the Thread gets interrupted.protected int
getCycleTime()
Gets the cycleTime of this worker in [ms].protected void
updateConfiguration(java.util.concurrent.atomic.AtomicBoolean defaultConfigurationFailed, java.lang.String componentId, java.util.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, deactivate, modified, triggerNextRun
-
-
-
-
Constructor Detail
-
DefaultConfigurationWorker
public DefaultConfigurationWorker(ComponentManagerImpl parent)
-
-
Method Detail
-
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(java.util.concurrent.atomic.AtomicBoolean defaultConfigurationFailed, java.lang.String factoryPid, java.util.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(java.util.concurrent.atomic.AtomicBoolean defaultConfigurationFailed, java.lang.String componentId, java.util.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
protected void deleteConfiguration(java.util.concurrent.atomic.AtomicBoolean defaultConfigurationFailed, java.lang.String componentId)
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
-
-