Java 类org.apache.http.impl.conn.SchemeRegistryFactory 实例源码

项目:search    文件:UpdateShardHandler.java   
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);
}
项目:raccoon4    文件:PlayManager.java   
/**
 * 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;
}
项目:read-open-source-code    文件:UpdateShardHandler.java   
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);
}
项目:hbc    文件:ClientBuilder.java   
public ClientBuilder() {
  enableGZip = true;
  name = "hosebird-client-" + clientNum.getAndIncrement();
  ThreadFactory threadFactory = new ThreadFactoryBuilder()
          .setDaemon(true)
          .setNameFormat("hosebird-client-io-thread-%d")
          .build();
  executorService = Executors.newSingleThreadExecutor(threadFactory);

  ThreadFactory rateTrackerThreadFactory = new ThreadFactoryBuilder()
          .setDaemon(true)
          .setNameFormat("hosebird-client-rateTracker-thread-%d")
          .build();

  ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(1, rateTrackerThreadFactory);
  rateTracker = new BasicRateTracker(30000, 100, true, scheduledExecutor);
  reconnectionManager = new BasicReconnectionManager(5);

  socketTimeoutMillis = 60000;
  connectionTimeoutMillis = 4000;

  schemeRegistry = SchemeRegistryFactory.createDefault();
}
项目:voldemort    文件:HttpStoreClientFactory.java   
public HttpStoreClientFactory(ClientConfig config) {
    super(config);
    ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
                                                                      config.getConnectionTimeout(TimeUnit.MILLISECONDS),
                                                                      TimeUnit.MILLISECONDS);
    mgr.setMaxTotal(config.getMaxTotalConnections());
    mgr.setDefaultMaxPerRoute(config.getMaxConnectionsPerNode());

    this.httpClient = new DefaultHttpClient(mgr);
    HttpParams clientParams = this.httpClient.getParams();

    HttpProtocolParams.setUserAgent(clientParams, VOLDEMORT_USER_AGENT);
    HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);

    HttpConnectionParams.setConnectionTimeout(clientParams,
                                              config.getConnectionTimeout(TimeUnit.MILLISECONDS));
    HttpConnectionParams.setSoTimeout(clientParams,
                                      config.getSocketTimeout(TimeUnit.MILLISECONDS));
    HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);

    this.httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);

    this.reroute = config.getRoutingTier().equals(RoutingTier.SERVER);
    this.requestFormatFactory = new RequestFormatFactory();
}
项目:voldemort    文件:HttpStoreTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    Cluster cluster = ServerTestUtils.getLocalCluster(1);
    Node node = cluster.getNodes().iterator().next();
    context = ServerTestUtils.getJettyServer(new ClusterMapper().writeCluster(cluster),
                                             VoldemortTestConstants.getSimpleStoreDefinitionsXml(),
                                             "users",
                                             RequestFormatType.VOLDEMORT_V1,
                                             node.getHttpPort());
    server = context.getServer();

    ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
                                                                                    5000,
                                                                                    TimeUnit.MILLISECONDS);
    httpClient = new DefaultHttpClient(connectionManager);
    httpStore = ServerTestUtils.getHttpStore("users",
                                             RequestFormatType.VOLDEMORT_V1,
                                             node.getHttpPort(),
                                             httpClient);
}
项目:lams    文件:SystemDefaultHttpClient.java   
@Override
protected ClientConnectionManager createClientConnectionManager() {
    PoolingClientConnectionManager connmgr = new PoolingClientConnectionManager(
            SchemeRegistryFactory.createSystemDefault());
    String s = System.getProperty("http.keepAlive");
    if ("true".equalsIgnoreCase(s)) {
        s = System.getProperty("http.maxConnections", "5");
        int max = Integer.parseInt(s);
        connmgr.setDefaultMaxPerRoute(max);
        connmgr.setMaxTotal(2 * max);
    }
    return connmgr;
}
项目:navi    文件:NaviHttpClientDriver.java   
public PoolingClientConnectionManager getPoolingClientConnectionManager(
    NaviHttpPoolConfig poolConfig) {
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(
        SchemeRegistryFactory.createDefault(), poolConfig.getTimeToLive(), TimeUnit.MILLISECONDS
    );

    // timeToLive maximum time to live. May be zero if the connection does
    // not have an expiry deadline.
    connectionManager.setDefaultMaxPerRoute(poolConfig.getMaxPerRoute()); // 默认每个通道最高2个链接
    connectionManager.setMaxTotal(poolConfig.getMaxActive()); // 默认最大20,现改成MaxActive可配,默认是8
    return connectionManager;
}
项目:navi    文件:NaviAPITestCase.java   
protected HttpClient getHttpClient() {
    if (httpClient == null) {
        httpClient = new DefaultHttpClient(
            new PoolingClientConnectionManager(SchemeRegistryFactory.createDefault(), 3000, TimeUnit.MILLISECONDS)
        );
    }
    return httpClient;
}
项目:purecloud-iot    文件:SystemDefaultHttpClient.java   
@Override
protected ClientConnectionManager createClientConnectionManager() {
    final PoolingClientConnectionManager connmgr = new PoolingClientConnectionManager(
            SchemeRegistryFactory.createSystemDefault());
    String s = System.getProperty("http.keepAlive", "true");
    if ("true".equalsIgnoreCase(s)) {
        s = System.getProperty("http.maxConnections", "5");
        final int max = Integer.parseInt(s);
        connmgr.setDefaultMaxPerRoute(max);
        connmgr.setMaxTotal(2 * max);
    }
    return connmgr;
}
项目:dummydroid    文件:GooglePlayAPI.java   
/**
 * Connection manager to allow concurrent connections.
 *
 * @return {@link ClientConnectionManager} instance
 */
public static ClientConnectionManager getConnectionManager() {
    PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(
            SchemeRegistryFactory.createDefault());
    connManager.setMaxTotal(100);
    connManager.setDefaultMaxPerRoute(30);
    return connManager;
}
项目:raccoon4    文件:GooglePlayAPI.java   
/**
 * Connection manager to allow concurrent connections.
 * 
 * @return {@link ClientConnectionManager} instance
 */
public static ClientConnectionManager getConnectionManager() {
    PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(
            SchemeRegistryFactory.createDefault());
    connManager.setMaxTotal(100);
    connManager.setDefaultMaxPerRoute(30);
    return connManager;
}
项目:just-for-fun    文件:HttpClientFactory.java   
/**
 * 
 * @param isMultiRequest
 *            是否支持多线程
 * @param connectionTimeout
 *            建立连接超时时间(毫秒)
 * @param socketTimeout
 *            等待数据超时时间(毫秒)
 * @return
 */
public static HttpClient getHttpClient(boolean isMultiRequest,
        int connectionTimeout, int socketTimeout) {
    SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
    ClientConnectionManager cm = isMultiRequest ? new PoolingClientConnectionManager(
            schemeRegistry) : new BasicClientConnectionManager(
            schemeRegistry);
    HttpParams params = isMultiRequest ? new SyncBasicHttpParams()
            : new BasicHttpParams();
    HttpClientParams.setCookiePolicy(params,
            CookiePolicy.BROWSER_COMPATIBILITY);
    HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
    HttpConnectionParams.setSoTimeout(params, socketTimeout);
    return new DefaultHttpClient(cm, params);
}
项目:Raccoon    文件:Archive.java   
/**
 * Get a proxy client, if it is configured.
 * 
 * @return either a client or null
 * @throws IOException
 *           if reading the config file fails
 * @throws KeyManagementException
 * @throws NumberFormatException
 *           if that port could not be parsed.
 * @throws NoSuchAlgorithmException
 */
public HttpClient getProxyClient() throws IOException, KeyManagementException,
        NoSuchAlgorithmException, NumberFormatException {
    File cfgfile = new File(root, NETCFG);
    if (cfgfile.exists()) {
        Properties cfg = new Properties();
        cfg.load(new FileInputStream(cfgfile));
        String ph = cfg.getProperty(PROXYHOST, null);
        String pp = cfg.getProperty(PROXYPORT, null);
        String pu = cfg.getProperty(PROXYUSER, null);
        String pw = cfg.getProperty(PROXYPASS, null);
        if (ph == null || pp == 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(ph, Integer.parseInt(pp));
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        if (pu != null && pw != null) {
            client.getCredentialsProvider().setCredentials(new AuthScope(proxy),
                    new UsernamePasswordCredentials(pu, pw));
        }
        return client;
    }
    return null;
}
项目:Raccoon    文件:GooglePlayAPI.java   
/**
 * Connection manager to allow concurrent connections.
 * 
 * @return {@link ClientConnectionManager} instance
 */
public static ClientConnectionManager getConnectionManager() {
    PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(
            SchemeRegistryFactory.createDefault());
    connManager.setMaxTotal(100);
    connManager.setDefaultMaxPerRoute(30);
    return connManager;
}
项目:read-open-source-code    文件:UpdateShardHandler.java   
public UpdateShardHandler(ConfigSolr cfg) {

  clientConnectionManager = new PoolingClientConnectionManager(SchemeRegistryFactory.createSystemDefault());
  clientConnectionManager.setMaxTotal(cfg.getMaxUpdateConnections());
  clientConnectionManager.setDefaultMaxPerRoute(cfg.getMaxUpdateConnectionsPerHost());


  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(HttpClientUtil.PROP_SO_TIMEOUT, cfg.getDistributedSocketTimeout());
  params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, cfg.getDistributedConnectionTimeout());
  params.set(HttpClientUtil.PROP_USE_RETRY, false);
  client = HttpClientUtil.createClient(params, clientConnectionManager);
}
项目:hbc    文件:RestartableHttpClientTest.java   
@Before
public void setup() throws Exception {
  mockAuth = mock(Authentication.class);
  mockParams = mock(HttpParams.class);
  defaultSchemeRegistry = SchemeRegistryFactory.createDefault();
  request = new HttpGet("http://hi");
}
项目:voldemort    文件:HttpClientBench.java   
private static HttpClient createClient() {
    ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
                                                                                    DEFAULT_CONNECTION_MANAGER_TIMEOUT,
                                                                                    TimeUnit.MILLISECONDS);

    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

    HttpParams clientParams = httpClient.getParams();

    HttpConnectionParams.setSocketBufferSize(clientParams, 60000);
    HttpConnectionParams.setTcpNoDelay(clientParams, false);
    HttpProtocolParams.setUserAgent(clientParams, VOLDEMORT_USER_AGENT);
    HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);
    // HostConfiguration hostConfig = new HostConfiguration();
    // hostConfig.setHost("localhost");

    HttpConnectionParams.setConnectionTimeout(clientParams, DEFAULT_CONNECTION_MANAGER_TIMEOUT);
    HttpConnectionParams.setSoTimeout(clientParams, 500);
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);

    connectionManager.setMaxTotal(DEFAULT_MAX_CONNECTIONS);
    connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_HOST_CONNECTIONS);
    HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);

    return httpClient;
}
项目:lams    文件:PoolingClientConnectionManager.java   
public PoolingClientConnectionManager() {
    this(SchemeRegistryFactory.createDefault());
}
项目:lams    文件:ThreadSafeClientConnManager.java   
/**
 * @since 4.1
 */
public ThreadSafeClientConnManager() {
    this(SchemeRegistryFactory.createDefault());
}
项目:purecloud-iot    文件:ThreadSafeClientConnManager.java   
/**
 * @since 4.1
 */
public ThreadSafeClientConnManager() {
    this(SchemeRegistryFactory.createDefault());
}