List of usage examples for org.apache.commons.pool ObjectPool clear
void clear() throws Exception, UnsupportedOperationException;
From source file:com.evanmclean.evlib.commons.dbcp.DbcpUtils.java
/** * Close all DBCP pools.//from w ww. j a v a 2 s. com */ public static void closePools() { final PoolingDriver driver = getPoolingDriver(); if (driver != null) { final String[] pns = driver.getPoolNames(); for (String pn : pns) try { final ObjectPool pool = driver.getConnectionPool(pn); if (pool != null) pool.clear(); } catch (Throwable ex) { // empty } } }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestObjectPool.java
private static void reset(final ObjectPool pool, final MethodCallPoolableObjectFactory factory, final List expectedMethods) throws Exception { pool.clear(); clear(factory, expectedMethods);/*from w w w . j av a2s . c om*/ factory.reset(); }
From source file:jp.co.acroquest.endosnipe.data.db.ConnectionManager.java
/** * ????????<br />// w ww. j a v a 2s. c o m * ???????????????? */ public void closeAll() { try { for (ObjectPool connectionPool : this.connectionPoolMap_.values()) { connectionPool.clear(); } int numActive = getNumActive(); if (numActive > 0) { LOGGER.log(ACTIVE_CONNECTIONS_REMAINED, numActive); } this.connectionPoolMap_.clear(); this.dataSourceList_.clear(); } catch (Exception ex) { LOGGER.log(EXCEPTION_OCCURED, ex, ex.getMessage()); } }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestBaseObjectPool.java
public void testUnsupportedOperations() throws Exception { if (!getClass().equals(TestBaseObjectPool.class)) { return; // skip redundant tests }/*from www. j a va2 s . c om*/ ObjectPool pool = new BaseObjectPool() { public Object borrowObject() { return null; } public void returnObject(Object obj) { } public void invalidateObject(Object obj) { } }; assertTrue("Negative expected.", pool.getNumIdle() < 0); assertTrue("Negative expected.", pool.getNumActive() < 0); try { pool.clear(); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // expected } try { pool.addObject(); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // expected } try { pool.setFactory(null); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // expected } }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestObjectPool.java
public void testPOFClearUsages() throws Exception { final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory(); final ObjectPool pool; try {/* w w w .ja va2s . co m*/ pool = makeEmptyPool(factory); } catch (UnsupportedOperationException uoe) { return; // test not supported } final List expectedMethods = new ArrayList(); /// Test correct behavior code paths PoolUtils.prefill(pool, 5); pool.clear(); //// Test exception handling clear should swallow destory object failures reset(pool, factory, expectedMethods); factory.setDestroyObjectFail(true); PoolUtils.prefill(pool, 5); pool.clear(); }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestObjectPool.java
public void testClosedPoolBehavior() throws Exception { final ObjectPool pool; try {/*from w ww .j a v a2 s .com*/ pool = makeEmptyPool(new MethodCallPoolableObjectFactory()); } catch (UnsupportedOperationException uoe) { return; // test not supported } Object o1 = pool.borrowObject(); Object o2 = pool.borrowObject(); pool.close(); try { pool.addObject(); fail("A closed pool must throw an IllegalStateException when addObject is called."); } catch (IllegalStateException ise) { // expected } try { pool.borrowObject(); fail("A closed pool must throw an IllegalStateException when borrowObject is called."); } catch (IllegalStateException ise) { // expected } // The following should not throw exceptions just because the pool is closed. if (pool.getNumIdle() >= 0) { assertEquals("A closed pool shouldn't have any idle objects.", 0, pool.getNumIdle()); } if (pool.getNumActive() >= 0) { assertEquals("A closed pool should still keep count of active objects.", 2, pool.getNumActive()); } pool.returnObject(o1); if (pool.getNumIdle() >= 0) { assertEquals("returnObject should not add items back into the idle object pool for a closed pool.", 0, pool.getNumIdle()); } if (pool.getNumActive() >= 0) { assertEquals("A closed pool should still keep count of active objects.", 1, pool.getNumActive()); } pool.invalidateObject(o2); if (pool.getNumIdle() >= 0) { assertEquals("invalidateObject must not add items back into the idle object pool.", 0, pool.getNumIdle()); } if (pool.getNumActive() >= 0) { assertEquals("A closed pool should still keep count of active objects.", 0, pool.getNumActive()); } pool.clear(); pool.close(); }
From source file:org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceSystemListener.java
@SuppressWarnings("unchecked") public void shutdown() { ICacheManager cacheManager = PentahoSystem.getCacheManager(null); List<ObjectPool> objectPools = null; objectPools = (List<ObjectPool>) cacheManager.getAllValuesFromRegionCache(IDBDatasourceService.JDBC_POOL); Logger.debug(this, "DatasourceSystemListener: Called for shutdown ..."); //$NON-NLS-1$ try {/*from w w w . j a v a 2 s .c o m*/ if (objectPools != null) { for (ObjectPool objectPool : objectPools) { if (null != objectPool) { objectPool.clear(); } } } } catch (Throwable ignored) { Logger.error(this, "Failed to clear connection pool: " + ignored.getMessage(), ignored); //$NON-NLS-1$ } cacheManager.removeRegionCache(IDBDatasourceService.JDBC_POOL); cacheManager.removeRegionCache(IDBDatasourceService.JDBC_DATASOURCE); Logger.debug(this, "DatasourceSystemListener: Completed shutdown."); //$NON-NLS-1$ }