1 /*
2 * Copyright 2013 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package io.netty.util.concurrent;
17
18 /**
19 * Special {@link Future} which is writable.
20 */
21 public interface Promise<V> extends Future<V> {
22
23 /**
24 * Marks this future as a success and notifies all
25 * listeners.
26 *
27 * If it is success or failed already it will throw an {@link IllegalStateException}.
28 */
29 Promise<V> setSuccess(V result);
30
31 /**
32 * Marks this future as a success and notifies all
33 * listeners.
34 *
35 * @return {@code true} if and only if successfully marked this future as
36 * a success. Otherwise {@code false} because this future is
37 * already marked as either a success or a failure.
38 */
39 boolean trySuccess(V result);
40
41 /**
42 * Marks this future as a failure and notifies all
43 * listeners.
44 *
45 * If it is success or failed already it will throw an {@link IllegalStateException}.
46 */
47 Promise<V> setFailure(Throwable cause);
48
49 /**
50 * Marks this future as a failure and notifies all
51 * listeners.
52 *
53 * @return {@code true} if and only if successfully marked this future as
54 * a failure. Otherwise {@code false} because this future is
55 * already marked as either a success or a failure.
56 */
57 boolean tryFailure(Throwable cause);
58
59 /**
60 * Make this future impossible to cancel.
61 *
62 * @return {@code true} if and only if successfully marked this future as uncancellable or it is already done
63 * without being cancelled. {@code false} if this future has been cancelled already.
64 */
65 boolean setUncancellable();
66
67 @Override
68 Promise<V> addListener(GenericFutureListener<? extends Future<? super V>> listener);
69
70 @Override
71 Promise<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
72
73 @Override
74 Promise<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener);
75
76 @Override
77 Promise<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
78
79 @Override
80 Promise<V> await() throws InterruptedException;
81
82 @Override
83 Promise<V> awaitUninterruptibly();
84
85 @Override
86 Promise<V> sync() throws InterruptedException;
87
88 @Override
89 Promise<V> syncUninterruptibly();
90 }