try {
status = cursor.getFirst(key, data, null);
BatchEvent batch = new BatchEvent();
for (int i = 0; status == OperationStatus.SUCCESS && i < batchSize; ++i) {
SimpleEvent event = createEvent(data);
if (event != null) {
batch.addEvent(event);
}
status = cursor.getNext(key, data, null);
}
try {
manager.send(batch);
} catch (Exception ioe) {
LOGGER.error("Error sending events", ioe);
break;
}
cursor.close();
cursor = null;
Transaction txn = environment.beginTransaction(null, null);
try {
for (Event event : batch.getEvents()) {
try {
Map<String, String> headers = event.getHeaders();
key = new DatabaseEntry(headers.get(FlumeEvent.GUID).getBytes(UTF8));
database.delete(txn, key);
} catch (Exception ex) {
LOGGER.error("Error deleting key from database", ex);
}
}
txn.commit();
} catch (Exception ex) {
LOGGER.error("Unable to commit transaction", ex);
if (txn != null) {
txn.abort();
}
}
} catch (Exception ex) {
LOGGER.error("Error reading database", ex);
shutdown = true;
break;
} finally {
if (cursor != null) {
cursor.close();
}
}
} else {
Transaction txn = environment.beginTransaction(null, null);
Cursor cursor = database.openCursor(txn, null);
try {
status = cursor.getFirst(key, data, LockMode.RMW);
while (status == OperationStatus.SUCCESS) {
SimpleEvent event = createEvent(data);
if (event != null) {
try {
manager.doSend(event);
} catch (Exception ioe) {
errors = true;