Class ConnectorServiceWrapper<O,I,CO,CI>

java.lang.Object
de.iip_ecosphere.platform.services.environment.AbstractService
de.iip_ecosphere.platform.services.environment.ConnectorServiceWrapper<O,I,CO,CI>
Type Parameters:
O - the output type from the underlying machine/platform
I - the input type to the underlying machine/platform
CO - the output type of the connector
CI - the input type of the connector
All Implemented Interfaces:
ParameterConfigurerProvider, Service, ServiceBase
Direct Known Subclasses:
MockingConnectorServiceWrapper

public class ConnectorServiceWrapper<O,I,CO,CI> extends AbstractService
Wraps a connector into a service. Implicitly reacts on parameter "inPath" and "outPath" as string to override dynamically the configured data path into the connector data.
Author:
Holger Eichelberger, SSE
  • Field Details

    • connector

      private de.iip_ecosphere.platform.connectors.Connector<O,I,CO,CI> connector
    • connParamSupplier

      private Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> connParamSupplier
    • paramConfigurers

      private Map<String,ParameterConfigurer<?>> paramConfigurers
    • outPath

      private String outPath
    • inPath

      private String inPath
  • Constructor Details

    • ConnectorServiceWrapper

      public ConnectorServiceWrapper(YamlService yaml, de.iip_ecosphere.platform.connectors.Connector<O,I,CO,CI> connector, Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> connParamSupplier)
      Creates a service wrapper instance.
      Parameters:
      yaml - the service information as read from YAML
      connector - the connector instance to wrap
      connParamSupplier - the connector parameter supplier for connecting the underlying connector
  • Method Details

    • getConnector

      public de.iip_ecosphere.platform.connectors.Connector<O,I,CO,CI> getConnector()
      Returns the connector instance.
      Returns:
      the connector instance
    • send

      public void send(CI data)
      Calls Connector.write(Object) on data and handles the respective exception potentially thrown by the underlying connector.
      Parameters:
      data - the data to write
    • setReceptionCallback

      public void setReceptionCallback(de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CO> callback)
      Attaches a reception callback to this connector. The callback is called upon a reception. Handles the respective exception potentially thrown by the underlying connector.
      Parameters:
      callback - the callback to attach
    • setState

      public void setState(ServiceState state) throws ExecutionException
      Description copied from class: AbstractService
      Changes the state. [R133c]
      Specified by:
      setState in interface ServiceBase
      Overrides:
      setState in class AbstractService
      Parameters:
      state - the new state
      Throws:
      ExecutionException - if changing the state fails for some reason
      See Also:
    • doSetState

      protected void doSetState(ServiceState state) throws ExecutionException
      Changes the state by calling AbstractService.setState(ServiceState). Introduced, so that super functionality is made available to super-classes as-is.
      Parameters:
      state - the new state
      Throws:
      ExecutionException - if changing the state fails for some reason
    • migrate

      public void migrate(String resourceId) throws ExecutionException
      Description copied from interface: Service
      Migrates a service. However, it may be required to migrate/move the containing artifact. [adaptation]
      Parameters:
      resourceId - the target resource id, e.g., a device
      Throws:
      ExecutionException - if migration fails
    • update

      public void update(URI location) throws ExecutionException
      Description copied from interface: Service
      Updates the service by the service in the given location. This operation is responsible for stopping the running service (if needed), replacing it, starting the new service.
      Parameters:
      location - the location of the new service, e.g., an URL
      Throws:
      ExecutionException - if the given service cannot be updated for some reason, e.g., because the replacement service is not an evolved version of the running service
    • switchTo

      public void switchTo(String targetId) throws ExecutionException
      Description copied from interface: Service
      Switches to an interface-compatible service. This method cares for stopping the old service, performing a handover if adequate, starting the target service. [adaptation]
      Parameters:
      targetId - the id of the target service
      Throws:
      ExecutionException - if switching the service cannot be performed for some reason
    • enablePolling

      public void enablePolling(boolean enablePolling)
      Enable/disable polling (does not influence the polling timer).
      Parameters:
      enablePolling - whether polling shall enabled
      See Also:
    • enableNotifications

      public void enableNotifications(boolean enableNotifications)
      Enables/disables notifications/polling at all.
      Parameters:
      enableNotifications - enable or disable notifications
    • getParameterConfigurer

      public ParameterConfigurer<?> getParameterConfigurer(String paramName)
      Description copied from interface: ParameterConfigurerProvider
      Returns the parameter configurer for a given parameter. We need this generic approach to ease code generation and initial setting of parameter values.
      Parameters:
      paramName - the name of the parameter
      Returns:
      the associated parameter configurer or null if there is none
    • getParameterNames

      public Set<String> getParameterNames()
      Description copied from interface: ParameterConfigurerProvider
      The set of parameter names.
      Returns:
      the parameter names, may be null for none
    • setInPath

      private void setInPath(String inPath)
      Changes inPath.
      Parameters:
      inPath - the in path (ignored if null or empty)
    • setOutPath

      private void setOutPath(String outPath)
      Changes outPath.
      Parameters:
      outPath - the out path (ignored if null or empty)
    • getOutPath

      public String getOutPath(String cfgPath)
      Returns the (eventually re-configured) data access path within the protocol.
      Parameters:
      cfgPath - the configured path from the model
      Returns:
      the path to use, may be cfgPath
    • getInPath

      public String getInPath(String cfgPath)
      Returns the (eventually re-configured) data access path within the protocol.
      Parameters:
      cfgPath - the configured path from the model
      Returns:
      the path to use, may be cfgPath