Skip to content

Commit 5cbefec

Browse files
committed
Add extra parameters to the DockerClient constructor's
The defaults remain 10 seconds for the read time out and to enable the LoggingFilter. Allows the caller to change the read time out and to disable the LoggingFilter For large images the logging filter spam's the console with the binary data that is being transferred. This new setting allows it to be turned off.
1 parent 11c0554 commit 5cbefec

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/main/java/com/github/dockerjava/client/DockerClient.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,28 @@ public class DockerClient {
6767
private AuthConfig authConfig;
6868

6969
public DockerClient() throws DockerException {
70-
this(Config.createConfig());
70+
this(10000, true);
71+
}
72+
public DockerClient(Integer readTimeout, boolean enableLoggingFilter) throws DockerException {
73+
this(Config.createConfig(), readTimeout, enableLoggingFilter);
7174
}
7275

7376
public DockerClient(String serverUrl) throws DockerException {
74-
this(configWithServerUrl(serverUrl));
77+
this(serverUrl, 10000, true);
7578
}
7679

80+
public DockerClient(String serverUrl, Integer readTimeout, boolean enableLoggingFilter) throws DockerException {
81+
this(configWithServerUrl(serverUrl), readTimeout, enableLoggingFilter);
82+
}
83+
7784
private static Config configWithServerUrl(String serverUrl)
7885
throws DockerException {
7986
final Config c = Config.createConfig();
8087
c.url = URI.create(serverUrl);
8188
return c;
8289
}
8390

84-
private DockerClient(Config config) {
91+
public DockerClient(Config config, Integer readTimeout, boolean enableLoggingFilter) {
8592
ClientConfig clientConfig = new DefaultClientConfig();
8693

8794
SchemeRegistry schemeRegistry = new SchemeRegistry();
@@ -101,14 +108,19 @@ private DockerClient(Config config) {
101108
client = new ApacheHttpClient4(new ApacheHttpClient4Handler(httpClient,
102109
null, false), clientConfig);
103110

104-
client.setReadTimeout(10000);
111+
// 1 hour
112+
client.setReadTimeout(readTimeout);
105113

106114
client.addFilter(new JsonClientFilter());
107-
client.addFilter(new SelectiveLoggingFilter());
115+
116+
if (enableLoggingFilter)
117+
client.addFilter(new SelectiveLoggingFilter());
108118

109119
baseResource = client.resource(config.url + "/v" + config.version);
110120
}
111121

122+
123+
112124
public void setCredentials(String username, String password, String email) {
113125
if (username == null) {
114126
throw new IllegalArgumentException("username is null");

0 commit comments

Comments
 (0)