View Javadoc

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      HttpTunnelingClientSocketPipelineSink() {
32          super();
33      }
34  
35      public void eventSunk(
36              ChannelPipeline pipeline, ChannelEvent e) throws Exception {
37          HttpTunnelingClientSocketChannel channel = (HttpTunnelingClientSocketChannel) e.getChannel();
38          ChannelFuture future = e.getFuture();
39          if (e instanceof ChannelStateEvent) {
40              ChannelStateEvent stateEvent = (ChannelStateEvent) e;
41              ChannelState state = stateEvent.getState();
42              Object value = stateEvent.getValue();
43              switch (state) {
44              case OPEN:
45                  if (Boolean.FALSE.equals(value)) {
46                      channel.closeReal(future);
47                  }
48                  break;
49              case BOUND:
50                  if (value != null) {
51                      channel.bindReal((SocketAddress) value, future);
52                  } else {
53                      channel.unbindReal(future);
54                  }
55                  break;
56              case CONNECTED:
57                  if (value != null) {
58                      channel.connectReal((SocketAddress) value, future);
59                  } else {
60                      channel.closeReal(future);
61                  }
62                  break;
63              case INTEREST_OPS:
64                  channel.setInterestOpsReal(((Integer) value).intValue(), future);
65                  break;
66              }
67          } else if (e instanceof MessageEvent) {
68              channel.writeReal((ChannelBuffer) ((MessageEvent) e).getMessage(), future);
69          }
70      }
71  }