Example usage for org.apache.commons.pool2.impl GenericKeyedObjectPoolConfig setMaxTotalPerKey

List of usage examples for org.apache.commons.pool2.impl GenericKeyedObjectPoolConfig setMaxTotalPerKey

Introduction

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

Prototype

public void setMaxTotalPerKey(int maxTotalPerKey) 

Source Link

Document

Set the value for the maxTotalPerKey configuration attribute for pools created with this configuration instance.

Usage

From source file:com.magnet.mmx.server.plugin.mmxmgmt.apns.APNSConnectionPoolImplTest.java

@BeforeClass
public static void setUp() throws Exception {
    LOGGER.info("Setting up the pool");
    GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
    config.setMaxTotalPerKey(MAX_OBJECTS_PER_KEY);
    config.setMaxIdlePerKey(3);/*w  ww  .ja v  a 2  s.co  m*/
    config.setMinEvictableIdleTimeMillis(10 * 60 * 1000L);
    config.setTimeBetweenEvictionRunsMillis(1000L);
    objectFactory = new StubAPNSConnectionKeyedPooledObjectFactory(appWithBadCert);
    APNSConnectionPoolImpl.initialize(objectFactory, config);

}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.apns.APNSConnectionPoolImpl.java

/**
 * Lifecycle method./*from w  w  w.  j  av  a2s  .c o m*/
 * Initializes the connection pool with the default object factory and configuration.
 * @throws java.lang.IllegalStateException if the pool instance has already been initialized.
 */
public static void initialize() {
    GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
    config.setMaxIdlePerKey(1);
    config.setMaxTotalPerKey(5);
    config.setMaxTotal(50);
    initialize(new APNSConnectionKeyedPooledObjectFactory(new OpenFireDBConnectionProvider()), config);
}

From source file:net.sheehantech.cherry.pool.KeyedPooledPushClient.java

@Override
public void init() throws ConnectionFailedException {
    GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
    if (maxTotal != null)
        config.setMaxTotalPerKey(maxTotal);
    if (maxIdle != null)
        config.setMaxIdlePerKey(maxIdle);
    if (minIdle != null)
        config.setMinIdlePerKey(minIdle);
    config.setTestOnBorrow(true);//  w  w  w . ja  v a 2 s  . co  m
    config.setTestWhileIdle(true);
    config.setBlockWhenExhausted(true);
    config.setMaxTotalPerKey(maxTotal);
    pool = new GenericKeyedObjectPool<K, PooledPushSocket>(
            new KeyedPooledPushSocketFactory(socketFactories, gateways, ports), config);
    try {
        for (K k : sslContexts.keySet())
            pool.preparePool(k);
    } catch (Exception e) {
        throw (new ConnectionFailedException(e));
    }
    logger.debug("Started new push socket pool with {} sockets", pool.getNumIdle());

}

From source file:io.mandrel.transport.thrift.ThriftClients.java

@PostConstruct
public void init() {

    GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
    poolConfig.setMaxTotalPerKey(4);
    poolConfig.setMinIdlePerKey(1);//w ww .j a  va 2 s  . c  o  m

    ThriftCatalog catalog = new ThriftCatalog();
    catalog.addDefaultCoercions(MandrelCoercions.class);
    ThriftCodecManager codecManager = new ThriftCodecManager(
            new CompilerThriftCodecFactory(ThriftCodecManager.class.getClassLoader()), catalog,
            Collections.emptySet());

    NettyClientConfig config = NettyClientConfig.newBuilder().build();
    NiftyClient niftyClient = new NiftyClient(config, local);
    ThriftClientManager clientManager = new ThriftClientManager(codecManager, niftyClient,
            Collections.emptySet());

    frontiers = new KeyedClientPool<>(FrontierContract.class, poolConfig, 9090,
            // Deflater.BEST_SPEED
            null, clientManager);
    prepare(frontiers);

    controllers = new KeyedClientPool<>(ControllerContract.class, poolConfig, 9090,
            // Deflater.BEST_SPEED
            null, clientManager);
    prepare(controllers);

    workers = new KeyedClientPool<>(WorkerContract.class, poolConfig, 9090,
            // Deflater.BEST_SPEED
            null, clientManager);
    prepare(workers);

    nodes = new KeyedClientPool<>(NodeContract.class, poolConfig, 9090,
            // Deflater.BEST_SPEED
            null, clientManager);
    prepare(nodes);
}

From source file:com.quancheng.saluki.core.grpc.GrpcEngine.java

private void initChannelPool() {
    GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
    config.setMaxTotal(1000);/*from   ww  w .jav  a  2s  . c  o m*/
    config.setMaxTotalPerKey(3);
    config.setBlockWhenExhausted(true);
    config.setMinIdlePerKey(3);
    config.setMaxWaitMillis(10);
    config.setNumTestsPerEvictionRun(Integer.MAX_VALUE);
    config.setTestOnBorrow(false);
    config.setTestOnReturn(false);
    config.setTestWhileIdle(false);
    config.setTimeBetweenEvictionRunsMillis(1 * 60000L);
    config.setMinEvictableIdleTimeMillis(10 * 60000L);
    config.setTestWhileIdle(false);
    this.channelPool = new GenericKeyedObjectPool<GrpcURL, Channel>(new GrpcChannelFactory(), config);
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.MMXPlugin.java

public void initializeAPNSConnectionPool() {

    MMXConfiguration configuration = MMXConfiguration.getConfiguration();
    int maxObjectsPerKey = configuration.getInt(MMXConfigKeys.APNS_POOL_MAX_CONNECTIONS_PER_APP,
            MMXServerConstants.APNS_POOL_MAX_CONNECTIONS_PER_APP);
    int maxIdleObjectsPerKey = configuration.getInt(MMXConfigKeys.APNS_POOL_MAX_IDLE_CONNECTIONS_PER_APP,
            MMXServerConstants.APNS_POOL_MAX_IDLE_CONNECTIONS_PER_APP);
    int ttlForIdleObjectsInMinutes = configuration.getInt(MMXConfigKeys.APNS_POOL_IDLE_TTL_MINUTES,
            MMXServerConstants.APNS_POOL_IDLE_TTL_MINUTES);
    int maxTotal = configuration.getInt(MMXConfigKeys.APNS_POOL_MAX_TOTAL_CONNECTIONS,
            MMXServerConstants.APNS_POOL_MAX_TOTAL_CONNECTIONS);

    Log.info(//from   w  w w. j  a v  a 2 s  . co m
            "Configuring APNS Connection pool with following values: maxObjects:{}, maxObjectsPerKey:{}, "
                    + "maxIdleObjectsPerKey:{}, ttlForIdleObjectsInMinutes:{}",
            maxTotal, maxObjectsPerKey, maxIdleObjectsPerKey, ttlForIdleObjectsInMinutes);

    GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
    config.setMaxTotalPerKey(maxObjectsPerKey);
    config.setMaxTotal(maxTotal);
    config.setMaxIdlePerKey(maxIdleObjectsPerKey);
    config.setMinEvictableIdleTimeMillis(ttlForIdleObjectsInMinutes * 60 * 1000L);

    APNSConnectionPoolImpl.initialize(config);
}

From source file:com.vmware.identity.idm.server.provider.LdapConnectionPool.java

private GenericKeyedObjectPoolConfig getGenericKeyedObjectPoolConfig(String tenantName) {
    LdapConnectionPoolConfig config = configManager.getConfiguration(tenantName);
    GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();

    poolConfig.setTestOnBorrow(config.getTestOnBorrow());
    poolConfig.setTimeBetweenEvictionRunsMillis(config.getEvictionInterval());
    poolConfig.setMinEvictableIdleTimeMillis(config.getIdleTime());
    poolConfig.setMaxTotal(config.getMaxConnections());
    poolConfig.setMaxTotalPerKey(config.getMaxConnectionsPerKey());
    poolConfig.setMaxWaitMillis(config.getMaxWaitMilis());

    return poolConfig;
}

From source file:com.haulmont.cuba.core.sys.AbstractScripting.java

private synchronized GenericKeyedObjectPool<String, Script> getPool() {
    if (pool == null) {
        GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
        poolConfig.setMaxTotalPerKey(-1);
        poolConfig.setMaxIdlePerKey(globalConfig.getGroovyEvaluationPoolMaxIdle());
        pool = new GenericKeyedObjectPool<>(new BaseKeyedPooledObjectFactory<String, Script>() {
            @Override/*from ww  w .  ja v  a 2s. c  om*/
            public Script create(String key) throws Exception {
                return createScript(key);
            }

            @Override
            public PooledObject<Script> wrap(Script value) {
                return new DefaultPooledObject<>(value);
            }
        }, poolConfig);
    }
    return pool;
}

From source file:JDBCPool.dbcp.demo.sourcecode.PoolableConnectionFactory.java

/**
 * ?PoolDefaultPooledObject??Connection/*www  .  j  av a2s  . c o m*/
 */
@Override
public PooledObject<PoolableConnection> makeObject() throws Exception {
    Connection conn = _connFactory.createConnection();
    if (conn == null) {
        throw new IllegalStateException("Connection factory returned null from createConnection");
    }

    try {
        initializeConnection(conn); //?SQL?SQL
    } catch (SQLException sqle) {
        // Make sure the connection is closed
        try {
            conn.close();
        } catch (SQLException ignore) {
            // ignore
        }
        // Rethrow original exception so it is visible to caller
        throw sqle;
    }

    long connIndex = connectionIndex.getAndIncrement();

    if (poolStatements) {
        conn = new PoolingConnection(conn);
        GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
        config.setMaxTotalPerKey(-1);
        config.setBlockWhenExhausted(false);
        config.setMaxWaitMillis(0);
        config.setMaxIdlePerKey(1);
        config.setMaxTotal(maxOpenPreparedStatements);
        if (dataSourceJmxName != null) {
            StringBuilder base = new StringBuilder(dataSourceJmxName.toString());
            base.append(Constants.JMX_CONNECTION_BASE_EXT);
            base.append(Long.toString(connIndex));
            config.setJmxNameBase(base.toString());
            config.setJmxNamePrefix(Constants.JMX_STATEMENT_POOL_PREFIX);
        } else {
            config.setJmxEnabled(false);
        }
        KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> stmtPool = new GenericKeyedObjectPool<>(
                (PoolingConnection) conn, config);
        ((PoolingConnection) conn).setStatementPool(stmtPool);
        ((PoolingConnection) conn).setCacheState(_cacheState);
    }

    // Register this connection with JMX
    ObjectName connJmxName;
    if (dataSourceJmxName == null) {
        connJmxName = null;
    } else {
        connJmxName = new ObjectName(
                dataSourceJmxName.toString() + Constants.JMX_CONNECTION_BASE_EXT + connIndex);
    }

    PoolableConnection pc = new PoolableConnection(conn, _pool, connJmxName, _disconnectionSqlCodes,
            _fastFailValidation);

    return new DefaultPooledObject<>(pc);
}

From source file:com.streamsets.datacollector.stagelibrary.ClassLoaderStageLibraryTask.java

@Override
public void initTask() {
    super.initTask();
    stageClassLoaders = runtimeInfo.getStageLibraryClassLoaders();
    if (!stageClassLoaders.isEmpty()) {
        resolveClassLoaderMethods(stageClassLoaders.get(0));
    }//from  w ww  .j  av a  2  s. c  o m
    json = ObjectMapperFactory.get();
    stageList = new ArrayList<>();
    stageMap = new HashMap<>();
    loadStages();
    stageList = ImmutableList.copyOf(stageList);
    stageMap = ImmutableMap.copyOf(stageMap);

    // localization cache for definitions
    localizedStageList = CacheBuilder.newBuilder().build(new CacheLoader<Locale, List<StageDefinition>>() {
        @Override
        public List<StageDefinition> load(Locale key) throws Exception {
            List<StageDefinition> list = new ArrayList<>();
            for (StageDefinition stage : stageList) {
                list.add(stage.localize());
            }
            return list;
        }
    });
    validateStageVersions(stageList);

    // initializing the list of targets that can be used for error handling
    ErrorHandlingChooserValues.setErrorHandlingOptions(this);

    // initializing the list of targets that can be used as aggregating sink
    StatsTargetChooserValues.setStatsTargetOptions(this);

    // initializing the pool of private stage classloaders
    GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
    poolConfig.setJmxEnabled(false);
    poolConfig.setMaxTotal(
            configuration.get(MAX_PRIVATE_STAGE_CLASS_LOADERS_KEY, MAX_PRIVATE_STAGE_CLASS_LOADERS_DEFAULT));
    poolConfig.setMinEvictableIdleTimeMillis(-1);
    poolConfig.setNumTestsPerEvictionRun(0);
    poolConfig.setMaxIdlePerKey(-1);
    poolConfig.setMinIdlePerKey(0);
    poolConfig.setMaxTotalPerKey(-1);
    poolConfig.setBlockWhenExhausted(false);
    poolConfig.setMaxWaitMillis(0);
    privateClassLoaderPool = new GenericKeyedObjectPool<>(new ClassLoaderFactory(stageClassLoaders),
            poolConfig);
}