From 187d88967e0d72ee314d89fe72002e8867e5f427 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 21 Oct 2015 13:21:30 +0200 Subject: [PATCH] issue #349 Remove the ServiceLoader logic, as there will be only one implementation of DockerCmdExecFactory --- .../dockerjava/core/DockerClientBuilder.java | 32 ++----------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/github/dockerjava/core/DockerClientBuilder.java b/src/main/java/com/github/dockerjava/core/DockerClientBuilder.java index 28c84cab5..6aed6c358 100644 --- a/src/main/java/com/github/dockerjava/core/DockerClientBuilder.java +++ b/src/main/java/com/github/dockerjava/core/DockerClientBuilder.java @@ -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 factoryClass; - - private static ServiceLoader serviceLoader = ServiceLoader.load(DockerCmdExecFactory.class); - - static { - serviceLoader.reload(); - Iterator iterator = serviceLoader.iterator(); - if (iterator.hasNext()) { - factoryClass = iterator.next().getClass(); - } - } - private DockerClientImpl dockerClient = null; private DockerCmdExecFactory dockerCmdExecFactory = null; @@ -46,16 +32,7 @@ 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) { @@ -63,11 +40,6 @@ public DockerClientBuilder withDockerCmdExecFactory(DockerCmdExecFactory dockerC return this; } - public DockerClientBuilder withServiceLoaderClassLoader(ClassLoader classLoader) { - serviceLoader = ServiceLoader.load(DockerCmdExecFactory.class, classLoader); - return this; - } - public DockerClient build() { if (dockerCmdExecFactory != null) { dockerClient.withDockerCmdExecFactory(dockerCmdExecFactory);