本文整理汇总了Java中org.apache.commons.pool2.impl.GenericObjectPool.close方法的典型用法代码示例。如果您正苦于以下问题:Java GenericObjectPool.close方法的具体用法?Java GenericObjectPool.close怎么用?Java GenericObjectPool.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool2.impl.GenericObjectPool
的用法示例。
在下文中一共展示了GenericObjectPool.close方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: genericPoolUsingWrappingShouldPropagateExceptionsCorrectly
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void genericPoolUsingWrappingShouldPropagateExceptionsCorrectly() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig());
StatefulRedisConnection<String, String> connection = pool.borrowObject();
RedisCommands<String, String> sync = connection.sync();
sync.set(key, value);
try {
sync.hgetall(key);
fail("Missing RedisCommandExecutionException");
} catch (RedisCommandExecutionException e) {
assertThat(e).hasMessageContaining("WRONGTYPE");
}
sync.close();
pool.close();
}
示例2: wrappedConnectionShouldUseWrappers
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void wrappedConnectionShouldUseWrappers() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig());
StatefulRedisConnection<String, String> connection = pool.borrowObject();
RedisCommands<String, String> sync = connection.sync();
assertThat(connection).isInstanceOf(StatefulRedisConnection.class).isNotInstanceOf(
StatefulRedisClusterConnectionImpl.class);
assertThat(Proxy.isProxyClass(connection.getClass())).isTrue();
assertThat(sync).isInstanceOf(RedisCommands.class);
assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isNotInstanceOf(RedisAsyncCommandsImpl.class);
assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isNotInstanceOf(
RedisReactiveCommandsImpl.class);
assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class)
.isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection);
sync.close();
pool.close();
}
示例3: wrappedMasterSlaveConnectionShouldUseWrappers
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void wrappedMasterSlaveConnectionShouldUseWrappers() throws Exception {
GenericObjectPool<StatefulRedisMasterSlaveConnection<String, String>> pool = ConnectionPoolSupport
.createGenericObjectPool(() -> MasterSlave.connect(client, new StringCodec(), RedisURI.create(host, port)),
new GenericObjectPoolConfig());
StatefulRedisMasterSlaveConnection<String, String> connection = pool.borrowObject();
RedisCommands<String, String> sync = connection.sync();
assertThat(connection).isInstanceOf(StatefulRedisMasterSlaveConnection.class);
assertThat(Proxy.isProxyClass(connection.getClass())).isTrue();
assertThat(sync).isInstanceOf(RedisCommands.class);
assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isNotInstanceOf(RedisAsyncCommandsImpl.class);
assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isNotInstanceOf(
RedisReactiveCommandsImpl.class);
assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class)
.isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection);
sync.close();
pool.close();
}
示例4: plainConnectionShouldNotUseWrappers
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void plainConnectionShouldNotUseWrappers() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig(), false);
StatefulRedisConnection<String, String> connection = pool.borrowObject();
RedisCommands<String, String> sync = connection.sync();
assertThat(connection).isInstanceOf(StatefulRedisConnection.class).isNotInstanceOf(
StatefulRedisClusterConnectionImpl.class);
assertThat(Proxy.isProxyClass(connection.getClass())).isFalse();
assertThat(sync).isInstanceOf(RedisCommands.class);
assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isInstanceOf(RedisAsyncCommandsImpl.class);
assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isInstanceOf(
RedisReactiveCommandsImpl.class);
assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class).isInstanceOf(
StatefulRedisConnectionImpl.class);
pool.returnObject(connection);
pool.close();
}
示例5: wrappedObjectClosedAfterReturn
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void wrappedObjectClosedAfterReturn() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig(), true);
StatefulRedisConnection<String, String> connection = pool.borrowObject();
RedisCommands<String, String> sync = connection.sync();
sync.ping();
sync.close();
try {
connection.isMulti();
fail("Missing RedisException");
} catch (RedisException e) {
assertThat(e).hasMessageContaining("deallocated");
}
pool.close();
}
示例6: tryWithResourcesReturnsConnectionToPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void tryWithResourcesReturnsConnectionToPool() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig());
StatefulRedisConnection<String, String> usedConnection = null;
try (StatefulRedisConnection<String, String> connection = pool.borrowObject()) {
RedisCommands<String, String> sync = connection.sync();
sync.ping();
usedConnection = connection;
}
try {
usedConnection.isMulti();
fail("Missing RedisException");
} catch (RedisException e) {
assertThat(e).hasMessageContaining("deallocated");
}
pool.close();
}
示例7: destroy
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
public void destroy() throws Exception {
for (GenericObjectPool<INaviDriver> pool : pools) {
try {
if (pool != null) {
pool.close();
}
} catch (Exception e) {
log.error("{}", e.getMessage());
}
}
}
示例8: close
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
public void close() {
GenericObjectPool<HttpClient> pool = objectPoolAtomicReference.get();
if (pool != null) {
pool.close();
}
streamingManager.close();
}
示例9: genericPoolShouldWorkWithPlainConnections
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void genericPoolShouldWorkWithPlainConnections() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig(), false);
borrowAndReturn(pool);
StatefulRedisConnection<String, String> connection = pool.borrowObject();
assertThat(Proxy.isProxyClass(connection.getClass())).isFalse();
pool.returnObject(connection);
pool.close();
}
示例10: wrappedClusterConnectionShouldUseWrappers
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void wrappedClusterConnectionShouldUseWrappers() throws Exception {
RedisClusterClient redisClusterClient = RedisClusterClient.create(TestClientResources.get(),
RedisURI.create(TestSettings.host(), 7379));
GenericObjectPool<StatefulRedisClusterConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
redisClusterClient::connect, new GenericObjectPoolConfig());
StatefulRedisClusterConnection<String, String> connection = pool.borrowObject();
RedisAdvancedClusterCommands<String, String> sync = connection.sync();
assertThat(connection).isInstanceOf(StatefulRedisClusterConnection.class).isNotInstanceOf(
StatefulRedisClusterConnectionImpl.class);
assertThat(Proxy.isProxyClass(connection.getClass())).isTrue();
assertThat(sync).isInstanceOf(RedisAdvancedClusterCommands.class);
assertThat(connection.async()).isInstanceOf(RedisAdvancedClusterAsyncCommands.class).isNotInstanceOf(
RedisAdvancedClusterAsyncCommandsImpl.class);
assertThat(connection.reactive()).isInstanceOf(RedisAdvancedClusterReactiveCommands.class).isNotInstanceOf(
RedisAdvancedClusterReactiveCommandsImpl.class);
assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisClusterConnection.class)
.isNotInstanceOf(StatefulRedisClusterConnectionImpl.class).isSameAs(connection);
sync.close();
pool.close();
FastShutdown.shutdown(redisClusterClient);
}
示例11: closeConnectionPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
* Closes the connection pool, silently swallowing any exception that occurs.
*/
private void closeConnectionPool() {
final GenericObjectPool<?> oldpool = connectionPool;
connectionPool = null;
try {
if (oldpool != null) {
oldpool.close();
}
} catch(final Exception e) {
/* Ignore */
}
}
示例12: close
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
public void close() {
GenericObjectPool<TcpClient> pool = objectPoolAtomicReference.get();
if (pool != null) {
pool.close();
}
}
示例13: genericPoolShouldWorkWithWrappedConnections
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void genericPoolShouldWorkWithWrappedConnections() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig());
borrowAndReturn(pool);
borrowAndClose(pool);
borrowAndCloseTryWithResources(pool);
pool.returnObject(pool.borrowObject().sync().getStatefulConnection());
pool.returnObject(pool.borrowObject().async().getStatefulConnection());
assertThat(channels).hasSize(1);
pool.close();
Wait.untilTrue(channels::isEmpty).waitOrTimeout();
assertThat(channels).isEmpty();
}
示例14: genericPoolShouldCloseConnectionsAboveMaxIdleSize
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void genericPoolShouldCloseConnectionsAboveMaxIdleSize() throws Exception {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxIdle(2);
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), poolConfig);
borrowAndReturn(pool);
borrowAndClose(pool);
borrowAndCloseTryWithResources(pool);
StatefulRedisConnection<String, String> c1 = pool.borrowObject();
StatefulRedisConnection<String, String> c2 = pool.borrowObject();
StatefulRedisConnection<String, String> c3 = pool.borrowObject();
assertThat(channels).hasSize(3);
pool.returnObject(c1);
pool.returnObject(c2);
pool.returnObject(c3);
assertThat(channels).hasSize(2);
pool.close();
Wait.untilTrue(channels::isEmpty).waitOrTimeout();
assertThat(channels).isEmpty();
}