Class SimpleOutboundHandler<O,A extends Address>

All Implemented Interfaces:
Handler
Direct Known Subclasses:
DirectConnectionMessageSinkHandler, LoopbackMessageSinkHandler, ObjectHolder2ApplicationMessageHandler, SuperPeerMessageSinkHandler

public abstract class SimpleOutboundHandler<O,A extends Address> extends AddressHandlerAdapter<A>
HandlerAdapter which allows to explicit only handle a specific type of messages.

For example here is an implementation which only handle ErrorMessages.

     public class ChunkedHandler extends
             SimpleOutboundHandler<ErrorMessage, CompressedPublicKey> {

        @Override
         protected void matchedWrite(HandlerContext ctx,
             CompressedPublicKey recipient, ErrorMessage msg,
             CompletableFuture<Void> future) {
             System.out.println(msg);
         }
     }
 
  • Constructor Details

    • SimpleOutboundHandler

      protected SimpleOutboundHandler()
      Create a new instance which will try to detect the types to match out of the type parameter of the class.
    • SimpleOutboundHandler

      protected SimpleOutboundHandler(Class<? extends O> outboundMessageType, Class<? extends A> addressType)
      Create a new instance
      Parameters:
      outboundMessageType - the type of messages to match
      addressType - the type of the address to match
  • Method Details

    • write

      public void write(HandlerContext ctx, Address recipient, Object msg, CompletableFuture<Void> future)
      Description copied from interface: Handler
      Gets called if a Object was send from the application to a recipient.
      Specified by:
      write in interface Handler
      Overrides:
      write in class HandlerAdapter
      Parameters:
      ctx - handler context
      recipient - the recipient of the message
      msg - the message
      future - a future for the message
    • acceptOutbound

      protected boolean acceptOutbound(Object msg)
      Returns true if the given message should be handled. If false it will be passed to the next Handler in the Pipeline.
    • matchedWrite

      protected abstract void matchedWrite(HandlerContext ctx, A recipient, O msg, CompletableFuture<Void> future)
      Is called for each message of type SimpleOutboundHandler.
      Parameters:
      ctx - handler context
      recipient - the recipient of the message
      msg - the message
      future - a future for the message