查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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 org.jboss.netty.buffer.ChannelBufferFactory;
19  import org.jboss.netty.buffer.HeapChannelBufferFactory;
20  import org.jboss.netty.channel.socket.ServerSocketChannelConfig;
21  
22  import java.util.Map;
23  import java.util.Map.Entry;
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      public void setOptions(Map<String, Object> options) {
34          for (Entry<String, Object> e: options.entrySet()) {
35              setOption(e.getKey(), e.getValue());
36          }
37      }
38  
39      /**
40       * Sets an individual option.  You can override this method to support
41       * additional configuration parameters.
42       */
43      public boolean setOption(String key, Object value) {
44          if (key == null) {
45              throw new NullPointerException("key");
46          }
47          if ("pipelineFactory".equals(key)) {
48              setPipelineFactory((ChannelPipelineFactory) value);
49          } else if ("bufferFactory".equals(key)) {
50              setBufferFactory((ChannelBufferFactory) value);
51          } else {
52              return false;
53          }
54          return true;
55      }
56  
57      public ChannelPipelineFactory getPipelineFactory() {
58          return pipelineFactory;
59      }
60  
61      public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
62          if (pipelineFactory == null) {
63              throw new NullPointerException("pipelineFactory");
64          }
65          this.pipelineFactory = pipelineFactory;
66      }
67  
68      public ChannelBufferFactory getBufferFactory() {
69          return bufferFactory;
70      }
71  
72      public void setBufferFactory(ChannelBufferFactory bufferFactory) {
73          if (bufferFactory == null) {
74              throw new NullPointerException("bufferFactory");
75          }
76  
77          this.bufferFactory = bufferFactory;
78      }
79  
80      public int getConnectTimeoutMillis() {
81          return 0;
82      }
83  
84      public void setConnectTimeoutMillis(int connectTimeoutMillis) {
85          // Unused
86      }
87  }