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