mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

gbellato
13.31.2006 e07cdcbd253fd366c5002f7368470e0158bfcc2c
Fix for 982 : reorganize synchronization code :

before synchronization code was in 2 packages :
org.opends.server.synchronization and org.opends.server.changelog

It was not clear that the code in the changelog package is part of the synchronization
also some code in both of these packages are actually used by both sides of the synchronization.

To make this better (and as said in the synchronization meeting) the code is now split in 4
packages that are all below : org.opends.server.synchronization
- synchronization.changelog contain the code running on the changelog side
- synchronization.plugin contain the code running on the DS side.
- synchronization.protocol contain the code used by both side to exchange information.
- synchronization.common contain utilities that can be used by any of the first 3 packages.

Hopefully this should make the synchronization code more easy to understand.
1 files copied
2 files deleted
4 files added
63 files renamed
4 files modified
1920 ■■■■ changed files
opends/src/server/org/opends/server/changelog/SerializingProtocolSession.java 122 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/ServerState.java 519 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/AckMessageList.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/AckMessageListComparator.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/Changelog.java 5 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ChangelogAckMessageList.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ChangelogCache.java 14 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ChangelogDB.java 8 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ChangelogData.java 7 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ChangelogDbEnv.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ChangelogIterator.java 8 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ChangelogIteratorComparator.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ChangelogKey.java 5 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/DbHandler.java 10 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/MsgQueue.java 6 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ServerHandler.java 21 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ServerReader.java 13 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ServerWriter.java 7 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/UpdateComparator.java 7 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/package-info.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/common/ChangeNumber.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/common/ChangeNumberGenerator.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/common/LogMessages.java 6 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/common/ServerState.java 284 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/common/package-info.java 34 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/package-info.java 41 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/AttrInfo.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/AttrInfoWithOptions.java 3 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/ChangelogBroker.java 15 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/FakeOperation.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/FakeOperationComparator.java 3 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/HistKey.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/HistVal.java 3 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/Historical.java 17 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/HistoricalCsnOrderingMatchingRule.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/ListenerThread.java 5 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/ModifyFakeOperation.java 5 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/MultimasterSynchronization.java 14 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/PendingChange.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java 309 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java 35 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/SynchronizationMonitor.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/ValueInfo.java 3 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/package-info.java 50 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/AckMessage.java 19 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/AddContext.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/AddMsg.java 5 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/ChangelogStartMessage.java 13 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/DeleteContext.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/DeleteMsg.java 5 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/ModifyContext.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/ModifyDNMsg.java 5 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/ModifyDnContext.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/ModifyMsg.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/OperationContext.java 3 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/ProtocolSession.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/ServerStartMessage.java 15 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/SocketSession.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/SynchronizationMessage.java 13 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/UpdateMessage.java 12 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/WindowMessage.java 10 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/protocol/package-info.java 51 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/changelog/UpdateComparatorTest.java 11 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java 7 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java 11 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ChangeNumberTest.java 5 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ServerStateTest.java 16 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/AttrInfoTest.java 6 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ModifyConflictTest.java 12 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ValueInfoTest.java 5 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/ProtocolWindowTest.java 10 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SyncMessagesTest.java 10 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SynchronizationMsgTest.java 23 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/changelog/SerializingProtocolSession.java
File was deleted
opends/src/server/org/opends/server/synchronization/ServerState.java
File was deleted
opends/src/server/org/opends/server/synchronization/changelog/AckMessageList.java
File was renamed from opends/src/server/org/opends/server/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
opends/src/server/org/opends/server/synchronization/changelog/AckMessageListComparator.java
File was renamed from opends/src/server/org/opends/server/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;
opends/src/server/org/opends/server/synchronization/changelog/Changelog.java
File was renamed from opends/src/server/org/opends/server/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;
opends/src/server/org/opends/server/synchronization/changelog/ChangelogAckMessageList.java
File was renamed from opends/src/server/org/opends/server/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
opends/src/server/org/opends/server/synchronization/changelog/ChangelogCache.java
File was renamed from opends/src/server/org/opends/server/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());
opends/src/server/org/opends/server/synchronization/changelog/ChangelogDB.java
File was renamed from opends/src/server/org/opends/server/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;
opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java
File was renamed from opends/src/server/org/opends/server/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
opends/src/server/org/opends/server/synchronization/changelog/ChangelogData.java
File was renamed from opends/src/server/org/opends/server/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.
opends/src/server/org/opends/server/synchronization/changelog/ChangelogDbEnv.java
File was renamed from opends/src/server/org/opends/server/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;
opends/src/server/org/opends/server/synchronization/changelog/ChangelogIterator.java
File was renamed from opends/src/server/org/opends/server/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
opends/src/server/org/opends/server/synchronization/changelog/ChangelogIteratorComparator.java
File was renamed from opends/src/server/org/opends/server/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
opends/src/server/org/opends/server/synchronization/changelog/ChangelogKey.java
File was renamed from opends/src/server/org/opends/server/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.
opends/src/server/org/opends/server/synchronization/changelog/DbHandler.java
File was renamed from opends/src/server/org/opends/server/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;
opends/src/server/org/opends/server/synchronization/changelog/MsgQueue.java
File was renamed from opends/src/server/org/opends/server/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.
opends/src/server/org/opends/server/synchronization/changelog/ServerHandler.java
File was renamed from opends/src/server/org/opends/server/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;
/**
opends/src/server/org/opends/server/synchronization/changelog/ServerReader.java
File was renamed from opends/src/server/org/opends/server/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;
opends/src/server/org/opends/server/synchronization/changelog/ServerWriter.java
File was renamed from opends/src/server/org/opends/server/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;
opends/src/server/org/opends/server/synchronization/changelog/UpdateComparator.java
File was renamed from opends/src/server/org/opends/server/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.
opends/src/server/org/opends/server/synchronization/changelog/package-info.java
File was renamed from opends/src/server/org/opends/server/changelog/package-info.java
@@ -76,4 +76,4 @@
 *  </ul>
 */
package org.opends.server.changelog;
package org.opends.server.synchronization.changelog;
opends/src/server/org/opends/server/synchronization/common/ChangeNumber.java
File was renamed from opends/src/server/org/opends/server/synchronization/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.
opends/src/server/org/opends/server/synchronization/common/ChangeNumberGenerator.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/common/LogMessages.java
File was renamed from opends/src/server/org/opends/server/synchronization/SynchMessages.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");
opends/src/server/org/opends/server/synchronization/common/ServerState.java
New file
@@ -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;
    }
  }
}
opends/src/server/org/opends/server/synchronization/common/package-info.java
copy from opends/src/server/org/opends/server/synchronization/FakeOperationComparator.java copy to opends/src/server/org/opends/server/synchronization/common/package-info.java
File was copied from opends/src/server/org/opends/server/synchronization/FakeOperationComparator.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;
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;
opends/src/server/org/opends/server/synchronization/plugin/AttrInfo.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/plugin/AttrInfoWithOptions.java
File was renamed from opends/src/server/org/opends/server/synchronization/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.
opends/src/server/org/opends/server/synchronization/plugin/ChangelogBroker.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/plugin/FakeOperation.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/plugin/FakeOperationComparator.java
File was renamed from opends/src/server/org/opends/server/synchronization/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.
opends/src/server/org/opends/server/synchronization/plugin/HistKey.java
File was renamed from opends/src/server/org/opends/server/synchronization/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.
opends/src/server/org/opends/server/synchronization/plugin/HistVal.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/plugin/Historical.java
File was renamed from opends/src/server/org/opends/server/synchronization/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);
opends/src/server/org/opends/server/synchronization/plugin/HistoricalCsnOrderingMatchingRule.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/plugin/ListenerThread.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/plugin/ModifyFakeOperation.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/plugin/MultimasterSynchronization.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/plugin/PendingChange.java
File was renamed from opends/src/server/org/opends/server/synchronization/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
opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java
New file
@@ -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;
  }
}
opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
File was renamed from opends/src/server/org/opends/server/synchronization/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
opends/src/server/org/opends/server/synchronization/plugin/SynchronizationMonitor.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/plugin/ValueInfo.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
/**
opends/src/server/org/opends/server/synchronization/plugin/package-info.java
New file
@@ -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;
opends/src/server/org/opends/server/synchronization/protocol/AckMessage.java
File was renamed from opends/src/server/org/opends/server/synchronization/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
opends/src/server/org/opends/server/synchronization/protocol/AddContext.java
File was renamed from opends/src/server/org/opends/server/synchronization/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
opends/src/server/org/opends/server/synchronization/protocol/AddMsg.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
/**
opends/src/server/org/opends/server/synchronization/protocol/ChangelogStartMessage.java
File was renamed from opends/src/server/org/opends/server/synchronization/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 :
opends/src/server/org/opends/server/synchronization/protocol/DeleteContext.java
File was renamed from opends/src/server/org/opends/server/synchronization/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.
opends/src/server/org/opends/server/synchronization/protocol/DeleteMsg.java
File was renamed from opends/src/server/org/opends/server/synchronization/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.
opends/src/server/org/opends/server/synchronization/protocol/ModifyContext.java
File was renamed from opends/src/server/org/opends/server/synchronization/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
opends/src/server/org/opends/server/synchronization/protocol/ModifyDNMsg.java
File was renamed from opends/src/server/org/opends/server/synchronization/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.
opends/src/server/org/opends/server/synchronization/protocol/ModifyDnContext.java
File was renamed from opends/src/server/org/opends/server/synchronization/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
opends/src/server/org/opends/server/synchronization/protocol/ModifyMsg.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
opends/src/server/org/opends/server/synchronization/protocol/OperationContext.java
File was renamed from opends/src/server/org/opends/server/synchronization/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
opends/src/server/org/opends/server/synchronization/protocol/ProtocolSession.java
File was renamed from opends/src/server/org/opends/server/changelog/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
opends/src/server/org/opends/server/synchronization/protocol/ServerStartMessage.java
File was renamed from opends/src/server/org/opends/server/synchronization/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()
  {
    /*
opends/src/server/org/opends/server/synchronization/protocol/SocketSession.java
File was renamed from opends/src/server/org/opends/server/changelog/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
opends/src/server/org/opends/server/synchronization/protocol/SynchronizationMessage.java
File was renamed from opends/src/server/org/opends/server/synchronization/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
opends/src/server/org/opends/server/synchronization/protocol/UpdateMessage.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
  }
}
opends/src/server/org/opends/server/synchronization/protocol/WindowMessage.java
File was renamed from opends/src/server/org/opends/server/synchronization/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;
  }
}
opends/src/server/org/opends/server/synchronization/protocol/package-info.java
New file
@@ -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;
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;
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);
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);
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ChangeNumberTest.java
File was renamed from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/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;
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/common/ServerStateTest.java
File was renamed from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/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));
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/AttrInfoTest.java
File was renamed from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/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;
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ModifyConflictTest.java
File was renamed from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/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;
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ValueInfoTest.java
File was renamed from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/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;
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/ProtocolWindowTest.java
File was renamed from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/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);
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SyncMessagesTest.java
File was renamed from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/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))
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SynchronizationMsgTest.java
File was renamed from opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/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} };
  }