Skip to content

Commit 0d9d1aa

Browse files
committed
StrictConnPool: Fix FIFO implementation
1 parent 7230a04 commit 0d9d1aa

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void close() {
157157
}
158158

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

163163
@Override
@@ -755,11 +755,13 @@ static class PerRoutePool<T, C extends ModalCloseable> {
755755
private final Set<PoolEntry<T, C>> leased;
756756
private final LinkedList<PoolEntry<T, C>> available;
757757
private final DisposalCallback<C> disposalCallback;
758+
private final PoolReusePolicy policy;
758759

759-
PerRoutePool(final T route, final DisposalCallback<C> disposalCallback) {
760+
PerRoutePool(final T route, final DisposalCallback<C> disposalCallback, final PoolReusePolicy policy) {
760761
super();
761762
this.route = route;
762763
this.disposalCallback = disposalCallback;
764+
this.policy = policy;
763765
this.leased = new HashSet<>();
764766
this.available = new LinkedList<>();
765767
}
@@ -818,7 +820,16 @@ public void free(final PoolEntry<T, C> entry, final boolean reusable) {
818820
final boolean found = this.leased.remove(entry);
819821
Asserts.check(found, "Entry %s has not been leased from this pool", entry);
820822
if (reusable) {
821-
this.available.addFirst(entry);
823+
switch (this.policy) {
824+
case LIFO:
825+
this.available.addFirst(entry);
826+
break;
827+
case FIFO:
828+
this.available.addLast(entry);
829+
break;
830+
default:
831+
throw new IllegalStateException("Unexpected ConnPoolPolicy value: " + policy);
832+
}
822833
}
823834
}
824835

0 commit comments

Comments
 (0)