001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2010 Sun Microsystems, Inc.
025 *      Portions Copyright 2013-2014 ForgeRock, AS.
026 *      Portions Copyright 2015 ForgeRock AS.
027 */
028package org.opends.server.replication.plugin;
029
030import java.util.Iterator;
031import java.util.Set;
032
033import org.forgerock.opendj.ldap.ByteString;
034import org.opends.server.replication.common.CSN;
035import org.opends.server.types.AttributeType;
036import org.opends.server.types.Entry;
037import org.opends.server.types.Modification;
038
039/** This class store historical information for a provided attribute. */
040public abstract class AttrHistorical
041{
042  /**
043   * This method will be called when replaying an operation.
044   * It should use whatever historical information is stored in this class
045   * to solve the conflict and modify the mod and the mods iterator accordingly
046   *
047   * @param modsIterator  The iterator on the mods from which the mod is extracted.
048   * @param csn  The CSN associated to the operation.
049   * @param modifiedEntry The entry modified by this operation.
050   * @param mod           The modification.
051   * @return {@code true} if a conflict was detected, {@code false} otherwise.
052   */
053  public abstract boolean replayOperation(
054      Iterator<Modification> modsIterator, CSN csn, Entry modifiedEntry, Modification mod);
055
056  /**
057   * This method calculates the historical information and update the hist
058   * attribute to store the historical information for modify operation that
059   * does not conflict with previous operation.
060   * This is the usual path and should therefore be optimized.
061   * <p>
062   * It does not check if the operation to process is conflicting or not with
063   * previous operations. The caller is responsible for this.
064   *
065   * @param csn The CSN of the operation to process
066   * @param mod The modify operation to process.
067   */
068  public abstract void processLocalOrNonConflictModification(CSN csn, Modification mod);
069
070  /**
071   * Create a new object from a provided attribute type. Historical is empty.
072   *
073   * @param type the provided attribute type.
074   * @return a new AttributeInfo object.
075   */
076  public static AttrHistorical createAttributeHistorical(AttributeType type)
077  {
078    return type.isSingleValue() ? new AttrHistoricalSingle() : new AttrHistoricalMultiple();
079  }
080
081  /**
082   * Get the historical informations for this attribute Info.
083   *
084   * @return the historical informations
085   */
086  public abstract Set<AttrValueHistorical> getValuesHistorical();
087
088  /**
089   * Returns the last time when this attribute was deleted.
090   *
091   * @return the last time when this attribute was deleted
092   */
093  public abstract CSN getDeleteTime();
094
095  /**
096   * Assign the provided information to this object.
097   *
098   * @param histKey the key to assign.
099   * @param value   the associated value or null if there is no value;
100   * @param csn     the associated CSN.
101   */
102  public abstract void assign(HistAttrModificationKey histKey, ByteString value, CSN csn);
103}