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