1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.timeout;
17
18 import io.netty5.channel.Channel;
19 import io.netty5.util.internal.StringUtil;
20
21 import static java.util.Objects.requireNonNull;
22
23
24
25
26 public class IdleStateEvent {
27 public static final IdleStateEvent FIRST_READER_IDLE_STATE_EVENT =
28 new DefaultIdleStateEvent(IdleState.READER_IDLE, true);
29 public static final IdleStateEvent READER_IDLE_STATE_EVENT =
30 new DefaultIdleStateEvent(IdleState.READER_IDLE, false);
31 public static final IdleStateEvent FIRST_WRITER_IDLE_STATE_EVENT =
32 new DefaultIdleStateEvent(IdleState.WRITER_IDLE, true);
33 public static final IdleStateEvent WRITER_IDLE_STATE_EVENT =
34 new DefaultIdleStateEvent(IdleState.WRITER_IDLE, false);
35 public static final IdleStateEvent FIRST_ALL_IDLE_STATE_EVENT =
36 new DefaultIdleStateEvent(IdleState.ALL_IDLE, true);
37 public static final IdleStateEvent ALL_IDLE_STATE_EVENT =
38 new DefaultIdleStateEvent(IdleState.ALL_IDLE, false);
39
40 private final IdleState state;
41 private final boolean first;
42
43
44
45
46
47
48
49 protected IdleStateEvent(IdleState state, boolean first) {
50 this.state = requireNonNull(state, "state");
51 this.first = first;
52 }
53
54
55
56
57 public IdleState state() {
58 return state;
59 }
60
61
62
63
64 public boolean isFirst() {
65 return first;
66 }
67
68 @Override
69 public String toString() {
70 return StringUtil.simpleClassName(this) + '(' + state + (first ? ", first" : "") + ')';
71 }
72
73 private static final class DefaultIdleStateEvent extends IdleStateEvent {
74 private final String representation;
75
76 DefaultIdleStateEvent(IdleState state, boolean first) {
77 super(state, first);
78 this.representation = "IdleStateEvent(" + state + (first ? ", first" : "") + ')';
79 }
80
81 @Override
82 public String toString() {
83 return representation;
84 }
85 }
86 }