001/* 002 * Copyright 2009-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.ArrayList; 026import java.util.Collections; 027import java.util.LinkedHashMap; 028import java.util.List; 029import java.util.Map; 030 031import com.unboundid.ldap.sdk.Entry; 032import com.unboundid.util.NotMutable; 033import com.unboundid.util.ThreadSafety; 034import com.unboundid.util.ThreadSafetyLevel; 035 036import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*; 037 038 039 040/** 041 * This class defines a monitor entry that provides summary information about 042 * a replicated data set within the Directory Server. 043 * <BR> 044 * <BLOCKQUOTE> 045 * <B>NOTE:</B> This class, and other classes within the 046 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 047 * supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661 048 * server products. These classes provide support for proprietary 049 * functionality or for external specifications that are not considered stable 050 * or mature enough to be guaranteed to work in an interoperable way with 051 * other types of LDAP servers. 052 * </BLOCKQUOTE> 053 * <BR> 054 * The server will present a replication summary monitor entry for each base DN 055 * for which replication is enabled, and it will include information about each 056 * replica and replication server processing changes for that base DN. 057 * Replication summary monitor entries can be retrieved using the 058 * {@link MonitorManager#getReplicationSummaryMonitorEntries} method. The 059 * {@link #getBaseDN} method may be used to retrieve information about the 060 * replicated base DN, the {@link #getReplicationServers} method may be used to 061 * retrieve information about the replication servers for that base DN, and the 062 * {@link #getReplicas} method may be used to retrieve information about the 063 * replicas for that base DN. Alternately, this information may be accessed 064 * using the generic API. See the {@link MonitorManager} class documentation 065 * for an example that demonstrates the use of the generic API for accessing 066 * monitor data. 067 */ 068@NotMutable() 069@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 070public final class ReplicationSummaryMonitorEntry 071 extends MonitorEntry 072{ 073 /** 074 * The structural object class used in replication summary monitor entries. 075 */ 076 static final String REPLICATION_SUMMARY_MONITOR_OC = 077 "ds-replication-server-summary-monitor-entry"; 078 079 080 081 /** 082 * The name of the attribute that contains the base DN for the replicated 083 * data. 084 */ 085 private static final String ATTR_BASE_DN = "base-dn"; 086 087 088 089 /** 090 * The name of the attribute that contains information about the replication 091 * servers for the replicated data. 092 */ 093 private static final String ATTR_REPLICATION_SERVER = "replication-server"; 094 095 096 097 /** 098 * The name of the attribute that contains information about the replicas 099 * for the replicated data. 100 */ 101 private static final String ATTR_REPLICA = "replica"; 102 103 104 105 /** 106 * The serial version UID for this serializable class. 107 */ 108 private static final long serialVersionUID = 3144471025744197014L; 109 110 111 112 // The base DN for the replicated data. 113 private final String baseDN; 114 115 // The list of replicas for the replicated data. 116 private final List<ReplicationSummaryReplica> replicas; 117 118 // The list of replication servers for the replicated data. 119 private final List<ReplicationSummaryReplicationServer> replicationServers; 120 121 122 123 /** 124 * Creates a new replication summary monitor entry from the provided entry. 125 * 126 * @param entry The entry to be parsed as a replication summary monitor 127 * entry. It must not be {@code null}. 128 */ 129 public ReplicationSummaryMonitorEntry(final Entry entry) 130 { 131 super(entry); 132 133 baseDN = getString(ATTR_BASE_DN); 134 135 final List<String> replicaStrings = getStrings(ATTR_REPLICA); 136 final ArrayList<ReplicationSummaryReplica> replList = 137 new ArrayList<ReplicationSummaryReplica>(replicaStrings.size()); 138 for (final String s : replicaStrings) 139 { 140 replList.add(new ReplicationSummaryReplica(s)); 141 } 142 replicas = Collections.unmodifiableList(replList); 143 144 final List<String> serverStrings = getStrings(ATTR_REPLICATION_SERVER); 145 final ArrayList<ReplicationSummaryReplicationServer> serverList = 146 new ArrayList<ReplicationSummaryReplicationServer>( 147 serverStrings.size()); 148 for (final String s : serverStrings) 149 { 150 serverList.add(new ReplicationSummaryReplicationServer(s)); 151 } 152 replicationServers = Collections.unmodifiableList(serverList); 153 } 154 155 156 157 /** 158 * Retrieves the base DN for this replication summary monitor entry. 159 * 160 * @return The base DN for this replication summary monitor entry, or 161 * {@code null} if it was not included in the monitor entry. 162 */ 163 public String getBaseDN() 164 { 165 return baseDN; 166 } 167 168 169 170 /** 171 * Retrieves a list of information about the replicas described in this 172 * replication server summary monitor entry. 173 * 174 * @return A list of information about the replicas described in this 175 * replication server summary monitor entry, or an empty list if it 176 * was not included in the monitor entry. 177 */ 178 public List<ReplicationSummaryReplica> getReplicas() 179 { 180 return replicas; 181 } 182 183 184 185 /** 186 * Retrieves a list of information about the replication servers described in 187 * this replication server summary monitor entry. 188 * 189 * @return A list of information about the replication servers described in 190 * this replication server summary monitor entry, or an empty list if 191 * it was not included in the monitor entry. 192 */ 193 public List<ReplicationSummaryReplicationServer> getReplicationServers() 194 { 195 return replicationServers; 196 } 197 198 199 200 /** 201 * {@inheritDoc} 202 */ 203 @Override() 204 public String getMonitorDisplayName() 205 { 206 return INFO_REPLICATION_SUMMARY_MONITOR_DISPNAME.get(); 207 } 208 209 210 211 /** 212 * {@inheritDoc} 213 */ 214 @Override() 215 public String getMonitorDescription() 216 { 217 return INFO_REPLICATION_SUMMARY_MONITOR_DESC.get(); 218 } 219 220 221 222 /** 223 * {@inheritDoc} 224 */ 225 @Override() 226 public Map<String,MonitorAttribute> getMonitorAttributes() 227 { 228 final LinkedHashMap<String,MonitorAttribute> attrs = 229 new LinkedHashMap<String,MonitorAttribute>(); 230 231 if (baseDN != null) 232 { 233 addMonitorAttribute(attrs, 234 ATTR_BASE_DN, 235 INFO_REPLICATION_SUMMARY_DISPNAME_BASE_DN.get(), 236 INFO_REPLICATION_SUMMARY_DESC_BASE_DN.get(), 237 baseDN); 238 } 239 240 if (! replicas.isEmpty()) 241 { 242 final ArrayList<String> replStrings = 243 new ArrayList<String>(replicas.size()); 244 for (final ReplicationSummaryReplica r : replicas) 245 { 246 replStrings.add(r.toString()); 247 } 248 249 addMonitorAttribute(attrs, 250 ATTR_REPLICA, 251 INFO_REPLICATION_SUMMARY_DISPNAME_REPLICA.get(), 252 INFO_REPLICATION_SUMMARY_DESC_REPLICA.get(), 253 replStrings); 254 } 255 256 if (! replicationServers.isEmpty()) 257 { 258 final ArrayList<String> serverStrings = 259 new ArrayList<String>(replicationServers.size()); 260 for (final ReplicationSummaryReplicationServer s : replicationServers) 261 { 262 serverStrings.add(s.toString()); 263 } 264 265 addMonitorAttribute(attrs, 266 ATTR_REPLICATION_SERVER, 267 INFO_REPLICATION_SUMMARY_DISPNAME_REPLICATION_SERVER.get(), 268 INFO_REPLICATION_SUMMARY_DESC_REPLICATION_SERVER.get(), 269 serverStrings); 270 } 271 272 return Collections.unmodifiableMap(attrs); 273 } 274}