1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.util.internal;
17
18 import io.netty.util.concurrent.Promise;
19 import io.netty.util.internal.logging.InternalLogger;
20
21
22
23
24 public final class PromiseNotificationUtil {
25
26 private PromiseNotificationUtil() { }
27
28
29
30
31 public static void tryCancel(Promise<?> p, InternalLogger logger) {
32 if (!p.cancel(false) && logger != null) {
33 Throwable err = p.cause();
34 if (err == null) {
35 logger.warn("Failed to cancel promise because it has succeeded already: {}", p);
36 } else {
37 logger.warn(
38 "Failed to cancel promise because it has failed already: {}, unnotified cause:",
39 p, err);
40 }
41 }
42 }
43
44
45
46
47 public static <V> void trySuccess(Promise<? super V> p, V result, InternalLogger logger) {
48 if (!p.trySuccess(result) && logger != null) {
49 Throwable err = p.cause();
50 if (err == null) {
51 logger.warn("Failed to mark a promise as success because it has succeeded already: {}", p);
52 } else {
53 logger.warn(
54 "Failed to mark a promise as success because it has failed already: {}, unnotified cause:",
55 p, err);
56 }
57 }
58 }
59
60
61
62
63 public static void tryFailure(Promise<?> p, Throwable cause, InternalLogger logger) {
64 if (!p.tryFailure(cause) && logger != null) {
65 Throwable err = p.cause();
66 if (err == null) {
67 logger.warn("Failed to mark a promise as failure because it has succeeded already: {}", p, cause);
68 } else {
69 logger.warn(
70 "Failed to mark a promise as failure because it has failed already: {}, unnotified cause: {}",
71 p, ThrowableUtil.stackTraceToString(err), cause);
72 }
73 }
74 }
75
76 }