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