View Javadoc

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 java.io.Serializable;
30  
31  import org.apache.http.annotation.Immutable;
32  
33  /**
34   * Pool statistics.
35   * <p>
36   * The total number of connections in the pool is equal to {@code available} plus {@code leased}.
37   * </p>
38   *
39   * @since 4.2
40   */
41  @Immutable
42  public class PoolStats implements Serializable {
43  
44      private static final long serialVersionUID = -2807686144795228544L;
45  
46      private final int leased;
47      private final int pending;
48      private final int available;
49      private final int max;
50  
51      public PoolStats(final int leased, final int pending, final int free, final int max) {
52          super();
53          this.leased = leased;
54          this.pending = pending;
55          this.available = free;
56          this.max = max;
57      }
58  
59      /**
60       * Gets the number of persistent connections tracked by the connection manager currently being used to execute
61       * requests.
62       * <p>
63       * The total number of connections in the pool is equal to {@code available} plus {@code leased}.
64       * </p>
65       *
66       * @return the number of persistent connections.
67       */
68      public int getLeased() {
69          return this.leased;
70      }
71  
72      /**
73       * Gets the number of connection requests being blocked awaiting a free connection. This can happen only if there
74       * are more worker threads contending for fewer connections.
75       *
76       * @return the number of connection requests being blocked awaiting a free connection.
77       */
78      public int getPending() {
79          return this.pending;
80      }
81  
82      /**
83       * Gets the number idle persistent connections.
84       * <p>
85       * The total number of connections in the pool is equal to {@code available} plus {@code leased}.
86       * </p>
87       *
88       * @return number idle persistent connections.
89       */
90      public int getAvailable() {
91          return this.available;
92      }
93  
94      /**
95       * Gets the maximum number of allowed persistent connections.
96       *
97       * @return the maximum number of allowed persistent connections.
98       */
99      public int getMax() {
100         return this.max;
101     }
102 
103     @Override
104     public String toString() {
105         final StringBuilder buffer = new StringBuilder();
106         buffer.append("[leased: ");
107         buffer.append(this.leased);
108         buffer.append("; pending: ");
109         buffer.append(this.pending);
110         buffer.append("; available: ");
111         buffer.append(this.available);
112         buffer.append("; max: ");
113         buffer.append(this.max);
114         buffer.append("]");
115         return buffer.toString();
116     }
117 
118 }