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

Jean-Noel Rouvignac
05.22.2015 b71a918506bf2bb0ed8fdc6fe0175ffbac5807e9
Remove getBaseDNString() methods.

After changing ArgX.get() to accept Object parameters instead of String + relaxing line length to 120 characters, it is now possible to get rid of getBaseDNString() methods, and directly use the getBaseDN() methods instead.
13 files modified
663 ■■■■■ changed files
opendj3-server-dev/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java 118 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/replication/server/DataServerHandler.java 46 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/replication/server/MessageHandler.java 18 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/replication/server/ReplicationServerHandler.java 18 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/replication/server/ServerHandler.java 29 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationDomain.java 52 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationMonitor.java 117 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/tasks/InitializeTargetTask.java 44 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/tasks/InitializeTask.java 61 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/tasks/PurgeConflictsHistoricalTask.java 82 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/tasks/SetGenerationIdTask.java 46 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DummyReplicationDomain.java 20 ●●●● patch | view | raw | blame | history
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/replication/service/ReplicationDomainTest.java 12 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -88,15 +88,6 @@
import org.opends.server.tasks.PurgeConflictsHistoricalTask;
import org.opends.server.tasks.TaskUtils;
import org.opends.server.types.*;
import org.opends.server.types.Attribute;
import org.opends.server.types.Attributes;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.Modification;
import org.opends.server.types.ObjectClass;
import org.opends.server.types.Operation;
import org.opends.server.types.OperationType;
import org.opends.server.types.RDN;
import org.opends.server.types.operation.*;
import org.opends.server.util.LDIFReader;
import org.opends.server.util.TimeThread;
@@ -349,8 +340,7 @@
  {
    protected ServerStateFlush()
    {
      super("Replica DS(" + getServerId()
          + ") state checkpointer for domain \"" + getBaseDNString() + "\"");
      super("Replica DS(" + getServerId() + ") state checkpointer for domain \"" + getBaseDN() + "\"");
    }
    /** {@inheritDoc} */
@@ -395,9 +385,7 @@
    protected RSUpdater(CSN replServerMaxCSN)
    {
      super("Replica DS(" + getServerId()
          + ") missing change publisher for domain \"" + getBaseDNString()
          + "\"");
      super("Replica DS(" + getServerId() + ") missing change publisher for domain \"" + getBaseDN() + "\"");
      this.startCSN = replServerMaxCSN;
    }
@@ -432,7 +420,7 @@
           * Log an error for the repair tool
           * that will need to re-synchronize the servers.
           */
          logger.error(ERR_CANNOT_RECOVER_CHANGES, getBaseDNString());
          logger.error(ERR_CANNOT_RECOVER_CHANGES, getBaseDN());
        }
      }
      catch (Exception e)
@@ -444,7 +432,7 @@
         * Log an error for the repair tool
         * that will need to re-synchronize the servers.
         */
        logger.error(ERR_CANNOT_RECOVER_CHANGES, getBaseDNString());
        logger.error(ERR_CANNOT_RECOVER_CHANGES, getBaseDN());
      }
      finally
      {
@@ -485,8 +473,7 @@
    Backend<?> backend = getBackend();
    if (backend == null)
    {
      throw new ConfigException(ERR_SEARCHING_DOMAIN_BACKEND.get(
                                  getBaseDNString()));
      throw new ConfigException(ERR_SEARCHING_DOMAIN_BACKEND.get(getBaseDN()));
    }
    try
@@ -495,7 +482,7 @@
    }
    catch (DirectoryException e)
    {
      logger.error(ERR_LOADING_GENERATION_ID, getBaseDNString(), stackTraceToSingleLineString(e));
      logger.error(ERR_LOADING_GENERATION_ID, getBaseDN(), stackTraceToSingleLineString(e));
    }
    /*
@@ -580,7 +567,7 @@
      // Should not happen as normally already called without problem in
      // isConfigurationChangeAcceptable or isConfigurationAcceptable
      // if we come up to this method
      logger.info(NOTE_ERR_FRACTIONAL, getBaseDNString(), stackTraceToSingleLineString(e));
      logger.info(NOTE_ERR_FRACTIONAL, getBaseDN(), stackTraceToSingleLineString(e));
      return;
    }
@@ -598,7 +585,7 @@
    catch  (ConfigException e)
    {
      // Should not happen
      logger.info(NOTE_ERR_FRACTIONAL, getBaseDNString(), stackTraceToSingleLineString(e));
      logger.info(NOTE_ERR_FRACTIONAL, getBaseDN(), stackTraceToSingleLineString(e));
      return;
    }
@@ -647,9 +634,7 @@
    // Read config stored in domain root entry
    if (logger.isTraceEnabled())
    {
      logger.trace(
          "Attempt to read the potential fractional config in domain root "
              + "entry " + getBaseDNString());
      logger.trace("Attempt to read the potential fractional config in domain root entry " + getBaseDN());
    }
    // Search the domain root entry that is used to save the generation id
@@ -660,9 +645,8 @@
    if (search.getResultCode() != ResultCode.SUCCESS
        && search.getResultCode() != ResultCode.NO_SUCH_OBJECT)
    {
      logger.error(ERR_SEARCHING_GENERATION_ID,
          search.getResultCode().getName() + " " + search.getErrorMessage(),
          getBaseDNString());
      String errorMsg = search.getResultCode().getName() + " " + search.getErrorMessage();
      logger.error(ERR_SEARCHING_GENERATION_ID, errorMsg, getBaseDN());
      return false;
    }
@@ -706,9 +690,8 @@
        }
        if (attr.size() > 1)
        {
          logger.error(ERR_LOADING_GENERATION_ID,
              getBaseDNString(),
              "#Values=" + attr.size() + " Must be exactly 1 in entry " + resultEntry.toLDIFString());
          String errorMsg = "#Values=" + attr.size() + " Must be exactly 1 in entry " + resultEntry.toLDIFString();
          logger.error(ERR_LOADING_GENERATION_ID, getBaseDN(), errorMsg);
        }
      }
    }
@@ -1435,7 +1418,7 @@
    }
    catch(DirectoryException e)
    {
      logger.info(NOTE_ERR_FRACTIONAL, getBaseDNString(), stackTraceToSingleLineString(e));
      logger.info(NOTE_ERR_FRACTIONAL, getBaseDN(), stackTraceToSingleLineString(e));
      return FRACTIONAL_HAS_NO_FRACTIONAL_FILTERED_ATTRIBUTES;
    }
    Set<ObjectClass> entryClasses = entryToModify.getObjectClasses().keySet();
@@ -1512,12 +1495,10 @@
    switch (importErrorMessageId)
    {
    case IMPORT_ERROR_MESSAGE_BAD_REMOTE:
      msg = NOTE_ERR_FULL_UPDATE_IMPORT_FRACTIONAL_BAD_REMOTE.get(
          getBaseDNString(), ieCtx.getImportSource());
      msg = NOTE_ERR_FULL_UPDATE_IMPORT_FRACTIONAL_BAD_REMOTE.get(getBaseDN(), ieCtx.getImportSource());
      break;
    case IMPORT_ERROR_MESSAGE_REMOTE_IS_FRACTIONAL:
      msg = NOTE_ERR_FULL_UPDATE_IMPORT_FRACTIONAL_REMOTE_IS_FRACTIONAL.get(
          getBaseDNString(), ieCtx.getImportSource());
      msg = NOTE_ERR_FULL_UPDATE_IMPORT_FRACTIONAL_REMOTE_IS_FRACTIONAL.get(getBaseDN(), ieCtx.getImportSource());
      break;
    }
    ieCtx.setException(new DirectoryException(UNWILLING_TO_PERFORM, msg));
@@ -1538,8 +1519,7 @@
  {
    if (target == RoutableMsg.ALL_SERVERS && fractionalConfig.isFractional())
    {
      LocalizableMessage msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_FULL_UPDATE_FRACTIONAL.get(
            getBaseDNString(), getServerId());
      LocalizableMessage msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_FULL_UPDATE_FRACTIONAL.get(getBaseDN(), getServerId());
      throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, msg);
    }
@@ -1560,7 +1540,7 @@
  {
    if (!deleteOperation.isSynchronizationOperation() && !brokerIsConnected())
    {
      LocalizableMessage msg = ERR_REPLICATION_COULD_NOT_CONNECT.get(getBaseDNString());
      LocalizableMessage msg = ERR_REPLICATION_COULD_NOT_CONNECT.get(getBaseDN());
      return new SynchronizationProviderResult.StopProcessing(
          ResultCode.UNWILLING_TO_PERFORM, msg);
    }
@@ -1631,7 +1611,7 @@
  {
    if (!addOperation.isSynchronizationOperation() && !brokerIsConnected())
    {
      LocalizableMessage msg = ERR_REPLICATION_COULD_NOT_CONNECT.get(getBaseDNString());
      LocalizableMessage msg = ERR_REPLICATION_COULD_NOT_CONNECT.get(getBaseDN());
      return new SynchronizationProviderResult.StopProcessing(
          ResultCode.UNWILLING_TO_PERFORM, msg);
    }
@@ -1658,8 +1638,7 @@
         */
        if (fractionalFilterOperation(addOperation, false))
        {
          LocalizableMessage msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_OPERATION.get(
            getBaseDNString(), addOperation);
          LocalizableMessage msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_OPERATION.get(getBaseDN(), addOperation);
          return new SynchronizationProviderResult.StopProcessing(
            ResultCode.UNWILLING_TO_PERFORM, msg);
        }
@@ -1761,7 +1740,7 @@
  {
    if (!modifyDNOperation.isSynchronizationOperation() && !brokerIsConnected())
    {
      LocalizableMessage msg = ERR_REPLICATION_COULD_NOT_CONNECT.get(getBaseDNString());
      LocalizableMessage msg = ERR_REPLICATION_COULD_NOT_CONNECT.get(getBaseDN());
      return new SynchronizationProviderResult.StopProcessing(
          ResultCode.UNWILLING_TO_PERFORM, msg);
    }
@@ -1786,8 +1765,7 @@
         */
        if (fractionalFilterOperation(modifyDNOperation, false))
        {
          LocalizableMessage msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_OPERATION.get(
            getBaseDNString(), modifyDNOperation);
          LocalizableMessage msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_OPERATION.get(getBaseDN(), modifyDNOperation);
          return new SynchronizationProviderResult.StopProcessing(
            ResultCode.UNWILLING_TO_PERFORM, msg);
        }
@@ -1879,7 +1857,7 @@
  {
    if (!modifyOperation.isSynchronizationOperation() && !brokerIsConnected())
    {
      LocalizableMessage msg = ERR_REPLICATION_COULD_NOT_CONNECT.get(getBaseDNString());
      LocalizableMessage msg = ERR_REPLICATION_COULD_NOT_CONNECT.get(getBaseDN());
      return new SynchronizationProviderResult.StopProcessing(
          ResultCode.UNWILLING_TO_PERFORM, msg);
    }
@@ -1919,8 +1897,7 @@
          case FRACTIONAL_HAS_FRACTIONAL_FILTERED_ATTRIBUTES:
            // Some attributes not compliant with fractional configuration :
            // forbid the operation
            LocalizableMessage msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_OPERATION.get(
              getBaseDNString(), modifyOperation);
            LocalizableMessage msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_OPERATION.get(getBaseDN(), modifyOperation);
            return new SynchronizationProviderResult.StopProcessing(
              ResultCode.UNWILLING_TO_PERFORM, msg);
        }
@@ -2082,7 +2059,7 @@
        } catch (TimeoutException ex)
        {
          // This exception may only be raised if assured replication is enabled
          logger.info(NOTE_DS_ACK_TIMEOUT, getBaseDNString(), getAssuredTimeout(), msg);
          logger.info(NOTE_DS_ACK_TIMEOUT, getBaseDN(), getAssuredTimeout(), msg);
        }
      }
@@ -2921,7 +2898,7 @@
        String conflictRDN =
            generateConflictRDN(entryUUID, op.getEntryDN().rdn().toString());
        msg.setDN(DN.valueOf(conflictRDN + "," + getBaseDNString()));
        msg.setDN(DN.valueOf(conflictRDN + "," + getBaseDN()));
        // reset the parent entryUUID so that the check done is the
        // handleConflict phase does not fail.
        msg.setParentEntryUUID(null);
@@ -3198,7 +3175,7 @@
       * not available, log an error and retry upon timeout
       * should we stop the modifications ?
       */
      logger.error(ERR_LOADING_GENERATION_ID, getBaseDNString(), stackTraceToSingleLineString(e));
      logger.error(ERR_LOADING_GENERATION_ID, getBaseDN(), stackTraceToSingleLineString(e));
      return;
    }
@@ -3270,7 +3247,7 @@
      if (result != ResultCode.SUCCESS)
      {
        logger.error(ERR_UPDATING_GENERATION_ID, result.getName(), getBaseDNString());
        logger.error(ERR_UPDATING_GENERATION_ID, result.getName(), getBaseDN());
      }
    }
    else
@@ -3293,8 +3270,7 @@
  {
    if (logger.isTraceEnabled())
    {
      logger.trace("Attempt to read generation ID from DB "
          + getBaseDNString());
      logger.trace("Attempt to read generation ID from DB " + getBaseDN());
    }
    /*
@@ -3318,9 +3294,8 @@
    {
      if (search.getResultCode() != ResultCode.NO_SUCH_OBJECT)
      {
        logger.error(ERR_SEARCHING_GENERATION_ID,
            search.getResultCode().getName() + " " + search.getErrorMessage(),
            getBaseDNString());
        String errorMsg = search.getResultCode().getName() + " " + search.getErrorMessage();
        logger.error(ERR_SEARCHING_GENERATION_ID, errorMsg, getBaseDN());
      }
    }
    else
@@ -3338,9 +3313,8 @@
          Attribute attr = attrs.get(0);
          if (attr.size()>1)
          {
            logger.error(ERR_LOADING_GENERATION_ID,
                getBaseDNString(),
                "#Values=" + attr.size() + " Must be exactly 1 in entry " + resultEntry.toLDIFString());
            String errorMsg = "#Values=" + attr.size() + " Must be exactly 1 in entry " + resultEntry.toLDIFString();
            logger.error(ERR_LOADING_GENERATION_ID, getBaseDN(), errorMsg);
          }
          else if (attr.size() == 1)
          {
@@ -3351,7 +3325,7 @@
            }
            catch(Exception e)
            {
              logger.error(ERR_LOADING_GENERATION_ID, getBaseDNString(), stackTraceToSingleLineString(e));
              logger.error(ERR_LOADING_GENERATION_ID, getBaseDN(), stackTraceToSingleLineString(e));
            }
          }
        }
@@ -3365,8 +3339,7 @@
      if (logger.isTraceEnabled())
      {
        logger.trace("Generation ID created for domain baseDN="
            + getBaseDNString() + " generationId=" + aGenerationId);
        logger.trace("Generation ID created for domain baseDN=" + getBaseDN() + " generationId=" + aGenerationId);
      }
    }
    else
@@ -3374,8 +3347,8 @@
      generationIdSavedStatus = true;
      if (logger.isTraceEnabled())
      {
        logger.trace("Generation ID successfully read from domain baseDN="
            + getBaseDNString() + " generationId=" + aGenerationId);
        logger.trace("Generation ID successfully read from domain baseDN=" + getBaseDN()
            + " generationId=" + aGenerationId);
      }
    }
    return aGenerationId;
@@ -3390,9 +3363,7 @@
    state.save();
  }
  /**
   * Do whatever is needed when a backup is finished.
   */
  /** Do whatever is needed when a backup is finished. */
  void backupEnd()
  {
    // Nothing is needed at the moment
@@ -4008,7 +3979,7 @@
    catch (Exception e)
    {
      throw new ConfigException(NOTE_ERR_UNABLE_TO_ENABLE_ECL.get(
          "Replication Domain on " + getBaseDNString(), stackTraceToSingleLineString(e)), e);
          "Replication Domain on " + getBaseDN(), stackTraceToSingleLineString(e)), e);
    }
  }
@@ -4037,7 +4008,7 @@
    if (forceBadDataSet)
    {
      signalNewStatus(StatusMachineEvent.TO_BAD_GEN_ID_STATUS_EVENT);
      logger.info(NOTE_FRACTIONAL_BAD_DATA_SET_NEED_RESYNC, getBaseDNString());
      logger.info(NOTE_FRACTIONAL_BAD_DATA_SET_NEED_RESYNC, getBaseDN());
      return; // Do not send changes to the replication server
    }
@@ -4075,7 +4046,7 @@
      }
    } catch (Exception e)
    {
      logger.error(ERR_PUBLISHING_FAKE_OPS, getBaseDNString(), stackTraceToSingleLineString(e));
      logger.error(ERR_PUBLISHING_FAKE_OPS, getBaseDN(), stackTraceToSingleLineString(e));
    }
  }
@@ -4403,12 +4374,11 @@
    catch (Exception e)
    {
      LocalizableMessage message = ERR_INVALID_IMPORT_SOURCE.get(
          getBaseDNString(), getServerId(), sourceString, stackTraceToSingleLineString(e));
          getBaseDN(), getServerId(), sourceString, stackTraceToSingleLineString(e));
      throw new DirectoryException(ResultCode.OTHER, message, e);
    }
    LocalizableMessage message = ERR_INVALID_IMPORT_SOURCE.get(
        getBaseDNString(), getServerId(), source, "");
    LocalizableMessage message = ERR_INVALID_IMPORT_SOURCE.get(getBaseDN(), getServerId(), source, "");
    throw new DirectoryException(ResultCode.OTHER, message);
  }
@@ -5007,7 +4977,7 @@
      long endDate) throws DirectoryException
  {
     logger.trace("[PURGE] purgeConflictsHistorical "
         + "on domain: " + getBaseDNString()
         + "on domain: " + getBaseDN()
         + "endDate:" + new Date(endDate)
         + "lastCSNPurgedFromHist: "
         + lastCSNPurgedFromHist.toStringUI());
opendj3-server-dev/src/server/org/opends/server/replication/server/DataServerHandler.java
@@ -22,24 +22,25 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2014 ForgeRock AS
 *      Portions Copyright 2011-2015 ForgeRock AS
 */
package org.opends.server.replication.server;
import java.io.IOException;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import java.util.*;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.replication.common.*;
import org.opends.server.replication.protocol.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ResultCode;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.replication.common.ServerStatus.*;
import static org.opends.server.replication.common.StatusMachine.*;
import static org.opends.server.replication.protocol.ProtocolVersion.*;
import java.io.IOException;
import java.util.*;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.replication.common.*;
import org.opends.server.replication.protocol.*;
import org.opends.server.types.*;
/**
 * This class defines a server handler, which handles all interaction with a
 * peer server (RS or DS).
@@ -102,10 +103,9 @@
    if (event == StatusMachineEvent.TO_BAD_GEN_ID_STATUS_EVENT
        && status == ServerStatus.FULL_UPDATE_STATUS)
    {
      // Prevent useless error message (full update status cannot lead to bad
      // gen status)
      // Prevent useless error message (full update status cannot lead to bad gen status)
      logger.info(NOTE_BAD_GEN_ID_IN_FULL_UPDATE, replicationServer.getServerId(),
              getBaseDNString(), serverId, generationId, newGenId);
          getBaseDN(), serverId, generationId, newGenId);
      return;
    }
@@ -132,7 +132,7 @@
      if (logger.isTraceEnabled())
      {
        logger.trace("In RS " + replicationServer.getServerId()
            + ", DS " + getServerId() + " for baseDN=" + getBaseDNString()
            + ", DS " + getServerId() + " for baseDN=" + getBaseDN()
            + " has already generation id " + newGenId
            + " so no ChangeStatusMsg sent to him.");
      }
@@ -146,10 +146,9 @@
    if (logger.isTraceEnabled())
    {
      logger.trace("In RS " + replicationServer.getServerId()
          + ", closing connection to DS " + getServerId() + " for baseDN="
          + getBaseDNString() + " to force reconnection as new local"
          + " generationId and remote one match and DS is in bad gen id: "
          + newGenId);
          + ", closing connection to DS " + getServerId() + " for baseDN=" + getBaseDN()
          + " to force reconnection as new local generationId"
          + " and remote one match and DS is in bad gen id: " + newGenId);
    }
    // Connection closure must not be done calling RSD.stopHandler() as it
@@ -214,7 +213,7 @@
    {
      logger.trace("In RS " + replicationServer.getServerId()
          + " Sending change status " + origin + " to " + getServerId()
          + " for baseDN=" + getBaseDNString() + ":\n" + csMsg);
          + " for baseDN=" + getBaseDN() + ":\n" + csMsg);
    }
    session.publish(csMsg);
@@ -599,8 +598,7 @@
      if (generationId != localGenerationId)
      {
        logger.warn(WARN_BAD_GENERATION_ID_FROM_DS, serverId, session.getReadableRemoteAddress(),
            generationId, getBaseDNString(),
            getReplicationServerId(), localGenerationId);
            generationId, getBaseDN(), getReplicationServerId(), localGenerationId);
      }
    }
    else
@@ -611,8 +609,7 @@
        // If the LDAP server has already sent changes
        // it is not expected to connect to an empty RS
        logger.warn(WARN_BAD_GENERATION_ID_FROM_DS, serverId, session.getReadableRemoteAddress(),
            generationId, getBaseDNString(),
            getReplicationServerId(), localGenerationId);
            generationId, getBaseDN(), getReplicationServerId(), localGenerationId);
      }
      else
      {
@@ -620,8 +617,7 @@
        // WARNING: Must be done before computing topo message to send
        // to peer server as topo message must embed valid generation id
        // for our server
        oldGenerationId =
            replicationServerDomain.changeGenerationId(generationId);
        oldGenerationId = replicationServerDomain.changeGenerationId(generationId);
      }
    }
    return startSessionMsg;
opendj3-server-dev/src/server/org/opends/server/replication/server/MessageHandler.java
@@ -26,6 +26,10 @@
 */
package org.opends.server.replication.server;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.types.Attributes.*;
import static org.opends.server.util.StaticUtils.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -48,10 +52,6 @@
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.types.Attributes.*;
import static org.opends.server.util.StaticUtils.*;
/**
 * This class implements a buffering/producer/consumer mechanism of
 * replication changes (UpdateMsg) used inside the replication server.
@@ -560,16 +560,6 @@
  }
  /**
   * Get the baseDN for this handler as a String.
   *
   * @return The name of the baseDN.
   */
  protected String getBaseDNString()
  {
    return baseDN.toString();
  }
  /**
   * Increase the counter of updates received from the server.
   */
  void incrementInCount()
opendj3-server-dev/src/server/org/opends/server/replication/server/ReplicationServerHandler.java
@@ -22,27 +22,28 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2014 ForgeRock AS
 *      Portions Copyright 2011-2015 ForgeRock AS
 */
package org.opends.server.replication.server;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.replication.protocol.ProtocolVersion.*;
import java.io.IOException;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.replication.common.DSInfo;
import org.opends.server.replication.common.RSInfo;
import org.opends.server.replication.common.ServerState;
import org.opends.server.replication.common.ServerStatus;
import org.opends.server.replication.protocol.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ResultCode;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.replication.protocol.ProtocolVersion.*;
/**
 * This class defines a server handler, which handles all interaction with a
@@ -53,10 +54,7 @@
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  /**
   * Properties filled only if remote server is a RS.
   */
  /** Properties filled only if remote server is a RS. */
  private String serverAddressURL;
  /**
   * this collection will contain as many elements as there are
@@ -514,7 +512,7 @@
       * replicationServerDomain.setGenerationId(generationId, false);
       */
      logger.warn(WARN_BAD_GENERATION_ID_FROM_RS, serverId, session.getReadableRemoteAddress(), generationId,
          getBaseDNString(), getReplicationServerId(), localGenerationId);
          getBaseDN(), getReplicationServerId(), localGenerationId);
    }
  }
opendj3-server-dev/src/server/org/opends/server/replication/server/ServerHandler.java
@@ -22,13 +22,13 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2014 ForgeRock AS
 *      Portions Copyright 2011-2015 ForgeRock AS
 */
package org.opends.server.replication.server;
import java.io.IOException;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import static org.opends.messages.ReplicationMessages.*;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import java.util.Set;
@@ -37,18 +37,20 @@
import java.util.concurrent.atomic.AtomicInteger;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.admin.std.server.MonitorProviderCfg;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.admin.std.server.MonitorProviderCfg;
import org.opends.server.core.DirectoryServer;
import org.opends.server.replication.common.AssuredMode;
import org.opends.server.replication.common.CSN;
import org.opends.server.replication.common.RSInfo;
import org.opends.server.replication.common.ServerStatus;
import org.opends.server.replication.protocol.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ResultCode;
import static org.opends.messages.ReplicationMessages.*;
import org.opends.server.types.Attribute;
import org.opends.server.types.Attributes;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
/**
 * This class defines a server handler  :
@@ -510,7 +512,7 @@
    List<Attribute> attributes = super.getMonitorData();
    attributes.add(Attributes.create("server-id", String.valueOf(serverId)));
    attributes.add(Attributes.create("domain-name", getBaseDNString()));
    attributes.add(Attributes.create("domain-name", String.valueOf(getBaseDN())));
    // Deprecated
    attributes.add(Attributes.create("max-waiting-changes", String
@@ -789,10 +791,7 @@
    if (!lockAcquired)
    {
      LocalizableMessage message = WARN_TIMEOUT_WHEN_CROSS_CONNECTION.get(
          getBaseDNString(),
          serverId,
          session.getReadableRemoteAddress(),
          getReplicationServerId());
          getBaseDN(), serverId, session.getReadableRemoteAddress(), getReplicationServerId());
      throw new DirectoryException(ResultCode.OTHER, message);
    }
  }
@@ -1199,9 +1198,9 @@
    if (isDataServer())
    {
      return ERR_DS_BADLY_DISCONNECTED.get(getReplicationServerId(),
          getServerId(), session.getReadableRemoteAddress(), getBaseDNString());
          getServerId(), session.getReadableRemoteAddress(), getBaseDN());
    }
    return ERR_RS_BADLY_DISCONNECTED.get(getReplicationServerId(),
        getServerId(), session.getReadableRemoteAddress(), getBaseDNString());
        getServerId(), session.getReadableRemoteAddress(), getBaseDN());
  }
}
opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationDomain.java
@@ -26,6 +26,10 @@
 */
package org.opends.server.replication.service;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.replication.common.AssuredMode.*;
import static org.opends.server.replication.common.StatusMachine.*;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -53,10 +57,6 @@
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.replication.common.AssuredMode.*;
import static org.opends.server.replication.common.StatusMachine.*;
/**
 * This class should be used as a base for Replication implementations.
 * <p>
@@ -434,7 +434,7 @@
    // Sanity check: is it a valid initial status?
    if (!isValidInitialStatus(initStatus))
    {
      logger.error(ERR_DS_INVALID_INIT_STATUS, initStatus, getBaseDNString(), getServerId());
      logger.error(ERR_DS_INVALID_INIT_STATUS, initStatus, getBaseDN(), getServerId());
    }
    else
    {
@@ -462,7 +462,7 @@
    StatusMachineEvent event = StatusMachineEvent.statusToEvent(reqStatus);
    if (event == StatusMachineEvent.INVALID_EVENT)
    {
      logger.error(ERR_DS_INVALID_REQUESTED_STATUS, reqStatus, getBaseDNString(), getServerId());
      logger.error(ERR_DS_INVALID_REQUESTED_STATUS, reqStatus, getBaseDN(), getServerId());
      return;
    }
@@ -525,16 +525,6 @@
  }
  /**
   * Gets the baseDN of this domain.
   *
   * @return The baseDN for this domain.
   */
  public String getBaseDNString()
  {
    return getBaseDN().toString();
  }
  /**
   * Get the server ID. The identifier of this Replication Domain inside the
   * Replication Service. Each Domain must use a unique ServerID.
   *
@@ -1460,7 +1450,7 @@
    if (serverToInitialize == RoutableMsg.ALL_SERVERS)
    {
      logger.info(NOTE_FULL_UPDATE_ENGAGED_FOR_REMOTE_START_ALL,
          countEntries(), getBaseDNString(), getServerId());
          countEntries(), getBaseDN(), getServerId());
      ieCtx.startList.addAll(getReplicaInfos().keySet());
@@ -1476,7 +1466,7 @@
    else
    {
      logger.info(NOTE_FULL_UPDATE_ENGAGED_FOR_REMOTE_START, countEntries(),
          getBaseDNString(), getServerId(), serverToInitialize);
          getBaseDN(), getServerId(), serverToInitialize);
      ieCtx.startList.add(serverToInitialize);
@@ -1526,8 +1516,7 @@
        {
          throw new DirectoryException(
              ResultCode.OTHER,
              ERR_INIT_NO_SUCCESS_START_FROM_SERVERS.get(getBaseDNString(),
                  ieCtx.failureList));
              ERR_INIT_NO_SUCCESS_START_FROM_SERVERS.get(getBaseDN(), ieCtx.failureList));
        }
        exportBackend(new BufferedOutputStream(new ReplOutputStream(this)));
@@ -1633,12 +1622,12 @@
    if (serverToInitialize == RoutableMsg.ALL_SERVERS)
    {
      logger.info(NOTE_FULL_UPDATE_ENGAGED_FOR_REMOTE_END_ALL,
          getBaseDNString(), getServerId(), cause);
          getBaseDN(), getServerId(), cause);
    }
    else
    {
      logger.info(NOTE_FULL_UPDATE_ENGAGED_FOR_REMOTE_END,
          getBaseDNString(), getServerId(), serverToInitialize, cause);
          getBaseDN(), getServerId(), serverToInitialize, cause);
    }
@@ -1974,9 +1963,8 @@
              && getConnectedRemoteDS(ieCtx.importSource) == null)
          {
            LocalizableMessage errMsg = ERR_INIT_EXPORTER_DISCONNECTION.get(
                getBaseDNString(), getServerId(), ieCtx.importSource);
            ieCtx.setExceptionIfNoneSet(new DirectoryException(
                ResultCode.OTHER, errMsg));
                getBaseDN(), getServerId(), ieCtx.importSource);
            ieCtx.setExceptionIfNoneSet(new DirectoryException(ResultCode.OTHER, errMsg));
            return null;
          }
        }
@@ -2171,7 +2159,7 @@
    }
    LocalizableMessage errMsg = !broker.isConnected()
        ? ERR_INITIALIZATION_FAILED_NOCONN.get(getBaseDNString())
        ? ERR_INITIALIZATION_FAILED_NOCONN.get(getBaseDN())
        : null;
    /*
@@ -2252,7 +2240,7 @@
    try
    {
      // Log starting
      logger.info(NOTE_FULL_UPDATE_ENGAGED_FROM_REMOTE_START, getBaseDNString(),
      logger.info(NOTE_FULL_UPDATE_ENGAGED_FROM_REMOTE_START, getBaseDN(),
          initTargetMsgReceived.getSenderID(), getServerId());
      // Go into full update status
@@ -2384,9 +2372,9 @@
      }
      finally
      {
        String errorMsg = ieCtx.getException() != null ? ieCtx.getException().getLocalizedMessage() : "";
        logger.info(NOTE_FULL_UPDATE_ENGAGED_FROM_REMOTE_END,
            getBaseDNString(), initTargetMsgReceived.getSenderID(), getServerId(),
            (ieCtx.getException() != null ? ieCtx.getException().getLocalizedMessage() : ""));
            getBaseDN(), initTargetMsgReceived.getSenderID(), getServerId(), errorMsg);
        releaseIEContext();
      } // finally
    } // finally
@@ -2501,7 +2489,7 @@
    }
    if (!allSet)
    {
      LocalizableMessage message = ERR_RESET_GENERATION_ID_FAILED.get(getBaseDNString());
      LocalizableMessage message = ERR_RESET_GENERATION_ID_FAILED.get(getBaseDN());
      throw new DirectoryException(ResultCode.OTHER, message);
    }
  }
@@ -2568,7 +2556,7 @@
    if (!isConnected())
    {
      LocalizableMessage message = ERR_RESET_GENERATION_CONN_ERR_ID.get(getBaseDNString(),
      LocalizableMessage message = ERR_RESET_GENERATION_CONN_ERR_ID.get(getBaseDN(),
          getServerId(), genIdMessage.getGenerationId());
      throw new DirectoryException(ResultCode.OTHER, message);
    }
@@ -2948,7 +2936,7 @@
    synchronized (sessionLock)
    {
      final String threadName = "Replica DS(" + getServerId()
          + ") listener for domain \"" + getBaseDNString() + "\"";
          + ") listener for domain \"" + getBaseDN() + "\"";
      listenerThread = new DirectoryThread(new Runnable()
      {
opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationMonitor.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions copyright 2013-2014 ForgeRock AS.
 *      Portions copyright 2013-2015 ForgeRock AS.
 */
package org.opends.server.replication.service;
@@ -34,8 +34,11 @@
import org.opends.server.admin.std.server.MonitorProviderCfg;
import org.opends.server.api.MonitorProvider;
import org.opends.server.core.DirectoryServer;
import org.opends.server.replication.service.ReplicationDomain.*;
import org.opends.server.types.*;
import org.opends.server.replication.service.ReplicationDomain.ImportExportContext;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeBuilder;
import org.opends.server.types.AttributeType;
import org.opends.server.types.Attributes;
/**
 * Class used to generate monitoring information for the replication.
@@ -53,10 +56,8 @@
    this.domain = domain;
  }
  /**
   * {@inheritDoc}
   */
  @Override()
  /** {@inheritDoc} */
  @Override
  public void initializeMonitorProvider(MonitorProviderCfg configuration)
  {
    // no implementation needed.
@@ -72,8 +73,8 @@
  public String getMonitorInstanceName()
  {
    return "Directory server DS(" + domain.getServerId() + ") "
        + domain.getLocalUrl() + ",cn="
        + domain.getBaseDNString().replace(',', '_').replace('=', '_')
        + domain.getLocalUrl()
        + ",cn=" + domain.getBaseDN().toString().replace(',', '_').replace('=', '_')
        + ",cn=Replication";
  }
@@ -90,33 +91,26 @@
  {
    List<Attribute> attributes = new ArrayList<Attribute>();
    attributes.add(Attributes.create("domain-name", domain.getBaseDNString()));
    attributes.add(Attributes.create("connected-to", domain
        .getReplicationServer()));
    addMonitorData(attributes, "lost-connections",
                   domain.getNumLostConnections());
    attributes.add(Attributes.create("domain-name", String.valueOf(domain.getBaseDN())));
    attributes.add(Attributes.create("connected-to", domain.getReplicationServer()));
    addMonitorData(attributes, "lost-connections", domain.getNumLostConnections());
    addMonitorData(attributes, "received-updates", domain.getNumRcvdUpdates());
    addMonitorData(attributes, "sent-updates", domain.getNumSentUpdates());
    // get number of changes replayed
    addMonitorData(attributes, "replayed-updates",
                   domain.getNumProcessedUpdates());
    addMonitorData(attributes, "replayed-updates", domain.getNumProcessedUpdates());
    addMonitorData(attributes, "server-id", domain.getServerId());
    // get window information
    addMonitorData(attributes, "max-rcv-window", domain.getMaxRcvWindow());
    addMonitorData(attributes, "current-rcv-window",
                               domain.getCurrentRcvWindow());
    addMonitorData(attributes, "max-send-window",
                               domain.getMaxSendWindow());
    addMonitorData(attributes, "current-send-window",
                               domain.getCurrentSendWindow());
    addMonitorData(attributes, "current-rcv-window", domain.getCurrentRcvWindow());
    addMonitorData(attributes, "max-send-window", domain.getMaxSendWindow());
    addMonitorData(attributes, "current-send-window", domain.getCurrentSendWindow());
    // get the Server State
    final String ATTR_SERVER_STATE = "server-state";
    AttributeType type =
      DirectoryServer.getDefaultAttributeType(ATTR_SERVER_STATE);
    AttributeType type = DirectoryServer.getDefaultAttributeType(ATTR_SERVER_STATE);
    AttributeBuilder builder = new AttributeBuilder(type, ATTR_SERVER_STATE);
    for (String str : domain.getServerState().toStringSet())
    {
@@ -124,22 +118,16 @@
    }
    attributes.add(builder.toAttribute());
    attributes.add(Attributes.create("ssl-encryption",
        String.valueOf(domain.isSessionEncrypted())));
    attributes.add(Attributes.create("generation-id",
        String.valueOf(domain.getGenerationID())));
    attributes.add(Attributes.create("ssl-encryption", String.valueOf(domain.isSessionEncrypted())));
    attributes.add(Attributes.create("generation-id", String.valueOf(domain.getGenerationID())));
    // Add import/export monitoring attributes
    final ImportExportContext ieContext = domain.getImportExportContext();
    if (ieContext != null)
    {
      addMonitorData(attributes, "total-update",
          ieContext.importInProgress() ? "import" : "export");
      addMonitorData(attributes, "total-update-entry-count",
          ieContext.getTotalEntryCount());
      addMonitorData(attributes, "total-update-entry-left",
          ieContext.getLeftEntryCount());
      addMonitorData(attributes, "total-update", ieContext.importInProgress() ? "import" : "export");
      addMonitorData(attributes, "total-update-entry-count", ieContext.getTotalEntryCount());
      addMonitorData(attributes, "total-update-entry-left", ieContext.getLeftEntryCount());
    }
@@ -150,42 +138,24 @@
     * Add assured replication related monitoring fields
     * (see domain.getXXX() method comment for field meaning)
     */
    addMonitorData(attributes, "assured-sr-sent-updates",
      domain.getAssuredSrSentUpdates());
    addMonitorData(attributes, "assured-sr-acknowledged-updates",
      domain.getAssuredSrAcknowledgedUpdates());
    addMonitorData(attributes, "assured-sr-not-acknowledged-updates",
      domain.getAssuredSrNotAcknowledgedUpdates());
    addMonitorData(attributes, "assured-sr-timeout-updates",
      domain.getAssuredSrTimeoutUpdates());
    addMonitorData(attributes, "assured-sr-wrong-status-updates",
      domain.getAssuredSrWrongStatusUpdates());
    addMonitorData(attributes, "assured-sr-replay-error-updates",
      domain.getAssuredSrReplayErrorUpdates());
    addMonitorData(attributes, "assured-sr-server-not-acknowledged-updates",
        domain.getAssuredSrServerNotAcknowledgedUpdates());
    addMonitorData(attributes, "assured-sr-received-updates",
      domain.getAssuredSrReceivedUpdates());
    addMonitorData(attributes, "assured-sr-received-updates-acked",
      domain.getAssuredSrReceivedUpdatesAcked());
    addMonitorData(attributes, "assured-sr-received-updates-not-acked",
      domain.getAssuredSrReceivedUpdatesNotAcked());
    addMonitorData(attributes, "assured-sd-sent-updates",
      domain.getAssuredSdSentUpdates());
    addMonitorData(attributes, "assured-sd-acknowledged-updates",
      domain.getAssuredSdAcknowledgedUpdates());
    addMonitorData(attributes, "assured-sd-timeout-updates",
      domain.getAssuredSdTimeoutUpdates());
    addMonitorData(attributes, "assured-sd-server-timeout-updates",
        domain.getAssuredSdServerTimeoutUpdates());
    addMonitorData(attributes, "assured-sr-sent-updates", domain.getAssuredSrSentUpdates());
    addMonitorData(attributes, "assured-sr-acknowledged-updates", domain.getAssuredSrAcknowledgedUpdates());
    addMonitorData(attributes, "assured-sr-not-acknowledged-updates", domain.getAssuredSrNotAcknowledgedUpdates());
    addMonitorData(attributes, "assured-sr-timeout-updates", domain.getAssuredSrTimeoutUpdates());
    addMonitorData(attributes, "assured-sr-wrong-status-updates", domain.getAssuredSrWrongStatusUpdates());
    addMonitorData(attributes, "assured-sr-replay-error-updates", domain.getAssuredSrReplayErrorUpdates());
    addMonitorData(attributes, "assured-sr-server-not-acknowledged-updates", domain
        .getAssuredSrServerNotAcknowledgedUpdates());
    addMonitorData(attributes, "assured-sr-received-updates", domain.getAssuredSrReceivedUpdates());
    addMonitorData(attributes, "assured-sr-received-updates-acked", domain.getAssuredSrReceivedUpdatesAcked());
    addMonitorData(attributes, "assured-sr-received-updates-not-acked", domain.getAssuredSrReceivedUpdatesNotAcked());
    addMonitorData(attributes, "assured-sd-sent-updates", domain.getAssuredSdSentUpdates());
    addMonitorData(attributes, "assured-sd-acknowledged-updates", domain.getAssuredSdAcknowledgedUpdates());
    addMonitorData(attributes, "assured-sd-timeout-updates", domain.getAssuredSdTimeoutUpdates());
    addMonitorData(attributes, "assured-sd-server-timeout-updates", domain.getAssuredSdServerTimeoutUpdates());
    // Status related monitoring fields
    addMonitorData(attributes, "last-status-change-date",
      domain.getLastStatusChangeDate().toString());
    addMonitorData(attributes, "last-status-change-date", domain.getLastStatusChangeDate().toString());
    addMonitorData(attributes, "status", domain.getStatus().toString());
@@ -217,8 +187,7 @@
   * @param name the name of the attribute to add.
   * @param value The integer value of he attribute to add.
   */
  public static void addMonitorData(List<Attribute> attributes, String name,
      int value)
  public static void addMonitorData(List<Attribute> attributes, String name, int value)
  {
    addMonitorData(attributes, name, String.valueOf(value));
  }
@@ -231,8 +200,7 @@
   * @param name the name of the attribute to add.
   * @param value The integer value of he attribute to add.
   */
  private static void addMonitorData(List<Attribute> attributes, String name,
      long value)
  private static void addMonitorData(List<Attribute> attributes, String name, long value)
  {
    addMonitorData(attributes, name, String.valueOf(value));
  }
@@ -245,8 +213,7 @@
   * @param name the name of the attribute to add.
   * @param value The String value of he attribute to add.
   */
  private static void addMonitorData(List<Attribute> attributes, String name,
      String value)
  private static void addMonitorData(List<Attribute> attributes, String name, String value)
  {
    AttributeType type = DirectoryServer.getDefaultAttributeType(name);
    attributes.add(Attributes.create(type, value));
opendj3-server-dev/src/server/org/opends/server/tasks/InitializeTargetTask.java
@@ -22,25 +22,30 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2013-2014 ForgeRock AS
 *      Portions Copyright 2013-2015 ForgeRock AS
 */
package org.opends.server.tasks;
import static org.opends.messages.BackendMessages.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.util.StaticUtils.*;
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.messages.TaskMessages;
import org.opends.server.backends.task.Task;
import org.opends.server.backends.task.TaskState;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.replication.plugin.LDAPReplicationDomain;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ResultCode;
import static org.opends.messages.BackendMessages.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.util.StaticUtils.*;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
/**
 * This class provides an implementation of a Directory Server task that can
@@ -56,17 +61,13 @@
  private int target;
  private long total;
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public LocalizableMessage getDisplayName() {
    return TaskMessages.INFO_TASK_INITIALIZE_TARGET_NAME.get();
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public void initializeTask() throws DirectoryException
  {
@@ -78,10 +79,8 @@
    // FIXME -- Do we need any special authorization here?
    Entry taskEntry = getTaskEntry();
    AttributeType typeDomainBase =
      getAttributeType(ATTR_TASK_INITIALIZE_TARGET_DOMAIN_DN, true);
    AttributeType typeScope =
      getAttributeType(ATTR_TASK_INITIALIZE_TARGET_SCOPE, true);
    AttributeType typeDomainBase = getAttributeType(ATTR_TASK_INITIALIZE_TARGET_DOMAIN_DN, true);
    AttributeType typeScope = getAttributeType(ATTR_TASK_INITIALIZE_TARGET_SCOPE, true);
    List<Attribute> attrList = taskEntry.getAttribute(typeDomainBase);
    domainString = TaskUtils.getSingleValueString(attrList);
@@ -108,15 +107,14 @@
    setTotal(0);
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  protected TaskState runTask()
  {
    if (logger.isTraceEnabled())
      logger.trace("[IE] InitializeTargetTask is starting on domain: "
          + domain.getBaseDNString());
    {
      logger.trace("[IE] InitializeTargetTask is starting on domain: " + domain.getBaseDN());
    }
    try
    {
opendj3-server-dev/src/server/org/opends/server/tasks/InitializeTask.java
@@ -22,23 +22,28 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2013-2014 ForgeRock AS
 *      Portions Copyright 2013-2015 ForgeRock AS
 */
package org.opends.server.tasks;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.core.DirectoryServer.*;
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.messages.TaskMessages;
import org.opends.server.backends.task.Task;
import org.opends.server.backends.task.TaskState;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.replication.plugin.LDAPReplicationDomain;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
/**
 * This class provides an implementation of a Directory Server task that can
@@ -54,31 +59,19 @@
  private LDAPReplicationDomain domain;
  private TaskState initState;
  /**
   * The total number of entries expected to be processed when this import will
   * end successfully.
   */
  private long total = 0;
  /** The total number of entries expected to be processed when this import will end successfully. */
  private long total;
  /** The number of entries still to be processed for this import to be completed. */
  private long left;
  private LocalizableMessage taskCompletionError;
  /**
   * The number of entries still to be processed for this import to be
   * completed.
   */
  private long left = 0;
  private LocalizableMessage taskCompletionError = null;
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public LocalizableMessage getDisplayName() {
    return TaskMessages.INFO_TASK_INITIALIZE_NAME.get();
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override public void initializeTask() throws DirectoryException
  {
    if (TaskState.isDone(getTaskState()))
@@ -123,16 +116,13 @@
    replaceAttributeValue(ATTR_TASK_INITIALIZE_DONE, String.valueOf(0));
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  protected TaskState runTask()
  {
    if (logger.isTraceEnabled())
    {
      logger.trace("[IE] InitializeTask is starting on domain: %s "
          + " from source:%d", domain.getBaseDNString(), source);
      logger.trace("[IE] InitializeTask is starting on domain: %s from source:%d", domain.getBaseDN(), source);
    }
    initState = getTaskState();
    try
@@ -146,19 +136,18 @@
        while (initState == TaskState.RUNNING)
        {
          initState.wait(1000);
          replaceAttributeValue(
              ATTR_TASK_INITIALIZE_LEFT, String.valueOf(left));
          replaceAttributeValue(
              ATTR_TASK_INITIALIZE_DONE, String.valueOf(total-left));
          replaceAttributeValue(ATTR_TASK_INITIALIZE_LEFT, String.valueOf(left));
          replaceAttributeValue(ATTR_TASK_INITIALIZE_DONE, String.valueOf(total-left));
        }
      }
      replaceAttributeValue(ATTR_TASK_INITIALIZE_LEFT, String.valueOf(left));
      replaceAttributeValue(
          ATTR_TASK_INITIALIZE_DONE, String.valueOf(total-left));
      replaceAttributeValue(ATTR_TASK_INITIALIZE_DONE, String.valueOf(total-left));
      // Error raised at completion time
      if (taskCompletionError != null)
      {
        logger.error(taskCompletionError);
      }
    }
    catch(InterruptedException ie) {}
@@ -185,9 +174,13 @@
    try
    {
      if (de == null)
      {
        initState =  TaskState.COMPLETED_SUCCESSFULLY;
      }
      else
      {
        taskCompletionError = de.getMessageObject();
      }
    }
    finally
    {
opendj3-server-dev/src/server/org/opends/server/tasks/PurgeConflictsHistoricalTask.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2013-2014 ForgeRock AS
 *      Portions Copyright 2013-2015 ForgeRock AS
 */
package org.opends.server.tasks;
@@ -50,10 +50,7 @@
 */
public class PurgeConflictsHistoricalTask extends Task
{
  /**
   * The default value for the maximum duration of the purge expressed in
   * seconds.
   */
  /** The default value for the maximum duration of the purge expressed in seconds. */
  public static final int DEFAULT_MAX_DURATION = 60 * 60;
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
@@ -80,7 +77,7 @@
  private TaskState initState;
  private static final void debugInfo(String s)
  private static void debugInfo(String s)
  {
    if (logger.isTraceEnabled())
    {
@@ -89,17 +86,13 @@
    }
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public LocalizableMessage getDisplayName() {
    return TaskMessages.INFO_TASK_PURGE_CONFLICTS_HIST_NAME.get();
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override public void initializeTask() throws DirectoryException
  {
    if (TaskState.isDone(getTaskState()))
@@ -110,12 +103,8 @@
    // FIXME -- Do we need any special authorization here?
    Entry taskEntry = getTaskEntry();
    AttributeType typeDomainBase;
    typeDomainBase =
      getAttributeType(ATTR_TASK_CONFLICTS_HIST_PURGE_DOMAIN_DN, true);
    List<Attribute> attrList;
    attrList = taskEntry.getAttribute(typeDomainBase);
    AttributeType typeDomainBase = getAttributeType(ATTR_TASK_CONFLICTS_HIST_PURGE_DOMAIN_DN, true);
    List<Attribute> attrList = taskEntry.getAttribute(typeDomainBase);
    domainString = TaskUtils.getSingleValueString(attrList);
    try
@@ -129,13 +118,10 @@
      LocalizableMessageBuilder mb = new LocalizableMessageBuilder();
      mb.append(TaskMessages.ERR_TASK_INITIALIZE_INVALID_DN.get());
      mb.append(e.getMessage());
      throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
          mb.toMessage());
      throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, mb.toMessage());
    }
    AttributeType typeMaxDuration;
    typeMaxDuration =
      getAttributeType(ATTR_TASK_CONFLICTS_HIST_PURGE_MAX_DURATION, true);
    AttributeType typeMaxDuration = getAttributeType(ATTR_TASK_CONFLICTS_HIST_PURGE_MAX_DURATION, true);
    attrList = taskEntry.getAttribute(typeMaxDuration);
    String maxDurationStringInSec = TaskUtils.getSingleValueString(attrList);
@@ -155,9 +141,7 @@
    }
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  protected TaskState runTask()
  {
@@ -165,28 +149,24 @@
    if (logger.isTraceEnabled())
    {
      debugInfo("[PURGE] PurgeConflictsHistoricalTask is starting "
          + "on domain: " + domain.getBaseDNString()
          + "on domain: " + domain.getBaseDN()
          + "max duration (sec):" + purgeTaskMaxDurationInSec);
    }
    try
    {
      replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_COMPLETED_IN_TIME,
          purgeCompletedInTime.toString());
      replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_COMPLETED_IN_TIME, purgeCompletedInTime.toString());
      // launch the task
      domain.purgeConflictsHistorical(this,
          TimeThread.getTime() + (purgeTaskMaxDurationInSec*1000));
      domain.purgeConflictsHistorical(this, TimeThread.getTime() + purgeTaskMaxDurationInSec*1000);
      purgeCompletedInTime = true;
      replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_COMPLETED_IN_TIME,
          purgeCompletedInTime.toString());
      replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_COMPLETED_IN_TIME, purgeCompletedInTime.toString());
      initState =  TaskState.COMPLETED_SUCCESSFULLY;
    }
    catch(DirectoryException de)
    {
      debugInfo("[PURGE] PurgeConflictsHistoricalTask exception " +
          de.getLocalizedMessage());
      debugInfo("[PURGE] PurgeConflictsHistoricalTask exception " + de.getLocalizedMessage());
      if (de.getResultCode() != ResultCode.ADMIN_LIMIT_EXCEEDED)
      {
        // Error raised at submission time
@@ -203,30 +183,26 @@
      try
      {
        // sets in the attributes the last stats values
        replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_COUNT,
            String.valueOf(this.purgeCount));
        replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_LAST_CSN,
            this.lastCSN.toStringUI());
        replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_COUNT, String.valueOf(purgeCount));
        replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_LAST_CSN, lastCSN.toStringUI());
        debugInfo("[PURGE] PurgeConflictsHistoricalTask write  attrs ");
      }
      catch(Exception e)
      {
        debugInfo("[PURGE] PurgeConflictsHistoricalTask exception " +
            e.getLocalizedMessage());
        debugInfo("[PURGE] PurgeConflictsHistoricalTask exception " + e.getLocalizedMessage());
        initState = TaskState.STOPPED_BY_ERROR;
      }
    }
    if (logger.isTraceEnabled())
    {
      debugInfo("[PURGE] PurgeConflictsHistoricalTask is ending " +
            "with state:" + initState.toString() +
      debugInfo("[PURGE] PurgeConflictsHistoricalTask is ending with state:" + initState +
            " completedInTime:" + purgeCompletedInTime);
    }
    return initState;
  }
  private int updateAttrPeriod = 0;
  private int updateAttrPeriod;
  private CSN lastCSN;
  private int purgeCount;
@@ -244,27 +220,23 @@
    try
    {
      if (purgeCount == 0)
        replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_FIRST_CSN,
            lastCSN.toStringUI());
      {
        replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_FIRST_CSN, lastCSN.toStringUI());
      }
      // we don't want the update of the task to overload too much task duration
      this.purgeCount = purgeCount;
      this.lastCSN = lastCSN;
      if (++updateAttrPeriod % 100 == 0)
      {
        replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_COUNT,
            String.valueOf(purgeCount));
        replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_LAST_CSN,
            lastCSN.toStringUI());
        debugInfo("[PURGE] PurgeConflictsHistoricalTask write  attrs "
            + purgeCount);
        replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_COUNT, String.valueOf(purgeCount));
        replaceAttributeValue(ATTR_TASK_CONFLICTS_HIST_PURGE_LAST_CSN, lastCSN.toStringUI());
        debugInfo("[PURGE] PurgeConflictsHistoricalTask write  attrs " + purgeCount);
      }
    }
    catch(DirectoryException de)
    {
      debugInfo("[PURGE] PurgeConflictsHistoricalTask exception " +
          de.getLocalizedMessage());
      debugInfo("[PURGE] PurgeConflictsHistoricalTask exception " + de.getLocalizedMessage());
      initState = TaskState.STOPPED_BY_ERROR;
    }
  }
opendj3-server-dev/src/server/org/opends/server/tasks/SetGenerationIdTask.java
@@ -22,24 +22,29 @@
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2013-2014 ForgeRock AS
 *      Portions Copyright 2013-2015 ForgeRock AS
 */
package org.opends.server.tasks;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.core.DirectoryServer.*;
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.messages.TaskMessages;
import org.opends.server.backends.task.Task;
import org.opends.server.backends.task.TaskState;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.replication.plugin.LDAPReplicationDomain;
import org.opends.server.replication.service.ReplicationDomain;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
/**
 * This class provides an implementation of a Directory Server task that can
@@ -49,21 +54,17 @@
public class SetGenerationIdTask extends Task
{
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  private String  domainString            = null;
  private ReplicationDomain domain        = null;
  private Long generationId = null;
  private String  domainString;
  private ReplicationDomain domain;
  private Long generationId;
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public LocalizableMessage getDisplayName() {
    return TaskMessages.INFO_TASK_SET_GENERATION_ID_NAME.get();
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public void initializeTask() throws DirectoryException
  {
@@ -76,10 +77,9 @@
    Entry taskEntry = getTaskEntry();
    // Retrieves the eventual generation-ID
    AttributeType typeNewValue =
      getAttributeType(ATTR_TASK_SET_GENERATION_ID_NEW_VALUE, true);
    AttributeType typeNewValue = getAttributeType(ATTR_TASK_SET_GENERATION_ID_NEW_VALUE, true);
    List<Attribute> attrList = taskEntry.getAttribute(typeNewValue);
    if ((attrList != null) && !attrList.isEmpty())
    if (attrList != null && !attrList.isEmpty())
    {
      try
      {
@@ -90,15 +90,12 @@
        LocalizableMessageBuilder mb = new LocalizableMessageBuilder();
        mb.append(TaskMessages.ERR_TASK_INITIALIZE_INVALID_GENERATION_ID.get());
        mb.append(e.getMessage());
        throw new DirectoryException(ResultCode.CLIENT_SIDE_PARAM_ERROR,
            mb.toMessage());
        throw new DirectoryException(ResultCode.CLIENT_SIDE_PARAM_ERROR, mb.toMessage());
      }
    }
    // Retrieves the replication domain
    AttributeType typeDomainBase =
      getAttributeType(ATTR_TASK_SET_GENERATION_ID_DOMAIN_DN, true);
    AttributeType typeDomainBase = getAttributeType(ATTR_TASK_SET_GENERATION_ID_DOMAIN_DN, true);
    attrList = taskEntry.getAttribute(typeDomainBase);
    domainString = TaskUtils.getSingleValueString(attrList);
@@ -116,16 +113,13 @@
    }
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  protected TaskState runTask()
  {
    if (logger.isTraceEnabled())
    {
      logger.trace("setGenerationIdTask is starting on domain %s"
              + domain.getBaseDNString());
      logger.trace("setGenerationIdTask is starting on domain %s" + domain.getBaseDN());
    }
    try
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DummyReplicationDomain.java
@@ -20,7 +20,7 @@
 *
 * CDDL HEADER END
 *
 *      Copyright 2013-2014 ForgeRock AS
 *      Copyright 2013-2015 ForgeRock AS
 */
package org.opends.server.replication.plugin;
@@ -34,21 +34,35 @@
import org.opends.server.replication.common.StatusMachineEvent;
import org.opends.server.replication.protocol.UpdateMsg;
import org.opends.server.replication.service.ReplicationDomain;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
@SuppressWarnings("javadoc")
public class DummyReplicationDomain extends ReplicationDomain
{
  private static DN baseDN;
  static
  {
    try
    {
      baseDN = DN.valueOf("cn=DummyReplicationDomain");
    }
    catch (DirectoryException e)
    {
      throw new RuntimeException(e);
    }
  }
  public DummyReplicationDomain(long generationId)
  {
    super(new DomainFakeCfg(null, -1, new TreeSet<String>()), generationId);
  }
  @Override
  public String getBaseDNString()
  public DN getBaseDN()
  {
    return "DummyReplicationDomain";
    return baseDN;
  }
  @Override
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/replication/service/ReplicationDomainTest.java
@@ -22,10 +22,14 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2014 ForgeRock AS
 *      Portions Copyright 2011-2015 ForgeRock AS
 */
package org.opends.server.replication.service;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.TestCaseUtils.*;
import static org.testng.Assert.*;
import java.util.Arrays;
import java.util.Map;
import java.util.SortedSet;
@@ -52,10 +56,6 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.TestCaseUtils.*;
import static org.testng.Assert.*;
/**
 * Test the Generic Replication Service.
 */
@@ -218,7 +218,7 @@
    catch (TimeoutException ex)
    {
      // This exception may only be raised if assured replication is enabled
      logger.info(NOTE_DS_ACK_TIMEOUT, domain.getBaseDNString(), domain.getAssuredTimeout(), updateMsg);
      logger.info(NOTE_DS_ACK_TIMEOUT, domain.getBaseDN(), domain.getAssuredTimeout(), updateMsg);
    }
  }