Class LoopbackTransport

java.lang.Object
dev.ua.theroer.magicutils.messaging.LoopbackTransport
All Implemented Interfaces:
MessageTransport, AutoCloseable

public final class LoopbackTransport extends Object implements MessageTransport
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.

  • Constructor Details

    • LoopbackTransport

      public LoopbackTransport()
      Creates an unlinked loopback transport.
  • Method Details

    • name

      public String name()
      Description copied from interface: MessageTransport
      Human-readable transport name for diagnostics/logging (for example "plugin-messaging", "redis").
      Specified by:
      name in interface MessageTransport
      Returns:
      transport name
    • start

      public void start(MessageTransport.EnvelopeSink sink)
      Description copied from interface: MessageTransport
      Starts 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:
      start in interface MessageTransport
      Parameters:
      sink - destination for received envelopes
    • link

      public void link(LoopbackTransport other)
      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

      public void publish(MessageEnvelope envelope)
      Description copied from interface: MessageTransport
      Publishes an encoded envelope to the network.

      The envelope's Target is advisory; transports that cannot route precisely broadcast and rely on receiver-side filtering.

      Specified by:
      publish in interface MessageTransport
      Parameters:
      envelope - envelope to send
    • close

      public void close()
      Description copied from interface: MessageTransport
      Stops the transport and releases resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface MessageTransport