001/*
002 * Copyright 2011-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2011-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) 2011-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.listener;
037
038
039
040import java.io.Serializable;
041import java.util.Collections;
042import java.util.Map;
043import java.util.TreeMap;
044
045import com.unboundid.ldap.sdk.DN;
046import com.unboundid.ldap.sdk.ReadOnlyEntry;
047import com.unboundid.util.NotMutable;
048import com.unboundid.util.ThreadSafety;
049import com.unboundid.util.ThreadSafetyLevel;
050
051
052
053/**
054 * This class provides an opaque data structure which represents a point-in-time
055 * snapshot for an in-memory directory server instance. Note that this snapshot
056 * will reflect only data held in the server (including both user data and any
057 * changelog information, if that is enabled), but will not alter the settings
058 * of the server which are defined through configuration.
059 */
060@NotMutable()
061@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
062public final class InMemoryDirectoryServerSnapshot
063       implements Serializable
064{
065  /**
066   * The serial version UID for this serializable class.
067   */
068  private static final long serialVersionUID = 4691579754615787705L;
069
070
071
072  // The first change number value at the time the snapshot was created.
073  private final long firstChangeNumber;
074
075  // The last change number value at the time the snapshot was created.
076  private final long lastChangeNumber;
077
078  // The set of entries held in the server at the time the snapshot was created.
079  private final Map<DN,ReadOnlyEntry> entryMap;
080
081
082
083  /**
084   * Creates a new in-memory directory server snapshot with the provided
085   * information.
086   *
087   * @param  m                  A map of the entries contained in the server
088   *                            (including changelog entries) at the time the
089   *                            snapshot was created.
090   * @param  firstChangeNumber  The first change number value at the time the
091   *                            snapshot was created.
092   * @param  lastChangeNumber   The last change number value at the time the
093   *                            snapshot was created.
094   */
095  InMemoryDirectoryServerSnapshot(final Map<DN,ReadOnlyEntry> m,
096                                  final long firstChangeNumber,
097                                  final long lastChangeNumber)
098  {
099    this.firstChangeNumber = firstChangeNumber;
100    this.lastChangeNumber  = lastChangeNumber;
101
102    entryMap = Collections.unmodifiableMap(new TreeMap<>(m));
103  }
104
105
106
107  /**
108   * Retrieves an unmodifiable map of all entries defined in the server at the
109   * time the snapshot was created.  This will include user-defined entries as
110   * sell as changelog entries, but it will exclude the root DSE and the schema
111   * subentry (since they are dynamically generated from the configuration).
112   *
113   * @return  An unmodifiable map of all entries defined in the server at the
114   *          time the snapshot was created.
115   */
116  public Map<DN,ReadOnlyEntry> getEntryMap()
117  {
118    return entryMap;
119  }
120
121
122
123  /**
124   * Retrieves the first change number for the server at the time the snapshot
125   * was created.
126   *
127   * @return  The first change number for the server at the time the snapshot
128   *          was created.
129   */
130  public long getFirstChangeNumber()
131  {
132    return firstChangeNumber;
133  }
134
135
136
137  /**
138   * Retrieves the last change number for the server at the time the snapshot
139   * was created.
140   *
141   * @return  The last change number for the server at the time the snapshot
142   *          was created.
143   */
144  public long getLastChangeNumber()
145  {
146    return lastChangeNumber;
147  }
148}