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