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