use of okhttp3.ConnectionPool in project okhttp by square.
the class StreamAllocation method newStream.
public HttpCodec newStream(OkHttpClient client, boolean doExtensiveHealthChecks) {
int connectTimeout = client.connectTimeoutMillis();
int readTimeout = client.readTimeoutMillis();
int writeTimeout = client.writeTimeoutMillis();
boolean connectionRetryEnabled = client.retryOnConnectionFailure();
try {
RealConnection resultConnection = findHealthyConnection(connectTimeout, readTimeout, writeTimeout, connectionRetryEnabled, doExtensiveHealthChecks);
HttpCodec resultCodec = resultConnection.newCodec(client, this);
synchronized (connectionPool) {
codec = resultCodec;
return resultCodec;
}
} catch (IOException e) {
throw new RouteException(e);
}
}
use of okhttp3.ConnectionPool in project okhttp by square.
the class StreamAllocation method streamFailed.
public void streamFailed(IOException e) {
Socket socket;
boolean noNewStreams = false;
synchronized (connectionPool) {
if (e instanceof StreamResetException) {
StreamResetException streamResetException = (StreamResetException) e;
if (streamResetException.errorCode == ErrorCode.REFUSED_STREAM) {
refusedStreamCount++;
}
// other errors must be retried on a new connection.
if (streamResetException.errorCode != ErrorCode.REFUSED_STREAM || refusedStreamCount > 1) {
noNewStreams = true;
route = null;
}
} else if (connection != null && (!connection.isMultiplexed() || e instanceof ConnectionShutdownException)) {
noNewStreams = true;
// If this route hasn't completed a call, avoid it for new connections.
if (connection.successCount == 0) {
if (route != null && e != null) {
routeSelector.connectFailed(route, e);
}
route = null;
}
}
socket = deallocate(noNewStreams, false, true);
}
closeQuietly(socket);
}
use of okhttp3.ConnectionPool in project twitter4j by yusuke.
the class Http2ClientTest method testSpdy.
public void testSpdy() throws Exception {
AlternativeHttpClientImpl.sPreferSpdy = true;
AlternativeHttpClientImpl.sPreferHttp2 = false;
AlternativeHttpClientImpl http = callOembed();
// check SPDY
Field f = http.getClass().getDeclaredField("okHttpClient");
f.setAccessible(true);
OkHttpClient client = (OkHttpClient) f.get(http);
assertNotNull("ensure that OkHttpClient is used", client);
ConnectionPool p = client.connectionPool();
assertEquals(1, p.connectionCount());
assertEquals(Protocol.SPDY_3, http.getLastRequestProtocol());
}
use of okhttp3.ConnectionPool in project atlasdb by palantir.
the class FeignOkHttpClients method newRawOkHttpClient.
@VisibleForTesting
static okhttp3.OkHttpClient newRawOkHttpClient(Optional<SSLSocketFactory> sslSocketFactory, Optional<ProxySelector> proxySelector, String userAgent) {
// Don't allow retrying on connection failures - see ticket #2194
okhttp3.OkHttpClient.Builder builder = new okhttp3.OkHttpClient.Builder().connectionSpecs(CONNECTION_SPEC_WITH_CYPHER_SUITES).connectionPool(new ConnectionPool(CONNECTION_POOL_SIZE, KEEP_ALIVE_TIME_MILLIS, TimeUnit.MILLISECONDS)).proxySelector(proxySelector.orElse(ProxySelector.getDefault())).retryOnConnectionFailure(false);
if (sslSocketFactory.isPresent()) {
builder.sslSocketFactory(sslSocketFactory.get());
}
builder.interceptors().add(new UserAgentAddingInterceptor(userAgent));
globalClientSettings.accept(builder);
return builder.build();
}
use of okhttp3.ConnectionPool in project protools by SeanDragon.
the class ToolHttpBuilder method init.
private static void init() {
// 连接池
connectionPool = new ConnectionPool(DEFAULT_MAX_IDLE_CONNECTIONS, DEFAULT_KEEP_ALIVE_DURATION, TimeUnit.MINUTES);
// 客户端构建对象
defaultBuilder = new OkHttpClient.Builder();
// 设置超时时间
defaultBuilder.connectTimeout(DEFAULT_CONNECT_TIMEOUT, TimeUnit.SECONDS).writeTimeout(DEFAULT_WRITE_TIMEOUT, TimeUnit.SECONDS).readTimeout(DEFAULT_READ_TIMEOUT, TimeUnit.SECONDS).connectionPool(connectionPool).retryOnConnectionFailure(true).followRedirects(true).followSslRedirects(true);
defaultClient = defaultBuilder.build();
// Runtime.getRuntime().addShutdownHook(new Thread(() -> connectionPool.evictAll()));
}
Aggregations