use of com.aphyr.riemann.Proto.Event in project nifi by apache.
the class PutRiemann method onTrigger.
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
// in the connection.
if (riemannClient == null || !riemannClient.isConnected()) {
// clean up the client and attempt to re-initialize the processor
cleanUpClient();
onScheduled(context);
}
List<FlowFile> incomingFlowFiles = session.get(batchSize);
List<FlowFile> successfulFlowFiles = new ArrayList<>(incomingFlowFiles.size());
List<Event> eventsQueue = new ArrayList<>(incomingFlowFiles.size());
for (FlowFile flowFile : incomingFlowFiles) {
try {
eventsQueue.add(FlowFileToEvent.fromAttributes(context, customAttributes, flowFile));
successfulFlowFiles.add(flowFile);
} catch (NumberFormatException e) {
getLogger().warn("Unable to create Riemann event.", e);
session.transfer(flowFile, REL_FAILURE);
}
}
try {
if (transport == Transport.TCP) {
Proto.Msg returnMessage = riemannClient.sendEvents(eventsQueue).deref(writeTimeout, TimeUnit.MILLISECONDS);
if (returnMessage == null) {
context.yield();
throw new ProcessException("Timed out writing to Riemann!");
}
} else {
riemannClient.sendEvents(eventsQueue);
}
riemannClient.flush();
session.transfer(successfulFlowFiles, REL_SUCCESS);
session.commit();
} catch (Exception e) {
context.yield();
session.transfer(incomingFlowFiles);
session.commit();
throw new ProcessException("Failed writing to Riemann\n" + e.getMessage());
}
}
Aggregations