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 public class UpstreamChannelStateEvent implements ChannelStateEvent {
24
25 private final Channel channel;
26 private final ChannelState state;
27 private final Object value;
28
29
30
31
32 public UpstreamChannelStateEvent(
33 Channel channel, ChannelState state, Object value) {
34
35 if (channel == null) {
36 throw new NullPointerException("channel");
37 }
38 if (state == null) {
39 throw new NullPointerException("state");
40 }
41
42 this.channel = channel;
43 this.state = state;
44 this.value = value;
45 }
46
47 public Channel getChannel() {
48 return channel;
49 }
50
51 public ChannelFuture getFuture() {
52 return succeededFuture(getChannel());
53 }
54
55 public ChannelState getState() {
56 return state;
57 }
58
59 public Object getValue() {
60 return value;
61 }
62
63 @Override
64 public String toString() {
65 String channelString = getChannel().toString();
66 StringBuilder buf = new StringBuilder(channelString.length() + 64);
67 buf.append(channelString);
68 switch (getState()) {
69 case OPEN:
70 if (Boolean.TRUE.equals(getValue())) {
71 buf.append(" OPEN");
72 } else {
73 buf.append(" CLOSED");
74 }
75 break;
76 case BOUND:
77 if (getValue() != null) {
78 buf.append(" BOUND: ");
79 buf.append(getValue());
80 } else {
81 buf.append(" UNBOUND");
82 }
83 break;
84 case CONNECTED:
85 if (getValue() != null) {
86 buf.append(" CONNECTED: ");
87 buf.append(getValue());
88 } else {
89 buf.append(" DISCONNECTED");
90 }
91 break;
92 case INTEREST_OPS:
93 buf.append(" INTEREST_CHANGED");
94 break;
95 default:
96 buf.append(getState().name());
97 buf.append(": ");
98 buf.append(getValue());
99 }
100 return buf.toString();
101 }
102 }