synchronized (pool) { if (factor.getNextShrink() < now) { // XXX: Pool 3: move test out of sync block final int numIdle = pool.getNumIdle(); if (numIdle > 0) { discard = true; pool.invalidateObject(obj); } else { pool.returnObject(obj);
/** * Borrow and object from the pool, ignoring the key * * @param key ignored * @return newly created object instance */ public V borrowObject(final K key) throws Exception, NoSuchElementException, IllegalStateException { return pool.borrowObject(); }
/** * {@inheritDoc} */ public void close() { try { synchronized (lock) { pool.close(); } } catch (Exception e) { // swallowed as of Pool 2 } }
/** * {@inheritDoc} */ @Override public void run() { boolean success = false; try { if (pool.getNumIdle() < minIdle) { pool.addObject(); } success = true; } catch (Exception e) { cancel(); } finally { // detect other types of Throwable and cancel this Timer if (!success) { cancel(); } } }
public String getBackingStoreDescription() throws FactoryException { AbstractCachedAuthorityFactory worker = null; try { worker = (AbstractCachedAuthorityFactory) getPool().borrowObject(); return worker.getBackingStoreDescription(); } catch (FactoryException e) { throw e; } catch (Exception e) { throw new FactoryException(e); } finally { try { getPool().returnObject(worker); } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to return worker " + e, e); } } } /**
/** * {@inheritDoc} */ public void returnObject(final T obj) { synchronized (lock) { try { pool.returnObject(obj); } catch (Exception e) { // swallowed as of Pool 2 } } }
public APIKeyValidatorClient get() throws Exception { if (log.isTraceEnabled()) { int active = clientPool.getNumActive(); if (active >= maxIdle) { log.trace("Key validation pool size is :" + active); } } return (APIKeyValidatorClient) clientPool.borrowObject(); }
/** * {@inheritDoc} */ public void invalidateObject(final T obj) { try { pool.invalidateObject(obj); } catch (Exception e) { // swallowed } }
/** * Return the number of objects checked out from the pool, ignoring the key. * * @param key ignored * @return active instance count */ public int getNumActive(final K key) throws UnsupportedOperationException { return pool.getNumActive(); }
@Test public void releaseInvalidConnection() throws Exception { when(connectionProvider.validate(connection)).thenReturn(failure("Connection is invalid", new IOException())); managedConnection.release(); verify(pool).invalidateObject(connection); verify(pool, never()).returnObject(connection); verify(poolingListener, never()).onReturn(connection); }
/** * {@inheritDoc} */ public int getNumIdle() throws UnsupportedOperationException { return pool.getNumIdle(); }
/** * Clear the pool, ignoring the key (has same effect as {@link #clear()}. * * @param key ignored. */ public void clear(final K key) throws Exception, UnsupportedOperationException { pool.clear(); }
/** * Sets the object factory associated with the pool * * @param factory object factory * @deprecated to be removed in version 2.0 */ @Deprecated public void setFactory(final PoolableObjectFactory<T> factory) throws IllegalStateException, UnsupportedOperationException { pool.setFactory(factory); }
/** * True if this mediator is currently connected to one or more workers. * * @return */ public boolean isConnected() { return (workers.getNumActive() + workers.getNumIdle()) > 0; }
public Set getAuthorityCodes(Class type) throws FactoryException { Set codes = (Set) cache.get(type); if (codes == null) { try { cache.writeLock(type); codes = (Set) cache.peek(type); if (codes == null) { AbstractCachedAuthorityFactory worker = null; try { worker = (AbstractCachedAuthorityFactory) getPool().borrowObject(); codes = worker.getAuthorityCodes(type); cache.put(type, codes); } catch (FactoryException e) { throw e; } catch (Exception e) { throw new FactoryException(e); } finally { try { getPool().returnObject(worker); } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to return worker " + e, e); } } } } finally { cache.writeUnLock(type); } } return codes; }
/** * Return and object to the pool, ignoring the key * * @param key ignored * @param obj object to return */ public void returnObject(final K key, final V obj) { try { pool.returnObject(obj); } catch (Exception e) { // swallowed as of Pool 2 } }
public ThriftKeyValidatorClient get() throws Exception { if (log.isTraceEnabled()) { int active = clientPool.getNumActive(); if (active >= maxIdle) { log.trace("Key validation pool size is :" + active); } } return (ThriftKeyValidatorClient) clientPool.borrowObject(); }
/** * {@inheritDoc} */ public void invalidateObject(final T obj) { synchronized (lock) { try { pool.invalidateObject(obj); } catch (Exception e) { // swallowed as of Pool 2 } } }