/** * Clears any objects sitting idle in the pool by removing them from the * idle instance pool and then invoking the configured * {@link PoolableObjectFactory#destroyObject(Object)} method on each idle * instance. * * <p> Implementation notes: * <ul><li>This method does not destroy or effect in any way instances that are * checked out of the pool when it is invoked.</li> * <li>Invoking this method does not prevent objects being * returned to the idle instance pool, even during its execution. It locks * the pool only during instance removal. Additional instances may be returned * while removed items are being destroyed.</li> * <li>Exceptions encountered destroying idle instances are swallowed.</li></ul></p> */ @Override public void clear() { List<ObjectTimestampPair<T>> toDestroy = new ArrayList<ObjectTimestampPair<T>>(); synchronized(this) { toDestroy.addAll(_pool); _numInternalProcessing = _numInternalProcessing + _pool._size; _pool.clear(); } destroy(toDestroy, _factory); }
_totalInternalProcessing = _totalInternalProcessing + pool.queue.size(); pool.queue.clear();
/** * Sets the {@link PoolableObjectFactory factory} this pool uses * to create new instances. Trying to change * the <code>factory</code> while there are borrowed objects will * throw an {@link IllegalStateException}. If there are instances idle * in the pool when this method is invoked, these will be destroyed * using the original factory. * * @param factory the {@link PoolableObjectFactory} used to create new instances. * @throws IllegalStateException when the factory cannot be set at this time * @deprecated to be removed in version 2.0 */ @Deprecated @Override public void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException { List<ObjectTimestampPair<T>> toDestroy = new ArrayList<ObjectTimestampPair<T>>(); final PoolableObjectFactory<T> oldFactory = _factory; synchronized (this) { assertOpen(); if(0 < getNumActive()) { throw new IllegalStateException("Objects are already active"); } else { toDestroy.addAll(_pool); _numInternalProcessing = _numInternalProcessing + _pool._size; _pool.clear(); } _factory = factory; } destroy(toDestroy, oldFactory); }
/** * Clears the specified pool, removing all pooled instances corresponding to the given <code>key</code>. * * @param key the key to clear */ @Override public void clear(K key) { Map<K, List<ObjectTimestampPair<V>>> toDestroy = new HashMap<K , List<ObjectTimestampPair<V>>>(); final ObjectQueue pool; synchronized (this) { pool = _poolMap.remove(key); if (pool == null) { return; } else { _poolList.remove(key); } // Copy objects to new list so pool.queue can be cleared inside // the sync List<ObjectTimestampPair<V>> objects = new ArrayList<ObjectTimestampPair<V>>(); objects.addAll(pool.queue); toDestroy.put(key, objects); _totalIdle = _totalIdle - pool.queue.size(); _totalInternalProcessing = _totalInternalProcessing + pool.queue.size(); pool.queue.clear(); } destroy(toDestroy, _factory); }
_totalInternalProcessing = _totalInternalProcessing + pool.queue.size(); pool.queue.clear();
/** * Clears any objects sitting idle in the pool by removing them from the * idle instance pool and then invoking the configured * {@link PoolableObjectFactory#destroyObject(Object)} method on each idle * instance. * * <p> Implementation notes: * <ul><li>This method does not destroy or effect in any way instances that are * checked out of the pool when it is invoked.</li> * <li>Invoking this method does not prevent objects being * returned to the idle instance pool, even during its execution. It locks * the pool only during instance removal. Additional instances may be returned * while removed items are being destroyed.</li> * <li>Exceptions encountered destroying idle instances are swallowed.</li></ul></p> */ @Override public void clear() { List<ObjectTimestampPair<T>> toDestroy = new ArrayList<ObjectTimestampPair<T>>(); synchronized(this) { toDestroy.addAll(_pool); _numInternalProcessing = _numInternalProcessing + _pool._size; _pool.clear(); } destroy(toDestroy, _factory); }
/** * Clears any objects sitting idle in the pool by removing them from the * idle instance pool and then invoking the configured * {@link PoolableObjectFactory#destroyObject(Object)} method on each idle * instance. * * <p> Implementation notes: * <ul><li>This method does not destroy or effect in any way instances that are * checked out of the pool when it is invoked.</li> * <li>Invoking this method does not prevent objects being * returned to the idle instance pool, even during its execution. It locks * the pool only during instance removal. Additional instances may be returned * while removed items are being destroyed.</li> * <li>Exceptions encountered destroying idle instances are swallowed.</li></ul></p> */ @Override public void clear() { List<ObjectTimestampPair<T>> toDestroy = new ArrayList<ObjectTimestampPair<T>>(); synchronized(this) { toDestroy.addAll(_pool); _numInternalProcessing = _numInternalProcessing + _pool._size; _pool.clear(); } destroy(toDestroy, _factory); }
/** * Clears any objects sitting idle in the pool by removing them from the * idle instance pool and then invoking the configured * {@link PoolableObjectFactory#destroyObject(Object)} method on each idle * instance. * * <p> Implementation notes: * <ul><li>This method does not destroy or effect in any way instances that are * checked out of the pool when it is invoked.</li> * <li>Invoking this method does not prevent objects being * returned to the idle instance pool, even during its execution. It locks * the pool only during instance removal. Additional instances may be returned * while removed items are being destroyed.</li></ul></p> */ public void clear() { List toDestroy = new ArrayList(); synchronized(this) { toDestroy.addAll(_pool); _numInternalProcessing = _numInternalProcessing + _pool._size; _pool.clear(); } destroy(toDestroy); }
/** * Clears any objects sitting idle in the pool by removing them from the * idle instance pool and then invoking the configured * {@link PoolableObjectFactory#destroyObject(Object)} method on each idle * instance. * * <p> Implementation notes: * <ul><li>This method does not destroy or effect in any way instances that are * checked out of the pool when it is invoked.</li> * <li>Invoking this method does not prevent objects being * returned to the idle instance pool, even during its execution. It locks * the pool only during instance removal. Additional instances may be returned * while removed items are being destroyed.</li></ul></p> */ public void clear() { List toDestroy = new ArrayList(); synchronized(this) { toDestroy.addAll(_pool); _numInternalProcessing = _numInternalProcessing + _pool._size; _pool.clear(); } destroy(toDestroy); }
/** * Clears the pool, removing all pooled instances. */ public synchronized void clear() { for(Iterator entries = _poolMap.entrySet().iterator(); entries.hasNext(); ) { final Map.Entry entry = (Map.Entry)entries.next(); final Object key = entry.getKey(); final CursorableLinkedList list = ((ObjectQueue)(entry.getValue())).queue; for(Iterator it = list.iterator(); it.hasNext(); ) { try { _factory.destroyObject(key,((ObjectTimestampPair)(it.next())).value); } catch(Exception e) { // ignore error, keep destroying the rest } it.remove(); } } _poolMap.clear(); _poolList.clear(); _totalIdle = 0; notifyAll(); }
/** * Sets the {@link PoolableObjectFactory factory} this pool uses * to create new instances. Trying to change * the <code>factory</code> while there are borrowed objects will * throw an {@link IllegalStateException}. If there are instances idle * in the pool when this method is invoked, these will be destroyed * using the original factory. * * @param factory the {@link PoolableObjectFactory} used to create new instances. * @throws IllegalStateException when the factory cannot be set at this time * @deprecated to be removed in version 2.0 */ @Deprecated @Override public void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException { List<ObjectTimestampPair<T>> toDestroy = new ArrayList<ObjectTimestampPair<T>>(); final PoolableObjectFactory<T> oldFactory = _factory; synchronized (this) { assertOpen(); if(0 < getNumActive()) { throw new IllegalStateException("Objects are already active"); } else { toDestroy.addAll(_pool); _numInternalProcessing = _numInternalProcessing + _pool._size; _pool.clear(); } _factory = factory; } destroy(toDestroy, oldFactory); }
_totalInternalProcessing = _totalInternalProcessing + pool.queue.size(); pool.queue.clear();
_totalInternalProcessing = _totalInternalProcessing + pool.queue.size(); pool.queue.clear();
/** * Sets the {@link PoolableObjectFactory factory} this pool uses * to create new instances. Trying to change * the <code>factory</code> while there are borrowed objects will * throw an {@link IllegalStateException}. * * @param factory the {@link PoolableObjectFactory} used to create new instances. * @throws IllegalStateException when the factory cannot be set at this time */ public void setFactory(PoolableObjectFactory factory) throws IllegalStateException { List toDestroy = new ArrayList(); synchronized (this) { assertOpen(); if(0 < getNumActive()) { throw new IllegalStateException("Objects are already active"); } else { toDestroy.addAll(_pool); _numInternalProcessing = _numInternalProcessing + _pool._size; _pool.clear(); } _factory = factory; } destroy(toDestroy); }
/** * Sets the {@link PoolableObjectFactory factory} this pool uses * to create new instances. Trying to change * the <code>factory</code> while there are borrowed objects will * throw an {@link IllegalStateException}. * * @param factory the {@link PoolableObjectFactory} used to create new instances. * @throws IllegalStateException when the factory cannot be set at this time */ public void setFactory(PoolableObjectFactory factory) throws IllegalStateException { List toDestroy = new ArrayList(); synchronized (this) { assertOpen(); if(0 < getNumActive()) { throw new IllegalStateException("Objects are already active"); } else { toDestroy.addAll(_pool); _numInternalProcessing = _numInternalProcessing + _pool._size; _pool.clear(); } _factory = factory; } destroy(toDestroy); }
/** * Clears the specified pool, removing all pooled instances corresponding to the given <code>key</code>. * * @param key the key to clear */ @Override public void clear(K key) { Map<K, List<ObjectTimestampPair<V>>> toDestroy = new HashMap<K , List<ObjectTimestampPair<V>>>(); final ObjectQueue pool; synchronized (this) { pool = _poolMap.remove(key); if (pool == null) { return; } else { _poolList.remove(key); } // Copy objects to new list so pool.queue can be cleared inside // the sync List<ObjectTimestampPair<V>> objects = new ArrayList<ObjectTimestampPair<V>>(); objects.addAll(pool.queue); toDestroy.put(key, objects); _totalIdle = _totalIdle - pool.queue.size(); _totalInternalProcessing = _totalInternalProcessing + pool.queue.size(); pool.queue.clear(); } destroy(toDestroy, _factory); }
/** * Sets the {@link PoolableObjectFactory factory} this pool uses * to create new instances. Trying to change * the <code>factory</code> while there are borrowed objects will * throw an {@link IllegalStateException}. If there are instances idle * in the pool when this method is invoked, these will be destroyed * using the original factory. * * @param factory the {@link PoolableObjectFactory} used to create new instances. * @throws IllegalStateException when the factory cannot be set at this time * @deprecated to be removed in version 2.0 */ @Deprecated @Override public void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException { List<ObjectTimestampPair<T>> toDestroy = new ArrayList<ObjectTimestampPair<T>>(); final PoolableObjectFactory<T> oldFactory = _factory; synchronized (this) { assertOpen(); if(0 < getNumActive()) { throw new IllegalStateException("Objects are already active"); } else { toDestroy.addAll(_pool); _numInternalProcessing = _numInternalProcessing + _pool._size; _pool.clear(); } _factory = factory; } destroy(toDestroy, oldFactory); }
/** * Clears the specified pool, removing all pooled instances corresponding to the given <code>key</code>. * * @param key the key to clear */ @Override public void clear(K key) { Map<K, List<ObjectTimestampPair<V>>> toDestroy = new HashMap<K , List<ObjectTimestampPair<V>>>(); final ObjectQueue pool; synchronized (this) { pool = _poolMap.remove(key); if (pool == null) { return; } else { _poolList.remove(key); } // Copy objects to new list so pool.queue can be cleared inside // the sync List<ObjectTimestampPair<V>> objects = new ArrayList<ObjectTimestampPair<V>>(); objects.addAll(pool.queue); toDestroy.put(key, objects); _totalIdle = _totalIdle - pool.queue.size(); _totalInternalProcessing = _totalInternalProcessing + pool.queue.size(); pool.queue.clear(); } destroy(toDestroy, _factory); }
/** * Clears the specified pool, removing all pooled instances corresponding to the given <code>key</code>. * * @param key the key to clear */ public void clear(Object key) { Map toDestroy = new HashMap(); final ObjectQueue pool; synchronized (this) { pool = (ObjectQueue)(_poolMap.remove(key)); if (pool == null) { return; } else { _poolList.remove(key); } // Copy objects to new list so pool.queue can be cleared inside // the sync List objects = new ArrayList(); objects.addAll(pool.queue); toDestroy.put(key, objects); _totalIdle = _totalIdle - pool.queue.size(); _totalInternalProcessing = _totalInternalProcessing + pool.queue.size(); pool.queue.clear(); } destroy(toDestroy); }
/** * Clears the specified pool, removing all pooled instances corresponding to the given <code>key</code>. * * @param key the key to clear */ public void clear(Object key) { Map toDestroy = new HashMap(); final ObjectQueue pool; synchronized (this) { pool = (ObjectQueue)(_poolMap.remove(key)); if (pool == null) { return; } else { _poolList.remove(key); } // Copy objects to new list so pool.queue can be cleared inside // the sync List objects = new ArrayList(); objects.addAll(pool.queue); toDestroy.put(key, objects); _totalIdle = _totalIdle - pool.queue.size(); _totalInternalProcessing = _totalInternalProcessing + pool.queue.size(); pool.queue.clear(); } destroy(toDestroy); }