Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.dstream.local.ri;
import java.lang.reflect.Field;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import io.dstream.DStreamConstants;
import io.dstream.DStreamExecutionGraph;
import io.dstream.DStreamOperation;
import io.dstream.SerializableStreamAssets.SerFunction;
import io.dstream.local.ri.ShuffleHelper.RefHolder;
import io.dstream.support.AbstractPartitionedStreamProducingSourceSupplier;
import io.dstream.support.Aggregators;
import io.dstream.support.Classifier;
import io.dstream.support.HashClassifier;
import io.dstream.support.PartitionIdHelper;
import io.dstream.support.SourceSupplier;
import io.dstream.support.UriSourceSupplier;
import io.dstream.utils.KVUtils;
import io.dstream.utils.ReflectionUtils;
import io.dstream.utils.SingleValueIterator;
/**
*
*
*/
final class LocalDStreamExecutionEngine {
private final Properties executionConfig;
private final String executionName;
private final Classifier classifier;
private List> realizedStageResults;
private final ThreadLocal partitionIdHolder;
@SuppressWarnings("unchecked")
public LocalDStreamExecutionEngine(String executionName, Properties executionConfig){
this.executionName = executionName;
this.executionConfig = executionConfig;
this.classifier = this.determineClassifier();
try {
Field tl = ReflectionUtils.findField(PartitionIdHelper.class, "partitionIdHolder", ThreadLocal.class);
tl.setAccessible(true);
this.partitionIdHolder = (ThreadLocal) tl.get(null);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
/**
*
*/
public Stream> execute(DStreamExecutionGraph pipeline) {
return this.execute(pipeline, false);
}
/**
*
*/
private Stream> execute(DStreamExecutionGraph pipeline, boolean partition) {
List streamOperations = pipeline.getOperations();
for (int i = 0; i < streamOperations.size(); i++) {
this.doExecuteStage(streamOperations.get(i), partition, pipeline.getName());
}
return this.realizedStageResults.stream().map(list -> list.stream());
}
/**
*
* @param streamOperation
* @param mapPartitions
*/
@SuppressWarnings("unchecked")
private void doExecuteStage(DStreamOperation streamOperation, boolean partition, String pipelineName){
SerFunction, Stream>> streamFunction = streamOperation.getStreamOperationFunction();
if (this.realizedStageResults == null){
List> realizedIntermediateResult = Stream.of( streamFunction.apply(this.createInitialStream(pipelineName)) )
.map(stream -> stream.collect(Collectors.toList()))
.collect(Collectors.toList());
if (partition){
Stream> mergedStream = realizedIntermediateResult.stream().map(list -> ((Stream