View Javadoc

    1   /*
    2    * Copyright 2009 Red Hat, Inc.
    3    *
    4    * Red Hat licenses this file to you under the Apache License, version 2.0
    5    * (the "License"); you may not use this file except in compliance with the
    6    * 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  /**
    30   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
    31   * @author Andy Taylor (andy.taylor@jboss.org)
    32   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
    33   * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $
    34   */
    35  final class HttpTunnelingClientSocketPipelineSink extends AbstractChannelSink {
    36
    37      HttpTunnelingClientSocketPipelineSink() {
    38          super();
    39      }
    40
    41      public void eventSunk(
    42              ChannelPipeline pipeline, ChannelEvent e) throws Exception {
    43          HttpTunnelingClientSocketChannel channel = (HttpTunnelingClientSocketChannel) e.getChannel();
    44          ChannelFuture future = e.getFuture();
    45          if (e instanceof ChannelStateEvent) {
    46              ChannelStateEvent stateEvent = (ChannelStateEvent) e;
    47              ChannelState state = stateEvent.getState();
    48              Object value = stateEvent.getValue();
    49              switch (state) {
    50              case OPEN:
    51                  if (Boolean.FALSE.equals(value)) {
    52                      channel.closeReal(future);
    53                  }
    54                  break;
    55              case BOUND:
    56                  if (value != null) {
    57                      channel.bindReal((SocketAddress) value, future);
    58                  } else {
    59                      channel.unbindReal(future);
    60                  }
    61                  break;
    62              case CONNECTED:
    63                  if (value != null) {
    64                      channel.connectReal((SocketAddress) value, future);
    65                  } else {
    66                      channel.closeReal(future);
    67                  }
    68                  break;
    69              case INTEREST_OPS:
    70                  channel.setInterestOpsReal(((Integer) value).intValue(), future);
    71                  break;
    72              }
    73          } else if (e instanceof MessageEvent) {
    74              channel.writeReal(((ChannelBuffer) ((MessageEvent) e).getMessage()), future);
    75          }
    76      }
    77  }