Class AbstractOpenemsComponent

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractOpenemsComponent​(ChannelId[] firstInitialChannelIds, ChannelId[]... furtherInitialChannelIds)
      Default constructor for AbstractOpenemsComponent.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      Channel<?> _channel​(java.lang.String channelName)
      Deprecated.
      protected void activate​(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.String alias, boolean enabled)
      Handles @Activate of implementations.
      protected Channel<?> addChannel​(ChannelId channelId)
      Initializes the given Channel-ID.
      protected void addChannels​(ChannelId[] initialChannelIds)
      Initializes the given Channel-IDs.
      protected void addChannels​(ChannelId[][] initialChannelIds)
      Initializes the given Channel-IDs.
      java.lang.String alias()
      Returns a human-readable name of this Component..
      java.util.Collection<Channel<?>> channels()
      Returns all Channels.
      protected void deactivate()
      Handles @Deactivate of implementations.
      org.osgi.service.component.ComponentContext getComponentContext()
      Returns the ComponentContext.
      java.lang.String id()
      Returns a unique ID for this OpenEMS component.
      boolean isEnabled()
      Returns whether this component is enabled.
      protected void logDebug​(org.slf4j.Logger log, java.lang.String message)
      Log a debug message including the Component ID.
      protected void logError​(org.slf4j.Logger log, java.lang.String message)
      Log an error message including the Component ID.
      protected void logInfo​(org.slf4j.Logger log, java.lang.String message)
      Log an info message including the Component ID.
      protected void logWarn​(org.slf4j.Logger log, java.lang.String message)
      Log a warn message including the Component ID.
      protected void modified​(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.String alias, boolean enabled)
      Handles @Modified of implementations.
      protected void removeChannel​(Channel<?> channel)
      Removes a Channel from this Component.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractOpenemsComponent

        protected AbstractOpenemsComponent​(ChannelId[] firstInitialChannelIds,
                                           ChannelId[]... furtherInitialChannelIds)
        Default constructor for AbstractOpenemsComponent.

        Automatically initializes (i.e. creates Channel instances for each given OpenemsComponent.ChannelId using the Channel-Doc.

        It is important to list all Channel-ID enums of all inherited OpenEMS-Natures, i.e. for every OpenEMS Java interface you are implementing, you need to list the interface' ChannelID-enum here like Interface.ChannelId.values().

        Use as follows:

         public YourPhantasticOpenemsComponent() {
                super(//
                                OpenemsComponent.ChannelId.values(), //
                                YourPhantasticOpenemsComponent.ChannelId.values());
         }
         

        Note: the separation in firstInitialChannelIds and furtherInitialChannelIds is only there to enforce that calling the constructor cannot be forgotten. This way it needs to be called with at least one parameter - which is always at least "OpenemsComponent.ChannelId.values()". Just use it as if it was:

         AbstractOpenemsComponent(ChannelId[]... channelIds)
         
        Parameters:
        firstInitialChannelIds - the Channel-IDs to initialize.
        furtherInitialChannelIds - the Channel-IDs to initialize.
    • Method Detail

      • activate

        protected void activate​(org.osgi.service.component.ComponentContext context,
                                java.lang.String id,
                                java.lang.String alias,
                                boolean enabled)
        Handles @Activate of implementations. Prints log output.
        Parameters:
        context - the OSGi ComponentContext
        id - the unique OpenEMS Component ID
        alias - Human-readable name of this Component. Typically 'config.alias()'. Defaults to 'id' if empty
        enabled - is the Component enabled?
      • modified

        protected void modified​(org.osgi.service.component.ComponentContext context,
                                java.lang.String id,
                                java.lang.String alias,
                                boolean enabled)
        Handles @Modified of implementations.
        Parameters:
        context - the OSGi ComponentContext
        id - the unique OpenEMS Component ID
        alias - Human-readable name of this Component. Typically 'config.alias()'. Defaults to 'id' if empty
        enabled - is the Component enabled?
      • deactivate

        protected void deactivate()
        Handles @Deactivate of implementations. Prints log output.
      • 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
      • addChannel

        protected Channel<?> addChannel​(ChannelId channelId)
        Initializes the given Channel-ID.
        • Creates an object instance from Channel-Doc
        • Registers the Channel
        Parameters:
        channelId - the given Channel-ID
        Returns:
        the newly created Channel
      • addChannels

        protected void addChannels​(ChannelId[] initialChannelIds)
        Initializes the given Channel-IDs.
        • Creates object instances from Channel-Doc
        • Registers the Channels
        Parameters:
        initialChannelIds - the given Channel-IDs
      • addChannels

        protected void addChannels​(ChannelId[][] initialChannelIds)
        Initializes the given Channel-IDs.
        • Creates object instances from Channel-Doc
        • Registers the Channels
        Parameters:
        initialChannelIds - the given Channel-IDs
      • id

        public java.lang.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 java.lang.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
      • _channel

        @Deprecated
        public Channel<?> _channel​(java.lang.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
      • removeChannel

        protected void removeChannel​(Channel<?> channel)
        Removes a Channel from this Component.
        Parameters:
        channel - the Channel
      • logDebug

        protected void logDebug​(org.slf4j.Logger log,
                                java.lang.String message)
        Log a debug message including the Component ID.
        Parameters:
        log - the Logger instance
        message - the message
      • logInfo

        protected void logInfo​(org.slf4j.Logger log,
                               java.lang.String message)
        Log an info message including the Component ID.
        Parameters:
        log - the Logger instance
        message - the message
      • logWarn

        protected void logWarn​(org.slf4j.Logger log,
                               java.lang.String message)
        Log a warn message including the Component ID.
        Parameters:
        log - the Logger instance
        message - the message
      • logError

        protected void logError​(org.slf4j.Logger log,
                                java.lang.String message)
        Log an error message including the Component ID.
        Parameters:
        log - the Logger instance
        message - the message