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