Skip to content

Commit

Permalink
Improved logging in PutFileEventHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
csrster committed Oct 12, 2021
1 parent 4f2a708 commit fa6ad58
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public PutFileEventHandler(List<String> pillars, File targetFile, URL uploadURL)

@Override
public void handleEvent(OperationEvent event) {
log.info("Got event from client: {}, {}", event.getEventType(), event.getInfo());
//TODO messages received after we are in finished=true should only be logged, but no further action taken.
logIfFinished(event);
log.info("Got event from client: {}, {} for conversation {}.", event.getEventType(), event.getInfo(), event.getConversationID());
if (event instanceof ContributorFailedEvent) {
log.info("Additional info: {}", ((ContributorFailedEvent) event).additionalInfo());
log.info("Additional info: {} for conversation {}.", ((ContributorFailedEvent) event).additionalInfo(), event.getConversationID());
}
switch (event.getEventType()) {
case IDENTIFICATION_COMPLETE:
Expand All @@ -62,19 +64,23 @@ public void handleEvent(OperationEvent event) {
}
break;
case COMPLETE:
log.info("Finished put fileID for file '{}'", event.getFileID());
logIfFinished(event);
log.info("Finished put fileID for file '{}' from conversation {}.", event.getFileID(), event.getConversationID());
cleanUpFileExchange();
finish();
break;
case FAILED:
logIfFinished(event);
log.info("Failed put fileID for file '{}'", event.getFileID());
if (event instanceof OperationFailedEvent) {
for (ContributorEvent contributorEvent: ((OperationFailedEvent) event).getComponentResults()) {
log.info("During put of {}, event {} from {} had status {} ({}).",
log.info("During put of {}, event {} from {} had status {} ({}) in conversation {}.",
event.getFileID(),
contributorEvent.getInfo(),
contributorEvent.getContributorID(),
contributorEvent.additionalInfo());
contributorEvent.additionalInfo(),
event.getConversationID()
);
}
}
failed = true;
Expand All @@ -92,6 +98,13 @@ public void handleEvent(OperationEvent event) {
}
}

private void logIfFinished(OperationEvent event) {
if (finished) {
log.info("CAREFUL! The following is an out-of-sync message for an event which we are finished handling: ", event
.getConversationID());
}
}

private void uploadToFileExchange() {
int bufferSize = 16384;
try (InputStream is = new BufferedInputStream(new FileInputStream(targetFile), bufferSize)) {
Expand Down

0 comments on commit fa6ad58

Please sign in to comment.