List of usage examples for org.apache.commons.pool2.impl GenericObjectPool close
@Override public void close()
From source file:com.heliosapm.streams.collector.ds.pool.TestMQPool.java
/** * @param args//from w ww. j a v a 2 s . c o m */ public static void main(String[] args) { try { log("Pool Test"); log(TEST_PROPS); JMXHelper.fireUpJMXMPServer(1077); final Properties p = Props.strToProps(TEST_PROPS); log("Props:" + p); final GenericObjectPool<Object> pool = null;//(GenericObjectPool<Object>)PoolConfig.deployPool(p); pool.preparePool(); log("Pool Deployed:" + pool.getNumIdle()); final List<Object> objects = new ArrayList<Object>(); for (int i = 0; i < 4; i++) { try { final Object o = pool.borrowObject(); log("Borrowed:" + o); objects.add(o); } catch (Exception e) { e.printStackTrace(); } } log("Objects:" + objects.size()); StdInCommandHandler.getInstance().registerCommand("close", new Runnable() { public void run() { for (Object o : objects) { pool.returnObject(o); } objects.clear(); try { pool.close(); } catch (Exception ex) { ex.printStackTrace(System.err); } } }).run(); } catch (Exception ex) { ex.printStackTrace(System.err); } }
From source file:com.heliosapm.streams.collector.ds.pool.PoolConfig.java
/** * Undeploys the named pool/*w w w . j a va2 s .c om*/ * @param name The name of the pool */ private static void undeployPool(final String name) { if (name == null || name.trim().isEmpty()) throw new IllegalArgumentException("The passed pool name was null or empty"); final String key = "pool/" + name; final GenericObjectPool<?> pool = GlobalCacheService.getInstance().remove(key); if (pool != null) { try { pool.close(); } catch (Exception x) { /* No Op */} } }
From source file:com.axibase.tsd.client.HttpClientManager.java
public void close() { GenericObjectPool<HttpClient> pool = objectPoolAtomicReference.get(); if (pool != null) { pool.close(); }/*from w ww. j a v a 2s . c o m*/ streamingManager.close(); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@Test public void genericPoolShouldWorkWithPlainConnections() throws Exception { GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), new GenericObjectPoolConfig(), false); borrowAndReturn(pool);/*from w w w . j a v a 2s. c o m*/ StatefulRedisConnection<String, String> connection = pool.borrowObject(); assertThat(Proxy.isProxyClass(connection.getClass())).isFalse(); pool.returnObject(connection); pool.close(); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@Test public void genericPoolShouldWorkWithWrappedConnections() throws Exception { GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), new GenericObjectPoolConfig()); borrowAndReturn(pool);/* w w w .ja v a 2 s .co m*/ borrowAndClose(pool); borrowAndCloseTryWithResources(pool); pool.returnObject(pool.borrowObject().sync().getStatefulConnection()); pool.returnObject(pool.borrowObject().async().getStatefulConnection()); pool.close(); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@Test public void softReferencePoolShouldWorkWithWrappedConnections() throws Exception { GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), new GenericObjectPoolConfig()); borrowAndReturn(pool);/*from ww w . j a va 2s . com*/ borrowAndClose(pool); borrowAndCloseTryWithResources(pool); pool.returnObject(pool.borrowObject().sync().getStatefulConnection()); pool.returnObject(pool.borrowObject().async().getStatefulConnection()); pool.close(); }
From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java
@Test public void genericPoolShouldWorkWithWrappedConnections() throws Exception { GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), new GenericObjectPoolConfig()); borrowAndReturn(pool);//from ww w .j av a 2s . c o m 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(); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@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();//from w ww . j a v a 2s . c o m sync.close(); try { connection.isMulti(); fail("Missing RedisException"); } catch (RedisException e) { assertThat(e).hasMessageContaining("deallocated"); } pool.close(); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@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);//from ww w .j av a 2 s .c om try { sync.hgetall(key); fail("Missing RedisCommandExecutionException"); } catch (RedisCommandExecutionException e) { assertThat(e).hasMessageContaining("WRONGTYPE"); } sync.close(); pool.close(); }
From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java
@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();/*w ww. jav a 2 s . c o m*/ connection.close(); try { connection.isMulti(); fail("Missing RedisException"); } catch (RedisException e) { assertThat(e).hasMessageContaining("deallocated"); } pool.close(); }