1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.hc.client5.http.impl;
28
29 import org.apache.hc.client5.http.HttpRoute;
30 import org.apache.hc.core5.annotation.Internal;
31 import org.apache.hc.core5.pool.ConnPoolControl;
32 import org.apache.hc.core5.pool.PoolStats;
33 import org.apache.hc.core5.util.Identifiable;
34
35
36
37
38
39
40 @Internal
41 public final class ConnPoolSupport {
42
43 public static String getId(final Object object) {
44 if (object == null) {
45 return null;
46 }
47 return object instanceof Identifiable
48 ? ((Identifiable) object).getId()
49 : object.getClass().getSimpleName() + "-"
50 + Integer.toHexString(System.identityHashCode(object));
51 }
52
53 public static String formatStats(
54 final HttpRoute route,
55 final Object state,
56 final ConnPoolControl<HttpRoute> connPool) {
57 final StringBuilder buf = new StringBuilder();
58 buf.append("[route: ").append(route).append("]");
59 if (state != null) {
60 buf.append("[state: ").append(state).append("]");
61 }
62 final PoolStats totals = connPool.getTotalStats();
63 final PoolStats stats = connPool.getStats(route);
64 buf.append("[total available: ").append(totals.getAvailable()).append("; ");
65 buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
66 buf.append(" of ").append(stats.getMax()).append("; ");
67 buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
68 buf.append(" of ").append(totals.getMax()).append("]");
69 return buf.toString();
70 }
71
72 }