Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions src/main/java/com/github/dockerjava/core/DockerClientBuilder.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
package com.github.dockerjava.core;

import java.util.Iterator;
import java.util.ServiceLoader;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.DockerCmdExecFactory;
import com.github.dockerjava.core.DockerClientConfig.DockerClientConfigBuilder;
import com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl;

public class DockerClientBuilder {

private static Class<? extends DockerCmdExecFactory> factoryClass;

private static ServiceLoader<DockerCmdExecFactory> serviceLoader = ServiceLoader.load(DockerCmdExecFactory.class);

static {
serviceLoader.reload();
Iterator<DockerCmdExecFactory> iterator = serviceLoader.iterator();
if (iterator.hasNext()) {
factoryClass = iterator.next().getClass();
}
}

private DockerClientImpl dockerClient = null;

private DockerCmdExecFactory dockerCmdExecFactory = null;
Expand All @@ -46,28 +32,14 @@ public static DockerClientBuilder getInstance(String serverUrl) {
}

public static DockerCmdExecFactory getDefaultDockerCmdExecFactory() {
if (factoryClass == null) {
throw new RuntimeException("Fatal: Can't find any implementation of '"
+ DockerCmdExecFactory.class.getName() + "' in the current classpath.");
}

try {
return factoryClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Fatal: Can't create new instance of '" + factoryClass.getName() + "'");
}
return new DockerCmdExecFactoryImpl();
}

public DockerClientBuilder withDockerCmdExecFactory(DockerCmdExecFactory dockerCmdExecFactory) {
this.dockerCmdExecFactory = dockerCmdExecFactory;
return this;
}

public DockerClientBuilder withServiceLoaderClassLoader(ClassLoader classLoader) {
serviceLoader = ServiceLoader.load(DockerCmdExecFactory.class, classLoader);
return this;
}

public DockerClient build() {
if (dockerCmdExecFactory != null) {
dockerClient.withDockerCmdExecFactory(dockerCmdExecFactory);
Expand Down