001/*
002 * Copyright 2014-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2014-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2014-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk;
037
038
039
040import java.io.Serializable;
041
042import com.unboundid.util.NotMutable;
043import com.unboundid.util.ThreadSafety;
044import com.unboundid.util.ThreadSafetyLevel;
045
046
047
048/**
049 * This class provides a data structure that holds information about the result
050 * of an LDAP connection pool health check.
051 */
052@NotMutable()
053@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
054public final class LDAPConnectionPoolHealthCheckResult
055       implements Serializable
056{
057  /**
058   * The serial version UID for this serializable class.
059   */
060  private static final long serialVersionUID = -7312002973891471180L;
061
062
063
064  // The number of connections found to be defunct.
065  private final int numDefunct;
066
067  // The number of connections examined during the health check.
068  private final int numExamined;
069
070  // The number of connections found to be expired.
071  private final int numExpired;
072
073
074
075  /**
076   * Creates a new health check result with the provided information.
077   *
078   * @param  numExamined  The number of connections examined during the health
079   *                      check.
080   * @param  numExpired   The number of connections found to have been
081   *                      established for longer than the pool's maximum
082   *                      connection age and were attempted to be replaced as
083   *                      expired.
084   * @param  numDefunct   The number of connections found to be invalid and were
085   *                      attempted to be replaced as defunct.
086   */
087  LDAPConnectionPoolHealthCheckResult(final int numExamined,
088                                      final int numExpired,
089                                      final int numDefunct)
090  {
091    this.numExamined = numExamined;
092    this.numExpired  = numExpired;
093    this.numDefunct  = numDefunct;
094  }
095
096
097
098  /**
099   * Retrieves the number of connections that were examined during the health
100   * check.
101   *
102   * @return  The number of connections that were examined during the health
103   *          check.
104   */
105  public int getNumExamined()
106  {
107    return numExamined;
108  }
109
110
111
112  /**
113   * Retrieves the number of connections found to have been established for
114   * longer than the pool's maximum connection age and were attempted to be
115   * replaced as expired.
116   *
117   * @return  The number of connections found to have been established for
118   *          longer than the pool's maximum connection age and were attempted
119   *          to be replaced as expired.
120   */
121  public int getNumExpired()
122  {
123    return numExpired;
124  }
125
126
127
128  /**
129   * Retrieves the number of connections found to be invalid (e.g., because they
130   * were no longer established, or because they failed the health check) and
131   * were attempted to be replaced as defunct.
132   *
133   * @return  The number of connections found to be invalid and were attempted
134   *          to be replaced as defunct.
135   */
136  public int getNumDefunct()
137  {
138    return numDefunct;
139  }
140
141
142
143  /**
144   * Retrieves a string representation of this connection pool health check
145   * result.
146   *
147   * @return  A string representation of this connection pool health check
148   *          result.
149   */
150  @Override()
151  public String toString()
152  {
153    final StringBuilder buffer = new StringBuilder();
154    toString(buffer);
155    return buffer.toString();
156  }
157
158
159
160  /**
161   * Appends a string representation of this connection pool health check result
162   * to the provided buffer.
163   *
164   * @param  buffer  The buffer to which the information should be appended.
165   */
166  public void toString(final StringBuilder buffer)
167  {
168    buffer.append("LDAPConnectionPoolHealthCheckResult(numExamined=");
169    buffer.append(numExamined);
170    buffer.append(", numExpired=");
171    buffer.append(numExpired);
172    buffer.append(", numDefunct=");
173    buffer.append(numDefunct);
174    buffer.append(')');
175  }
176}