Package org.drasyl.pipeline.skeleton
Class SimpleOutboundHandler<O,A extends Address>
- java.lang.Object
-
- org.drasyl.pipeline.skeleton.HandlerAdapter
-
- org.drasyl.pipeline.skeleton.AddressHandlerAdapter<A>
-
- org.drasyl.pipeline.skeleton.SimpleOutboundHandler<O,A>
-
- All Implemented Interfaces:
Handler
- Direct Known Subclasses:
HopCountGuard,LocalHostDiscovery,LoopbackMessageHandler,Message2ByteBufHandler,StaticRoutesHandler,UdpServer
public abstract class SimpleOutboundHandler<O,A extends Address> extends AddressHandlerAdapter<A>
HandlerAdapterwhich allows to explicit only handle a specific type of messages.For example here is an implementation which only handle
MyMessages of typeMyMessage.public class ChunkedHandler extendsSimpleOutboundHandler<MyMessage,CompressedPublicKey> {@Overrideprotected void matchedWrite(HandlerContextctx,CompressedPublicKeyrecipient,MyMessagemsg,CompletableFuture<Void> future) { System.out.println(msg); } }
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSimpleOutboundHandler()Create 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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected 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.skeleton.AddressHandlerAdapter
acceptAddress
-
Methods inherited from class org.drasyl.pipeline.skeleton.HandlerAdapter
eventTriggered, exceptionCaught, handlerAdded, handlerRemoved, read
-
-
-
-
Method Detail
-
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
protected boolean acceptOutbound(Object msg)
-
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
-
-