查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
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  }