/** * {@inheritDoc} */ public void returnObject(final V obj) { try { keyedPool.returnObject(key, obj); } catch (Exception e) { // swallowed as of Pool 2 } }
/** * {@inheritDoc} */ public V borrowObject() throws Exception, NoSuchElementException, IllegalStateException { return keyedPool.borrowObject(key); }
/** * {@inheritDoc} */ public void invalidateObject(final K key, final V obj) { try { keyedPool.invalidateObject(key, obj); } catch (Exception e) { // swallowed } }
@Override public void doOperation(int id) throws Exception { Integer key = id % numKeys; String s = (String) pool.borrowObject(key); pool.returnObject(key, s); } };
public Iterable<Result> execute(Query query) throws Exception { JMXConnection jmxConnection = null; try { jmxConnection = pool.borrowObject(this); ImmutableList.Builder<Result> results = ImmutableList.builder(); MBeanServerConnection connection = jmxConnection.getMBeanServerConnection(); for (ObjectName queryName : query.queryNames(connection)) { results.addAll(query.fetchResults(connection, queryName)); } return results.build(); } catch (Exception e) { if (jmxConnection != null) { pool.invalidateObject(this, jmxConnection); jmxConnection = null; } throw e; } finally { if (jmxConnection != null) { pool.returnObject(this, jmxConnection); } } }
/** * {@inheritDoc} */ public void close() { try { keyedPool.close(); } catch (Exception e) { // swallowed as of Pool 2 } }
keyedPool.invalidateObject(key, obj); } else { keyedPool.returnObject(key, obj);
/** * {@inheritDoc} */ public int getNumIdle(final K key) throws UnsupportedOperationException { synchronized (lock) { return keyedPool.getNumIdle(key); } }
/** * {@inheritDoc} */ public int getNumActive() throws UnsupportedOperationException { return keyedPool.getNumActive(key); }
/** * Sets the object factory used by the pool. * * @param factory KeyedPoolableObjectFactory used by the pool * @deprecated to be removed in pool 2.0 */ @Deprecated public void setFactory(final KeyedPoolableObjectFactory<K, V> factory) throws IllegalStateException, UnsupportedOperationException { synchronized (lock) { keyedPool.setFactory(factory); } }
public static String getPoolStatus() { if (attributeObjectPool == null) return ""; return "active="+attributeObjectPool.getNumActive()+", idle="+attributeObjectPool.getNumIdle(); }
/** * {@inheritDoc} */ public void clear() throws Exception, UnsupportedOperationException { synchronized (lock) { keyedPool.clear(); } }
/** * {@inheritDoc} */ @Override public void run() { boolean success = false; try { if (keyedPool.getNumIdle(key) < minIdle) { keyedPool.addObject(key); } success = true; } catch (Exception e) { cancel(); } finally { // detect other types of Throwable and cancel this Timer if (!success) { cancel(); } } }
/** * {@inheritDoc} */ public void close() { try { synchronized (lock) { keyedPool.close(); } } catch (Exception e) { // swallowed as of Pool 2 } }
/** * {@inheritDoc} */ public int getNumIdle() throws UnsupportedOperationException { return keyedPool.getNumIdle(); }
/** * {@inheritDoc} */ public int getNumActive(final K key) throws UnsupportedOperationException { return keyedPool.getNumActive(key); }
/** * 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 KeyedPoolableObjectFactory<K, V> factory) throws IllegalStateException, UnsupportedOperationException { keyedPool.setFactory(factory); }
public static String getPoolStatus() { if (pktObjectPool == null) return ""; return "active="+pktObjectPool.getNumActive()+", idle="+pktObjectPool.getNumIdle(); }
/** * {@inheritDoc} */ public void clear() throws Exception, UnsupportedOperationException { keyedPool.clear(); }
/** * {@inheritDoc} */ public void returnObject(final K key, final V obj) { synchronized (lock) { try { keyedPool.returnObject(key, obj); } catch (Exception e) { // swallowed } } }