Class MessageToMessageDecoder<I,A extends Address>
- java.lang.Object
-
- org.drasyl.pipeline.skeleton.HandlerAdapter
-
- org.drasyl.pipeline.skeleton.AddressHandlerAdapter<A>
-
- org.drasyl.pipeline.skeleton.SimpleInboundEventAwareHandler<I,Event,A>
-
- org.drasyl.pipeline.skeleton.SimpleInboundHandler<I,A>
-
- org.drasyl.pipeline.handler.codec.MessageToMessageDecoder<I,A>
-
- All Implemented Interfaces:
Handler
public abstract class MessageToMessageDecoder<I,A extends Address> extends SimpleInboundHandler<I,A>
SimpleInboundHandler
which decodes from one message to one ore more other message(s).For example here is an implementation which decodes an
String
to anInteger
.public class StringToIntegerDecoder extends
MessageToMessageDecoder
<String
,Address
> {@Override
public void decode(HandlerContext
ctx,Address
recipient,String
message, List<Object> out) throwsException
{ out.add(message.length()); } }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 theMessageToMessageDecoder
will callReferenceCounted.release()
on encoded messages.
-
-
Constructor Summary
Constructors Constructor Description MessageToMessageDecoder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
decode(HandlerContext ctx, A sender, I msg, List<Object> out)
Decode from one message to one or more other.protected void
matchedInbound(HandlerContext ctx, A sender, I msg, CompletableFuture<Void> future)
Is called for each message of typeSimpleInboundEventAwareHandler
.-
Methods inherited from class org.drasyl.pipeline.skeleton.SimpleInboundHandler
matchedEvent, onEvent
-
Methods inherited from class org.drasyl.pipeline.skeleton.SimpleInboundEventAwareHandler
acceptEvent, acceptInbound, onInbound
-
Methods inherited from class org.drasyl.pipeline.skeleton.AddressHandlerAdapter
acceptAddress
-
Methods inherited from class org.drasyl.pipeline.skeleton.HandlerAdapter
onAdded, onException, onOutbound, onRemoved
-
-
-
-
Method Detail
-
matchedInbound
protected void matchedInbound(HandlerContext ctx, A sender, I msg, CompletableFuture<Void> future) throws Exception
Description copied from class:SimpleInboundEventAwareHandler
Is called for each message of typeSimpleInboundEventAwareHandler
.- Specified by:
matchedInbound
in classSimpleInboundEventAwareHandler<I,Event,A extends Address>
- Parameters:
ctx
- handler contextsender
- the sender of the messagemsg
- the messagefuture
- the future of the message- Throws:
Exception
-
decode
protected abstract void decode(HandlerContext ctx, A sender, I msg, List<Object> out) throws Exception
Decode from one message to one or more other. This method will be called for each inbound message that can be handled by this decoder.- Parameters:
ctx
- theHandlerContext
which thisMessageToMessageDecoder
belongs tosender
- the sender of the messagemsg
- the message to decodeout
- theList
to which decoded messages should be added- Throws:
Exception
- is thrown if an error occurs
-
-