1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.channel;
17
18 import org.jboss.netty.buffer.ChannelBuffer;
19 import org.jboss.netty.logging.InternalLogger;
20 import org.jboss.netty.logging.InternalLoggerFactory;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public class SimpleChannelUpstreamHandler implements ChannelUpstreamHandler {
55
56 private static final InternalLogger logger =
57 InternalLoggerFactory.getInstance(SimpleChannelUpstreamHandler.class.getName());
58
59
60
61
62 public SimpleChannelUpstreamHandler() {
63 super();
64 }
65
66
67
68
69
70
71 public void handleUpstream(
72 ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
73
74 if (e instanceof MessageEvent) {
75 messageReceived(ctx, (MessageEvent) e);
76 } else if (e instanceof WriteCompletionEvent) {
77 WriteCompletionEvent evt = (WriteCompletionEvent) e;
78 writeComplete(ctx, evt);
79 } else if (e instanceof ChildChannelStateEvent) {
80 ChildChannelStateEvent evt = (ChildChannelStateEvent) e;
81 if (evt.getChildChannel().isOpen()) {
82 childChannelOpen(ctx, evt);
83 } else {
84 childChannelClosed(ctx, evt);
85 }
86 } else if (e instanceof ChannelStateEvent) {
87 ChannelStateEvent evt = (ChannelStateEvent) e;
88 switch (evt.getState()) {
89 case OPEN:
90 if (Boolean.TRUE.equals(evt.getValue())) {
91 channelOpen(ctx, evt);
92 } else {
93 channelClosed(ctx, evt);
94 }
95 break;
96 case BOUND:
97 if (evt.getValue() != null) {
98 channelBound(ctx, evt);
99 } else {
100 channelUnbound(ctx, evt);
101 }
102 break;
103 case CONNECTED:
104 if (evt.getValue() != null) {
105 channelConnected(ctx, evt);
106 } else {
107 channelDisconnected(ctx, evt);
108 }
109 break;
110 case INTEREST_OPS:
111 channelInterestChanged(ctx, evt);
112 break;
113 default:
114 ctx.sendUpstream(e);
115 }
116 } else if (e instanceof ExceptionEvent) {
117 exceptionCaught(ctx, (ExceptionEvent) e);
118 } else {
119 ctx.sendUpstream(e);
120 }
121 }
122
123
124
125
126
127 public void messageReceived(
128 ChannelHandlerContext ctx, MessageEvent e) throws Exception {
129 ctx.sendUpstream(e);
130 }
131
132
133
134
135
136 public void exceptionCaught(
137 ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
138 if (this == ctx.getPipeline().getLast()) {
139 logger.warn(
140 "EXCEPTION, please implement " + getClass().getName() +
141 ".exceptionCaught() for proper handling.", e.getCause());
142 }
143 ctx.sendUpstream(e);
144 }
145
146
147
148
149
150
151
152
153 public void channelOpen(
154 ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
155 ctx.sendUpstream(e);
156 }
157
158
159
160
161
162
163
164
165
166 public void channelBound(
167 ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
168 ctx.sendUpstream(e);
169 }
170
171
172
173
174
175
176
177
178
179 public void channelConnected(
180 ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
181 ctx.sendUpstream(e);
182 }
183
184
185
186
187
188 public void channelInterestChanged(
189 ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
190 ctx.sendUpstream(e);
191 }
192
193
194
195
196 public void channelDisconnected(
197 ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
198 ctx.sendUpstream(e);
199 }
200
201
202
203
204 public void channelUnbound(
205 ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
206 ctx.sendUpstream(e);
207 }
208
209
210
211
212
213 public void channelClosed(
214 ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
215 ctx.sendUpstream(e);
216 }
217
218
219
220
221 public void writeComplete(
222 ChannelHandlerContext ctx, WriteCompletionEvent e) throws Exception {
223 ctx.sendUpstream(e);
224 }
225
226
227
228
229
230 public void childChannelOpen(
231 ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception {
232 ctx.sendUpstream(e);
233 }
234
235
236
237
238
239 public void childChannelClosed(
240 ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception {
241 ctx.sendUpstream(e);
242 }
243 }