/** * {@inheritDoc} */ @Override public void destroyObject(final PooledObject<T> p) throws Exception { writeLock.lock(); try { factory.destroyObject(p); } finally { writeLock.unlock(); } }
/** * {@inheritDoc} */ @Override public void destroyObject(final PooledObject<T> p) throws Exception { writeLock.lock(); try { factory.destroyObject(p); } finally { writeLock.unlock(); } }
/** * Destroys a wrapped pooled object. * * @param toDestroy The wrapped pooled object to destroy * * @throws Exception If the factory fails to destroy the pooled object * cleanly */ private void destroy(final PooledObject<T> toDestroy) throws Exception { toDestroy.invalidate(); idleObjects.remove(toDestroy); allObjects.remove(new IdentityWrapper<>(toDestroy.getObject())); try { factory.destroyObject(toDestroy); } finally { destroyedCount.incrementAndGet(); createCount.decrementAndGet(); } }
/** * Clears any objects sitting idle in the pool. */ @Override public synchronized void clear() { if (null != factory) { final Iterator<PooledSoftReference<T>> iter = idleReferences.iterator(); while (iter.hasNext()) { try { final PooledSoftReference<T> ref = iter.next(); if (null != ref.getObject()) { factory.destroyObject(ref); } } catch (final Exception e) { // ignore error, keep destroying the rest } } } idleReferences.clear(); pruneClearedReferences(); }
/** * Destroys a {@code PooledSoftReference} and removes it from the idle and all * references pools. * * @param toDestroy PooledSoftReference to destroy * * @throws Exception If an error occurs while trying to destroy the object */ private void destroy(final PooledSoftReference<T> toDestroy) throws Exception { toDestroy.invalidate(); idleReferences.remove(toDestroy); allReferences.remove(toDestroy); try { factory.destroyObject(toDestroy); } finally { destroyCount++; toDestroy.getReference().clear(); } }
private static <T> List<String> invokeEveryMethod(final PooledObjectFactory<T> pof) throws Exception { pof.activateObject(null); pof.destroyObject(null); pof.makeObject(); pof.passivateObject(null); pof.validateObject(null); pof.toString(); final List<String> expectedMethods = Arrays.asList(new String[] { "activateObject", "destroyObject", "makeObject", "passivateObject", "validateObject", "toString", }); return expectedMethods; }
@Test public void testDefaultMethods() throws Exception { final PooledObjectFactory<Object> factory = new TestFactory(); factory.activateObject(null); // a no-op factory.passivateObject(null); // a no-op factory.destroyObject(null); // a no-op assertTrue(factory.validateObject(null)); // constant true }
/** * {@inheritDoc} */ @Override public void destroyObject(final PooledObject<T> p) throws Exception { writeLock.lock(); try { factory.destroyObject(p); } finally { writeLock.unlock(); } }
/** * Destroys a wrapped pooled object. * * @param toDestroy The wrapped pooled object to destroy * * @throws Exception If the factory fails to destroy the pooled object * cleanly */ private void destroy(final PooledObject<T> toDestroy) throws Exception { toDestroy.invalidate(); idleObjects.remove(toDestroy); allObjects.remove(new IdentityWrapper<>(toDestroy.getObject())); try { factory.destroyObject(toDestroy); } finally { destroyedCount.incrementAndGet(); createCount.decrementAndGet(); } }
/** * Clears any objects sitting idle in the pool. */ @Override public synchronized void clear() { if (null != factory) { final Iterator<PooledSoftReference<T>> iter = idleReferences.iterator(); while (iter.hasNext()) { try { final PooledSoftReference<T> ref = iter.next(); if (null != ref.getObject()) { factory.destroyObject(ref); } } catch (final Exception e) { // ignore error, keep destroying the rest } } } idleReferences.clear(); pruneClearedReferences(); }
/** * Destroys a {@code PooledSoftReference} and removes it from the idle and all * references pools. * * @param toDestroy PooledSoftReference to destroy * * @throws Exception If an error occurs while trying to destroy the object */ private void destroy(final PooledSoftReference<T> toDestroy) throws Exception { toDestroy.invalidate(); idleReferences.remove(toDestroy); allReferences.remove(toDestroy); try { factory.destroyObject(toDestroy); } finally { destroyCount++; toDestroy.getReference().clear(); } }