How to force a single MessageToByteEncoder.encode on multiple channels

29 views
Skip to first unread message

martin.a...@gmail.com

unread,
Oct 18, 2017, 10:48:06 AM10/18/17
to Netty discussions
Imagine the following scenario:
There are multiple clients and same message is dispatched to all of them. Now the message can be a single string, or, it can be a more complex object.
Since the MessageToByteEncoder.encode's output will result in the same byte buffer each and every time, why not actually call the operation just once and then write that out buffer to each channel.

This is important not only for sparing some system resource. Also imagine I have an message pool that I reuse, so if I decode particular message once, I know when I can "release" it.
Otherwise I'll need to trace whether it has been written to all receiving channels and "release" then.

Thanks

Norman Maurer

unread,
Oct 22, 2017, 12:00:34 AM10/22/17
to ne...@googlegroups.com
I am not sure what you are asking for honestly. If you want to do this just decode the message by yourself and write the same ´ByteBuf´ to multiple channels. Just be sure you correctly retain and duplicate it.

--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/e09ed85c-4117-48f3-80d4-34a7941dad3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

martin.a...@gmail.com

unread,
Oct 22, 2017, 4:50:03 AM10/22/17
to Netty discussions
hi there,
thanks for your answer! As far as I know Netty uses internal pool of ByteBuf. Can you show me a quick example of how obtaining, retaining and duplicating would look like as I'm not 100% familiar with the framework. Thank you!
Reply all
Reply to author
Forward
0 new messages