Class AbstractTransportConnector

java.lang.Object
de.iip_ecosphere.platform.transport.connectors.impl.AbstractTransportConnector
All Implemented Interfaces:
TransportConnector
Direct Known Subclasses:
AbstractMqttTransportConnector, DirectMemoryTransferTransportConnector, PrintTransportConnector

public abstract class AbstractTransportConnector extends Object implements TransportConnector
An abstract transport connector.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • AbstractTransportConnector

      public AbstractTransportConnector()
  • Method Details

    • useTls

      protected boolean useTls(TransportParameter params)
      Returns whether the connector shall use TLS.
      Parameters:
      params - the transport parameters
      Returns:
      true for TLS enabled, false else
    • createTlsContext

      protected SSLContext createTlsContext(TransportParameter params) throws IOException
      Helper method to determine a SSL/TLS context. Apply only if useTls(TransportParameter) returns true. Relies on IdentityStore#createTlsContext(String, String, String...) if TransportParameter.getKeystoreKey() is given, else on SslUtils.createTlsContext(java.io.File, String, String).
      Parameters:
      params - the transport parameters
      Returns:
      the TLS context
      Throws:
      IOException - if creating the context or obtaining key information fails
    • applyAuthenticationKey

      public static boolean applyAuthenticationKey(String authenticationKey, AbstractTransportConnector.AuthenticationConsumer consumer)
      Tries to apply the given authentication key to the given consumer.
      Parameters:
      authenticationKey - the authentication key
      consumer - the consumer
      Returns:
      true for applied, false for ignored/failed
      See Also:
    • applyAuthenticationKey

      public static boolean applyAuthenticationKey(String authenticationKey, AbstractTransportConnector.AuthenticationConsumer consumer, Supplier<Boolean> anonymousSupplier)
      Tries to apply the given authentication key to the given consumer.
      Parameters:
      authenticationKey - the authentication key
      consumer - the consumer
      anonymousSupplier - for anonymous supplier/acceptor, may be null for none
      Returns:
      true for applied, false for ignored/failed
      See Also:
    • applyIdentityToken

      public static boolean applyIdentityToken(de.iip_ecosphere.platform.support.identities.IdentityToken tok, AbstractTransportConnector.AuthenticationConsumer consumer)
      Tries to apply the given identity token as user/password to the given consumer.
      Parameters:
      tok - the identity token
      consumer - the consumer
      Returns:
      true for applied, false for ignored/failed
      See Also:
    • applyIdentityToken

      public static boolean applyIdentityToken(de.iip_ecosphere.platform.support.identities.IdentityToken tok, AbstractTransportConnector.AuthenticationConsumer consumer, Supplier<Boolean> anonymousSupplier)
      Tries to apply the given identity token as user/password to the given consumer.
      Parameters:
      tok - the identity token
      consumer - the consumer for user/password
      anonymousSupplier - for anonymous supplier/acceptor, may be null for none
      Returns:
      true for applied, false for ignored/failed
    • setReceptionCallback

      public void setReceptionCallback(String stream, ReceptionCallback<?> callback) throws IOException
      Description copied from interface: TransportConnector
      Attaches a reception callback to stream. The callback is called upon a reception. Implicitly subscribes to channel.
      Specified by:
      setReceptionCallback in interface TransportConnector
      Parameters:
      stream - the stream to attach the reception to
      callback - the callback to attach
      Throws:
      IOException - in case that problems during registering the callback (e.g., during subscription) happens
    • detachReceptionCallback

      public void detachReceptionCallback(String stream, ReceptionCallback<?> callback) throws IOException
      Description copied from interface: TransportConnector
      Detaches a reception callback to stream.
      Specified by:
      detachReceptionCallback in interface TransportConnector
      Parameters:
      stream - the stream to detach the reception callback from
      callback - the callback to detach
      Throws:
      IOException - in case that problems during detaching the callback
    • connect

      public void connect(TransportParameter params) throws IOException
      Description copied from interface: TransportConnector
      Connects the underlying connections.
      Specified by:
      connect in interface TransportConnector
      Parameters:
      params - the parameters to start the underlying connection
      Throws:
      IOException - in case that problems during the connection happens
    • unsubscribe

      public void unsubscribe(String stream, boolean delete) throws IOException
      Description copied from interface: TransportConnector
      Unsubscribes from a channel implicitly subscribed with TransportConnector.setReceptionCallback(String, ReceptionCallback).
      Specified by:
      unsubscribe in interface TransportConnector
      Parameters:
      stream - the stream to unsubscribe from
      delete - if true, try to delete/clean up the communication side on the server (may not be supported by the implementing connector, is ignored then)
      Throws:
      IOException - if the action fails for some reason
    • disconnect

      public void disconnect() throws IOException
      Description copied from interface: TransportConnector
      Disconnects the underlying connections. Unsubscribes on all known subscribed depending on TransportParameter.getCloseAction().
      Specified by:
      disconnect in interface TransportConnector
      Throws:
      IOException - in case that problems during the disconnect happens
    • getTransportParameter

      protected TransportParameter getTransportParameter()
      Returns the transport parameters.
      Returns:
      the parameters
    • getActionTimeout

      protected int getActionTimeout()
      Returns the timeout for individual send/receive actions.
      Returns:
      the timeout in milliseconds
    • getCloseAction

      protected TransportParameter.CloseAction getCloseAction()
      Returns the close action.
      Returns:
      the close action
    • getApplicationId

      protected String getApplicationId()
      The unique application/client identifier. Considers TransportParameter.getApplicationId() and TransportParameter.getAutoApplicationId().
      Returns:
      the client identifier
    • getApplicationId

      public static String getApplicationId(String applicationId, String infix, boolean makeUnique)
      Creates a unique application/client identifier.
      Parameters:
      applicationId - the basic application id (may be null, turned to an empty string then)
      infix - an optional infix to be appended to applicationId (may be null, turned to an empty string then)
      makeUnique - make unique or just compose given information
      Returns:
      the client identifier
    • getCallback

      protected List<ReceptionCallback<?>> getCallback(String stream)
      The callback for a certain stream.
      Parameters:
      stream - the stream to return the callback for
      Returns:
      the callback (may be null for none)
    • registerStream

      protected void registerStream(String stream)
      Registers a stream name without callback. A callback may be registered later.
      Parameters:
      stream - the name of the stream
    • isStreamKnown

      protected boolean isStreamKnown(String stream)
      Returns whether a stream name exists, irrespective of a registered callback.
      Parameters:
      stream - the stream name to look for
      Returns:
      true if the stream is known, false else
    • notifyCallback

      protected <T> void notifyCallback(String stream, byte[] data)
      Notifies the callback in stream based on received serialized data.
      Type Parameters:
      T - the type of data
      Parameters:
      stream - the stream to notify the callback for
      data - the received serialized data
    • serialize

      protected <T> byte[] serialize(String stream, T data) throws IOException
      Serializes data to stream. [helper]
      Type Parameters:
      T - the type of the data
      Parameters:
      stream - the stream to serialize to
      data - the data to serialize
      Returns:
      the serialized bytes
      Throws:
      IOException - in case that problems occur during serialization
    • getSerializerProvider

      protected SerializerRegistry.SerializerProvider getSerializerProvider()
      Returns the serializer provider.
      Returns:
      the provider
    • setSerializerProvider

      public void setSerializerProvider(SerializerRegistry.SerializerProvider serializerProvider)
      Description copied from interface: TransportConnector
      Defines a special, local serializer provider that supersedes SerializerRegistry.DEFAULT_PROVIDER.
      Specified by:
      setSerializerProvider in interface TransportConnector
      Parameters:
      serializerProvider - the provider, ignored if null