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

Matthew Swift
31.25.2013 5a872b4517410def8b08290ebd0645b053be4e32
opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -537,11 +537,7 @@
      dbEnv = new ReplicationDbEnv(getFileForPath(dbDirname).getAbsolutePath(),
          this);
      /*
       * Open replicationServer socket
       */
      String localhostname = InetAddress.getLocalHost().getHostName();
      serverURL = localhostname + ":" + String.valueOf(replicationPort);
      setServerURL();
      listenSocket = new ServerSocket();
      listenSocket.bind(new InetSocketAddress(replicationPort));
@@ -1038,8 +1034,7 @@
        stopListen = false;
        replicationPort = newPort;
        String localhostname = InetAddress.getLocalHost().getHostName();
        serverURL = localhostname + ":" + String.valueOf(replicationPort);
        setServerURL();
        listenSocket = new ServerSocket();
        listenSocket.bind(new InetSocketAddress(replicationPort));
@@ -1151,6 +1146,41 @@
    return new ConfigChangeResult(ResultCode.SUCCESS, false);
  }
  /*
   * Try and set a sensible URL for this replication server. Since we are
   * listening on all addresses there are a couple of potential candidates: 1) a
   * matching server url in the replication server's configuration, 2) hostname
   * local address.
   */
  private void setServerURL() throws UnknownHostException
  {
    /*
     * First try the set of configured replication servers to see if one of them
     * is this replication server (this should always be the case).
     */
    for (String rs : replicationServers)
    {
      /*
       * No need validate the string format because the admin framework has
       * already done it.
       */
      final int index = rs.lastIndexOf(":");
      final String hostname = rs.substring(0, index);
      final int port = Integer.parseInt(rs.substring(index + 1));
      if (port == replicationPort && isLocalAddress(hostname))
      {
        serverURL = rs;
        return;
      }
    }
    /*
     * Fall-back to the machine hostname.
     */
    serverURL = InetAddress.getLocalHost().getHostName() + ":"
        + replicationPort;
  }
  /**
   * Broadcast a configuration change that just happened to the whole topology
   * by sending a TopologyMsg to every entity in the topology.