Exemplo n.º 1
0
  @Override
  public final void registerInputOutput() throws Exception {
    LOG.debug("registerInputOutput for {}", getName());

    boolean initializationCompleted = false;
    try {
      AccumulatorRegistry accumulatorRegistry = getEnvironment().getAccumulatorRegistry();

      userClassLoader = getUserCodeClassLoader();
      configuration = new StreamConfig(getTaskConfiguration());
      accumulatorMap = accumulatorRegistry.getUserMap();

      stateBackend = createStateBackend();
      stateBackend.initializeForJob(getEnvironment().getJobID());

      headOperator = configuration.getStreamOperator(userClassLoader);
      operatorChain =
          new OperatorChain<>(this, headOperator, accumulatorRegistry.getReadWriteReporter());

      if (headOperator != null) {
        headOperator.setup(this, configuration, operatorChain.getChainEntryPoint());
      }

      timerService =
          Executors.newSingleThreadScheduledExecutor(
              new DispatcherThreadFactory(TRIGGER_THREAD_GROUP, "Time Trigger for " + getName()));

      // task specific initialization
      init();

      initializationCompleted = true;
    } finally {
      if (!initializationCompleted) {
        if (timerService != null) {
          timerService.shutdownNow();
        }
        if (operatorChain != null) {
          operatorChain.releaseOutputs();
        }
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Initializes the input readers of the DataSinkTask.
   *
   * @throws RuntimeException Thrown in case of invalid task input configuration.
   */
  @SuppressWarnings("unchecked")
  private void initInputReaders() throws Exception {
    int numGates = 0;
    //  ---------------- create the input readers ---------------------
    // in case where a logical input unions multiple physical inputs, create a union reader
    final int groupSize = this.config.getGroupSize(0);
    numGates += groupSize;
    if (groupSize == 1) {
      // non-union case
      inputReader =
          new MutableRecordReader<DeserializationDelegate<IT>>(getEnvironment().getInputGate(0));
    } else if (groupSize > 1) {
      // union case
      inputReader =
          new MutableRecordReader<IOReadableWritable>(
              new UnionInputGate(getEnvironment().getAllInputGates()));
    } else {
      throw new Exception("Illegal input group size in task configuration: " + groupSize);
    }

    final AccumulatorRegistry accumulatorRegistry = getEnvironment().getAccumulatorRegistry();
    final AccumulatorRegistry.Reporter reporter = accumulatorRegistry.getReadWriteReporter();

    inputReader.setReporter(reporter);

    this.inputTypeSerializerFactory = this.config.getInputSerializer(0, getUserCodeClassLoader());
    @SuppressWarnings({"rawtypes"})
    final MutableObjectIterator<?> iter =
        new ReaderIterator(inputReader, this.inputTypeSerializerFactory.getSerializer());
    this.reader = (MutableObjectIterator<IT>) iter;

    // final sanity check
    if (numGates != this.config.getNumInputs()) {
      throw new Exception(
          "Illegal configuration: Number of input gates and group sizes are not consistent.");
    }
  }
Exemplo n.º 3
0
  @Override
  public void init() throws Exception {
    StreamConfig configuration = getConfiguration();

    TypeSerializer<IN> inSerializer = configuration.getTypeSerializerIn1(getUserCodeClassLoader());
    int numberOfInputs = configuration.getNumberOfInputs();

    if (numberOfInputs > 0) {
      InputGate[] inputGates = getEnvironment().getAllInputGates();
      inputProcessor =
          new StreamInputProcessor<IN>(
              inputGates,
              inSerializer,
              getCheckpointBarrierListener(),
              configuration.getCheckpointMode(),
              getEnvironment().getIOManager(),
              getExecutionConfig().areTimestampsEnabled());

      // make sure that stream tasks report their I/O statistics
      AccumulatorRegistry registry = getEnvironment().getAccumulatorRegistry();
      AccumulatorRegistry.Reporter reporter = registry.getReadWriteReporter();
      inputProcessor.setReporter(reporter);
    }
  }