Class 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) //
            ));
     }
     
    • Constructor Detail

    • 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 class AbstractWorker
      • 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 error
        factoryPid - the Factory-PID
        properties - 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 error
        componentId - the Component-ID
        properties - 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 error
        componentId - 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 class AbstractWorker
        Returns: