public synchronized boolean isEmpty() { return currentBatch.isEmpty(); }
public synchronized MessageBatch drain() { if (!currentBatch.isEmpty()) { MessageBatch ret = currentBatch; currentBatch = new MessageBatch(mesageBatchSize); return ret; } else { return null; } } }
/** * Asynchronously writes the message batch to the channel. * * <p>If the write operation fails, then we will close the channel and trigger a reconnect. */ private void flushMessages(final Channel channel, final MessageBatch batch) { if (null == batch || batch.isEmpty()) { return; } final int numMessages = batch.size(); LOG.debug("writing {} messages to channel {}", batch.size(), channel.toString()); pendingMessages.addAndGet(numMessages); ChannelFuture future = channel.writeAndFlush(batch); future.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { pendingMessages.addAndGet(0 - numMessages); if (future.isSuccess()) { LOG.debug("sent {} messages to {}", numMessages, dstAddressPrefixedName); messagesSent.getAndAdd(batch.size()); } else { LOG.error("failed to send {} messages to {}: {}", numMessages, dstAddressPrefixedName, future.cause()); closeChannelAndReconnect(future.channel()); messagesLost.getAndAdd(numMessages); } } }); }
public synchronized boolean isEmpty() { return currentBatch.isEmpty(); }
public synchronized MessageBatch drain() { if(!currentBatch.isEmpty()) { MessageBatch ret = currentBatch; currentBatch = new MessageBatch(mesageBatchSize); return ret; } else { return null; } } }
/** * Asynchronously writes the message batch to the channel. * * If the write operation fails, then we will close the channel and trigger a reconnect. */ private void flushMessages(Channel channel, final MessageBatch batch) { if (null == batch || batch.isEmpty()) { return; } final int numMessages = batch.size(); LOG.debug("writing {} messages to channel {}", batch.size(), channel.toString()); pendingMessages.addAndGet(numMessages); ChannelFuture future = channel.write(batch); future.addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) throws Exception { pendingMessages.addAndGet(0 - numMessages); if (future.isSuccess()) { LOG.debug("sent {} messages to {}", numMessages, dstAddressPrefixedName); messagesSent.getAndAdd(batch.size()); } else { LOG.error("failed to send {} messages to {}: {}", numMessages, dstAddressPrefixedName, future.getCause()); closeChannelAndReconnect(future.getChannel()); messagesLost.getAndAdd(numMessages); } } }); }