1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.channel.socket.http;
17
18 import java.net.SocketAddress;
19
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.jboss.netty.channel.AbstractChannelSink;
22 import org.jboss.netty.channel.ChannelEvent;
23 import org.jboss.netty.channel.ChannelFuture;
24 import org.jboss.netty.channel.ChannelPipeline;
25 import org.jboss.netty.channel.ChannelState;
26 import org.jboss.netty.channel.ChannelStateEvent;
27 import org.jboss.netty.channel.MessageEvent;
28
29 final class HttpTunnelingClientSocketPipelineSink extends AbstractChannelSink {
30
31 public void eventSunk(
32 ChannelPipeline pipeline, ChannelEvent e) throws Exception {
33 HttpTunnelingClientSocketChannel channel = (HttpTunnelingClientSocketChannel) e.getChannel();
34 ChannelFuture future = e.getFuture();
35 if (e instanceof ChannelStateEvent) {
36 ChannelStateEvent stateEvent = (ChannelStateEvent) e;
37 ChannelState state = stateEvent.getState();
38 Object value = stateEvent.getValue();
39 switch (state) {
40 case OPEN:
41 if (Boolean.FALSE.equals(value)) {
42 channel.closeReal(future);
43 }
44 break;
45 case BOUND:
46 if (value != null) {
47 channel.bindReal((SocketAddress) value, future);
48 } else {
49 channel.unbindReal(future);
50 }
51 break;
52 case CONNECTED:
53 if (value != null) {
54 channel.connectReal((SocketAddress) value, future);
55 } else {
56 channel.closeReal(future);
57 }
58 break;
59 case INTEREST_OPS:
60 channel.setInterestOpsReal(((Integer) value).intValue(), future);
61 break;
62 }
63 } else if (e instanceof MessageEvent) {
64 channel.writeReal((ChannelBuffer) ((MessageEvent) e).getMessage(), future);
65 }
66 }
67 }