Repository: incubator-rocketmq Updated Branches: refs/heads/spec 574a6fc06 -> 08ab1ae26
[ROCKETMQ-17] Develop a vendor-neutral open standard for distributed messaging: Add the asynchronous send message mechanism ASF JIRA: https://issues.apache.org/jira/browse/ROCKETMQ-17 Project: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/commit/86f4e261 Tree: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/tree/86f4e261 Diff: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/diff/86f4e261 Branch: refs/heads/spec Commit: 86f4e26171935ed92c0341c56fa60e4033aa40af Parents: 574a6fc Author: vintagewang <[email protected]> Authored: Sun Jan 1 19:50:15 2017 +0800 Committer: vintagewang <[email protected]> Committed: Sun Jan 1 19:50:15 2017 +0800 ---------------------------------------------------------------------- .../java/org/apache/openmessaging/Producer.java | 4 + .../java/org/apache/openmessaging/Promise.java | 93 ++++++++++++++++++++ .../apache/openmessaging/PromiseListener.java | 23 +++++ 3 files changed, 120 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/86f4e261/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/Producer.java ---------------------------------------------------------------------- diff --git a/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/Producer.java b/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/Producer.java index 48a154a..53c2194 100644 --- a/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/Producer.java +++ b/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/Producer.java @@ -22,4 +22,8 @@ public interface Producer extends MessageFactory { void shutdown(); void send(final BytesMessage message); + + Promise<Void> sendAsync(final BytesMessage message); + + void sendOneway(final BytesMessage message); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/86f4e261/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/Promise.java ---------------------------------------------------------------------- diff --git a/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/Promise.java b/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/Promise.java new file mode 100644 index 0000000..4bab70e --- /dev/null +++ b/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/Promise.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openmessaging; + +public interface Promise<V> { + + /** + * 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. + * <p> + * <p>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. + * + * @return {@code true} if this task was cancelled before it completed + */ + boolean isCancelled(); + + /** + * Returns {@code true} if this task completed. + * <p> + * Completion may be due to normal termination, an exception, or + * cancellation -- in all of these cases, this method will return + * {@code true}. + * + * @return {@code true} if this task completed + */ + boolean isDone(); + + /** + * Waits if necessary for the computation to complete, and then + * retrieves its result. + * + * @return the computed result + */ + V get(); + + /** + * Waits if necessary for at most the given time for the computation + * to complete, and then retrieves its result, if available. + * + * @param timeout the maximum time to wait + * @return the computed result <p> if the computation was cancelled + */ + V get(long timeout); + + /** + * @param value Value + * @return Whether set is success + */ + boolean set(V value); + + /** + * @param listener PromiseListener + */ + void addListener(PromiseListener listener); + + /** + * @return + */ + Exception getException(); +} http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/86f4e261/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/PromiseListener.java ---------------------------------------------------------------------- diff --git a/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/PromiseListener.java b/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/PromiseListener.java new file mode 100644 index 0000000..0498f1e --- /dev/null +++ b/spec/code/messaging-user-level-api/java/src/main/java/org/apache/openmessaging/PromiseListener.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openmessaging; + +public interface PromiseListener<V> { + void operationComplete(Promise<V> promise); + + void operationFailed(Promise<V> promise); +}
