presto-main/src/main/java/io/prestosql/execution/scheduler/TopologyAwareNodeSelectorFactory.java/TopologyAwareNodeSelectorFactory/TopologyAwareNodeSelectorFactory
class TopologyAwareNodeSelectorFactory:    @Inject
    public TopologyAwareNodeSelectorFactory(
            NetworkTopology networkTopology,
            InternalNodeManager nodeManager,
            NodeSchedulerConfig schedulerConfig,
            NodeTaskMap nodeTaskMap,
            TopologyAwareNodeSelectorConfig topologyConfig)
    {
        requireNonNull(networkTopology, "networkTopology is null");
        requireNonNull(nodeManager, "nodeManager is null");
        requireNonNull(schedulerConfig, "schedulerConfig is null");
        requireNonNull(nodeTaskMap, "nodeTaskMap is null");
        requireNonNull(topologyConfig, "topologyConfig is null");

        this.networkTopology = networkTopology;
        this.nodeManager = nodeManager;
        this.minCandidates = schedulerConfig.getMinCandidates();
        this.includeCoordinator = schedulerConfig.isIncludeCoordinator();
        this.maxSplitsPerNode = schedulerConfig.getMaxSplitsPerNode();
        this.maxPendingSplitsPerTask = schedulerConfig.getMaxPendingSplitsPerTask();
        this.nodeTaskMap = requireNonNull(nodeTaskMap, "nodeTaskMap is null");
        checkArgument(maxSplitsPerNode >= maxPendingSplitsPerTask, "maxSplitsPerNode must be > maxPendingSplitsPerTask");

        Builder<CounterStat> placementCounters = ImmutableList.builder();
        ImmutableMap.Builder<String, CounterStat> placementCountersByName = ImmutableMap.builder();

        // always add a counter for "all" locations, which is the default global segment
        CounterStat allCounter = new CounterStat();
        placementCounters.add(allCounter);
        placementCountersByName.put("all", allCounter);

        for (String segmentName : ImmutableList.copyOf(topologyConfig.getLocationSegmentNames())) {
            CounterStat segmentCounter = new CounterStat();
            placementCounters.add(segmentCounter);
            placementCountersByName.put(segmentName, segmentCounter);
        }

        this.placementCounters = placementCounters.build();
        this.placementCountersByName = placementCountersByName.build();
    }