1
17 package org.apache.tomcat.util.net;
18
19 import java.io.IOException;
20 import java.net.ServerSocket;
21 import java.net.Socket;
22 import java.net.SocketException;
23 import java.net.StandardSocketOptions;
24 import java.nio.channels.AsynchronousServerSocketChannel;
25 import java.nio.channels.AsynchronousSocketChannel;
26
27 import javax.management.ObjectName;
28
29
34 public class SocketProperties {
35
36
44 protected int processorCache = 500;
45
46
55 protected int eventCache = 500;
56
57
61 protected boolean directBuffer = false;
62
63
67 protected boolean directSslBuffer = false;
68
69
73 protected Integer rxBufSize = null;
74
75
79 protected Integer txBufSize = null;
80
81
85 protected int appReadBufSize = 8192;
86
87
91 protected int appWriteBufSize = 8192;
92
93
104 protected int bufferPool = 500;
105
106
118 protected int bufferPoolSize = 1024*1024*100;
119
120
123 protected Boolean tcpNoDelay = Boolean.TRUE;
124
125
128 protected Boolean soKeepAlive = null;
129
130
133 protected Boolean ooBInline = null;
134
135
138 protected Boolean soReuseAddress = null;
139
140
144 protected Boolean soLingerOn = null;
145
146
150 protected Integer soLingerTime = null;
151
152
155 protected Integer soTimeout = Integer.valueOf(20000);
156
157
163 protected Integer performanceConnectionTime = null;
164
165
171 protected Integer performanceLatency = null;
172
173
179 protected Integer performanceBandwidth = null;
180
181
185 protected long timeoutInterval = 1000;
186
187
190 protected int unlockTimeout = 250;
191
192 private ObjectName oname = null;
193
194
195 public void setProperties(Socket socket) throws SocketException{
196 if (rxBufSize != null)
197 socket.setReceiveBufferSize(rxBufSize.intValue());
198 if (txBufSize != null)
199 socket.setSendBufferSize(txBufSize.intValue());
200 if (ooBInline !=null)
201 socket.setOOBInline(ooBInline.booleanValue());
202 if (soKeepAlive != null)
203 socket.setKeepAlive(soKeepAlive.booleanValue());
204 if (performanceConnectionTime != null && performanceLatency != null &&
205 performanceBandwidth != null)
206 socket.setPerformancePreferences(
207 performanceConnectionTime.intValue(),
208 performanceLatency.intValue(),
209 performanceBandwidth.intValue());
210 if (soReuseAddress != null)
211 socket.setReuseAddress(soReuseAddress.booleanValue());
212 if (soLingerOn != null && soLingerTime != null)
213 socket.setSoLinger(soLingerOn.booleanValue(),
214 soLingerTime.intValue());
215 if (soTimeout != null && soTimeout.intValue() >= 0)
216 socket.setSoTimeout(soTimeout.intValue());
217 if (tcpNoDelay != null) {
218 try {
219 socket.setTcpNoDelay(tcpNoDelay.booleanValue());
220 } catch (SocketException e) {
221
222 }
223 }
224 }
225
226 public void setProperties(ServerSocket socket) throws SocketException{
227 if (rxBufSize != null)
228 socket.setReceiveBufferSize(rxBufSize.intValue());
229 if (performanceConnectionTime != null && performanceLatency != null &&
230 performanceBandwidth != null)
231 socket.setPerformancePreferences(
232 performanceConnectionTime.intValue(),
233 performanceLatency.intValue(),
234 performanceBandwidth.intValue());
235 if (soReuseAddress != null)
236 socket.setReuseAddress(soReuseAddress.booleanValue());
237 if (soTimeout != null && soTimeout.intValue() >= 0)
238 socket.setSoTimeout(soTimeout.intValue());
239 }
240
241 public void setProperties(AsynchronousSocketChannel socket) throws IOException {
242 if (rxBufSize != null)
243 socket.setOption(StandardSocketOptions.SO_RCVBUF, rxBufSize);
244 if (txBufSize != null)
245 socket.setOption(StandardSocketOptions.SO_SNDBUF, txBufSize);
246 if (soKeepAlive != null)
247 socket.setOption(StandardSocketOptions.SO_KEEPALIVE, soKeepAlive);
248 if (soReuseAddress != null)
249 socket.setOption(StandardSocketOptions.SO_REUSEADDR, soReuseAddress);
250 if (soLingerOn != null && soLingerOn.booleanValue() && soLingerTime != null)
251 socket.setOption(StandardSocketOptions.SO_LINGER, soLingerTime);
252 if (tcpNoDelay != null)
253 socket.setOption(StandardSocketOptions.TCP_NODELAY, tcpNoDelay);
254 }
255
256 public void setProperties(AsynchronousServerSocketChannel socket) throws IOException {
257 if (rxBufSize != null)
258 socket.setOption(StandardSocketOptions.SO_RCVBUF, rxBufSize);
259 if (soReuseAddress != null)
260 socket.setOption(StandardSocketOptions.SO_REUSEADDR, soReuseAddress);
261 }
262
263 public boolean getDirectBuffer() {
264 return directBuffer;
265 }
266
267 public boolean getDirectSslBuffer() {
268 return directSslBuffer;
269 }
270
271 public boolean getOoBInline() {
272 return ooBInline.booleanValue();
273 }
274
275 public int getPerformanceBandwidth() {
276 return performanceBandwidth.intValue();
277 }
278
279 public int getPerformanceConnectionTime() {
280 return performanceConnectionTime.intValue();
281 }
282
283 public int getPerformanceLatency() {
284 return performanceLatency.intValue();
285 }
286
287 public int getRxBufSize() {
288 return rxBufSize.intValue();
289 }
290
291 public boolean getSoKeepAlive() {
292 return soKeepAlive.booleanValue();
293 }
294
295 public boolean getSoLingerOn() {
296 return soLingerOn.booleanValue();
297 }
298
299 public int getSoLingerTime() {
300 return soLingerTime.intValue();
301 }
302
303 public boolean getSoReuseAddress() {
304 return soReuseAddress.booleanValue();
305 }
306
307 public int getSoTimeout() {
308 return soTimeout.intValue();
309 }
310
311 public boolean getTcpNoDelay() {
312 return tcpNoDelay.booleanValue();
313 }
314
315 public int getTxBufSize() {
316 return txBufSize.intValue();
317 }
318
319 public int getBufferPool() {
320 return bufferPool;
321 }
322
323 public int getBufferPoolSize() {
324 return bufferPoolSize;
325 }
326
327 public int getEventCache() {
328 return eventCache;
329 }
330
331 public int getAppReadBufSize() {
332 return appReadBufSize;
333 }
334
335 public int getAppWriteBufSize() {
336 return appWriteBufSize;
337 }
338
339 public int getProcessorCache() {
340 return processorCache;
341 }
342
343 public long getTimeoutInterval() {
344 return timeoutInterval;
345 }
346
347 public int getDirectBufferPool() {
348 return bufferPool;
349 }
350
351 public void setPerformanceConnectionTime(int performanceConnectionTime) {
352 this.performanceConnectionTime =
353 Integer.valueOf(performanceConnectionTime);
354 }
355
356 public void setTxBufSize(int txBufSize) {
357 this.txBufSize = Integer.valueOf(txBufSize);
358 }
359
360 public void setTcpNoDelay(boolean tcpNoDelay) {
361 this.tcpNoDelay = Boolean.valueOf(tcpNoDelay);
362 }
363
364 public void setSoTimeout(int soTimeout) {
365 this.soTimeout = Integer.valueOf(soTimeout);
366 }
367
368 public void setSoReuseAddress(boolean soReuseAddress) {
369 this.soReuseAddress = Boolean.valueOf(soReuseAddress);
370 }
371
372 public void setSoLingerTime(int soLingerTime) {
373 this.soLingerTime = Integer.valueOf(soLingerTime);
374 }
375
376 public void setSoKeepAlive(boolean soKeepAlive) {
377 this.soKeepAlive = Boolean.valueOf(soKeepAlive);
378 }
379
380 public void setRxBufSize(int rxBufSize) {
381 this.rxBufSize = Integer.valueOf(rxBufSize);
382 }
383
384 public void setPerformanceLatency(int performanceLatency) {
385 this.performanceLatency = Integer.valueOf(performanceLatency);
386 }
387
388 public void setPerformanceBandwidth(int performanceBandwidth) {
389 this.performanceBandwidth = Integer.valueOf(performanceBandwidth);
390 }
391
392 public void setOoBInline(boolean ooBInline) {
393 this.ooBInline = Boolean.valueOf(ooBInline);
394 }
395
396 public void setDirectBuffer(boolean directBuffer) {
397 this.directBuffer = directBuffer;
398 }
399
400 public void setDirectSslBuffer(boolean directSslBuffer) {
401 this.directSslBuffer = directSslBuffer;
402 }
403
404 public void setSoLingerOn(boolean soLingerOn) {
405 this.soLingerOn = Boolean.valueOf(soLingerOn);
406 }
407
408 public void setBufferPool(int bufferPool) {
409 this.bufferPool = bufferPool;
410 }
411
412 public void setBufferPoolSize(int bufferPoolSize) {
413 this.bufferPoolSize = bufferPoolSize;
414 }
415
416 public void setEventCache(int eventCache) {
417 this.eventCache = eventCache;
418 }
419
420 public void setAppReadBufSize(int appReadBufSize) {
421 this.appReadBufSize = appReadBufSize;
422 }
423
424 public void setAppWriteBufSize(int appWriteBufSize) {
425 this.appWriteBufSize = appWriteBufSize;
426 }
427
428 public void setProcessorCache(int processorCache) {
429 this.processorCache = processorCache;
430 }
431
432 public void setTimeoutInterval(long timeoutInterval) {
433 this.timeoutInterval = timeoutInterval;
434 }
435
436 public void setDirectBufferPool(int directBufferPool) {
437 this.bufferPool = directBufferPool;
438 }
439
440 public int getUnlockTimeout() {
441 return unlockTimeout;
442 }
443
444 public void setUnlockTimeout(int unlockTimeout) {
445 this.unlockTimeout = unlockTimeout;
446 }
447
448 void setObjectName(ObjectName oname) {
449 this.oname = oname;
450 }
451
452 ObjectName getObjectName() {
453 return oname;
454 }
455 }
456