Skip to content

Commit f8f6879

Browse files
authored
Merge pull request #875 from BLasan/5.3.x
Feat: Add Socket Timeout
2 parents b753f1b + e75db8c commit f8f6879

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

components/data-bridge/org.wso2.carbon.databridge.receiver.binary/src/main/java/org/wso2/carbon/databridge/receiver/binary/BinaryDataReceiverConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ private BinaryDataReceiverConstants(){
3232
public static final int DEFAULT_TCP_RECEIVER_THREAD_POOL_SIZE = 100;
3333
public static final int DEFAULT_SSL_RECEIVER_PORT = 9611;
3434
public static final int DEFAULT_TCP_RECEIVER_PORT = 9711;
35+
public static final String SOCKET_TIMEOUT = "socketTimeout";
36+
public static final int DEFAULT_SOCKET_TIMEOUT = 0;
3537
public static final String DATA_BRIDGE_RECEIVER_CONFIG_NAME = "Binary";
3638
public static final String SSL_RECEIVER_PORT_CONFIG_NAME = "sslPort";
3739
public static final String TCP_RECEIVER_PORT_CONFIG_NAME = "tcpPort";

components/data-bridge/org.wso2.carbon.databridge.receiver.binary/src/main/java/org/wso2/carbon/databridge/receiver/binary/conf/BinaryDataReceiverConfiguration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class BinaryDataReceiverConfiguration {
3535
private String sslProtocols;
3636
private String ciphers;
3737

38+
private int socketTimeout;
39+
3840
public BinaryDataReceiverConfiguration(int sslPort, int tcpPort) {
3941
this.sslPort = sslPort;
4042
this.tcpPort = tcpPort;
@@ -61,6 +63,11 @@ public BinaryDataReceiverConfiguration(DataBridgeConfiguration dataBridgeConfigu
6163
sslProtocols = sslProtocolObj != null ? sslProtocolObj.toString() : null;
6264
Object ciphersObj = dataReceiver.getConfiguration(BinaryDataReceiverConstants.SSL_RECEIVER_CIPHERS_CONFIG_NAME, null);
6365
ciphers = sslProtocolObj != null ? ciphersObj.toString() : null;
66+
this.socketTimeout = Integer.parseInt(dataReceiver.getConfiguration(BinaryDataReceiverConstants.SOCKET_TIMEOUT,
67+
BinaryDataReceiverConstants.DEFAULT_SOCKET_TIMEOUT).toString());
68+
if (this.socketTimeout < 0) {
69+
this.socketTimeout = BinaryDataReceiverConstants.DEFAULT_SOCKET_TIMEOUT;
70+
}
6471
}
6572

6673
public int getSSLPort() {
@@ -95,4 +102,7 @@ public boolean isEnable() {
95102

96103
return enable;
97104
}
105+
public int getSocketTimeout() {
106+
return socketTimeout;
107+
}
98108
}

components/data-bridge/org.wso2.carbon.databridge.receiver.binary/src/main/java/org/wso2/carbon/databridge/receiver/binary/internal/BinaryDataReceiver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public void run() {
212212
while (true) {
213213
try {
214214
Socket socket = this.serverSocket.accept();
215+
socket.setSoTimeout(binaryDataReceiverConfiguration.getSocketTimeout());
215216
sslReceiverExecutorService.submit(new BinaryTransportReceiver(socket));
216217
} catch (IOException e) {
217218
log.error("Error while accepting the connection. ", e);
@@ -232,6 +233,7 @@ public void run() {
232233
while (true) {
233234
try {
234235
Socket socket = this.serverSocket.accept();
236+
socket.setSoTimeout(binaryDataReceiverConfiguration.getSocketTimeout());
235237
tcpReceiverExecutorService.submit(new BinaryTransportReceiver(socket));
236238
} catch (IOException e) {
237239
log.error("Error while accepting the connection. ", e);

0 commit comments

Comments
 (0)