Class TransportConverter<T>

java.lang.Object
de.iip_ecosphere.platform.services.environment.services.TransportConverter<T>
Type Parameters:
T - the data type
Direct Known Subclasses:
TransportToAasConverter, TransportToWsConverter

public abstract class TransportConverter<T> extends Object
Implements a generic converter from transport stream entries to some protocol.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • TransportConverter

      public TransportConverter(String transportStream, Class<T> dataType)
      Creates a service instance.
      Parameters:
      transportStream - the transport stream to be observed (name of the stream)
      dataType - the type of the data in the transport stream
    • TransportConverter

      public TransportConverter(String transportStream, Class<T> dataType, Predicate<T> handleNewFilter)
      Creates a service instance.
      Parameters:
      transportStream - the transport stream to be observed (name of the stream)
      dataType - the type of the data in the transport stream
      handleNewFilter - filter for handleNew(Object), may be null
  • Method Details

    • setHandleNewFilter

      public void setHandleNewFilter(Predicate<T> handleNewFilter)
      Sets a filter for handleNew(Object).
      Parameters:
      handleNewFilter - filter for handleNew(Object), may be null
    • setExcludedFields

      public void setExcludedFields(Set<String> excludedFields)
      Sets the excluded fields for handleNew(Object).
      Parameters:
      excludedFields - the excluded fields, may be null or empty for none
    • isExcludedField

      public boolean isExcludedField(String fieldName)
      Returns whether fieldName is excluded.
      Parameters:
      fieldName - the name of the field
      Returns:
      true for excluded, false else
    • getExcludedFieldsArray

      protected String[] getExcludedFieldsArray()
      Returns the excluded fields array.
      Returns:
      the excluded fields as array
    • addNotifier

      public void addNotifier(de.iip_ecosphere.platform.support.function.IOConsumer<T> notifier)
      Defines a new notifier which is called when new data arrives. Currently only one notifier is supported.
      Parameters:
      notifier - the notifier, ignored if null
    • handleNew

      protected abstract void handleNew(T data)
      Handles a new trace record. Called upon arrival. [protected for mocking]
      Parameters:
      data - the trace record data
    • handleNewAndNotify

      private void handleNewAndNotify(T data)
      Handles a new trace record by calling handleNew(Object) upon arrival. Entry point for handling new data, calling handleNew(Object) to ensure that notifier are processed.
      Parameters:
      data - the trace record data
    • getValue

      protected Object getValue(Object object, Method method, String field)
      Obtains the value return by method on payload.
      Parameters:
      object - the object to call the method on
      method - the method to call
      field - the represented field (for logging)
      Returns:
      the value of field via method
    • mapPayloadType

      protected String mapPayloadType(Class<?> cls)
      Allows for application specific payload type names.
      Parameters:
      cls - the type
      Returns:
      the mapped name
    • isGetter

      protected static boolean isGetter(Method method)
      Returns whether method is an usual getter.
      Parameters:
      method - the method to analyze
      Returns:
      true for getter, false else
    • getType

      protected final Class<T> getType()
      Returns the handled data type.
      Returns:
      the type
    • initializeSubmodel

      public void initializeSubmodel(de.iip_ecosphere.platform.support.aas.Submodel.SubmodelBuilder smBuilder)
      Initializes the submodel.
      Parameters:
      smBuilder - the submodel builder
    • start

      public void start(de.iip_ecosphere.platform.support.iip_aas.AasPartRegistry.AasSetup aasSetup)
      Starts the transport tracer.
      Parameters:
      aasSetup - the AAS setup to use
    • isAasEnabled

      protected boolean isAasEnabled()
      Returns whether the converter functionality shall be enabled. [requires renaming]
      Returns:
      true for enabled, false else
    • setAasEnabledSupplier

      public void setAasEnabledSupplier(Supplier<Boolean> enabledSupplier)
      Changes the optional supplier for the AAS enabled state. [requires renaming]
      Parameters:
      enabledSupplier - the new supplier, ignored if null
    • isAasStarted

      public boolean isAasStarted()
      Returns whether the AAS was started/startup is done.
      Returns:
      true for started, false else
    • setTimeout

      public void setTimeout(long timeout)
      Changes the timeout until trace events are deleted.
      Parameters:
      timeout - the timeout in ms
    • setCleanupTimeout

      public void setCleanupTimeout(long cleanupTimeout)
      Changes the cleanup timeout, i.e., the time between two cleanups.
      Parameters:
      cleanupTimeout - the timeout in ms, disables cleanup if negative
    • cleanup

      public boolean cleanup()
      Pursues a cleanup of the internal data structures, if applicable.
      Returns:
      whether a cleanup process was executed (not whether elements were deleted)
    • stop

      public void stop()
      Stops the transport, deletes the AAS.
    • getEndpoint

      public de.iip_ecosphere.platform.support.Endpoint getEndpoint()
      Returns the server endpoint to connect to.
      Returns:
      the server endpoint, may be null for none, in particular if this connector is hosted by an AAS
    • isTraceInAas

      public boolean isTraceInAas()
      Returns whether traced data is directly stored in the AAS or not.
      Returns:
      true for traced data in AAS, false else
    • createWatcher

      public abstract TransportConverter.Watcher<T> createWatcher(int period)
      Creates a watcher instance.
      Parameters:
      period - the watching period in ms
      Returns:
      the watcher
    • getEndpoint

      public static de.iip_ecosphere.platform.support.aas.SubmodelElementCollection getEndpoint(de.iip_ecosphere.platform.support.aas.ElementContainer parent, String path)
      Returns an AAS submodel element collection representing an endpoint.
      Parameters:
      parent - the parent submodel or element collection
      path - the URI path used as id to represent the endpoint
      Returns:
      the submodel element collection or null for none
    • getEndpoint

      public static de.iip_ecosphere.platform.support.Endpoint getEndpoint(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection endpoint)
      Turns a submodel element collection with endpoint information into an endpoint object.
      Parameters:
      endpoint - the submodel, e.g., from getEndpoint(ElementContainer, String)
      Returns:
      the endpoint object, may be null if the object cannot be created
    • toAasEndpointId

      public static String toAasEndpointId(String path)
      Turns an URI path into an endpoint AAS idShort.
      Parameters:
      path - the path
      Returns:
      the idShort
    • addEndpointToAas

      public static void addEndpointToAas(de.iip_ecosphere.platform.support.aas.SubmodelElementContainerBuilder smBuilder, de.iip_ecosphere.platform.support.Endpoint endpoint)
      Adds an endpoint to a given (endpoint) submodel/elements collection.
      Parameters:
      smBuilder - the submodel/elements collection builder
      endpoint - the endpoint, may be null