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