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      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.equals("pipelineFactory")) {
45              setPipelineFactory((ChannelPipelineFactory) value);
46          } else if (key.equals("bufferFactory")) {
47              setBufferFactory((ChannelBufferFactory) value);
48          } else {
49              return false;
50          }
51          return true;
52      }
53  
54      public ChannelPipelineFactory getPipelineFactory() {
55          return pipelineFactory;
56      }
57  
58      public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
59          if (pipelineFactory == null) {
60              throw new NullPointerException("pipelineFactory");
61          }
62          this.pipelineFactory = pipelineFactory;
63      }
64  
65      public ChannelBufferFactory getBufferFactory() {
66          return bufferFactory;
67      }
68  
69      public void setBufferFactory(ChannelBufferFactory bufferFactory) {
70          if (bufferFactory == null) {
71              throw new NullPointerException("bufferFactory");
72          }
73  
74          this.bufferFactory = bufferFactory;
75      }
76  
77      public int getConnectTimeoutMillis() {
78          return 0;
79      }
80  
81      public void setConnectTimeoutMillis(int connectTimeoutMillis) {
82          // Unused
83      }
84  }