public class Transport extends Object
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)).| Modifier and Type | Class and Description |
|---|---|
static class |
Transport.TransportInstance
An instance of the transport.
|
| Modifier and Type | Field and Description |
|---|---|
private static boolean |
DEBUG |
private static Set<String> |
globalRoutingKeys |
private static Transport.TransportInstance |
globalTransport |
private static Transport.TransportInstance |
localTransport |
private static Predicate<TraceRecord> |
traceFilter |
| Modifier | Constructor and Description |
|---|---|
private |
Transport()
Prevents external creation.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
addGlobalRoutingKey(String routingKey)
Adds a global routing key.
|
static TransportConnector |
createConnector()
Tries creating a (global) connector.
|
static TransportConnector |
createConnector(String routingKey)
Returns a connector for a routing key.
|
static TransportConnector |
getConnector()
Returns the (global) transport connector.
|
static Transport.TransportInstance |
getGlobalTransport()
Returns the (global) transport instance.
|
private static String |
getHostSafe(Transport.TransportInstance instance)
Returns the target host/port of the given transport
instance. |
static TransportConnector |
getLocalConnector()
Returns the (local) transport connector.
|
static Transport.TransportInstance |
getLocalTransport()
Returns the (local) transport instance.
|
static void |
releaseConnector()
Releases an existing (global) connector and stays offline.
|
static void |
releaseConnector(boolean stayOff)
Releases an existing (global) connector.
|
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. |
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. |
static void |
sendAlert(Alert alert)
Sends an alert message (global).
|
static void |
sendContainerStatus(ActionType action,
String containerId,
String... aliasIds)
Sends a container status message.
|
static void |
sendProcessStatus(String componentId,
int step,
int max,
String description)
Sends information about a processing status (global).
|
static void |
sendProcessStatus(String componentId,
int step,
int max,
String description,
String subDescription)
Sends information about a processing status (global).
|
static void |
sendResourceStatus(ActionType action,
String... aliasIds)
Sends a resource status message for this resource.
|
static void |
sendResourceStatus(ActionType action,
String deviceId,
String... aliasIds)
Sends a resource status message.
|
static void |
sendServiceArtifactStatus(ActionType action,
String artifactId,
String... aliasIds)
Sends a service artifact status message.
|
static void |
sendServiceStatus(ActionType action,
String serviceId,
String... aliasIds)
Sends a service status message.
|
static void |
sendStatus(StatusMessage msg)
Sends a status message (global).
|
static void |
sendTraceRecord(TraceRecord record)
Sends a trace record (global).
|
static void |
setLocalSetup(Supplier<TransportSetup> supplier)
Sets up the (local) transport information and enforces a local transport instance.
|
static void |
setTraceFilter(Predicate<TraceRecord> filter)
Defines a (global, local) trace filter.
|
static void |
setTransportSetup(Supplier<TransportSetup> supplier)
Sets up the (global) transport information.
|
private static Predicate<TraceRecord> traceFilter
private static Transport.TransportInstance globalTransport
private static Transport.TransportInstance localTransport
private static final boolean DEBUG
public static void sendServiceStatus(ActionType action, String serviceId, String... aliasIds)
Id.getDeviceId(). Calls createConnector() to obtain
a connector instance on demand.action - the action on the serviceserviceId - the service IdaliasIds - optional alias ids for the servicepublic static void sendServiceArtifactStatus(ActionType action, String artifactId, String... aliasIds)
Id.getDeviceId(). Calls createConnector() to
obtain a connector instance on demand.action - the action on the artifactartifactId - the artifact IdaliasIds - optional alias ids for the artifactpublic static void sendContainerStatus(ActionType action, String containerId, String... aliasIds)
Id.getDeviceId(). Calls createConnector() to obtain
a connector instance on demand.action - the action on the containercontainerId - the container IdaliasIds - optional alias ids for the containerpublic static void sendResourceStatus(ActionType action, String... aliasIds)
createConnector() to obtain
a connector instance on demand.action - the action on the containeraliasIds - optional alias ids for the resourcepublic static void sendResourceStatus(ActionType action, String deviceId, String... aliasIds)
createConnector() to obtain
a connector instance on demand.action - the action on the containerdeviceId - the device id, may be null then Id.getDeviceId() is usedaliasIds - optional alias ids for the resourcepublic static void send(de.iip_ecosphere.platform.support.function.IOConsumer<TransportConnector> sender, String kind)
kind with no/global routing and cares fore queuing.sender - the sender including the messagekind - the kind of the message for loggingpublic static void send(de.iip_ecosphere.platform.support.function.IOConsumer<TransportConnector> sender, String kind, String... routingKeys)
kind and cares fore queuing.sender - the sender including the messagekind - the kind of the message for loggingroutingKeys - if null, empty or in globalRoutingKeys then use the globalTransport
instance, else the localTransport instance; may use both transport instancesaddGlobalRoutingKey(String)public static TransportConnector createConnector(String routingKey)
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 localTransportprivate static final String getHostSafe(Transport.TransportInstance instance)
instance. [DEBUGGING]instance - the instancepublic static void addGlobalRoutingKey(String routingKey)
routingKey - the routing key, may be any string, null or empty is ignoredpublic static void setTraceFilter(Predicate<TraceRecord> filter)
filter - the filter, null for no filterpublic static void sendTraceRecord(TraceRecord record)
createConnector() to obtain
a connector instance on demand. Caches messages if no connector is available.record - the record to be sentpublic static void sendProcessStatus(String componentId, int step, int max, String description)
componentId - the component idstep - the step [0; max]max - the maximum stepdescription - the description of the taskpublic static void sendProcessStatus(String componentId, int step, int max, String description, String subDescription)
componentId - the component idstep - the step [0; max]max - the maximum stepdescription - the description of the tasksubDescription - the description of an optional sub-task within the actual task, may be null or emptypublic static void sendStatus(StatusMessage msg)
createConnector() to obtain
a connector instance on demand. Caches messages if no connector is available.msg - the message to be sentpublic static void sendAlert(Alert alert)
createConnector() to obtain
a connector instance on demand. Caches messages if no connector is available.alert - the alert to be sentpublic static void setTransportSetup(Supplier<TransportSetup> supplier)
supplier - the transport supplierpublic static void setLocalSetup(Supplier<TransportSetup> supplier)
supplier - the transport supplierpublic static TransportConnector createConnector()
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.setTransportSetup(Supplier),
releaseConnector(),
releaseConnector(boolean)public static void releaseConnector()
public static void releaseConnector(boolean stayOff)
stayOff - whether a call to createConnector() shall create a new connector or prevent sending
further messages.public static TransportConnector getConnector()
createConnector()public static Transport.TransportInstance getGlobalTransport()
public static TransportConnector getLocalConnector()
createConnector()public static Transport.TransportInstance getLocalTransport()
getGlobalTransport()Copyright © 2022. All rights reserved.