Hi,
in the process of reworking the Streaming Operator model I'm also
reworking the sources in order to get rid of the loop in each source.
Right now, the interface for sources (SourceFunction) has one method:
run(). This is called when the source starts and can just output
elements at any time using the Collector interface. This does not give
the Task that runs the source a lot of control in suspending operation
for performing checkpoints or some such thing.

I thought about changing the interface to this:

interface SourceFunction<T>  {
  boolean reachedEnd();
  T next();
}

This is similar to the batch API and also to what Stephan proposes in
his pull request. I think this will not work for streaming because
sources might not have new elements to emit at the moment but might
have something to emit in the future. This is problematic because
streaming topologies are usually running indefinitely. In that case,
the reachedEnd() and next() would have to be blocking (until a new
element arrives). This again does not give the task the power to
suspend operation at will.

I propose a three function interface:

interface SourceFunction<T> {
  boolean reachedEnd():
  boolean hasNext():
  T next();
}

where the contract for the source is as follows:
 - reachedEnd() == true => stop the source
 - hasNext() == true => call next() to retrieve next element
 - hasNext() == false => call again at some later point
 - next() => retrieve next element, throw exception if no element available

I thought about allowing next() to return NULL to signal that no
element is available at the moment. This will not work because a
source might want to return NULL as an element.

What do you think? Any other ideas about solving this?

Cheers,
Aljoscha

Reply via email to