@@ -67,26 +67,30 @@ 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 ) {
85- // restEndpointUrl = config.url + "/v" + config.version;
91+ public DockerClient (Config config , Integer readTimeout , boolean enableLoggingFilter ) {
8692 ClientConfig clientConfig = new DefaultClientConfig ();
87- // clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
88- // Boolean.TRUE);
89-
93+
9094 SchemeRegistry schemeRegistry = new SchemeRegistry ();
9195 schemeRegistry .register (new Scheme ("http" , config .url .getPort (),
9296 PlainSocketFactory .getSocketFactory ()));
@@ -104,16 +108,19 @@ private DockerClient(Config config) {
104108 client = new ApacheHttpClient4 (new ApacheHttpClient4Handler (httpClient ,
105109 null , false ), clientConfig );
106110
107- client .setReadTimeout (10000 );
108- // Experimental support for unix sockets:
109- // client = new UnixSocketClient(clientConfig);
110-
111+ // 1 hour
112+ client .setReadTimeout (readTimeout );
113+
111114 client .addFilter (new JsonClientFilter ());
112- client .addFilter (new SelectiveLoggingFilter ());
115+
116+ if (enableLoggingFilter )
117+ client .addFilter (new SelectiveLoggingFilter ());
113118
114119 baseResource = client .resource (config .url + "/v" + config .version );
115120 }
116121
122+
123+
117124 public void setCredentials (String username , String password , String email ) {
118125 if (username == null ) {
119126 throw new IllegalArgumentException ("username is null" );
@@ -201,54 +208,22 @@ public ImportImageCmd importImageCmd(String repository,
201208 .withBaseResource (baseResource );
202209 }
203210
204- // public ImageCreateResponse importImage(String repository,
205- // InputStream imageStream) {
206- // return execute(importImageCmd(repository, imageStream));
207- // }
208-
209211 public SearchImagesCmd searchImagesCmd (String term ) {
210212 return new SearchImagesCmd (term ).withBaseResource (baseResource );
211213 }
212214
213- // public List<SearchItem> searchImages(String term) {
214- // return execute(searchImagesCmd(term));
215- // }
216-
217215 public RemoveImageCmd removeImageCmd (String imageId ) {
218216 return new RemoveImageCmd (imageId ).withBaseResource (baseResource );
219217 }
220218
221- // /**
222- // * Remove an image, deleting any tags it might have.
223- // */
224- // public void removeImage(String imageId) {
225- // execute(removeImageCmd(imageId));
226- // }
227- //
228- // public void removeImages(List<String> images) {
229- // Preconditions.checkNotNull(images, "List of images can't be null");
230- //
231- // for (String imageId : images) {
232- // removeImage(imageId);
233- // }
234- // }
235-
236219 public ListImagesCmd listImagesCmd () {
237220 return new ListImagesCmd ().withBaseResource (baseResource );
238221 }
239222
240- // public List<Image> listImages() {
241- // return execute(listImagesCmd());
242- // }
243-
244223 public InspectImageCmd inspectImageCmd (String imageId ) {
245224 return new InspectImageCmd (imageId ).withBaseResource (baseResource );
246225 }
247226
248- // public ImageInspectResponse inspectImage(String imageId) {
249- // return execute(inspectImageCmd(imageId));
250- // }
251-
252227 /**
253228 * * CONTAINER API *
254229 */
@@ -257,10 +232,6 @@ public ListContainersCmd listContainersCmd() {
257232 return new ListContainersCmd ().withBaseResource (baseResource );
258233 }
259234
260- // public List<Container> listContainers() {
261- // return execute(listContainersCmd());
262- // }
263-
264235 public CreateContainerCmd createContainerCmd (String image ) {
265236 return new CreateContainerCmd (new CreateContainerConfig ()).withImage (
266237 image ).withBaseResource (baseResource );
0 commit comments