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 042 * the client connections currently established. Note that the information 043 * available for each client connection may vary based on the type of connection 044 * handler with which that connection is associated. 045 * <BR> 046 * <BLOCKQUOTE> 047 * <B>NOTE:</B> This class, and other classes within the 048 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 049 * supported for use against Ping Identity, UnboundID, and 050 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 051 * for proprietary functionality or for external specifications that are not 052 * considered stable or mature enough to be guaranteed to work in an 053 * interoperable way with other types of LDAP servers. 054 * </BLOCKQUOTE> 055 * <BR> 056 * The server should present at most one client connection monitor entry. It 057 * can be retrieved using the 058 * {@link MonitorManager#getClientConnectionMonitorEntry} method. The 059 * {@link ClientConnectionMonitorEntry#getConnections} method may be used to 060 * retrieve information for each connection. Alternately, this information may 061 * be accessed using the generic API. See the {@link MonitorManager} class 062 * documentation for an example that demonstrates the use of the generic API for 063 * accessing monitor data. 064 */ 065@NotMutable() 066@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 067public final class ClientConnectionMonitorEntry 068 extends MonitorEntry 069{ 070 /** 071 * The structural object class used in client connection monitor entries. 072 */ 073 static final String CLIENT_CONNECTION_MONITOR_OC = 074 "ds-client-connection-monitor-entry"; 075 076 077 078 /** 079 * The name of the attribute that contains information about the established 080 * connections. 081 */ 082 private static final String ATTR_CONNECTION = "connection"; 083 084 085 086 /** 087 * The serial version UID for this serializable class. 088 */ 089 private static final long serialVersionUID = -1705824766273147598L; 090 091 092 093 // The list of connections currently established. 094 private final List<String> connections; 095 096 097 098 /** 099 * Creates a new client connection monitor entry from the provided entry. 100 * 101 * @param entry The entry to be parsed as a client connection monitor entry. 102 * It must not be {@code null}. 103 */ 104 public ClientConnectionMonitorEntry(final Entry entry) 105 { 106 super(entry); 107 108 connections = getStrings(ATTR_CONNECTION); 109 } 110 111 112 113 /** 114 * Retrieves a list of the string representations of the connections 115 * established to the Directory Server. Values should be space-delimited 116 * name-value pairs with the values surrounded by quotation marks. 117 * 118 * @return A list of the string representations of the connections 119 * established to the Directory Server, or an empty list if it was 120 * not included in the monitor entry or there are no established 121 * connections. 122 */ 123 public List<String> getConnections() 124 { 125 return connections; 126 } 127 128 129 130 /** 131 * {@inheritDoc} 132 */ 133 @Override() 134 public String getMonitorDisplayName() 135 { 136 return INFO_CLIENT_CONNECTION_MONITOR_DISPNAME.get(); 137 } 138 139 140 141 /** 142 * {@inheritDoc} 143 */ 144 @Override() 145 public String getMonitorDescription() 146 { 147 return INFO_CLIENT_CONNECTION_MONITOR_DESC.get(); 148 } 149 150 151 152 /** 153 * {@inheritDoc} 154 */ 155 @Override() 156 public Map<String,MonitorAttribute> getMonitorAttributes() 157 { 158 final LinkedHashMap<String,MonitorAttribute> attrs = 159 new LinkedHashMap<>(StaticUtils.computeMapCapacity(1)); 160 161 if (! connections.isEmpty()) 162 { 163 addMonitorAttribute(attrs, 164 ATTR_CONNECTION, 165 INFO_CLIENT_CONNECTION_DISPNAME_CONNECTION.get(), 166 INFO_CLIENT_CONNECTION_DESC_CONNECTION.get(), 167 connections); 168 } 169 170 return Collections.unmodifiableMap(attrs); 171 } 172}