summaryrefslogtreecommitdiffstats
path: root/yolean/src/main/java/com/yahoo/yolean/concurrent/ResourcePool.java
diff options
context:
space:
mode:
Diffstat (limited to 'yolean/src/main/java/com/yahoo/yolean/concurrent/ResourcePool.java')
-rw-r--r--yolean/src/main/java/com/yahoo/yolean/concurrent/ResourcePool.java16
1 files changed, 12 insertions, 4 deletions
diff --git a/yolean/src/main/java/com/yahoo/yolean/concurrent/ResourcePool.java b/yolean/src/main/java/com/yahoo/yolean/concurrent/ResourcePool.java
index 75f8c961349..895fa890beb 100644
--- a/yolean/src/main/java/com/yahoo/yolean/concurrent/ResourcePool.java
+++ b/yolean/src/main/java/com/yahoo/yolean/concurrent/ResourcePool.java
@@ -4,6 +4,7 @@ package com.yahoo.yolean.concurrent;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
+import java.util.function.Supplier;
/**
* <p>This implements a simple stack based resource pool. If you are out of resources new are allocated from the
@@ -15,17 +16,24 @@ import java.util.Iterator;
public final class ResourcePool<T> implements Iterable<T> {
private final Deque<T> pool = new ArrayDeque<>();
- private final ResourceFactory<T> factory;
+ private final Supplier<T> factory;
+ /** @deprecated Use {@link ResourcePool( Supplier )} instead */
+ @Deprecated(forRemoval = true, since = "7")
+ @SuppressWarnings("removal")
public ResourcePool(ResourceFactory<T> factory) {
+ this(factory.asSupplier());
+ }
+
+ public ResourcePool(Supplier<T> factory) {
this.factory = factory;
}
- public final T alloc() {
- return pool.isEmpty() ? factory.create() : pool.pop();
+ public T alloc() {
+ return pool.isEmpty() ? factory.get() : pool.pop();
}
- public final void free(T e) {
+ public void free(T e) {
pool.push(e);
}