Package org.drasyl.pipeline
Class AbstractEndHandler
- java.lang.Object
-
- org.drasyl.pipeline.AbstractEndHandler
-
- All Implemented Interfaces:
Handler
,HandlerContext
public abstract class AbstractEndHandler extends Object implements Handler
Skeleton implementation for end handler of thePipeline
.
-
-
Constructor Summary
Constructors Constructor Description AbstractEndHandler(String name, DrasylConfig config, Pipeline pipeline, io.reactivex.rxjava3.core.Scheduler scheduler, Identity identity, TypeValidator validator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DrasylConfig
config()
void
eventTriggered(HandlerContext ctx, Event event, CompletableFuture<Void> future)
Gets called if aEvent
was emitted.void
exceptionCaught(HandlerContext ctx, Exception cause)
Gets called if aException
was thrown.CompletableFuture<Void>
fireEventTriggered(Event event, CompletableFuture<Void> future)
Received an event.HandlerContext
fireExceptionCaught(Exception cause)
Received anThrowable
in one of the inbound operations.CompletableFuture<Void>
fireRead(CompressedPublicKey sender, Object msg, CompletableFuture<Void> future)
Received a message.Handler
handler()
void
handlerAdded(HandlerContext ctx)
Gets called after theHandler
was added to the actual context and it's ready to handle events.void
handlerRemoved(HandlerContext ctx)
Gets called after theHandler
was removed from the actual context and it doesn't handle events anymore.Identity
identity()
String
name()
Pipeline
pipeline()
void
read(HandlerContext ctx, CompressedPublicKey sender, Object msg, CompletableFuture<Void> future)
Gets called if aObject
was received.io.reactivex.rxjava3.core.Scheduler
scheduler()
Implementation Note: This method should always return a scheduler, that differs from the normal pipeline scheduler.TypeValidator
validator()
CompletableFuture<Void>
write(CompressedPublicKey recipient, Object msg, CompletableFuture<Void> future)
Request to write a message via thisHandlerContext
through thePipeline
.void
write(HandlerContext ctx, CompressedPublicKey recipient, Object msg, CompletableFuture<Void> future)
Gets called if aObject
was send from the application to a recipient.
-
-
-
Constructor Detail
-
AbstractEndHandler
public AbstractEndHandler(String name, DrasylConfig config, Pipeline pipeline, io.reactivex.rxjava3.core.Scheduler scheduler, Identity identity, TypeValidator validator)
-
-
Method Detail
-
handler
public Handler handler()
- Specified by:
handler
in interfaceHandlerContext
- Returns:
- the associated
Handler
-
handlerAdded
public void handlerAdded(HandlerContext ctx)
Description copied from interface:Handler
Gets called after theHandler
was added to the actual context and it's ready to handle events.- Specified by:
handlerAdded
in interfaceHandler
-
handlerRemoved
public void handlerRemoved(HandlerContext ctx)
Description copied from interface:Handler
Gets called after theHandler
was removed from the actual context and it doesn't handle events anymore.- Specified by:
handlerRemoved
in interfaceHandler
-
read
public void read(HandlerContext ctx, CompressedPublicKey sender, Object msg, CompletableFuture<Void> future)
Description copied from interface:Handler
Gets called if aObject
was received.
-
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
- Parameters:
ctx
- handler contextevent
- the eventfuture
- a future for the message
-
exceptionCaught
public void exceptionCaught(HandlerContext ctx, Exception cause)
Description copied from interface:Handler
Gets called if aException
was thrown.- Specified by:
exceptionCaught
in interfaceHandler
-
write
public void write(HandlerContext ctx, CompressedPublicKey recipient, Object msg, CompletableFuture<Void> future)
Description copied from interface:Handler
Gets called if aObject
was send from the application to a recipient.
-
name
public String name()
- Specified by:
name
in interfaceHandlerContext
- Returns:
- the name of the
Handler
-
fireExceptionCaught
public HandlerContext fireExceptionCaught(Exception cause)
Description copied from interface:HandlerContext
Received anThrowable
in one of the inbound operations.This will result in having the
Handler.exceptionCaught(HandlerContext, Exception)
method called of the nextHandler
contained in thePipeline
.- Specified by:
fireExceptionCaught
in interfaceHandlerContext
- Parameters:
cause
- the cause
-
fireRead
public CompletableFuture<Void> fireRead(CompressedPublicKey sender, Object msg, CompletableFuture<Void> future)
Description copied from interface:HandlerContext
Received a message.This will result in having the
Handler.read(HandlerContext, CompressedPublicKey, Object, CompletableFuture)
method called of the nextHandler
contained in thePipeline
.- Specified by:
fireRead
in interfaceHandlerContext
- Parameters:
sender
- the sender of the messagemsg
- the messagefuture
- the future of the message
-
fireEventTriggered
public CompletableFuture<Void> fireEventTriggered(Event event, CompletableFuture<Void> future)
Description copied from interface:HandlerContext
Received an event.This will result in having the
Handler.eventTriggered(HandlerContext, Event, CompletableFuture)
method called of the nextHandler
contained in thePipeline
.- Specified by:
fireEventTriggered
in interfaceHandlerContext
- Parameters:
event
- the eventfuture
- the future of the message
-
write
public CompletableFuture<Void> write(CompressedPublicKey recipient, Object msg, CompletableFuture<Void> future)
Description copied from interface:HandlerContext
Request to write a message via thisHandlerContext
through thePipeline
.- Specified by:
write
in interfaceHandlerContext
- Parameters:
recipient
- the recipient of the messagemsg
- the messagefuture
- the future of the message
-
config
public DrasylConfig config()
- Specified by:
config
in interfaceHandlerContext
- Returns:
- the corresponding
DrasylConfig
-
pipeline
public Pipeline pipeline()
- Specified by:
pipeline
in interfaceHandlerContext
- Returns:
- the corresponding
Pipeline
-
scheduler
public io.reactivex.rxjava3.core.Scheduler scheduler()
Description copied from interface:HandlerContext
Implementation Note: This method should always return a scheduler, that differs from the normal pipeline scheduler. E.g. theDrasylScheduler.getInstanceHeavy()
- Specified by:
scheduler
in interfaceHandlerContext
- Returns:
- the corresponding
Scheduler
-
identity
public Identity identity()
- Specified by:
identity
in interfaceHandlerContext
- Returns:
- the identity of this node
-
validator
public TypeValidator validator()
- Specified by:
validator
in interfaceHandlerContext
- Returns:
- the type validator
-
-