Class MessageToMessageEncoder<O,A extends Address>
- java.lang.Object
-
- org.drasyl.pipeline.skeleton.HandlerAdapter
-
- org.drasyl.pipeline.skeleton.AddressHandlerAdapter<A>
-
- org.drasyl.pipeline.skeleton.SimpleOutboundHandler<O,A>
-
- org.drasyl.pipeline.handler.codec.MessageToMessageEncoder<O,A>
-
- All Implemented Interfaces:
Handler
public abstract class MessageToMessageEncoder<O,A extends Address> extends SimpleOutboundHandler<O,A>
SimpleOutboundHandler
which encodes from one message to one ore more other message(s).For example here is an implementation which decodes an
Integer
to aString
.public class IntegerToStringEncoder extends
MessageToMessageEncoder
<Integer
,Address
> {@Override
public void encode(HandlerContext
ctx,Address
recipient,Integer
message, List<Object> out) throwsException
{ out.add(message.toString()); } }Be aware that you need to call
ReferenceCounted.retain()
on messages that are just passed through if they are of typeReferenceCounted
. This is needed as theMessageToMessageEncoder
will callReferenceCounted.release()
on encoded messages.
-
-
Constructor Summary
Constructors Constructor Description MessageToMessageEncoder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
encode(HandlerContext ctx, A recipient, O msg, List<Object> out)
Encode from one message to one or more other.protected void
matchedOutbound(HandlerContext ctx, A recipient, O msg, CompletableFuture<Void> future)
Is called for each message of typeSimpleOutboundHandler
.-
Methods inherited from class org.drasyl.pipeline.skeleton.SimpleOutboundHandler
acceptOutbound, onOutbound
-
Methods inherited from class org.drasyl.pipeline.skeleton.AddressHandlerAdapter
acceptAddress
-
Methods inherited from class org.drasyl.pipeline.skeleton.HandlerAdapter
onAdded, onEvent, onException, onInbound, onRemoved
-
-
-
-
Method Detail
-
matchedOutbound
protected void matchedOutbound(HandlerContext ctx, A recipient, O msg, CompletableFuture<Void> future) throws Exception
Description copied from class:SimpleOutboundHandler
Is called for each message of typeSimpleOutboundHandler
.- Specified by:
matchedOutbound
in classSimpleOutboundHandler<O,A extends Address>
- Parameters:
ctx
- handler contextrecipient
- the recipient of the messagemsg
- the messagefuture
- a future for the message- Throws:
Exception
-
encode
protected abstract void encode(HandlerContext ctx, A recipient, O msg, List<Object> out) throws Exception
Encode from one message to one or more other. This method will be called for each outbound message that can be handled by this decoder.- Parameters:
ctx
- theHandlerContext
which thisMessageToMessageDecoder
belongs torecipient
- the recipient of the messagemsg
- the message to encodeout
- theList
to which encoded messages should be added- Throws:
Exception
- is thrown if an error occurs
-
-