@Override public AsyncPoolStats getStats() { // get a copy of the stats synchronized (_lock) { return _statsTracker.getStats(); } }
@Override public void onError(Throwable e) { boolean create; synchronized (_lock) { _statsTracker.incrementDestroyErrors(); create = objectDestroyed(); } if (create) { create(); } // TODO log this error! } });
@Override public void onSuccess(T t) { boolean create; synchronized (_lock) { _statsTracker.incrementDestroyed(); create = objectDestroyed(); } if (create) { create(); } }
public final T get() { return _item; }
public enum Strategy { MRU, LRU } private final Strategy _strategy;
private <U> Collection<U> reap(Queue<TimedObject<U>> queue, long timeout) { List<U> toReap = new ArrayList<U>(); long now = System.currentTimeMillis(); long target = now - timeout; synchronized (_lock) { int excess = _poolSize - _minSize; for (TimedObject<U> p; (p = queue.peek()) != null && p.getTime() < target && excess > 0; excess--) { toReap.add(queue.poll().get()); _statsTracker.incrementTimedOut(); } } return toReap; }
if (bad) _statsTracker.incrementBadDestroyed();
/** * This method is safe to call while holding the lock. DO NOT * call any callbacks in this method! * @return true if another object creation should be initiated. */ private boolean shouldCreate() { boolean result = false; synchronized (_lock) { if (_state == State.RUNNING) { if (_poolSize >= _maxSize) { // If we pass up an opportunity to create an object due to full pool, the next // timeout is not necessarily caused by any previous creation failure. Need to // think about this a little more. What if the pool is full due to pending creations // that eventually fail? _lastCreateError = null; } else if (_waiters.size() > 0 || _poolSize < _minSize) { _poolSize++; _statsTracker.sampleMaxPoolSize(); result = true; } } } return result; }
_statsTracker.sampleMaxCheckedOut();
_statsTracker = new AsyncPoolStatsTracker( () -> _lifecycle.getStats(), () -> 1,
_statsTracker.incrementTimedOut(); _item.reset();
_statsTracker.incrementBadDestroyed();
_statsTracker.sampleMaxCheckedOut();
@Override public PoolStats getStats() { synchronized (_lock) { return _statsTracker.getStats(); } }