Eliminate Submission

David Lloyd david.lloyd at redhat.com
Mon Feb 4 21:12:41 UTC 2019

Why not return CompletionStage<Void> from cancel?  In other words...
what would it mean if it returns FALSE but there was no exceptional

On Mon, Feb 4, 2019 at 2:57 PM Douglas Surber <douglas.surber at oracle.com> wrote:
> I've never been happy with Submission but it seemed necessary. After thinking about it off and on for a couple of years it occurred to me that CompletionStage does not declare cancel. So I propose that ADBA define a new interface that is an extension to CompletionStage and that declares cancel.
> Implementing this shouldn't be hard. Extend CompletableFuture and add cancel() which would just do whatever is necessary to cancel the Operation. I don't think any interaction with the CompletableFuture itself would be necessary.
> Every use of Submission is the same or simpler with CancelableCompletionStage.
> op.submit();                                                    no change
> CompletionStage cs = op.submit().getCompletionStage();          remove call to getCompletionStage();
> CompleteableFuture cf = op.submit()
>                                 .getCompletionStage()
>                                 .toCompleteableFuture();        remove call to getCompletionStage();
> Submission s = op.submit();                                     replace Submission with CancelableCompletionStage
> If you can see any problems with this let me know.
> Douglas
> package jdk.incubator.sql2;
> /**
>  * The result of submitting an {@link Operation}. This extension to
>  * java.util.concurrent.CompletionStage adds a method {@code cancel}. Calling
>  * this method attempts to prevent or abort execution of the Operation that
>  * created this CancelableCompletionStage. This is in contrast to the {@code cancel(boolean)}
>  * method declared by java.util.concurrent.CompletableFuture which does not
>  * attempt to cancel the task that produces its result. As the signatures are
>  * different the two methods do not interfere with one another.
>  *
>  * @param <T> The type of the result of the {@link Operation} that created this
>  * {@code CancelableCompletionStage}
>  */
> public interface CancelableCompletionStage<T> extends java.util.concurrent.CompletionStage {
>   /**
>    * Request that the {@link Operation} not be executed or that its execution be
>    * aborted if already begun. This is a best effort action and may not succeed
>    * in preventing or aborting the execution. This method does not block.
>    *
>    * If execution is prevented the Operation is completed exceptionally with
>    * SkippedSqlException. If the Operation is aborted it is completed
>    * exceptionally with SqlException.
>    *
>    * @return a {@link java.util.concurrent.CompletionStage} that has the value
>    * true if the {@link Operation} is canceled.
>    */
>   public CompletionStage<Boolean> cancel();
> }


More information about the jdbc-spec-discuss mailing list