Interface KastRuntimeContext


  • public interface KastRuntimeContext
    • Method Detail

      • getJobId

        String getJobId()
        The ID of the current job. Note that Job ID can change in particular upon manual restart. The returned ID should NOT be used for any job management tasks.
      • getTaskName

        String getTaskName()
        Returns the name of the task in which the UDF runs, as assigned during plan construction.
        Returns:
        The name of the task in which the UDF runs.
      • getNumberOfParallelSubtasks

        int getNumberOfParallelSubtasks()
        Gets the parallelism with which the parallel task runs.
        Returns:
        The parallelism with which the parallel task runs.
      • getMaxNumberOfParallelSubtasks

        int getMaxNumberOfParallelSubtasks()
        Gets the number of max-parallelism with which the parallel task runs.
        Returns:
        The max-parallelism with which the parallel task runs.
      • getIndexOfThisSubtask

        int getIndexOfThisSubtask()
        Gets the number of this parallel subtask. The numbering starts from 0 and goes up to parallelism-1 (parallelism as returned by getNumberOfParallelSubtasks()).
        Returns:
        The index of the parallel subtask.
      • getAttemptNumber

        int getAttemptNumber()
        Gets the attempt number of this parallel subtask. First attempt is numbered 0.
        Returns:
        Attempt number of the subtask.
      • getUserCodeClassLoader

        ClassLoader getUserCodeClassLoader()
        Gets the ClassLoader to load classes that are not in system's classpath, but are part of the jar file of a user job.
        Returns:
        The ClassLoader for user code classes.
      • hasBroadcastVariable

        boolean hasBroadcastVariable​(String name)
        Tests for the existence of the broadcast variable identified by the given name.
        Parameters:
        name - The name under which the broadcast variable is registered;
        Returns:
        Whether a broadcast variable exists for the given name.
      • getMapState

        <UK,​UV> KastMapState<UK,​UV> getMapState​(String name,
                                                            Class<UK> keyClass,
                                                            Class<UV> valueClass)
        Gets a handle to the system's key/value map state.

        This state is only accessible if the function is executed on a KeyedStream.

        
         DataStream<MyType> stream = ...;
         KeyedStream<MyType> keyedStream = stream.keyBy("id");
        
         keyedStream.map(new RichMapFunction<MyType, List<MyType>>() {
        
             private MapState<MyType, Long> state;
        
             public void open(Configuration cfg) {
                 state = getRuntimeContext().getMapState(
                         new MapStateDescriptor<>("sum", MyType.class, Long.class));
             }
        
             public Tuple2<MyType, Long> map(MyType value) {
                 return new Tuple2<>(value, state.get(value));
             }
         });
        
         
        Type Parameters:
        UK - The type of the user keys stored in the state.
        UV - The type of the user values stored in the state.
        Returns:
        The partitioned state object.
        Throws:
        UnsupportedOperationException - Thrown, if no partitioned state is available for the function (function is not part of a KeyedStream).