use of com.unboundid.ldap.sdk.ChangeLogEntry in project ldapsdk by pingidentity.
the class InMemoryRequestHandler method addChangeLogEntry.
/**
* Adds the provided changelog entry to the data set, removing an old entry if
* necessary to remain within the maximum allowed number of changes. This
* must only be called from a synchronized method, and the change number for
* the changelog entry must have been obtained by calling
* {@code lastChangeNumber.incrementAndGet()}.
*
* @param e The changelog entry to add to the data set.
* @param authzDN The authorization DN for the change.
*/
private void addChangeLogEntry(@NotNull final ChangeLogEntry e, @NotNull final DN authzDN) {
// Construct the DN object to use for the entry and put it in the map.
final long changeNumber = e.getChangeNumber();
final Schema schema = schemaRef.get();
final DN dn = new DN(new RDN("changeNumber", String.valueOf(changeNumber), schema), changeLogBaseDN);
final Entry entry = e.duplicate();
if (generateOperationalAttributes) {
final Date d = new Date();
entry.addAttribute(new Attribute("entryDN", DistinguishedNameMatchingRule.getInstance(), dn.toNormalizedString()));
entry.addAttribute(new Attribute("entryUUID", CryptoHelper.getRandomUUID().toString()));
entry.addAttribute(new Attribute("subschemaSubentry", DistinguishedNameMatchingRule.getInstance(), subschemaSubentryDN.toString()));
entry.addAttribute(new Attribute("creatorsName", DistinguishedNameMatchingRule.getInstance(), authzDN.toString()));
entry.addAttribute(new Attribute("createTimestamp", GeneralizedTimeMatchingRule.getInstance(), StaticUtils.encodeGeneralizedTime(d)));
entry.addAttribute(new Attribute("modifiersName", DistinguishedNameMatchingRule.getInstance(), authzDN.toString()));
entry.addAttribute(new Attribute("modifyTimestamp", GeneralizedTimeMatchingRule.getInstance(), StaticUtils.encodeGeneralizedTime(d)));
}
entryMap.put(dn, new ReadOnlyEntry(entry));
indexAdd(entry);
// Update the first change number and/or trim the changelog if necessary.
final long firstNumber = firstChangeNumber.get();
if (changeNumber == 1L) {
// It's the first change, so we need to set the first change number.
firstChangeNumber.set(1);
} else {
// See if we need to trim an entry.
final long numChangeLogEntries = changeNumber - firstNumber + 1;
if (numChangeLogEntries > maxChangelogEntries) {
// We need to delete the first changelog entry and increment the
// first change number.
firstChangeNumber.incrementAndGet();
final Entry deletedEntry = entryMap.remove(new DN(new RDN("changeNumber", String.valueOf(firstNumber), schema), changeLogBaseDN));
indexDelete(deletedEntry);
}
}
}
Aggregations