本文整理匯總了Java中org.apache.http.impl.conn.PoolingClientConnectionManager.setDefaultMaxPerRoute方法的典型用法代碼示例。如果您正苦於以下問題:Java PoolingClientConnectionManager.setDefaultMaxPerRoute方法的具體用法?Java PoolingClientConnectionManager.setDefaultMaxPerRoute怎麽用?Java PoolingClientConnectionManager.setDefaultMaxPerRoute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.conn.PoolingClientConnectionManager
的用法示例。
在下文中一共展示了PoolingClientConnectionManager.setDefaultMaxPerRoute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getHttpClient
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
/**
* 每次返回一個新的HttpClient實例
* @author nan.li
* @return
*/
public static DefaultHttpClient getHttpClient()
{
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
cm.setMaxTotal(500);
cm.setDefaultMaxPerRoute(200);
HttpParams params = new BasicHttpParams();
params.setParameter("http.connection.timeout", Integer.valueOf(CON_TIMEOUT));
params.setParameter("http.socket.timeout", Integer.valueOf(SO_TIMEOUT));
params.setParameter("http.useragent", UA_WINDOW7_CHROME);
DefaultHttpClient client = new DefaultHttpClient(cm, params);
return client;
}
示例2: pooledConnectionHttpClient
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
/**
* Creates an HttpClient with a Pooling Client connection manager.
*
* @param maxConnections the max number of connections
* @param connectionTimeoutInMs the connection timeout in ms.
* @param socketTimeoutInMs the socket timeout in ms.
* @return an HttpClient with a Pooling Client connection manager.
*/
public static HttpClient pooledConnectionHttpClient(int maxConnections, int connectionTimeoutInMs, int socketTimeoutInMs) {
PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
cm.setDefaultMaxPerRoute(maxConnections);
cm.setMaxTotal(maxConnections);
HttpClient httpClient = new DefaultHttpClient(cm);
HttpParams params = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, connectionTimeoutInMs);
HttpConnectionParams.setSoTimeout(params, socketTimeoutInMs);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Created Pooled HTTP Client. Max Connections per route=" + maxConnections +
", Max Connections=" + maxConnections + ", Connection Timeout in ms=" + connectionTimeoutInMs + ", Socket Timeout in ms=" + socketTimeoutInMs);
}
return httpClient;
}
示例3: HttpClientFactory
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
/**
* Constructor.
* @param ssl True if SSL connections are desired. False otherwise.
*/
public HttpClientFactory(boolean ssl) {
// create the logger
logger = Logger.getLogger(HttpClientFactory.class);
if (ssl) {
sslConnectionsManager = new PoolingClientConnectionManager(getSchemeRegistry());
sslConnectionsManager.setMaxTotal(Constants.MAX_CONNS);
sslConnectionsManager.setDefaultMaxPerRoute(Constants.MAX_CONNS_PER_ROUTE);
} else {
connectionsManager = new PoolingClientConnectionManager();
connectionsManager.setMaxTotal(Constants.MAX_CONNS);
connectionsManager.setDefaultMaxPerRoute(Constants.MAX_CONNS_PER_ROUTE);
} // if else
logger.info("Setting max total connections (" + Constants.MAX_CONNS + ")");
logger.info("Setting default max connections per route (" + Constants.MAX_CONNS_PER_ROUTE + ")");
}
示例4: UpdateShardHandler
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
public UpdateShardHandler(ConfigSolr cfg) {
clientConnectionManager = new PoolingClientConnectionManager(SchemeRegistryFactory.createSystemDefault());
if (cfg != null ) {
clientConnectionManager.setMaxTotal(cfg.getMaxUpdateConnections());
clientConnectionManager.setDefaultMaxPerRoute(cfg.getMaxUpdateConnectionsPerHost());
}
ModifiableSolrParams params = new ModifiableSolrParams();
if (cfg != null) {
params.set(HttpClientUtil.PROP_SO_TIMEOUT,
cfg.getDistributedSocketTimeout());
params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT,
cfg.getDistributedConnectionTimeout());
}
// in the update case, we want to do retries, and to use
// the default Solr retry handler that createClient will
// give us
params.set(HttpClientUtil.PROP_USE_RETRY, true);
log.info("Creating UpdateShardHandler HTTP client with params: {}", params);
client = HttpClientUtil.createClient(params, clientConnectionManager);
}
示例5: init
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
private void init(String host, int port, String userName, String password) {
this.host = host;
this.port = port;
this.userName = userName;
this.password = password;
this.baseUrl = SCHEME_HTTP + host + ":" + port + KYLIN_API_PATH;
final HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setSoTimeout(httpParams, httpSocketTimeoutMs);
HttpConnectionParams.setConnectionTimeout(httpParams, httpConnectionTimeoutMs);
final PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
KylinConfig config = KylinConfig.getInstanceFromEnv();
cm.setDefaultMaxPerRoute(config.getRestClientDefaultMaxPerRoute());
cm.setMaxTotal(config.getRestClientMaxTotal());
client = new DefaultHttpClient(cm, httpParams);
if (userName != null && password != null) {
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password);
provider.setCredentials(AuthScope.ANY, credentials);
client.setCredentialsProvider(provider);
}
}
示例6: createProxyClient
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
/**
* create a proxy client
*
* @return either a client or null if none is configured
* @throws KeyManagementException
* @throws NumberFormatException
* if that port could not be parsed.
* @throws NoSuchAlgorithmException
*/
private static HttpClient createProxyClient(PlayProfile profile)
throws KeyManagementException, NoSuchAlgorithmException {
if (profile.getProxyAddress() == null) {
return null;
}
PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(
SchemeRegistryFactory.createDefault());
connManager.setMaxTotal(100);
connManager.setDefaultMaxPerRoute(30);
DefaultHttpClient client = new DefaultHttpClient(connManager);
client.getConnectionManager().getSchemeRegistry()
.register(Utils.getMockedScheme());
HttpHost proxy = new HttpHost(profile.getProxyAddress(),
profile.getProxyPort());
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
if (profile.getProxyUser() != null && profile.getProxyPassword() != null) {
client.getCredentialsProvider().setCredentials(
new AuthScope(proxy),
new UsernamePasswordCredentials(profile.getProxyUser(), profile
.getProxyPassword()));
}
return client;
}
示例7: SparqlPersistance
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
@Inject
public SparqlPersistance(@Named("r2r.fusekiUrl") String sparqlQuery, SparqlPostClient sparqlClient) throws Exception {
this.sparqlQuery = new SparqlQueryClient(sparqlQuery + "/query");
this.sparqlClient = sparqlClient;
// putting this here for now
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 40000);
PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
cm.setDefaultMaxPerRoute(20);
cm.setMaxTotal(200);
HttpOp.setDefaultHttpClient(new DefaultHttpClient(cm, params));
// make sure we have the latest model
// for some reason we need to do post to capture the prefixes
sparqlClient.post(R2ROntology.createR2ROntModel());
sparqlClient.update("CREATE GRAPH <" + R2R_DERIVED_GRAPH + ">");
// by loading these now, we make sure that we do not collide with calls to upsertAffiliation
knownAffiliations = loadAffiliations();
}
示例8: buildClient
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
private static HttpClient buildClient(final String fedoraUsername,
final String fedoraPassword,
final String repositoryURL) {
final PoolingClientConnectionManager connMann = new PoolingClientConnectionManager();
connMann.setMaxTotal(MAX_VALUE);
connMann.setDefaultMaxPerRoute(MAX_VALUE);
final DefaultHttpClient httpClient = new DefaultHttpClient(connMann);
httpClient.setRedirectStrategy(new DefaultRedirectStrategy());
httpClient.setHttpRequestRetryHandler(new StandardHttpRequestRetryHandler(0, false));
// If the Fedora instance requires authentication, set it up here
if (!isBlank(fedoraUsername) && !isBlank(fedoraPassword)) {
LOGGER.debug("Adding BASIC credentials to client for repo requests.");
final URI fedoraUri = URI.create(repositoryURL);
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(fedoraUri.getHost(), fedoraUri.getPort()),
new UsernamePasswordCredentials(fedoraUsername, fedoraPassword));
httpClient.setCredentialsProvider(credsProvider);
}
return httpClient;
}
示例9: createClient
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
private void createClient() {
BasicHttpParams httpParams = new BasicHttpParams();
httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeoutMs);
httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeoutMs);
HttpClientParams.setRedirecting(httpParams, allowRedirects);
HttpClientParams.setConnectionManagerTimeout(httpParams, connectionManagerTimeoutMs);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
connectionManager.setMaxTotal(maxConnections);
connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute);
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, httpParams);
this.client = new HttpClient4Client(httpClient);
}
示例10: DefaultHttpClientImpl
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
public DefaultHttpClientImpl() {
cm = new PoolingClientConnectionManager();
cm.setMaxTotal(100);
cm.setDefaultMaxPerRoute(100);
client = new SystemDefaultHttpClient() {
@Override
protected ClientConnectionManager createClientConnectionManager() {
return cm;
}
};
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
client.getParams().setParameter(CoreConnectionPNames.TCP_NODELAY, true);
client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 30000);
}
示例11: DefaultWmsHttpClientFactory
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
public DefaultWmsHttpClientFactory() {
final PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
cm.setMaxTotal(100);
cm.setDefaultMaxPerRoute(100);
client = new SystemDefaultHttpClient() {
@Override
protected ClientConnectionManager createClientConnectionManager() {
return cm;
}
};
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
client.getParams().setParameter(CoreConnectionPNames.TCP_NODELAY, true);
client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 30000);
}
示例12: JiraClient
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
/**
* Creates an authenticated JIRA client with custom HttpClient.
*
* @param httpClient Custom HttpClient to be used
* @param uri Base URI of the JIRA server
* @param creds Credentials to authenticate with
* @throws JiraException
*/
public JiraClient(HttpClient httpClient, String uri, ICredentials creds) throws JiraException {
if (httpClient == null) {
PoolingClientConnectionManager connManager = new PoolingClientConnectionManager();
connManager.setDefaultMaxPerRoute(20);
connManager.setMaxTotal(40);
httpClient = new DefaultHttpClient(connManager);
}
restclient = new RestClient(httpClient, creds, URI.create(uri));
if (creds != null) {
username = creds.getLogonName();
//intialize connection if required
creds.initialize(restclient);
}
}
示例13: JenkinsHttpClient
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
public JenkinsHttpClient(String username, String authToken) {
DocumentBuilder builder;
try {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
}
catch (ParserConfigurationException e) {
throw new ProcessingException(e);
}
handler = new XMLResponseHandler(builder);
PoolingClientConnectionManager manager = new PoolingClientConnectionManager();
manager.setDefaultMaxPerRoute(20);
httpClient = new DefaultHttpClient(manager);
if (username != null) {
Credentials credentials = new UsernamePasswordCredentials(username, authToken);
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
httpClient.addRequestInterceptor(preemptiveAuth, 0);
}
}
示例14: createSolrClients
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
private Set<SolrClient> createSolrClients(Map<String, String> indexConnectionParams) throws MalformedURLException {
String solrMode = getSolrMode(indexConnectionParams);
if (solrMode.equals("cloud")) {
String indexZkHost = indexConnectionParams.get(SolrConnectionParams.ZOOKEEPER);
String collectionName = indexConnectionParams.get(SolrConnectionParams.COLLECTION);
CloudSolrClient solrServer = new CloudSolrClient.Builder().withZkHost(indexZkHost).build();
int zkSessionTimeout = HBaseIndexerConfiguration.getSessionTimeout(getConf());
solrServer.setZkClientTimeout(zkSessionTimeout);
solrServer.setZkConnectTimeout(zkSessionTimeout);
solrServer.setDefaultCollection(collectionName);
return Collections.singleton((SolrClient)solrServer);
} else if (solrMode.equals("classic")) {
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
connectionManager.setDefaultMaxPerRoute(getSolrMaxConnectionsPerRoute(indexConnectionParams));
connectionManager.setMaxTotal(getSolrMaxConnectionsTotal(indexConnectionParams));
HttpClient httpClient = new DefaultHttpClient(connectionManager);
return new HashSet<SolrClient>(createHttpSolrClients(indexConnectionParams, httpClient));
} else {
throw new RuntimeException("Only 'cloud' and 'classic' are valid values for solr.mode, but got " + solrMode);
}
}
示例15: configureConnectionManager
import org.apache.http.impl.conn.PoolingClientConnectionManager; //導入方法依賴的package包/類
public ClientConnectionManager configureConnectionManager(
HttpParams params) throws ArangoDb4JException {
if (conman == null) {
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(configureScheme());
PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
cm.setMaxTotal(maxConnections);
cm.setDefaultMaxPerRoute(maxConnections);
conman = cm;
}
if (cleanupIdleConnections) {
IdleConnectionMonitor.monitor(conman);
}
return conman;
}