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 ErrorMessage
s.
public class ChunkedHandler extendsSimpleOutboundHandler
<ErrorMessage
,CompressedPublicKey
> {@Override
protected void matchedWrite(HandlerContext
ctx,CompressedPublicKey
recipient,ErrorMessage
msg,CompletableFuture
<Void
> future) { System.out.println(msg); } }
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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
Modifier and TypeMethodDescriptionprotected 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.AddressHandlerAdapter
acceptAddress
Methods 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: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
-
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
-