use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project chao-cloud by chaojunzi.
the class RedisDynamicConfig method buildPoolConfig.
/**
* 构造对象池
*
* @param lettuce {@link Lettuce}
* @return {@link GenericObjectPoolConfig}
*/
@SuppressWarnings("rawtypes")
private GenericObjectPoolConfig buildPoolConfig(Lettuce lettuce) {
Pool pool = lettuce.getPool();
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
if (pool != null) {
poolConfig.setMaxTotal(pool.getMaxActive());
poolConfig.setMaxIdle(pool.getMaxIdle());
poolConfig.setMaxWaitMillis(pool.getMaxWait().toMillis());
poolConfig.setMinIdle(pool.getMinIdle());
}
poolConfig.setEvictorShutdownTimeoutMillis(lettuce.getShutdownTimeout().toMillis());
return poolConfig;
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project hazelcast-simulator by hazelcast.
the class Jedis3Driver method startDriverInstance.
@Override
public void startDriverInstance() throws Exception {
Set<HostAndPort> addresses = getAddresses();
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(100);
if (get("REDIS_CLUSTER_PASSWORD") != null) {
this.client = new JedisCluster(addresses, 30000, 30000, 3, get("REDIS_CLUSTER_PASSWORD"), poolConfig);
} else {
this.client = new JedisCluster(addresses, poolConfig);
}
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project x-pipe by ctripcorp.
the class XpipeNettyClientPool method createDefaultPoolConfig.
private static GenericObjectPoolConfig createDefaultPoolConfig() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setJmxEnabled(false);
return config;
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project cicada by aquariusStudio.
the class SwtWebAccessorService method createObjectPool.
/**
* Use pool to manager swt browser resource.
*/
private void createObjectPool() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMinEvictableIdleTimeMillis(-1);
config.setMaxTotal(20);
PooledObjectFactory<SwtWebAccessor> pooledObjectFactory = new BasePooledObjectFactory<SwtWebAccessor>() {
@Override
public SwtWebAccessor create() throws Exception {
ObjectHolder<SwtWebAccessor> objectHolder = new ObjectHolder<>();
SwtWebAccessorService.this.display.syncExec(new Runnable() {
@Override
public void run() {
Browser browser = createBrowserTabItem();
BrowserUtil.initialize(browser);
SwtWebAccessor webAccessor = new SwtWebAccessor(browser, SwtWebAccessorService.this);
objectHolder.setValue(webAccessor);
}
/**
* @return
*/
private Browser createBrowserTabItem() {
TabItem item = new TabItem(SwtWebAccessorService.this.parentTab, SWT.NONE);
Composite parent = new Composite(SwtWebAccessorService.this.parentTab, SWT.None);
GridLayout gridLayout = new GridLayout(2, false);
parent.setLayout(gridLayout);
Text urlText = new Text(parent, SWT.FLAT);
urlText.setEditable(false);
urlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button copyButton = new Button(parent, SWT.PUSH);
copyButton.setLayoutData(new GridData());
copyButton.setText(Messages.ActionCopy);
copyButton.addSelectionListener(new SelectionAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardUtil.setClipboardString(urlText.getText());
}
});
Browser browser = new Browser(parent, WorkbenchActivator.getDefault().getBrowserStyle());
browser.addLocationListener(new LocationAdapter() {
@Override
public void changing(LocationEvent event) {
urlText.setText(browser.getUrl());
}
});
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 2;
browser.setLayoutData(gridData);
item.setText(" " + SwtWebAccessorService.this.parentTab.getItemCount() + " ");
item.setControl(parent);
return browser;
}
});
return objectHolder.getValue();
}
@Override
public PooledObject<SwtWebAccessor> wrap(SwtWebAccessor webAccessor) {
return new DefaultPooledObject<SwtWebAccessor>(webAccessor);
}
/**
* {@inheritDoc}}
*/
@Override
public void passivateObject(PooledObject<SwtWebAccessor> pooledObject) throws Exception {
pooledObject.getObject().get(AboutBlank, DefaultProcessMonitor.createInstance());
}
};
this.webAccessorPool = new GenericObjectPool<>(pooledObjectFactory, config);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project atlasdb by palantir.
the class CassandraClientPoolingContainer method createClientPool.
/**
* Pool size:
* Always keep {@link CassandraKeyValueServiceConfig#poolSize()} connections around, per host. Allow bursting
* up to {@link CassandraKeyValueServiceConfig#maxConnectionBurstSize()} connections per host under load.
*
* Borrowing from pool:
* On borrow, check if the connection is actually open. If it is not,
* immediately discard this connection from the pool, and try to take another.
* Borrow attempts against a fully in-use pool immediately throw a NoSuchElementException.
* {@code CassandraClientPool} when it sees this will:
* Follow an exponential backoff as a method of back pressure.
* Try 3 times against this host, and then give up and try against different hosts 3 additional times.
*
* In an asynchronous thread (using default values):
* Every 20-30 seconds, examine approximately a tenth of the connections in pool.
* Discard any connections in this tenth of the pool whose TCP connections are closed.
* Discard any connections in this tenth of the pool that have been idle for more than 10 minutes,
* while still keeping a minimum number of idle connections around for fast borrows.
*/
private GenericObjectPool<CassandraClient> createClientPool() {
CassandraClientConfig clientConfig = CassandraClientConfig.of(config);
CassandraClientFactory cassandraClientFactory = new CassandraClientFactory(metricsManager, proxy, clientConfig);
GenericObjectPoolConfig<CassandraClient> poolConfig = new GenericObjectPoolConfig<>();
poolConfig.setMinIdle(config.poolSize());
poolConfig.setMaxIdle(config.maxConnectionBurstSize());
poolConfig.setMaxTotal(config.maxConnectionBurstSize());
// immediately throw when we try and borrow from a full pool; dealt with at higher level
poolConfig.setBlockWhenExhausted(false);
// this test is free/just checks a boolean and does not block; borrow is still fast
poolConfig.setTestOnBorrow(true);
poolConfig.setSoftMinEvictableIdleTimeMillis(TimeUnit.MILLISECONDS.convert(Duration.ofSeconds(config.idleConnectionTimeoutSeconds())));
poolConfig.setMinEvictableIdleTimeMillis(Long.MAX_VALUE);
// the randomness here is to prevent all of the pools for all of the hosts
// evicting all at at once, which isn't great for C*.
int timeBetweenEvictionsSeconds = config.timeBetweenConnectionEvictionRunsSeconds();
int delta = ThreadLocalRandom.current().nextInt(Math.min(timeBetweenEvictionsSeconds / 2, 10));
poolConfig.setTimeBetweenEvictionRunsMillis(TimeUnit.MILLISECONDS.convert(Duration.ofSeconds(timeBetweenEvictionsSeconds + delta)));
poolConfig.setNumTestsPerEvictionRun(-(int) (1.0 / config.proportionConnectionsToCheckPerEvictionRun()));
poolConfig.setTestWhileIdle(true);
poolConfig.setJmxNamePrefix(proxy.getHostString());
poolConfig.setEvictionPolicy(new DefaultEvictionPolicy<>());
GenericObjectPool<CassandraClient> pool = new GenericObjectPool<>(cassandraClientFactory, poolConfig);
pool.setSwallowedExceptionListener(exception -> log.info("Swallowed exception within object pool", exception));
registerMetrics(pool);
log.info("Creating a Cassandra client pool for {} with the configuration {}", SafeArg.of("cassandraHost", cassandraServer.cassandraHostName()), SafeArg.of("proxy", proxy), SafeArg.of("poolConfig", poolConfig));
return pool;
}
Aggregations