_poolList = new CursorableLinkedList<K>();
pool = new ObjectQueue(); _poolMap.put(key, pool); _poolList.add(key); if (_maxIdle >= 0 && (pool.queue.size() >= _maxIdle)) { shouldDestroy = true; } else if (success) { pool.queue.addFirst(new ObjectTimestampPair<V>(obj)); } else { pool.queue.addLast(new ObjectTimestampPair<V>(obj)); synchronized(this) { pool.decrementActiveCount(); if (pool.queue.isEmpty() && pool.activeCount == 0 && pool.internalProcessingCount == 0) { _poolMap.remove(key); _poolList.remove(key);
/** * 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); }
/** * Resets the eviction object cursor for the given key * * @param key eviction key */ private void resetEvictionObjectCursor(Object key) { if (_evictionCursor != null) { _evictionCursor.close(); } if (_poolMap == null) { return; } ObjectQueue pool = _poolMap.get(key); if (pool != null) { CursorableLinkedList<ObjectTimestampPair<V>> queue = pool.queue; _evictionCursor = queue.cursor(_lifo ? queue.size() : 0); } }
/** * Inserts the specified element at the specified position in this list. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices). * * @param index index at which the specified element is to be inserted. * @param element element to be inserted. * * @throws ClassCastException if the class of the specified element * prevents it from being added to this list. * @throws IllegalArgumentException if some aspect of the specified * element prevents it from being added to this list. * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > size()). */ public void add(int index, E element) { if(index == _size) { add(element); } else { if(index < 0 || index > _size) { throw new IndexOutOfBoundsException(String.valueOf(index) + " < 0 or " + String.valueOf(index) + " > " + _size); } Listable<E> succ = (isEmpty() ? null : getListableAt(index)); Listable<E> pred = (null == succ ? null : succ.prev()); insertListable(pred,succ,element); } }
if (!_pool.isEmpty() && !_allocationQueue.isEmpty()) { Latch<T> latch = _allocationQueue.removeFirst(); latch.setPair( _pool.removeFirst()); _numInternalProcessing++; synchronized (latch) {
pool = new ObjectQueue(); _poolMap.put(latch.getkey(), pool); _poolList.add(latch.getkey()); if (!pool.queue.isEmpty()) { allocationQueueIter.remove(); latch.setPair( pool.queue.removeFirst()); pool.incrementInternalProcessingCount(); _totalIdle--;
/** * Removes all of the elements from this list. This * list will be empty after this call returns (unless * it throws an exception). */ public void clear() { /* // this is the quick way, but would force us // to break all the cursors _modCount++; _head.setNext(null); _head.setPrev(null); _size = 0; */ Iterator<E> it = iterator(); while(it.hasNext()) { it.next(); it.remove(); } }
@Override public boolean add(E o) { checkForComod(); return super.add(o); }
/** * 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); }
/** * Resets the eviction key cursor and closes any * associated eviction object cursor */ private void resetEvictionKeyCursor() { if (_evictionKeyCursor != null) { _evictionKeyCursor.close(); } _evictionKeyCursor = _poolList.cursor(); if (null != _evictionCursor) { _evictionCursor.close(); _evictionCursor = null; } }
@Override public boolean addFirst(E o) { checkForComod(); return super.addFirst(o); }
@Override public boolean addLast(E o) { checkForComod(); return super.addLast(o); }
@Override public E removeFirst() { checkForComod(); return super.removeFirst(); }
@Override public boolean remove(Object o) { checkForComod(); return super.remove(o); }
@Override public boolean isEmpty() { checkForComod(); return super.isEmpty(); }