All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ray.streaming.api.function.internal.CollectionSourceFunction Maven / Gradle / Ivy

package io.ray.streaming.api.function.internal;

import io.ray.streaming.api.function.impl.SourceFunction;
import java.util.Collection;

/**
 * The SourceFunction that fetch data from a Java Collection object.
 *
 * @param  Type of the data output by the source.
 */
public class CollectionSourceFunction implements SourceFunction {

  private Collection values;
  private boolean finished = false;

  public CollectionSourceFunction(Collection values) {
    this.values = values;
  }

  @Override
  public void init(int totalParallel, int currentIndex) {}

  @Override
  public void fetch(SourceContext ctx) throws Exception {
    if (finished) {
      return;
    }
    for (T value : values) {
      ctx.collect(value);
    }
    finished = true;
  }

  @Override
  public void close() {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy