All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.unbxd.client.ConnectionManager Maven / Gradle / Ivy

The newest version!
package com.unbxd.client;

import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;

/**
 * Created with IntelliJ IDEA.
 * User: sourabh
 * Date: 09/07/14
 * Time: 11:39 AM
 * To change this template use File | Settings | File Templates.
 */
public class ConnectionManager {

    private static final int DEFAULT_MAX_HTTP_CONNECTIONS = 10;
    private static final int MAX_TOTAL_HTTP = 20;

    private static PoolingHttpClientConnectionManager __connectionManager;

    public static PoolingHttpClientConnectionManager getConnectionManager() {
        if(__connectionManager == null){
            synchronized (ConnectionManager.class){
                if(__connectionManager == null){

                    Registry registry = RegistryBuilder.create()
                            .register("http", PlainConnectionSocketFactory.getSocketFactory())
                            .register("https", SSLConnectionSocketFactory.getSocketFactory())
                            .build();

                    __connectionManager = new PoolingHttpClientConnectionManager(registry);

                    __connectionManager.setMaxTotal(MAX_TOTAL_HTTP);
                    __connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_HTTP_CONNECTIONS);
                }
            }
        }

        return __connectionManager;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy