use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericKeyedObjectPool in project tomcat by apache.
the class PoolableConnectionFactory method makeObject.
@Override
public PooledObject<PoolableConnection> makeObject() throws Exception {
Connection conn = connectionFactory.createConnection();
if (conn == null) {
throw new IllegalStateException("Connection factory returned null from createConnection");
}
try {
initializeConnection(conn);
} catch (final SQLException sqle) {
// Make sure the connection is closed
Utils.closeQuietly((AutoCloseable) conn);
// Rethrow original exception so it is visible to caller
throw sqle;
}
final long connIndex = connectionIndex.getAndIncrement();
if (poolStatements) {
conn = new PoolingConnection(conn);
final GenericKeyedObjectPoolConfig<DelegatingPreparedStatement> config = new GenericKeyedObjectPoolConfig<>();
config.setMaxTotalPerKey(-1);
config.setBlockWhenExhausted(false);
config.setMaxWait(Duration.ZERO);
config.setMaxIdlePerKey(1);
config.setMaxTotal(maxOpenPreparedStatements);
if (dataSourceJmxObjectName != null) {
final StringBuilder base = new StringBuilder(dataSourceJmxObjectName.toString());
base.append(Constants.JMX_CONNECTION_BASE_EXT);
base.append(connIndex);
config.setJmxNameBase(base.toString());
config.setJmxNamePrefix(Constants.JMX_STATEMENT_POOL_PREFIX);
} else {
config.setJmxEnabled(false);
}
final PoolingConnection poolingConn = (PoolingConnection) conn;
final KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> stmtPool = new GenericKeyedObjectPool<>(poolingConn, config);
poolingConn.setStatementPool(stmtPool);
poolingConn.setClearStatementPoolOnReturn(clearStatementPoolOnReturn);
poolingConn.setCacheState(cacheState);
}
// Register this connection with JMX
final ObjectName connJmxName;
if (dataSourceJmxObjectName == null) {
connJmxName = null;
} else {
connJmxName = new ObjectName(dataSourceJmxObjectName.toString() + Constants.JMX_CONNECTION_BASE_EXT + connIndex);
}
final PoolableConnection pc = new PoolableConnection(conn, pool, connJmxName, disconnectionSqlCodes, fastFailValidation);
pc.setCacheState(cacheState);
return new DefaultPooledObject<>(pc);
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericKeyedObjectPool in project openhab1-addons by openhab.
the class ModbusBinding method reconstructConnectionPool.
private static void reconstructConnectionPool() {
connectionFactory = new ModbusSlaveConnectionFactoryImpl();
GenericKeyedObjectPool<ModbusSlaveEndpoint, ModbusSlaveConnection> genericKeyedObjectPool = new GenericKeyedObjectPool<ModbusSlaveEndpoint, ModbusSlaveConnection>(connectionFactory, poolConfig);
genericKeyedObjectPool.setSwallowedExceptionListener(new SwallowedExceptionListener() {
@Override
public void onSwallowException(Exception e) {
logger.error("Connection pool swallowed unexpected exception: {}", e.getMessage());
}
});
connectionPool = genericKeyedObjectPool;
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericKeyedObjectPool in project datanucleus-rdbms by datanucleus.
the class SharedPoolDataSource method registerPool.
private void registerPool(String username, String password) throws NamingException, SQLException {
ConnectionPoolDataSource cpds = testCPDS(username, password);
// Create an object pool to contain our PooledConnections
factory = new KeyedCPDSConnectionFactory(cpds, getValidationQuery(), getValidationQueryTimeout(), isRollbackAfterValidation());
factory.setMaxConnLifetimeMillis(getMaxConnLifetimeMillis());
GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
config.setBlockWhenExhausted(getDefaultBlockWhenExhausted());
config.setEvictionPolicyClassName(getDefaultEvictionPolicyClassName());
config.setLifo(getDefaultLifo());
config.setMaxIdlePerKey(getDefaultMaxIdle());
config.setMaxTotal(getMaxTotal());
config.setMaxTotalPerKey(getDefaultMaxTotal());
config.setMaxWaitMillis(getDefaultMaxWaitMillis());
config.setMinEvictableIdleTimeMillis(getDefaultMinEvictableIdleTimeMillis());
config.setMinIdlePerKey(getDefaultMinIdle());
config.setNumTestsPerEvictionRun(getDefaultNumTestsPerEvictionRun());
config.setSoftMinEvictableIdleTimeMillis(getDefaultSoftMinEvictableIdleTimeMillis());
config.setTestOnCreate(getDefaultTestOnCreate());
config.setTestOnBorrow(getDefaultTestOnBorrow());
config.setTestOnReturn(getDefaultTestOnReturn());
config.setTestWhileIdle(getDefaultTestWhileIdle());
config.setTimeBetweenEvictionRunsMillis(getDefaultTimeBetweenEvictionRunsMillis());
KeyedObjectPool<UserPassKey, PooledConnectionAndInfo> tmpPool = new GenericKeyedObjectPool<>(factory, config);
factory.setPool(tmpPool);
pool = tmpPool;
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericKeyedObjectPool in project x-pipe by ctripcorp.
the class XpipeNettyClientKeyedObjectPool method setKeyPooConfig.
public final void setKeyPooConfig(int minIdlePerKey, long softMinEvictableIdleTimeMillis, long minEvictableIdleTimeMillis, long timeBetweenEvictionRunsMillis) {
if (objectPool instanceof GenericKeyedObjectPool) {
logger.info("[setKeyPooConfig]{}, {}, {}, {}", minIdlePerKey, softMinEvictableIdleTimeMillis, minEvictableIdleTimeMillis, timeBetweenEvictionRunsMillis);
GenericKeyedObjectPool genericKeyedObjectPool = (GenericKeyedObjectPool) objectPool;
genericKeyedObjectPool.setMinIdlePerKey(minIdlePerKey);
genericKeyedObjectPool.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
genericKeyedObjectPool.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
genericKeyedObjectPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
} else {
logger.warn("[setKeyPooConfig][not generickeyedobjectpool]");
}
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericKeyedObjectPool in project x-pipe by ctripcorp.
the class XpipeNettyClientKeyedObjectPool method doInitialize.
@Override
protected void doInitialize() throws Exception {
this.pooledObjectFactory = new NettyKeyedPoolClientFactory();
pooledObjectFactory.start();
GenericKeyedObjectPool<InetSocketAddress, NettyClient> genericKeyedObjectPool = new GenericKeyedObjectPool<>(pooledObjectFactory, config);
genericKeyedObjectPool.setTestOnBorrow(true);
genericKeyedObjectPool.setTestOnCreate(true);
genericKeyedObjectPool.setSoftMinEvictableIdleTimeMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
genericKeyedObjectPool.setMinEvictableIdleTimeMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
genericKeyedObjectPool.setTimeBetweenEvictionRunsMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
this.objectPool = genericKeyedObjectPool;
}
Aggregations