當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。