1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.SocketChannelConfig;
24 import org.jboss.netty.util.internal.ConversionUtil;
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.equals("pipelineFactory")) {
42 setPipelineFactory((ChannelPipelineFactory) value);
43 } else if (key.equals("connectTimeoutMillis")) {
44 setConnectTimeoutMillis(ConversionUtil.toInt(value));
45 } else if (key.equals("bufferFactory")) {
46 setBufferFactory((ChannelBufferFactory) value);
47 } else {
48 return false;
49 }
50 return true;
51 }
52
53 public int getConnectTimeoutMillis() {
54 return connectTimeoutMillis;
55 }
56
57 public ChannelBufferFactory getBufferFactory() {
58 return bufferFactory;
59 }
60
61 public void setBufferFactory(ChannelBufferFactory bufferFactory) {
62 if (bufferFactory == null) {
63 throw new NullPointerException("bufferFactory");
64 }
65 this.bufferFactory = bufferFactory;
66 }
67
68 public ChannelPipelineFactory getPipelineFactory() {
69 return null;
70 }
71
72 public void setConnectTimeoutMillis(int connectTimeoutMillis) {
73 if (connectTimeoutMillis < 0) {
74 throw new IllegalArgumentException("connectTimeoutMillis: " + connectTimeoutMillis);
75 }
76 this.connectTimeoutMillis = connectTimeoutMillis;
77 }
78
79 public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
80
81 }
82 }