Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: required
dist: trusty
language: java
jdk:
- oraclejdk8
- openjdk11
addons:
# Fix OpenJDK builds
# https://github.com/travis-ci/travis-ci/issues/5227
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<distributionManagement>
Expand Down Expand Up @@ -100,7 +100,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.7.22</version>
<version>3.6.28</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/graylog2/syslog4j/SyslogConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public interface SyslogConstants extends Serializable {
public static final boolean TCP_SO_LINGER_DEFAULT = true;
public static final int TCP_SO_LINGER_SECONDS_DEFAULT = 1;
public static final boolean TCP_KEEP_ALIVE_DEFAULT = true;
public static final boolean TCP_KEEP_ALIVE_COUNT_DEFAULT = true;
public static final int TCP_KEEP_ALIVE_COUNT_VALUE_DEFAULT = 8;
public static final boolean TCP_KEEP_ALIVE_INTERVAL_DEFAULT = true;
public static final int TCP_KEEP_ALIVE_INTERVAL_SECONDS_DEFAULT = 75;
public static final boolean TCP_KEEP_ALIVE_IDLE_DEFAULT = true;
public static final int TCP_KEEP_ALIVE_IDLE_SECONDS_DEFAULT = 1200;
public static final boolean TCP_REUSE_ADDRESS_DEFAULT = true;
public static final boolean TCP_SET_BUFFER_SIZE_DEFAULT = true;
public static final int TCP_FRESH_CONNECTION_INTERVAL_DEFAULT = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public class TCPNetSyslogConfig extends AbstractNetSyslogConfig implements TCPNe

protected boolean keepAlive = TCP_KEEP_ALIVE_DEFAULT;

protected boolean keepAliveCount = TCP_KEEP_ALIVE_COUNT_DEFAULT;
protected int keepAliveCountValue = TCP_KEEP_ALIVE_COUNT_VALUE_DEFAULT;
protected boolean keepAliveInterval = TCP_KEEP_ALIVE_INTERVAL_DEFAULT;
protected int keepAliveIntervalSeconds = TCP_KEEP_ALIVE_INTERVAL_SECONDS_DEFAULT;
protected boolean keepAliveIdle = TCP_KEEP_ALIVE_IDLE_DEFAULT;
protected int keepAliveIdleSeconds = TCP_KEEP_ALIVE_IDLE_SECONDS_DEFAULT;

protected boolean reuseAddress = TCP_REUSE_ADDRESS_DEFAULT;

protected boolean setBufferSize = TCP_SET_BUFFER_SIZE_DEFAULT;
Expand Down Expand Up @@ -137,6 +144,51 @@ public void setKeepAlive(boolean keepAlive) {
this.keepAlive = keepAlive;
}

@Override
public boolean isKeepAliveCount() {
return this.keepAliveCount;
}

@Override
public void setKeepAliveCountValue(int countValue) {
this.keepAliveCountValue = countValue;
}

@Override
public int getKeepAliveCountValue() {
return this.keepAliveCountValue;
}

@Override
public boolean isKeepAliveInterval() {
return this.keepAliveInterval;
}

@Override
public void setKeepAliveIntervalSeconds(int intervalSeconds) {
this.keepAliveIntervalSeconds = intervalSeconds;
}

@Override
public int getKeepAliveIntervalSeconds() {
return this.keepAliveIntervalSeconds;
}

@Override
public boolean isKeepAliveIdle() {
return this.keepAliveIdle;
}

@Override
public void setKeepAliveIdleSeconds(int idleSeconds) {
this.keepAliveIdleSeconds = idleSeconds;
}

@Override
public int getKeepAliveIdleSeconds() {
return this.keepAliveIdleSeconds;
}

public boolean isReuseAddress() {
return this.reuseAddress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ public interface TCPNetSyslogConfigIF extends AbstractNetSyslogConfigIF {

public void setKeepAlive(boolean keepAlive);

public boolean isKeepAliveCount();

public void setKeepAliveCountValue(int countValue);

public int getKeepAliveCountValue();

public boolean isKeepAliveInterval();

public void setKeepAliveIntervalSeconds(int intervalSeconds);

public int getKeepAliveIntervalSeconds();

public boolean isKeepAliveIdle();

public void setKeepAliveIdleSeconds(int idleSeconds);

public int getKeepAliveIdleSeconds();

public boolean isReuseAddress();

public void setReuseAddress(boolean reuseAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.net.SocketFactory;

import jdk.net.ExtendedSocketOptions;
import org.graylog2.syslog4j.SyslogConstants;
import org.graylog2.syslog4j.SyslogRuntimeException;
import org.graylog2.syslog4j.impl.AbstractSyslog;
Expand Down Expand Up @@ -67,6 +68,18 @@ protected Socket createSocket(InetAddress hostAddress, int port, boolean keepali
newSocket.setKeepAlive(keepalive);
}

if (this.tcpNetSyslogConfig.isKeepAliveCount()) {
newSocket.setOption(ExtendedSocketOptions.TCP_KEEPCOUNT, tcpNetSyslogConfig.getKeepAliveCountValue());
}

if (this.tcpNetSyslogConfig.isKeepAliveInterval()) {
newSocket.setOption(ExtendedSocketOptions.TCP_KEEPINTERVAL,tcpNetSyslogConfig.getKeepAliveIntervalSeconds() );
}

if (this.tcpNetSyslogConfig.isKeepAliveIdle()) {
newSocket.setOption(ExtendedSocketOptions.TCP_KEEPIDLE,tcpNetSyslogConfig.getKeepAliveIdleSeconds() );
}

if (this.tcpNetSyslogConfig.isReuseAddress()) {
newSocket.setReuseAddress(true);
}
Expand Down