rpc.turbo.pool.ObjectFactory Maven / Gradle / Ivy
package rpc.turbo.pool;
import stormpot.Allocator;
import stormpot.Slot;
@FunctionalInterface
public interface ObjectFactory extends Allocator> {
public T newInstance();
@Override
default public PoolableObject allocate(Slot slot) throws Exception {
return new PoolableObject(slot, newInstance());
}
@Override
default public void deallocate(PoolableObject poolable) throws Exception {
if (poolable == null) {
return;
}
T t = poolable.get();
if (t == null) {
return;
}
if (t instanceof AutoCloseable) {
((AutoCloseable) t).close();
}
}
}