Class AbstractDuplexHandler

java.lang.Object
com.lucimber.dbus.connection.AbstractDuplexHandler
All Implemented Interfaces:
Handler, InboundHandler, OutboundHandler
Direct Known Subclasses:
ConnectionHealthHandler, ConnectionReconnectHandler

public abstract class AbstractDuplexHandler extends Object implements InboundHandler, OutboundHandler
An abstract base class that combines both InboundHandler and OutboundHandler interfaces to handle bidirectional message flow in a Pipeline.

Subclasses can override one or both sets of handler methods to implement custom logic for inbound and outbound processing. This class is useful for handlers that need to observe or manipulate both directions of message flow.

The default implementations of all methods simply propagate events through the pipeline without any additional processing, making this class suitable as a base for handlers that only need to override specific methods.

Since:
1.0.0
See Also:
  • Constructor Details

    • AbstractDuplexHandler

      public AbstractDuplexHandler()
  • Method Details

    • handleInboundFailure

      public void handleInboundFailure(Context ctx, Throwable cause)
      Description copied from interface: InboundHandler
      Invoked when an error occurs during the processing of an inbound message.

      This method can be used to log, transform, or recover from the error as appropriate.

      Specified by:
      handleInboundFailure in interface InboundHandler
      Parameters:
      ctx - the Context this handler is bound to.
      cause - the Throwable describing the failure.
    • handleInboundMessage

      public void handleInboundMessage(Context ctx, InboundMessage msg)
      Description copied from interface: InboundHandler
      Invoked when an inbound message is received and propagated through the pipeline.

      Handlers may inspect, transform, or act upon the message before forwarding it downstream.

      Specified by:
      handleInboundMessage in interface InboundHandler
      Parameters:
      ctx - the Context this handler is bound to.
      msg - the InboundMessage being processed.
    • handleOutboundMessage

      public void handleOutboundMessage(Context ctx, OutboundMessage msg, CompletableFuture<Void> future)
      Description copied from interface: OutboundHandler
      Invoked when an outbound message is propagated through the pipeline.

      This method is responsible for handling or forwarding the outbound OutboundMessage. Completion of the provided CompletableFuture signals the success or failure of the operation.

      Specified by:
      handleOutboundMessage in interface OutboundHandler
      Parameters:
      ctx - the Context this handler is bound to.
      msg - the outbound message to process.
      future - the future to complete once the message has been handled or an error has occurred.
    • handleUserEvent

      public void handleUserEvent(Context ctx, Object evt)
      Description copied from interface: Handler
      Invoked when a user-defined event is propagated through the pipeline.

      Handlers can choose to react to or forward the event, depending on their logic.

      Specified by:
      handleUserEvent in interface Handler
      Parameters:
      ctx - the Context this handler is bound to.
      evt - the user-defined event to handle.
    • onConnectionActive

      public void onConnectionActive(Context ctx)
      Description copied from interface: Handler
      Invoked when the connection associated with this context becomes active.
      Specified by:
      onConnectionActive in interface Handler
      Parameters:
      ctx - the Context this handler is bound to.
    • onConnectionInactive

      public void onConnectionInactive(Context ctx)
      Description copied from interface: Handler
      Invoked when the connection associated with this context becomes inactive.
      Specified by:
      onConnectionInactive in interface Handler
      Parameters:
      ctx - the Context this handler is bound to.
    • onHandlerAdded

      public void onHandlerAdded(Context ctx)
      Description copied from interface: Handler
      Invoked when this handler is added to the pipeline.

      This is typically the first lifecycle method called for a handler.

      Specified by:
      onHandlerAdded in interface Handler
      Parameters:
      ctx - the Context this handler is bound to.
    • onHandlerRemoved

      public void onHandlerRemoved(Context ctx)
      Description copied from interface: Handler
      Invoked just before this handler is removed from the pipeline.

      This allows the handler to perform any necessary cleanup.

      Specified by:
      onHandlerRemoved in interface Handler
      Parameters:
      ctx - the Context this handler is bound to.
    • getLogger

      protected abstract org.slf4j.Logger getLogger()
      Returns the logger of the subclass.
      Returns:
      the logger