1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.SocketChannelConfig;
21 import org.jboss.netty.util.internal.ConversionUtil;
22
23 import java.util.Map;
24 import java.util.Map.Entry;
25
26
27
28
29 public class DefaultChannelConfig implements ChannelConfig {
30
31 private volatile ChannelBufferFactory bufferFactory = HeapChannelBufferFactory.getInstance();
32 private volatile int connectTimeoutMillis = 10000;
33
34 public void setOptions(Map<String, Object> options) {
35 for (Entry<String, Object> e: options.entrySet()) {
36 setOption(e.getKey(), e.getValue());
37 }
38 }
39
40 public boolean setOption(String key, Object value) {
41 if (key == null) {
42 throw new NullPointerException("key");
43 }
44
45 if ("pipelineFactory".equals(key)) {
46 setPipelineFactory((ChannelPipelineFactory) value);
47 } else if ("connectTimeoutMillis".equals(key)) {
48 setConnectTimeoutMillis(ConversionUtil.toInt(value));
49 } else if ("bufferFactory".equals(key)) {
50 setBufferFactory((ChannelBufferFactory) value);
51 } else {
52 return false;
53 }
54 return true;
55 }
56
57 public int getConnectTimeoutMillis() {
58 return connectTimeoutMillis;
59 }
60
61 public ChannelBufferFactory getBufferFactory() {
62 return bufferFactory;
63 }
64
65 public void setBufferFactory(ChannelBufferFactory bufferFactory) {
66 if (bufferFactory == null) {
67 throw new NullPointerException("bufferFactory");
68 }
69 this.bufferFactory = bufferFactory;
70 }
71
72 public ChannelPipelineFactory getPipelineFactory() {
73 return null;
74 }
75
76 public void setConnectTimeoutMillis(int connectTimeoutMillis) {
77 if (connectTimeoutMillis < 0) {
78 throw new IllegalArgumentException("connectTimeoutMillis: " + connectTimeoutMillis);
79 }
80 this.connectTimeoutMillis = connectTimeoutMillis;
81 }
82
83 public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
84
85 }
86 }