001 /*
002 * Copyright 2008-2015 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2015 UnboundID Corp.
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 */
021 package com.unboundid.ldap.sdk.unboundidds.monitors;
022
023
024
025 import java.util.Collections;
026 import java.util.LinkedHashMap;
027 import java.util.List;
028 import java.util.Map;
029
030 import com.unboundid.ldap.sdk.Entry;
031 import com.unboundid.util.NotMutable;
032 import com.unboundid.util.ThreadSafety;
033 import com.unboundid.util.ThreadSafetyLevel;
034
035 import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*;
036
037
038
039 /**
040 * <BLOCKQUOTE>
041 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID
042 * LDAP SDK for Java. It is not available for use in applications that
043 * include only the Standard Edition of the LDAP SDK, and is not supported for
044 * use in conjunction with non-UnboundID products.
045 * </BLOCKQUOTE>
046 * This class defines a monitor entry that provides general information about
047 * the client connections currently established. Note that the information
048 * available for each client connection may vary based on the type of connection
049 * handler with which that connection is associated.
050 * <BR><BR>
051 * The server should present at most one client connection monitor entry. It
052 * can be retrieved using the
053 * {@link MonitorManager#getClientConnectionMonitorEntry} method. The
054 * {@link ClientConnectionMonitorEntry#getConnections} method may be used to
055 * retrieve information for each connection. Alternately, this information may
056 * be accessed using the generic API. See the {@link MonitorManager} class
057 * documentation for an example that demonstrates the use of the generic API for
058 * accessing monitor data.
059 */
060 @NotMutable()
061 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
062 public final class ClientConnectionMonitorEntry
063 extends MonitorEntry
064 {
065 /**
066 * The structural object class used in client connection monitor entries.
067 */
068 static final String CLIENT_CONNECTION_MONITOR_OC =
069 "ds-client-connection-monitor-entry";
070
071
072
073 /**
074 * The name of the attribute that contains information about the established
075 * connections.
076 */
077 private static final String ATTR_CONNECTION = "connection";
078
079
080
081 /**
082 * The serial version UID for this serializable class.
083 */
084 private static final long serialVersionUID = -1705824766273147598L;
085
086
087
088 // The list of connections currently established.
089 private final List<String> connections;
090
091
092
093 /**
094 * Creates a new client connection monitor entry from the provided entry.
095 *
096 * @param entry The entry to be parsed as a client connection monitor entry.
097 * It must not be {@code null}.
098 */
099 public ClientConnectionMonitorEntry(final Entry entry)
100 {
101 super(entry);
102
103 connections = getStrings(ATTR_CONNECTION);
104 }
105
106
107
108 /**
109 * Retrieves a list of the string representations of the connections
110 * established to the Directory Server. Values should be space-delimited
111 * name-value pairs with the values surrounded by quotation marks.
112 *
113 * @return A list of the string representations of the connections
114 * established to the Directory Server, or an empty list if it was
115 * not included in the monitor entry or there are no established
116 * connections.
117 */
118 public List<String> getConnections()
119 {
120 return connections;
121 }
122
123
124
125 /**
126 * {@inheritDoc}
127 */
128 @Override()
129 public String getMonitorDisplayName()
130 {
131 return INFO_CLIENT_CONNECTION_MONITOR_DISPNAME.get();
132 }
133
134
135
136 /**
137 * {@inheritDoc}
138 */
139 @Override()
140 public String getMonitorDescription()
141 {
142 return INFO_CLIENT_CONNECTION_MONITOR_DESC.get();
143 }
144
145
146
147 /**
148 * {@inheritDoc}
149 */
150 @Override()
151 public Map<String,MonitorAttribute> getMonitorAttributes()
152 {
153 final LinkedHashMap<String,MonitorAttribute> attrs =
154 new LinkedHashMap<String,MonitorAttribute>();
155
156 if (! connections.isEmpty())
157 {
158 addMonitorAttribute(attrs,
159 ATTR_CONNECTION,
160 INFO_CLIENT_CONNECTION_DISPNAME_CONNECTION.get(),
161 INFO_CLIENT_CONNECTION_DESC_CONNECTION.get(),
162 connections);
163 }
164
165 return Collections.unmodifiableMap(attrs);
166 }
167 }