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.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
    29   *      constructor in AbstractChannel.
    30   */
    31  class EmbeddedChannel extends AbstractChannel {
    32
    33      private static final Integer DUMMY_ID = 0;
    34
    35      private final ChannelConfig config;
    36      private final SocketAddress localAddress = new EmbeddedSocketAddress();
    37      private final SocketAddress remoteAddress = new EmbeddedSocketAddress();
    38
    39      EmbeddedChannel(ChannelPipeline pipeline, ChannelSink sink) {
    40          super(DUMMY_ID, null, EmbeddedChannelFactory.INSTANCE, pipeline, sink);
    41          config = new DefaultChannelConfig();
    42      }
    43
    44      public ChannelConfig getConfig() {
    45          return config;
    46      }
    47
    48      public SocketAddress getLocalAddress() {
    49          return localAddress;
    50      }
    51
    52      public SocketAddress getRemoteAddress() {
    53          return remoteAddress;
    54      }
    55
    56      public boolean isBound() {
    57          return true;
    58      }
    59
    60      public boolean isConnected() {
    61          return true;
    62      }
    63  }