Reputation: 14790
Netty 4.1.2.Final
I am using Unpooled.wrappedBuffer
method to wrap more than one ByteBuf
s, API doc is here.
public static ByteBuf wrappedBuffer(ByteBuf... buffers)
The doc says
Reference count ownership of all variables is transfered to this method.
I update the question so it is more clear.
I need send more than one ByteBuf
s to multiple connections at once. I can't use ChannelGroup
because some of the clients works in long-polling mode which means the response has to be sent in next request whose channel is not ready at this moment.
Hence, I have the following data structure stores the connected channels
private static final ConcurrentHashMap<String, Channel> channels
= new ConcurrentHashMap<String, Channel>();
And I have a method to broadcast the ByteBuf to the channels
public static void broadcast(final long registrationID, final ByteBuf [] buffers){
final ByteBuf wrappedBuf = Unpooled.wrappedBuffer(buffers);
for( Map.Entry<String, Channel> entry : channels.entrySet()){
final Channel channel = entry.getValue();
if( channel != null ){
wrappedBuf.retain();
boolean isLongPooling = channel.attr(TYPE).get();
if( isLongPooling )
Reply.send( channel, wrappedBuf); // add into a queue which will be pulled by client in next request
else
channel.writeAndFlush(wrappedBuf); // real time client , send in current channel
}
}
wrappedBuf.release();
}
The problem is that: If I have more than one real-time clients connected, only one of them receives the response even if all of then are written.
It seems it is a problem caused by reference count?
Thank you
Upvotes: 0
Views: 523
Reputation: 23557
No... it means that the you need to call release() on the returned buffer.
Upvotes: 1