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;
    17
    18  import java.util.Map;
    19  import java.util.Map.Entry;
    20
    21  import org.jboss.netty.buffer.ChannelBufferFactory;
    22  import org.jboss.netty.buffer.HeapChannelBufferFactory;
    23  import org.jboss.netty.channel.socket.ServerSocketChannelConfig;
    24
    25  /**
    26   * The default {@link ServerSocketChannelConfig} implementation.
    27   *
    28   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
    29   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
    30   *
    31   * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $
    32   */
    33  public class DefaultServerChannelConfig implements ChannelConfig {
    34
    35      private volatile ChannelPipelineFactory pipelineFactory;
    36      private volatile ChannelBufferFactory bufferFactory = HeapChannelBufferFactory.getInstance();
    37
    38      /**
    39       * Creates a new instance.
    40       */
    41      public DefaultServerChannelConfig() {
    42          super();
    43      }
    44
    45      public void setOptions(Map<String, Object> options) {
    46          for (Entry<String, Object> e: options.entrySet()) {
    47              setOption(e.getKey(), e.getValue());
    48          }
    49      }
    50
    51      /**
    52       * Sets an individual option.  You can override this method to support
    53       * additional configuration parameters.
    54       */
    55      public boolean setOption(String key, Object value) {
    56          if (key.equals("pipelineFactory")) {
    57              setPipelineFactory((ChannelPipelineFactory) value);
    58          } else if (key.equals("bufferFactory")) {
    59              setBufferFactory((ChannelBufferFactory) value);
    60          } else {
    61              return false;
    62          }
    63          return true;
    64      }
    65
    66      public ChannelPipelineFactory getPipelineFactory() {
    67          return pipelineFactory;
    68      }
    69
    70      public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
    71          if (pipelineFactory == null) {
    72              throw new NullPointerException("pipelineFactory");
    73          }
    74          this.pipelineFactory = pipelineFactory;
    75      }
    76
    77      public ChannelBufferFactory getBufferFactory() {
    78          return bufferFactory;
    79      }
    80
    81      public void setBufferFactory(ChannelBufferFactory bufferFactory) {
    82          if (bufferFactory == null) {
    83              throw new NullPointerException("bufferFactory");
    84          }
    85
    86          this.bufferFactory = bufferFactory;
    87      }
    88
    89      public int getConnectTimeoutMillis() {
    90          return 0;
    91      }
    92
    93      public void setConnectTimeoutMillis(int connectTimeoutMillis) {
    94          // Unused
    95      }
    96  }