<commit_before>package com.outbrain.ob1k.consul;

import com.google.common.base.Preconditions;
import com.outbrain.ob1k.client.targets.TargetProvider;
import io.netty.util.internal.ThreadLocalRandom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * A {@link TargetProvider} that provides targets registered in consul.
 *
 * @author <NAME>
 */
public class ConsulBasedTargetProvider implements TargetProvider, HealthyTargetsList.TargetsChangedListener {

  private static final Logger log = LoggerFactory.getLogger(ConsulBasedTargetProvider.class);

  private final ThreadLocal<Integer> currIndex = new ThreadLocal<Integer>() {
    @Override
    protected Integer initialValue() {
      return ThreadLocalRandom.current().nextInt();
    }
  };

  private final String urlSuffix;
  private final Map<String, Integer> tag2weight;
  private final HealthyTargetsList healtyTargetsList;
  private volatile List<String> targets;

  public ConsulBasedTargetProvider(final HealthyTargetsList healtyTargetsList, final String urlSuffix, final Map<String, Integer> tag2weight) {
    this.urlSuffix = urlSuffix == null ? "" : urlSuffix;
    this.tag2weight = tag2weight == null ? Collections.<String, Integer>emptyMap() : new HashMap<>(tag2weight);
    this.healtyTargetsList = Preconditions.checkNotNull(healtyTargetsList, "healtyTargetsList must not be null");
    healtyTargetsList.addListener(this);
  }

  @Override
  public String getTargetLogicalName() {
    return healtyTargetsList.getModule();
  }

  @Override
  public String provideTarget() {
    if (targets.isEmpty()) {
      throw new IllegalStateException("No targets are currently registered for module " + healtyTargetsList.getModule());
    }

    final int index = currIndex.get();
    currIndex.set(index + 1);
    final List<String> currTargets = targets;
    String target = currTargets.get(Math.abs(index % currTargets.size()));
    log.debug("target provided: {}", target);<commit_msg>final for Misha the king of finals<commit_after>package com.outbrain.ob1k.consul;

import com.google.common.base.Preconditions;
import com.outbrain.ob1k.client.targets.TargetProvider;
import io.netty.util.internal.ThreadLocalRandom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * A {@link TargetProvider} that provides targets registered in consul.
 *
 * @author <NAME>
 */
public class ConsulBasedTargetProvider implements TargetProvider, HealthyTargetsList.TargetsChangedListener {

  private static final Logger log = LoggerFactory.getLogger(ConsulBasedTargetProvider.class);

  private final ThreadLocal<Integer> currIndex = new ThreadLocal<Integer>() {
    @Override
    protected Integer initialValue() {
      return ThreadLocalRandom.current().nextInt();
    }
  };

  private final String urlSuffix;
  private final Map<String, Integer> tag2weight;
  private final HealthyTargetsList healtyTargetsList;
  private volatile List<String> targets;

  public ConsulBasedTargetProvider(final HealthyTargetsList healtyTargetsList, final String urlSuffix, final Map<String, Integer> tag2weight) {
    this.urlSuffix = urlSuffix == null ? "" : urlSuffix;
    this.tag2weight = tag2weight == null ? Collections.<String, Integer>emptyMap() : new HashMap<>(tag2weight);
    this.healtyTargetsList = Preconditions.checkNotNull(healtyTargetsList, "healtyTargetsList must not be null");
    healtyTargetsList.addListener(this);
  }

  @Override
  public String getTargetLogicalName() {
    return healtyTargetsList.getModule();
  }

  @Override
  public String provideTarget() {
    if (targets.isEmpty()) {
      throw new IllegalStateException("No targets are currently registered for module " + healtyTargetsList.getModule());
    }

    final int index = currIndex.get();
    currIndex.set(index + 1);
    final List<String> currTargets = targets;
    final String target = currTargets.get(Math.abs(index % currTargets.size()));
    log.debug("target provided: {}", target);
{'fraction_non_alphanumeric': 0.10086793338024864, 'fraction_numerical': 0.004691531785127844, 'mean_word_length': 5.022598870056497, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '833470', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1220, 'n_words': 296}