/** * {@inheritDoc} */ @Override public void invalidateObject(final K key, final V obj) { try { keyedPool.invalidateObject(key, obj); } catch (final Exception e) { // swallowed } }
/** * {@inheritDoc} */ @Override public void invalidateObject(final K key, final V obj) { final WriteLock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { keyedPool.invalidateObject(key, obj); } catch (final Exception e) { // swallowed as of Pool 2 } finally { writeLock.unlock(); } }
@Override public void invalidateObject(final K key, final V proxy) throws Exception { final V pooledObject = proxySource.resolveProxy(proxy); pool.invalidateObject(key, pooledObject); }
@Override public void run() { try { pool.invalidateObject(key, obj); } catch (final IllegalStateException ex) { // Ignore } catch (final Exception ex) { Assert.fail("Unexpected exception " + ex.toString()); } finally { done = true; } } public boolean complete() {
keyedPool.invalidateObject(key, obj); } else { keyedPool.returnObject(key, obj);
/** * {@inheritDoc} */ @Override public void invalidateObject(final K key, final V obj) { try { keyedPool.invalidateObject(key, obj); } catch (final Exception e) { // swallowed } }
private static List<String> invokeEveryMethod(final KeyedObjectPool<Object,Object> kop) throws Exception { kop.addObject(null); kop.borrowObject(null); kop.clear(); kop.clear(null); kop.close(); kop.getNumActive(); kop.getNumActive(null); kop.getNumIdle(); kop.getNumIdle(null); kop.invalidateObject(null, new Object()); kop.returnObject(null, new Object()); kop.toString(); final List<String> expectedMethods = Arrays.asList(new String[] { "addObject", "borrowObject", "clear", "clear", "close", "getNumActive", "getNumActive", "getNumIdle", "getNumIdle", "invalidateObject", "returnObject", "toString" }); return expectedMethods; }
@Test(expected=IllegalStateException.class) public void testAccessAfterInvalidate() throws Exception { final TestObject obj = pool.borrowObject(KEY1); assertNotNull(obj); // Make sure proxied methods are working obj.setData(DATA1); assertEquals(DATA1, obj.getData()); pool.invalidateObject(KEY1, obj); assertNotNull(obj); obj.getData(); }
/** * {@inheritDoc} */ @Override public void invalidateObject(final K key, final V obj) { final WriteLock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { keyedPool.invalidateObject(key, obj); } catch (final Exception e) { // swallowed as of Pool 2 } finally { writeLock.unlock(); } }
pool.invalidateObject(KEY, obj); expectedMethods.add(new MethodCall("destroyObject", KEY, obj)); assertEquals(expectedMethods, factory.getMethodCalls()); factory.setDestroyObjectFail(true); try { pool.invalidateObject(KEY, obj); fail("Expecting destroy exception to propagate"); } catch (final PrivateException ex) {
@Override public void invalidateObject(final K key, final V proxy) throws Exception { final V pooledObject = proxySource.resolveProxy(proxy); pool.invalidateObject(key, pooledObject); }
@Test public void testBaseInvalidateObject() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException uoe) { return; // skip this test if unsupported } final Object keya = makeKey(0); assertEquals(0,_pool.getNumActive(keya)); assertEquals(0,_pool.getNumIdle(keya)); final Object obj0 = _pool.borrowObject(keya); final Object obj1 = _pool.borrowObject(keya); assertEquals(2,_pool.getNumActive(keya)); assertEquals(0,_pool.getNumIdle(keya)); _pool.invalidateObject(keya,obj0); assertEquals(1,_pool.getNumActive(keya)); assertEquals(0,_pool.getNumIdle(keya)); _pool.invalidateObject(keya,obj1); assertEquals(0,_pool.getNumActive(keya)); assertEquals(0,_pool.getNumIdle(keya)); _pool.close(); }
/** * Invalidates the PooledConnection in the pool. The KeyedCPDSConnectionFactory closes the connection and pool * counters are updated appropriately. Also clears any idle instances associated with the user name that was used to * create the PooledConnection. Connections associated with this user are not affected and they will not be * automatically closed on return to the pool. */ @Override public void invalidate(final PooledConnection pc) throws SQLException { final PooledConnectionAndInfo info = pcMap.get(pc); if (info == null) { throw new IllegalStateException(NO_KEY_MESSAGE); } final UserPassKey key = info.getUserPassKey(); try { pool.invalidateObject(key, info); // Destroy and update pool counters pool.clear(key); // Remove any idle instances with this key } catch (final Exception ex) { throw new SQLException("Error invalidating connection", ex); } }
/** * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future */ @Override public void connectionErrorOccurred(final ConnectionEvent event) { final PooledConnection pc = (PooledConnection) event.getSource(); if (null != event.getSQLException()) { System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")"); } pc.removeConnectionEventListener(this); final PooledConnectionAndInfo info = pcMap.get(pc); if (info == null) { throw new IllegalStateException(NO_KEY_MESSAGE); } try { pool.invalidateObject(info.getUserPassKey(), info); } catch (final Exception e) { System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info); e.printStackTrace(); } }
/** * This will be called if the Connection returned by the getConnection method came from a PooledConnection, and the * user calls the close() method of this connection object. What we need to do here is to release this * PooledConnection from our pool... */ @Override public void connectionClosed(final ConnectionEvent event) { final PooledConnection pc = (PooledConnection) event.getSource(); // if this event occurred because we were validating, or if this // connection has been marked for removal, ignore it // otherwise return the connection to the pool. if (!validatingSet.contains(pc)) { final PooledConnectionAndInfo pci = pcMap.get(pc); if (pci == null) { throw new IllegalStateException(NO_KEY_MESSAGE); } try { pool.returnObject(pci.getUserPassKey(), pci); } catch (final Exception e) { System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + "NOT BE RETURNED TO THE POOL"); pc.removeConnectionEventListener(this); try { pool.invalidateObject(pci.getUserPassKey(), pci); } catch (final Exception e3) { System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci); e3.printStackTrace(); } } } }
public void invalidateTransport(TTransportWrapper transport) { if (closed.get()) { LOGGER.debug("invalidated {} for closed pool", transport); transport.close(); return; } try { LOGGER.debug("[{}] Invalidating address {}", id, transport); if (!isPoolEnabled) { transport.close(); } else { pool.invalidateObject(transport.getAddress(), transport); // Invalidate the whole pool associated with the given address // It is a bit brutal since a single bad connection may // cause an invalidation, but otherwise we may have a lot of bad // connections in the pool and try to return them. pool.clear(transport.getAddress()); } } catch (Exception e) { LOGGER.error("Failed to invalidate {}", transport, e); } }
this.keyedObjectPool.returnObject(this.dirContextType, context); } else { this.keyedObjectPool.invalidateObject(this.dirContextType, context);
this.keyedObjectPool.returnObject(this.dirContextType, context); } else { this.keyedObjectPool.invalidateObject(this.dirContextType, context);
this.keyedObjectPool.returnObject(this.dirContextType, context); } else { this.keyedObjectPool.invalidateObject(this.dirContextType, context);
assertEquals("returnObject should not add items back into the idle object pool for a closed pool.", 0, pool.getNumIdle(KEY)); assertEquals("returnObject should not add items back into the idle object pool for a closed pool.", 0, pool.getNumIdle()); pool.invalidateObject(KEY, o2); pool.clear(KEY); pool.clear();