Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-4361] Introduce Flink's own future abstraction #2472

Closed
wants to merge 3 commits into from

Conversation

tillrohrmann
Copy link
Contributor

@tillrohrmann tillrohrmann commented Sep 5, 2016

Flink's future abstraction whose API is similar to Java 8's CompletableFuture.
That's in order to ease a future transition to this class once we ditch Java 7.
At the moment, the current future implementation is backed by Scala's futures.

The current set of operations comprises:

  • isDone to check the completion of the future
  • get/getNow to obtain the future's value
  • cancel to cancel the future (best effort basis)
  • thenApplyAsync to transform the future's value into another value
  • thenAcceptAsync to register a callback for a successful completion of the future
  • exceptionallyAsync to register a callback for an exception completion of the future
  • thenComposeAsync to transform the future's value and flatten the returned future
  • handleAsync to register a callback which is called either with the regular result
    or the exceptional result

Additionally, Flink offers a CompletableFuture which can be completed with a regular
value or an exception:

  • complete/completeExceptionally

Flink's future abstraction whose API is similar to Java 8's CompletableFuture.
That's in order to ease a future transition to this class once we ditch Java 7.
The current set of operations comprises:

- isDone to check the completion of the future
- get/getNow to obtain the future's value
- cancel to cancel the future (best effort basis)
- thenApplyAsync to transform the future's value into another value
- thenAcceptAsync to register a callback for a successful completion of the future
- exceptionallyAsync to register a callback for an exception completion of the future
- thenComposeAsync to transform the future's value and flatten the returned future
- handleAsync to register a callback which is called either with the regular result
or the exceptional result

Additionally, Flink offers a CompletableFuture which can be completed with a regular
value or an exception:

- complete/completeExceptionally
public FlinkCompletableFuture() {
promise = new scala.concurrent.impl.Promise.DefaultPromise<>();
scalaFuture = promise.future();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary new line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will remove it.

@tillrohrmann
Copy link
Contributor Author

Thanks for your review @KurtYoung. Will address your comments.

Copy link
Contributor

@mxm mxm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @tillrohrmann. You nicely abstracted away our Scala future/promise dependency. That lets us easily replace the Scala implementation with the Java 8 futures in the future (ha!).

*
* @return true if the future is completed; otherwise false
*/
boolean isDone();
Copy link
Contributor

@mxm mxm Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not named isCompleted()? That would be analogue to the complete() function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because I sticked to Java 8's CompletableFuture implementation where it is named the same.

I'm not super happy with the naming either. But I also see the benefit of sticking to Java 8's CompletableFuture interface. This will allow us to easily replace it once we switch to Java 8.

I think we have to decide whether we want to stick to Java 8's CompletableFuture or not. In the latter case we can rename other methods as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. After all, it's a minor naming issue.

<R> Future<R> exceptionallyAsync(ApplyFunction<Throwable, ? extends R> exceptionallyFunction, Executor executor);

/**
* Applies the given function to the value of the future. The apply function can return a future
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can return a future

should be

must return a future

or

returns a future

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The "can" should be removed. Will change it.

@StephanEwen
Copy link
Contributor

The naming is not super nice, I agree. But there is a clear benefit for Java 8 familiar people to stick with something established.

+1 for this from my side.

Next time we get involved in the Java community processes, to make sure they have better names ;-)

@tillrohrmann
Copy link
Contributor Author

Thanks for the review @KurtYoung, @mxm and @StephanEwen. I will merge this PR to the flip-6 branch.

asfgit pushed a commit that referenced this pull request Sep 21, 2016
Flink's future abstraction whose API is similar to Java 8's CompletableFuture.
That's in order to ease a future transition to this class once we ditch Java 7.
The current set of operations comprises:

- isDone to check the completion of the future
- get/getNow to obtain the future's value
- cancel to cancel the future (best effort basis)
- thenApplyAsync to transform the future's value into another value
- thenAcceptAsync to register a callback for a successful completion of the future
- exceptionallyAsync to register a callback for an exception completion of the future
- thenComposeAsync to transform the future's value and flatten the returned future
- handleAsync to register a callback which is called either with the regular result
or the exceptional result

Additionally, Flink offers a CompletableFuture which can be completed with a regular
value or an exception:

- complete/completeExceptionally

Complete FlinkCompletableFuture exceptionally with a CanellationException upon cancel

This closes #2472.
tillrohrmann added a commit to tillrohrmann/flink that referenced this pull request Sep 21, 2016
Flink's future abstraction whose API is similar to Java 8's CompletableFuture.
That's in order to ease a future transition to this class once we ditch Java 7.
The current set of operations comprises:

- isDone to check the completion of the future
- get/getNow to obtain the future's value
- cancel to cancel the future (best effort basis)
- thenApplyAsync to transform the future's value into another value
- thenAcceptAsync to register a callback for a successful completion of the future
- exceptionallyAsync to register a callback for an exception completion of the future
- thenComposeAsync to transform the future's value and flatten the returned future
- handleAsync to register a callback which is called either with the regular result
or the exceptional result

Additionally, Flink offers a CompletableFuture which can be completed with a regular
value or an exception:

- complete/completeExceptionally

Complete FlinkCompletableFuture exceptionally with a CanellationException upon cancel

This closes apache#2472.
tillrohrmann added a commit to tillrohrmann/flink that referenced this pull request Sep 27, 2016
Flink's future abstraction whose API is similar to Java 8's CompletableFuture.
That's in order to ease a future transition to this class once we ditch Java 7.
The current set of operations comprises:

- isDone to check the completion of the future
- get/getNow to obtain the future's value
- cancel to cancel the future (best effort basis)
- thenApplyAsync to transform the future's value into another value
- thenAcceptAsync to register a callback for a successful completion of the future
- exceptionallyAsync to register a callback for an exception completion of the future
- thenComposeAsync to transform the future's value and flatten the returned future
- handleAsync to register a callback which is called either with the regular result
or the exceptional result

Additionally, Flink offers a CompletableFuture which can be completed with a regular
value or an exception:

- complete/completeExceptionally

Complete FlinkCompletableFuture exceptionally with a CanellationException upon cancel

This closes apache#2472.
@tillrohrmann tillrohrmann deleted the futures branch November 1, 2016 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants