本文整理匯總了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();
}