Skip to content
Merged
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 @@ -157,7 +157,7 @@ public void close() {
}

private PerRoutePool<T, C> getPool(final T route) {
return this.routeToPool.computeIfAbsent(route, r -> new PerRoutePool<>(route, this.disposalCallback));
return this.routeToPool.computeIfAbsent(route, r -> new PerRoutePool<>(route, this.disposalCallback, this.policy));
}

@Override
Expand Down Expand Up @@ -755,11 +755,13 @@ static class PerRoutePool<T, C extends ModalCloseable> {
private final Set<PoolEntry<T, C>> leased;
private final LinkedList<PoolEntry<T, C>> available;
private final DisposalCallback<C> disposalCallback;
private final PoolReusePolicy policy;

PerRoutePool(final T route, final DisposalCallback<C> disposalCallback) {
PerRoutePool(final T route, final DisposalCallback<C> disposalCallback, final PoolReusePolicy policy) {
super();
this.route = route;
this.disposalCallback = disposalCallback;
this.policy = policy;
this.leased = new HashSet<>();
this.available = new LinkedList<>();
}
Expand Down Expand Up @@ -818,7 +820,16 @@ public void free(final PoolEntry<T, C> entry, final boolean reusable) {
final boolean found = this.leased.remove(entry);
Asserts.check(found, "Entry %s has not been leased from this pool", entry);
if (reusable) {
this.available.addFirst(entry);
switch (this.policy) {
case LIFO:
this.available.addFirst(entry);
break;
case FIFO:
this.available.addLast(entry);
break;
default:
throw new IllegalStateException("Unexpected ConnPoolPolicy value: " + policy);
}
}
}

Expand Down
Loading