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
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.replication.plugin;
028
029 import java.util.ArrayList;
030 import java.util.Iterator;
031
032 import org.opends.server.replication.common.ChangeNumber;
033 import org.opends.server.types.AttributeType;
034 import org.opends.server.types.AttributeValue;
035 import org.opends.server.types.Entry;
036 import org.opends.server.types.Modification;
037
038
039 /**
040 * This classes is used to store historical information.
041 * One object of this type is created for each attribute that was changed in
042 * the entry.
043 */
044 public abstract class AttributeInfo
045 {
046 /**
047 * This method will be called when replaying an operation.
048 * It should use whatever historical information is stored in this class
049 * to solve the conflict and modify the mod and the mods iterator accordingly
050 *
051 * @param modsIterator The iterator on the mods from which the mod is\
052 * extracted.
053 * @param changeNumber The changeNumber associated to the operation.
054 * @param modifiedEntry The entry modified by this operation.
055 * @param mod The modification.
056 *
057 * @return a boolean indicating if a conflict was detected.
058 */
059 public abstract boolean replayOperation(
060 Iterator<Modification> modsIterator, ChangeNumber changeNumber,
061 Entry modifiedEntry, Modification mod);
062
063 /**
064 * This method calculate the historical information and update the hist
065 * attribute to store the historical information for modify operation that
066 * does not conflict with previous operation.
067 * This is the usual path and should therefore be optimized.
068 *
069 * It does not check if the operation to process is conflicting or not with
070 * previous operations. The caller is responsible for this.
071 *
072 * @param changeNumber The changeNumber of the operation to process
073 * @param mod The modify operation to process.
074 */
075 public abstract void processLocalOrNonConflictModification(
076 ChangeNumber changeNumber, Modification mod);
077
078 /**
079 * Create a new AttributeInfo object that will be used with the givene type.
080 *
081 * @param type the AttrbuteType with which the ATtributeInfo is going to be
082 * used.
083 * @return a new AttributeInfo object.
084 */
085 public static AttributeInfo createAttributeInfo(AttributeType type)
086 {
087 if (type.isSingleValue())
088 return new AttrInfoSingle();
089 else
090 return new AttrInfoMultiple();
091 }
092
093 /**
094 * Get the List of ValueInfo for this attribute Info.
095 *
096 * @return the List of ValueInfo
097 */
098 public abstract ArrayList<ValueInfo> getValuesInfo();
099
100
101 /**
102 * Returns the last time when the attribute was deleted.
103 *
104 * @return the last time when the attribute was deleted
105 */
106 public abstract ChangeNumber getDeleteTime();
107
108 /**
109 * Load the provided information.
110 *
111 * @param histKey the key to load.
112 * @param value the associated value or null if there is no value;
113 * @param cn the associated ChangeNumber.
114 */
115 public abstract void load(
116 HistKey histKey, AttributeValue value, ChangeNumber cn);
117
118 }
119