1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.transport.socket;
21
22 import org.apache.mina.core.service.IoService;
23
24
25
26
27
28
29 public class DefaultSocketSessionConfig extends AbstractSocketSessionConfig {
30 private static boolean DEFAULT_REUSE_ADDRESS = false;
31 private static int DEFAULT_TRAFFIC_CLASS = 0;
32 private static boolean DEFAULT_KEEP_ALIVE = false;
33 private static boolean DEFAULT_OOB_INLINE = false;
34 private static int DEFAULT_SO_LINGER = -1;
35 private static boolean DEFAULT_TCP_NO_DELAY = false;
36
37 protected IoService parent;
38 private boolean defaultReuseAddress;
39
40 private boolean reuseAddress;
41
42
43 private int receiveBufferSize = -1;
44
45
46 private int sendBufferSize = -1;
47
48 private int trafficClass = DEFAULT_TRAFFIC_CLASS;
49 private boolean keepAlive = DEFAULT_KEEP_ALIVE;
50 private boolean oobInline = DEFAULT_OOB_INLINE;
51 private int soLinger = DEFAULT_SO_LINGER;
52 private boolean tcpNoDelay = DEFAULT_TCP_NO_DELAY;
53
54
55
56
57 public DefaultSocketSessionConfig() {
58
59 }
60
61 public void init(IoService parent) {
62 this.parent = parent;
63
64 if (parent instanceof SocketAcceptor) {
65 defaultReuseAddress = true;
66 } else {
67 defaultReuseAddress = DEFAULT_REUSE_ADDRESS;
68 }
69
70 reuseAddress = defaultReuseAddress;
71 }
72
73 public boolean isReuseAddress() {
74 return reuseAddress;
75 }
76
77 public void setReuseAddress(boolean reuseAddress) {
78 this.reuseAddress = reuseAddress;
79 }
80
81 public int getReceiveBufferSize() {
82 return receiveBufferSize;
83 }
84
85 public void setReceiveBufferSize(int receiveBufferSize) {
86 this.receiveBufferSize = receiveBufferSize;
87 }
88
89 public int getSendBufferSize() {
90 return sendBufferSize;
91 }
92
93 public void setSendBufferSize(int sendBufferSize) {
94 this.sendBufferSize = sendBufferSize;
95 }
96
97 public int getTrafficClass() {
98 return trafficClass;
99 }
100
101 public void setTrafficClass(int trafficClass) {
102 this.trafficClass = trafficClass;
103 }
104
105 public boolean isKeepAlive() {
106 return keepAlive;
107 }
108
109 public void setKeepAlive(boolean keepAlive) {
110 this.keepAlive = keepAlive;
111 }
112
113 public boolean isOobInline() {
114 return oobInline;
115 }
116
117 public void setOobInline(boolean oobInline) {
118 this.oobInline = oobInline;
119 }
120
121 public int getSoLinger() {
122 return soLinger;
123 }
124
125 public void setSoLinger(int soLinger) {
126 this.soLinger = soLinger;
127 }
128
129 public boolean isTcpNoDelay() {
130 return tcpNoDelay;
131 }
132
133 public void setTcpNoDelay(boolean tcpNoDelay) {
134 this.tcpNoDelay = tcpNoDelay;
135 }
136
137 @Override
138 protected boolean isKeepAliveChanged() {
139 return keepAlive != DEFAULT_KEEP_ALIVE;
140 }
141
142 @Override
143 protected boolean isOobInlineChanged() {
144 return oobInline != DEFAULT_OOB_INLINE;
145 }
146
147 @Override
148 protected boolean isReceiveBufferSizeChanged() {
149 return receiveBufferSize != -1;
150 }
151
152 @Override
153 protected boolean isReuseAddressChanged() {
154 return reuseAddress != defaultReuseAddress;
155 }
156
157 @Override
158 protected boolean isSendBufferSizeChanged() {
159 return sendBufferSize != -1;
160 }
161
162 @Override
163 protected boolean isSoLingerChanged() {
164 return soLinger != DEFAULT_SO_LINGER;
165 }
166
167 @Override
168 protected boolean isTcpNoDelayChanged() {
169 return tcpNoDelay != DEFAULT_TCP_NO_DELAY;
170 }
171
172 @Override
173 protected boolean isTrafficClassChanged() {
174 return trafficClass != DEFAULT_TRAFFIC_CLASS;
175 }
176 }