001/*
002 * Copyright 2009-2017 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2017 Ping Identity Corporation
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 */
021package com.unboundid.ldap.sdk.unboundidds.monitors;
022
023
024
025import com.unboundid.util.StaticUtils;
026import com.unboundid.util.ThreadSafety;
027import com.unboundid.util.ThreadSafetyLevel;
028
029
030
031/**
032 * This class provides information about the health check states that may be
033 * held by an LDAP external server.
034 * <BR>
035 * <BLOCKQUOTE>
036 *   <B>NOTE:</B>  This class, and other classes within the
037 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
038 *   supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661
039 *   server products.  These classes provide support for proprietary
040 *   functionality or for external specifications that are not considered stable
041 *   or mature enough to be guaranteed to work in an interoperable way with
042 *   other types of LDAP servers.
043 * </BLOCKQUOTE>
044 */
045@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
046public enum HealthCheckState
047{
048  /**
049   * The health check state that indicates that the associated LDAP external
050   * server is available.
051   */
052  AVAILABLE("available"),
053
054
055
056  /**
057   * The health check state that indicates that the associated LDAP external
058   * server is in a degraded state.
059   */
060  DEGRADED("degraded"),
061
062
063
064  /**
065   * The health check state that indicates that the associated LDAP external
066   * server is unavailable.
067   */
068  UNAVAILABLE("unavailable"),
069
070
071
072  /**
073   * The health check state that indicates that there are no local servers
074   * defined, and therefore no health information is available for local
075   * servers.
076   */
077  NO_LOCAL_SERVERS("no-local-servers"),
078
079
080
081  /**
082   * The health check state that indicates that there are no local servers
083   * defined, and therefore no health information is available for remote
084   * servers.
085   */
086  NO_REMOTE_SERVERS("no-remote-servers");
087
088
089
090  // The name for this health check state.
091  private final String name;
092
093
094
095  /**
096   * Creates a new health check state with the specified name.
097   *
098   * @param  name  The name for this health check state.
099   */
100  HealthCheckState(final String name)
101  {
102    this.name = name;
103  }
104
105
106
107  /**
108   * Retrieves the name for this health check state.
109   *
110   * @return  The name for this health check state.
111   */
112  public String getName()
113  {
114    return name;
115  }
116
117
118
119  /**
120   * Retrieves the health check state with the specified name.
121   *
122   * @param  name  The name of the health check state to retrieve.
123   *
124   * @return  The health check state with the specified name, or {@code null} if
125   *          there is no health check state with the given name.
126   */
127  public static HealthCheckState forName(final String name)
128  {
129    final String lowerName = StaticUtils.toLowerCase(name);
130
131    if (lowerName.equals("available"))
132    {
133      return AVAILABLE;
134    }
135    else if (lowerName.equals("degraded"))
136    {
137      return DEGRADED;
138    }
139    else if (lowerName.equals("unavailable"))
140    {
141      return UNAVAILABLE;
142    }
143    else if (lowerName.equals("no-local-servers") ||
144             lowerName.equals("no_local_servers"))
145    {
146      return NO_LOCAL_SERVERS;
147    }
148    else if (lowerName.equals("no-remote-servers") ||
149             lowerName.equals("no_remote_servers"))
150    {
151      return NO_REMOTE_SERVERS;
152    }
153    else
154    {
155      return null;
156    }
157  }
158
159
160
161  /**
162   * Retrieves a string representation of this health check state.
163   *
164   * @return  A string representation of this health check state.
165   */
166  @Override()
167  public String toString()
168  {
169    return name;
170  }
171}