use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project ksan by infinistor.
the class MariaDB method initConnectionPool.
private void initConnectionPool(String dbUrl, String dbPort, String dbName, String userName, String passwd) throws Exception {
try {
Class.forName("org.mariadb.jdbc.Driver");
String jdbcUrl = "jdbc:mariadb://" + dbUrl + ":" + dbPort + "/" + dbName + "?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8";
logger.debug(jdbcUrl);
ConnectionFactory connFactory = new DriverManagerConnectionFactory(jdbcUrl, userName, passwd);
PoolableConnectionFactory poolableConnFactory = new PoolableConnectionFactory(connFactory, null);
poolableConnFactory.setValidationQuery("select 1");
GenericObjectPoolConfig<PoolableConnection> poolConfig = new GenericObjectPoolConfig<PoolableConnection>();
Duration timeBetweenEvictionRuns = Duration.ofSeconds(60);
poolConfig.setTimeBetweenEvictionRuns(timeBetweenEvictionRuns);
poolConfig.setTestWhileIdle(true);
poolConfig.setMinIdle(4);
poolConfig.setMaxTotal(16);
poolConfig.setTestOnBorrow(true);
poolConfig.setTestWhileIdle(true);
GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnFactory, poolConfig);
poolableConnFactory.setPool(connectionPool);
Class.forName("org.apache.commons.dbcp2.PoolingDriver");
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
driver.registerPool("cpMetering", connectionPool);
jrpool = new JedisPool(dbUrl, 6379);
} catch (ClassNotFoundException e) {
throw new RuntimeException("fail to load JDBC Driver", e);
} catch (SQLException e) {
throw new RuntimeException("fail to load JDBC Driver", e);
}
initDBTable();
loadbuckets();
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project springframework-source-5.1.x by wb02125055.
the class CommonsPool2TargetSource method createObjectPool.
/**
* Subclasses can override this if they want to return a specific Commons pool.
* They should apply any configuration properties to the pool here.
* <p>Default is a GenericObjectPool instance with the given pool size.
* @return an empty Commons {@code ObjectPool}.
* @see GenericObjectPool
* @see #setMaxSize
*/
protected ObjectPool createObjectPool() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(getMaxSize());
config.setMaxIdle(getMaxIdle());
config.setMinIdle(getMinIdle());
config.setMaxWaitMillis(getMaxWait());
config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
config.setBlockWhenExhausted(isBlockWhenExhausted());
return new GenericObjectPool(this, config);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project anomaly-detection by opensearch-project.
the class CheckpointDaoTests method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
indexName = "testIndexName";
// gson = PowerMockito.mock(Gson.class);
gson = new GsonBuilder().serializeSpecialFloatingPointValues().create();
thresholdingModelClass = HybridThresholdingModel.class;
when(clock.instant()).thenReturn(Instant.now());
mapper = new RandomCutForestMapper();
mapper.setSaveExecutorContextEnabled(true);
trcfMapper = new ThresholdedRandomCutForestMapper();
trcfSchema = AccessController.doPrivileged((PrivilegedAction<Schema<ThresholdedRandomCutForestState>>) () -> RuntimeSchema.getSchema(ThresholdedRandomCutForestState.class));
converter = new V1JsonToV2StateConverter();
serializeRCFBufferPool = spy(AccessController.doPrivileged(new PrivilegedAction<GenericObjectPool<LinkedBuffer>>() {
@Override
public GenericObjectPool<LinkedBuffer> run() {
return new GenericObjectPool<>(new BasePooledObjectFactory<LinkedBuffer>() {
@Override
public LinkedBuffer create() throws Exception {
return LinkedBuffer.allocate(AnomalyDetectorSettings.SERIALIZATION_BUFFER_BYTES);
}
@Override
public PooledObject<LinkedBuffer> wrap(LinkedBuffer obj) {
return new DefaultPooledObject<>(obj);
}
});
}
}));
serializeRCFBufferPool.setMaxTotal(AnomalyDetectorSettings.MAX_TOTAL_RCF_SERIALIZATION_BUFFERS);
serializeRCFBufferPool.setMaxIdle(AnomalyDetectorSettings.MAX_TOTAL_RCF_SERIALIZATION_BUFFERS);
serializeRCFBufferPool.setMinIdle(0);
serializeRCFBufferPool.setBlockWhenExhausted(false);
serializeRCFBufferPool.setTimeBetweenEvictionRuns(AnomalyDetectorSettings.HOURLY_MAINTENANCE);
anomalyRate = 0.005;
checkpointDao = new CheckpointDao(client, clientUtil, indexName, gson, mapper, converter, trcfMapper, trcfSchema, thresholdingModelClass, indexUtil, maxCheckpointBytes, serializeRCFBufferPool, AnomalyDetectorSettings.SERIALIZATION_BUFFER_BYTES, anomalyRate);
when(indexUtil.doesCheckpointIndexExist()).thenReturn(true);
modelId = "testModelId";
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project proctor by indeedeng.
the class SvnObjectPools method createObjectPool.
private static <T> ObjectPool<T> createObjectPool(final PooledObjectFactory<T> factory) {
final GenericObjectPoolConfig objectPoolConfig = new GenericObjectPoolConfig();
// arbitrary, but positive so objects do get evicted
objectPoolConfig.setMinEvictableIdleTimeMillis(TimeUnit.HOURS.toMillis(1));
// arbitrary, but positive so objects do get evicted
objectPoolConfig.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES.toMillis(10));
objectPoolConfig.setJmxEnabled(false);
objectPoolConfig.setBlockWhenExhausted(false);
// uncapped number of objects in the pool
objectPoolConfig.setMaxTotal(-1);
final AbandonedConfig abandonedConfig = new AbandonedConfig();
abandonedConfig.setRemoveAbandonedOnBorrow(true);
abandonedConfig.setRemoveAbandonedTimeout((int) TimeUnit.MINUTES.toSeconds(30));
return new GenericObjectPool<T>(factory, objectPoolConfig, abandonedConfig);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project bboss by bbossgroups.
the class BasicDataSource method createConnectionPool.
/**
* Creates a connection pool for this datasource. This method only exists
* so subclasses can replace the implementation class.
*
* This implementation configures all pool properties other than
* timeBetweenEvictionRunsMillis. Setting that property is deferred to
* {@link #startPoolMaintenance()}, since setting timeBetweenEvictionRunsMillis
* to a positive value causes {@link GenericObjectPool}'s eviction timer
* to be started.
*/
protected void createConnectionPool(PoolableConnectionFactory factory) {
// Create an object pool to contain our active connections
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
updateJmxName(config);
// Disable JMX on the underlying pool if the DS is not registered.
config.setJmxEnabled(registeredJmxName != null);
GenericObjectPool<PoolableConnection> gop;
if (abandonedConfig != null && (abandonedConfig.getRemoveAbandonedOnBorrow() || abandonedConfig.getRemoveAbandonedOnMaintenance() || abandonedConfig.getLogAbandoned())) {
// 改造实现跟踪功能 biaoping.yin
gop = new GenericObjectPool<PoolableConnection>(factory, config, abandonedConfig);
} else {
gop = new GenericObjectPool<PoolableConnection>(factory, config);
}
gop.setMaxTotal(maxTotal);
gop.setMaxIdle(maxIdle);
gop.setMinIdle(minIdle);
gop.setMaxWaitMillis(maxWaitMillis);
gop.setTestOnCreate(testOnCreate);
gop.setTestOnBorrow(testOnBorrow);
gop.setTestOnReturn(testOnReturn);
gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
gop.setTestWhileIdle(testWhileIdle);
gop.setLifo(lifo);
gop.setSwallowedExceptionListener(new SwallowedExceptionLogger(log, logExpiredConnections));
gop.setEvictionPolicyClassName(evictionPolicyClassName);
factory.setPool(gop);
connectionPool = gop;
}
Aggregations