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>
HandlerAdapter
which allows to explicit only handle a specific type of messages.For example here is an implementation which only handle
MyMessage
s of typeMyMessage
.public class ChunkedHandler extends
SimpleOutboundHandler
<MyMessage
,CompressedPublicKey
> {@Override
protected void matchedWrite(HandlerContext
ctx,CompressedPublicKey
recipient,MyMessage
msg,CompletableFuture
<Void
> future) { System.out.println(msg); } }
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SimpleOutboundHandler()
Create a new instance which will try to detect the types to match out of the type parameter of the class.protected
SimpleOutboundHandler(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 boolean
acceptOutbound(Object msg)
Returnstrue
if the given message should be handled.protected abstract void
matchedWrite(HandlerContext ctx, A recipient, O msg, CompletableFuture<Void> future)
Is called for each message of typeSimpleOutboundHandler
.void
write(HandlerContext ctx, Address recipient, Object msg, CompletableFuture<Void> future)
Gets called if aObject
was 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:Handler
Gets called if aObject
was send from the application to a recipient.- Specified by:
write
in interfaceHandler
- Overrides:
write
in 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
-
-