I am looking to open up multiple connections using a netty client bootstrap in order to parse messages coming from multiple sources. The messages all have the same format, however, due to the amount of data that needs to be processed, I must run each connection on separate threads (This is assuming netty creates a thread per client channel, which I couldn't find a reference for - if that's not the case, how would this be achieved?).
This is the code that I use to connect to the data server:
var b = new Bootstrap()
.group(group)
.channel(classOf[NioSocketChannel])
.handler(RawFeedChannelInitializer)
var ch1 = b.clone().connect(host, port).sync().channel();
var ch2 = b.clone().connect(host, port).sync().channel();
The initializer calls RawPacketDecoder
, which extends ReplayingDecoder, and is defined here.
The code works well without @Sharable
when opening a single connection, but for the purpose of my application I must connect to the same server multiple times.
This results in the runtime error @Sharable annotation is not allowed
pointing to my RawPacketDecoder
class.
I am not entirely sure on how to get past this issue, short of reimplementing in scala an instantiable class of ReplayingDecoder
as my decoder based directly on ByteToMessageDecoder
.
Any help would be greatly appreciated.
Note: I am using netty 4.0.32 Final