X Tutup
Skip to content

Commit 187d889

Browse files
committed
issue #349
Remove the ServiceLoader logic, as there will be only one implementation of DockerCmdExecFactory
1 parent 135cfe5 commit 187d889

File tree

1 file changed

+2
-30
lines changed

1 file changed

+2
-30
lines changed

src/main/java/com/github/dockerjava/core/DockerClientBuilder.java

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
package com.github.dockerjava.core;
22

3-
import java.util.Iterator;
4-
import java.util.ServiceLoader;
5-
63
import com.github.dockerjava.api.DockerClient;
74
import com.github.dockerjava.api.command.DockerCmdExecFactory;
85
import com.github.dockerjava.core.DockerClientConfig.DockerClientConfigBuilder;
6+
import com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl;
97

108
public 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

Comments
 (0)
X Tutup