From ddfe3f54e46b3a00947b7e54876c7aba0eeb9025 Mon Sep 17 00:00:00 2001 From: gaohaoxiang Date: Tue, 26 Feb 2019 14:43:54 +0800 Subject: [PATCH] add cancel method for Future --- .../main/java/io/openmessaging/Future.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/openmessaging-api/src/main/java/io/openmessaging/Future.java b/openmessaging-api/src/main/java/io/openmessaging/Future.java index b22ad541..e0973549 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Future.java +++ b/openmessaging-api/src/main/java/io/openmessaging/Future.java @@ -32,6 +32,29 @@ * @since OMS 1.0.0 */ public interface Future { + /** + * Attempts to cancel execution of this task. This attempt will + * fail if the task has already completed, has already been cancelled, + * or could not be cancelled for some other reason. If successful, + * and this task has not started when {@code cancel} is called, + * this task should never run. If the task has already started, + * then the {@code mayInterruptIfRunning} parameter determines + * whether the thread executing this task should be interrupted in + * an attempt to stop the task. + * + *

After this method returns, subsequent calls to {@link #isDone} will + * always return {@code true}. Subsequent calls to {@link #isCancelled} + * will always return {@code true} if this method returned {@code true}. + * + * @param mayInterruptIfRunning {@code true} if the thread executing this + * task should be interrupted; otherwise, in-progress tasks are allowed + * to complete + * @return {@code false} if the task could not be cancelled, + * typically because it has already completed normally; + * {@code true} otherwise + */ + boolean cancel(boolean mayInterruptIfRunning); + /** * Returns {@code true} if this task was cancelled before it completed normally. *