01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.net.core;
06:
07: import com.tc.logging.TCLogger;
08: import com.tc.logging.TCLogging;
09: import com.tc.properties.TCProperties;
10: import com.tc.properties.TCPropertiesImpl;
11:
12: import java.net.Socket;
13: import java.net.SocketException;
14:
15: /**
16: * Nothing particularly fancy, just a common place that defines the socket options we set for our connections
17: */
18: class SocketParams {
19: private static final TCLogger logger = TCLogging
20: .getLogger(SocketParams.class);
21:
22: private static final String PREFIX = "net.core";
23: private static final String RECV_BUFFER = "recv.buffer";
24: private static final String SEND_BUFFER = "send.buffer";
25: private static final String TCP_NO_DELAY = "tcpnodelay";
26: private static final String KEEP_ALIVE = "keepalive";
27:
28: private final int recvBuffer;
29: private final int sendBuffer;
30: private final boolean tcpNoDelay;
31: private final boolean keepAlive;
32:
33: SocketParams() {
34: TCProperties props = TCPropertiesImpl.getProperties()
35: .getPropertiesFor(PREFIX);
36:
37: this .recvBuffer = props.getInt(RECV_BUFFER);
38: this .sendBuffer = props.getInt(SEND_BUFFER);
39: this .keepAlive = props.getBoolean(KEEP_ALIVE);
40: this .tcpNoDelay = props.getBoolean(TCP_NO_DELAY);
41:
42: }
43:
44: void applySocketParams(Socket s) {
45: try {
46: s.setSendBufferSize(sendBuffer);
47: } catch (SocketException e) {
48: logger
49: .error("error setting sendBuffer to " + sendBuffer,
50: e);
51: }
52:
53: try {
54: s.setReceiveBufferSize(recvBuffer);
55: } catch (SocketException e) {
56: logger
57: .error("error setting recvBuffer to " + recvBuffer,
58: e);
59: }
60:
61: try {
62: s.setTcpNoDelay(tcpNoDelay);
63: } catch (SocketException e) {
64: logger
65: .error("error setting TcpNoDelay to " + tcpNoDelay,
66: e);
67: }
68:
69: try {
70: s.setKeepAlive(keepAlive);
71: } catch (SocketException e) {
72: logger.error("error setting KeepAlive to " + keepAlive, e);
73: }
74: }
75:
76: }
|