Make AbstractHttpClientProvider contents lazily instantiated

This commit is contained in:
Bingkun Guo 2015-06-08 09:01:45 -05:00
parent 52f261eea7
commit 22607d19be
1 changed files with 5 additions and 9 deletions

View File

@ -36,9 +36,7 @@ public abstract class AbstractHttpClientProvider<HttpClientType> implements Prov
private final Key<Supplier<DruidHttpClientConfig>> configKey; private final Key<Supplier<DruidHttpClientConfig>> configKey;
private final Key<SSLContext> sslContextKey; private final Key<SSLContext> sslContextKey;
private Provider<Supplier<DruidHttpClientConfig>> configProvider; private Injector injector;
private Provider<Lifecycle> lifecycleProvider;
private Binding<SSLContext> sslContextBinding;
public AbstractHttpClientProvider() public AbstractHttpClientProvider()
{ {
@ -73,9 +71,7 @@ public abstract class AbstractHttpClientProvider<HttpClientType> implements Prov
@Inject @Inject
public void configure(Injector injector) public void configure(Injector injector)
{ {
configProvider = injector.getProvider(configKey); this.injector = injector;
sslContextBinding = injector.getExistingBinding(sslContextKey);
lifecycleProvider = injector.getProvider(Lifecycle.class);
} }
public Key<Supplier<DruidHttpClientConfig>> getConfigKey() public Key<Supplier<DruidHttpClientConfig>> getConfigKey()
@ -90,16 +86,16 @@ public abstract class AbstractHttpClientProvider<HttpClientType> implements Prov
public Provider<Supplier<DruidHttpClientConfig>> getConfigProvider() public Provider<Supplier<DruidHttpClientConfig>> getConfigProvider()
{ {
return configProvider; return injector.getProvider(configKey);
} }
public Provider<Lifecycle> getLifecycleProvider() public Provider<Lifecycle> getLifecycleProvider()
{ {
return lifecycleProvider; return injector.getProvider(Lifecycle.class);
} }
public Binding<SSLContext> getSslContextBinding() public Binding<SSLContext> getSslContextBinding()
{ {
return sslContextBinding; return injector.getExistingBinding(sslContextKey);
} }
} }