001/*
002 * Copyright 2014-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2014-2024 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-2024 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.NotNull;
044import com.unboundid.util.ThreadSafety;
045import com.unboundid.util.ThreadSafetyLevel;
046
047
048
049/**
050 * This class provides a data structure that holds information about the result
051 * of an LDAP connection pool health check.
052 */
053@NotMutable()
054@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
055public final class LDAPConnectionPoolHealthCheckResult
056       implements Serializable
057{
058  /**
059   * The serial version UID for this serializable class.
060   */
061  private static final long serialVersionUID = -7312002973891471180L;
062
063
064
065  // The number of connections found to be defunct.
066  private final int numDefunct;
067
068  // The number of connections examined during the health check.
069  private final int numExamined;
070
071  // The number of connections found to be expired.
072  private final int numExpired;
073
074
075
076  /**
077   * Creates a new health check result with the provided information.
078   *
079   * @param  numExamined  The number of connections examined during the health
080   *                      check.
081   * @param  numExpired   The number of connections found to have been
082   *                      established for longer than the pool's maximum
083   *                      connection age and were attempted to be replaced as
084   *                      expired.
085   * @param  numDefunct   The number of connections found to be invalid and were
086   *                      attempted to be replaced as defunct.
087   */
088  LDAPConnectionPoolHealthCheckResult(final int numExamined,
089                                      final int numExpired,
090                                      final int numDefunct)
091  {
092    this.numExamined = numExamined;
093    this.numExpired  = numExpired;
094    this.numDefunct  = numDefunct;
095  }
096
097
098
099  /**
100   * Retrieves the number of connections that were examined during the health
101   * check.
102   *
103   * @return  The number of connections that were examined during the health
104   *          check.
105   */
106  public int getNumExamined()
107  {
108    return numExamined;
109  }
110
111
112
113  /**
114   * Retrieves the number of connections found to have been established for
115   * longer than the pool's maximum connection age and were attempted to be
116   * replaced as expired.
117   *
118   * @return  The number of connections found to have been established for
119   *          longer than the pool's maximum connection age and were attempted
120   *          to be replaced as expired.
121   */
122  public int getNumExpired()
123  {
124    return numExpired;
125  }
126
127
128
129  /**
130   * Retrieves the number of connections found to be invalid (e.g., because they
131   * were no longer established, or because they failed the health check) and
132   * were attempted to be replaced as defunct.
133   *
134   * @return  The number of connections found to be invalid and were attempted
135   *          to be replaced as defunct.
136   */
137  public int getNumDefunct()
138  {
139    return numDefunct;
140  }
141
142
143
144  /**
145   * Retrieves a string representation of this connection pool health check
146   * result.
147   *
148   * @return  A string representation of this connection pool health check
149   *          result.
150   */
151  @Override()
152  @NotNull()
153  public String toString()
154  {
155    final StringBuilder buffer = new StringBuilder();
156    toString(buffer);
157    return buffer.toString();
158  }
159
160
161
162  /**
163   * Appends a string representation of this connection pool health check result
164   * to the provided buffer.
165   *
166   * @param  buffer  The buffer to which the information should be appended.
167   */
168  public void toString(@NotNull final StringBuilder buffer)
169  {
170    buffer.append("LDAPConnectionPoolHealthCheckResult(numExamined=");
171    buffer.append(numExamined);
172    buffer.append(", numExpired=");
173    buffer.append(numExpired);
174    buffer.append(", numDefunct=");
175    buffer.append(numDefunct);
176    buffer.append(')');
177  }
178}