markAsShared();
final State runtimeCfgState = this.copy();
runtimeCfgState.markAsShared();
final ServiceLocator locator = Injections.createLocator(new ClientBinder(runtimeCfgState.getProperties()));
locator.setDefaultClassAnalyzerName(JerseyClassAnalyzer.NAME);
// AutoDiscoverable.
if (!CommonProperties.getValue(runtimeCfgState.getProperties(), RuntimeType.CLIENT,
CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, Boolean.FALSE, Boolean.class)) {
runtimeCfgState.configureAutoDiscoverableProviders(locator);
} else {
runtimeCfgState.configureForcedAutoDiscoverableProviders(locator);
}
// Configure binders and features.
runtimeCfgState.configureMetaProviders(locator);
// Bind configuration.
final AbstractBinder configBinder = new AbstractBinder() {
@Override
protected void configure() {
bind(runtimeCfgState).to(Configuration.class);
}
};
final DynamicConfiguration dc = Injections.getConfiguration(locator);
configBinder.bind(dc);
dc.commit();
// Bind providers.
ProviderBinder.bindProviders(runtimeCfgState.getComponentBag(), RuntimeType.CLIENT, null, locator);
final ClientConfig configuration = new ClientConfig(runtimeCfgState);
final Connector connector = connectorProvider.getConnector(client, configuration);
final ClientRuntime crt = new ClientRuntime(configuration, connector, locator);
client.addListener(new JerseyClient.LifecycleListener() {
@Override
public void onClose() {
try {
crt.close();
} finally {
ServiceLocatorFactory.getInstance().destroy(locator.getName());
}
}
});
return crt;