Class DummyComponentManager

java.lang.Object
io.openems.edge.common.test.DummyComponentManager
All Implemented Interfaces:
ClockProvider, ComponentManager, OpenemsComponent, JsonApi

public class DummyComponentManager extends Object implements ComponentManager
Simulates a ComponentManager for the OpenEMS Component test framework.
  • Constructor Details

    • DummyComponentManager

      public DummyComponentManager()
    • DummyComponentManager

      public DummyComponentManager(Clock clock)
  • Method Details

    • getEnabledComponents

      public List<OpenemsComponent> getEnabledComponents()
      Description copied from interface: ComponentManager
      Gets all enabled OpenEMS-Components.

      Be aware that via this method usage of the Component service is not tracked by the bundle's use count (See BundleContext.getService(org.osgi.framework.ServiceReference)). Make sure to use the references as shortly as possible.

      Specified by:
      getEnabledComponents in interface ComponentManager
      Returns:
      a List of OpenEMS-Components
    • getAllComponents

      public List<OpenemsComponent> getAllComponents()
      Description copied from interface: ComponentManager
      Gets all OpenEMS-Components.

      Be aware that via this method usage of the Component service is not tracked by the bundle's use count (See BundleContext.getService(org.osgi.framework.ServiceReference)). Make sure to use the references as shortly as possible.

      Specified by:
      getAllComponents in interface ComponentManager
      Returns:
      a List of OpenEMS-Components
    • getEnabledComponentsOfType

      public <T extends OpenemsComponent> List<T> getEnabledComponentsOfType(Class<T> clazz)
      Description copied from interface: ComponentManager
      Gets all enabled OpenEMS-Components of the given Type.

      Be aware that via this method usage of the Component service is not tracked by the bundle's use count (See BundleContext.getService(org.osgi.framework.ServiceReference)). Make sure to use the references as shortly as possible.

      Specified by:
      getEnabledComponentsOfType in interface ComponentManager
      Type Parameters:
      T - the given Type, subclass of OpenemsComponent
      Parameters:
      clazz - the given Type, subclass of OpenemsComponent
      Returns:
      a List of OpenEMS-Components
    • getComponent

      public <T extends OpenemsComponent> T getComponent(String componentId) throws OpenemsError.OpenemsNamedException
      Description copied from interface: ComponentManager
      Gets a OpenEMS-Component by its Component-ID. The Component is guaranteed to be enabled.

      Be aware that via this method usage of the Component service is not tracked by the bundle's use count (See BundleContext.getService(org.osgi.framework.ServiceReference)). Make sure to use the references as shortly as possible.

      Specified by:
      getComponent in interface ComponentManager
      Type Parameters:
      T - the typed Component
      Parameters:
      componentId - the Component-ID (e.g. "_sum")
      Returns:
      the OpenEMS-Component
      Throws:
      OpenemsError.OpenemsNamedException - if the Component was not found
    • getPossiblyDisabledComponent

      public <T extends OpenemsComponent> T getPossiblyDisabledComponent(String componentId) throws OpenemsError.OpenemsNamedException
      Description copied from interface: ComponentManager
      Gets a OpenEMS-Component by its Component-ID. Be careful, that the Component might not be 'enabled'. If in doubt, use ComponentManager.getComponent(String) instead.

      Be aware that via this method usage of the Component service is not tracked by the bundle's use count (See BundleContext.getService(org.osgi.framework.ServiceReference)). Make sure to use the references as shortly as possible.

      Specified by:
      getPossiblyDisabledComponent in interface ComponentManager
      Type Parameters:
      T - the typed Component
      Parameters:
      componentId - the Component-ID (e.g. "_sum")
      Returns:
      the OpenEMS-Component
      Throws:
      OpenemsError.OpenemsNamedException - if the Component was not found
    • addComponent

      public DummyComponentManager addComponent(OpenemsComponent component)
      Specific for this Dummy implementation.
      Parameters:
      component - the component that should be added
      Returns:
      this
    • setConfigJson

      public void setConfigJson(com.google.gson.JsonObject json)
      Sets a EdgeConfig json.
      Parameters:
      json - the EdgeConfig json
    • getEdgeConfig

      public EdgeConfig getEdgeConfig()
      Description copied from interface: ComponentManager
      Gets the complete configuration of this OpenEMS Edge.

      Internally updates the cache if necessary and publishes a CONFIG_UPDATE event on update.

      Specified by:
      getEdgeConfig in interface ComponentManager
      Returns:
      the EdgeConfig object
    • id

      public String id()
      Description copied from interface: OpenemsComponent
      Returns a unique ID for this OpenEMS component.
      Specified by:
      id in interface OpenemsComponent
      Returns:
      the unique ID
    • alias

      public String alias()
      Description copied from interface: OpenemsComponent
      Returns a human-readable name of this Component..
      Specified by:
      alias in interface OpenemsComponent
      Returns:
      the human-readable name
    • isEnabled

      public boolean isEnabled()
      Description copied from interface: OpenemsComponent
      Returns whether this component is enabled.
      Specified by:
      isEnabled in interface OpenemsComponent
      Returns:
      true if the component is enabled
    • getComponentContext

      public org.osgi.service.component.ComponentContext getComponentContext()
      Description copied from interface: OpenemsComponent
      Returns the ComponentContext.
      Specified by:
      getComponentContext in interface OpenemsComponent
      Returns:
      the OSGi ComponentContext
    • _channel

      @Deprecated public Channel<?> _channel(String channelName)
      Deprecated.
      Description copied from interface: OpenemsComponent
      Returns an undefined Channel defined by its ChannelId string representation.

      Note: It is preferred to use the typed channel()-method, that's why it is marked as @Deprecated.

      Specified by:
      _channel in interface OpenemsComponent
      Parameters:
      channelName - the Channel-ID as a string
      Returns:
      the Channel or null
    • channels

      public Collection<Channel<?>> channels()
      Description copied from interface: OpenemsComponent
      Returns all Channels.
      Specified by:
      channels in interface OpenemsComponent
      Returns:
      a Collection of Channels
    • handleJsonrpcRequest

      Description copied from interface: JsonApi
      Handles a JSON-RPC Request.
      Specified by:
      handleJsonrpcRequest in interface JsonApi
      Parameters:
      user - the authenticated User
      request - the JSON-RPC Request
      Returns:
      a Future JSON-RPC Success Response; null response results in a OpenemsError.JSONRPC_UNHANDLED_METHOD
      Throws:
      OpenemsError.OpenemsNamedException - on error
    • getClock

      public Clock getClock()
      Description copied from interface: ComponentManager
      Gets the OpenEMS Clock - either the real system clock or a mocked clock for simulations.
      Specified by:
      getClock in interface ClockProvider
      Specified by:
      getClock in interface ComponentManager
      Returns:
      the Clock
    • setConfigurationAdmin

      public void setConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin configurationAdmin)