Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
*/
public interface EventCallback {
public void onEvent(Event event);
public void onException(Throwable throwable);
public void onCompletion(int numEvents);
}
14 changes: 11 additions & 3 deletions src/main/java/com/github/dockerjava/api/model/EventNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,26 @@ public static EventNotifier create(EventCallback eventCallback, WebTarget webTar

@Override
public Void call() throws Exception {
Response response = webTarget.request().get(Response.class);
InputStream inputStream = response.readEntity(InputStream.class);
int numEvents=0;
Response response = null;
try {
response = webTarget.request().get(Response.class);
InputStream inputStream = response.readEntity(InputStream.class);
JsonParser jp = JSON_FACTORY.createParser(inputStream);
while (jp.nextToken() != JsonToken.END_OBJECT && !jp.isClosed()) {
eventCallback.onEvent(OBJECT_MAPPER.readValue(jp, Event.class));
numEvents++;
}
} finally {
}
catch(Exception e) {
eventCallback.onException(e);
}
finally {
if (response != null) {
response.close();
}
}
eventCallback.onCompletion(numEvents);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,15 @@ public void onEvent(Event event) {
LOG.info("Received event #{}: {}", countDownLatch.getCount(), event);
countDownLatch.countDown();
}

@Override
public void onException(Throwable throwable) {
LOG.error("Error occurred: {}", throwable.getMessage());
}

@Override
public void onCompletion(int numEvents) {
LOG.info("Number of events received: {}", numEvents);
}
}
}