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