private void flushRequest(Channel channel, final MessageBatch requests) {
if (requests == null)
return;
pendings.incrementAndGet();
ChannelFuture future = channel.write(requests);
future.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future)
throws Exception {
pendings.decrementAndGet();
if (!future.isSuccess()) {
LOG.info(
"failed to send requests to " + remote_addr.toString() + ": ", future.getCause());
Channel channel = future.getChannel();
if (null != channel) {
channel.close();
channelRef.compareAndSet(channel, null);
}