Class MockingConnectorServiceWrapper<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>
de.iip_ecosphere.platform.services.environment.MockingConnectorServiceWrapper<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:
de.iip_ecosphere.platform.connectors.events.EventHandlingConnector, ParameterConfigurerProvider, Service, ServiceBase

public class MockingConnectorServiceWrapper<O,I,CO,CI> extends ConnectorServiceWrapper<O,I,CO,CI> implements de.iip_ecosphere.platform.connectors.events.EventHandlingConnector
Mocks a ConnectorServiceWrapper by data in a JSON file through DataMapper. JSON data may contain meta values $period or $repeats as for DataMapper.BaseDataUnitFunctions.
Author:
Holger Eichelberger, SSE
  • Field Details

    • connectorOutType

      private Class<? extends CO> connectorOutType
    • callback

      private de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CO> callback
    • inputCallback

      private de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CI> inputCallback
    • connParamSupplier

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

      private boolean enableNotifications
    • fileName

      private String fileName
    • dataRunnable

    • cachingStrategy

      private de.iip_ecosphere.platform.connectors.CachingStrategy cachingStrategy
    • triggerIterator

      private de.iip_ecosphere.platform.support.json.IOIterator<? extends CO> triggerIterator
    • recorder

      private DataRecorder recorder
    • storage

      private Map<String,Object> storage
    • notificationInterval

      private int notificationInterval
  • Constructor Details

    • MockingConnectorServiceWrapper

      public MockingConnectorServiceWrapper(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

    • createDataRecorder

      protected DataRecorder createDataRecorder()
      Creates an optional data recorder instance.
      Returns:
      the data recorder instance, may be null for none
      See Also:
    • createDataRecorderOrig

      protected final DataRecorder createDataRecorderOrig()
      Creates a default data recorder instance (writes to target in JSON format). Cannot be overriden to be accessible to subclasses although createDataRecorder() is overridden.
      Returns:
      the data recorder instance, may be null for none
      See Also:
    • send

      public void send(CI data)
      Calls Connector.write(Object) on data and handles the respective exception potentially thrown by the underlying connector.
      Overrides:
      send in class ConnectorServiceWrapper<O,I,CO,CI>
      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.
      Overrides:
      setReceptionCallback in class ConnectorServiceWrapper<O,I,CO,CI>
      Parameters:
      callback - the callback to attach
    • getDataStream

      protected InputStream getDataStream(String name)
      Returns the input data stream for mocking. Considers ".yml" (legacy, typo) and ".json" files.
      Parameters:
      name - the name of the file/resource to be used
      Returns:
      the stream, may be null
    • openDataStream

      protected InputStream openDataStream(String name)
      Tries to open an input data stream for mocking.
      Parameters:
      name - the name of the file/resource to be used
      Returns:
      the stream, may be null
    • startData

      private void startData(Supplier<Boolean> continueFunction) throws IOException
      Starts data ingestion.
      Parameters:
      continueFunction - supplier indicating whether further data shall be ingested although still potential input data may be available
      Throws:
      IOException - if the data file cannot be found/opened
    • handleReceived

      private void handleReceived(CO data, int notifInterval)
      Handles received data.
      Parameters:
      data - the data
      notifInterval - the notification interval causing a sleep if data was sent, ignored if not positive
    • startDataThread

      private void startDataThread()
      Starts a parallel thread for data ingestion. Non-blocking execution is typically required by a streaming engine.
    • 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 ConnectorServiceWrapper<O,I,CO,CI>
      Parameters:
      state - the new state
      Throws:
      ExecutionException - if changing the state fails for some reason
      See Also:
    • 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]
      Specified by:
      migrate in interface Service
      Overrides:
      migrate in class ConnectorServiceWrapper<O,I,CO,CI>
      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.
      Specified by:
      update in interface Service
      Overrides:
      update in class ConnectorServiceWrapper<O,I,CO,CI>
      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]
      Specified by:
      switchTo in interface Service
      Overrides:
      switchTo in class ConnectorServiceWrapper<O,I,CO,CI>
      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)
      Description copied from class: ConnectorServiceWrapper
      Enable/disable polling (does not influence the polling timer).
      Specified by:
      enablePolling in interface de.iip_ecosphere.platform.connectors.events.EventHandlingConnector
      Overrides:
      enablePolling in class ConnectorServiceWrapper<O,I,CO,CI>
      Parameters:
      enablePolling - whether polling shall enabled
      See Also:
    • enableNotifications

      public void enableNotifications(boolean enableNotifications)
      Description copied from class: ConnectorServiceWrapper
      Enables/disables notifications/polling at all.
      Overrides:
      enableNotifications in class ConnectorServiceWrapper<O,I,CO,CI>
      Parameters:
      enableNotifications - enable or disable notifications
    • emitData

      public void emitData(CI data)
      Emits data received from the platform.
      Parameters:
      data - the last data
    • setInputCallback

      public void setInputCallback(de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CI> inputCallback)
      Sets a callback on data received from the platform.
      Parameters:
      inputCallback - the input callback, may be null for none
    • trigger

      public void trigger()
      Specified by:
      trigger in interface de.iip_ecosphere.platform.connectors.events.EventHandlingConnector
    • trigger

      public void trigger(de.iip_ecosphere.platform.connectors.events.ConnectorTriggerQuery query)
      Specified by:
      trigger in interface de.iip_ecosphere.platform.connectors.events.EventHandlingConnector
    • setStorageValue

      public void setStorageValue(String key, Object value)
      Specified by:
      setStorageValue in interface de.iip_ecosphere.platform.connectors.events.EventHandlingConnector
    • getStorageValue

      public Object getStorageValue(String key)
      Specified by:
      getStorageValue in interface de.iip_ecosphere.platform.connectors.events.EventHandlingConnector
    • setDataTimeDifference

      public void setDataTimeDifference(int difference)
      Specified by:
      setDataTimeDifference in interface de.iip_ecosphere.platform.connectors.events.EventHandlingConnector