1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.channel;
17
18 import io.netty5.util.concurrent.Future;
19 import io.netty5.util.concurrent.FutureContextListener;
20
21
22
23
24
25
26
27 public final class ChannelFutureListeners {
28
29
30
31
32
33 public static final FutureContextListener<ChannelOutboundInvoker, Object> CLOSE = new Close();
34
35
36
37
38
39 public static final FutureContextListener<ChannelOutboundInvoker, Object> CLOSE_ON_FAILURE = new CloseOnFailure();
40
41
42
43
44
45 public static final FutureContextListener<Channel, Object> FIRE_EXCEPTION_ON_FAILURE = new FireExceptionOnFailure();
46
47 private ChannelFutureListeners() {
48 }
49
50 private static final class Close implements FutureContextListener<ChannelOutboundInvoker, Object> {
51 @Override
52 public void operationComplete(ChannelOutboundInvoker context, Future<?> future) throws Exception {
53 context.close();
54 }
55 }
56
57 private static final class CloseOnFailure implements FutureContextListener<ChannelOutboundInvoker, Object> {
58 @Override
59 public void operationComplete(ChannelOutboundInvoker context, Future<?> future) throws Exception {
60 if (future.isFailed()) {
61 context.close();
62 }
63 }
64 }
65
66 private static final class FireExceptionOnFailure implements FutureContextListener<Channel, Object> {
67 @Override
68 public void operationComplete(Channel context, Future<?> future) throws Exception {
69 if (future.isFailed()) {
70 context.pipeline().fireChannelExceptionCaught(future.cause());
71 }
72 }
73 }
74 }