Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[modbus] Modbus transport API simplification (openhab#7994)
* [modbus] connection closing behaviour finetuned The binding closes TCP/serial connections connections as per user configuration. It is either - every time, immediately after a transaction (reconnectAfterMillis=0) - *after* a read/write transaction, if the connection has been open "too long" (configurable with reconnectAfterMillis) We have an obvious downside to this simple logic -- the connection can remain open "indefinitely" if there are no transactions occurring. With Modbus we are quite often dealing with PLCs and other embedded systems with limited resources, and "reserving" the connection is not always something we want. Previously (2.5.x branch) connections were also closed when - a regular poll task was unregistered (i.e. we stop reading regularly from a modbus server ("slave"). Since most users have regular polling in place, so this ensured that connections do get closed. In this commit, the behaviour is adjusted such that connections are closed when last communication interface pointing to the server/serial port (i.e. "endpoint") is close()'d. With modbus binding this basically means when the tcp or serial thing is removed / disabled, the connections is closed/freed, but only if it is the last thing pointing to that server or serial port. Since modbus.sunspec binding reuses modbus serial & tcp endpoint things, the same note applies for modbus.sunspec binding. This is change in functional behaviour but in a way is logical. We can further introduce to have "delayed"/"deferred"/"debounce" connection closing connections as per the setting reconnectAfterMillis even in situations where communication interface is still open. * [modbus] Check and disconnect idle connections without transactions * [modbus] mvn spotless:apply * [modbubs] Fixed log message * [modbus] Race condition fix The CountDownLatch was used as a guard (latch.await) in many tests to wait for callbacks to be called before proceeding with assertions. Since the latch was countDown() beginning of the callback, we introduced a race condition with the subsequent assertions and updating the other counters used in the subsequent assertions. This commit updates the CountDownLatch as the last step of the callback, resolving the race condition. * [modbus] small test fix * [modbus] readcallback changed to nonnull * [modbus] Refactored ModbusCommunicationInterface to have seperate callback for result and failure However I had to dig deep to reach all the affected parts. Also there is a new callback, and a new "result" type to communicate the failures. * [modbus] SmokeTest refactored to new api * [modbus] Modbus bundle refactored to use the new api * [modbus][sunspec] refactored sunspec bundle to use the new modbus API * [modbus] refactor modbus tests to use the new api * [modbus] Removed ModbusWriteCallback interface from ModbusDataThingHandler Also reset ModbusDataThingHandler testWriteHandling generic to it's original form * [modbus] ModbusDataThingHandler does not implement ModbusReadCallback anymore Instead it has a public onReadResult method. ModbusPollerThingHandler changed to work with ModbusDataThingHandler children. * [modbus] Fixed caching in ModbusPollerThingHandler * [modbus] read modbus data as Optionals * [modbus] toString for PollResult * [modbus] fixed confusing variable name * [modbus] Disallow null callbacks * [modbus] mvn spotless:apply * [modbus] Removing Nullable decorations * [modbus] submitOneTimeWrite simplification * [modbus] Less verbose logging * [modbus] submitOneTimePoll simplification * [modbus] Less verbose logging * [modbus] Many null warnings removed * [modbus] Fix: no need for a @nonnull annotation because it is default * [modbus] Removing unneeded Nullable, using final in immutables * [modbus] Explicit functional interface * [modbus] @nullable and @NonNullByDefault aligned with coding conventions * [modbus] Collections.emptyMap instead of allocating new map every time. Signed-off-by: Sami Salonen <[email protected]> Co-authored-by: Nagy Attila Gábor <[email protected]>
- Loading branch information