本文整理汇总了Java中com.squareup.okhttp.ConnectionPool类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionPool类的具体用法?Java ConnectionPool怎么用?Java ConnectionPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionPool类属于com.squareup.okhttp包,在下文中一共展示了ConnectionPool类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createClient
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
private OkHttpClient createClient() {
OkHttpClient client = new OkHttpClient();
client.setFollowProtocolRedirects(followRedirects);
if (connectTimeout != DEFAULT_TIMEOUT) {
client.setConnectTimeout(connectTimeout, SECONDS);
}
if (readTimeout != DEFAULT_TIMEOUT) {
client.setReadTimeout(readTimeout, SECONDS);
}
if (allowInsecure) {
client.setSslSocketFactory(createInsecureSslSocketFactory());
}
// If we don't set this reference, there's no way to clean shutdown persistent connections.
client.setConnectionPool(ConnectionPool.getDefault());
return client;
}
示例2: createHttpClient
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
/**
* @return a new http client
*/
private OkHttpClient createHttpClient() {
OkHttpClient client = new OkHttpClient();
client.setReadTimeout(connectorOptions.getReadTimeout(), TimeUnit.SECONDS);
client.setWriteTimeout(connectorOptions.getWriteTimeout(), TimeUnit.SECONDS);
client.setConnectTimeout(connectorOptions.getConnectTimeout(), TimeUnit.SECONDS);
client.setFollowRedirects(connectorOptions.isFollowRedirects());
client.setFollowSslRedirects(connectorOptions.isFollowRedirects());
client.setProxySelector(ProxySelector.getDefault());
client.setCookieHandler(CookieHandler.getDefault());
client.setCertificatePinner(CertificatePinner.DEFAULT);
client.setAuthenticator(AuthenticatorAdapter.INSTANCE);
client.setConnectionPool(ConnectionPool.getDefault());
client.setProtocols(Util.immutableList(Protocol.HTTP_1_1));
client.setConnectionSpecs(DEFAULT_CONNECTION_SPECS);
client.setSocketFactory(SocketFactory.getDefault());
Internal.instance.setNetwork(client, Network.DEFAULT);
return client;
}
示例3: HawkularMetricsClient
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
/**
* Constructor.
* @param metricsServer
*/
public HawkularMetricsClient(URL metricsServer) {
this.serverUrl = metricsServer;
httpClient = new OkHttpClient();
httpClient.setReadTimeout(DEFAULT_READ_TIMEOUT, TimeUnit.SECONDS);
httpClient.setWriteTimeout(DEFAULT_WRITE_TIMEOUT, TimeUnit.SECONDS);
httpClient.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT, TimeUnit.SECONDS);
httpClient.setFollowRedirects(true);
httpClient.setFollowSslRedirects(true);
httpClient.setProxySelector(ProxySelector.getDefault());
httpClient.setCookieHandler(CookieHandler.getDefault());
httpClient.setCertificatePinner(CertificatePinner.DEFAULT);
httpClient.setAuthenticator(AuthenticatorAdapter.INSTANCE);
httpClient.setConnectionPool(ConnectionPool.getDefault());
httpClient.setProtocols(Util.immutableList(Protocol.HTTP_1_1));
httpClient.setConnectionSpecs(DEFAULT_CONNECTION_SPECS);
httpClient.setSocketFactory(SocketFactory.getDefault());
Internal.instance.setNetwork(httpClient, Network.DEFAULT);
}
示例4: createDefaultHttpClient
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
private OkHttpClient createDefaultHttpClient() {
OkHttpClient httpClient = new OkHttpClient();
httpClient.setConnectTimeout(10, TimeUnit.SECONDS);
httpClient.setReadTimeout(10, TimeUnit.SECONDS);
httpClient.setWriteTimeout(20, TimeUnit.SECONDS);
httpClient.setConnectionPool(new ConnectionPool(20, 2 * 60 * 1000));
return httpClient;
}
示例5: RouteSelector
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool,
Dns dns, RouteDatabase routeDatabase) {
this.address = address;
this.uri = uri;
this.proxySelector = proxySelector;
this.pool = pool;
this.dns = dns;
this.routeDatabase = routeDatabase;
this.postponedRoutes = new LinkedList<Route>();
resetNextProxy(uri, address.getProxy());
}
示例6: startPollingOnChangeEndpoint
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
public void startPollingOnChangeEndpoint(
OnServerContentChangeListener onServerContentChangeListener) {
if (mOnChangePollingEnabled) {
// polling already enabled
return;
}
mOnChangePollingEnabled = true;
mOnServerContentChangeListener = onServerContentChangeListener;
mOnChangePollingClient = new OkHttpClient();
mOnChangePollingClient
.setConnectionPool(new ConnectionPool(1, LONG_POLL_KEEP_ALIVE_DURATION_MS))
.setConnectTimeout(HTTP_CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
enqueueOnChangeEndpointLongPolling();
}
示例7: okClient
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
OkClient okClient() {
val client = okHttpClientConfig.create();
client.setConnectionPool(new ConnectionPool(maxIdleConnections, keepAliveDurationMs));
client.setRetryOnConnectionFailure(retryOnConnectionFailure);
client.interceptors().add(new RetryingInterceptor(maxElapsedBackoffMs));
return new OkClient(client);
}
示例8: okClient
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
OkClient okClient() {
OkHttpClient client = okHttpClientConfig.create();
client.setConnectionPool(new ConnectionPool(maxIdleConnections, keepAliveDurationMs));
client.setRetryOnConnectionFailure(retryOnConnectionFailure);
return new OkClient(client);
}
示例9: HttpConnection
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
public HttpConnection(ConnectionPool paramConnectionPool, Connection paramConnection, Socket paramSocket)
throws IOException
{
this.pool = paramConnectionPool;
this.connection = paramConnection;
this.socket = paramSocket;
this.source = Okio.buffer(Okio.source(paramSocket));
this.sink = Okio.buffer(Okio.sink(paramSocket));
}
示例10: RouteSelector
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool, Dns dns, RouteDatabase routeDatabase) {
this.address = address;
this.uri = uri;
this.proxySelector = proxySelector;
this.pool = pool;
this.dns = dns;
this.routeDatabase = routeDatabase;
this.postponedRoutes = new LinkedList<Route>();
resetNextProxy(uri, address.getProxy());
}
示例11: provideClient
import com.squareup.okhttp.ConnectionPool; //导入依赖的package包/类
@Provides
@Singleton
Client provideClient(OkHttpClient client) {
client = new OkHttpClient();
client.setConnectTimeout(30, TimeUnit.SECONDS); // connect timeout
client.setReadTimeout(30, TimeUnit.SECONDS); // socket timeout
client.setConnectionPool(new ConnectionPool(0, 5 * 60 * 1000));
return new OkClient(client);
}