Lazy initialisation of the singleton default client factory instance
public class HttpCommandExecutor implements CommandExecutor, NeedsLocalLogs {
- private static final HttpClient.Factory defaultClientFactory = HttpClient.Factory.createDefault();
-
private final URL remoteServer;
private final HttpClient client;
private final HttpClient.Factory httpClientFactory;
private LocalLogs logs = LocalLogs.getNullLogger();
+ private static class DefaultClientFactoryHolder {
+ static HttpClient.Factory defaultClientFactory = HttpClient.Factory.createDefault();
+ }
+
+ public static HttpClient.Factory getDefaultClientFactory() {
+ return DefaultClientFactoryHolder.defaultClientFactory;
+ }
+
public HttpCommandExecutor(URL addressOfRemoteServer) {
this(emptyMap(), Require.nonNull("Server URL", addressOfRemoteServer));
}
@@ -63,7 +69,7 @@ public HttpCommandExecutor(URL addressOfRemoteServer) {
public HttpCommandExecutor(ClientConfig config) {
this(emptyMap(),
Require.nonNull("HTTP client configuration", config),
- defaultClientFactory);
+ getDefaultClientFactory());
}
/**
@@ -79,7 +85,7 @@ public HttpCommandExecutor(
{
this(Require.nonNull("Additional commands", additionalCommands),
Require.nonNull("Server URL", addressOfRemoteServer),
- defaultClientFactory);
+ getDefaultClientFactory());
}
public HttpCommandExecutor(
