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