1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.channel.socket;
17
18 import java.net.ServerSocket;
19 import java.net.SocketException;
20
21 import org.jboss.netty.channel.ChannelException;
22 import org.jboss.netty.channel.DefaultServerChannelConfig;
23 import org.jboss.netty.util.internal.ConversionUtil;
24
25
26
27
28 public class DefaultServerSocketChannelConfig extends DefaultServerChannelConfig
29 implements ServerSocketChannelConfig {
30
31 private final ServerSocket socket;
32 private volatile int backlog;
33
34
35
36
37 public DefaultServerSocketChannelConfig(ServerSocket socket) {
38 if (socket == null) {
39 throw new NullPointerException("socket");
40 }
41 this.socket = socket;
42 }
43
44 @Override
45 public boolean setOption(String key, Object value) {
46 if (super.setOption(key, value)) {
47 return true;
48 }
49
50 if (key.equals("receiveBufferSize")) {
51 setReceiveBufferSize(ConversionUtil.toInt(value));
52 } else if (key.equals("reuseAddress")) {
53 setReuseAddress(ConversionUtil.toBoolean(value));
54 } else if (key.equals("backlog")) {
55 setBacklog(ConversionUtil.toInt(value));
56 } else {
57 return false;
58 }
59 return true;
60 }
61
62 public boolean isReuseAddress() {
63 try {
64 return socket.getReuseAddress();
65 } catch (SocketException e) {
66 throw new ChannelException(e);
67 }
68 }
69
70 public void setReuseAddress(boolean reuseAddress) {
71 try {
72 socket.setReuseAddress(reuseAddress);
73 } catch (SocketException e) {
74 throw new ChannelException(e);
75 }
76 }
77
78 public int getReceiveBufferSize() {
79 try {
80 return socket.getReceiveBufferSize();
81 } catch (SocketException e) {
82 throw new ChannelException(e);
83 }
84 }
85
86 public void setReceiveBufferSize(int receiveBufferSize) {
87 try {
88 socket.setReceiveBufferSize(receiveBufferSize);
89 } catch (SocketException e) {
90 throw new ChannelException(e);
91 }
92 }
93
94 public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
95 socket.setPerformancePreferences(connectionTime, latency, bandwidth);
96 }
97
98 public int getBacklog() {
99 return backlog;
100 }
101
102 public void setBacklog(int backlog) {
103 if (backlog < 0) {
104 throw new IllegalArgumentException("backlog: " + backlog);
105 }
106 this.backlog = backlog;
107 }
108 }