11package com .github .dockerjava .core ;
22
3- import java .util .Iterator ;
4- import java .util .ServiceLoader ;
5-
63import com .github .dockerjava .api .DockerClient ;
74import com .github .dockerjava .api .command .DockerCmdExecFactory ;
85import com .github .dockerjava .core .DockerClientConfig .DockerClientConfigBuilder ;
6+ import com .github .dockerjava .jaxrs .DockerCmdExecFactoryImpl ;
97
108public class DockerClientBuilder {
119
12- private static Class <? extends DockerCmdExecFactory > factoryClass ;
13-
14- private static ServiceLoader <DockerCmdExecFactory > serviceLoader = ServiceLoader .load (DockerCmdExecFactory .class );
15-
16- static {
17- serviceLoader .reload ();
18- Iterator <DockerCmdExecFactory > iterator = serviceLoader .iterator ();
19- if (iterator .hasNext ()) {
20- factoryClass = iterator .next ().getClass ();
21- }
22- }
23-
2410 private DockerClientImpl dockerClient = null ;
2511
2612 private DockerCmdExecFactory dockerCmdExecFactory = null ;
@@ -46,28 +32,14 @@ public static DockerClientBuilder getInstance(String serverUrl) {
4632 }
4733
4834 public static DockerCmdExecFactory getDefaultDockerCmdExecFactory () {
49- if (factoryClass == null ) {
50- throw new RuntimeException ("Fatal: Can't find any implementation of '"
51- + DockerCmdExecFactory .class .getName () + "' in the current classpath." );
52- }
53-
54- try {
55- return factoryClass .newInstance ();
56- } catch (InstantiationException | IllegalAccessException e ) {
57- throw new RuntimeException ("Fatal: Can't create new instance of '" + factoryClass .getName () + "'" );
58- }
35+ return new DockerCmdExecFactoryImpl ();
5936 }
6037
6138 public DockerClientBuilder withDockerCmdExecFactory (DockerCmdExecFactory dockerCmdExecFactory ) {
6239 this .dockerCmdExecFactory = dockerCmdExecFactory ;
6340 return this ;
6441 }
6542
66- public DockerClientBuilder withServiceLoaderClassLoader (ClassLoader classLoader ) {
67- serviceLoader = ServiceLoader .load (DockerCmdExecFactory .class , classLoader );
68- return this ;
69- }
70-
7143 public DockerClient build () {
7244 if (dockerCmdExecFactory != null ) {
7345 dockerClient .withDockerCmdExecFactory (dockerCmdExecFactory );
0 commit comments