Class Transport

java.lang.Object
de.iip_ecosphere.platform.transport.Transport

public class Transport extends Object
Global and local transport support. At startup of the platform, sending messages and creating a connector may happen in parallel. So far, there is no strategy to clean up the queue, i.e., createConnector() or one of the send methods in this class are expected to be called in reasonable manner. This class supports two internal transport instances, the default global transport instance (for a global transport broker, initially the same as the local broker), and the local broker for local communication without using the external network (to be activated by setLocalSetup(Supplier)).
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • Transport

      private Transport()
      Prevents external creation.
  • Method Details

    • sendServiceStatus

      public static void sendServiceStatus(ActionType action, String serviceId, String... aliasIds)
      Sends a service status message. Uses Id.getDeviceId(). Calls createConnector() to obtain a connector instance on demand.
      Parameters:
      action - the action on the service
      serviceId - the service Id
      aliasIds - optional alias ids for the service
    • sendServiceStatusWithDescription

      public static void sendServiceStatusWithDescription(ActionType action, String serviceId, String description, String... aliasIds)
      Sends a service status message. Uses Id.getDeviceId(). Calls createConnector() to obtain a connector instance on demand.
      Parameters:
      action - the action on the service
      serviceId - the service Id
      description - an optional description of the status change
      aliasIds - optional alias ids for the service
    • sendServiceArtifactStatus

      public static void sendServiceArtifactStatus(ActionType action, String artifactId, String... aliasIds)
      Sends a service artifact status message. Uses Id.getDeviceId(). Calls createConnector() to obtain a connector instance on demand.
      Parameters:
      action - the action on the artifact
      artifactId - the artifact Id
      aliasIds - optional alias ids for the artifact
    • sendContainerStatus

      public static void sendContainerStatus(ActionType action, String containerId, String... aliasIds)
      Sends a container status message. Uses Id.getDeviceId(). Calls createConnector() to obtain a connector instance on demand.
      Parameters:
      action - the action on the container
      containerId - the container Id
      aliasIds - optional alias ids for the container
    • sendResourceStatus

      public static void sendResourceStatus(ActionType action, String... aliasIds)
      Sends a resource status message for this resource. Calls createConnector() to obtain a connector instance on demand.
      Parameters:
      action - the action on the container
      aliasIds - optional alias ids for the resource
    • sendResourceStatus

      public static void sendResourceStatus(ActionType action, String deviceId, String... aliasIds)
      Sends a resource status message. Calls createConnector() to obtain a connector instance on demand.
      Parameters:
      action - the action on the container
      deviceId - the device id, may be null then Id.getDeviceId() is used
      aliasIds - optional alias ids for the resource
    • send

      public static void send(de.iip_ecosphere.platform.support.function.IOConsumer<TransportConnector> sender, String kind)
      Sends a message of a certain kind with no/global routing and cares fore queuing.
      Parameters:
      sender - the sender including the message
      kind - the kind of the message for logging
    • send

      public static void send(de.iip_ecosphere.platform.support.function.IOConsumer<TransportConnector> sender, String kind, String... routingKeys)
      Sends a message of a certain kind and cares fore queuing.
      Parameters:
      sender - the sender including the message
      kind - the kind of the message for logging
      routingKeys - if null, empty or in globalRoutingKeys then use the globalTransport instance, else the localTransport instance; may use both transport instances
      See Also:
    • createConnector

      public static TransportConnector createConnector(String routingKey)
      Returns a connector for a routing key.
      Parameters:
      routingKey - if null, empty or in globalRoutingKeys then return the result of creating the connector in globalTransport, else the result for creating the connector in localTransport
      Returns:
      the connector
    • getHostSafe

      private static final String getHostSafe(Transport.TransportInstance instance)
      Returns the target host/port of the given transport instance. [DEBUGGING]
      Parameters:
      instance - the instance
      Returns:
      the host name/port or information which part is currently not initialized
    • addGlobalRoutingKey

      public static void addGlobalRoutingKey(String routingKey)
      Adds a global routing key.
      Parameters:
      routingKey - the routing key, may be any string, null or empty is ignored
    • setTraceFilter

      public static void setTraceFilter(Predicate<TraceRecord> filter)
      Defines a (global, local) trace filter.
      Parameters:
      filter - the filter, null for no filter
    • sendTraceRecord

      public static void sendTraceRecord(TraceRecord record)
      Sends a trace record (global). Calls createConnector() to obtain a connector instance on demand. Caches messages if no connector is available.
      Parameters:
      record - the record to be sent
    • sendProcessStatus

      public static void sendProcessStatus(String componentId, int step, int max, String description)
      Sends information about a processing status (global).
      Parameters:
      componentId - the component id
      step - the step [0; max]
      max - the maximum step
      description - the description of the task
    • sendProcessStatus

      public static void sendProcessStatus(String componentId, int step, int max, String description, String subDescription)
      Sends information about a processing status (global).
      Parameters:
      componentId - the component id
      step - the step [0; max]
      max - the maximum step
      description - the description of the task
      subDescription - the description of an optional sub-task within the actual task, may be null or empty
    • sendProcessStatus

      public static void sendProcessStatus(String componentId, ActionTypes type, Object result)
      Sends information about finalizing a task-based process (global). Attaches the actual task data if available.
      Parameters:
      componentId - the component id
      type - shall be ActionTypes.RESULT or ActionTypes.ERROR
      result - a serializable result, may be null
    • sendStatus

      public static void sendStatus(StatusMessage msg)
      Sends a status message (global). Calls createConnector() to obtain a connector instance on demand. Caches messages if no connector is available.
      Parameters:
      msg - the message to be sent
    • sendAlert

      public static void sendAlert(Alert alert)
      Sends an alert message (global). Calls createConnector() to obtain a connector instance on demand. Caches messages if no connector is available.
      Parameters:
      alert - the alert to be sent
    • setTransportSetup

      public static Supplier<TransportSetup> setTransportSetup(Supplier<TransportSetup> supplier)
      Sets up the (global) transport information.
      Parameters:
      supplier - the transport supplier
      Returns:
      supplier the supplier before this operation
    • setLocalSetup

      public static void setLocalSetup(Supplier<TransportSetup> supplier)
      Sets up the (local) transport information and enforces a local transport instance.
      Parameters:
      supplier - the transport supplier
    • createConnector

      public static TransportConnector createConnector()
      Tries creating a (global) connector. If successful, globalTransport will be initialized for caching. The instance is cached. The transport information must be set up before setTransportSetup(Supplier). After successfully creating a connector, queued messages are sent and removed from the queue. However, there is no guarantee that a connector can be created.
      Returns:
      the (cached) connector, may be null
      See Also:
    • releaseConnector

      public static void releaseConnector()
      Releases an existing (global) connector and stays offline.
    • releaseConnector

      public static void releaseConnector(boolean stayOff)
      Releases an existing (global) connector.
      Parameters:
      stayOff - whether a call to createConnector() shall create a new connector or prevent sending further messages.
    • getConnector

      public static TransportConnector getConnector()
      Returns the (global) transport connector.
      Returns:
      the transport connector, may be null
      See Also:
    • getGlobalTransport

      public static Transport.TransportInstance getGlobalTransport()
      Returns the (global) transport instance.
      Returns:
      the transport instance, may be uninitialized
    • getLocalConnector

      public static TransportConnector getLocalConnector()
      Returns the (local) transport connector.
      Returns:
      the transport connector, may be the same as the global connector, may be null
      See Also:
    • getLocalTransport

      public static Transport.TransportInstance getLocalTransport()
      Returns the (local) transport instance.
      Returns:
      the transport instance, may be uninitialized, may be the same as getGlobalTransport()