1 /*
2 * ====================================================================
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 * ====================================================================
20 *
21 * This software consists of voluntary contributions made by many
22 * individuals on behalf of the Apache Software Foundation. For more
23 * information on the Apache Software Foundation, please see
24 * <http://www.apache.org/>.
25 *
26 */
27 package org.apache.http.pool;
28
29 import org.apache.http.annotation.Immutable;
30
31 /**
32 * Pool statistics.
33 * <p>
34 * The total number of connections in the pool is equal to {@code available} plus {@code leased}.
35 * </p>
36 *
37 * @since 4.2
38 */
39 @Immutable
40 public class PoolStats {
41
42 private final int leased;
43 private final int pending;
44 private final int available;
45 private final int max;
46
47 public PoolStats(final int leased, final int pending, final int free, final int max) {
48 super();
49 this.leased = leased;
50 this.pending = pending;
51 this.available = free;
52 this.max = max;
53 }
54
55 /**
56 * Gets the number of persistent connections tracked by the connection manager currently being used to execute
57 * requests.
58 * <p>
59 * The total number of connections in the pool is equal to {@code available} plus {@code leased}.
60 * </p>
61 *
62 * @return the number of persistent connections.
63 */
64 public int getLeased() {
65 return this.leased;
66 }
67
68 /**
69 * Gets the number of connection requests being blocked awaiting a free connection. This can happen only if there
70 * are more worker threads contending for fewer connections.
71 *
72 * @return the number of connection requests being blocked awaiting a free connection.
73 */
74 public int getPending() {
75 return this.pending;
76 }
77
78 /**
79 * Gets the number idle persistent connections.
80 * <p>
81 * The total number of connections in the pool is equal to {@code available} plus {@code leased}.
82 * </p>
83 *
84 * @return number idle persistent connections.
85 */
86 public int getAvailable() {
87 return this.available;
88 }
89
90 /**
91 * Gets the maximum number of allowed persistent connections.
92 *
93 * @return the maximum number of allowed persistent connections.
94 */
95 public int getMax() {
96 return this.max;
97 }
98
99 @Override
100 public String toString() {
101 final StringBuilder buffer = new StringBuilder();
102 buffer.append("[leased: ");
103 buffer.append(this.leased);
104 buffer.append("; pending: ");
105 buffer.append(this.pending);
106 buffer.append("; available: ");
107 buffer.append(this.available);
108 buffer.append("; max: ");
109 buffer.append(this.max);
110 buffer.append("]");
111 return buffer.toString();
112 }
113
114 }