Class Transport
java.lang.Object
de.iip_ecosphere.platform.transport.Transport
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn instance of the transport. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanprivate static Transport.TransportInstanceprivate static Transport.TransportInstanceprivate static final longprivate static Predicate<TraceRecord> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddGlobalRoutingKey(String routingKey) Adds a global routing key.static TransportConnectorTries creating a (global) connector.static TransportConnectorcreateConnector(String routingKey) Returns a connector for a routing key.static TransportConnectorReturns the (global) transport connector.static Transport.TransportInstanceReturns the (global) transport instance.private static final StringgetHostSafe(Transport.TransportInstance instance) Returns the target host/port of the given transportinstance.static TransportConnectorReturns the (local) transport connector.static Transport.TransportInstanceReturns the (local) transport instance.static voidReleases an existing (global) connector and stays offline.static voidreleaseConnector(boolean stayOff) Releases an existing (global) connector.static voidsend(de.iip_ecosphere.platform.support.function.IOConsumer<TransportConnector> sender, String kind) Sends a message of a certainkindwith no/global routing and cares fore queuing.static voidsend(de.iip_ecosphere.platform.support.function.IOConsumer<TransportConnector> sender, String kind, String... routingKeys) Sends a message of a certainkindand cares fore queuing.static voidSends an alert message (global).static voidsendContainerStatus(ActionType action, String containerId, String... aliasIds) Sends a container status message.static voidsendProcessStatus(String componentId, int step, int max, String description) Sends information about a processing status (global).static voidsendProcessStatus(String componentId, int step, int max, String description, String subDescription) Sends information about a processing status (global).static voidsendProcessStatus(String componentId, ActionTypes type, Object result) Sends information about finalizing a task-based process (global).static voidsendResourceStatus(ActionType action, String... aliasIds) Sends a resource status message for this resource.static voidsendResourceStatus(ActionType action, String deviceId, String... aliasIds) Sends a resource status message.static voidsendServiceArtifactStatus(ActionType action, String artifactId, String... aliasIds) Sends a service artifact status message.static voidsendServiceStatus(ActionType action, String serviceId, String... aliasIds) Sends a service status message.static voidsendServiceStatusWithDescription(ActionType action, String serviceId, String description, String... aliasIds) Sends a service status message.static voidsendStatus(StatusMessage msg) Sends a status message (global).static voidsendTraceRecord(TraceRecord record) Sends a trace record (global).static voidsetLocalSetup(Supplier<TransportSetup> supplier) Sets up the (local) transport information and enforces a local transport instance.static voidsetTraceFilter(Predicate<TraceRecord> filter) Defines a (global, local) trace filter.static Supplier<TransportSetup> setTransportSetup(Supplier<TransportSetup> supplier) Sets up the (global) transport information.
-
Field Details
-
traceFilter
-
globalTransport
-
localTransport
-
globalRoutingKeys
-
DEBUG
private static final boolean DEBUG- See Also:
-
QUEUE_MSG_TIMEOUT
private static final long QUEUE_MSG_TIMEOUT
-
-
Constructor Details
-
Transport
private Transport()Prevents external creation.
-
-
Method Details
-
sendServiceStatus
Sends a service status message. UsesId.getDeviceId(). CallscreateConnector()to obtain a connector instance on demand.- Parameters:
action- the action on the serviceserviceId- the service IdaliasIds- optional alias ids for the service
-
sendServiceStatusWithDescription
public static void sendServiceStatusWithDescription(ActionType action, String serviceId, String description, String... aliasIds) Sends a service status message. UsesId.getDeviceId(). CallscreateConnector()to obtain a connector instance on demand.- Parameters:
action- the action on the serviceserviceId- the service Iddescription- an optional description of the status changealiasIds- optional alias ids for the service
-
sendServiceArtifactStatus
public static void sendServiceArtifactStatus(ActionType action, String artifactId, String... aliasIds) Sends a service artifact status message. UsesId.getDeviceId(). CallscreateConnector()to obtain a connector instance on demand.- Parameters:
action- the action on the artifactartifactId- the artifact IdaliasIds- optional alias ids for the artifact
-
sendContainerStatus
Sends a container status message. UsesId.getDeviceId(). CallscreateConnector()to obtain a connector instance on demand.- Parameters:
action- the action on the containercontainerId- the container IdaliasIds- optional alias ids for the container
-
sendResourceStatus
Sends a resource status message for this resource. CallscreateConnector()to obtain a connector instance on demand.- Parameters:
action- the action on the containeraliasIds- optional alias ids for the resource
-
sendResourceStatus
Sends a resource status message. CallscreateConnector()to obtain a connector instance on demand.- Parameters:
action- the action on the containerdeviceId- the device id, may be null thenId.getDeviceId()is usedaliasIds- 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 certainkindwith no/global routing and cares fore queuing.- Parameters:
sender- the sender including the messagekind- 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 certainkindand cares fore queuing.- Parameters:
sender- the sender including the messagekind- the kind of the message for loggingroutingKeys- if null, empty or inglobalRoutingKeysthen use theglobalTransportinstance, else thelocalTransportinstance; may use both transport instances- See Also:
-
createConnector
Returns a connector for a routing key.- Parameters:
routingKey- if null, empty or inglobalRoutingKeysthen return the result of creating the connector inglobalTransport, else the result for creating the connector inlocalTransport- Returns:
- the connector
-
getHostSafe
Returns the target host/port of the given transportinstance. [DEBUGGING]- Parameters:
instance- the instance- Returns:
- the host name/port or information which part is currently not initialized
-
addGlobalRoutingKey
Adds a global routing key.- Parameters:
routingKey- the routing key, may be any string, null or empty is ignored
-
setTraceFilter
Defines a (global, local) trace filter.- Parameters:
filter- the filter, null for no filter
-
sendTraceRecord
Sends a trace record (global). CallscreateConnector()to obtain a connector instance on demand. Caches messages if no connector is available.- Parameters:
record- the record to be sent
-
sendProcessStatus
Sends information about a processing status (global).- Parameters:
componentId- the component idstep- the step [0; max]max- the maximum stepdescription- 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 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 empty
-
sendProcessStatus
Sends information about finalizing a task-based process (global). Attaches the actual task data if available.- Parameters:
componentId- the component idtype- shall beActionTypes.RESULTorActionTypes.ERRORresult- a serializable result, may be null
-
sendStatus
Sends a status message (global). CallscreateConnector()to obtain a connector instance on demand. Caches messages if no connector is available.- Parameters:
msg- the message to be sent
-
sendAlert
Sends an alert message (global). CallscreateConnector()to obtain a connector instance on demand. Caches messages if no connector is available.- Parameters:
alert- the alert to be sent
-
setTransportSetup
Sets up the (global) transport information.- Parameters:
supplier- the transport supplier- Returns:
- supplier the supplier before this operation
-
setLocalSetup
Sets up the (local) transport information and enforces a local transport instance.- Parameters:
supplier- the transport supplier
-
createConnector
Tries creating a (global) connector. If successful,globalTransportwill be initialized for caching. The instance is cached. The transport information must be set up beforesetTransportSetup(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 tocreateConnector()shall create a new connector or prevent sending further messages.
-
getConnector
Returns the (global) transport connector.- Returns:
- the transport connector, may be null
- See Also:
-
getGlobalTransport
Returns the (global) transport instance.- Returns:
- the transport instance, may be uninitialized
-
getLocalConnector
Returns the (local) transport connector.- Returns:
- the transport connector, may be the same as the global connector, may be null
- See Also:
-
getLocalTransport
Returns the (local) transport instance.- Returns:
- the transport instance, may be uninitialized, may be the same as
getGlobalTransport()
-