56380
|
1 |
/*
|
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
package jdk.incubator.sql2;
|
|
26 |
|
|
27 |
import java.util.concurrent.CompletionStage;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* The result of submitting an {@link Operation}. The {@link cancel} method of a
|
|
31 |
* {@link CompletionStage} does not cancel the {@link Operation}. This is part
|
|
32 |
* of the contract of {@link CompletionStage}. This type provides a method to
|
|
33 |
* cancel the {@link Operation}. Canceling an {@link Operation} only makes sense
|
|
34 |
* after the {@link Operation} is submitted so this type is the result of
|
|
35 |
* submitting an {@link Operation}.
|
|
36 |
*
|
|
37 |
* ISSUE: Should Operation.submit return a CompletionStage with the requirement
|
|
38 |
* that cancel attempts to cancel the database action? Conceptually this is fine.
|
|
39 |
* The concern is that it requires the implementor to implement their own
|
|
40 |
* CompletionStage or at the least subclass CompletableFuture to override
|
|
41 |
* cancel. Neither of these is trivial.
|
|
42 |
*
|
|
43 |
* @param <T> The type of the result of the {@link Operation} that created this
|
|
44 |
* {@link Submission}
|
|
45 |
*/
|
|
46 |
public interface Submission<T> {
|
|
47 |
|
|
48 |
/**
|
|
49 |
* Request that the {@link Operation} not be executed or that its execution be
|
|
50 |
* aborted if already begun. This is a best effort action and may not succeed
|
|
51 |
* in preventing or aborting the execution. This method does not block.
|
|
52 |
*
|
|
53 |
* If execution is prevented the Operation is completed exceptionally with
|
|
54 |
* SkippedSqlException. If the Operation is aborted it is completed
|
|
55 |
* exceptionally with SqlException.
|
|
56 |
*
|
|
57 |
* @return a {@link java.util.concurrent.CompletionStage} that has the value
|
|
58 |
* true if the {@link Operation} is canceled.
|
|
59 |
*/
|
|
60 |
public CompletionStage<Boolean> cancel();
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Returns a {@link CompletionStage} which value is the result of the
|
|
64 |
* {@link Operation}. Any actions on the returned {@link CompletionStage},
|
|
65 |
* eg {@code completeExceptionally} or {@code cancel}, have no impact on this
|
|
66 |
* {@link Operation}. If this {@link Operation} is already completed the
|
|
67 |
* returned {@link CompletionStage} will be completed.
|
|
68 |
*
|
|
69 |
* The returned {@link CompletionStage} is completed after the Operation
|
|
70 |
* is completed. It may be completed by the same thread that completed the
|
|
71 |
* Operation or a different one. The Operation following the one that created
|
|
72 |
* this Submission begins execution when the Operation that created this
|
|
73 |
* Submission is completed. It is not required to wait for the returned
|
|
74 |
* CompletionStage to complete. [Note: this is necessary because the app can
|
|
75 |
* call this method after the Operation completes.]
|
|
76 |
*
|
|
77 |
* Each call of this method for a given {@link Operation} returns the same
|
|
78 |
* {@link CompletionStage}.
|
|
79 |
*
|
|
80 |
* @return the {@link java.util.concurrent.CompletionStage} for the result of this
|
|
81 |
* {@link Operation}. Retained.
|
|
82 |
*/
|
|
83 |
public CompletionStage<T> getCompletionStage();
|
|
84 |
|
|
85 |
}
|