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