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