Package org.drasyl.pipeline
Class SimpleInboundHandler<I,E>
- java.lang.Object
-
- org.drasyl.pipeline.HandlerAdapter
-
- org.drasyl.pipeline.SimpleInboundHandler<I,E>
-
- All Implemented Interfaces:
Handler
- Direct Known Subclasses:
SimpleDuplexHandler
public abstract class SimpleInboundHandler<I,E> extends HandlerAdapter
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 extends
SimpleInboundHandler
<ApplicationMessage
,MessageEvent
> {@Override
protected void matchedEventTriggered(HandlerContext
ctx,MessageEvent
event) { System.out.println(event); } }
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SimpleInboundHandler()
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)
Create a new instance
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected 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, CompressedPublicKey sender, I msg, CompletableFuture<Void> future)
Is called for each message of typeSimpleInboundHandler
.void
read(HandlerContext ctx, CompressedPublicKey sender, Object msg, CompletableFuture<Void> future)
Gets called if aObject
was received.-
Methods inherited from class org.drasyl.pipeline.HandlerAdapter
exceptionCaught, handlerAdded, handlerRemoved, write
-
-
-
-
Method Detail
-
read
public void read(HandlerContext ctx, CompressedPublicKey sender, Object msg, CompletableFuture<Void> future)
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
public void eventTriggered(HandlerContext ctx, Event event, CompletableFuture<Void> future)
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
protected boolean acceptEvent(Event msg)
-
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
protected boolean acceptInbound(Object msg)
-
matchedRead
protected abstract void matchedRead(HandlerContext ctx, CompressedPublicKey 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
-
-