public static boolean addLocator(int distributedSystemId, DistributionLocatorId locator,
      LocatorMembershipListener locatorListener, DistributionLocatorId sourceLocator) {
    final ConcurrentMap<Integer, Set<DistributionLocatorId>> allLocatorsInfo = locatorListener
        .getAllLocatorsInfo();
    Set<DistributionLocatorId> locatorsSet = new CopyOnWriteHashSet<>();
    locatorsSet.add(locator);
    Set<DistributionLocatorId> existingValue =
        allLocatorsInfo.putIfAbsent(distributedSystemId, locatorsSet);
    if (existingValue != null) {
      if (!locator.getMemberName().equals(DistributionConfig.DEFAULT_NAME)) {
        final DistributionLocatorId existingLocator =
            getLocatorWithSameMemberName(existingValue, locator);

        if (existingLocator != null) {
          // if locator with same name exist, check did all parameters are same
          if (!locator.detailCompare(existingLocator)) {
            // some parameters had changed for existing locator replace it
            if (existingLocator.getTimeStamp() > locator.getTimeStamp()) {
              return false;
            }

            existingValue.remove(existingLocator);
            final ConcurrentMap<Integer, Set<String>> allServerLocatorsInfo = locatorListener
                .getAllServerLocatorsInfo();
            Set<String> allLocators = allServerLocatorsInfo.get(distributedSystemId);
            allLocators.remove(existingLocator.toString());
            existingValue.add(locator);
            addServerLocator(distributedSystemId, locatorListener, locator);
            locatorListener.locatorJoined(distributedSystemId, locator, sourceLocator);
            return true;
          }
          return false;
        } else if (!existingValue.contains(locator)) {
          existingValue.add(locator);
          addServerLocator(distributedSystemId, locatorListener, locator);
          locatorListener.locatorJoined(distributedSystemId, locator, sourceLocator);
          return true;

        } else {
          DistributionLocatorId oldLocator =
              getLocatorFromCollection(existingValue, locator);

          if (oldLocator == null) {
            return false;
          }

          if (oldLocator.getTimeStamp() > locator.getTimeStamp()) {
            return false;
          }

          // for new member name, existing host[port] received
          // replace it, to contain the latest info
          existingValue.remove(oldLocator);
          // member name is not used in equals(), so this is the way to replace old locator
          existingValue.add(locator);
          locatorListener.locatorJoined(distributedSystemId, locator, sourceLocator);
          return true;

        }

      } else if (!existingValue.contains(locator)) {
        existingValue.add(locator);
        addServerLocator(distributedSystemId, locatorListener, locator);
        locatorListener.locatorJoined(distributedSystemId, locator, sourceLocator);

      } else {
        return false;

      }

    } else {
      addServerLocator(distributedSystemId, locatorListener, locator);
      locatorListener.locatorJoined(distributedSystemId, locator, sourceLocator);
    }
    return true;
  }
This method adds the given locator to allLocatorInfoMap. It also invokes a locatorListener to
inform other locators in allLocatorInfoMap about this newly added locator.
geode-wan/src/main/java/org/apache/geode/cache/wan/internal/client/locator/LocatorHelper.java