Class AbstractRichFunction
- java.lang.Object
-
- org.apache.flink.api.common.functions.AbstractRichFunction
-
- All Implemented Interfaces:
Serializable,org.apache.flink.api.common.functions.Function,RichFunction
- Direct Known Subclasses:
BulkIterationBase.TerminationCriterionMapper,NoOpFunction,RichAggregateFunction,RichCoGroupFunction,RichCrossFunction,RichFilterFunction,RichFlatJoinFunction,RichFlatMapFunction,RichGroupCombineFunction,RichGroupReduceFunction,RichJoinFunction,RichMapFunction,RichMapPartitionFunction,RichReduceFunction
@Public public abstract class AbstractRichFunction extends Object implements RichFunction, Serializable
An abstract stub implementation for rich user-defined functions. Rich functions have additional methods for initialization (RichFunction.open(OpenContext)) and teardown (close()), as well as access to their runtime execution context viagetRuntimeContext().- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractRichFunction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Tear-down method for the user code.IterationRuntimeContextgetIterationRuntimeContext()Gets a specialized version of theRuntimeContext, which has additional information about the iteration in which the function is executed.RuntimeContextgetRuntimeContext()Gets the context that contains information about the UDF's runtime, such as the parallelism of the function, the subtask index of the function, or the name of the task that executes the function.voidopen(Configuration parameters)Initialization method for the function.voidsetRuntimeContext(RuntimeContext t)Sets the function's runtime context.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.flink.api.common.functions.RichFunction
open
-
-
-
-
Method Detail
-
setRuntimeContext
public void setRuntimeContext(RuntimeContext t)
Description copied from interface:RichFunctionSets the function's runtime context. Called by the framework when creating a parallel instance of the function.- Specified by:
setRuntimeContextin interfaceRichFunction- Parameters:
t- The runtime context.
-
getRuntimeContext
public RuntimeContext getRuntimeContext()
Description copied from interface:RichFunctionGets the context that contains information about the UDF's runtime, such as the parallelism of the function, the subtask index of the function, or the name of the task that executes the function.The RuntimeContext also gives access to the
Accumulators and theDistributedCache.- Specified by:
getRuntimeContextin interfaceRichFunction- Returns:
- The UDF's runtime context.
-
getIterationRuntimeContext
public IterationRuntimeContext getIterationRuntimeContext()
Description copied from interface:RichFunctionGets a specialized version of theRuntimeContext, which has additional information about the iteration in which the function is executed. This IterationRuntimeContext is only available if the function is part of an iteration. Otherwise, this method throws an exception.- Specified by:
getIterationRuntimeContextin interfaceRichFunction- Returns:
- The IterationRuntimeContext.
-
open
public void open(Configuration parameters) throws Exception
Description copied from interface:RichFunctionInitialization method for the function. It is called before the actual working methods (like map or join) and thus suitable for one time setup work. For functions that are part of an iteration, this method will be invoked at the beginning of each iteration superstep.The configuration object passed to the function can be used for configuration and initialization. The configuration contains all parameters that were configured on the function in the program composition.
public class MyFilter extends RichFilterFunction<String> { private String searchString; public void open(Configuration parameters) { this.searchString = parameters.getString("foo"); } public boolean filter(String value) { return value.equals(searchString); } }By default, this method does nothing.
- Specified by:
openin interfaceRichFunction- Parameters:
parameters- The configuration containing the parameters attached to the contract.- Throws:
Exception- Implementations may forward exceptions, which are caught by the runtime. When the runtime catches an exception, it aborts the task and lets the fail-over logic decide whether to retry the task execution.- See Also:
Configuration, FLIP-344: Remove parameter in RichFunction#open
-
close
public void close() throws ExceptionDescription copied from interface:RichFunctionTear-down method for the user code. It is called after the last call to the main working methods (e.g. map or join). For functions that are part of an iteration, this method will be invoked after each iteration superstep.This method can be used for clean up work.
- Specified by:
closein interfaceRichFunction- Throws:
Exception- Implementations may forward exceptions, which are caught by the runtime. When the runtime catches an exception, it aborts the task and lets the fail-over logic decide whether to retry the task execution.
-
-