1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.channel;
17
18
19
20
21 public class DownstreamChannelStateEvent implements ChannelStateEvent {
22
23 private final Channel channel;
24 private final ChannelFuture future;
25 private final ChannelState state;
26 private final Object value;
27
28
29
30
31 public DownstreamChannelStateEvent(
32 Channel channel, ChannelFuture future,
33 ChannelState state, Object value) {
34
35 if (channel == null) {
36 throw new NullPointerException("channel");
37 }
38 if (future == null) {
39 throw new NullPointerException("future");
40 }
41 if (state == null) {
42 throw new NullPointerException("state");
43 }
44 this.channel = channel;
45 this.future = future;
46 this.state = state;
47 this.value = value;
48 }
49
50 public Channel getChannel() {
51 return channel;
52 }
53
54 public ChannelFuture getFuture() {
55 return future;
56 }
57
58 public ChannelState getState() {
59 return state;
60 }
61
62 public Object getValue() {
63 return value;
64 }
65
66 @Override
67 public String toString() {
68 String channelString = getChannel().toString();
69 StringBuilder buf = new StringBuilder(channelString.length() + 64);
70 buf.append(channelString);
71 switch (getState()) {
72 case OPEN:
73 if (Boolean.TRUE.equals(getValue())) {
74 buf.append(" OPEN");
75 } else {
76 buf.append(" CLOSE");
77 }
78 break;
79 case BOUND:
80 if (getValue() != null) {
81 buf.append(" BIND: ");
82 buf.append(getValue());
83 } else {
84 buf.append(" UNBIND");
85 }
86 break;
87 case CONNECTED:
88 if (getValue() != null) {
89 buf.append(" CONNECT: ");
90 buf.append(getValue());
91 } else {
92 buf.append(" DISCONNECT");
93 }
94 break;
95 case INTEREST_OPS:
96 buf.append(" CHANGE_INTEREST: ");
97 buf.append(getValue());
98 break;
99 default:
100 buf.append(' ');
101 buf.append(getState().name());
102 buf.append(": ");
103 buf.append(getValue());
104 }
105 return buf.toString();
106 }
107 }