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.unboundidds.monitors;
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 defines a data structure that provides information about the
051 * availability of an LDAP external server associated with a load-balancing
052 * algorithm.
053 * <BR>
054 * <BLOCKQUOTE>
055 *   <B>NOTE:</B>  This class, and other classes within the
056 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
057 *   supported for use against Ping Identity, UnboundID, and
058 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
059 *   for proprietary functionality or for external specifications that are not
060 *   considered stable or mature enough to be guaranteed to work in an
061 *   interoperable way with other types of LDAP servers.
062 * </BLOCKQUOTE>
063 */
064@NotMutable()
065@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
066public final class LoadBalancingAlgorithmServerAvailabilityData
067       implements Serializable
068{
069  /**
070   * The serial version UID for this serializable class.
071   */
072  private static final long serialVersionUID = -2195372034654700615L;
073
074
075
076  // The health check state for the LDAP external server.
077  @NotNull private final HealthCheckState healthCheckState;
078
079  // The port number for the LDAP external server.
080  private final int serverPort;
081
082  // The address for the LDAP external server.
083  @NotNull private final String serverAddress;
084
085
086
087  /**
088   * Creates a new server availability data object decoded from the provided
089   * string.
090   *
091   * @param  s  The string representation of the
092   */
093  LoadBalancingAlgorithmServerAvailabilityData(@NotNull final String s)
094  {
095    final int firstColonPos = s.indexOf(':');
096    final int secondColonPos = s.indexOf(':', (firstColonPos+1));
097
098    serverAddress = s.substring(0, firstColonPos);
099    serverPort = Integer.parseInt(s.substring(firstColonPos+1, secondColonPos));
100    healthCheckState = HealthCheckState.forName(s.substring(secondColonPos+1));
101  }
102
103
104
105  /**
106   * Retrieves the address for the LDAP external server.
107   *
108   * @return  The address for the LDAP external server.
109   */
110  @NotNull()
111  public String getServerAddress()
112  {
113    return serverAddress;
114  }
115
116
117
118  /**
119   * Retrieves the port number for the LDAP external server.
120   *
121   * @return  The port number for the LDAP external server.
122   */
123  public int getServerPort()
124  {
125    return serverPort;
126  }
127
128
129
130  /**
131   * Retrieves the health check state for the LDAP external server.
132   *
133   * @return  The health check state for the LDAP external server.
134   */
135  @NotNull()
136  public HealthCheckState getHealthCheckState()
137  {
138    return healthCheckState;
139  }
140
141
142
143  /**
144   * Retrieves a string representation of this server availability data object.
145   *
146   * @return  A string representation of this server availability data object.
147   */
148  @Override()
149  @NotNull()
150  public String toString()
151  {
152    final StringBuilder buffer = new StringBuilder();
153    toString(buffer);
154    return buffer.toString();
155  }
156
157
158
159  /**
160   * Appends a string representation of this server availability data object to
161   * the provided buffer.
162   *
163   * @param  buffer  The buffer to which the information should be appended.
164   */
165  public void toString(@NotNull final StringBuilder buffer)
166  {
167    buffer.append("LoadBalancingAlgorithmServerAvailabilityData(address=");
168    buffer.append(serverAddress);
169    buffer.append(", port=");
170    buffer.append(serverPort);
171    buffer.append(", healthCheckState=");
172    buffer.append(healthCheckState.name());
173    buffer.append(')');
174  }
175
176
177
178  /**
179   * Retrieves a compact representation of the server availability data, in the
180   * form in which it appears in the load-balancing algorithm monitor entry.
181   *
182   * @return  A compact representation of the server availability data.
183   */
184  @NotNull()
185  public String toCompactString()
186  {
187    return serverAddress + ':' + serverPort + ':' + healthCheckState.name();
188  }
189}