Package org.drasyl.pipeline
Class SimpleInboundHandler<I,E,A extends Address>
java.lang.Object
org.drasyl.pipeline.HandlerAdapter
org.drasyl.pipeline.AddressHandlerAdapter<A>
org.drasyl.pipeline.SimpleInboundHandler<I,E,A>
- All Implemented Interfaces:
Handler
- Direct Known Subclasses:
ApplicationMessage2ObjectHolderHandler
,GroupsClientHandler
,GroupsManagerHandler
,SimpleDuplexHandler
HandlerAdapter
which allows to explicit only handle a specific type of messages and
events.
For example here is an implementation which only handle MessageEvent
events.
public class MessageEventHandler extendsSimpleInboundHandler
<ApplicationMessage
,MessageEvent
,CompressedPublicKey
> {@Override
protected void matchedEventTriggered(HandlerContext
ctx,MessageEvent
event) { System.out.println(event); }@Override
protected void matchedRead(HandlerContext
ctx,CompressedPublicKey
sender,ApplicationMessage
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
SimpleInboundHandler
(Class<? extends I> inboundMessageType, Class<? extends E> inboundEventType, Class<? extends A> addressType) Create a new instance -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
acceptEvent
(Event msg) Returnstrue
if the given event should be handled.protected boolean
acceptInbound
(Object msg) Returnstrue
if the given message should be handled.void
eventTriggered
(HandlerContext ctx, Event event, CompletableFuture<Void> future) Gets called if aEvent
was emitted.protected abstract void
matchedEventTriggered
(HandlerContext ctx, E event, CompletableFuture<Void> future) Is called for each event of typeSimpleInboundHandler
.protected abstract void
matchedRead
(HandlerContext ctx, A sender, I msg, CompletableFuture<Void> future) Is called for each message of typeSimpleInboundHandler
.void
read
(HandlerContext ctx, Address sender, Object msg, CompletableFuture<Void> future) Gets called if aObject
was received.Methods inherited from class org.drasyl.pipeline.AddressHandlerAdapter
acceptAddress
Methods inherited from class org.drasyl.pipeline.HandlerAdapter
exceptionCaught, handlerAdded, handlerRemoved, write
-
Constructor Details
-
SimpleInboundHandler
protected SimpleInboundHandler()Create a new instance which will try to detect the types to match out of the type parameter of the class. -
SimpleInboundHandler
protected SimpleInboundHandler(Class<? extends I> inboundMessageType, Class<? extends E> inboundEventType, Class<? extends A> addressType) Create a new instance- Parameters:
inboundMessageType
- the type of messages to matchinboundEventType
- the type of events to matchaddressType
- the type of the address to match
-
-
Method Details
-
read
Description copied from interface:Handler
Gets called if aObject
was received.- Specified by:
read
in interfaceHandler
- Overrides:
read
in classHandlerAdapter
- Parameters:
ctx
- handler contextsender
- the sender of the messagemsg
- the messagefuture
- a future for the message
-
eventTriggered
Description copied from interface:Handler
Gets called if aEvent
was emitted.- Specified by:
eventTriggered
in interfaceHandler
- Overrides:
eventTriggered
in classHandlerAdapter
- Parameters:
ctx
- handler contextevent
- the eventfuture
- a future for the message
-
acceptEvent
-
matchedEventTriggered
protected abstract void matchedEventTriggered(HandlerContext ctx, E event, CompletableFuture<Void> future) Is called for each event of typeSimpleInboundHandler
.- Parameters:
ctx
- handler contextevent
- the eventfuture
- the future of the message
-
acceptInbound
-
matchedRead
protected abstract void matchedRead(HandlerContext ctx, A sender, I msg, CompletableFuture<Void> future) Is called for each message of typeSimpleInboundHandler
.- Parameters:
ctx
- handler contextsender
- the sender of the messagemsg
- the messagefuture
- the future of the message
-