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.handler.codec.embedder;
    17
    18  import java.net.SocketAddress;
    19
    20  import org.jboss.netty.channel.AbstractChannel;
    21  import org.jboss.netty.channel.ChannelConfig;
    22  import org.jboss.netty.channel.ChannelPipeline;
    23  import org.jboss.netty.channel.ChannelSink;
    24  import org.jboss.netty.channel.DefaultChannelConfig;
    25
    26  /**
    27   * TODO Make EmbeddedChannel implement ChannelConfig and ChannelSink to reduce overhead.
    28   * TODO Do not extend AbstractChannel to reduce overhead and remove the internal-use-only constructor in AbstractChannel.
    29   *
    30   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
    31   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
    32   * @version $Rev: 2280 $, $Date: 2010-05-19 15:29:43 +0900 (Wed, 19 May 2010) $
    33   */
    34  class EmbeddedChannel extends AbstractChannel {
    35
    36      private static final Integer DUMMY_ID = Integer.valueOf(0);
    37
    38      private final ChannelConfig config;
    39      private final SocketAddress localAddress = new EmbeddedSocketAddress();
    40      private final SocketAddress remoteAddress = new EmbeddedSocketAddress();
    41
    42      EmbeddedChannel(ChannelPipeline pipeline, ChannelSink sink) {
    43          super(DUMMY_ID, null, EmbeddedChannelFactory.INSTANCE, pipeline, sink);
    44          config = new DefaultChannelConfig();
    45      }
    46
    47      public ChannelConfig getConfig() {
    48          return config;
    49      }
    50
    51      public SocketAddress getLocalAddress() {
    52          return localAddress;
    53      }
    54
    55      public SocketAddress getRemoteAddress() {
    56          return remoteAddress;
    57      }
    58
    59      public boolean isBound() {
    60          return true;
    61      }
    62
    63      public boolean isConnected() {
    64          return true;
    65      }
    66  }