本文整理汇总了Java中org.apache.commons.pool2.impl.GenericObjectPool类的典型用法代码示例。如果您正苦于以下问题:Java GenericObjectPool类的具体用法?Java GenericObjectPool怎么用?Java GenericObjectPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericObjectPool类属于org.apache.commons.pool2.impl包,在下文中一共展示了GenericObjectPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JedisPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public JedisPool(final String host) {
URI uri = URI.create(host);
if (JedisURIHelper.isValid(uri)) {
String h = uri.getHost();
int port = uri.getPort();
String password = JedisURIHelper.getPassword(uri);
int database = JedisURIHelper.getDBIndex(uri);
boolean ssl = uri.getScheme().equals("rediss");
this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(h, port, Protocol.DEFAULT_TIMEOUT,
Protocol.DEFAULT_TIMEOUT, password, database, null, ssl, null, null, null),
new GenericObjectPoolConfig());
} else {
this.internalPool = new GenericObjectPool<Jedis>(
new JedisFactory(host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT,
null, Protocol.DEFAULT_DATABASE, null, false, null, null, null),
new GenericObjectPoolConfig());
}
}
示例2: JaRedisPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public JaRedisPool(final String host) {
URI uri = URI.create(host);
if (JedisURIHelper.isValid(uri)) {
String h = uri.getHost();
int port = uri.getPort();
String password = JedisURIHelper.getPassword(uri);
int database = JedisURIHelper.getDBIndex(uri);
this.internalPool = new GenericObjectPool<>(new JaRedisFactory(h, port,
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null),
new GenericObjectPoolConfig());
} else {
this.internalPool = new GenericObjectPool<>(new JaRedisFactory(host,
Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
Protocol.DEFAULT_DATABASE, null), new GenericObjectPoolConfig());
}
}
示例3: DrawGuess
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
@Autowired
public DrawGuess(ApplicationContext context,
ApiResponseFactory apiResponseFactory, DrawWordMapper mapper) {
this.apiResponsePool = new GenericObjectPool<>(apiResponseFactory);
this.mapper = mapper;
HashMap<Integer, RequestHandler> handlers = new HashMap<>();
String[] beans = context.getBeanNamesForAnnotation(DrawGuessEventHandler.class);
for (String bean : beans) {
RequestHandler handler = context.getBean(bean, RequestHandler.class);
DrawGuessEventHandler annotation = handler.getClass().getAnnotation(DrawGuessEventHandler.class);
DrawCode[] value = annotation.value();
for (DrawCode drawCode : value) {
handlers.put(drawCode.getCode(), handler);
}
}
setRequestHandlers(handlers);
}
示例4: DefaultSessionPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public DefaultSessionPool(final ConnectionService connect, final X509TrustManager trust, final X509KeyManager key,
final VaultRegistry registry, final Cache<Path> cache, final TranscriptListener transcript,
final Host bookmark) {
this.connect = connect;
this.registry = registry;
this.cache = cache;
this.bookmark = bookmark;
this.transcript = transcript;
final GenericObjectPoolConfig configuration = new GenericObjectPoolConfig();
configuration.setJmxEnabled(false);
configuration.setEvictionPolicyClassName(CustomPoolEvictionPolicy.class.getName());
configuration.setBlockWhenExhausted(true);
configuration.setMaxWaitMillis(BORROW_MAX_WAIT_INTERVAL);
this.pool = new GenericObjectPool<Session>(new PooledSessionFactory(connect, trust, key, cache, bookmark, registry), configuration);
final AbandonedConfig abandon = new AbandonedConfig();
abandon.setUseUsageTracking(true);
this.pool.setAbandonedConfig(abandon);
}
示例5: JedisPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public JedisPool(final String host) {
URI uri = URI.create(host);
if (JedisURIHelper.isValid(uri)) {
String h = uri.getHost();
int port = uri.getPort();
String password = JedisURIHelper.getPassword(uri);
int database = JedisURIHelper.getDBIndex(uri);
this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(h, port,
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null),
new GenericObjectPoolConfig());
} else {
this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(host,
Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
Protocol.DEFAULT_DATABASE, null), new GenericObjectPoolConfig());
}
}
示例6: setupObjectPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
@Override
public void setupObjectPool() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(poolSize);
objectPool = new GenericObjectPool<>(new BasePooledObjectFactory<TestObject>() {
@Override
public TestObject create() throws Exception {
return new TestObject(true);
}
@Override
public PooledObject<TestObject> wrap(TestObject testObject) {
return new DefaultPooledObject<>(testObject);
}
}, config);
}
示例7: ensureClient
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
protected synchronized void ensureClient() throws SQLException {
if (client == null) {
ClientConfiguration clientConfiguration = new ClientConfiguration(properties);
LOGGER.log(Level.SEVERE, "Booting HerdDB Client, url:" + url + ", properties:" + properties + " clientConfig " + clientConfiguration);
clientConfiguration.readJdbcUrl(url);
client = new HDBClient(clientConfiguration);
}
if (pool == null) {
if (properties.containsKey("maxActive")) {
this.maxActive = Integer.parseInt(properties.get("maxActive").toString());
}
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setBlockWhenExhausted(true);
config.setMaxTotal(maxActive);
config.setMaxIdle(maxActive);
config.setMinIdle(maxActive / 2);
config.setJmxNamePrefix("HerdDBClient");
pool = new GenericObjectPool<>(new ConnectionsFactory(), config);
}
}
示例8: setPoolConfig
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
@Override
public void setPoolConfig(String host, int port, int timeout, int maxPoolSize, GenericObjectPool<Jedis> pool) {
this.host = host;
this.port = port;
// System.err.println("setPoolConfig host:" + host + " port:" + port + " maxPoolSize:" + maxPoolSize);
connectionInfo = new ConnectionInfo();
connectionInfo.setPort(port);
connectionInfo.setHost(host);// 是否要解析成IP?
connectionInfo.setMaxPoolSize(maxPoolSize);
connectionInfo.setContent("");
connectionInfo.setType("Redis");
connectionInfo.setPool(pool);
connectionMonitorService.add(connectionInfo);
}
示例9: getSocketPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public static SocketPool getSocketPool(String host , int port) {
String key = host+":"+port;
SocketPool pool = socketPoolMap.get(key);
if(pool==null) {
lock.lock();
pool = socketPoolMap.get(key);
if(pool==null) {
pool = new SocketPool(host,port);
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(10);
GenericObjectPool<SocketConnection> objectPool = new GenericObjectPool<SocketConnection>(pool,poolConfig);
pool.setObjectPool(objectPool);
socketPoolMap.put(key, pool);
}
lock.unlock();
}
return pool;
}
示例10: build
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
@SuppressWarnings("unused")
public RethinkDBPool build() {
ConnectionFactory factory = new ConnectionFactory(hostname, port, username, password, database);
GenericObjectPoolConfig config = this.config;
if (config == null) {
config = new GenericObjectPoolConfig();
config.setMaxTotal(maxConnections);
config.setMinIdle(minFreeConnections);
config.setMaxIdle(maxFreeConnections);
}
GenericObjectPool<Connection> pool = new GenericObjectPool<>(factory, config);
return new RethinkDBPool(pool, timeout);
}
示例11: JedisPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
public JedisPool(final String host) {
URI uri = URI.create(host);
if (JedisURIHelper.isValid(uri)) {
String h = uri.getHost();
int port = uri.getPort();
String password = JedisURIHelper.getPassword(uri);
int database = JedisURIHelper.getDBIndex(uri);
this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(h, port,
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null),
new GenericObjectPoolConfig());
this.host = h;
this.port = port;
} else {
this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(host,
Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
Protocol.DEFAULT_DATABASE, null), new GenericObjectPoolConfig());
this.host = host;
this.port = Protocol.DEFAULT_PORT;
}
}
示例12: start
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
/**
* This can be overriden to set pool size and borrow timeout
* for each start/restart.
* The super method must be called at the end of the overriding method.
* @throws Exception
*/
public synchronized void start() throws Exception {
if (pool==null) {
pool = new GenericObjectPool<PooledConnection>(new MDWPoolFactory());
}
pool.setMaxTotal(pool_size);
if (borrow_timeout<0) {
pool.setBlockWhenExhausted(true);
pool.setMaxWaitMillis(-1);
} else if (borrow_timeout==0) {
pool.setBlockWhenExhausted(false);
pool.setMaxWaitMillis(0);
} else {
pool.setBlockWhenExhausted(true);
pool.setMaxWaitMillis(borrow_timeout*1000);
}
setStarted(true);
}
示例13: createPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
private ObjectPool<PoolableConnection> createPool(String connectionString) {
// A ConnectionFactory that the pool will use to create Connections.
ConnectionFactory connectionFactory =
new DriverManagerConnectionFactory(connectionString, null);
// PoolableConnectionFactory wraps the real Connections with the
// classes that implement the pooling functionality.
PoolableConnectionFactory poolableConnectionFactory =
new PoolableConnectionFactory(connectionFactory, null);
poolableConnectionFactory.setValidationQuery("SELECT 1");
// Actual pool of connections.
GenericObjectPool<PoolableConnection> connectionPool =
new GenericObjectPool<>(poolableConnectionFactory);
int connMax = getConfig()
.getInt(OctopusConfiguration.MASTER_CONNECTION_POOL_MAX, 8);
connectionPool.setMaxTotal(connMax);
connectionPool.setTestOnBorrow(true);
// Set the factory's pool property to the owning pool.
poolableConnectionFactory.setPool(connectionPool);
return connectionPool;
}
示例14: initLocalBroker
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
private void initLocalBroker() throws ProvisioningException {
if (this.isInternalQueue()) {
this.broker = BrokerHolder.getInstance( cfgMgr, "local",this);
} else {
this.mpPool = new GenericObjectPool<MessageProducerHolder>(new PooledMessageProducerFactory(this.cfgMgr,this));
this.mpPool.setMaxTotal(this.cfgMgr.getCfg().getProvisioning().getQueueConfig().getMaxProducers());
this.cfgMgr.addThread(new StopableThread() {
@Override
public void run() {
// TODO Auto-generated method stub
}
@Override
public void stop() {
mpPool.close();
mpPool.clear();
}
});
}
}
示例15: check
import org.apache.commons.pool2.impl.GenericObjectPool; //导入依赖的package包/类
@Override
protected Result check() throws Exception {
GenericObjectPool<PoolableConnection> pool = (GenericObjectPool<PoolableConnection>) connectionPool;
if (pool.getNumWaiters() > maxWaitingConnections) {
return Result.unhealthy("Overloaded connection pool. name="
+ poolName + " nbrWaiters=" + pool.getNumWaiters());
}
PoolableConnectionFactory poolFactory = (PoolableConnectionFactory) pool
.getFactory();
PoolableConnection conn = null;
try {
conn = pool.borrowObject();
poolFactory.validateConnection(conn);
} catch (Exception e) {
return Result
.unhealthy("Database connection validation error. error="
+ ExceptionUtils.getStackTrace(e));
} finally {
DbUtils.closeQuietly(conn);
}
return Result.healthy();
}