From ddfe3f54e46b3a00947b7e54876c7aba0eeb9025 Mon Sep 17 00:00:00 2001 From: gaohaoxiang Date: Tue, 26 Feb 2019 14:43:54 +0800 Subject: [PATCH 1/4] 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. * From 9a4c99d8f0932822642d559e02d19c833140f681 Mon Sep 17 00:00:00 2001 From: gaohaoxiang Date: Tue, 26 Feb 2019 14:44:51 +0800 Subject: [PATCH 2/4] add ACCOUNT_KEY for Future --- .../src/main/java/io/openmessaging/OMSBuiltinKeys.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java b/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java index 5702724b..7d47d9a6 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java +++ b/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java @@ -41,6 +41,11 @@ public interface OMSBuiltinKeys { */ String ACCOUNT_ID = "ACCOUNT_ID"; + /** + * The {@code ACCOUNT_KEY} key shows the specified account key in OMS attribute. + */ + String ACCOUNT_KEY = "ACCOUNT_KEY"; + /** * The {@code REGION} key shows the specified region in OMS driver schema. */ From e4f1e52e43ced3eb315a1e47fb233d58f9dbf5e4 Mon Sep 17 00:00:00 2001 From: gaohaoxiang Date: Tue, 26 Feb 2019 14:55:01 +0800 Subject: [PATCH 3/4] fix KeyValue bug --- .../src/main/java/io/openmessaging/KeyValue.java | 4 ++-- .../io/openmessaging/internal/DefaultKeyValue.java | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java index d521bb6e..f9ea4a28 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java +++ b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java @@ -82,7 +82,7 @@ public interface KeyValue { * @return the value in this {@code KeyValue} object with the specified key value * @see #put(String, short) */ - int getShort(String key); + short getShort(String key); /** * Searches for the {@code short} property with the specified key in this {@code KeyValue} object. If the key is not @@ -93,7 +93,7 @@ public interface KeyValue { * @return the value in this {@code KeyValue} object with the specified key value * @see #put(String, short) */ - int getShort(String key, short defaultValue); + short getShort(String key, short defaultValue); /** * Searches for the {@code int} property with the specified key in this {@code KeyValue} object. If the key is not diff --git a/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java b/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java index e2f6477b..be121b9b 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java +++ b/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java @@ -32,13 +32,16 @@ public class DefaultKeyValue implements KeyValue { private Map properties; @Override - public int getShort(String key) { - return 0; + public short getShort(String key) { + if (!properties.containsKey(key)) { + return 0; + } + return Short.valueOf(properties.get(key)); } @Override - public int getShort(String key, short defaultValue) { - return 0; + public short getShort(String key, short defaultValue) { + return properties.containsKey(key) ? getShort(key) : defaultValue; } @Override From 60c025931832b7e88d9c1c2b0d7ecc601abcf6fd Mon Sep 17 00:00:00 2001 From: gaohaoxiang Date: Tue, 26 Feb 2019 14:44:51 +0800 Subject: [PATCH 4/4] Add ACCOUNT_KEY to OMSBuiltinKeys --- .../src/main/java/io/openmessaging/OMSBuiltinKeys.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java b/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java index 5702724b..7d47d9a6 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java +++ b/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java @@ -41,6 +41,11 @@ public interface OMSBuiltinKeys { */ String ACCOUNT_ID = "ACCOUNT_ID"; + /** + * The {@code ACCOUNT_KEY} key shows the specified account key in OMS attribute. + */ + String ACCOUNT_KEY = "ACCOUNT_KEY"; + /** * The {@code REGION} key shows the specified region in OMS driver schema. */