Package org.drasyl.pipeline
Class SimpleOutboundHandler<O,A extends Address>
java.lang.Object
org.drasyl.pipeline.HandlerAdapter
org.drasyl.pipeline.AddressHandlerAdapter<A>
org.drasyl.pipeline.SimpleOutboundHandler<O,A>
- All Implemented Interfaces:
Handler
- Direct Known Subclasses:
DirectConnectionMessageSinkHandler,LoopbackMessageSinkHandler,ObjectHolder2ApplicationMessageHandler,SuperPeerMessageSinkHandler
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 Summary
ConstructorsModifierConstructorDescriptionprotectedCreate a new instance which will try to detect the types to match out of the type parameter of the class.protectedSimpleOutboundHandler(Class<? extends O> outboundMessageType, Class<? extends A> addressType) Create a new instance -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptOutbound(Object msg) Returnstrueif the given message should be handled.protected abstract voidmatchedWrite(HandlerContext ctx, A recipient, O msg, CompletableFuture<Void> future) Is called for each message of typeSimpleOutboundHandler.voidwrite(HandlerContext ctx, Address recipient, Object msg, CompletableFuture<Void> future) Gets called if aObjectwas send from the application to a recipient.Methods inherited from class org.drasyl.pipeline.AddressHandlerAdapter
acceptAddressMethods inherited from class org.drasyl.pipeline.HandlerAdapter
eventTriggered, exceptionCaught, handlerAdded, handlerRemoved, read
-
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 matchaddressType- 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:HandlerGets called if aObjectwas send from the application to a recipient.- Specified by:
writein interfaceHandler- Overrides:
writein classHandlerAdapter- Parameters:
ctx- handler contextrecipient- the recipient of the messagemsg- the messagefuture- a future for the message
-
acceptOutbound
-
matchedWrite
protected abstract void matchedWrite(HandlerContext ctx, A recipient, O msg, CompletableFuture<Void> future) Is called for each message of typeSimpleOutboundHandler.- Parameters:
ctx- handler contextrecipient- the recipient of the messagemsg- the messagefuture- a future for the message
-