use of com.linkedin.r2.transport.common.TransportClientFactory in project rest.li by linkedin.
the class SimpleLoadBalancerState method createTransportClients.
private Map<String, TransportClient> createTransportClients(ServiceProperties serviceProperties) {
Map<String, Object> transportClientProperties = new HashMap<>(serviceProperties.getTransportClientProperties());
List<String> schemes = serviceProperties.getPrioritizedSchemes();
Map<String, TransportClient> newTransportClients = new HashMap<>();
if (schemes == null || schemes.isEmpty()) {
warn(_log, "Prioritized schemes is null for service properties = ", serviceProperties.getServiceName());
return newTransportClients;
}
for (String scheme : schemes) {
TransportClientFactory factory = _clientFactories.get(scheme);
if ("https".equals(scheme)) {
if (_isSSLEnabled) {
if (_sslContext != null && _sslParameters != null) {
transportClientProperties.put(HttpClientFactory.HTTP_SSL_CONTEXT, _sslContext);
transportClientProperties.put(HttpClientFactory.HTTP_SSL_PARAMS, _sslParameters);
} else {
error(_log, "https specified as a prioritized scheme for service: ", serviceProperties.getServiceName(), " but no SSLContext or SSLParameters have been configured.");
if (schemes.size() == 1) {
// throw exception when https is the only scheme specified
throw new IllegalStateException("SSL enabled but required SSLContext and SSLParameters" + "were not both present.");
}
continue;
}
} else {
continue;
}
}
if (factory == null) {
warn(_log, "Failed to find client factory for scheme ", scheme);
continue;
}
final String clusterName = serviceProperties.getClusterName();
transportClientProperties.put(HttpClientFactory.HTTP_SERVICE_NAME, serviceProperties.getServiceName());
transportClientProperties.put(HttpClientFactory.HTTP_POOL_STATS_NAME_PREFIX, clusterName);
TransportClient client = _sslSessionValidatorFactory == null ? factory.getClient(transportClientProperties) : new ClusterAwareTransportClient(clusterName, factory.getClient(transportClientProperties), _clusterInfo, _sslSessionValidatorFactory);
newTransportClients.put(scheme.toLowerCase(), client);
}
return newTransportClients;
}
Aggregations