001/* 002 * Copyright 2008-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2008-2020 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) 2015-2020 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.StaticUtils; 048import com.unboundid.util.ThreadSafety; 049import com.unboundid.util.ThreadSafetyLevel; 050 051import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*; 052 053 054 055/** 056 * This class defines a monitor entry that provides general information about 057 * the client connections currently established. Note that the information 058 * available for each client connection may vary based on the type of connection 059 * handler with which that connection is associated. 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 * The server should present at most one client connection monitor entry. It 072 * can be retrieved using the 073 * {@link MonitorManager#getClientConnectionMonitorEntry} method. The 074 * {@link ClientConnectionMonitorEntry#getConnections} method may be used to 075 * retrieve information for each connection. Alternately, this information may 076 * be accessed using the generic API. See the {@link MonitorManager} class 077 * documentation for an example that demonstrates the use of the generic API for 078 * accessing monitor data. 079 */ 080@NotMutable() 081@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 082public final class ClientConnectionMonitorEntry 083 extends MonitorEntry 084{ 085 /** 086 * The structural object class used in client connection monitor entries. 087 */ 088 static final String CLIENT_CONNECTION_MONITOR_OC = 089 "ds-client-connection-monitor-entry"; 090 091 092 093 /** 094 * The name of the attribute that contains information about the established 095 * connections. 096 */ 097 private static final String ATTR_CONNECTION = "connection"; 098 099 100 101 /** 102 * The serial version UID for this serializable class. 103 */ 104 private static final long serialVersionUID = -1705824766273147598L; 105 106 107 108 // The list of connections currently established. 109 private final List<String> connections; 110 111 112 113 /** 114 * Creates a new client connection monitor entry from the provided entry. 115 * 116 * @param entry The entry to be parsed as a client connection monitor entry. 117 * It must not be {@code null}. 118 */ 119 public ClientConnectionMonitorEntry(final Entry entry) 120 { 121 super(entry); 122 123 connections = getStrings(ATTR_CONNECTION); 124 } 125 126 127 128 /** 129 * Retrieves a list of the string representations of the connections 130 * established to the Directory Server. Values should be space-delimited 131 * name-value pairs with the values surrounded by quotation marks. 132 * 133 * @return A list of the string representations of the connections 134 * established to the Directory Server, or an empty list if it was 135 * not included in the monitor entry or there are no established 136 * connections. 137 */ 138 public List<String> getConnections() 139 { 140 return connections; 141 } 142 143 144 145 /** 146 * {@inheritDoc} 147 */ 148 @Override() 149 public String getMonitorDisplayName() 150 { 151 return INFO_CLIENT_CONNECTION_MONITOR_DISPNAME.get(); 152 } 153 154 155 156 /** 157 * {@inheritDoc} 158 */ 159 @Override() 160 public String getMonitorDescription() 161 { 162 return INFO_CLIENT_CONNECTION_MONITOR_DESC.get(); 163 } 164 165 166 167 /** 168 * {@inheritDoc} 169 */ 170 @Override() 171 public Map<String,MonitorAttribute> getMonitorAttributes() 172 { 173 final LinkedHashMap<String,MonitorAttribute> attrs = 174 new LinkedHashMap<>(StaticUtils.computeMapCapacity(1)); 175 176 if (! connections.isEmpty()) 177 { 178 addMonitorAttribute(attrs, 179 ATTR_CONNECTION, 180 INFO_CLIENT_CONNECTION_DISPNAME_CONNECTION.get(), 181 INFO_CLIENT_CONNECTION_DESC_CONNECTION.get(), 182 connections); 183 } 184 185 return Collections.unmodifiableMap(attrs); 186 } 187}