/** * {@inheritDoc} */ @Override public void passivateObject(final K key, final PooledObject<V> p) throws Exception { writeLock.lock(); try { keyedFactory.passivateObject(key, p); } finally { writeLock.unlock(); } }
/** * Add an object to the set of idle objects for a given key. * * @param key The key to associate with the idle object * @param p The wrapped object to add. * * @throws Exception If the associated factory fails to passivate the object */ private void addIdleObject(final K key, final PooledObject<T> p) throws Exception { if (p != null) { factory.passivateObject(key, p); final LinkedBlockingDeque<PooledObject<T>> idleObjects = poolMap.get(key).getIdleObjects(); if (getLifo()) { idleObjects.addFirst(p); } else { idleObjects.addLast(p); } } }
private static <K, V> List<String> invokeEveryMethod(final KeyedPooledObjectFactory<K, V> kpof) throws Exception { kpof.activateObject(null, null); kpof.destroyObject(null, null); kpof.makeObject(null); kpof.passivateObject(null, null); kpof.validateObject(null, null); kpof.toString(); final List<String> expectedMethods = Arrays.asList(new String[] { "activateObject", "destroyObject", "makeObject", "passivateObject", "validateObject", "toString", }); return expectedMethods; }
} else { try { factory.passivateObject(evictionKey, underTest); } catch (final Exception e) { destroy(evictionKey, underTest, true);
@Test public void testDefaultMethods() throws Exception { final KeyedPooledObjectFactory<Object,Object> factory = new TestFactory(); factory.activateObject("key",null); // a no-op factory.passivateObject("key",null); // a no-op factory.destroyObject("key",null); // a no-op assertTrue(factory.validateObject("key",null)); // constant true }
/** * {@inheritDoc} */ @Override public void passivateObject(final K key, final PooledObject<V> p) throws Exception { writeLock.lock(); try { keyedFactory.passivateObject(key, p); } finally { writeLock.unlock(); } }
factory.passivateObject(key, p); } catch (final Exception e1) { swallowException(e1);
/** * Add an object to the set of idle objects for a given key. * * @param key The key to associate with the idle object * @param p The wrapped object to add. * * @throws Exception If the associated factory fails to passivate the object */ private void addIdleObject(final K key, final PooledObject<T> p) throws Exception { if (p != null) { factory.passivateObject(key, p); final LinkedBlockingDeque<PooledObject<T>> idleObjects = poolMap.get(key).getIdleObjects(); if (getLifo()) { idleObjects.addFirst(p); } else { idleObjects.addLast(p); } } }
@Test public void poolFactoryNonstandardObjectLifecycleTest() throws Exception { // Pooled object may be created and passivated right away // E.g. GenericKeyedObjectPool: returnObject() -> reuseCapacity() -> create() and addIdleObject(), which invokes passivate() PooledObject<TServiceClient> pooledObject = factory.makeObject(thriftClientKey); factory.passivateObject(thriftClientKey, pooledObject); }
@Test public void poolFactoryFullObjectLifecycleTest() throws Exception { PooledObject<TServiceClient> pooledObject = factory.makeObject(thriftClientKey); factory.activateObject(thriftClientKey, pooledObject); factory.validateObject(thriftClientKey, pooledObject); factory.passivateObject(thriftClientKey, pooledObject); }
} else { try { factory.passivateObject(evictionKey, underTest); } catch (final Exception e) { destroy(evictionKey, underTest, true);
@Test public void poolFactoryOverlappingObjectLifecyclesTest() throws Exception { PooledObject<TServiceClient> pooledObject1 = factory.makeObject(thriftClientKey); // activateObject leads to tracer.isEnabled() --> true factory.activateObject(thriftClientKey, pooledObject1); factory.validateObject(thriftClientKey, pooledObject1); // Create another pooled object and passivate it right away. // See poolFactoryNonstandardObjectLifecycleTest() for details PooledObject<TServiceClient> pooledObject2 = factory.makeObject(thriftClientKey); factory.passivateObject(thriftClientKey, pooledObject2); } }
factory.passivateObject(key, p); } catch (final Exception e1) { swallowException(e1);