当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionKeepAliveStrategy类代码示例

本文整理汇总了Java中org.apache.http.conn.ConnectionKeepAliveStrategy的典型用法代码示例。如果您正苦于以下问题:Java ConnectionKeepAliveStrategy类的具体用法?Java ConnectionKeepAliveStrategy怎么用?Java ConnectionKeepAliveStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionKeepAliveStrategy类属于org.apache.http.conn包,在下文中一共展示了ConnectionKeepAliveStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: DefaultRequestDirector

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
@Deprecated
public DefaultRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectHandler redirectHandler,
        final AuthenticationHandler targetAuthHandler,
        final AuthenticationHandler proxyAuthHandler,
        final UserTokenHandler userTokenHandler,
        final HttpParams params) {
    this(LogFactory.getLog(DefaultRequestDirector.class),
            requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler,
            new DefaultRedirectStrategyAdaptor(redirectHandler),
            new AuthenticationStrategyAdaptor(targetAuthHandler),
            new AuthenticationStrategyAdaptor(proxyAuthHandler),
            userTokenHandler,
            params);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:DefaultRequestDirector.java

示例2: MinimalClientExec

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
public MinimalClientExec(
        final HttpRequestExecutor requestExecutor,
        final HttpClientConnectionManager connManager,
        final ConnectionReuseStrategy reuseStrategy,
        final ConnectionKeepAliveStrategy keepAliveStrategy) {
    Args.notNull(requestExecutor, "HTTP request executor");
    Args.notNull(connManager, "Client connection manager");
    Args.notNull(reuseStrategy, "Connection reuse strategy");
    Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
    this.httpProcessor = new ImmutableHttpProcessor(
            new RequestContentHC4(),
            new RequestTargetHostHC4(),
            new RequestClientConnControl(),
            new RequestUserAgentHC4(VersionInfoHC4.getUserAgent(
                    "Apache-HttpClient", "org.apache.http.client", getClass())));
    this.requestExecutor    = requestExecutor;
    this.connManager        = connManager;
    this.reuseStrategy      = reuseStrategy;
    this.keepAliveStrategy  = keepAliveStrategy;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:21,代码来源:MinimalClientExec.java

示例3: MinimalClientExec

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
public MinimalClientExec(
        final HttpRequestExecutor requestExecutor,
        final HttpClientConnectionManager connManager,
        final ConnectionReuseStrategy reuseStrategy,
        final ConnectionKeepAliveStrategy keepAliveStrategy) {
    Args.notNull(requestExecutor, "HTTP request executor");
    Args.notNull(connManager, "Client connection manager");
    Args.notNull(reuseStrategy, "Connection reuse strategy");
    Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
    this.httpProcessor = new ImmutableHttpProcessor(
            new RequestContent(),
            new RequestTargetHost(),
            new RequestClientConnControl(),
            new RequestUserAgent(VersionInfo.getUserAgent(
                    "Apache-HttpClient", "org.apache.http.client", getClass())));
    this.requestExecutor    = requestExecutor;
    this.connManager        = connManager;
    this.reuseStrategy      = reuseStrategy;
    this.keepAliveStrategy  = keepAliveStrategy;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:MinimalClientExec.java

示例4: createMainExec

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
/**
 * Produces an instance of {@link ClientExecChain} to be used as a main exec.
 * <p>
 * Default implementation produces an instance of {@link MainClientExec}
 * </p>
 * <p>
 * For internal use.
 * </p>
 *
 * @since 4.4
 */
protected ClientExecChain createMainExec(
        final HttpRequestExecutor requestExec,
        final HttpClientConnectionManager connManager,
        final ConnectionReuseStrategy reuseStrategy,
        final ConnectionKeepAliveStrategy keepAliveStrategy,
        final HttpProcessor proxyHttpProcessor,
        final AuthenticationStrategy targetAuthStrategy,
        final AuthenticationStrategy proxyAuthStrategy,
        final UserTokenHandler userTokenHandler)
{
    return new MainClientExec(
            requestExec,
            connManager,
            reuseStrategy,
            keepAliveStrategy,
            proxyHttpProcessor,
            targetAuthStrategy,
            proxyAuthStrategy,
            userTokenHandler);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:32,代码来源:HttpClientBuilder.java

示例5: getStrategy

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
private ConnectionKeepAliveStrategy getStrategy() {
    return new ConnectionKeepAliveStrategy() {
        @Override
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator it = new BasicHeaderElementIterator
                    (response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase
                        ("timeout")) {
                    return Long.parseLong(value) * 1000;
                }
            }
            return 5 * 1000;
        }
    };
}
 
开发者ID:Bandwidth,项目名称:java-bandwidth,代码行数:20,代码来源:BandwidthClient.java

示例6: getKeepAliveStrategy

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
/**
 * @return The connection keep alive strategy.
 */
private ConnectionKeepAliveStrategy getKeepAliveStrategy() {

    return (response, context) -> {
        // Honor 'keep-alive' header
        HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
        while (it.hasNext()) {
            HeaderElement he = it.nextElement();
            String param = he.getName();
            String value = he.getValue();
            if (value != null && "timeout".equalsIgnoreCase(param)) {
                try {
                    return Long.parseLong(value) * 1000;
                } catch(NumberFormatException ignore) {
                    // let's move on the next header value
                    break;
                }
            }
        }
        // otherwise use the default value
        return defaultKeepAlive * 1000;
    };
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:26,代码来源:HttpClient.java

示例7: getRequestDirector

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
/** This method mainly exists to make the wrapper more testable. oh, apache's insanity. */
protected RequestDirector getRequestDirector(HttpRequestExecutor requestExec,
                                             ClientConnectionManager conman,
                                             ConnectionReuseStrategy reustrat,
                                             ConnectionKeepAliveStrategy kastrat,
                                             HttpRoutePlanner rouplan,
                                             HttpProcessor httpProcessor,
                                             HttpRequestRetryHandler retryHandler,
                                             RedirectHandler redirectHandler,
                                             AuthenticationHandler targetAuthHandler,
                                             AuthenticationHandler proxyAuthHandler,
                                             UserTokenHandler stateHandler,
                                             HttpParams params
) {
    return new DefaultRequestDirector(requestExec, conman, reustrat, kastrat, rouplan,
            httpProcessor, retryHandler, redirectHandler, targetAuthHandler, proxyAuthHandler,
            stateHandler, params);
}
 
开发者ID:triveous,项目名称:SoundcloudAPI,代码行数:19,代码来源:ApiWrapper.java

示例8: getRequestDirector

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
/** This method mainly exists to make the wrapper more testable. oh, apache's insanity. */
protected RequestDirector getRequestDirector(HttpRequestExecutor requestExec,
                                             ClientConnectionManager conman,
                                             ConnectionReuseStrategy reustrat,
                                             ConnectionKeepAliveStrategy kastrat,
                                             HttpRoutePlanner rouplan,
                                             HttpProcessor httpProcessor,
                                             HttpRequestRetryHandler retryHandler,
                                             RedirectHandler redirectHandler,
                                             AuthenticationHandler targetAuthHandler,
                                             AuthenticationHandler proxyAuthHandler,
                                             UserTokenHandler stateHandler,
                                             HttpParams params
) {
	return new DefaultRequestDirector(requestExec, conman, reustrat, kastrat, rouplan,
			httpProcessor, retryHandler, redirectHandler, targetAuthHandler, proxyAuthHandler,
			stateHandler, params);
}
 
开发者ID:EnteriseToolkit,项目名称:paperchains,代码行数:19,代码来源:ApiWrapper.java

示例9: getKeepAliveStrategy

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
private ConnectionKeepAliveStrategy getKeepAliveStrategy(final long defaultVal) {
    return new ConnectionKeepAliveStrategy() {
        @Override
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout")) {
                    return Long.parseLong(value) * 1000;
                }
            }
            return defaultVal;
        }
    };
}
 
开发者ID:UglyTroLL,项目名称:ReKognitionJavaSDK,代码行数:18,代码来源:HttpManager.java

示例10: getHttpClient

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
public HttpClient getHttpClient() {
	if (httpClient == null) {
		synchronized (this) {
			if (httpClient == null) {
				if (pool == null) { //初始化pool
					try {
						afterPropertiesSet();
					} catch (Exception e) {
						logger.error(e.getMessage(), e);
					}
				}

				HttpClientBuilder httpClientBuilder = HttpClients.custom();
				httpClientBuilder.setConnectionManager(pool);
				httpClientBuilder.setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(conntimeout).setSocketTimeout(sotimeout).build());
				httpClientBuilder.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
					public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
						HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
						while (it.hasNext()) {
							HeaderElement he = it.nextElement();
							String param = he.getName();
							String value = he.getValue();
							if (value != null && param.equalsIgnoreCase("timeout")) {
								try {
									return Long.parseLong(value) * 1000;
								} catch (NumberFormatException ignore) {
								}
							}
						}
						// 否则保持活动5秒
						return 5 * 1000;
					}
				});
				httpClient = httpClientBuilder.build();
			}
		}
	}
	return httpClient;
}
 
开发者ID:funtl,项目名称:framework,代码行数:40,代码来源:HttpClientUtil.java

示例11: createClientRequestDirector

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
/**
 * @deprecated (4.1) do not use
 */
@Deprecated
protected RequestDirector createClientRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectHandler redirectHandler,
        final AuthenticationHandler targetAuthHandler,
        final AuthenticationHandler proxyAuthHandler,
        final UserTokenHandler userTokenHandler,
        final HttpParams params) {
    return new DefaultRequestDirector(
            requestExec,
            conman,
            reustrat,
            kastrat,
            rouplan,
            httpProcessor,
            retryHandler,
            redirectHandler,
            targetAuthHandler,
            proxyAuthHandler,
            userTokenHandler,
            params);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:AbstractHttpClient.java

示例12: SafeHttpClient

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public SafeHttpClient() {

    HttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, factoryClassName);
    // 设置最大连接数
    ConnManagerParams.setMaxTotalConnections(httpParams, maxTotalConnections);
    // 设置获取连接的最大等待时间
    ConnManagerParams.setTimeout(httpParams, waitTimeout);
    // 设置每个路由最大连接数
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(maxRouteConnections);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute);
    // 设置连接超时时间
    HttpConnectionParams.setConnectionTimeout(httpParams, connectTimeout);
    // 设置读取超时时间
    HttpConnectionParams.setSoTimeout(httpParams, readTimeout);
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    this.setParams(httpParams);
    this.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator it =
                    new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout")) {
                    try {
                        return Long.parseLong(value) * 1000;
                    } catch (NumberFormatException ignore) {
                    }
                }
            }
            return 5 * 1000;
        }
    });
    this.getConnectionManager();
}
 
开发者ID:codeWatching,项目名称:codePay,代码行数:39,代码来源:SafeHttpClient.java

示例13: createConnectionKeepAliveStrategy

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
/**
 * Retrieve a keep alive strategy.
 * This will use the value of readTimeout.
 * @return strategy.
 */
protected ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy()
{
  return new ConnectionKeepAliveStrategy() {
    @Override
    public long getKeepAliveDuration( HttpResponse hr, HttpContext hc ) {
      return readTimeout;
    }};
}
 
开发者ID:SixArmDonkey,项目名称:aerodrome-for-jet,代码行数:14,代码来源:APIHttpClient.java

示例14: MainClientExec

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
public MainClientExec(
        final HttpRequestExecutor requestExecutor,
        final HttpClientConnectionManager connManager,
        final ConnectionReuseStrategy reuseStrategy,
        final ConnectionKeepAliveStrategy keepAliveStrategy,
        final AuthenticationStrategy targetAuthStrategy,
        final AuthenticationStrategy proxyAuthStrategy,
        final UserTokenHandler userTokenHandler) {
    Args.notNull(requestExecutor, "HTTP request executor");
    Args.notNull(connManager, "Client connection manager");
    Args.notNull(reuseStrategy, "Connection reuse strategy");
    Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
    Args.notNull(targetAuthStrategy, "Target authentication strategy");
    Args.notNull(proxyAuthStrategy, "Proxy authentication strategy");
    Args.notNull(userTokenHandler, "User token handler");
    this.authenticator      = new HttpAuthenticator();
    this.proxyHttpProcessor = new ImmutableHttpProcessor(
            new RequestTargetHostHC4(), new RequestClientConnControl());
    this.routeDirector      = new BasicRouteDirector();
    this.requestExecutor    = requestExecutor;
    this.connManager        = connManager;
    this.reuseStrategy      = reuseStrategy;
    this.keepAliveStrategy  = keepAliveStrategy;
    this.targetAuthStrategy = targetAuthStrategy;
    this.proxyAuthStrategy  = proxyAuthStrategy;
    this.userTokenHandler   = userTokenHandler;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:28,代码来源:MainClientExec.java

示例15: MainClientExec

import org.apache.http.conn.ConnectionKeepAliveStrategy; //导入依赖的package包/类
/**
 * @since 4.4
 */
public MainClientExec(
        final HttpRequestExecutor requestExecutor,
        final HttpClientConnectionManager connManager,
        final ConnectionReuseStrategy reuseStrategy,
        final ConnectionKeepAliveStrategy keepAliveStrategy,
        final HttpProcessor proxyHttpProcessor,
        final AuthenticationStrategy targetAuthStrategy,
        final AuthenticationStrategy proxyAuthStrategy,
        final UserTokenHandler userTokenHandler) {
    Args.notNull(requestExecutor, "HTTP request executor");
    Args.notNull(connManager, "Client connection manager");
    Args.notNull(reuseStrategy, "Connection reuse strategy");
    Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
    Args.notNull(proxyHttpProcessor, "Proxy HTTP processor");
    Args.notNull(targetAuthStrategy, "Target authentication strategy");
    Args.notNull(proxyAuthStrategy, "Proxy authentication strategy");
    Args.notNull(userTokenHandler, "User token handler");
    this.authenticator      = new HttpAuthenticator();
    this.routeDirector      = new BasicRouteDirector();
    this.requestExecutor    = requestExecutor;
    this.connManager        = connManager;
    this.reuseStrategy      = reuseStrategy;
    this.keepAliveStrategy  = keepAliveStrategy;
    this.proxyHttpProcessor = proxyHttpProcessor;
    this.targetAuthStrategy = targetAuthStrategy;
    this.proxyAuthStrategy  = proxyAuthStrategy;
    this.userTokenHandler   = userTokenHandler;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:32,代码来源:MainClientExec.java


注:本文中的org.apache.http.conn.ConnectionKeepAliveStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。