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