From 7285f1982973fea4f3074108424e172965a514c8 Mon Sep 17 00:00:00 2001 From: Hazim Date: Wed, 25 Oct 2017 14:49:57 +0500 Subject: [PATCH] Add awaitSuccess with timeout --- .../core/command/PullImageResultCallback.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/github/dockerjava/core/command/PullImageResultCallback.java b/src/main/java/com/github/dockerjava/core/command/PullImageResultCallback.java index ce274dbe8..38db05def 100644 --- a/src/main/java/com/github/dockerjava/core/command/PullImageResultCallback.java +++ b/src/main/java/com/github/dockerjava/core/command/PullImageResultCallback.java @@ -50,4 +50,25 @@ public void awaitSuccess() { throw new DockerClientException("Could not pull image: " + message); } } + + /** + * Awaits the image to be pulled successful, with timeout + * + * @throws DockerClientException + * if the pull fails. + */ + public void awaitSuccess(long timeout, TimeUnit timeUnit) { + try { + awaitCompletion(timeout, timeUnit); + } catch (InterruptedException e) { + throw new DockerClientException("", e); + } + + if (latestItem == null) { + throw new DockerClientException("Could not pull image"); + } else if (!latestItem.isPullSuccessIndicated()) { + String message = (latestItem.getError() != null) ? latestItem.getError() : latestItem.getStatus(); + throw new DockerClientException("Could not pull image: " + message); + } + } }