forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaitContainerResultCallback.java
More file actions
76 lines (65 loc) · 2.12 KB
/
Copy pathWaitContainerResultCallback.java
File metadata and controls
76 lines (65 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Created on 21.07.2015
*/
package com.github.dockerjava.core.command;
import com.github.dockerjava.api.exception.DockerClientException;
import com.github.dockerjava.api.model.WaitResponse;
import com.github.dockerjava.core.async.ResultCallbackTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.CheckForNull;
import java.util.concurrent.TimeUnit;
/**
*
* @author Marcus Linke
*
* @deprecated use {@link com.github.dockerjava.api.command.WaitContainerResultCallback}
*/
@Deprecated
public class WaitContainerResultCallback extends ResultCallbackTemplate<WaitContainerResultCallback, WaitResponse> {
private static final Logger LOGGER = LoggerFactory.getLogger(WaitContainerResultCallback.class);
@CheckForNull
private WaitResponse waitResponse = null;
@Override
public void onNext(WaitResponse waitResponse) {
this.waitResponse = waitResponse;
LOGGER.debug(waitResponse.toString());
}
/**
* Awaits the status code from the container.
*
* @throws DockerClientException
* if the wait operation fails.
*/
public Integer awaitStatusCode() {
try {
awaitCompletion();
} catch (InterruptedException e) {
throw new DockerClientException("", e);
}
return getStatusCode();
}
/**
* Awaits the status code from the container.
*
* @throws DockerClientException
* if the wait operation fails.
*/
public Integer awaitStatusCode(long timeout, TimeUnit timeUnit) {
try {
if (!awaitCompletion(timeout, timeUnit)) {
throw new DockerClientException("Awaiting status code timeout.");
}
} catch (InterruptedException e) {
throw new DockerClientException("Awaiting status code interrupted: ", e);
}
return getStatusCode();
}
private Integer getStatusCode() {
if (waitResponse == null) {
throw new DockerClientException("Error while wait container");
} else {
return waitResponse.getStatusCode();
}
}
}