/** * Create a StackKeyedObjectPool with current property settings. * * @return a new StackKeyedObjectPool with the configured factory, maxSleeping and initialCapacity */ public KeyedObjectPool<K, V> createPool() { return new StackKeyedObjectPool<K, V>(_factory,_maxSleeping,_initCapacity); }
assertOpen(); Stack<V> stack = (_pools.get(key)); if(null == stack) { incrementActiveCount(key); return obj;
/** * Sets the {@link KeyedPoolableObjectFactory factory} the pool uses * to create new instances. * Trying to change the <code>factory</code> after a pool has been used will frequently * throw an {@link UnsupportedOperationException}. * * @param factory the {@link KeyedPoolableObjectFactory} used to manage object instances * @throws IllegalStateException when the factory cannot be set at this time * @deprecated to be removed in pool 2.0 */ @Deprecated @Override public synchronized void setFactory(KeyedPoolableObjectFactory<K, V> factory) throws IllegalStateException { if(0 < getNumActive()) { throw new IllegalStateException("Objects are already active"); } else { clear(); _factory = factory; } }
decrementActiveCount(key); if (null != _factory) { if (_factory.validateObject(key, obj)) { if (isClosed()) { if (null != _factory) { try {
/** * Clears the specified pool, removing all pooled instances corresponding to the given <code>key</code>. * * @param key the key to clear */ @Override public synchronized void clear(K key) { Stack<V> stack = _pools.remove(key); destroyStack(key,stack); }
/** * {@inheritDoc} */ @Override public synchronized void invalidateObject(K key, V obj) throws Exception { decrementActiveCount(key); if(null != _factory) { _factory.destroyObject(key,obj); } notifyAll(); // _totalActive has changed }
/** * Close this pool, and free any resources associated with it. * <p> * Calling {@link #addObject addObject} or {@link #borrowObject borrowObject} after invoking * this method on a pool will cause them to throw an {@link IllegalStateException}. * </p> * * @throws Exception <strong>deprecated</strong>: implementations should silently fail if not all resources can be freed. */ @Override public void close() throws Exception { super.close(); clear(); }
/** * Returns the number of instances currently borrowed from but not yet returned * to the pool corresponding to the given <code>key</code>. * * @param key the key to query * @return the number of instances corresponding to the given <code>key</code> currently borrowed in this pool */ @Override public synchronized int getNumActive(K key) { return getActiveCount(key); }
assertOpen(); if (_factory == null) { throw new IllegalStateException("Cannot add objects without a factory.");
public synchronized void returnObject(Object key, Object obj) throws Exception { decrementActiveCount(key); if (null != _factory) { if (_factory.validateObject(key, obj)) { if (isClosed()) { if (null != _factory) { try {
/** * Clears the pool, removing all pooled instances. */ @Override public synchronized void clear() { Iterator<K> it = _pools.keySet().iterator(); while(it.hasNext()) { K key = it.next(); Stack<V> stack = _pools.get(key); destroyStack(key,stack); } _totIdle = 0; _pools.clear(); _activeCount.clear(); }
public synchronized void invalidateObject(Object key, Object obj) throws Exception { decrementActiveCount(key); if(null != _factory) { _factory.destroyObject(key,obj); } notifyAll(); // _totalActive has changed }
/** * Close this pool, and free any resources associated with it. * <p> * Calling {@link #addObject addObject} or {@link #borrowObject borrowObject} after invoking * this method on a pool will cause them to throw an {@link IllegalStateException}. * </p> * * @throws Exception <strong>deprecated</strong>: implementations should silently fail if not all resources can be freed. */ public void close() throws Exception { super.close(); clear(); }
/** * Returns the number of instances currently borrowed from but not yet returned * to the pool corresponding to the given <code>key</code>. * * @param key the key to query * @return the number of instances corresponding to the given <code>key</code> currently borrowed in this pool */ public synchronized int getNumActive(Object key) { return getActiveCount(key); }
assertOpen(); if (_factory == null) { throw new IllegalStateException("Cannot add objects without a factory.");
/** * Sets the {@link KeyedPoolableObjectFactory factory} the pool uses * to create new instances. * Trying to change the <code>factory</code> after a pool has been used will frequently * throw an {@link UnsupportedOperationException}. * * @param factory the {@link KeyedPoolableObjectFactory} used to create new instances. * @throws IllegalStateException when the factory cannot be set at this time */ public synchronized void setFactory(KeyedPoolableObjectFactory factory) throws IllegalStateException { if(0 < getNumActive()) { throw new IllegalStateException("Objects are already active"); } else { clear(); _factory = factory; } }
public synchronized Object borrowObject(Object key) throws Exception { assertOpen(); Stack stack = (Stack)(_pools.get(key)); if(null == stack) { incrementActiveCount(key); return obj;
public synchronized void returnObject(Object key, Object obj) throws Exception { decrementActiveCount(key); if (null != _factory) { if (_factory.validateObject(key, obj)) { if (isClosed()) { if (null != _factory) { try {
/** * Clears the specified pool, removing all pooled instances corresponding to the given <code>key</code>. * * @param key the key to clear */ public synchronized void clear(Object key) { Stack stack = (Stack)(_pools.remove(key)); destroyStack(key,stack); }
public synchronized void invalidateObject(Object key, Object obj) throws Exception { decrementActiveCount(key); if(null != _factory) { _factory.destroyObject(key,obj); } notifyAll(); // _totalActive has changed }