brooklyn.util.pool.Pool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brooklyn-utils-common Show documentation
Show all versions of brooklyn-utils-common Show documentation
Utility classes and methods developed for Brooklyn but not dependendent on Brooklyn or much else
package brooklyn.util.pool;
import java.io.Closeable;
import java.io.IOException;
import com.google.common.base.Function;
/**
* See discussion at http://code.google.com/p/guava-libraries/issues/detail?id=683.
* This API is inspired by that proposed by [email protected]
*
* There are two ways to use the pool.
*
* Passive:
*
*
* {@code
* Pool pool = ...
* Lease lease = pool.leaseObject();
* try {
* Expensive o = lease.leasedObject();
* doSomethingWith(o);
* } finally {
* lease.close();
* }
* }
*
*
* Or active:
*
*
* {@code
* Pool pool = ...
* pool.exec(
* new Function() {
* public Void apply(Expensive o) {
* doSomethingWith(o);
* return null;
* }
* });
* }
*
*
* @see BasicPool
*
* @author aled
*/
public interface Pool extends Closeable {
Lease leaseObject();
R exec(Function super T,R> receiver);
void close() throws IOException;
}