Example usage for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool

List of usage examples for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool.

Prototype

public GenericObjectPool(PooledObjectFactory<T> factory, GenericObjectPoolConfig config,
        AbandonedConfig abandonedConfig) 

Source Link

Document

Create a new GenericObjectPool that tracks and destroys objects that are checked out, but never returned to the pool.

Usage

From source file:ezbake.thrift.ThriftConnectionPool.java

/**
 * Create a new connection pool based on the supplied client and protocol factories as well as the supplied pool
 * configuration.//w w w  .  java 2s  .  c o m
 *
 * @param clientFactory Factory used to create TServiceClient
 * @param protocolFactory Factory used to generate the protocol used when creating a new TServiceClient for the pool
 * @param poolConfig Configuration object used to determine things like pool evicition, max idle connections,
 *                   max active connections, etc
 */
public ThriftConnectionPool(ClientFactory<T> clientFactory, ProtocolFactory protocolFactory,
        GenericObjectPoolConfig poolConfig, AbandonedConfig abandonedConfig) {
    this.internalPool = new GenericObjectPool<T>(new ThriftClientFactory(clientFactory, protocolFactory),
            poolConfig, abandonedConfig);
}

From source file:ddf.ldap.ldaplogin.LdapLoginConfig.java

/**
 * Update method that receives new properties.
 *
 * @param props Map of properties./*from w  w w .j  a  v  a2s .co m*/
 */
public void update(Map<String, ?> props) {
    if (props != null) {
        LOGGER.debug("Received an updated set of configurations for the LDAP Login Config.");

        if (connectionPoolServiceRegistration != null) {
            connectionPoolServiceRegistration.unregister();
        }
        if (ldapConnectionPool != null) {
            ldapConnectionPool.close();
        }

        ConnectionFactory ldapConnectionFactory = null;

        List<String> urls = new ArrayList<>();
        Object urlsObj = props.get(LDAP_URL);
        if (urlsObj instanceof String[]) {
            urls.addAll(Arrays.asList((String[]) urlsObj));
        } else {
            urls.add(urlsObj.toString());
        }

        List<ConnectionFactory> connectionFactories = new ArrayList<>();

        Boolean startTls = props.get(START_TLS) != null
                && Boolean.parseBoolean(props.get(START_TLS).toString());

        for (String url : urls) {
            connectionFactories.add(createLdapConnectionFactory(url, startTls));
        }

        String loadBalancingAlgorithm = (String) props.get(LDAP_LOAD_BALANCING);
        Options options = Options.defaultOptions();
        if (FAILOVER.equalsIgnoreCase(loadBalancingAlgorithm)) {
            ldapConnectionFactory = Connections.newFailoverLoadBalancer(connectionFactories, options);
        } else {
            ldapConnectionFactory = Connections.newRoundRobinLoadBalancer(connectionFactories, options);
        }

        ldapConnectionPool = new GenericObjectPool<>(
                new LdapConnectionPooledObjectFactory(ldapConnectionFactory), createGenericPoolConfig(id),
                createGenericPoolAbandonConfig());

        Dictionary<String, String> serviceProps = new DictionaryMap<>();
        serviceProps.put("id", id);

        LOGGER.debug("Registering LdapConnectionPool");
        connectionPoolServiceRegistration = context.registerService(GenericObjectPool.class.getName(),
                ldapConnectionPool, serviceProps);

        // create modules from the newly updated config
        Module ldapModule = createLdapModule(props);
        ldapService.update(ldapModule);
    }
}

From source file:org.apache.sentry.service.thrift.PoolClientInvocationHandler.java

public PoolClientInvocationHandler(Configuration conf) throws Exception {
    this.conf = conf;
    readConfiguration();//from  ww  w  .j  av a2 s  . c o  m
    poolFactory = new SentryServiceClientPoolFactory(conf);
    pool = new GenericObjectPool<SentryPolicyServiceClient>(poolFactory, poolConfig, new AbandonedConfig());
}

From source file:org.atmosphere.pool.UnboundedApachePoolableProvider.java

@Override
public void configure(AtmosphereConfig config) {
    this.config = config;
    configureGenericObjectPoolConfig();/* w  w w.  j  a  v a  2 s . c o m*/
    genericObjectPool = new GenericObjectPool<Broadcaster>(new BroadcasterFactory(), poolConfig,
            abandonedConfig);
}