Class DefaultHandlerContext
- java.lang.Object
-
- org.drasyl.pipeline.DefaultHandlerContext
-
- All Implemented Interfaces:
HandlerContext
public class DefaultHandlerContext extends Object
The default handler context implementation.
-
-
Constructor Summary
Constructors Constructor Description DefaultHandlerContext(String name, Handler handler, DrasylConfig config, Pipeline pipeline, DrasylScheduler dependentScheduler, DrasylScheduler independentScheduler, Identity identity, PeersManager peersManager, Serialization inboundSerialization, Serialization outboundSerialization)
Generates a new default handler context for the givenhandler
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DrasylConfig
config()
Returns the correspondingDrasylConfig
.DrasylScheduler
dependentScheduler()
This method returns the same thread pool that is used by the normal pipeline processing.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(Address sender, Object msg, CompletableFuture<Void> future)
Received a message.Handler
handler()
Returns the associatedHandler
.Identity
identity()
Returns the identity of this node.Serialization
inboundSerialization()
Returns the inboundSerialization
of this pipeline.DrasylScheduler
independentScheduler()
Implementation Note: This method must always return a scheduler, that differs from the normal pipeline scheduler.String
name()
Returns the name of theHandler
.Serialization
outboundSerialization()
Returns the outboundSerialization
of this pipeline.PeersManager
peersManager()
Returns the peers manager of this node.Pipeline
pipeline()
Returns the correspondingPipeline
.CompletableFuture<Void>
write(Address recipient, Object msg, CompletableFuture<Void> future)
Request to write a message via thisHandlerContext
through thePipeline
.
-
-
-
Constructor Detail
-
DefaultHandlerContext
public DefaultHandlerContext(String name, Handler handler, DrasylConfig config, Pipeline pipeline, DrasylScheduler dependentScheduler, DrasylScheduler independentScheduler, Identity identity, PeersManager peersManager, Serialization inboundSerialization, Serialization outboundSerialization)
Generates a new default handler context for the givenhandler
.- Parameters:
name
- the name of the handlerhandler
- the handlerconfig
- the config of the drasyl nodepipeline
- the corresponding pipeline objectdependentScheduler
- the dependent schedulerindependentScheduler
- the independent scheduleridentity
- the identity of the corresponding nodepeersManager
- the peers manager of the corresponding nodeinboundSerialization
- the inbound serialization of the pipelineoutboundSerialization
- the outbound serialization of the pipeline
-
-
Method Detail
-
handler
public Handler handler()
Description copied from interface:HandlerContext
Returns the associatedHandler
.- Returns:
- the associated
Handler
-
name
public String name()
Description copied from interface:HandlerContext
Returns the name of theHandler
.- 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
.Note: It is guaranteed that this method will always be executed inside the
HandlerContext.dependentScheduler()
.- Specified by:
fireExceptionCaught
in interfaceHandlerContext
- Parameters:
cause
- the cause
-
fireRead
public CompletableFuture<Void> fireRead(Address sender, Object msg, CompletableFuture<Void> future)
Description copied from interface:HandlerContext
Received a message.This will result in having the
Handler.read(HandlerContext, Address, Object, CompletableFuture)
method called of the nextHandler
contained in thePipeline
.Note: It is guaranteed that this method will always be executed inside the
HandlerContext.dependentScheduler()
.If an exception occurs during the execution of this method, the given
msg
is automatically released when it is of typeReferenceCounted
.- 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
.Note: It is guaranteed that this method will always be executed inside the
HandlerContext.dependentScheduler()
.- Specified by:
fireEventTriggered
in interfaceHandlerContext
- Parameters:
event
- the eventfuture
- the future of the message
-
write
public CompletableFuture<Void> write(Address recipient, Object msg, CompletableFuture<Void> future)
Description copied from interface:HandlerContext
Request to write a message via thisHandlerContext
through thePipeline
.This will result in having the
Handler.write(HandlerContext, Address, Object, CompletableFuture)
method called of the nextHandler
contained in thePipeline
.Note: It is guaranteed that this method will always be executed inside the
HandlerContext.dependentScheduler()
.If an exception occurs during the execution of this method, the given
msg
is automatically released when it is of typeReferenceCounted
.- Specified by:
write
in interfaceHandlerContext
- Parameters:
recipient
- the recipient of the messagemsg
- the messagefuture
- the future of the message
-
config
public DrasylConfig config()
Description copied from interface:HandlerContext
Returns the correspondingDrasylConfig
.- Specified by:
config
in interfaceHandlerContext
- Returns:
- the corresponding
DrasylConfig
-
pipeline
public Pipeline pipeline()
Description copied from interface:HandlerContext
Returns the correspondingPipeline
.- Specified by:
pipeline
in interfaceHandlerContext
- Returns:
- the corresponding
Pipeline
-
dependentScheduler
public DrasylScheduler dependentScheduler()
Description copied from interface:HandlerContext
This method returns the same thread pool that is used by the normal pipeline processing. Tasks given to this scheduler should be short living.- Specified by:
dependentScheduler
in interfaceHandlerContext
- Returns:
- normal pipeline processing thread pool
-
independentScheduler
public DrasylScheduler independentScheduler()
Description copied from interface:HandlerContext
Implementation Note: This method must always return a scheduler, that differs from the normal pipeline scheduler. E.g. theDrasylSchedulerUtil.getInstanceHeavy()
This method returns an independent scheduler that does not add the given task to the same pool as the normal pipeline thread pool.
- Specified by:
independentScheduler
in interfaceHandlerContext
- Returns:
- independent scheduler
DrasylScheduler
-
identity
public Identity identity()
Description copied from interface:HandlerContext
Returns the identity of this node.- Specified by:
identity
in interfaceHandlerContext
- Returns:
- the identity of this node
-
peersManager
public PeersManager peersManager()
Description copied from interface:HandlerContext
Returns the peers manager of this node.- Specified by:
peersManager
in interfaceHandlerContext
- Returns:
- the peers manager of this node
-
inboundSerialization
public Serialization inboundSerialization()
Description copied from interface:HandlerContext
Returns the inboundSerialization
of this pipeline.- Specified by:
inboundSerialization
in interfaceHandlerContext
- Returns:
- the inbound
Serialization
-
outboundSerialization
public Serialization outboundSerialization()
Description copied from interface:HandlerContext
Returns the outboundSerialization
of this pipeline.- Specified by:
outboundSerialization
in interfaceHandlerContext
- Returns:
- the outbound
Serialization
-
-