From e07cdcbd253fd366c5002f7368470e0158bfcc2c Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Mon, 13 Nov 2006 08:31:12 +0000
Subject: [PATCH] Fix for 982 : reorganize synchronization code :

---
 opends/src/server/org/opends/server/synchronization/changelog/ChangelogAckMessageList.java                       |    4 
 opends/src/server/org/opends/server/synchronization/common/ChangeNumberGenerator.java                            |    2 
 opends/src/server/org/opends/server/synchronization/plugin/AttrInfoWithOptions.java                              |    3 
 opends/src/server/org/opends/server/synchronization/protocol/WindowMessage.java                                  |   10 
 opends/src/server/org/opends/server/synchronization/plugin/ModifyFakeOperation.java                              |    5 
 opends/src/server/org/opends/server/synchronization/protocol/DeleteContext.java                                  |    4 
 opends/src/server/org/opends/server/synchronization/package-info.java                                            |   41 -
 opends/src/server/org/opends/server/synchronization/plugin/package-info.java                                     |   50 +
 opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ChangeNumberTest.java         |    5 
 opends/src/server/org/opends/server/synchronization/plugin/HistVal.java                                          |    3 
 opends/src/server/org/opends/server/synchronization/changelog/UpdateComparator.java                              |    7 
 opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java             |   11 
 opends/src/server/org/opends/server/synchronization/common/package-info.java                                     |   34 
 opends/src/server/org/opends/server/synchronization/plugin/SynchronizationMonitor.java                           |    2 
 opends/src/server/org/opends/server/synchronization/plugin/FakeOperation.java                                    |    4 
 opends/src/server/org/opends/server/synchronization/changelog/MsgQueue.java                                      |    6 
 opends/src/server/org/opends/server/synchronization/protocol/UpdateMessage.java                                  |   12 
 opends/src/server/org/opends/server/synchronization/plugin/HistKey.java                                          |    2 
 opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java                            |   35 
 opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SynchronizationMsgTest.java |   23 
 opends/src/server/org/opends/server/synchronization/protocol/AddMsg.java                                         |    5 
 opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java                      |    7 
 opends/src/server/org/opends/server/synchronization/changelog/Changelog.java                                     |    5 
 opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java                          |    2 
 opends/src/server/org/opends/server/synchronization/changelog/ChangelogIterator.java                             |    8 
 opends/src/server/org/opends/server/synchronization/changelog/ChangelogData.java                                 |    7 
 opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/ProtocolWindowTest.java     |   10 
 opends/src/server/org/opends/server/synchronization/changelog/ChangelogDbEnv.java                                |    4 
 opends/src/server/org/opends/server/synchronization/changelog/ChangelogIteratorComparator.java                   |    4 
 opends/src/server/org/opends/server/synchronization/protocol/OperationContext.java                               |    3 
 opends/src/server/org/opends/server/synchronization/changelog/DbHandler.java                                     |   10 
 opends/src/server/org/opends/server/synchronization/plugin/AttrInfo.java                                         |    4 
 opends/src/server/org/opends/server/synchronization/plugin/ChangelogBroker.java                                  |   15 
 opends/src/server/org/opends/server/synchronization/common/ServerState.java                                      |  284 +++++++++
 opends/src/server/org/opends/server/synchronization/changelog/AckMessageListComparator.java                      |    2 
 opends/src/server/org/opends/server/synchronization/plugin/MultimasterSynchronization.java                       |   14 
 opends/src/server/org/opends/server/synchronization/protocol/SocketSession.java                                  |    4 
 opends/src/server/org/opends/server/synchronization/plugin/ListenerThread.java                                   |    5 
 opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/AttrInfoTest.java             |    6 
 opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ServerStateTest.java          |   16 
 opends/src/server/org/opends/server/synchronization/common/ChangeNumber.java                                     |    2 
 opends/src/server/org/opends/server/synchronization/plugin/PendingChange.java                                    |    4 
 opends/src/server/org/opends/server/synchronization/changelog/ChangelogDB.java                                   |    8 
 opends/src/server/org/opends/server/synchronization/protocol/AckMessage.java                                     |   19 
 opends/src/server/org/opends/server/synchronization/protocol/ChangelogStartMessage.java                          |   13 
 opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SyncMessagesTest.java       |   10 
 opends/src/server/org/opends/server/synchronization/changelog/ServerWriter.java                                  |    7 
 opends/src/server/org/opends/server/synchronization/plugin/ValueInfo.java                                        |    3 
 opends/src/server/org/opends/server/synchronization/protocol/ProtocolSession.java                                |    4 
 opends/src/server/org/opends/server/synchronization/common/LogMessages.java                                      |    6 
 opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java                            |  309 ++++++++++
 opends/src/server/org/opends/server/synchronization/changelog/ServerReader.java                                  |   13 
 opends/src/server/org/opends/server/synchronization/changelog/ChangelogCache.java                                |   14 
 opends/src/server/org/opends/server/synchronization/protocol/ModifyDNMsg.java                                    |    5 
 opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ValueInfoTest.java            |    5 
 opends/src/server/org/opends/server/synchronization/protocol/SynchronizationMessage.java                         |   13 
 opends/src/server/org/opends/server/synchronization/protocol/DeleteMsg.java                                      |    5 
 opends/src/server/org/opends/server/synchronization/protocol/ModifyContext.java                                  |    4 
 opends/src/server/org/opends/server/synchronization/protocol/AddContext.java                                     |    4 
 opends/src/server/org/opends/server/synchronization/protocol/ServerStartMessage.java                             |   15 
 opends/tests/unit-tests-testng/src/server/org/opends/server/changelog/UpdateComparatorTest.java                  |   11 
 opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ModifyConflictTest.java       |   12 
 opends/src/server/org/opends/server/synchronization/protocol/ModifyDnContext.java                                |    4 
 opends/src/server/org/opends/server/synchronization/changelog/AckMessageList.java                                |    4 
 opends/src/server/org/opends/server/synchronization/plugin/Historical.java                                       |   17 
 opends/src/server/org/opends/server/synchronization/changelog/ChangelogKey.java                                  |    5 
 opends/src/server/org/opends/server/synchronization/plugin/HistoricalCsnOrderingMatchingRule.java                |    2 
 opends/src/server/org/opends/server/synchronization/changelog/package-info.java                                  |    2 
 /dev/null                                                                                                        |  519 -----------------
 opends/src/server/org/opends/server/synchronization/protocol/ModifyMsg.java                                      |    6 
 opends/src/server/org/opends/server/synchronization/plugin/FakeOperationComparator.java                          |    3 
 opends/src/server/org/opends/server/synchronization/protocol/package-info.java                                   |   51 +
 opends/src/server/org/opends/server/synchronization/changelog/ServerHandler.java                                 |   21 
 73 files changed, 1,003 insertions(+), 795 deletions(-)

diff --git a/opends/src/server/org/opends/server/changelog/SerializingProtocolSession.java b/opends/src/server/org/opends/server/changelog/SerializingProtocolSession.java
deleted file mode 100644
index c2b0a5c..0000000
--- a/opends/src/server/org/opends/server/changelog/SerializingProtocolSession.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- *      Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- *      Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.changelog;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.Socket;
-import java.net.SocketException;
-
-import org.opends.server.synchronization.SynchronizationMessage;
-
-/**
- * This class use serialization to implement the ProtocolSession interface.
- * It was done to speed up the development of the sycnhronization feature
- * because it delegate most of its job to the object serialization but
- * will be replaced by a more appropriate mechanism.
- */
-public class SerializingProtocolSession implements ProtocolSession
-{
-  Socket socket;
-  ObjectOutputStream socketOutput = null;
-  ObjectInputStream socketInput = null;
-  private int count = 0;
-
-  /**
-   * Creates a new SerializingProtocolSession based on the provided
-   * socket.
-   * @param socket The socket that will be used to create the
-   *               SerializingProtocolSession
-   * @throws IOException When an IO error happen using the provided socket.
-   */
-  public SerializingProtocolSession(Socket socket) throws IOException
-  {
-    this.socket = socket;
-    socketOutput = new ObjectOutputStream(socket.getOutputStream());
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public void close() throws IOException
-  {
-    socket.close();
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public synchronized void publish(SynchronizationMessage msg)
-            throws IOException, SocketException
-  {
-    socketOutput.writeObject(msg);
-    socketOutput.flush();
-    /*
-     * ObjectOutputStream class keep a cache of objects that have already
-     * been sent across this stream. This improve performances by avoiding
-     * sending several times the same object but unfortunately can cause
-     * memory growth and in our case severe performance degradations.
-     * We therefore free those resources by reseting the cache
-     * every so often
-     */
-    if (count++ >= 5000)
-    {
-      socketOutput.reset();
-      count = 0;
-    }
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public SynchronizationMessage receive()
-            throws IOException, ClassNotFoundException
-  {
-    if (socketInput == null)
-    {
-      socketInput = new ObjectInputStream(socket.getInputStream());
-    }
-    return (SynchronizationMessage) socketInput.readObject();
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public String getRemoteAddress()
-  {
-    return socket.getInetAddress().getHostAddress();
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public void setSoTimeout(int timeout) throws SocketException
-  {
-    socket.setSoTimeout(timeout);
-  }
-}
diff --git a/opends/src/server/org/opends/server/synchronization/ServerState.java b/opends/src/server/org/opends/server/synchronization/ServerState.java
deleted file mode 100644
index 59560b3..0000000
--- a/opends/src/server/org/opends/server/synchronization/ServerState.java
+++ /dev/null
@@ -1,519 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying * information:
- *      Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- *      Portions Copyright 2006 Sun Microsystems, Inc.
- */
-package org.opends.server.synchronization;
-
-import static org.opends.server.loggers.Error.logError;
-import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.zip.DataFormatException;
-
-import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
-
-import org.opends.server.core.AddOperation;
-import org.opends.server.types.Control;
-import org.opends.server.types.DN;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.core.ModifyOperation;
-import org.opends.server.protocols.asn1.ASN1OctetString;
-import org.opends.server.protocols.internal.InternalClientConnection;
-import org.opends.server.protocols.internal.InternalSearchOperation;
-import org.opends.server.protocols.ldap.LDAPAttribute;
-import org.opends.server.protocols.ldap.LDAPException;
-import org.opends.server.protocols.ldap.LDAPFilter;
-import org.opends.server.protocols.ldap.LDAPModification;
-import org.opends.server.types.Attribute;
-import org.opends.server.types.AttributeType;
-import org.opends.server.types.AttributeValue;
-import org.opends.server.types.DereferencePolicy;
-import org.opends.server.types.DirectoryException;
-import org.opends.server.types.ErrorLogCategory;
-import org.opends.server.types.ErrorLogSeverity;
-import org.opends.server.types.ModificationType;
-import org.opends.server.types.ResultCode;
-import org.opends.server.types.SearchResultEntry;
-import org.opends.server.types.SearchScope;
-
-
-/**
- * ServerState class.
- * This object is used to store the last update seem on this server
- * from each server.
- * It is exchanged with the changelog servers at connection establishment time
- * It is locally saved in the database
- * TODO : should extract from this object the code that read/save
- * from/to the database on the LDAP server side and put it in a new class
- * that is only used on the LDAP server side and that encapsulate this class.
- */
-public class ServerState implements Serializable
-{
-  private static final long serialVersionUID = 314772980474416183L;
-
-  private HashMap<Short, ChangeNumber> list;
-  transient private static final String
-                                  SYNCHRONIZATION_STATE = "ds-sync-state";
-  transient private DN baseDn;
-  transient boolean savedStatus = true;
-  transient private InternalClientConnection conn =
-                                              new InternalClientConnection();
-  transient private ASN1OctetString serverStateAsn1Dn;
-  transient private DN serverStateDn;
-
-  /**
-   * create a new ServerState.
-   * @param baseDn The baseDN for which the ServerState is created
-   */
-  public ServerState(DN baseDn)
-  {
-    list = new HashMap<Short, ChangeNumber>();
-    this.baseDn = baseDn;
-    serverStateAsn1Dn = new ASN1OctetString(
-        "dc=ffffffff-ffffffff-ffffffff-ffffffff,"
-        + baseDn.toString());
-    try
-    {
-      serverStateDn = DN.decode(serverStateAsn1Dn);
-    } catch (DirectoryException e)
-    {
-      // never happens
-    }
-  }
-
-  /**
-   * Creates a new ServerState object from its encoded form.
-   *
-   * @param in The byte array containing the encoded ServerState form.
-   * @param pos The position in the byte array where the encoded ServerState
-   *            starts.
-   * @param endpos The position in the byte array where the encoded ServerState
-   *               ends.
-   * @throws DataFormatException If the encoded form was not correct.
-   */
-  public ServerState(byte[] in, int pos, int endpos)
-         throws DataFormatException
-  {
-    try
-    {
-      list = new HashMap<Short, ChangeNumber>();
-
-      while (endpos > pos)
-      {
-        /*
-         * read the ServerId
-         */
-        int length = getNextLength(in, pos);
-        String serverIdString = new String(in, pos, length, "UTF-8");
-        short serverId = Short.valueOf(serverIdString);
-        pos += length +1;
-
-        /*
-         * read the ChangeNumber
-         */
-        length = getNextLength(in, pos);
-        String cnString = new String(in, pos, length, "UTF-8");
-        ChangeNumber cn = new ChangeNumber(cnString);
-        pos += length +1;
-
-        /*
-         * Add the serverid
-         */
-        list.put(serverId, cn);
-      }
-
-    } catch (UnsupportedEncodingException e)
-    {
-      throw new DataFormatException("UTF-8 is not supported by this jvm.");
-    }
-  }
-
-  /**
-   * Get the length of the next String encoded in the in byte array.
-   *
-   * @param in the byte array where to calculate the string.
-   * @param pos the position whre to start from in the byte array.
-   * @return the length of the next string.
-   * @throws DataFormatException If the byte array does not end with null.
-   */
-  private int getNextLength(byte[] in, int pos) throws DataFormatException
-  {
-    int offset = pos;
-    int length = 0;
-    while (in[offset++] != 0)
-    {
-      if (offset >= in.length)
-        throw new DataFormatException("byte[] is not a valid modify msg");
-      length++;
-    }
-    return length;
-  }
-
-  /**
-   * Update the Server State with a ChangeNumber.
-   * All operations with smaller CSN and the same serverID must be committed
-   * before calling this method.
-   * @param changeNumber the committed ChangeNumber.
-   * @return a boolean indicating if the update was meaningfull.
-   */
-  public boolean update(ChangeNumber changeNumber)
-  {
-    if (changeNumber == null)
-      return false;
-    synchronized(this)
-    {
-      Short id =  changeNumber.getServerId();
-      ChangeNumber oldCN = list.get(id);
-      if (oldCN == null || changeNumber.newer(oldCN))
-      {
-        list.put(id,changeNumber);
-        savedStatus = false;
-        return true;
-      }
-      else
-      {
-        return false;
-      }
-    }
-  }
-
-  /**
-   * return a Set of String usable as a textual representation of
-   * a Server state.
-   * format : time seqnum id
-   *
-   * example :
-   *  1 00000109e4666da600220001
-   *  2 00000109e44567a600220002
-   *
-   * @return the representation of the Server state
-   */
-  public Set<String> toStringSet()
-  {
-    HashSet<String> set = new HashSet<String>();
-    synchronized (this)
-    {
-
-      for (Short key  : list.keySet())
-      {
-        ChangeNumber change = list.get(key);
-        Date date = new Date(change.getTime());
-        set.add(change.toString() + " " + date.toString());
-      }
-    }
-
-    return set;
-  }
-
-  /**
-   * return the text representation of ServerState.
-   * @return the text representation of ServerState
-   */
-  @Override
-  public String toString()
-  {
-    synchronized (this)
-    {
-      String str = null;
-      for (Short key  : list.keySet())
-      {
-        ChangeNumber change = list.get(key);
-        str += " " + change.toString();
-      }
-
-      return str;
-    }
-  }
-
-  /**
-   * Get the largest ChangeNumber seen for a given LDAP server ID.
-   *
-   * @param serverId : the server ID
-   * @return the largest ChangeNumber seen
-   */
-  public ChangeNumber getMaxChangeNumber(short serverId)
-  {
-    return list.get(serverId);
-  }
-
-  /**
-   * Save this object to persistent storage.
-   */
-  public void save()
-  {
-    if ((list.size() == 0) || savedStatus)
-      return;
-
-    ArrayList<ASN1OctetString> values = new ArrayList<ASN1OctetString>();
-    synchronized (this)
-    {
-      for (Short id : list.keySet())
-      {
-        ASN1OctetString value = new ASN1OctetString(list.get(id).toString());
-        values.add(value);
-      }
-      savedStatus = true;
-    }
-    LDAPAttribute attr = new LDAPAttribute(SYNCHRONIZATION_STATE, values);
-    LDAPModification mod = new LDAPModification(ModificationType.REPLACE, attr);
-    ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>(1);
-    mods.add(mod);
-
-    boolean done = false;
-    while (!done)
-    {
-      /*
-       * Generate a modify operation on the Server State Entry :
-       * cn=ffffffff-ffffffff-ffffffff-ffffffff, baseDn
-       */
-      ModifyOperation op =
-        new ModifyOperation(conn, InternalClientConnection.nextOperationID(),
-            InternalClientConnection.nextMessageID(),
-            new ArrayList<Control>(0), serverStateAsn1Dn,
-            mods);
-      op.setInternalOperation(true);
-      op.setSynchronizationOperation(true);
-
-      op.run();
-      ResultCode resultCode = op.getResultCode();
-      if (resultCode != ResultCode.SUCCESS)
-      {
-        if (resultCode == ResultCode.NO_SUCH_OBJECT)
-        {
-          createStateEntry();
-        }
-        else
-        {
-          savedStatus = false;
-          int msgID = MSGID_ERROR_UPDATING_RUV;
-          String message = getMessage(msgID,
-              op.getResultCode().getResultCodeName(),
-              op.toString(), op.getErrorMessage(),
-              baseDn.toString());
-          logError(ErrorLogCategory.SYNCHRONIZATION,
-              ErrorLogSeverity.SEVERE_ERROR,
-              message, msgID);
-          break;
-        }
-      }
-      else
-        done = true;
-    }
-  }
-
-  /**
-   * Load the ServerState from the backing entry in database to memory.
-   */
-  public void loadState()
-  {
-    /*
-     * Read the serverState from the database,
-     * If not there create empty entry
-     */
-    LDAPFilter filter;
-    try
-    {
-      filter = LDAPFilter.decode("objectclass=*");
-    } catch (LDAPException e)
-    {
-      // can not happen
-      return;
-    }
-
-    /*
-     * Search the database entry that is used to periodically
-     * save the ServerState
-     */
-    InternalSearchOperation search = conn.processSearch(serverStateAsn1Dn,
-        SearchScope.BASE_OBJECT,
-        DereferencePolicy.DEREF_ALWAYS, 0, 0, false,
-        filter,new LinkedHashSet<String>(0));
-    if (((search.getResultCode() != ResultCode.SUCCESS)) &&
-        ((search.getResultCode() != ResultCode.NO_SUCH_OBJECT)))
-    {
-      int msgID = MSGID_ERROR_SEARCHING_RUV;
-      String message = getMessage(msgID,
-          search.getResultCode().getResultCodeName(),
-          search.toString(), search.getErrorMessage(),
-          baseDn.toString());
-      logError(ErrorLogCategory.SYNCHRONIZATION, ErrorLogSeverity.SEVERE_ERROR,
-          message, msgID);
-    }
-
-    SearchResultEntry resultEntry = null;
-    if (search.getResultCode() == ResultCode.SUCCESS)
-    {
-      /*
-       * Read the serverState from the SYNCHRONIZATION_STATE attribute
-       */
-      LinkedList<SearchResultEntry> result = search.getSearchEntries();
-      resultEntry = result.getFirst();
-      if (resultEntry != null)
-      {
-        AttributeType synchronizationStateType =
-          DirectoryServer.getAttributeType(SYNCHRONIZATION_STATE);
-        List<Attribute> attrs =
-          resultEntry.getAttribute(synchronizationStateType);
-        if (attrs != null)
-        {
-          Attribute attr = attrs.get(0);
-          LinkedHashSet<AttributeValue> values = attr.getValues();
-          for (AttributeValue value : values)
-          {
-            ChangeNumber changeNumber =
-              new ChangeNumber(value.getStringValue());
-            update(changeNumber);
-          }
-        }
-      }
-
-      /*
-       * TODO : The ServerState is saved to the database periodically,
-       * therefore in case of crash it is possible that is does not contain
-       * the latest changes that have been processed and saved to the
-       * database.
-       * In order to make sure that we don't loose them, search all the entries
-       * that have been updated after this entry.
-       * This is done by using the HistoricalCsnOrderingMatchingRule
-       * and an ordering index for historical attribute
-       */
-    }
-
-    if ((resultEntry == null) ||
-        ((search.getResultCode() != ResultCode.SUCCESS)))
-    {
-      createStateEntry();
-    }
-  }
-
-  /**
-   * Create the Entry that will be used to store the ServerState information.
-   * It will be updated when the server stops and periodically.
-   */
-  private void createStateEntry()
-  {
-    ArrayList<LDAPAttribute> attrs = new ArrayList<LDAPAttribute>();
-
-    ArrayList<ASN1OctetString> values = new ArrayList<ASN1OctetString>();
-    ASN1OctetString value = new ASN1OctetString("extensibleObject");
-    values.add(value);
-    LDAPAttribute attr = new LDAPAttribute("objectClass", values);
-    value = new ASN1OctetString("domain");
-    values.add(value);
-    attr = new LDAPAttribute("objectClass", values);
-    attrs.add(attr);
-
-    values = new ArrayList<ASN1OctetString>();
-    value = new ASN1OctetString("ffffffff-ffffffff-ffffffff-ffffffff");
-    values.add(value);
-    attr = new LDAPAttribute("dc", values);
-    attrs.add(attr);
-
-    AddOperation add = conn.processAdd(serverStateAsn1Dn, attrs);
-    ResultCode resultCode = add.getResultCode();
-    if ((resultCode != ResultCode.SUCCESS) &&
-        (resultCode != ResultCode.NO_SUCH_OBJECT))
-    {
-      int msgID = MSGID_ERROR_UPDATING_RUV;
-      String message = getMessage(msgID,
-          add.getResultCode().getResultCodeName(),
-          add.toString(), add.getErrorMessage(),
-          baseDn.toString());
-      logError(ErrorLogCategory.SYNCHRONIZATION,
-          ErrorLogSeverity.SEVERE_ERROR,
-          message, msgID);
-    }
-  }
-
-  /**
-   * Get the Dn where the ServerState is stored.
-   * @return Returns the serverStateDn.
-   */
-  public DN getServerStateDn()
-  {
-    return serverStateDn;
-  }
-
-  /**
-   * Add the tail into resultByteArray at position pos.
-   */
-  private int addByteArray(byte[] tail, byte[] resultByteArray, int pos)
-  {
-    for (int i=0; i<tail.length; i++,pos++)
-    {
-      resultByteArray[pos] = tail[i];
-    }
-    resultByteArray[pos++] = 0;
-    return pos;
-  }
-
-  /**
-   * Encode this ServerState object and return its byte array representation.
-   *
-   * @return a byte array with an encoded representation of this object.
-   * @throws UnsupportedEncodingException if UTF8 is not supported by the JVM.
-   */
-  public byte[] getBytes() throws UnsupportedEncodingException
-  {
-    synchronized (this)
-    {
-      int length = 0;
-      List<String> idList = new ArrayList<String>(list.size());
-      for (short id : list.keySet())
-      {
-        String temp = String.valueOf(id);
-        idList.add(temp);
-        length += temp.length() + 1;
-      }
-      List<String> cnList = new ArrayList<String>(list.size());
-      for (ChangeNumber cn : list.values())
-      {
-        String temp = cn.toString();
-        cnList.add(temp);
-        length += temp.length() + 1;
-      }
-      byte[] result = new byte[length];
-
-      int pos = 0;
-      for (int i=0; i< list.size(); i++)
-      {
-        String str = idList.get(i);
-        pos = addByteArray(str.getBytes("UTF-8"), result, pos);
-        str = cnList.get(i);
-        pos = addByteArray(str.getBytes("UTF-8"), result, pos);
-      }
-      return result;
-    }
-  }
-}
diff --git a/opends/src/server/org/opends/server/changelog/AckMessageList.java b/opends/src/server/org/opends/server/synchronization/changelog/AckMessageList.java
similarity index 96%
rename from opends/src/server/org/opends/server/changelog/AckMessageList.java
rename to opends/src/server/org/opends/server/synchronization/changelog/AckMessageList.java
index 59bcc97..7527599 100644
--- a/opends/src/server/org/opends/server/changelog/AckMessageList.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/AckMessageList.java
@@ -24,11 +24,11 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import java.util.LinkedList;
 
-import org.opends.server.synchronization.ChangeNumber;
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * This class is used to store the list of acks received for
diff --git a/opends/src/server/org/opends/server/changelog/AckMessageListComparator.java b/opends/src/server/org/opends/server/synchronization/changelog/AckMessageListComparator.java
similarity index 95%
rename from opends/src/server/org/opends/server/changelog/AckMessageListComparator.java
rename to opends/src/server/org/opends/server/synchronization/changelog/AckMessageListComparator.java
index c2c756d..a287b39 100644
--- a/opends/src/server/org/opends/server/changelog/AckMessageListComparator.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/AckMessageListComparator.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import java.util.Comparator;
 
diff --git a/opends/src/server/org/opends/server/changelog/Changelog.java b/opends/src/server/org/opends/server/synchronization/changelog/Changelog.java
similarity index 98%
rename from opends/src/server/org/opends/server/changelog/Changelog.java
rename to opends/src/server/org/opends/server/synchronization/changelog/Changelog.java
index 497e2f4..b90ea1d 100644
--- a/opends/src/server/org/opends/server/changelog/Changelog.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/Changelog.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -42,6 +42,7 @@
 import org.opends.server.config.StringConfigAttribute;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.messages.MessageHandler;
+import org.opends.server.synchronization.protocol.SocketSession;
 import org.opends.server.types.ConfigChangeResult;
 import org.opends.server.types.DN;
 import org.opends.server.types.ErrorLogCategory;
@@ -49,7 +50,7 @@
 
 import static org.opends.server.loggers.Error.logError;
 import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
diff --git a/opends/src/server/org/opends/server/changelog/ChangelogAckMessageList.java b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogAckMessageList.java
similarity index 95%
rename from opends/src/server/org/opends/server/changelog/ChangelogAckMessageList.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ChangelogAckMessageList.java
index 328b10a..0788ec3 100644
--- a/opends/src/server/org/opends/server/changelog/ChangelogAckMessageList.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogAckMessageList.java
@@ -24,9 +24,9 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
-import org.opends.server.synchronization.ChangeNumber;
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * This class is used to store acks for update messages coming from
diff --git a/opends/src/server/org/opends/server/changelog/ChangelogCache.java b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogCache.java
similarity index 97%
rename from opends/src/server/org/opends/server/changelog/ChangelogCache.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ChangelogCache.java
index 398bcf3..5ebc5df 100644
--- a/opends/src/server/org/opends/server/changelog/ChangelogCache.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogCache.java
@@ -24,10 +24,10 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 import static org.opends.server.loggers.Error.logError;
 
 import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
@@ -36,10 +36,10 @@
 import org.opends.server.types.DN;
 import org.opends.server.types.ErrorLogCategory;
 import org.opends.server.types.ErrorLogSeverity;
-import org.opends.server.synchronization.AckMessage;
-import org.opends.server.synchronization.ChangeNumber;
-import org.opends.server.synchronization.ServerState;
-import org.opends.server.synchronization.UpdateMessage;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.common.ServerState;
+import org.opends.server.synchronization.protocol.AckMessage;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 
 import java.io.IOException;
 import java.util.HashSet;
@@ -548,7 +548,7 @@
    */
   public ServerState getDbServerState()
   {
-    ServerState serverState = new ServerState(baseDn);
+    ServerState serverState = new ServerState();
     for (DbHandler db : sourceDbHandlers.values())
     {
       serverState.update(db.getLastChange());
diff --git a/opends/src/server/org/opends/server/changelog/ChangelogDB.java b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogDB.java
similarity index 97%
rename from opends/src/server/org/opends/server/changelog/ChangelogDB.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ChangelogDB.java
index c476e40..fc94e70 100644
--- a/opends/src/server/org/opends/server/changelog/ChangelogDB.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogDB.java
@@ -24,11 +24,11 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import static org.opends.server.loggers.Error.logError;
 import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
 
 import java.util.List;
@@ -37,8 +37,8 @@
 import org.opends.server.types.DN;
 import org.opends.server.types.ErrorLogCategory;
 import org.opends.server.types.ErrorLogSeverity;
-import org.opends.server.synchronization.ChangeNumber;
-import org.opends.server.synchronization.UpdateMessage;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 
 import com.sleepycat.je.Cursor;
 import com.sleepycat.je.DatabaseEntry;
diff --git a/opends/src/server/org/opends/server/changelog/ChangelogDBException.java b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java
similarity index 97%
rename from opends/src/server/org/opends/server/changelog/ChangelogDBException.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java
index f7fe980..a226de2 100644
--- a/opends/src/server/org/opends/server/changelog/ChangelogDBException.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 /**
  * This class define an Exception that must be used when some error
diff --git a/opends/src/server/org/opends/server/changelog/ChangelogData.java b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogData.java
similarity index 90%
rename from opends/src/server/org/opends/server/changelog/ChangelogData.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ChangelogData.java
index 2856771..aa38563 100644
--- a/opends/src/server/org/opends/server/changelog/ChangelogData.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogData.java
@@ -24,11 +24,12 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import com.sleepycat.je.DatabaseEntry;
-import org.opends.server.synchronization.SynchronizationMessage;
-import org.opends.server.synchronization.UpdateMessage;
+
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 
 /**
  * SuperClass of DatabaseEntry used for data stored in the Changelog Databases.
diff --git a/opends/src/server/org/opends/server/changelog/ChangelogDbEnv.java b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogDbEnv.java
similarity index 98%
rename from opends/src/server/org/opends/server/changelog/ChangelogDbEnv.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ChangelogDbEnv.java
index f9fdfa4..4fe79d4 100644
--- a/opends/src/server/org/opends/server/changelog/ChangelogDbEnv.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogDbEnv.java
@@ -24,11 +24,11 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import static org.opends.server.loggers.Error.logError;
 import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
 
 import java.io.File;
diff --git a/opends/src/server/org/opends/server/changelog/ChangelogIterator.java b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogIterator.java
similarity index 92%
rename from opends/src/server/org/opends/server/changelog/ChangelogIterator.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ChangelogIterator.java
index 6e3a51a..2a595a5 100644
--- a/opends/src/server/org/opends/server/changelog/ChangelogIterator.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogIterator.java
@@ -24,13 +24,13 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import com.sleepycat.je.DatabaseException;
 
-import org.opends.server.changelog.ChangelogDB.ChangelogCursor;
-import org.opends.server.synchronization.ChangeNumber;
-import org.opends.server.synchronization.UpdateMessage;
+import org.opends.server.synchronization.changelog.ChangelogDB.ChangelogCursor;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 
 /**
  * This class allows to iterate through the changes received from a given
diff --git a/opends/src/server/org/opends/server/changelog/ChangelogIteratorComparator.java b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogIteratorComparator.java
similarity index 93%
rename from opends/src/server/org/opends/server/changelog/ChangelogIteratorComparator.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ChangelogIteratorComparator.java
index 881baa3..71dff9c 100644
--- a/opends/src/server/org/opends/server/changelog/ChangelogIteratorComparator.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogIteratorComparator.java
@@ -24,11 +24,11 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import java.util.Comparator;
 
-import org.opends.server.synchronization.ChangeNumber;
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * This Class define a Comparator that allows to know which ChangelogIterator
diff --git a/opends/src/server/org/opends/server/changelog/ChangelogKey.java b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogKey.java
similarity index 93%
rename from opends/src/server/org/opends/server/changelog/ChangelogKey.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ChangelogKey.java
index 2f9447e..6c3ab5c 100644
--- a/opends/src/server/org/opends/server/changelog/ChangelogKey.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogKey.java
@@ -24,12 +24,13 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import java.io.UnsupportedEncodingException;
 
 import com.sleepycat.je.DatabaseEntry;
-import org.opends.server.synchronization.ChangeNumber;
+
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * Superclass of DatabaseEntry.
diff --git a/opends/src/server/org/opends/server/changelog/DbHandler.java b/opends/src/server/org/opends/server/synchronization/changelog/DbHandler.java
similarity index 97%
rename from opends/src/server/org/opends/server/changelog/DbHandler.java
rename to opends/src/server/org/opends/server/synchronization/changelog/DbHandler.java
index 593b868..ac53f2b 100644
--- a/opends/src/server/org/opends/server/changelog/DbHandler.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/DbHandler.java
@@ -24,11 +24,11 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import static org.opends.server.loggers.Error.logError;
 import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
 
 import java.util.ArrayList;
@@ -38,7 +38,6 @@
 
 import org.opends.server.api.DirectoryThread;
 import org.opends.server.api.MonitorProvider;
-import org.opends.server.changelog.ChangelogDB.ChangelogCursor;
 import org.opends.server.config.ConfigEntry;
 import org.opends.server.config.ConfigException;
 import org.opends.server.types.Attribute;
@@ -48,8 +47,9 @@
 import org.opends.server.types.InitializationException;
 import org.opends.server.util.TimeThread;
 import org.opends.server.core.DirectoryServer;
-import org.opends.server.synchronization.ChangeNumber;
-import org.opends.server.synchronization.UpdateMessage;
+import org.opends.server.synchronization.changelog.ChangelogDB.ChangelogCursor;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 
 import com.sleepycat.je.DatabaseException;
 
diff --git a/opends/src/server/org/opends/server/changelog/MsgQueue.java b/opends/src/server/org/opends/server/synchronization/changelog/MsgQueue.java
similarity index 94%
rename from opends/src/server/org/opends/server/changelog/MsgQueue.java
rename to opends/src/server/org/opends/server/synchronization/changelog/MsgQueue.java
index f8e8e6d..f411515 100644
--- a/opends/src/server/org/opends/server/changelog/MsgQueue.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/MsgQueue.java
@@ -24,13 +24,13 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import java.util.SortedMap;
 import java.util.TreeMap;
 
-import org.opends.server.synchronization.ChangeNumber;
-import org.opends.server.synchronization.UpdateMessage;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 
 /**
  * This class is used to build ordered lists of UpdateMessage.
diff --git a/opends/src/server/org/opends/server/changelog/ServerHandler.java b/opends/src/server/org/opends/server/synchronization/changelog/ServerHandler.java
similarity index 97%
rename from opends/src/server/org/opends/server/changelog/ServerHandler.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ServerHandler.java
index 6934954..10663dc 100644
--- a/opends/src/server/org/opends/server/changelog/ServerHandler.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ServerHandler.java
@@ -24,11 +24,11 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import static org.opends.server.loggers.Error.logError;
 import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
 
 import java.io.IOException;
@@ -52,14 +52,15 @@
 import org.opends.server.types.ErrorLogSeverity;
 import org.opends.server.types.InitializationException;
 import org.opends.server.core.DirectoryServer;
-import org.opends.server.synchronization.AckMessage;
-import org.opends.server.synchronization.ChangeNumber;
-import org.opends.server.synchronization.ChangelogStartMessage;
-import org.opends.server.synchronization.ServerStartMessage;
-import org.opends.server.synchronization.ServerState;
-import org.opends.server.synchronization.SynchronizationMessage;
-import org.opends.server.synchronization.UpdateMessage;
-import org.opends.server.synchronization.WindowMessage;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.common.ServerState;
+import org.opends.server.synchronization.protocol.AckMessage;
+import org.opends.server.synchronization.protocol.ChangelogStartMessage;
+import org.opends.server.synchronization.protocol.ProtocolSession;
+import org.opends.server.synchronization.protocol.ServerStartMessage;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
+import org.opends.server.synchronization.protocol.UpdateMessage;
+import org.opends.server.synchronization.protocol.WindowMessage;
 import org.opends.server.util.TimeThread;
 
 /**
diff --git a/opends/src/server/org/opends/server/changelog/ServerReader.java b/opends/src/server/org/opends/server/synchronization/changelog/ServerReader.java
similarity index 91%
rename from opends/src/server/org/opends/server/changelog/ServerReader.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ServerReader.java
index d0f1126..94cd21c 100644
--- a/opends/src/server/org/opends/server/changelog/ServerReader.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ServerReader.java
@@ -24,19 +24,20 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import static org.opends.server.loggers.Error.logError;
 import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 
 import java.io.IOException;
 
 import org.opends.server.api.DirectoryThread;
-import org.opends.server.synchronization.AckMessage;
-import org.opends.server.synchronization.SynchronizationMessage;
-import org.opends.server.synchronization.UpdateMessage;
-import org.opends.server.synchronization.WindowMessage;
+import org.opends.server.synchronization.protocol.AckMessage;
+import org.opends.server.synchronization.protocol.ProtocolSession;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
+import org.opends.server.synchronization.protocol.UpdateMessage;
+import org.opends.server.synchronization.protocol.WindowMessage;
 import org.opends.server.types.ErrorLogCategory;
 import org.opends.server.types.ErrorLogSeverity;
 
diff --git a/opends/src/server/org/opends/server/changelog/ServerWriter.java b/opends/src/server/org/opends/server/synchronization/changelog/ServerWriter.java
similarity index 94%
rename from opends/src/server/org/opends/server/changelog/ServerWriter.java
rename to opends/src/server/org/opends/server/synchronization/changelog/ServerWriter.java
index 445a7d2..f68db9c 100644
--- a/opends/src/server/org/opends/server/changelog/ServerWriter.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/ServerWriter.java
@@ -24,18 +24,19 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import static org.opends.server.loggers.Error.logError;
 import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 
 import java.io.IOException;
 import java.net.SocketException;
 import java.util.NoSuchElementException;
 
 import org.opends.server.api.DirectoryThread;
-import org.opends.server.synchronization.UpdateMessage;
+import org.opends.server.synchronization.protocol.ProtocolSession;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 import org.opends.server.types.ErrorLogCategory;
 import org.opends.server.types.ErrorLogSeverity;
 
diff --git a/opends/src/server/org/opends/server/changelog/UpdateComparator.java b/opends/src/server/org/opends/server/synchronization/changelog/UpdateComparator.java
similarity index 90%
rename from opends/src/server/org/opends/server/changelog/UpdateComparator.java
rename to opends/src/server/org/opends/server/synchronization/changelog/UpdateComparator.java
index 9a56227..d3e3f06 100644
--- a/opends/src/server/org/opends/server/changelog/UpdateComparator.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/UpdateComparator.java
@@ -24,11 +24,12 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
 
 import java.util.Comparator;
-import org.opends.server.synchronization.UpdateMessage;
-import org.opends.server.synchronization.ChangeNumber;
+
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 
 /**
  * Class to use for establishing an order within UpdateMessages.
diff --git a/opends/src/server/org/opends/server/changelog/package-info.java b/opends/src/server/org/opends/server/synchronization/changelog/package-info.java
similarity index 97%
rename from opends/src/server/org/opends/server/changelog/package-info.java
rename to opends/src/server/org/opends/server/synchronization/changelog/package-info.java
index 359d52f..5d35f51 100644
--- a/opends/src/server/org/opends/server/changelog/package-info.java
+++ b/opends/src/server/org/opends/server/synchronization/changelog/package-info.java
@@ -76,4 +76,4 @@
  *  </ul>
  */
 
-package org.opends.server.changelog;
+package org.opends.server.synchronization.changelog;
diff --git a/opends/src/server/org/opends/server/synchronization/ChangeNumber.java b/opends/src/server/org/opends/server/synchronization/common/ChangeNumber.java
similarity index 98%
rename from opends/src/server/org/opends/server/synchronization/ChangeNumber.java
rename to opends/src/server/org/opends/server/synchronization/common/ChangeNumber.java
index 77e08b7..ec67d61 100644
--- a/opends/src/server/org/opends/server/synchronization/ChangeNumber.java
+++ b/opends/src/server/org/opends/server/synchronization/common/ChangeNumber.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.common;
 
 /**
  * Class used to represent Change Numbers.
diff --git a/opends/src/server/org/opends/server/synchronization/ChangeNumberGenerator.java b/opends/src/server/org/opends/server/synchronization/common/ChangeNumberGenerator.java
similarity index 98%
rename from opends/src/server/org/opends/server/synchronization/ChangeNumberGenerator.java
rename to opends/src/server/org/opends/server/synchronization/common/ChangeNumberGenerator.java
index 93b69b9..c865276 100644
--- a/opends/src/server/org/opends/server/synchronization/ChangeNumberGenerator.java
+++ b/opends/src/server/org/opends/server/synchronization/common/ChangeNumberGenerator.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.common;
 
 import org.opends.server.util.TimeThread;
 
diff --git a/opends/src/server/org/opends/server/synchronization/SynchMessages.java b/opends/src/server/org/opends/server/synchronization/common/LogMessages.java
similarity index 98%
rename from opends/src/server/org/opends/server/synchronization/SynchMessages.java
rename to opends/src/server/org/opends/server/synchronization/common/LogMessages.java
index 6fefefc..329dfbc 100644
--- a/opends/src/server/org/opends/server/synchronization/SynchMessages.java
+++ b/opends/src/server/org/opends/server/synchronization/common/LogMessages.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.common;
 
 import org.opends.server.messages.MessageHandler;
 import static org.opends.server.messages.MessageHandler.*;
@@ -33,7 +33,7 @@
  * This class defines the set of message IDs and default format strings for
  * messages associated with the Synchronization.
  */
-public class SynchMessages {
+public class LogMessages {
 
   /**
    * Name used to store attachment of historical information in the
@@ -268,7 +268,7 @@
    * Register the messages from this class in the core server.
    *
    */
-  static void registerMessages()
+  public static void registerMessages()
   {
     MessageHandler.registerMessage(MSGID_SYNC_INVALID_DN,
        "The Synchronization configuration DN is invalid");
diff --git a/opends/src/server/org/opends/server/synchronization/common/ServerState.java b/opends/src/server/org/opends/server/synchronization/common/ServerState.java
new file mode 100644
index 0000000..e5d741f
--- /dev/null
+++ b/opends/src/server/org/opends/server/synchronization/common/ServerState.java
@@ -0,0 +1,284 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+package org.opends.server.synchronization.common;
+
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.zip.DataFormatException;
+
+import org.opends.server.protocols.asn1.ASN1OctetString;
+
+
+/**
+ * ServerState class.
+ * This object is used to store the last update seem on this server
+ * from each server.
+ * It is exchanged with the changelog servers at connection establishment time.
+ */
+public class ServerState
+{
+  private HashMap<Short, ChangeNumber> list;
+
+  /**
+   * Creates a new empty ServerState.
+   */
+  public ServerState()
+  {
+    list = new HashMap<Short, ChangeNumber>();
+  }
+
+
+  /**
+   * Creates a new ServerState object from its encoded form.
+   *
+   * @param in The byte array containing the encoded ServerState form.
+   * @param pos The position in the byte array where the encoded ServerState
+   *            starts.
+   * @param endpos The position in the byte array where the encoded ServerState
+   *               ends.
+   * @throws DataFormatException If the encoded form was not correct.
+   */
+  public ServerState(byte[] in, int pos, int endpos)
+         throws DataFormatException
+  {
+    try
+    {
+      list = new HashMap<Short, ChangeNumber>();
+
+      while (endpos > pos)
+      {
+        /*
+         * read the ServerId
+         */
+        int length = getNextLength(in, pos);
+        String serverIdString = new String(in, pos, length, "UTF-8");
+        short serverId = Short.valueOf(serverIdString);
+        pos += length +1;
+
+        /*
+         * read the ChangeNumber
+         */
+        length = getNextLength(in, pos);
+        String cnString = new String(in, pos, length, "UTF-8");
+        ChangeNumber cn = new ChangeNumber(cnString);
+        pos += length +1;
+
+        /*
+         * Add the serverid
+         */
+        list.put(serverId, cn);
+      }
+
+    } catch (UnsupportedEncodingException e)
+    {
+      throw new DataFormatException("UTF-8 is not supported by this jvm.");
+    }
+  }
+
+  /**
+   * Get the length of the next String encoded in the in byte array.
+   *
+   * @param in the byte array where to calculate the string.
+   * @param pos the position whre to start from in the byte array.
+   * @return the length of the next string.
+   * @throws DataFormatException If the byte array does not end with null.
+   */
+  private int getNextLength(byte[] in, int pos) throws DataFormatException
+  {
+    int offset = pos;
+    int length = 0;
+    while (in[offset++] != 0)
+    {
+      if (offset >= in.length)
+        throw new DataFormatException("byte[] is not a valid modify msg");
+      length++;
+    }
+    return length;
+  }
+
+  /**
+   * Update the Server State with a ChangeNumber.
+   * All operations with smaller CSN and the same serverID must be committed
+   * before calling this method.
+   * @param changeNumber the committed ChangeNumber.
+   * @return a boolean indicating if the update was meaningfull.
+   */
+  public boolean update(ChangeNumber changeNumber)
+  {
+    if (changeNumber == null)
+      return false;
+    synchronized(this)
+    {
+      Short id =  changeNumber.getServerId();
+      ChangeNumber oldCN = list.get(id);
+      if (oldCN == null || changeNumber.newer(oldCN))
+      {
+        list.put(id,changeNumber);
+        return true;
+      }
+      else
+      {
+        return false;
+      }
+    }
+  }
+
+  /**
+   * return a Set of String usable as a textual representation of
+   * a Server state.
+   * format : time seqnum id
+   *
+   * example :
+   *  1 00000109e4666da600220001
+   *  2 00000109e44567a600220002
+   *
+   * @return the representation of the Server state
+   */
+  public Set<String> toStringSet()
+  {
+    HashSet<String> set = new HashSet<String>();
+    synchronized (this)
+    {
+
+      for (Short key  : list.keySet())
+      {
+        ChangeNumber change = list.get(key);
+        Date date = new Date(change.getTime());
+        set.add(change.toString() + " " + date.toString());
+      }
+    }
+
+    return set;
+  }
+
+  /**
+   * Return an ArrayList of ANS1OctetString encoding the ChangeNumbers
+   * contained in the ServerState.
+   * @return an ArrayList of ANS1OctetString encoding the ChangeNumbers
+   * contained in the ServerState.
+   */
+  public ArrayList<ASN1OctetString> toASN1ArrayList()
+  {
+    ArrayList<ASN1OctetString> values = new ArrayList<ASN1OctetString>();
+    synchronized (this)
+    {
+      for (Short id : list.keySet())
+      {
+        ASN1OctetString value = new ASN1OctetString(list.get(id).toString());
+        values.add(value);
+      }
+    }
+    return values;
+  }
+  /**
+   * return the text representation of ServerState.
+   * @return the text representation of ServerState
+   */
+  @Override
+  public String toString()
+  {
+    synchronized (this)
+    {
+      String str = null;
+      for (Short key  : list.keySet())
+      {
+        ChangeNumber change = list.get(key);
+        str += " " + change.toString();
+      }
+
+      return str;
+    }
+  }
+
+  /**
+   * Get the largest ChangeNumber seen for a given LDAP server ID.
+   *
+   * @param serverId : the server ID
+   * @return the largest ChangeNumber seen
+   */
+  public ChangeNumber getMaxChangeNumber(short serverId)
+  {
+    return list.get(serverId);
+  }
+
+  /**
+   * Add the tail into resultByteArray at position pos.
+   */
+  private int addByteArray(byte[] tail, byte[] resultByteArray, int pos)
+  {
+    for (int i=0; i<tail.length; i++,pos++)
+    {
+      resultByteArray[pos] = tail[i];
+    }
+    resultByteArray[pos++] = 0;
+    return pos;
+  }
+
+  /**
+   * Encode this ServerState object and return its byte array representation.
+   *
+   * @return a byte array with an encoded representation of this object.
+   * @throws UnsupportedEncodingException if UTF8 is not supported by the JVM.
+   */
+  public byte[] getBytes() throws UnsupportedEncodingException
+  {
+    synchronized (this)
+    {
+      int length = 0;
+      List<String> idList = new ArrayList<String>(list.size());
+      for (short id : list.keySet())
+      {
+        String temp = String.valueOf(id);
+        idList.add(temp);
+        length += temp.length() + 1;
+      }
+      List<String> cnList = new ArrayList<String>(list.size());
+      for (ChangeNumber cn : list.values())
+      {
+        String temp = cn.toString();
+        cnList.add(temp);
+        length += temp.length() + 1;
+      }
+      byte[] result = new byte[length];
+
+      int pos = 0;
+      for (int i=0; i< list.size(); i++)
+      {
+        String str = idList.get(i);
+        pos = addByteArray(str.getBytes("UTF-8"), result, pos);
+        str = cnList.get(i);
+        pos = addByteArray(str.getBytes("UTF-8"), result, pos);
+      }
+      return result;
+    }
+  }
+}
diff --git a/opends/src/server/org/opends/server/synchronization/FakeOperationComparator.java b/opends/src/server/org/opends/server/synchronization/common/package-info.java
similarity index 60%
copy from opends/src/server/org/opends/server/synchronization/FakeOperationComparator.java
copy to opends/src/server/org/opends/server/synchronization/common/package-info.java
index 7580269..47307c4 100644
--- a/opends/src/server/org/opends/server/synchronization/FakeOperationComparator.java
+++ b/opends/src/server/org/opends/server/synchronization/common/package-info.java
@@ -24,23 +24,23 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
-
-import java.util.Comparator;
 
 /**
- * This Class implements a Comparator that can be used to build TreeSet
- * containing FakeOperations sorted by the ChangeNumber order.
+ * This package contains utilities that can are used by all the packages
+ * below org.opends.server.synchronization
+ * <br>
+ * The main classes of this core are :
+ * <ul>
+ * <li>
+ * <A HREF="ChangeNumber.html"><B>ChangeNumber</B></A>
+ * Define Change Numbers used to identify and to order the LDAP changes
+ * </li>
+ * <li>
+ * <A HREF="ServerState.html"><B>ServerStaten</B></A>
+ * This class is used to define and store the updatedness of any component
+ * of the synchronization architecture (i.e : to know which changes
+ * it has already processed).
+ * </li>
+ * </ul>
  */
-public class FakeOperationComparator implements Comparator<FakeOperation>
-{
-  /**
-   * {@inheritDoc}
-   */
-  public int compare(FakeOperation op1, FakeOperation op2)
-  {
-    if (op1 == null)
-      return -1;
-    return op1.getChangeNumber().compareTo(op2.getChangeNumber());
-  }
-}
+package org.opends.server.synchronization.common;
diff --git a/opends/src/server/org/opends/server/synchronization/package-info.java b/opends/src/server/org/opends/server/synchronization/package-info.java
index 16fba6a..02142d0 100644
--- a/opends/src/server/org/opends/server/synchronization/package-info.java
+++ b/opends/src/server/org/opends/server/synchronization/package-info.java
@@ -26,44 +26,7 @@
  */
 
 /**
- * This package contains the part of the Multimaster
- * synchronization code that works on the Directory Server side.
- * <br>
- * The main classes of this core are :
- * <ul>
- * <li>
- * <A HREF="MultimasterSynchronization.html"><B>MultimasterSynchronization
- * </B></A>contains the synchronization provider
- * code and more generally all the code that makes the glue between the core
- * server and the synchronization code.
- * </li>
- * <li>
- * <A HREF="SynchronizationDomain.html"><B>SynchronizationDomain</B></A>
- * contains the bulk of the Directory Server side of the
- * synchronization code. Most notably it contains the root method for
- * publishing a change, processing a change received from the changelog
- * service, handle conflict resolution, handle protocol messages from the
- * changelog server.
- * </li>
- * <li>
- * <A HREF="ChangeNumber.html"><B>ChangeNumber</B></A>
- * and <A HREF="ChangeNumberGenerator.html"><B>ChangeNumberGenerator</B></A>
- * contain the code related to Change Numbers code and their generation.
- * </li>
- * <li>
- * <A HREF="ServerState.html"><B>ServerState</B></A>
- * contain the code necessary for maintaining the updatedness
- * of a server.
- * Historical.java and the classes that it uses contain the code for
- * generating and loading the historical information (only modify aspects are
- * implemented)
- * </li>
- * <li>
- * <A HREF="SynchronizationMessage.html"><B>SynchronizationMessage</B></A>
- * and the classes that inherit from it contain the
- * description of the protocol messages that are exchanged between the
- * directory servers and the changelog servers and their encoding/decoding.
- * </li>
- * </ul>
+ * This package contains the code for the synchronization feature
+ * which provides a Multi-Master replication system.
  */
 package org.opends.server.synchronization;
diff --git a/opends/src/server/org/opends/server/synchronization/AttrInfo.java b/opends/src/server/org/opends/server/synchronization/plugin/AttrInfo.java
similarity index 97%
rename from opends/src/server/org/opends/server/synchronization/AttrInfo.java
rename to opends/src/server/org/opends/server/synchronization/plugin/AttrInfo.java
index 52f4ead..1f899de 100644
--- a/opends/src/server/org/opends/server/synchronization/AttrInfo.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/AttrInfo.java
@@ -24,10 +24,12 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import java.util.ArrayList;
 import java.util.LinkedHashSet;
+
+import org.opends.server.synchronization.common.ChangeNumber;
 import org.opends.server.types.AttributeValue;
 
 
diff --git a/opends/src/server/org/opends/server/synchronization/AttrInfoWithOptions.java b/opends/src/server/org/opends/server/synchronization/plugin/AttrInfoWithOptions.java
similarity index 97%
rename from opends/src/server/org/opends/server/synchronization/AttrInfoWithOptions.java
rename to opends/src/server/org/opends/server/synchronization/plugin/AttrInfoWithOptions.java
index 60b5951..ef00977 100644
--- a/opends/src/server/org/opends/server/synchronization/AttrInfoWithOptions.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/AttrInfoWithOptions.java
@@ -24,11 +24,12 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import java.util.HashMap;
 import java.util.Set;
 
+
 /**
  * Used to store historical information.
  * Contain a map of AttrInfo for each options of a given attribute type.
diff --git a/opends/src/server/org/opends/server/synchronization/ChangelogBroker.java b/opends/src/server/org/opends/server/synchronization/plugin/ChangelogBroker.java
similarity index 96%
rename from opends/src/server/org/opends/server/synchronization/ChangelogBroker.java
rename to opends/src/server/org/opends/server/synchronization/plugin/ChangelogBroker.java
index 2778e34..f96b10a 100644
--- a/opends/src/server/org/opends/server/synchronization/ChangelogBroker.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/ChangelogBroker.java
@@ -24,11 +24,11 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import static org.opends.server.loggers.Error.logError;
 import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
 
 import java.util.LinkedHashSet;
@@ -43,13 +43,20 @@
 import java.net.SocketException;
 import java.net.SocketTimeoutException;
 
-import org.opends.server.changelog.ProtocolSession;
-import org.opends.server.changelog.SocketSession;
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.protocols.internal.InternalClientConnection;
 import org.opends.server.protocols.internal.InternalSearchListener;
 import org.opends.server.protocols.internal.InternalSearchOperation;
 import org.opends.server.protocols.ldap.LDAPFilter;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.common.ServerState;
+import org.opends.server.synchronization.protocol.ChangelogStartMessage;
+import org.opends.server.synchronization.protocol.ProtocolSession;
+import org.opends.server.synchronization.protocol.ServerStartMessage;
+import org.opends.server.synchronization.protocol.SocketSession;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
+import org.opends.server.synchronization.protocol.UpdateMessage;
+import org.opends.server.synchronization.protocol.WindowMessage;
 import org.opends.server.types.DN;
 import org.opends.server.types.DereferencePolicy;
 import org.opends.server.types.ErrorLogCategory;
diff --git a/opends/src/server/org/opends/server/synchronization/FakeOperation.java b/opends/src/server/org/opends/server/synchronization/plugin/FakeOperation.java
similarity index 93%
rename from opends/src/server/org/opends/server/synchronization/FakeOperation.java
rename to opends/src/server/org/opends/server/synchronization/plugin/FakeOperation.java
index 0af1f53..2cf5bed 100644
--- a/opends/src/server/org/opends/server/synchronization/FakeOperation.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/FakeOperation.java
@@ -24,8 +24,10 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
 import org.opends.server.types.Modification;
 
 
diff --git a/opends/src/server/org/opends/server/synchronization/FakeOperationComparator.java b/opends/src/server/org/opends/server/synchronization/plugin/FakeOperationComparator.java
similarity index 96%
rename from opends/src/server/org/opends/server/synchronization/FakeOperationComparator.java
rename to opends/src/server/org/opends/server/synchronization/plugin/FakeOperationComparator.java
index 7580269..7c23ce1 100644
--- a/opends/src/server/org/opends/server/synchronization/FakeOperationComparator.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/FakeOperationComparator.java
@@ -24,10 +24,11 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import java.util.Comparator;
 
+
 /**
  * This Class implements a Comparator that can be used to build TreeSet
  * containing FakeOperations sorted by the ChangeNumber order.
diff --git a/opends/src/server/org/opends/server/synchronization/HistKey.java b/opends/src/server/org/opends/server/synchronization/plugin/HistKey.java
similarity index 97%
rename from opends/src/server/org/opends/server/synchronization/HistKey.java
rename to opends/src/server/org/opends/server/synchronization/plugin/HistKey.java
index 534e89b..210d50f 100644
--- a/opends/src/server/org/opends/server/synchronization/HistKey.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/HistKey.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 /**
  * Enumeration used for storing type of historical information.
diff --git a/opends/src/server/org/opends/server/synchronization/HistVal.java b/opends/src/server/org/opends/server/synchronization/plugin/HistVal.java
similarity index 97%
rename from opends/src/server/org/opends/server/synchronization/HistVal.java
rename to opends/src/server/org/opends/server/synchronization/plugin/HistVal.java
index 4d9da8d..b43458c 100644
--- a/opends/src/server/org/opends/server/synchronization/HistVal.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/HistVal.java
@@ -24,13 +24,14 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.synchronization.common.ChangeNumber;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
diff --git a/opends/src/server/org/opends/server/synchronization/Historical.java b/opends/src/server/org/opends/server/synchronization/plugin/Historical.java
similarity index 98%
rename from opends/src/server/org/opends/server/synchronization/Historical.java
rename to opends/src/server/org/opends/server/synchronization/plugin/Historical.java
index c780765..fe95ffa 100644
--- a/opends/src/server/org/opends/server/synchronization/Historical.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/Historical.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -38,6 +38,8 @@
 import org.opends.server.core.AddOperation;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.ModifyOperation;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.protocol.OperationContext;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
@@ -65,9 +67,18 @@
 
 public class Historical
 {
-  static final String HISTORICALATTRIBUTENAME = "ds-sync-hist";
-  static final AttributeType historicalAttrType =
+  /**
+   * The name of the attribute used to store historical information.
+   */
+  public static final String HISTORICALATTRIBUTENAME = "ds-sync-hist";
+
+  /**
+   * The AttributeType associated to the attribute used to store
+   * hitorical information.
+   */
+  public static final AttributeType historicalAttrType =
     DirectoryServer.getSchema().getAttributeType(HISTORICALATTRIBUTENAME);
+
   static final String ENTRYUIDNAME = "entryuuid";
   static final AttributeType entryuuidAttrType =
     DirectoryServer.getSchema().getAttributeType(ENTRYUIDNAME);
diff --git a/opends/src/server/org/opends/server/synchronization/HistoricalCsnOrderingMatchingRule.java b/opends/src/server/org/opends/server/synchronization/plugin/HistoricalCsnOrderingMatchingRule.java
similarity index 98%
rename from opends/src/server/org/opends/server/synchronization/HistoricalCsnOrderingMatchingRule.java
rename to opends/src/server/org/opends/server/synchronization/plugin/HistoricalCsnOrderingMatchingRule.java
index 2fde2b4..ad23fd8 100644
--- a/opends/src/server/org/opends/server/synchronization/HistoricalCsnOrderingMatchingRule.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/HistoricalCsnOrderingMatchingRule.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import org.opends.server.api.OrderingMatchingRule;
 import org.opends.server.config.ConfigEntry;
diff --git a/opends/src/server/org/opends/server/synchronization/ListenerThread.java b/opends/src/server/org/opends/server/synchronization/plugin/ListenerThread.java
similarity index 93%
rename from opends/src/server/org/opends/server/synchronization/ListenerThread.java
rename to opends/src/server/org/opends/server/synchronization/plugin/ListenerThread.java
index 1d9e66b..609df93 100644
--- a/opends/src/server/org/opends/server/synchronization/ListenerThread.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/ListenerThread.java
@@ -24,14 +24,15 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import static org.opends.server.loggers.Error.logError;
 import static org.opends.server.messages.MessageHandler.getMessage;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
 
 import org.opends.server.api.DirectoryThread;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 import org.opends.server.types.ErrorLogCategory;
 import org.opends.server.types.ErrorLogSeverity;
 
diff --git a/opends/src/server/org/opends/server/synchronization/ModifyFakeOperation.java b/opends/src/server/org/opends/server/synchronization/plugin/ModifyFakeOperation.java
similarity index 90%
rename from opends/src/server/org/opends/server/synchronization/ModifyFakeOperation.java
rename to opends/src/server/org/opends/server/synchronization/plugin/ModifyFakeOperation.java
index 24338df..bcdfb17 100644
--- a/opends/src/server/org/opends/server/synchronization/ModifyFakeOperation.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/ModifyFakeOperation.java
@@ -24,10 +24,13 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import java.util.ArrayList;
 
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.protocol.ModifyMsg;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
 import org.opends.server.types.DN;
 import org.opends.server.types.Modification;
 
diff --git a/opends/src/server/org/opends/server/synchronization/MultimasterSynchronization.java b/opends/src/server/org/opends/server/synchronization/plugin/MultimasterSynchronization.java
similarity index 96%
rename from opends/src/server/org/opends/server/synchronization/MultimasterSynchronization.java
rename to opends/src/server/org/opends/server/synchronization/plugin/MultimasterSynchronization.java
index 7369a49..0143f89 100644
--- a/opends/src/server/org/opends/server/synchronization/MultimasterSynchronization.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/MultimasterSynchronization.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -33,10 +33,12 @@
 import org.opends.server.api.ConfigChangeListener;
 import org.opends.server.api.ConfigDeleteListener;
 import org.opends.server.api.SynchronizationProvider;
-import org.opends.server.changelog.Changelog;
 import org.opends.server.config.ConfigEntry;
 import org.opends.server.config.ConfigException;
 import org.opends.server.core.AddOperation;
+import org.opends.server.synchronization.changelog.Changelog;
+import org.opends.server.synchronization.common.LogMessages;
+import org.opends.server.synchronization.common.ServerState;
 import org.opends.server.types.DN;
 import org.opends.server.core.DeleteOperation;
 import org.opends.server.types.DirectoryException;
@@ -49,7 +51,7 @@
 import org.opends.server.types.ResultCode;
 import org.opends.server.types.SynchronizationProviderResult;
 
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
 
 /**
  * This class is used to load the Synchronization code inside the JVM
@@ -93,7 +95,7 @@
   public void initializeSynchronizationProvider(ConfigEntry configEntry)
   throws ConfigException
   {
-    SynchMessages.registerMessages();
+    LogMessages.registerMessages();
 
     configEntry.registerAddListener(this);
     configEntry.registerDeleteListener(this);
@@ -469,6 +471,10 @@
       }
     } while (domain == null);
 
+    /*
+     * Don't apply synchronization to the special entry where the ServerState
+     * is stored.
+     */
     if ((domain!= null) && (domain.getServerStateDN().equals(dn)))
       return null;
 
diff --git a/opends/src/server/org/opends/server/synchronization/PendingChange.java b/opends/src/server/org/opends/server/synchronization/plugin/PendingChange.java
similarity index 94%
rename from opends/src/server/org/opends/server/synchronization/PendingChange.java
rename to opends/src/server/org/opends/server/synchronization/plugin/PendingChange.java
index f2e8509..328e7eb 100644
--- a/opends/src/server/org/opends/server/synchronization/PendingChange.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/PendingChange.java
@@ -24,9 +24,11 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import org.opends.server.core.Operation;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 
 /**
  * This class is use to store the list of operations currently
diff --git a/opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java b/opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java
new file mode 100644
index 0000000..f2c2d70
--- /dev/null
+++ b/opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java
@@ -0,0 +1,309 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+package org.opends.server.synchronization.plugin;
+
+import static org.opends.server.loggers.Error.logError;
+import static org.opends.server.messages.MessageHandler.getMessage;
+import static org.opends.server.synchronization.common.LogMessages.*;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.opends.server.core.AddOperation;
+import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.ModifyOperation;
+import org.opends.server.protocols.asn1.ASN1OctetString;
+import org.opends.server.protocols.internal.InternalClientConnection;
+import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.ldap.LDAPAttribute;
+import org.opends.server.protocols.ldap.LDAPException;
+import org.opends.server.protocols.ldap.LDAPFilter;
+import org.opends.server.protocols.ldap.LDAPModification;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.common.ServerState;
+import org.opends.server.types.Attribute;
+import org.opends.server.types.AttributeType;
+import org.opends.server.types.AttributeValue;
+import org.opends.server.types.Control;
+import org.opends.server.types.DN;
+import org.opends.server.types.DereferencePolicy;
+import org.opends.server.types.DirectoryException;
+import org.opends.server.types.ErrorLogCategory;
+import org.opends.server.types.ErrorLogSeverity;
+import org.opends.server.types.ModificationType;
+import org.opends.server.types.ResultCode;
+import org.opends.server.types.SearchResultEntry;
+import org.opends.server.types.SearchScope;
+
+/**
+ * This class implements a ServerState that is stored on the backends
+ * used to store the synchronized data and that is therefore persistent
+ * accross server reboot.
+ */
+public class PersistentServerState extends ServerState
+{
+   private DN baseDn;
+   private boolean savedStatus = true;
+   private InternalClientConnection conn =
+                                              new InternalClientConnection();
+   private ASN1OctetString serverStateAsn1Dn;
+   private DN serverStateDn;
+
+   /**
+    * The attribute name used to store the state in the backend.
+    */
+   protected static final String SYNCHRONIZATION_STATE = "ds-sync-state";
+
+  /**
+   * create a new ServerState.
+   * @param baseDn The baseDN for which the ServerState is created
+   */
+  public PersistentServerState(DN baseDn)
+  {
+    this.baseDn = baseDn;
+    serverStateAsn1Dn = new ASN1OctetString(
+        "dc=ffffffff-ffffffff-ffffffff-ffffffff,"
+        + baseDn.toString());
+    try
+    {
+      serverStateDn = DN.decode(serverStateAsn1Dn);
+    } catch (DirectoryException e)
+    {
+      // never happens
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public boolean update(ChangeNumber changeNumber)
+  {
+    savedStatus = false;
+    return super.update(changeNumber);
+  }
+
+  /**
+   * Save this object to persistent storage.
+   */
+  public void save()
+  {
+    if (savedStatus)
+      return;
+
+    savedStatus = true;
+
+    ArrayList<ASN1OctetString> values = this.toASN1ArrayList();
+
+    if (values.size() == 0)
+      return;
+
+    LDAPAttribute attr =
+      new LDAPAttribute(SYNCHRONIZATION_STATE, values);
+    LDAPModification mod = new LDAPModification(ModificationType.REPLACE, attr);
+    ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>(1);
+    mods.add(mod);
+
+    boolean done = false;
+    while (!done)
+    {
+      /*
+       * Generate a modify operation on the Server State Entry :
+       * cn=ffffffff-ffffffff-ffffffff-ffffffff, baseDn
+       */
+      ModifyOperation op =
+        new ModifyOperation(conn, InternalClientConnection.nextOperationID(),
+            InternalClientConnection.nextMessageID(),
+            new ArrayList<Control>(0), serverStateAsn1Dn,
+            mods);
+      op.setInternalOperation(true);
+      op.setSynchronizationOperation(true);
+
+      op.run();
+      ResultCode resultCode = op.getResultCode();
+      if (resultCode != ResultCode.SUCCESS)
+      {
+        if (resultCode == ResultCode.NO_SUCH_OBJECT)
+        {
+          createStateEntry();
+        }
+        else
+        {
+          savedStatus = false;
+          int msgID = MSGID_ERROR_UPDATING_RUV;
+          String message = getMessage(msgID,
+              op.getResultCode().getResultCodeName(),
+              op.toString(), op.getErrorMessage(),
+              baseDn.toString());
+          logError(ErrorLogCategory.SYNCHRONIZATION,
+              ErrorLogSeverity.SEVERE_ERROR,
+              message, msgID);
+          break;
+        }
+      }
+      else
+        done = true;
+    }
+  }
+
+  /**
+   * Load the ServerState from the backing entry in database to memory.
+   */
+  public void loadState()
+  {
+    /*
+     * Read the serverState from the database,
+     * If not there create empty entry
+     */
+    LDAPFilter filter;
+    try
+    {
+      filter = LDAPFilter.decode("objectclass=*");
+    } catch (LDAPException e)
+    {
+      // can not happen
+      return;
+    }
+
+    /*
+     * Search the database entry that is used to periodically
+     * save the ServerState
+     */
+    InternalSearchOperation search = conn.processSearch(serverStateAsn1Dn,
+        SearchScope.BASE_OBJECT,
+        DereferencePolicy.DEREF_ALWAYS, 0, 0, false,
+        filter,new LinkedHashSet<String>(0));
+    if (((search.getResultCode() != ResultCode.SUCCESS)) &&
+        ((search.getResultCode() != ResultCode.NO_SUCH_OBJECT)))
+    {
+      int msgID = MSGID_ERROR_SEARCHING_RUV;
+      String message = getMessage(msgID,
+          search.getResultCode().getResultCodeName(),
+          search.toString(), search.getErrorMessage(),
+          baseDn.toString());
+      logError(ErrorLogCategory.SYNCHRONIZATION, ErrorLogSeverity.SEVERE_ERROR,
+          message, msgID);
+    }
+
+    SearchResultEntry resultEntry = null;
+    if (search.getResultCode() == ResultCode.SUCCESS)
+    {
+      /*
+       * Read the serverState from the SYNCHRONIZATION_STATE attribute
+       */
+      LinkedList<SearchResultEntry> result = search.getSearchEntries();
+      resultEntry = result.getFirst();
+      if (resultEntry != null)
+      {
+        AttributeType synchronizationStateType =
+          DirectoryServer.getAttributeType(SYNCHRONIZATION_STATE);
+        List<Attribute> attrs =
+          resultEntry.getAttribute(synchronizationStateType);
+        if (attrs != null)
+        {
+          Attribute attr = attrs.get(0);
+          LinkedHashSet<AttributeValue> values = attr.getValues();
+          for (AttributeValue value : values)
+          {
+            ChangeNumber changeNumber =
+              new ChangeNumber(value.getStringValue());
+            update(changeNumber);
+          }
+        }
+      }
+
+      /*
+       * TODO : The ServerState is saved to the database periodically,
+       * therefore in case of crash it is possible that is does not contain
+       * the latest changes that have been processed and saved to the
+       * database.
+       * In order to make sure that we don't loose them, search all the entries
+       * that have been updated after this entry.
+       * This is done by using the HistoricalCsnOrderingMatchingRule
+       * and an ordering index for historical attribute
+       */
+    }
+
+    if ((resultEntry == null) ||
+        ((search.getResultCode() != ResultCode.SUCCESS)))
+    {
+      createStateEntry();
+    }
+  }
+
+  /**
+   * Create the Entry that will be used to store the ServerState information.
+   * It will be updated when the server stops and periodically.
+   */
+  private void createStateEntry()
+  {
+    ArrayList<LDAPAttribute> attrs = new ArrayList<LDAPAttribute>();
+
+    ArrayList<ASN1OctetString> values = new ArrayList<ASN1OctetString>();
+    ASN1OctetString value = new ASN1OctetString("extensibleObject");
+    values.add(value);
+    LDAPAttribute attr = new LDAPAttribute("objectClass", values);
+    value = new ASN1OctetString("domain");
+    values.add(value);
+    attr = new LDAPAttribute("objectClass", values);
+    attrs.add(attr);
+
+    values = new ArrayList<ASN1OctetString>();
+    value = new ASN1OctetString("ffffffff-ffffffff-ffffffff-ffffffff");
+    values.add(value);
+    attr = new LDAPAttribute("dc", values);
+    attrs.add(attr);
+
+    AddOperation add = conn.processAdd(serverStateAsn1Dn, attrs);
+    ResultCode resultCode = add.getResultCode();
+    if ((resultCode != ResultCode.SUCCESS) &&
+        (resultCode != ResultCode.NO_SUCH_OBJECT))
+    {
+      int msgID = MSGID_ERROR_UPDATING_RUV;
+      String message = getMessage(msgID,
+          add.getResultCode().getResultCodeName(),
+          add.toString(), add.getErrorMessage(),
+          baseDn.toString());
+      logError(ErrorLogCategory.SYNCHRONIZATION,
+          ErrorLogSeverity.SEVERE_ERROR,
+          message, msgID);
+    }
+  }
+
+  /**
+   * Get the Dn where the ServerState is stored.
+   * @return Returns the serverStateDn.
+   */
+  public DN getServerStateDn()
+  {
+    return serverStateDn;
+  }
+
+
+}
diff --git a/opends/src/server/org/opends/server/synchronization/SynchronizationDomain.java b/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
similarity index 97%
rename from opends/src/server/org/opends/server/synchronization/SynchronizationDomain.java
rename to opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
index 766359b..a11c2bd 100644
--- a/opends/src/server/org/opends/server/synchronization/SynchronizationDomain.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
@@ -24,15 +24,15 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
 import static org.opends.server.util.TimeThread.getTime;
-import static org.opends.server.synchronization.SynchMessages.*;
+import static org.opends.server.synchronization.common.LogMessages.*;
+import static org.opends.server.synchronization.plugin.Historical.*;
+import static org.opends.server.synchronization.protocol.OperationContext.*;
 import static org.opends.server.loggers.Error.*;
 import static org.opends.server.messages.MessageHandler.*;
-import static org.opends.server.synchronization.OperationContext.SYNCHROCONTEXT;
-import static org.opends.server.synchronization.Historical.*;
 
 import java.net.SocketTimeoutException;
 import java.util.ArrayList;
@@ -63,6 +63,18 @@
 import org.opends.server.protocols.internal.InternalClientConnection;
 import org.opends.server.protocols.internal.InternalSearchOperation;
 import org.opends.server.protocols.ldap.LDAPException;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.common.ChangeNumberGenerator;
+import org.opends.server.synchronization.common.ServerState;
+import org.opends.server.synchronization.protocol.AckMessage;
+import org.opends.server.synchronization.protocol.AddContext;
+import org.opends.server.synchronization.protocol.DeleteContext;
+import org.opends.server.synchronization.protocol.ModifyContext;
+import org.opends.server.synchronization.protocol.ModifyDNMsg;
+import org.opends.server.synchronization.protocol.ModifyDnContext;
+import org.opends.server.synchronization.protocol.OperationContext;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 import org.opends.server.types.ConfigChangeResult;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.DN;
@@ -103,7 +115,7 @@
   private int numSentUpdates = 0;
   private int numProcessedUpdates = 0;
   private int debugCount = 0;
-  private ServerState state;
+  private PersistentServerState state;
   private int numReplayedPostOpCalled = 0;
 
   private int maxReceiveQueue = 0;
@@ -204,7 +216,7 @@
       baseDN = baseDn.activeValue();
     configAttributes.add(baseDn);
 
-    state = new ServerState(baseDN);
+    state = new PersistentServerState(baseDN);
     state.loadState();
 
     /*
@@ -704,7 +716,16 @@
             return null;
           }
 
-          update = msg.processReceive(this);
+          if (msg instanceof AckMessage)
+          {
+            AckMessage ack = (AckMessage) msg;
+            receiveAck(ack);
+          }
+          else if (msg instanceof UpdateMessage)
+          {
+            update = (UpdateMessage) msg;
+            receiveUpdate(update);
+          }
         } catch (SocketTimeoutException e)
         {
           // just retry
diff --git a/opends/src/server/org/opends/server/synchronization/SynchronizationMonitor.java b/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationMonitor.java
similarity index 98%
rename from opends/src/server/org/opends/server/synchronization/SynchronizationMonitor.java
rename to opends/src/server/org/opends/server/synchronization/plugin/SynchronizationMonitor.java
index c59ecec..1b8ae4b 100644
--- a/opends/src/server/org/opends/server/synchronization/SynchronizationMonitor.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationMonitor.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import java.util.ArrayList;
 import java.util.LinkedHashSet;
diff --git a/opends/src/server/org/opends/server/synchronization/ValueInfo.java b/opends/src/server/org/opends/server/synchronization/plugin/ValueInfo.java
similarity index 96%
rename from opends/src/server/org/opends/server/synchronization/ValueInfo.java
rename to opends/src/server/org/opends/server/synchronization/plugin/ValueInfo.java
index 245f044..e1ed7a8 100644
--- a/opends/src/server/org/opends/server/synchronization/ValueInfo.java
+++ b/opends/src/server/org/opends/server/synchronization/plugin/ValueInfo.java
@@ -24,8 +24,9 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
+import org.opends.server.synchronization.common.ChangeNumber;
 import org.opends.server.types.AttributeValue;
 
 /**
diff --git a/opends/src/server/org/opends/server/synchronization/plugin/package-info.java b/opends/src/server/org/opends/server/synchronization/plugin/package-info.java
new file mode 100644
index 0000000..51330f9
--- /dev/null
+++ b/opends/src/server/org/opends/server/synchronization/plugin/package-info.java
@@ -0,0 +1,50 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+
+/**
+ * This package contains the part of the Multimaster
+ * synchronization code that works on the Directory Server side.
+ * <br>
+ * The main classes of this core are :
+ * <ul>
+ * <li>
+ * <A HREF="MultimasterSynchronization.html"><B>MultimasterSynchronization
+ * </B></A>contains the synchronization provider
+ * code and more generally all the code that makes the glue between the core
+ * server and the synchronization code.
+ * </li>
+ * <li>
+ * <A HREF="SynchronizationDomain.html"><B>SynchronizationDomain</B></A>
+ * contains the bulk of the Directory Server side of the
+ * synchronization code. Most notably it contains the root method for
+ * publishing a change, processing a change received from the changelog
+ * service, handle conflict resolution, handle protocol messages from the
+ * changelog server.
+ * </li>
+ * </ul>
+ */
+package org.opends.server.synchronization.plugin;
diff --git a/opends/src/server/org/opends/server/synchronization/AckMessage.java b/opends/src/server/org/opends/server/synchronization/protocol/AckMessage.java
similarity index 88%
rename from opends/src/server/org/opends/server/synchronization/AckMessage.java
rename to opends/src/server/org/opends/server/synchronization/protocol/AckMessage.java
index f1e72d5..cb35f38 100644
--- a/opends/src/server/org/opends/server/synchronization/AckMessage.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/AckMessage.java
@@ -24,19 +24,18 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
-import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.util.zip.DataFormatException;
 
+import org.opends.server.synchronization.common.ChangeNumber;
+
 /**
  * Used to send acks between LDAP and changelog servers.
  */
-public class AckMessage extends SynchronizationMessage implements Serializable
+public class AckMessage extends SynchronizationMessage
 {
-  private static final long serialVersionUID = -8695651898339602441L;
-
   // ChangeNumber of the update that was acked.
   private ChangeNumber changeNumber;
 
@@ -92,16 +91,6 @@
    * {@inheritDoc}
    */
   @Override
-  public UpdateMessage processReceive(SynchronizationDomain domain)
-  {
-    domain.receiveAck(this);
-    return null;
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override
   public byte[] getBytes()
   {
     try
diff --git a/opends/src/server/org/opends/server/synchronization/AddContext.java b/opends/src/server/org/opends/server/synchronization/protocol/AddContext.java
similarity index 93%
rename from opends/src/server/org/opends/server/synchronization/AddContext.java
rename to opends/src/server/org/opends/server/synchronization/protocol/AddContext.java
index c736429..9859af9 100644
--- a/opends/src/server/org/opends/server/synchronization/AddContext.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/AddContext.java
@@ -24,7 +24,9 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
+
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * This class describe the Synchronization contexte that is attached to
diff --git a/opends/src/server/org/opends/server/synchronization/AddMsg.java b/opends/src/server/org/opends/server/synchronization/protocol/AddMsg.java
similarity index 97%
rename from opends/src/server/org/opends/server/synchronization/AddMsg.java
rename to opends/src/server/org/opends/server/synchronization/protocol/AddMsg.java
index a69c8b9..6cc8fb2 100644
--- a/opends/src/server/org/opends/server/synchronization/AddMsg.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/AddMsg.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
 import org.opends.server.core.AddOperation;
 import org.opends.server.core.DirectoryServer;
@@ -42,10 +42,11 @@
 import org.opends.server.protocols.internal.InternalClientConnection;
 import org.opends.server.protocols.ldap.LDAPAttribute;
 import org.opends.server.protocols.ldap.LDAPException;
+import org.opends.server.synchronization.common.ChangeNumber;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.AttributeValue;
 
-import static org.opends.server.synchronization.OperationContext.*;
+import static org.opends.server.synchronization.protocol.OperationContext.*;
 import static org.opends.server.util.StaticUtils.toLowerCase;
 
 /**
diff --git a/opends/src/server/org/opends/server/synchronization/ChangelogStartMessage.java b/opends/src/server/org/opends/server/synchronization/protocol/ChangelogStartMessage.java
similarity index 96%
rename from opends/src/server/org/opends/server/synchronization/ChangelogStartMessage.java
rename to opends/src/server/org/opends/server/synchronization/protocol/ChangelogStartMessage.java
index 2767579..2684c12 100644
--- a/opends/src/server/org/opends/server/synchronization/ChangelogStartMessage.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/ChangelogStartMessage.java
@@ -24,12 +24,13 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.util.zip.DataFormatException;
 
+import org.opends.server.synchronization.common.ServerState;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.DN;
 
@@ -178,16 +179,6 @@
    * {@inheritDoc}
    */
   @Override
-  public UpdateMessage processReceive(SynchronizationDomain domain)
-  {
-    // This is currently not used.
-    return null;
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override
   public byte[] getBytes()
   {
     /* The ChangelogStartMessage is stored in the form :
diff --git a/opends/src/server/org/opends/server/synchronization/DeleteContext.java b/opends/src/server/org/opends/server/synchronization/protocol/DeleteContext.java
similarity index 92%
rename from opends/src/server/org/opends/server/synchronization/DeleteContext.java
rename to opends/src/server/org/opends/server/synchronization/protocol/DeleteContext.java
index f99ff0f..ae1dabc 100644
--- a/opends/src/server/org/opends/server/synchronization/DeleteContext.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/DeleteContext.java
@@ -24,7 +24,9 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
+
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * This class is used to describe the context attached to a Delete Operation.
diff --git a/opends/src/server/org/opends/server/synchronization/DeleteMsg.java b/opends/src/server/org/opends/server/synchronization/protocol/DeleteMsg.java
similarity index 94%
rename from opends/src/server/org/opends/server/synchronization/DeleteMsg.java
rename to opends/src/server/org/opends/server/synchronization/protocol/DeleteMsg.java
index 1d288e5..e3d17b4 100644
--- a/opends/src/server/org/opends/server/synchronization/DeleteMsg.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/DeleteMsg.java
@@ -24,9 +24,9 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
-import static org.opends.server.synchronization.OperationContext.*;
+import static org.opends.server.synchronization.protocol.OperationContext.*;
 
 import java.io.UnsupportedEncodingException;
 import java.util.zip.DataFormatException;
@@ -35,6 +35,7 @@
 import org.opends.server.core.Operation;
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.protocols.internal.InternalClientConnection;
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * Object used when sending delete information to Changelogs.
diff --git a/opends/src/server/org/opends/server/synchronization/ModifyContext.java b/opends/src/server/org/opends/server/synchronization/protocol/ModifyContext.java
similarity index 92%
rename from opends/src/server/org/opends/server/synchronization/ModifyContext.java
rename to opends/src/server/org/opends/server/synchronization/protocol/ModifyContext.java
index b89edac..93f9f32 100644
--- a/opends/src/server/org/opends/server/synchronization/ModifyContext.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/ModifyContext.java
@@ -24,7 +24,9 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
+
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * This class describe the synchronization context that is attached to
diff --git a/opends/src/server/org/opends/server/synchronization/ModifyDNMsg.java b/opends/src/server/org/opends/server/synchronization/protocol/ModifyDNMsg.java
similarity index 97%
rename from opends/src/server/org/opends/server/synchronization/ModifyDNMsg.java
rename to opends/src/server/org/opends/server/synchronization/protocol/ModifyDNMsg.java
index 6436bc4..42b00fe 100644
--- a/opends/src/server/org/opends/server/synchronization/ModifyDNMsg.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/ModifyDNMsg.java
@@ -24,9 +24,9 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
-import static org.opends.server.synchronization.OperationContext.*;
+import static org.opends.server.synchronization.protocol.OperationContext.*;
 
 import java.io.UnsupportedEncodingException;
 import java.util.zip.DataFormatException;
@@ -35,6 +35,7 @@
 import org.opends.server.core.Operation;
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.protocols.internal.InternalClientConnection;
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * Message used to send Modify DN information.
diff --git a/opends/src/server/org/opends/server/synchronization/ModifyDnContext.java b/opends/src/server/org/opends/server/synchronization/protocol/ModifyDnContext.java
similarity index 94%
rename from opends/src/server/org/opends/server/synchronization/ModifyDnContext.java
rename to opends/src/server/org/opends/server/synchronization/protocol/ModifyDnContext.java
index e6cde3e..3847c43 100644
--- a/opends/src/server/org/opends/server/synchronization/ModifyDnContext.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/ModifyDnContext.java
@@ -24,7 +24,9 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
+
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * This class describe the synchronization context that is attached to
diff --git a/opends/src/server/org/opends/server/synchronization/ModifyMsg.java b/opends/src/server/org/opends/server/synchronization/protocol/ModifyMsg.java
similarity index 96%
rename from opends/src/server/org/opends/server/synchronization/ModifyMsg.java
rename to opends/src/server/org/opends/server/synchronization/protocol/ModifyMsg.java
index 0156287..47f2b3b 100644
--- a/opends/src/server/org/opends/server/synchronization/ModifyMsg.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/ModifyMsg.java
@@ -24,9 +24,9 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
-import static org.opends.server.synchronization.OperationContext.*;
+import static org.opends.server.synchronization.protocol.OperationContext.*;
 
 import org.opends.server.core.ModifyOperation;
 import org.opends.server.core.Operation;
@@ -37,6 +37,8 @@
 import org.opends.server.protocols.ldap.LDAPModification;
 import org.opends.server.protocols.asn1.ASN1Element;
 import org.opends.server.protocols.internal.InternalClientConnection;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.plugin.Historical;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.DN;
 import org.opends.server.types.Modification;
diff --git a/opends/src/server/org/opends/server/synchronization/OperationContext.java b/opends/src/server/org/opends/server/synchronization/protocol/OperationContext.java
similarity index 96%
rename from opends/src/server/org/opends/server/synchronization/OperationContext.java
rename to opends/src/server/org/opends/server/synchronization/protocol/OperationContext.java
index fb48525..e88e32a 100644
--- a/opends/src/server/org/opends/server/synchronization/OperationContext.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/OperationContext.java
@@ -24,9 +24,10 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
 import org.opends.server.core.Operation;
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * This class describe the Synchronization context that is attached
diff --git a/opends/src/server/org/opends/server/changelog/ProtocolSession.java b/opends/src/server/org/opends/server/synchronization/protocol/ProtocolSession.java
similarity index 97%
rename from opends/src/server/org/opends/server/changelog/ProtocolSession.java
rename to opends/src/server/org/opends/server/synchronization/protocol/ProtocolSession.java
index 1448e47..7da612d 100644
--- a/opends/src/server/org/opends/server/changelog/ProtocolSession.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/ProtocolSession.java
@@ -24,14 +24,12 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.protocol;
 
 import java.io.IOException;
 import java.net.SocketException;
 import java.util.zip.DataFormatException;
 
-import org.opends.server.synchronization.SynchronizationMessage;
-
 /**
  * The ProtocolSession interface should be implemented by a class that
  * implement the send/reception part of the Multimaster synchronization
diff --git a/opends/src/server/org/opends/server/synchronization/ServerStartMessage.java b/opends/src/server/org/opends/server/synchronization/protocol/ServerStartMessage.java
similarity index 97%
rename from opends/src/server/org/opends/server/synchronization/ServerStartMessage.java
rename to opends/src/server/org/opends/server/synchronization/protocol/ServerStartMessage.java
index a93d6ee..48b6c74 100644
--- a/opends/src/server/org/opends/server/synchronization/ServerStartMessage.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/ServerStartMessage.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
@@ -32,6 +32,7 @@
 import java.net.UnknownHostException;
 import java.util.zip.DataFormatException;
 
+import org.opends.server.synchronization.common.ServerState;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.DN;
 
@@ -263,18 +264,6 @@
    * {@inheritDoc}
    */
   @Override
-  public UpdateMessage processReceive(SynchronizationDomain domain)
-  {
-    /*
-     * This is currently not used.
-     */
-    return null;
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override
   public byte[] getBytes()
   {
     /*
diff --git a/opends/src/server/org/opends/server/changelog/SocketSession.java b/opends/src/server/org/opends/server/synchronization/protocol/SocketSession.java
similarity index 97%
rename from opends/src/server/org/opends/server/changelog/SocketSession.java
rename to opends/src/server/org/opends/server/synchronization/protocol/SocketSession.java
index 13708ad..08f8285 100644
--- a/opends/src/server/org/opends/server/changelog/SocketSession.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/SocketSession.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.changelog;
+package org.opends.server.synchronization.protocol;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -33,8 +33,6 @@
 import java.net.SocketException;
 import java.util.zip.DataFormatException;
 
-import org.opends.server.synchronization.SynchronizationMessage;
-
 /**
  * This class Implement a protocol session using a basic socket and relying on
  * the innate encoding/decoding capabilities of the SynchronizationMessage
diff --git a/opends/src/server/org/opends/server/synchronization/SynchronizationMessage.java b/opends/src/server/org/opends/server/synchronization/protocol/SynchronizationMessage.java
similarity index 91%
rename from opends/src/server/org/opends/server/synchronization/SynchronizationMessage.java
rename to opends/src/server/org/opends/server/synchronization/protocol/SynchronizationMessage.java
index 800bf39..77dcc1b 100644
--- a/opends/src/server/org/opends/server/synchronization/SynchronizationMessage.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/SynchronizationMessage.java
@@ -24,9 +24,8 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
-import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.util.zip.DataFormatException;
 
@@ -37,7 +36,7 @@
  * When extending this class one should also create a new MSG_TYPE
  * and should update the generateMsg() method.
  */
-public abstract class SynchronizationMessage implements Serializable
+public abstract class SynchronizationMessage
 {
   static final byte MSG_TYPE_MODIFY_REQUEST = 1;
   static final byte MSG_TYPE_ADD_REQUEST = 2;
@@ -49,14 +48,6 @@
   static final byte MSG_TYPE_WINDOW = 8;
 
   /**
-   * Do the processing necessary when the message is received.
-   *
-   * @param domain The Synchronization domain where the messages was received.
-   * @return an UpdateMessage if the processing result is an UpdateMessage.
-   */
-  public abstract UpdateMessage processReceive(SynchronizationDomain domain);
-
-  /**
    * Return the byte[] representation of this message.
    * Depending on the message type, the first byte of the byte[] must be.
    * MSG_TYPE_MODIFY_REQUEST
diff --git a/opends/src/server/org/opends/server/synchronization/UpdateMessage.java b/opends/src/server/org/opends/server/synchronization/protocol/UpdateMessage.java
similarity index 97%
rename from opends/src/server/org/opends/server/synchronization/UpdateMessage.java
rename to opends/src/server/org/opends/server/synchronization/protocol/UpdateMessage.java
index 2d4d550..287122c 100644
--- a/opends/src/server/org/opends/server/synchronization/UpdateMessage.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/UpdateMessage.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
@@ -38,6 +38,7 @@
 import org.opends.server.protocols.asn1.ASN1Exception;
 import org.opends.server.protocols.internal.InternalClientConnection;
 import org.opends.server.protocols.ldap.LDAPException;
+import org.opends.server.synchronization.common.ChangeNumber;
 
 /**
  * Abstract class that must be extended to define a message
@@ -359,13 +360,4 @@
     }
 
   }
-  /**
-   * {@inheritDoc}
-   */
-  @Override
-  public UpdateMessage processReceive(SynchronizationDomain domain)
-  {
-    domain.receiveUpdate(this);
-    return this;
-  }
 }
diff --git a/opends/src/server/org/opends/server/synchronization/WindowMessage.java b/opends/src/server/org/opends/server/synchronization/protocol/WindowMessage.java
similarity index 94%
rename from opends/src/server/org/opends/server/synchronization/WindowMessage.java
rename to opends/src/server/org/opends/server/synchronization/protocol/WindowMessage.java
index 868bd12..e2e5f92 100644
--- a/opends/src/server/org/opends/server/synchronization/WindowMessage.java
+++ b/opends/src/server/org/opends/server/synchronization/protocol/WindowMessage.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
@@ -130,12 +130,4 @@
     return numAck;
   }
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override
-  public UpdateMessage processReceive(SynchronizationDomain domain)
-  {
-    return null;
-  }
 }
diff --git a/opends/src/server/org/opends/server/synchronization/protocol/package-info.java b/opends/src/server/org/opends/server/synchronization/protocol/package-info.java
new file mode 100644
index 0000000..705ffcd
--- /dev/null
+++ b/opends/src/server/org/opends/server/synchronization/protocol/package-info.java
@@ -0,0 +1,51 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+
+/**
+ * This package contains the code used by the changelog and by the
+ * code running on the Directory Server side to exchange their information.
+ * <br>
+ * <br>
+ * The main classes of this packages are :
+ * <br>
+ * <ul>
+ * <li><A HREF="SocketSession.html"><B>SocketSession</B></A>
+ * implements the ProtocolSession interface that is
+ * used by the changelog server and the directory server to communicate.
+ * This is done by using the innate encoding/decoding capabilities of the
+ * SynchronizationMessages objects. This class is used by both the
+ * changelog and the synchronization package.
+ * </li>
+ * <li><A HREF="SynchronizationMessage.html"><B>SynchronizationMessage</B></A>
+ * This class and the class that inherit from it contain the
+ * messages that are used for communication between the changelog and the
+ * Directory Server as well as the methods fro encoding/decoding them.
+ * </li>
+ *  </ul>
+ */
+
+package org.opends.server.synchronization.protocol;
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/changelog/UpdateComparatorTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/changelog/UpdateComparatorTest.java
index 12f0a47..11ad842 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/changelog/UpdateComparatorTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/changelog/UpdateComparatorTest.java
@@ -29,16 +29,17 @@
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
-import static org.opends.server.synchronization.OperationContext.SYNCHROCONTEXT;
+import static org.opends.server.synchronization.protocol.OperationContext.SYNCHROCONTEXT;
 import static org.testng.Assert.*;
 
 
 import org.opends.server.core.DeleteOperation;
 import org.opends.server.protocols.internal.InternalClientConnection;
-import org.opends.server.synchronization.ChangeNumber;
-import org.opends.server.synchronization.DeleteContext;
-import org.opends.server.synchronization.DeleteMsg;
-import org.opends.server.synchronization.UpdateMessage;
+import org.opends.server.synchronization.changelog.UpdateComparator;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.protocol.DeleteContext;
+import org.opends.server.synchronization.protocol.DeleteMsg;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.DN;
 import org.opends.server.util.TimeThread;
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java
index f73ca4b..69dd07f 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java
@@ -49,6 +49,11 @@
 import org.opends.server.core.ModifyOperation;
 import org.opends.server.core.Operation;
 import org.opends.server.protocols.internal.InternalClientConnection;
+import org.opends.server.synchronization.plugin.ChangelogBroker;
+import org.opends.server.synchronization.plugin.MultimasterSynchronization;
+import org.opends.server.synchronization.plugin.PersistentServerState;
+import org.opends.server.synchronization.protocol.AddMsg;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
@@ -397,7 +402,7 @@
   private ChangelogBroker openChangelogSession(final DN baseDn, short serverId)
           throws Exception, SocketException
   {
-    ServerState state = new ServerState(baseDn);
+    PersistentServerState state = new PersistentServerState(baseDn);
     state.loadState();
     ChangelogBroker broker = new ChangelogBroker(state, baseDn,
                                                  serverId, 0, 0, 0, 0, 100);
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java
index 245cf7b..072dc0f 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java
@@ -39,6 +39,15 @@
 import org.opends.server.plugins.ShortCircuitPlugin;
 import org.opends.server.schema.DirectoryStringSyntax;
 import org.opends.server.schema.IntegerSyntax;
+import org.opends.server.synchronization.common.ChangeNumberGenerator;
+import org.opends.server.synchronization.plugin.ChangelogBroker;
+import org.opends.server.synchronization.plugin.MultimasterSynchronization;
+import org.opends.server.synchronization.plugin.PersistentServerState;
+import org.opends.server.synchronization.protocol.AddMsg;
+import org.opends.server.synchronization.protocol.DeleteMsg;
+import org.opends.server.synchronization.protocol.ModifyDNMsg;
+import org.opends.server.synchronization.protocol.ModifyMsg;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
 import org.opends.server.config.ConfigEntry;
 import org.opends.server.config.ConfigException;
 import org.opends.server.core.AddOperation;
@@ -857,7 +866,7 @@
   private ChangelogBroker openChangelogSession(final DN baseDn, short serverId)
           throws Exception, SocketException
   {
-    ServerState state = new ServerState(baseDn);
+    PersistentServerState state = new PersistentServerState(baseDn);
     state.loadState();
     ChangelogBroker broker = new ChangelogBroker(state, baseDn,
                                                  serverId, 0, 0, 0, 0, 100);
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ChangeNumberTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ChangeNumberTest.java
similarity index 96%
rename from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ChangeNumberTest.java
rename to opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ChangeNumberTest.java
index dafe316..07f1fc5 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ChangeNumberTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ChangeNumberTest.java
@@ -24,13 +24,16 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.common;
 
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 import static org.testng.Assert.*;
 
 
+import org.opends.server.synchronization.SynchronizationTestCase;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.common.ChangeNumberGenerator;
 import org.opends.server.util.TimeThread;
 
 
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ServerStateTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ServerStateTest.java
similarity index 89%
rename from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ServerStateTest.java
rename to opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ServerStateTest.java
index 8576d1a..d514805 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ServerStateTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ServerStateTest.java
@@ -24,13 +24,15 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.common;
 
 import static org.testng.Assert.*;
 
 import java.util.Set;
 
-import org.opends.server.types.DN;
+import org.opends.server.synchronization.SynchronizationTestCase;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.common.ServerState;
 import org.opends.server.util.TimeThread;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
@@ -60,17 +62,11 @@
          throws Exception
   {
     // Check constructor
-    DN dn = DN.decode("cn=com");
-    ServerState serverState = new ServerState(dn) ;
+    ServerState serverState = new ServerState() ;
 
     // Check Load
     // serverState.loadState() ;
-    // TODO Check result
-
-    // Check getServerStateDn()
-    DN returned_DN = serverState.getServerStateDn();
-    // Check that the returned DN stays below dn
-    assertTrue(dn.isAncestorOf(returned_DN));
+    // TODO Check result;
 
     // Check update
     assertFalse(serverState.update(null));
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/AttrInfoTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/AttrInfoTest.java
similarity index 94%
rename from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/AttrInfoTest.java
rename to opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/AttrInfoTest.java
index 7022218..e5542af 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/AttrInfoTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/AttrInfoTest.java
@@ -24,12 +24,16 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import java.util.ArrayList;
 import java.util.LinkedHashSet;
 
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.synchronization.SynchronizationTestCase;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.plugin.AttrInfo;
+import org.opends.server.synchronization.plugin.ValueInfo;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
 import org.opends.server.util.TimeThread;
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ModifyConflictTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ModifyConflictTest.java
similarity index 95%
rename from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ModifyConflictTest.java
rename to opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ModifyConflictTest.java
index 192cc39..9fc61f1 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ModifyConflictTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ModifyConflictTest.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -36,13 +36,21 @@
 import org.testng.annotations.Test;
 import static org.testng.Assert.*;
 
-import static org.opends.server.synchronization.OperationContext.*;
+import static org.opends.server.synchronization.protocol.OperationContext.*;
 
 import org.opends.server.core.AddOperation;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.ModifyOperation;
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.protocols.internal.InternalClientConnection;
+import org.opends.server.synchronization.SynchronizationTestCase;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.plugin.FakeOperation;
+import org.opends.server.synchronization.plugin.FakeOperationComparator;
+import org.opends.server.synchronization.plugin.Historical;
+import org.opends.server.synchronization.protocol.ModifyContext;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
+import org.opends.server.synchronization.protocol.UpdateMessage;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ValueInfoTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ValueInfoTest.java
similarity index 93%
rename from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ValueInfoTest.java
rename to opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ValueInfoTest.java
index 0a1bc9e..9869e86 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ValueInfoTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ValueInfoTest.java
@@ -24,9 +24,12 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.plugin;
 
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.synchronization.SynchronizationTestCase;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.plugin.ValueInfo;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
 import org.opends.server.util.TimeThread;
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ProtocolWindowTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/ProtocolWindowTest.java
similarity index 96%
rename from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ProtocolWindowTest.java
rename to opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/ProtocolWindowTest.java
index e0a952e..ce766ae 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ProtocolWindowTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/ProtocolWindowTest.java
@@ -25,7 +25,7 @@
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
 
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
 import static org.opends.server.loggers.Error.logError;
 import static org.testng.Assert.*;
@@ -49,6 +49,12 @@
 import org.opends.server.protocols.internal.InternalSearchOperation;
 import org.opends.server.protocols.ldap.LDAPException;
 import org.opends.server.protocols.ldap.LDAPFilter;
+import org.opends.server.synchronization.common.ServerState;
+import org.opends.server.synchronization.plugin.ChangelogBroker;
+import org.opends.server.synchronization.plugin.MultimasterSynchronization;
+import org.opends.server.synchronization.plugin.PersistentServerState;
+import org.opends.server.synchronization.protocol.AddMsg;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
@@ -409,7 +415,7 @@
   private ChangelogBroker openChangelogSession(final DN baseDn, short serverId)
           throws Exception, SocketException
   {
-    ServerState state = new ServerState(baseDn);
+    PersistentServerState state = new PersistentServerState(baseDn);
     state.loadState();
     ChangelogBroker broker =
       new ChangelogBroker(state, baseDn, serverId, 0, 0, 0, 0, WINDOW_SIZE);
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/SyncMessagesTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SyncMessagesTest.java
similarity index 83%
rename from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/SyncMessagesTest.java
rename to opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SyncMessagesTest.java
index faea894..d1b59c9 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/SyncMessagesTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SyncMessagesTest.java
@@ -24,11 +24,13 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
 import java.lang.reflect.Field;
 
 import org.opends.server.messages.MessageHandler;
+import org.opends.server.synchronization.SynchronizationTestCase;
+import org.opends.server.synchronization.common.LogMessages;
 import org.testng.annotations.Test;
 import static org.testng.Assert.*;
 
@@ -45,9 +47,9 @@
   public void synchroMessagesTest()
          throws Exception
   {
-    SynchMessages.registerMessages() ;
-    Field fields[] = SynchMessages.class.getFields() ;
-    SynchMessages synMsg = new SynchMessages() ;
+    LogMessages.registerMessages() ;
+    Field fields[] = LogMessages.class.getFields() ;
+    LogMessages synMsg = new LogMessages() ;
     for (Field f : fields)
     {
       if (f.getClass().equals(Integer.class))
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/SynchronizationMsgTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SynchronizationMsgTest.java
similarity index 94%
rename from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/SynchronizationMsgTest.java
rename to opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SynchronizationMsgTest.java
index 8ccc759..01a0c91 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/SynchronizationMsgTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SynchronizationMsgTest.java
@@ -24,7 +24,7 @@
  *
  *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
-package org.opends.server.synchronization;
+package org.opends.server.synchronization.protocol;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -44,7 +44,20 @@
 import org.opends.server.core.ModifyOperation;
 import org.opends.server.core.Operation;
 import org.opends.server.protocols.internal.InternalClientConnection;
-import org.opends.server.synchronization.ModifyMsg;
+import org.opends.server.synchronization.SynchronizationTestCase;
+import org.opends.server.synchronization.common.ChangeNumber;
+import org.opends.server.synchronization.common.ServerState;
+import org.opends.server.synchronization.plugin.PendingChange;
+import org.opends.server.synchronization.protocol.AckMessage;
+import org.opends.server.synchronization.protocol.AddMsg;
+import org.opends.server.synchronization.protocol.ChangelogStartMessage;
+import org.opends.server.synchronization.protocol.DeleteMsg;
+import org.opends.server.synchronization.protocol.ModifyDNMsg;
+import org.opends.server.synchronization.protocol.ModifyMsg;
+import org.opends.server.synchronization.protocol.ServerStartMessage;
+import org.opends.server.synchronization.protocol.SynchronizationMessage;
+import org.opends.server.synchronization.protocol.UpdateMessage;
+import org.opends.server.synchronization.protocol.WindowMessage;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
@@ -56,7 +69,7 @@
 import org.opends.server.types.RDN;
 import org.opends.server.util.TimeThread;
 
-import static org.opends.server.synchronization.OperationContext.*;
+import static org.opends.server.synchronization.protocol.OperationContext.*;
 
 /**
  * Test the contructors, encoders and decoders of the synchronization
@@ -443,7 +456,7 @@
   public Object [][] createServerStartMessageTestData() throws Exception
   {
     DN baseDN = DN.decode("dc=example, dc=com");
-    ServerState state = new ServerState(baseDN);
+    ServerState state = new ServerState();
     return new Object [][] { {(short)1, baseDN, 100, state} };
   }
   /**
@@ -470,7 +483,7 @@
   public Object [][] createChangelogStartMessageTestData() throws Exception
   {
     DN baseDN = DN.decode("dc=example, dc=com");
-    ServerState state = new ServerState(baseDN);
+    ServerState state = new ServerState();
     return new Object [][] { {(short)1, baseDN, 100, "localhost:8989", state} };
   }
   

--
Gitblit v1.10.0