Class LoopbackTransport
java.lang.Object
dev.ua.theroer.magicutils.messaging.LoopbackTransport
- All Implemented Interfaces:
MessageTransport, AutoCloseable
In-process transport that delivers published envelopes straight back to the
local sink.
Useful as a no-network default (single server), and as a test double. Since
MessageEnvelope.acceptedBy(MessageSource, Predicate) rejects a member's own messages, a lone
member never sees its own traffic; wire two loopback transports together via
link(LoopbackTransport) to simulate two members in a unit test.
-
Nested Class Summary
Nested classes/interfaces inherited from interface MessageTransport
MessageTransport.EnvelopeSink -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Stops the transport and releases resources.voidlink(LoopbackTransport other) Links this transport to a peer so published envelopes are delivered to it, emulating a two-member network in-process.name()Human-readable transport name for diagnostics/logging (for example "plugin-messaging", "redis").voidpublish(MessageEnvelope envelope) Publishes an encoded envelope to the network.voidStarts the transport and begins delivering received envelopes to the sink.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MessageTransport
isConnected
-
Constructor Details
-
LoopbackTransport
public LoopbackTransport()Creates an unlinked loopback transport.
-
-
Method Details
-
name
Description copied from interface:MessageTransportHuman-readable transport name for diagnostics/logging (for example "plugin-messaging", "redis").- Specified by:
namein interfaceMessageTransport- Returns:
- transport name
-
start
Description copied from interface:MessageTransportStarts the transport and begins delivering received envelopes to the sink.Called once before any
MessageTransport.publish(MessageEnvelope). Implementations that need a background subscriber thread or channel registration set it up here.- Specified by:
startin interfaceMessageTransport- Parameters:
sink- destination for received envelopes
-
link
Links this transport to a peer so published envelopes are delivered to it, emulating a two-member network in-process.- Parameters:
other- the peer transport
-
publish
Description copied from interface:MessageTransportPublishes an encoded envelope to the network.The envelope's
Targetis advisory; transports that cannot route precisely broadcast and rely on receiver-side filtering.- Specified by:
publishin interfaceMessageTransport- Parameters:
envelope- envelope to send
-
close
public void close()Description copied from interface:MessageTransportStops the transport and releases resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceMessageTransport
-