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;
    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  public class DefaultServerChannelConfig implements ChannelConfig {
    29
    30      private volatile ChannelPipelineFactory pipelineFactory;
    31      private volatile ChannelBufferFactory bufferFactory = HeapChannelBufferFactory.getInstance();
    32
    33      /**
    34       * Creates a new instance.
    35       */
    36      public DefaultServerChannelConfig() {
    37          super();
    38      }
    39
    40      public void setOptions(Map<String, Object> options) {
    41          for (Entry<String, Object> e: options.entrySet()) {
    42              setOption(e.getKey(), e.getValue());
    43          }
    44      }
    45
    46      /**
    47       * Sets an individual option.  You can override this method to support
    48       * additional configuration parameters.
    49       */
    50      public boolean setOption(String key, Object value) {
    51          if (key.equals("pipelineFactory")) {
    52              setPipelineFactory((ChannelPipelineFactory) value);
    53          } else if (key.equals("bufferFactory")) {
    54              setBufferFactory((ChannelBufferFactory) value);
    55          } else {
    56              return false;
    57          }
    58          return true;
    59      }
    60
    61      public ChannelPipelineFactory getPipelineFactory() {
    62          return pipelineFactory;
    63      }
    64
    65      public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
    66          if (pipelineFactory == null) {
    67              throw new NullPointerException("pipelineFactory");
    68          }
    69          this.pipelineFactory = pipelineFactory;
    70      }
    71
    72      public ChannelBufferFactory getBufferFactory() {
    73          return bufferFactory;
    74      }
    75
    76      public void setBufferFactory(ChannelBufferFactory bufferFactory) {
    77          if (bufferFactory == null) {
    78              throw new NullPointerException("bufferFactory");
    79          }
    80
    81          this.bufferFactory = bufferFactory;
    82      }
    83
    84      public int getConnectTimeoutMillis() {
    85          return 0;
    86      }
    87
    88      public void setConnectTimeoutMillis(int connectTimeoutMillis) {
    89          // Unused
    90      }
    91  }