private void mainLoop() {
    long lastRefreshTime = EnvironmentEdgeManager.currentTime();
    boolean firstRefresh = true;
    for (;;) {
      synchronized (this) {
        for (;;) {
          if (stopped) {
            LOG.info("Registry end points refresher loop exited.");
            return;
          }
          // if refreshNow is true, then we will wait until minTimeBetweenRefreshesMs elapsed,
          // otherwise wait until periodicRefreshMs elapsed
          long waitTime = getRefreshIntervalMs(firstRefresh)
            - (EnvironmentEdgeManager.currentTime() - lastRefreshTime);
          if (waitTime <= 0) {
            // we are going to refresh, reset this flag
            firstRefresh = false;
            refreshNow = false;
            break;
          }
          try {
            wait(waitTime);
          } catch (InterruptedException e) {
            LOG.warn("Interrupted during wait", e);
            Thread.currentThread().interrupt();
            continue;
          }
        }
      }
      LOG.debug("Attempting to refresh registry end points");
      try {
        refresher.refresh();
      } catch (IOException e) {
        LOG.warn("Error refresh registry end points", e);
      }
      // We do not think it is a big deal to fail one time, so no matter what is refresh result, we
      // just update this refresh time and wait for the next round. If later this becomes critical,
      // could change to only update this value when we have done a successful refreshing.
      lastRefreshTime = EnvironmentEdgeManager.currentTime();
      LOG.debug("Finished refreshing registry end points");
    }
  }
Thread safe utility that keeps registry end points used by {@link ConnectionRegistry} up to date.
By default the refresh happens periodically (configured via {@code intervalSecsConfigName}). The
refresh can also be triggered on demand via {@link #refreshNow()}. To prevent a flood of
on-demand refreshes we expect that any attempts two should be spaced at least
{@code minIntervalSecsConfigName} seconds apart.
hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegistryEndpointsRefresher.java