Class 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.
    Author:
    Holger Eichelberger, SSE
    • Field Detail

      • connectorOutType

        private java.lang.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 java.util.function.Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> connParamSupplier
      • enableNotifications

        private boolean enableNotifications
      • fileName

        private java.lang.String fileName
      • cachingStrategy

        private de.iip_ecosphere.platform.connectors.CachingStrategy cachingStrategy
    • Constructor Detail

      • MockingConnectorServiceWrapper

        public MockingConnectorServiceWrapper​(YamlService yaml,
                                              de.iip_ecosphere.platform.connectors.Connector<O,​I,​CO,​CI> connector,
                                              java.util.function.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 Detail

      • 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 java.io.InputStream getDataStream​(java.lang.String name)
        The input data stream.
        Parameters:
        name - the name of the file/resource to be used
        Returns:
        the stream
      • startData

        private void startData​(java.util.function.Supplier<java.lang.Boolean> continueFunction)
                        throws java.io.IOException
        Starts data ingestion.
        Parameters:
        continueFunction - supplier indicating whether further data shall be ingested although still potential input data may be available
        Throws:
        java.io.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.
      • migrate

        public void migrate​(java.lang.String resourceId)
                     throws java.util.concurrent.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:
        java.util.concurrent.ExecutionException - if migration fails
      • update

        public void update​(java.net.URI location)
                    throws java.util.concurrent.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:
        java.util.concurrent.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​(java.lang.String targetId)
                      throws java.util.concurrent.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:
        java.util.concurrent.ExecutionException - if switching the service cannot be performed for some reason
      • 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