001/* 002 * Copyright 2008-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2008-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) 2008-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.util.Collections; 041import java.util.LinkedHashMap; 042import java.util.List; 043import java.util.Map; 044 045import com.unboundid.ldap.sdk.Entry; 046import com.unboundid.util.NotMutable; 047import com.unboundid.util.NotNull; 048import com.unboundid.util.Nullable; 049import com.unboundid.util.StaticUtils; 050import com.unboundid.util.ThreadSafety; 051import com.unboundid.util.ThreadSafetyLevel; 052 053import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*; 054 055 056 057/** 058 * This class defines a monitor entry that provides general information about a 059 * Directory Server connection handler. 060 * <BR> 061 * <BLOCKQUOTE> 062 * <B>NOTE:</B> This class, and other classes within the 063 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 064 * supported for use against Ping Identity, UnboundID, and 065 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 066 * for proprietary functionality or for external specifications that are not 067 * considered stable or mature enough to be guaranteed to work in an 068 * interoperable way with other types of LDAP servers. 069 * </BLOCKQUOTE> 070 * <BR> 071 * Information that may be available in a connection handler monitor entry 072 * includes: 073 * <UL> 074 * <LI>The total number of connections that are established.</LI> 075 * <LI>The protocol that the connection handler uses to communicate with 076 * clients.</LI> 077 * <LI>A list of the listeners (addresses and ports on which the connection 078 * handler is listening for connections.</LI> 079 * <LI>Information about each of the connections established to the connection 080 * handler. The information available for these connections may vary by 081 * connection handler type.</LI> 082 * </UL> 083 * The connection handler monitor entries provided by the server can be 084 * retrieved using the {@link MonitorManager#getConnectionHandlerMonitorEntries} 085 * method. These entries provide specific methods for accessing information 086 * about the connection handler (e.g., the 087 * {@link ConnectionHandlerMonitorEntry#getNumConnections} method can be used 088 * to retrieve the total number of connections established). Alternately, this 089 * information may be accessed using the generic API. See the 090 * {@link MonitorManager} class documentation for an example that demonstrates 091 * the use of the generic API for accessing monitor data. 092 */ 093@NotMutable() 094@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 095public final class ConnectionHandlerMonitorEntry 096 extends MonitorEntry 097{ 098 /** 099 * The structural object class used in connection handler monitor entries. 100 */ 101 @NotNull static final String CONNECTION_HANDLER_MONITOR_OC = 102 "ds-connectionhandler-monitor-entry"; 103 104 105 106 /** 107 * The name of the attribute that contains information about the established 108 * connections. 109 */ 110 @NotNull private static final String ATTR_CONNECTION = 111 "ds-connectionhandler-connection"; 112 113 114 115 /** 116 * The name of the attribute that contains information about the listeners. 117 */ 118 @NotNull private static final String ATTR_LISTENER = 119 "ds-connectionhandler-listener"; 120 121 122 123 /** 124 * The name of the attribute that contains information about the number of 125 * established connections. 126 */ 127 @NotNull private static final String ATTR_NUM_CONNECTIONS = 128 "ds-connectionhandler-num-connections"; 129 130 131 132 /** 133 * The name of the attribute that contains information about the protocol. 134 */ 135 @NotNull private static final String ATTR_PROTOCOL = 136 "ds-connectionhandler-protocol"; 137 138 139 140 /** 141 * The serial version UID for this serializable class. 142 */ 143 private static final long serialVersionUID = -2922139631867367609L; 144 145 146 147 // The list of connections currently established. 148 @NotNull private final List<String> connections; 149 150 // The list of listeners for the connection handler. 151 @NotNull private final List<String> listeners; 152 153 // The number of connections established. 154 @Nullable private final Long numConnections; 155 156 // The protocol used by the connection handler. 157 @Nullable private final String protocol; 158 159 160 161 /** 162 * Creates a new connection handler monitor entry from the provided entry. 163 * 164 * @param entry The entry to be parsed as a connection handler monitor 165 * entry. It must not be {@code null}. 166 */ 167 public ConnectionHandlerMonitorEntry(@NotNull final Entry entry) 168 { 169 super(entry); 170 171 connections = getStrings(ATTR_CONNECTION); 172 listeners = getStrings(ATTR_LISTENER); 173 numConnections = getLong(ATTR_NUM_CONNECTIONS); 174 protocol = getString(ATTR_PROTOCOL); 175 } 176 177 178 179 /** 180 * Retrieves a list of the string representations of the connections 181 * established to the associated connection handler. Values should be 182 * space-delimited name-value pairs with the values surrounded by quotation 183 * marks. 184 * 185 * @return A list of the string representations of the connections 186 * established to the associated connection handler, or an empty list 187 * if it was not included in the monitor entry or there are no 188 * established connections. 189 */ 190 @NotNull() 191 public List<String> getConnections() 192 { 193 return connections; 194 } 195 196 197 198 /** 199 * Retrieves a list of the listeners for the associated connection handler. 200 * 201 * @return A list of the listeners for the associated connection handler, or 202 * an empty list if it was not included in the monitor entry or the 203 * connection handler does not have any listeners. 204 */ 205 @NotNull() 206 public List<String> getListeners() 207 { 208 return listeners; 209 } 210 211 212 213 /** 214 * Retrieves the number of connections currently established to the associated 215 * connection handler. 216 * 217 * @return The number of connections currently established to the associated 218 * connection handler, or {@code null} if it was not included in the 219 * monitor entry. 220 */ 221 @Nullable() 222 public Long getNumConnections() 223 { 224 return numConnections; 225 } 226 227 228 229 /** 230 * Retrieves the protocol for the associated connection handler. 231 * 232 * @return The protocol for the associated connection handler, or 233 * {@code null} if it was not included in the monitor entry. 234 */ 235 @Nullable() 236 public String getProtocol() 237 { 238 return protocol; 239 } 240 241 242 243 /** 244 * {@inheritDoc} 245 */ 246 @Override() 247 @NotNull() 248 public String getMonitorDisplayName() 249 { 250 return INFO_CONNECTION_HANDLER_MONITOR_DISPNAME.get(); 251 } 252 253 254 255 /** 256 * {@inheritDoc} 257 */ 258 @Override() 259 @NotNull() 260 public String getMonitorDescription() 261 { 262 return INFO_CONNECTION_HANDLER_MONITOR_DESC.get(); 263 } 264 265 266 267 /** 268 * {@inheritDoc} 269 */ 270 @Override() 271 @NotNull() 272 public Map<String,MonitorAttribute> getMonitorAttributes() 273 { 274 final LinkedHashMap<String,MonitorAttribute> attrs = 275 new LinkedHashMap<>(StaticUtils.computeMapCapacity(4)); 276 277 if (protocol != null) 278 { 279 addMonitorAttribute(attrs, 280 ATTR_PROTOCOL, 281 INFO_CONNECTION_HANDLER_DISPNAME_PROTOCOL.get(), 282 INFO_CONNECTION_HANDLER_DESC_PROTOCOL.get(), 283 protocol); 284 } 285 286 if (! listeners.isEmpty()) 287 { 288 addMonitorAttribute(attrs, 289 ATTR_LISTENER, 290 INFO_CONNECTION_HANDLER_DISPNAME_LISTENER.get(), 291 INFO_CONNECTION_HANDLER_DESC_LISTENER.get(), 292 listeners); 293 } 294 295 if (numConnections != null) 296 { 297 addMonitorAttribute(attrs, 298 ATTR_NUM_CONNECTIONS, 299 INFO_CONNECTION_HANDLER_DISPNAME_NUM_CONNECTIONS.get(), 300 INFO_CONNECTION_HANDLER_DESC_NUM_CONNECTIONS.get(), 301 numConnections); 302 } 303 304 if (! connections.isEmpty()) 305 { 306 addMonitorAttribute(attrs, 307 ATTR_CONNECTION, 308 INFO_CONNECTION_HANDLER_DISPNAME_CONNECTION.get(), 309 INFO_CONNECTION_HANDLER_DESC_CONNECTION.get(), 310 connections); 311 } 312 313 return Collections.unmodifiableMap(attrs); 314 } 315}