Source:
public LocalExchange( PartitioningProviderManager partitioningProviderManager, Session session, int sinkFactoryCount, int bufferCount, PartitioningHandle partitioning, List<Integer> partitionChannels, List<Type> partitioningChannelTypes, Optional<Integer> partitionHashChannel, DataSize maxBufferedBytes) { this.allSinkFactories = Stream.generate(() -> new LocalExchangeSinkFactory(LocalExchange.this)) .limit(sinkFactoryCount) .collect(toImmutableList()); openSinkFactories.addAll(allSinkFactories); noMoreSinkFactories(); ImmutableList.Builder<LocalExchangeSource> sources = ImmutableList.builder(); for (int i = 0; i < bufferCount; i++) { sources.add(new LocalExchangeSource(source -> checkAllSourcesFinished())); } this.sources = sources.build(); List<Consumer<PageReference>> buffers = this.sources.stream() .map(buffer -> (Consumer<PageReference>) buffer::addPage) .collect(toImmutableList()); this.memoryManager = new LocalExchangeMemoryManager(maxBufferedBytes.toBytes()); if (partitioning.equals(SINGLE_DISTRIBUTION)) { exchangerSupplier = () -> new BroadcastExchanger(buffers, memoryManager); } else if (partitioning.equals(FIXED_BROADCAST_DISTRIBUTION)) { exchangerSupplier = () -> new BroadcastExchanger(buffers, memoryManager); } else if (partitioning.equals(FIXED_ARBITRARY_DISTRIBUTION)) { exchangerSupplier = () -> new RandomExchanger(buffers, memoryManager); } else if (partitioning.equals(FIXED_PASSTHROUGH_DISTRIBUTION)) { Iterator<LocalExchangeSource> sourceIterator = this.sources.iterator(); exchangerSupplier = () -> { checkState(sourceIterator.hasNext(), "no more sources"); return new PassthroughExchanger(sourceIterator.next(), maxBufferedBytes.toBytes() / bufferCount, memoryManager::updateMemoryUsage); }; } else { exchangerSupplier = () -> new PartitioningExchanger( buffers, memoryManager, createPartitionFunction( partitioningProviderManager, session, partitioning, bufferCount, partitioningChannelTypes, partitionHashChannel.isPresent()), partitionChannels, partitionHashChannel); } }

Target:
public LocalExchange( PartitioningProviderManager partitioningProviderManager, Session session, int sinkFactoryCount, int bufferCount, PartitioningHandle partitioning, List<Integer> partitionChannels, List<Type> partitioningChannelTypes, Optional<Integer> partitionHashChannel, DataSize maxBufferedBytes) { this.allSinkFactories = Stream.generate(() -> new LocalExchangeSinkFactory(LocalExchange.this)) .limit(sinkFactoryCount) .collect(toImmutableList()); openSinkFactories.addAll(allSinkFactories); noMoreSinkFactories(); ImmutableList.Builder<LocalExchangeSource> sources = ImmutableList.builder(); for (int i = 0; i < bufferCount; i++) { sources.add(new LocalExchangeSource(source -> checkAllSourcesFinished())); } this.sources = sources.build(); List<Consumer<PageReference>> buffers = this.sources.stream() .map(buffer -> (Consumer<PageReference>) buffer::addPage) .collect(toImmutableList()); this.memoryManager = new LocalExchangeMemoryManager(maxBufferedBytes.toBytes()); if (partitioning.equals(SINGLE_DISTRIBUTION)) { exchangerSupplier = () -> new BroadcastExchanger(buffers, memoryManager); } else if (partitioning.equals(FIXED_BROADCAST_DISTRIBUTION)) { exchangerSupplier = () -> new BroadcastExchanger(buffers, memoryManager); } else if (partitioning.equals(FIXED_ARBITRARY_DISTRIBUTION)) { exchangerSupplier = () -> new RandomExchanger(buffers, memoryManager); } else if (partitioning.equals(FIXED_PASSTHROUGH_DISTRIBUTION)) { Iterator<LocalExchangeSource> sourceIterator = this.sources.iterator(); exchangerSupplier = () -> { checkState(sourceIterator.hasNext(), "no more sources"); return new PassthroughExchanger(sourceIterator.next(), maxBufferedBytes.toBytes() / bufferCount, memoryManager::updateMemoryUsage); }; } else if (partitioning.equals(FIXED_HASH_DISTRIBUTION) || partitioning.getConnectorId().isPresent()) { exchangerSupplier = () -> new PartitioningExchanger( buffers, memoryManager, createPartitionFunction( partitioningProviderManager, session, partitioning, bufferCount, partitioningChannelTypes, partitionHashChannel.isPresent()), partitionChannels, partitionHashChannel); } else { throw new IllegalArgumentException("Unsupported local exchange partitioning " + partitioning); } }