Changes to linger to be an Integer named lingerTime

Changes to the pom, new 3.1.0-SNAPSHOT version
RAD-1600
pull/49/head
Benjamin Perez 4 years ago
parent bb770c1d0c
commit 30b3e931b2

@ -1,3 +1,11 @@
*Release notes for 3.1.0*
* Remove the retries on openConnection()
* Add the lingerTime to one of the constructors on TcpMaster and set it into the socket connection.
* The lingerTime will be an Integer representing seconds and any negative or null value will disable it.
* SO_LINGER will be set in the socket connection and will only affect on close connection
* Factory method added to account for lingerTime
* Remove the no longer used RETRY_PAUSE_ fields from TcpMaster
*Release notes for 3.0.6*
* Add ability to validate slave ID in responses. Defaults to enabled for Ascii, RTU and Encapsulated TCP, disabled for Tcp and Udp
* Add retry to serial connections if the connection is broken try to re-open the serial port retries number of times

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.infiniteautomation</groupId>
<artifactId>modbus4j</artifactId>
<version>3.0.6-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<name>Modbus4j Library</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -108,4 +108,4 @@
<url>https://maven.mangoautomation.net/repository/ias-release/</url>
</repository>
</distributionManagement>
</project>
</project>

@ -67,9 +67,6 @@ abstract public class ModbusMaster extends Modbus {
private int timeout = 500;
private int retries = 2;
//default linger to -1 (disabled)
private int lingerTime = 5;
/**
* Should we validate the responses:
* - ensure that the requested slave id is what is in the response
@ -600,21 +597,5 @@ abstract public class ModbusMaster extends Modbus {
return sp;
}
/**
* <p>Getter for the field <code>linger</code>.</p>
*
* @return an int.
*/
public int getLingerTime() {
return lingerTime;
}
/**
* <p>Setter for the field <code>linger</code>.</p>
*
* @param lingerTime an int.
*/
public void setLingerTime(int lingerTime) {
this.lingerTime = lingerTime;
}
}

@ -56,8 +56,6 @@ import com.serotonin.modbus4j.sero.messaging.WaitingRoomKeyFactory;
* @version 5.0.0
*/
public class TcpMaster extends ModbusMaster {
private static final int RETRY_PAUSE_START = 50;
private static final int RETRY_PAUSE_MAX = 1000;
// Configuration fields.
private final Log LOG = LogFactory.getLog(TcpMaster.class);
@ -65,12 +63,14 @@ public class TcpMaster extends ModbusMaster {
private final IpParameters ipParameters;
private final boolean keepAlive;
private final boolean autoIncrementTransactionId;
private final Integer lingerTime;
// Runtime fields.
private Socket socket;
private Transport transport;
private MessageControl conn;
/**
* <p>Constructor for TcpMaster.</p>
*
@ -78,37 +78,72 @@ public class TcpMaster extends ModbusMaster {
* @param keepAlive
* @param autoIncrementTransactionId
* @param validateResponse - confirm that requested slave id is the same in the response
* @param lingerTime The setting only affects socket close.
*/
public TcpMaster(IpParameters params, boolean keepAlive, boolean autoIncrementTransactionId, boolean validateResponse) {
public TcpMaster(IpParameters params, boolean keepAlive, boolean autoIncrementTransactionId, boolean validateResponse, Integer lingerTime) {
this.ipParameters = params;
this.keepAlive = keepAlive;
this.autoIncrementTransactionId = autoIncrementTransactionId;
this.lingerTime = lingerTime;
}
/**
* <p>Constructor for TcpMaster.</p>
*
* Default to lingerTime disabled
*
* @param params
* @param keepAlive
* @param autoIncrementTransactionId
* @param validateResponse - confirm that requested slave id is the same in the response
*/
public TcpMaster(IpParameters params, boolean keepAlive, boolean autoIncrementTransactionId, boolean validateResponse) {
this(params, keepAlive, autoIncrementTransactionId, validateResponse, -1);
//this.ipParameters = params;
//this.keepAlive = keepAlive;
//this.autoIncrementTransactionId = autoIncrementTransactionId;
}
/**
* <p>Constructor for TcpMaster.</p>
* Default to not validating the slave id in responses
* Default to lingerTime disabled
*
* @param params a {@link com.serotonin.modbus4j.ip.IpParameters} object.
* @param keepAlive a boolean.
* @param autoIncrementTransactionId a boolean.
*/
public TcpMaster(IpParameters params, boolean keepAlive, boolean autoIncrementTransactionId) {
this(params, keepAlive, autoIncrementTransactionId, false);
this(params, keepAlive, autoIncrementTransactionId, false, -1);
}
/**
* <p>Constructor for TcpMaster.</p>
*
* Default to auto increment transaction id
* Default to not validating the slave id in responses
* Default to lingerTime disabled
*
* @param params a {@link com.serotonin.modbus4j.ip.IpParameters} object.
* @param keepAlive a boolean.
* @param lingerTime an Integer. The setting only affects socket close.
*/
public TcpMaster(IpParameters params, boolean keepAlive,Integer lingerTime) {
this(params, keepAlive, true, false, lingerTime);
}
/**
* <p>Constructor for TcpMaster.</p>
*
* Default to auto increment transaction id
* Default to not validating the slave id in responses
* Default to lingerTime disabled
*
* @param params a {@link com.serotonin.modbus4j.ip.IpParameters} object.
* @param keepAlive a boolean.
*/
public TcpMaster(IpParameters params, boolean keepAlive) {
this(params, keepAlive, true, false);
this(params, keepAlive, true, false,-1);
}
/**
@ -256,14 +291,14 @@ public class TcpMaster extends ModbusMaster {
// Make sure any existing connection is closed.
closeConnection();
int linger = getLingerTime();
Integer soLinger = getLingerTime();
socket = new Socket();
socket.setSoTimeout(getTimeout());
if(linger < 0)
if(soLinger == null || soLinger < 0)//any null or negative will disable SO_Linger
socket.setSoLinger(false, 0);
else
socket.setSoLinger(true, linger);
socket.setSoLinger(true, soLinger);
socket.connect(new InetSocketAddress(ipParameters.getHost(), ipParameters.getPort()), getTimeout());
if (getePoll() != null)
transport = new EpollStreamTransport(socket.getInputStream(), socket.getOutputStream(), getePoll());
@ -300,4 +335,14 @@ public class TcpMaster extends ModbusMaster {
conn = null;
socket = null;
}
/**
* <p>Getter for the field <code>lingerTime</code>.</p>
*
* @return an Integer.
*/
public Integer getLingerTime() {
return lingerTime;
}
}

Loading…
Cancel
Save