Java Code Examples for org.apache.flink.api.common.functions.util.FunctionUtils#closeFunction()

The following examples show how to use org.apache.flink.api.common.functions.util.FunctionUtils#closeFunction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapOperatorBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	MapFunction<IN, OUT> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);
	
	ArrayList<OUT> result = new ArrayList<OUT>(inputData.size());

	TypeSerializer<IN> inSerializer = getOperatorInfo().getInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	for (IN element : inputData) {
		IN inCopy = inSerializer.copy(element);
		OUT out = function.map(inCopy);
		result.add(outSerializer.copy(out));
	}

	FunctionUtils.closeFunction(function);
	
	return result;
}
 
Example 2
Source File: MapPartitionOperatorBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	MapPartitionFunction<IN, OUT> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);
	
	ArrayList<OUT> result = new ArrayList<OUT>(inputData.size() / 4);

	TypeSerializer<IN> inSerializer = getOperatorInfo().getInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	CopyingIterator<IN> source = new CopyingIterator<IN>(inputData.iterator(), inSerializer);
	CopyingListCollector<OUT> resultCollector = new CopyingListCollector<OUT>(result, outSerializer);

	function.mapPartition(source, resultCollector);

	result.trimToSize();
	FunctionUtils.closeFunction(function);
	return result;
}
 
Example 3
Source File: CrossOperatorBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN1> inputData1, List<IN2> inputData2, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	CrossFunction<IN1, IN2, OUT> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);

	ArrayList<OUT> result = new ArrayList<OUT>(inputData1.size() * inputData2.size());
	
	TypeSerializer<IN1> inSerializer1 = getOperatorInfo().getFirstInputType().createSerializer(executionConfig);
	TypeSerializer<IN2> inSerializer2 = getOperatorInfo().getSecondInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	for (IN1 element1 : inputData1) {
		for (IN2 element2 : inputData2) {
			IN1 copy1 = inSerializer1.copy(element1);
			IN2 copy2 = inSerializer2.copy(element2);
			OUT o = function.cross(copy1, copy2);
			result.add(outSerializer.copy(o));
		}
	}

	FunctionUtils.closeFunction(function);
	return result;
}
 
Example 4
Source File: ChainedFlatMapDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelTask() {
	try {
		FunctionUtils.closeFunction(this.mapper);
	}
	catch (Throwable t) {
	}
}
 
Example 5
Source File: OuterJoinOperatorBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN1> leftInput, List<IN2> rightInput, RuntimeContext runtimeContext, ExecutionConfig executionConfig) throws Exception {
	TypeInformation<IN1> leftInformation = getOperatorInfo().getFirstInputType();
	TypeInformation<IN2> rightInformation = getOperatorInfo().getSecondInputType();
	TypeInformation<OUT> outInformation = getOperatorInfo().getOutputType();

	TypeComparator<IN1> leftComparator = buildComparatorFor(0, executionConfig, leftInformation);
	TypeComparator<IN2> rightComparator = buildComparatorFor(1, executionConfig, rightInformation);

	TypeSerializer<IN1> leftSerializer = leftInformation.createSerializer(executionConfig);
	TypeSerializer<IN2> rightSerializer = rightInformation.createSerializer(executionConfig);

	OuterJoinListIterator<IN1, IN2> outerJoinIterator =
			new OuterJoinListIterator<>(leftInput, leftSerializer, leftComparator,
					rightInput, rightSerializer, rightComparator, outerJoinType);

	// --------------------------------------------------------------------
	// Run UDF
	// --------------------------------------------------------------------
	FlatJoinFunction<IN1, IN2, OUT> function = userFunction.getUserCodeObject();

	FunctionUtils.setFunctionRuntimeContext(function, runtimeContext);
	FunctionUtils.openFunction(function, this.parameters);

	List<OUT> result = new ArrayList<>();
	Collector<OUT> collector = new CopyingListCollector<>(result, outInformation.createSerializer(executionConfig));

	while (outerJoinIterator.next()) {
		IN1 left = outerJoinIterator.getLeft();
		IN2 right = outerJoinIterator.getRight();
		function.join(left == null ? null : leftSerializer.copy(left), right == null ? null : rightSerializer.copy(right), collector);
	}

	FunctionUtils.closeFunction(function);

	return result;
}
 
Example 6
Source File: ChainedAllReduceDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelTask() {
	try {
		FunctionUtils.closeFunction(this.reducer);
	} catch (Throwable t) {
	}
}
 
Example 7
Source File: ChainedAllReduceDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelTask() {
	try {
		FunctionUtils.closeFunction(this.reducer);
	} catch (Throwable t) {
	}
}
 
Example 8
Source File: NFA.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Tear-down method for the NFA.
 */
public void close() throws Exception {
	for (State<T> state : getStates()) {
		for (StateTransition<T> transition : state.getStateTransitions()) {
			IterativeCondition condition = transition.getCondition();
			FunctionUtils.closeFunction(condition);
		}
	}
}
 
Example 9
Source File: ChainedMapDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelTask() {
	try {
		FunctionUtils.closeFunction(this.mapper);
	} catch (Throwable t) {
	}
}
 
Example 10
Source File: LookupJoinRunner.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws Exception {
	super.close();
	if (fetcher != null) {
		FunctionUtils.closeFunction(fetcher);
	}
	if (collector != null) {
		FunctionUtils.closeFunction(collector);
	}
}
 
Example 11
Source File: ChainedFlatMapDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelTask() {
	try {
		FunctionUtils.closeFunction(this.mapper);
	}
	catch (Throwable t) {
	}
}
 
Example 12
Source File: PatternTimeoutFlatSelectAdapter.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	super.close();
	FunctionUtils.closeFunction(flatTimeoutFunction);
}
 
Example 13
Source File: ReduceApplyProcessWindowFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	FunctionUtils.closeFunction(this.windowFunction);
}
 
Example 14
Source File: PatternTimeoutFlatSelectAdapter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	super.close();
	FunctionUtils.closeFunction(flatTimeoutFunction);
}
 
Example 15
Source File: FoldApplyProcessAllWindowFunction.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	FunctionUtils.closeFunction(this.windowFunction);
}
 
Example 16
Source File: TemporalProcessTimeJoinOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	FunctionUtils.closeFunction(joinCondition);
}
 
Example 17
Source File: PatternFlatSelectAdapter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	FunctionUtils.closeFunction(flatSelectFunction);
}
 
Example 18
Source File: LookupJoinWithCalcRunner.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	super.close();
	FunctionUtils.closeFunction(calc);
}
 
Example 19
Source File: PatternSelectAdapter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	FunctionUtils.closeFunction(selectFunction);
}
 
Example 20
Source File: BatchTask.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Closes the given stub using its {@link org.apache.flink.api.common.functions.RichFunction#close()} method. If the close call produces
 * an exception, a new exception with a standard error message is created, using the encountered exception
 * as its cause.
 * 
 * @param stub The user code instance to be closed.
 * 
 * @throws Exception Thrown, if the user code's close method produces an exception.
 */
public static void closeUserCode(Function stub) throws Exception {
	try {
		FunctionUtils.closeFunction(stub);
	} catch (Throwable t) {
		throw new Exception("The user defined 'close()' method caused an exception: " + t.getMessage(), t);
	}
}