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_RECEIVE_BUFFER_SIZE = 1024;
32 private static int DEFAULT_SEND_BUFFER_SIZE = 1024;
33 private static int DEFAULT_TRAFFIC_CLASS = 0;
34 private static boolean DEFAULT_KEEP_ALIVE = false;
35 private static boolean DEFAULT_OOB_INLINE = false;
36 private static int DEFAULT_SO_LINGER = -1;
37 private static boolean DEFAULT_TCP_NO_DELAY = false;
38
39 private IoService parent;
40 private boolean defaultReuseAddress;
41 private int defaultReceiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
42
43 private boolean reuseAddress;
44 private int receiveBufferSize = defaultReceiveBufferSize;
45 private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE;
46 private int trafficClass = DEFAULT_TRAFFIC_CLASS;
47 private boolean keepAlive = DEFAULT_KEEP_ALIVE;
48 private boolean oobInline = DEFAULT_OOB_INLINE;
49 private int soLinger = DEFAULT_SO_LINGER;
50 private boolean tcpNoDelay = DEFAULT_TCP_NO_DELAY;
51
52
53
54
55 public DefaultSocketSessionConfig() {
56
57 }
58
59 public void init(IoService parent) {
60 this.parent = parent;
61 if (parent instanceof SocketAcceptor) {
62 defaultReuseAddress = true;
63 } else {
64 defaultReuseAddress = DEFAULT_REUSE_ADDRESS;
65 }
66 reuseAddress = defaultReuseAddress;
67 }
68
69 public boolean isReuseAddress() {
70 return reuseAddress;
71 }
72
73 public void setReuseAddress(boolean reuseAddress) {
74 this.reuseAddress = reuseAddress;
75 }
76
77 public int getReceiveBufferSize() {
78 return receiveBufferSize;
79 }
80
81 public void setReceiveBufferSize(int receiveBufferSize) {
82 this.receiveBufferSize = receiveBufferSize;
83
84
85
86
87
88
89
90
91
92 if (!parent.isActive() && parent instanceof SocketAcceptor) {
93 defaultReceiveBufferSize = receiveBufferSize;
94 }
95 }
96
97 public int getSendBufferSize() {
98 return sendBufferSize;
99 }
100
101 public void setSendBufferSize(int sendBufferSize) {
102 this.sendBufferSize = sendBufferSize;
103 }
104
105 public int getTrafficClass() {
106 return trafficClass;
107 }
108
109 public void setTrafficClass(int trafficClass) {
110 this.trafficClass = trafficClass;
111 }
112
113 public boolean isKeepAlive() {
114 return keepAlive;
115 }
116
117 public void setKeepAlive(boolean keepAlive) {
118 this.keepAlive = keepAlive;
119 }
120
121 public boolean isOobInline() {
122 return oobInline;
123 }
124
125 public void setOobInline(boolean oobInline) {
126 this.oobInline = oobInline;
127 }
128
129 public int getSoLinger() {
130 return soLinger;
131 }
132
133 public void setSoLinger(int soLinger) {
134 this.soLinger = soLinger;
135 }
136
137 public boolean isTcpNoDelay() {
138 return tcpNoDelay;
139 }
140
141 public void setTcpNoDelay(boolean tcpNoDelay) {
142 this.tcpNoDelay = tcpNoDelay;
143 }
144
145 @Override
146 protected boolean isKeepAliveChanged() {
147 return keepAlive != DEFAULT_KEEP_ALIVE;
148 }
149
150 @Override
151 protected boolean isOobInlineChanged() {
152 return oobInline != DEFAULT_OOB_INLINE;
153 }
154
155 @Override
156 protected boolean isReceiveBufferSizeChanged() {
157 return receiveBufferSize != defaultReceiveBufferSize;
158 }
159
160 @Override
161 protected boolean isReuseAddressChanged() {
162 return reuseAddress != defaultReuseAddress;
163 }
164
165 @Override
166 protected boolean isSendBufferSizeChanged() {
167 return sendBufferSize != DEFAULT_SEND_BUFFER_SIZE;
168 }
169
170 @Override
171 protected boolean isSoLingerChanged() {
172 return soLinger != DEFAULT_SO_LINGER;
173 }
174
175 @Override
176 protected boolean isTcpNoDelayChanged() {
177 return tcpNoDelay != DEFAULT_TCP_NO_DELAY;
178 }
179
180 @Override
181 protected boolean isTrafficClassChanged() {
182 return trafficClass != DEFAULT_TRAFFIC_CLASS;
183 }
184 }