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

pgamba
14.37.2009 5ec0cb08889c9f1a24fd4cc8b139dcdb942dd92a
opendj-sdk/opends/src/server/org/opends/server/replication/common/MultiDomainServerState.java
@@ -26,9 +26,16 @@
 */
package org.opends.server.replication.common;
import java.util.HashMap;
import java.util.Iterator;
import java.util.TreeMap;
import org.opends.messages.Category;
import org.opends.messages.Message;
import org.opends.messages.Severity;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ResultCode;
/**
 * This object is used to store a list of ServerState object, one by
@@ -106,7 +113,7 @@
   */
  public void update(String serviceId, ServerState serverState)
  {
    list.put(serviceId,serverState);
    list.put(serviceId,serverState.duplicate());
  }
  /**
@@ -208,11 +215,59 @@
    {
      ServerState state = list.get(serviceId);
      ServerState coveredState = covered.list.get(serviceId);
      if ((coveredState == null) || (!state.cover(coveredState)))
      if ((state==null)||(coveredState == null) || (!state.cover(coveredState)))
      {
        return false;
      }
    }
    return true;
  }
  /**
   * Splits the provided generalizedServerState being a String with the
   * following syntax: "domain1:state1;domain2:state2;..."
   * to a hashmap of (domain DN, domain ServerState).
   * @param multidomainserverstate the provided state
   * @exception DirectoryException when an error occurs
   * @return the splited state.
   */
  public static HashMap<String,ServerState> splitGenStateToServerStates(
      String multidomainserverstate)
      throws DirectoryException
  {
    HashMap<String,ServerState> startStates = new HashMap<String,ServerState>();
    try
    {
      // Split the provided multidomainserverstate into domains
      String[] domains = multidomainserverstate.split(";");
      for (String domain : domains)
      {
        // For each domain, split the changenumbers by server
        // and build a server state (SHOULD BE OPTIMIZED)
        ServerState serverStateByDomain = new ServerState();
        String[] fields = domain.split(":");
        String domainBaseDN = fields[0];
        if (fields.length>1)
        {
          String strState = fields[1];
          String[] strCN = strState.split(" ");
          for (String sr : strCN)
          {
            ChangeNumber fromChangeNumber = new ChangeNumber(sr);
            serverStateByDomain.update(fromChangeNumber);
          }
        }
        startStates.put(domainBaseDN, serverStateByDomain);
      }
    }
    catch(Exception e)
    {
      throw new DirectoryException(
          ResultCode.OPERATIONS_ERROR,
          Message.raw(Category.SYNC, Severity.INFORMATION,"Exception raised: "),
          e);
    }
    return startStates;
  }
}