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