/* (non-Javadoc)
     * @see cn.com.rebirth.search.core.node.settings.NodeSettingsService.Listener#onRefreshSettings(cn.com.rebirth.commons.settings.Settings)
     */
    @Override
    public void onRefreshSettings(Settings settings) {
      boolean disableAllocation =
          settings.getAsBoolean(
              "cluster.routing.allocation.disable_allocation",
              DisableAllocationDecider.this.disableAllocation);
      if (disableAllocation != DisableAllocationDecider.this.disableAllocation) {
        logger.info(
            "updating [cluster.routing.allocation.disable_allocation] from [{}] to [{}]",
            DisableAllocationDecider.this.disableAllocation,
            disableAllocation);
        DisableAllocationDecider.this.disableAllocation = disableAllocation;
      }

      boolean disableReplicaAllocation =
          settings.getAsBoolean(
              "cluster.routing.allocation.disable_replica_allocation",
              DisableAllocationDecider.this.disableReplicaAllocation);
      if (disableReplicaAllocation != DisableAllocationDecider.this.disableReplicaAllocation) {
        logger.info(
            "updating [cluster.routing.allocation.disable_replica_allocation] from [{}] to [{}]",
            DisableAllocationDecider.this.disableReplicaAllocation,
            disableReplicaAllocation);
        DisableAllocationDecider.this.disableReplicaAllocation = disableReplicaAllocation;
      }
    }
  /**
   * Instantiates a new disable allocation decider.
   *
   * @param settings the settings
   * @param nodeSettingsService the node settings service
   */
  @Inject
  public DisableAllocationDecider(Settings settings, NodeSettingsService nodeSettingsService) {
    super(settings);
    this.disableAllocation =
        settings.getAsBoolean("cluster.routing.allocation.disable_allocation", false);
    this.disableReplicaAllocation =
        settings.getAsBoolean("cluster.routing.allocation.disable_replica_allocation", false);

    nodeSettingsService.addListener(new ApplySettings());
  }
    /* (non-Javadoc)
     * @see cn.com.rebirth.search.core.index.settings.IndexSettingsService.Listener#onRefreshSettings(cn.com.rebirth.commons.settings.Settings)
     */
    @Override
    public void onRefreshSettings(Settings settings) {
      double expungeDeletesPctAllowed =
          settings.getAsDouble(
              "index.merge.policy.expunge_deletes_allowed",
              TieredMergePolicyProvider.this.forceMergeDeletesPctAllowed);
      if (expungeDeletesPctAllowed != TieredMergePolicyProvider.this.forceMergeDeletesPctAllowed) {
        logger.info(
            "updating [expunge_deletes_allowed] from [{}] to [{}]",
            TieredMergePolicyProvider.this.forceMergeDeletesPctAllowed,
            expungeDeletesPctAllowed);
        TieredMergePolicyProvider.this.forceMergeDeletesPctAllowed = expungeDeletesPctAllowed;
        for (CustomTieredMergePolicyProvider policy : policies) {
          policy.setForceMergeDeletesPctAllowed(expungeDeletesPctAllowed);
        }
      }

      ByteSizeValue floorSegment =
          settings.getAsBytesSize(
              "index.merge.policy.floor_segment", TieredMergePolicyProvider.this.floorSegment);
      if (!floorSegment.equals(TieredMergePolicyProvider.this.floorSegment)) {
        logger.info(
            "updating [floor_segment] from [{}] to [{}]",
            TieredMergePolicyProvider.this.floorSegment,
            floorSegment);
        TieredMergePolicyProvider.this.floorSegment = floorSegment;
        for (CustomTieredMergePolicyProvider policy : policies) {
          policy.setFloorSegmentMB(floorSegment.mbFrac());
        }
      }

      int maxMergeAtOnce =
          settings.getAsInt(
              "index.merge.policy.max_merge_at_once",
              TieredMergePolicyProvider.this.maxMergeAtOnce);
      if (maxMergeAtOnce != TieredMergePolicyProvider.this.maxMergeAtOnce) {
        logger.info(
            "updating [max_merge_at_once] from [{}] to [{}]",
            TieredMergePolicyProvider.this.maxMergeAtOnce,
            maxMergeAtOnce);
        TieredMergePolicyProvider.this.maxMergeAtOnce = maxMergeAtOnce;
        for (CustomTieredMergePolicyProvider policy : policies) {
          policy.setMaxMergeAtOnce(maxMergeAtOnce);
        }
      }

      int maxMergeAtOnceExplicit =
          settings.getAsInt(
              "index.merge.policy.max_merge_at_once_explicit",
              TieredMergePolicyProvider.this.maxMergeAtOnceExplicit);
      if (maxMergeAtOnceExplicit != TieredMergePolicyProvider.this.maxMergeAtOnceExplicit) {
        logger.info(
            "updating [max_merge_at_once_explicit] from [{}] to [{}]",
            TieredMergePolicyProvider.this.maxMergeAtOnceExplicit,
            maxMergeAtOnceExplicit);
        TieredMergePolicyProvider.this.maxMergeAtOnceExplicit = maxMergeAtOnceExplicit;
        for (CustomTieredMergePolicyProvider policy : policies) {
          policy.setMaxMergeAtOnceExplicit(maxMergeAtOnceExplicit);
        }
      }

      ByteSizeValue maxMergedSegment =
          settings.getAsBytesSize(
              "index.merge.policy.max_merged_segment",
              TieredMergePolicyProvider.this.maxMergedSegment);
      if (!maxMergedSegment.equals(TieredMergePolicyProvider.this.maxMergedSegment)) {
        logger.info(
            "updating [max_merged_segment] from [{}] to [{}]",
            TieredMergePolicyProvider.this.maxMergedSegment,
            maxMergedSegment);
        TieredMergePolicyProvider.this.maxMergedSegment = maxMergedSegment;
        for (CustomTieredMergePolicyProvider policy : policies) {
          policy.setFloorSegmentMB(maxMergedSegment.mbFrac());
        }
      }

      double segmentsPerTier =
          settings.getAsDouble(
              "index.merge.policy.segments_per_tier",
              TieredMergePolicyProvider.this.segmentsPerTier);
      if (segmentsPerTier != TieredMergePolicyProvider.this.segmentsPerTier) {
        logger.info(
            "updating [segments_per_tier] from [{}] to [{}]",
            TieredMergePolicyProvider.this.segmentsPerTier,
            segmentsPerTier);
        TieredMergePolicyProvider.this.segmentsPerTier = segmentsPerTier;
        for (CustomTieredMergePolicyProvider policy : policies) {
          policy.setSegmentsPerTier(segmentsPerTier);
        }
      }

      double reclaimDeletesWeight =
          settings.getAsDouble(
              "index.merge.policy.reclaim_deletes_weight",
              TieredMergePolicyProvider.this.reclaimDeletesWeight);
      if (reclaimDeletesWeight != TieredMergePolicyProvider.this.reclaimDeletesWeight) {
        logger.info(
            "updating [reclaim_deletes_weight] from [{}] to [{}]",
            TieredMergePolicyProvider.this.reclaimDeletesWeight,
            reclaimDeletesWeight);
        TieredMergePolicyProvider.this.reclaimDeletesWeight = reclaimDeletesWeight;
        for (CustomTieredMergePolicyProvider policy : policies) {
          policy.setReclaimDeletesWeight(reclaimDeletesWeight);
        }
      }

      boolean compoundFormat =
          settings.getAsBoolean(
              "index.compound_format", TieredMergePolicyProvider.this.compoundFormat);
      if (compoundFormat != TieredMergePolicyProvider.this.compoundFormat) {
        logger.info(
            "updating index.compound_format from [{}] to [{}]",
            TieredMergePolicyProvider.this.compoundFormat,
            compoundFormat);
        TieredMergePolicyProvider.this.compoundFormat = compoundFormat;
        for (CustomTieredMergePolicyProvider policy : policies) {
          policy.setUseCompoundFile(compoundFormat);
        }
      }
    }