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