code: private void  handleLeadershipChange(NotificationContext changeContext) {
      if (this.helixManager.isPresent() && this.helixManager.get().isLeader()) {
        LOGGER.info("Leader notification for {} HM.isLeader {}", this.helixManager.get().getInstanceName(),
            this.helixManager.get().isLeader());
  
        if (this.isSchedulerEnabled) {
          LOGGER.info("Gobblin Service is now running in master instance mode, enabling Scheduler.");
          this.scheduler.setActive(true);
        }
  
        if (this.isGitConfigMonitorEnabled) {
          this.gitConfigMonitor.setActive(true);
        }
  
        if (this.isDagManagerEnabled) {
          //Activate DagManager only if TopologyCatalog is initialized. If not; skip activation.
          if (this.topologyCatalog.getInitComplete().getCount() == 0) {
            this.dagManager.setActive(true);
          }
        }
      } else if (this.helixManager.isPresent()) {
        LOGGER.info("Leader lost notification for {} HM.isLeader {}", this.helixManager.get().getInstanceName(),
            this.helixManager.get().isLeader());
        if (this.isSchedulerEnabled) {
          LOGGER.info("Gobblin Service is now running in slave instance mode, disabling Scheduler.");
          this.scheduler.setActive(false);
        }
  
        if (this.isGitConfigMonitorEnabled) {
          this.gitConfigMonitor.setActive(false);
        }
  
        if (this.isDagManagerEnabled) {
          this.dagManager.setActive(false);
        }
      }
    }
docs: Handle leadership change.
  @param changeContext notification context