CachedPlcConnectionManager not closing connections? #1674
-
Hi, Here is a sample which should reproduce the behaviour: public class CachedConnectionTest {
public static void main(String[] args) throws InterruptedException {
var connectionString = "s7://192.168.188.23";
var driverManager = PlcDriverManager.getDefault();
var cachedConnectionManager = CachedPlcConnectionManager
.getBuilder(driverManager.getConnectionManager())
.withMaxLeaseTime(Duration.ofMillis(1000))
.withMaxWaitTime(Duration.ofMillis(1000))
.build();
try (PlcConnection plcConnection = cachedConnectionManager.getConnection(connectionString)) {
var readRequest = plcConnection
.readRequestBuilder()
.addTagAddress("test", "%I0.2:BOOL")
.build();
var response = readRequest.execute().get(5000, TimeUnit.MILLISECONDS);
System.out.printf("Read value: %s%n", response.getBoolean("test"));
} catch (Exception e) {
System.out.printf("Error while reading from PLC with connection string %s%n ", connectionString);
}
for (; ; ) {
TimeUnit.MILLISECONDS.sleep(1000);
}
}
} While the program is running and after the response has arrived, I disconnect from the LAN and PLC4X then continuous to print these messages (roughly every second and indefinitely until I reconnect):
Trace level looks like this., it seems PLC4X is trying to reconnect although the connection should be closed:
I wonder if the connection is not properly closed? Or am I doing something wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Well the Cache doesn't close connections at all. |
Beta Was this translation helpful? Give feedback.
Well the Cache doesn't close connections at all.
the withMaxLeaseTime is the maximum time that a lease is allowed to be used by the borrowing code before the Cache invalidates the handle and passes the connection to the next thread waiting for a connection. The withMaxWaitTime is the maximum amount of time that a thread is willing to wait for a new connection, before the cache cancels the request.