Class AbstractTransportConnector
java.lang.Object
de.iip_ecosphere.platform.transport.connectors.impl.AbstractTransportConnector
- All Implemented Interfaces:
TransportConnector
- Direct Known Subclasses:
AbstractMqttTransportConnector,DirectMemoryTransferTransportConnector,PrintTransportConnector
An abstract transport connector.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceConsumes token authentication data. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<String, List<ReceptionCallback<?>>> private TransportParameterFields inherited from interface de.iip_ecosphere.platform.transport.connectors.TransportConnector
EMPTY_PARENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanapplyAuthenticationKey(String authenticationKey, AbstractTransportConnector.AuthenticationConsumer consumer) Tries to apply the given authentication key to the given consumer.static booleanapplyAuthenticationKey(String authenticationKey, AbstractTransportConnector.AuthenticationConsumer consumer, Supplier<Boolean> anonymousSupplier) Tries to apply the given authentication key to the given consumer.static booleanapplyIdentityToken(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.static booleanapplyIdentityToken(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.voidconnect(TransportParameter params) Connects the underlying connections.protected SSLContextcreateTlsContext(TransportParameter params) Helper method to determine a SSL/TLS context.voiddetachReceptionCallback(String stream, ReceptionCallback<?> callback) Detaches a receptioncallbacktostream.voidDisconnects the underlying connections.protected intReturns the timeout for individual send/receive actions.protected StringThe unique application/client identifier.static StringgetApplicationId(String applicationId, String infix, boolean makeUnique) Creates a unique application/client identifier.protected List<ReceptionCallback<?>> getCallback(String stream) The callback for a certain stream.protected TransportParameter.CloseActionReturns the close action.protected SerializerRegistry.SerializerProviderReturns the serializer provider.protected TransportParameterReturns the transport parameters.protected booleanisStreamKnown(String stream) Returns whether astreamname exists, irrespective of a registered callback.protected <T> voidnotifyCallback(String stream, byte[] data) Notifies the callback instreambased on received serializeddata.protected voidregisterStream(String stream) Registers astreamname without callback.protected <T> byte[]Serializesdatatostream.voidsetReceptionCallback(String stream, ReceptionCallback<?> callback) Attaches a receptioncallbacktostream.voidsetSerializerProvider(SerializerRegistry.SerializerProvider serializerProvider) Defines a special, local serializer provider that supersedesSerializerRegistry.DEFAULT_PROVIDER.voidunsubscribe(String stream, boolean delete) Unsubscribes from a channel implicitly subscribed withTransportConnector.setReceptionCallback(String, ReceptionCallback).protected booleanuseTls(TransportParameter params) Returns whether the connector shall use TLS.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.iip_ecosphere.platform.transport.connectors.TransportConnector
asyncSend, composeStreamName, enabledEncryption, getName, supportedEncryption, syncSend
-
Field Details
-
callbacks
-
params
-
serializerProvider
-
-
Constructor Details
-
AbstractTransportConnector
public AbstractTransportConnector()
-
-
Method Details
-
useTls
Returns whether the connector shall use TLS.- Parameters:
params- the transport parameters- Returns:
truefor TLS enabled,falseelse
-
createTlsContext
Helper method to determine a SSL/TLS context. Apply only ifuseTls(TransportParameter)returnstrue. Relies onIdentityStore#createTlsContext(String, String, String...)ifTransportParameter.getKeystoreKey()is given, else onSslUtils.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 keyconsumer- the consumer- Returns:
truefor applied,falsefor 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 keyconsumer- the consumeranonymousSupplier- for anonymous supplier/acceptor, may be null for none- Returns:
truefor applied,falsefor 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 tokenconsumer- the consumer- Returns:
truefor applied,falsefor 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 tokenconsumer- the consumer for user/passwordanonymousSupplier- for anonymous supplier/acceptor, may be null for none- Returns:
truefor applied,falsefor ignored/failed
-
setReceptionCallback
Description copied from interface:TransportConnectorAttaches a receptioncallbacktostream. Thecallbackis called upon a reception. Implicitly subscribes tochannel.- Specified by:
setReceptionCallbackin interfaceTransportConnector- Parameters:
stream- the stream to attach the reception tocallback- 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:TransportConnectorDetaches a receptioncallbacktostream.- Specified by:
detachReceptionCallbackin interfaceTransportConnector- Parameters:
stream- the stream to detach the reception callback fromcallback- the callback to detach- Throws:
IOException- in case that problems during detaching the callback
-
connect
Description copied from interface:TransportConnectorConnects the underlying connections.- Specified by:
connectin interfaceTransportConnector- Parameters:
params- the parameters to start the underlying connection- Throws:
IOException- in case that problems during the connection happens
-
unsubscribe
Description copied from interface:TransportConnectorUnsubscribes from a channel implicitly subscribed withTransportConnector.setReceptionCallback(String, ReceptionCallback).- Specified by:
unsubscribein interfaceTransportConnector- Parameters:
stream- the stream to unsubscribe fromdelete- iftrue, 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
Description copied from interface:TransportConnectorDisconnects the underlying connections.Unsubscribeson all knownsubscribeddepending onTransportParameter.getCloseAction().- Specified by:
disconnectin interfaceTransportConnector- Throws:
IOException- in case that problems during the disconnect happens
-
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
Returns the close action.- Returns:
- the close action
-
getApplicationId
The unique application/client identifier. ConsidersTransportParameter.getApplicationId()andTransportParameter.getAutoApplicationId().- Returns:
- the client identifier
-
getApplicationId
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 toapplicationId(may be null, turned to an empty string then)makeUnique- make unique or just compose given information- Returns:
- the client identifier
-
getCallback
The callback for a certain stream.- Parameters:
stream- the stream to return the callback for- Returns:
- the callback (may be null for none)
-
registerStream
Registers astreamname without callback. A callback may be registered later.- Parameters:
stream- the name of the stream
-
isStreamKnown
Returns whether astreamname exists, irrespective of a registered callback.- Parameters:
stream- the stream name to look for- Returns:
trueif the stream is known,falseelse
-
notifyCallback
Notifies the callback instreambased on received serializeddata.- Type Parameters:
T- the type of data- Parameters:
stream- the stream to notify the callback fordata- the received serialized data
-
serialize
Serializesdatatostream. [helper]- Type Parameters:
T- the type of the data- Parameters:
stream- the stream to serialize todata- the data to serialize- Returns:
- the serialized bytes
- Throws:
IOException- in case that problems occur during serialization
-
getSerializerProvider
Returns the serializer provider.- Returns:
- the provider
-
setSerializerProvider
Description copied from interface:TransportConnectorDefines a special, local serializer provider that supersedesSerializerRegistry.DEFAULT_PROVIDER.- Specified by:
setSerializerProviderin interfaceTransportConnector- Parameters:
serializerProvider- the provider, ignored if null
-