Package org.drasyl.pipeline.codec
Class Codec<E,D,A extends Address>
- java.lang.Object
-
- org.drasyl.pipeline.HandlerAdapter
-
- org.drasyl.pipeline.AddressHandlerAdapter<A>
-
- org.drasyl.pipeline.SimpleInboundHandler<I,E,A>
-
- org.drasyl.pipeline.SimpleDuplexHandler<E,Event,D,A>
-
- org.drasyl.pipeline.codec.Codec<E,D,A>
-
- All Implemented Interfaces:
Handler
- Direct Known Subclasses:
DefaultCodec
public abstract class Codec<E,D,A extends Address> extends SimpleDuplexHandler<E,Event,D,A>
Standard interface for all codecs of thePipeline
.
A codec can be used to encode/decode a given set of objects into the correct format to process the object in the ongoing steps.
A codec must have a symmetrical construction.encode(HandlerContext, Object, Consumer)
converts an object of type D into type E anddecode(HandlerContext, Object, Consumer)
vice versa.Note: You can use the
HandlerContext.inboundValidator()
} orHandlerContext.outboundValidator()
} to check if a givenClass
is allowed to be encode/decode.
-
-
Constructor Summary
Constructors Constructor Description Codec()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
matchedEventTriggered(HandlerContext ctx, Event event, CompletableFuture<Void> future)
Is called for each event of typeSimpleInboundHandler
.protected void
matchedRead(HandlerContext ctx, A sender, E msg, CompletableFuture<Void> future)
Is called for each message of typeSimpleInboundHandler
.protected void
matchedWrite(HandlerContext ctx, A recipient, D msg, CompletableFuture<Void> future)
Is called for each message of typeSimpleDuplexHandler
.-
Methods inherited from class org.drasyl.pipeline.SimpleDuplexHandler
acceptOutbound, write
-
Methods inherited from class org.drasyl.pipeline.SimpleInboundHandler
acceptEvent, acceptInbound, eventTriggered, read
-
Methods inherited from class org.drasyl.pipeline.AddressHandlerAdapter
acceptAddress
-
Methods inherited from class org.drasyl.pipeline.HandlerAdapter
exceptionCaught, handlerAdded, handlerRemoved
-
-
-
-
Method Detail
-
matchedEventTriggered
protected void matchedEventTriggered(HandlerContext ctx, Event event, CompletableFuture<Void> future)
Description copied from class:SimpleInboundHandler
Is called for each event of typeSimpleInboundHandler
.- Specified by:
matchedEventTriggered
in classSimpleInboundHandler<E,Event,A extends Address>
- Parameters:
ctx
- handler contextevent
- the eventfuture
- the future of the message
-
matchedRead
protected void matchedRead(HandlerContext ctx, A sender, E msg, CompletableFuture<Void> future)
Description copied from class:SimpleInboundHandler
Is called for each message of typeSimpleInboundHandler
.- Specified by:
matchedRead
in classSimpleInboundHandler<E,Event,A extends Address>
- Parameters:
ctx
- handler contextsender
- the sender of the messagemsg
- the messagefuture
- the future of the message
-
matchedWrite
protected void matchedWrite(HandlerContext ctx, A recipient, D msg, CompletableFuture<Void> future)
Description copied from class:SimpleDuplexHandler
Is called for each message of typeSimpleDuplexHandler
.- Specified by:
matchedWrite
in classSimpleDuplexHandler<E,Event,D,A extends Address>
- Parameters:
ctx
- handler contextrecipient
- the recipient of the messagemsg
- the messagefuture
- a future for the message
-
-