private void run() throws IOException, FlumeException,
EventDeliveryException {
EventReader reader = null;
RpcClient rpcClient;
if (rpcClientPropsFile != null) {
rpcClient = RpcClientFactory.getInstance(new File(rpcClientPropsFile));
} else {
rpcClient = RpcClientFactory.getDefaultInstance(hostname, port,
BATCH_SIZE);
}
try {
if (fileName != null) {
reader = new SimpleTextLineEventReader(new FileReader(new File(fileName)));
} else if (dirName != null) {
reader = new ReliableSpoolingFileEventReader.Builder()
.spoolDirectory(new File(dirName)).build();
} else {
reader = new SimpleTextLineEventReader(new InputStreamReader(System.in));
}
long lastCheck = System.currentTimeMillis();
long sentBytes = 0;
int batchSize = rpcClient.getBatchSize();
List<Event> events;
while (!(events = reader.readEvents(batchSize)).isEmpty()) {
for (Event event : events) {
event.setHeaders(headers);
sentBytes += event.getBody().length;
sent++;
long now = System.currentTimeMillis();
if (now >= lastCheck + 5000) {
logger.debug("Packed {} bytes, {} events", sentBytes, sent);
lastCheck = now;
}
}
rpcClient.appendBatch(events);
if (reader instanceof ReliableEventReader) {
((ReliableEventReader) reader).commit();
}
}
logger.debug("Finished");
} finally {
if (reader != null) {
logger.debug("Closing reader");
reader.close();
}
logger.debug("Closing RPC client");
rpcClient.close();
}
}