Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
*
* @param <K> The type of keys managed by this factory.
* @param <V> Type of element managed by this factory.
* @param <E> Type of exception thrown by this factory.
*
* @since 2.0
*/
public abstract class BaseKeyedPooledObjectFactory<K, V> extends BaseObject
implements KeyedPooledObjectFactory<K, V> {
public abstract class BaseKeyedPooledObjectFactory<K, V, E extends Exception> extends BaseObject implements KeyedPooledObjectFactory<K, V, E> {

/**
* Reinitialize an instance to be returned by the pool.
Expand All @@ -45,8 +45,7 @@ public abstract class BaseKeyedPooledObjectFactory<K, V> extends BaseObject
* @param p a {@code PooledObject} wrapping the instance to be activated
*/
@Override
public void activateObject(final K key, final PooledObject<V> p)
throws Exception {
public void activateObject(final K key, final PooledObject<V> p) throws E {
// The default implementation is a no-op.
}

Expand All @@ -56,11 +55,10 @@ public void activateObject(final K key, final PooledObject<V> p)
* @param key the key used when constructing the object
* @return an instance that can be served by the pool
*
* @throws Exception if there is a problem creating a new instance,
* @throws E if there is a problem creating a new instance,
* this will be propagated to the code requesting an object.
*/
public abstract V create(K key)
throws Exception;
public abstract V create(K key) throws E;

/**
* Destroy an instance no longer needed by the pool.
Expand All @@ -72,13 +70,12 @@ public abstract V create(K key)
* @param p a {@code PooledObject} wrapping the instance to be destroyed
*/
@Override
public void destroyObject(final K key, final PooledObject<V> p)
throws Exception {
public void destroyObject(final K key, final PooledObject<V> p) throws E {
// The default implementation is a no-op.
}

@Override
public PooledObject<V> makeObject(final K key) throws Exception {
public PooledObject<V> makeObject(final K key) throws E {
return wrap(create(key));
}

Expand All @@ -92,8 +89,7 @@ public PooledObject<V> makeObject(final K key) throws Exception {
* @param p a {@code PooledObject} wrapping the instance to be passivated
*/
@Override
public void passivateObject(final K key, final PooledObject<V> p)
throws Exception {
public void passivateObject(final K key, final PooledObject<V> p) throws E {
// The default implementation is a no-op.
}

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/apache/commons/pool2/BaseObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
* </p>
*
* @param <T> Type of element pooled in this pool.
* @param <E> Type of exception thrown by this pool.
*
* @since 2.0
*/
public abstract class BaseObjectPool<T> extends BaseObject implements ObjectPool<T> {
public abstract class BaseObjectPool<T, E extends Exception> extends BaseObject implements ObjectPool<T, E> {

private volatile boolean closed;

Expand All @@ -40,7 +41,7 @@ public abstract class BaseObjectPool<T> extends BaseObject implements ObjectPool
* method
*/
@Override
public void addObject() throws Exception, UnsupportedOperationException {
public void addObject() throws E, UnsupportedOperationException {
throw new UnsupportedOperationException();
}

Expand All @@ -59,7 +60,7 @@ protected final void assertOpen() throws IllegalStateException {
}

@Override
public abstract T borrowObject() throws Exception;
public abstract T borrowObject() throws E;

/**
* Not supported in this base implementation.
Expand All @@ -68,7 +69,7 @@ protected final void assertOpen() throws IllegalStateException {
* method
*/
@Override
public void clear() throws Exception, UnsupportedOperationException {
public void clear() throws E, UnsupportedOperationException {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -105,7 +106,7 @@ public int getNumIdle() {
}

@Override
public abstract void invalidateObject(T obj) throws Exception;
public abstract void invalidateObject(T obj) throws E;

/**
* Has this pool instance been closed.
Expand All @@ -117,7 +118,7 @@ public final boolean isClosed() {
}

@Override
public abstract void returnObject(T obj) throws Exception;
public abstract void returnObject(T obj) throws E;

@Override
protected void toStringAppendFields(final StringBuilder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@
* This class is immutable, and therefore thread-safe
*
* @param <T> Type of element managed in this factory.
* @param <E> Type of exception thrown in this factory.
*
* @see PooledObjectFactory
* @see BaseKeyedPooledObjectFactory
*
* @since 2.0
*/
public abstract class BasePooledObjectFactory<T> extends BaseObject implements PooledObjectFactory<T> {
public abstract class BasePooledObjectFactory<T, E extends Exception> extends BaseObject implements PooledObjectFactory<T, E> {

/**
* No-op.
*
* @param p ignored
*/
@Override
public void activateObject(final PooledObject<T> p) throws Exception {
public void activateObject(final PooledObject<T> p) throws E {
// The default implementation is a no-op.
}

Expand All @@ -49,10 +50,10 @@ public void activateObject(final PooledObject<T> p) throws Exception {
*
* @return an instance to be served by the pool
*
* @throws Exception if there is a problem creating a new instance,
* @throws E if there is a problem creating a new instance,
* this will be propagated to the code requesting an object.
*/
public abstract T create() throws Exception;
public abstract T create() throws E;

/**
* No-op.
Expand All @@ -61,12 +62,12 @@ public void activateObject(final PooledObject<T> p) throws Exception {
*/
@Override
public void destroyObject(final PooledObject<T> p)
throws Exception {
throws E {
// The default implementation is a no-op.
}

@Override
public PooledObject<T> makeObject() throws Exception {
public PooledObject<T> makeObject() throws E {
return wrap(create());
}

Expand All @@ -77,7 +78,7 @@ public PooledObject<T> makeObject() throws Exception {
*/
@Override
public void passivateObject(final PooledObject<T> p)
throws Exception {
throws E {
// The default implementation is a no-op.
}

Expand Down
40 changes: 20 additions & 20 deletions src/main/java/org/apache/commons/pool2/KeyedObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@
*
* @param <K> The type of keys maintained by this pool.
* @param <V> Type of element pooled in this pool.
* @param <E> Type of exception thrown by this pool.
*
* @see KeyedPooledObjectFactory
* @see ObjectPool
* @see org.apache.commons.pool2.impl.GenericKeyedObjectPool GenericKeyedObjectPool
*
* @since 2.0
*/
public interface KeyedObjectPool<K, V> extends Closeable {
public interface KeyedObjectPool<K, V, E extends Exception> extends Closeable {

/**
* Creates an object using the {@link KeyedPooledObjectFactory factory} or
Expand All @@ -78,15 +79,14 @@ public interface KeyedObjectPool<K, V> extends Closeable {
*
* @param key the key a new instance should be added to
*
* @throws Exception
* @throws E
* when {@link KeyedPooledObjectFactory#makeObject} fails.
* @throws IllegalStateException
* after {@link #close} has been called on this pool.
* @throws UnsupportedOperationException
* when this pool cannot add new idle objects.
*/
void addObject(K key) throws Exception, IllegalStateException,
UnsupportedOperationException;
void addObject(K key) throws E, IllegalStateException, UnsupportedOperationException;

/**
* Calls {@link KeyedObjectPool#addObject(Object)} with each
Expand All @@ -98,14 +98,14 @@ void addObject(K key) throws Exception, IllegalStateException,
* {@link Collection} of keys to add objects for.
* @param count
* the number of idle objects to add for each {@code key}.
* @throws Exception
* @throws E
* when {@link KeyedObjectPool#addObject(Object)} fails.
* @throws IllegalArgumentException
* when {@code keyedPool}, {@code keys}, or any value
* in {@code keys} is {@code null}.
* @see #addObjects(Object, int)
*/
default void addObjects(final Collection<K> keys, final int count) throws Exception, IllegalArgumentException {
default void addObjects(final Collection<K> keys, final int count) throws E, IllegalArgumentException {
if (keys == null) {
throw new IllegalArgumentException(PoolUtils.MSG_NULL_KEYS);
}
Expand All @@ -122,13 +122,13 @@ default void addObjects(final Collection<K> keys, final int count) throws Except
* the key to add objects for.
* @param count
* the number of idle objects to add for {@code key}.
* @throws Exception
* @throws E
* when {@link KeyedObjectPool#addObject(Object)} fails.
* @throws IllegalArgumentException
* when {@code key} is {@code null}.
* @since 2.8.0
*/
default void addObjects(final K key, final int count) throws Exception, IllegalArgumentException {
default void addObjects(final K key, final int count) throws E, IllegalArgumentException {
if (key == null) {
throw new IllegalArgumentException(PoolUtils.MSG_NULL_KEY);
}
Expand Down Expand Up @@ -166,24 +166,24 @@ default void addObjects(final K key, final int count) throws Exception, IllegalA
*
* @throws IllegalStateException
* after {@link #close close} has been called on this pool
* @throws Exception
* @throws E
* when {@link KeyedPooledObjectFactory#makeObject
* makeObject} throws an exception
* @throws NoSuchElementException
* when the pool is exhausted and cannot or will not return
* another instance
*/
V borrowObject(K key) throws Exception, NoSuchElementException, IllegalStateException;
V borrowObject(K key) throws E, NoSuchElementException, IllegalStateException;

/**
* Clears the pool, removing all pooled instances (optional operation).
*
* @throws UnsupportedOperationException when this implementation doesn't
* support the operation
*
* @throws Exception if the pool cannot be cleared
* @throws E if the pool cannot be cleared
*/
void clear() throws Exception, UnsupportedOperationException;
void clear() throws E, UnsupportedOperationException;

/**
* Clears the specified pool, removing all pooled instances corresponding to
Expand All @@ -194,9 +194,9 @@ default void addObjects(final K key, final int count) throws Exception, IllegalA
* @throws UnsupportedOperationException when this implementation doesn't
* support the operation
*
* @throws Exception if the key cannot be cleared
* @throws E if the key cannot be cleared
*/
void clear(K key) throws Exception, UnsupportedOperationException;
void clear(K key) throws E, UnsupportedOperationException;

/**
* Closes this pool, and free any resources associated with it.
Expand Down Expand Up @@ -277,9 +277,9 @@ default List<K> getKeys() {
* @param key the key used to obtain the object
* @param obj a {@link #borrowObject borrowed} instance to be returned.
*
* @throws Exception if the instance cannot be invalidated
* @throws E if the instance cannot be invalidated
*/
void invalidateObject(K key, V obj) throws Exception;
void invalidateObject(K key, V obj) throws E;

/**
* Invalidates an object from the pool, using the provided
Expand All @@ -300,10 +300,10 @@ default List<K> getKeys() {
* @param obj a {@link #borrowObject borrowed} instance to be returned.
* @param destroyMode destroy activation context provided to the factory
*
* @throws Exception if the instance cannot be invalidated
* @throws E if the instance cannot be invalidated
* @since 2.9.0
*/
default void invalidateObject(final K key, final V obj, final DestroyMode destroyMode) throws Exception {
default void invalidateObject(final K key, final V obj, final DestroyMode destroyMode) throws E {
invalidateObject(key, obj);
}

Expand All @@ -324,7 +324,7 @@ default void invalidateObject(final K key, final V obj, final DestroyMode destro
* to return an object that was never borrowed from the pool
* will trigger this exception.
*
* @throws Exception if an instance cannot be returned to the pool
* @throws E if an instance cannot be returned to the pool
*/
void returnObject(K key, V obj) throws Exception;
void returnObject(K key, V obj) throws E;
}
Loading