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

jcduff
23.04.2008 f73b655466092169abac34833fb628fce1fcdebe
opends/src/server/org/opends/server/replication/server/LightweightServerHandler.java
@@ -32,18 +32,20 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import org.opends.server.admin.std.server.MonitorProviderCfg;
import org.opends.server.api.MonitorProvider;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.replication.common.AssuredMode;
import org.opends.server.replication.common.DSInfo;
import org.opends.server.replication.common.ServerState;
import org.opends.server.replication.common.ServerStatus;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.DN;
import org.opends.server.types.AttributeBuilder;
import org.opends.server.types.Attributes;
import org.opends.server.types.InitializationException;
/**
@@ -62,27 +64,62 @@
  // The tracer object for the debug logger.
  private static final DebugTracer TRACER = getTracer();
  short serverId;
  ServerHandler replServerHandler;
  ReplicationServerDomain rsDomain;
  DN baseDn;
  private ServerHandler replServerHandler;
  private ReplicationServerDomain rsDomain;
  // The id of the RS this DS is connected to
  private short replicationServerId = -1;
  // Server id of this DS
  private short serverId = -1;
  // Generation id of this DS
  private long generationId = -1;
  // Group id of the DS;
  private byte groupId = (byte) -1;
  // Status of this DS
  private ServerStatus status = ServerStatus.INVALID_STATUS;
  // Referrals URLs this DS is exporting
  private List<String> refUrls = new ArrayList<String>();
  // Assured replication enabled on DS or not
  private boolean assuredFlag = false;
  // DS assured mode (relevant if assured replication enabled)
  private AssuredMode assuredMode = AssuredMode.SAFE_DATA_MODE;
  // DS safe data level (relevant if assured mode is safe data)
  private byte safeDataLevel = (byte) -1;
  /**
   * Creates a new LighweightServerHandler with the provided serverid, connected
   * to the remote Replication Server represented by replServerHandler.
   *
   * @param serverId The serverId of this remote LDAP server.
   * @param replServerHandler The server handler of the Replication Server to
   * which this LDAP server is remotely connected.
   * @param replServerHandler The server handler of the RS this remote DS is
   * connected to
   * @param replicationServerId The serverId of the RS this remote DS is
   * connected to
   * @param serverId The serverId of this remote DS.
   * @param generationId The generation id of this remote DS.
   * @param groupId The group id of the remote DS
   * @param status The  id of the remote DS
   * @param refUrls The exported referral URLs of the remote DS
   * @param assuredFlag The assured flag of the remote DS
   * @param assuredMode The assured mode of the remote DS
   * @param safeDataLevel The safe data level of the remote DS
   */
  public LightweightServerHandler(String serverId,
      ServerHandler replServerHandler)
  public LightweightServerHandler(ServerHandler replServerHandler,
    short replicationServerId, short serverId, long generationId, byte groupId,
    ServerStatus status, List<String> refUrls, boolean assuredFlag,
    AssuredMode assuredMode, byte safeDataLevel)
  {
    super("Server Handler");
    this.serverId = Short.valueOf(serverId);
    this.replServerHandler = replServerHandler;
    this.rsDomain = replServerHandler.getDomain();
    this.baseDn = rsDomain.getBaseDn();
    this.replicationServerId = replicationServerId;
    this.serverId = serverId;
    this.generationId = generationId;
    this.groupId = groupId;
    this.status = status;
    this.refUrls = refUrls;
    this.assuredFlag = assuredFlag;
    this.assuredMode = assuredMode;
    this.safeDataLevel = safeDataLevel;
    if (debugEnabled())
      TRACER.debugInfo(
@@ -94,6 +131,18 @@
}
  /**
   * Creates a DSInfo structure representing this remote DS.
   * @return The DSInfo structure representing this remote DS
   */
  public DSInfo toDSInfo()
  {
    DSInfo dsInfo = new DSInfo(serverId, replicationServerId, generationId,
      status, assuredFlag, assuredMode, safeDataLevel, groupId, refUrls);
    return dsInfo;
  }
  /**
   * Get the serverID associated with this LDAP server.
   * @return The serverId.
   */
@@ -154,7 +203,7 @@
  public String getMonitorInstanceName()
  {
    String serverURL=""; // FIXME
    String str = baseDn.toString() + " " + serverURL + " "
    String str = rsDomain.getBaseDn().toString() + " " + serverURL + " "
       + String.valueOf(serverId);
    return "Undirect LDAP Server " + str;
  }
@@ -202,11 +251,11 @@
  {
    ArrayList<Attribute> attributes = new ArrayList<Attribute>();
    attributes.add(new Attribute("server-id",
    attributes.add(Attributes.create("server-id",
        String.valueOf(serverId)));
    attributes.add(new Attribute("base-dn",
    attributes.add(Attributes.create("base-dn",
        rsDomain.getBaseDn().toNormalizedString()));
    attributes.add(new Attribute("connected-to",
    attributes.add(Attributes.create("connected-to",
        replServerHandler.getMonitorInstanceName()));
    // Retrieves the topology counters
@@ -222,42 +271,37 @@
      }
      /* get the Server State */
      final String ATTR_SERVER_STATE = "server-state";
      AttributeType type =
        DirectoryServer.getDefaultAttributeType(ATTR_SERVER_STATE);
      LinkedHashSet<AttributeValue> values =
        new LinkedHashSet<AttributeValue>();
      AttributeBuilder builder = new AttributeBuilder("server-state");
      for (String str : remoteState.toStringSet())
      {
        values.add(new AttributeValue(type,str));
        builder.add(str);
      }
      if (values.size() == 0)
      if (builder.size() == 0)
      {
        values.add(new AttributeValue(type,"unknown"));
        builder.add("unknown");
      }
      Attribute attr = new Attribute(type, ATTR_SERVER_STATE, values);
      attributes.add(attr);
      attributes.add(builder.toAttribute());
      // Oldest missing update
      Long approxFirstMissingDate=md.getApproxFirstMissingDate(serverId);
      if ((approxFirstMissingDate != null) && (approxFirstMissingDate>0))
      {
        Date date = new Date(approxFirstMissingDate);
        attributes.add(new Attribute("approx-older-change-not-synchronized",
          date.toString()));
        attributes.add(
            new Attribute("approx-older-change-not-synchronized-millis",
            String.valueOf(approxFirstMissingDate)));
        attributes.add(Attributes.create(
            "approx-older-change-not-synchronized", date.toString()));
        attributes.add(Attributes.create(
            "approx-older-change-not-synchronized-millis", String
                .valueOf(approxFirstMissingDate)));
      }
      // Missing changes
      long missingChanges = md.getMissingChanges(serverId);
      attributes.add(new Attribute("missing-changes",
      attributes.add(Attributes.create("missing-changes",
          String.valueOf(missingChanges)));
      // Replication delay
      long delay = md.getApproxDelay(serverId);
      attributes.add(new Attribute("approximate-delay",
      attributes.add(Attributes.create("approximate-delay",
          String.valueOf(delay)));
    }
@@ -265,7 +309,7 @@
    {
      // TODO: improve the log
      // We failed retrieving the remote monitor data.
      attributes.add(new Attribute("error",
      attributes.add(Attributes.create("error",
        stackTraceToSingleLineString(e)));
    }
    return attributes;