Package org.drasyl.pipeline.skeleton
Class SimpleInboundEventAwareHandler<I,E,A extends Address>
- java.lang.Object
-
- org.drasyl.pipeline.skeleton.HandlerAdapter
-
- org.drasyl.pipeline.skeleton.AddressHandlerAdapter<A>
-
- org.drasyl.pipeline.skeleton.SimpleInboundEventAwareHandler<I,E,A>
-
- All Implemented Interfaces:
Handler
- Direct Known Subclasses:
SimpleDuplexEventAwareHandler
,SimpleInboundHandler
public abstract class SimpleInboundEventAwareHandler<I,E,A extends Address> extends AddressHandlerAdapter<A>
HandlerAdapter
which allows to explicit only handle a specific type of inbound messages and events.For example here is an implementation which only handle inbound
MyMessage
messages andMessageEvent
events.public class MessageEventHandler extends
SimpleInboundEventAwareHandler
<MyMessage
,MessageEvent
,CompressedPublicKey
> {@Override
protected void matchedEventTriggered(HandlerContext
ctx,MessageEvent
event) { System.out.println(event); }@Override
protected void matchedRead(HandlerContext
ctx,CompressedPublicKey
sender,MyMessage
msg,CompletableFuture
<Void
> future) { System.out.println(msg); } }
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SimpleInboundEventAwareHandler()
Create a new instance which will try to detect the types to match out of the type parameter of the class.protected
SimpleInboundEventAwareHandler(Class<? extends I> inboundMessageType, Class<? extends E> inboundEventType, 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
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 typeSimpleInboundEventAwareHandler
.protected abstract void
matchedRead(HandlerContext ctx, A sender, I msg, CompletableFuture<Void> future)
Is called for each message of typeSimpleInboundEventAwareHandler
.void
read(HandlerContext ctx, Address sender, Object msg, CompletableFuture<Void> future)
Gets called if aObject
was received.-
Methods inherited from class org.drasyl.pipeline.skeleton.AddressHandlerAdapter
acceptAddress
-
Methods inherited from class org.drasyl.pipeline.skeleton.HandlerAdapter
exceptionCaught, handlerAdded, handlerRemoved, write
-
-
-
-
Constructor Detail
-
SimpleInboundEventAwareHandler
protected SimpleInboundEventAwareHandler()
Create a new instance which will try to detect the types to match out of the type parameter of the class.
-
SimpleInboundEventAwareHandler
protected SimpleInboundEventAwareHandler(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 Detail
-
read
public void read(HandlerContext ctx, Address 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 typeSimpleInboundEventAwareHandler
.- Parameters:
ctx
- handler contextevent
- the eventfuture
- the future of the message
-
acceptInbound
protected boolean acceptInbound(Object msg)
-
matchedRead
protected abstract void matchedRead(HandlerContext ctx, A sender, I msg, CompletableFuture<Void> future)
Is called for each message of typeSimpleInboundEventAwareHandler
.- Parameters:
ctx
- handler contextsender
- the sender of the messagemsg
- the messagefuture
- the future of the message
-
-