Using Netty ChannelLocal

JavaDocs for Netty explains ChannelLocal to be similar to ThreadLocal, however I have some questions about this use. ThreadLocal is a static class with static methods that access instance-specific objects. ChannelLocal is not static, has a static internal map, or has static methods. The documentation does not include an example of accessing ChannelLocal or placing an object in ChannelLocal, so I was hoping someone could give me some idea about this usage.

Thanks!

+3
source share
1 answer

ChannelLocal is used to assign some data to a channel.

Here is an example:

// Declare public static final ChannelLocal<Integer> data = new ChannelLocal<Integer>(); // Set data.set(e.getChannel(), 1); // Get int a = data.get(e.getChannel()); 

Here are a couple of real life examples:

+4
source

Source: https://habr.com/ru/post/906692/


All Articles