Class DefaultPipeline

java.lang.Object
com.lucimber.dbus.connection.DefaultPipeline
All Implemented Interfaces:
InboundPropagator, OutboundPropagator, Pipeline

public final class DefaultPipeline extends Object implements Pipeline
A thread-safe pipeline of OutboundHandler instances associated with a Connection. This class maintains the order of handlers and ensures propagation of read, write, exception, and user-defined events.
  • Constructor Details

    • DefaultPipeline

      public DefaultPipeline(Connection connection)
      Constructs a new pipeline for the given connection.
  • Method Details

    • addLast

      public Pipeline addLast(String name, Handler handler)
      Description copied from interface: Pipeline
      Appends a new Handler to the end of the pipeline.
      Specified by:
      addLast in interface Pipeline
      Parameters:
      name - a unique name used to identify the handler within the pipeline.
      handler - the Handler instance to add.
      Returns:
      this Pipeline instance for method chaining.
    • getConnection

      public Connection getConnection()
      Description copied from interface: Pipeline
      Retrieves the Connection that this pipeline is bound to.
      Specified by:
      getConnection in interface Pipeline
      Returns:
      the associated Connection instance.
    • remove

      public Pipeline remove(String name)
      Description copied from interface: Pipeline
      Removes the Handler with the specified name from the pipeline.
      Specified by:
      remove in interface Pipeline
      Parameters:
      name - the unique name of the handler to remove.
      Returns:
      this Pipeline instance for method chaining.
    • propagateConnectionActive

      public void propagateConnectionActive()
      Description copied from interface: InboundPropagator
      Propagates a connection-activated event to the next handler in the pipeline.

      If not intercepted, this event will reach the tail handler.

      Specified by:
      propagateConnectionActive in interface InboundPropagator
    • propagateConnectionInactive

      public void propagateConnectionInactive()
      Description copied from interface: InboundPropagator
      Propagates a connection-inactivated event to the next handler in the pipeline.

      If not intercepted, this event will reach the tail handler.

      Specified by:
      propagateConnectionInactive in interface InboundPropagator
    • propagateInboundMessage

      public void propagateInboundMessage(InboundMessage msg)
      Description copied from interface: InboundPropagator
      Propagates an inbound message to the next handler in the pipeline.

      This allows handlers to process or forward the message as needed.

      Specified by:
      propagateInboundMessage in interface InboundPropagator
      Parameters:
      msg - the InboundMessage to propagate.
    • propagateInboundFailure

      public void propagateInboundFailure(Throwable cause)
      Description copied from interface: InboundPropagator
      Propagates an exception or failure encountered during inbound message processing.

      If not intercepted, the failure will be delivered to the final handler in the chain.

      Specified by:
      propagateInboundFailure in interface InboundPropagator
      Parameters:
      cause - the Throwable representing the failure.
    • propagateOutboundMessage

      public void propagateOutboundMessage(OutboundMessage msg, CompletableFuture<Void> future)
      Description copied from interface: OutboundPropagator
      Propagates an outbound message to the previous handler in the pipeline.

      If not intercepted, the message will eventually reach the head handler.

      Specified by:
      propagateOutboundMessage in interface OutboundPropagator
      Parameters:
      msg - the OutboundMessage to propagate.
      future - a CompletableFuture to complete once the message is successfully handled or if an error occurs during propagation.