100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Minor update to IO client re-connect logic (#735)
Rich Turnere6e5d5317a1b
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.ymlindex 44e150548..49f929ecd 100644--- a/.github/workflows/ci_cd.yml+++ b/.github/workflows/ci_cd.yml@@ -637,6 +637,13 @@ jobs:timeout-minutes: 20#continue-on-error: true+ - name: Archive backend test results+ if: always()+ uses: actions/upload-artifact@v3+ with:+ name: backend-test-results+ path: test/build/reports/tests+- name: Cleanup backend testsif: ${{ steps.test-backend-command.outputs.value != '' && steps.test-ui-command.outputs.value != '' }}run: ${{ steps.run-backend-tests.outputs.cleanup }}diff --git a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.java b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.javaindex 090acce08..5df01c480 100644--- a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.java+++ b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.java@@ -78,7 +78,6 @@ public abstract class AbstractNettyIOClient<T, U extends SocketAddress> implemenpublic static long RECONNECT_DELAY_INITIAL_MILLIS = 1000L;public static long RECONNECT_DELAY_MAX_MILLIS = 5*60000L;- public static long RECONNECT_DELAY_JITTER_MILLIS = 10000L;/*** This is intended to be used at the end of a decoder chain where the previous decoder outputs a {@link ByteBuf};@@ -211,17 +210,15 @@ public abstract class AbstractNettyIOClient<T, U extends SocketAddress> implemenonConnectionStatusChanged(ConnectionStatus.CONNECTING);}- scheduleDoConnect(true);+ scheduleDoConnect(false);}protected void scheduleDoConnect(boolean immediate) {- long jitter = immediate ? 50 : Math.max(50, RECONNECT_DELAY_JITTER_MILLIS);- long delay = immediate ? 50 : Math.max(50, RECONNECT_DELAY_INITIAL_MILLIS);- long maxDelay = immediate ? 51 : Math.max(delay+1, Math.max(50, RECONNECT_DELAY_MAX_MILLIS));+ long delay = immediate ? 50 : Math.max(250, RECONNECT_DELAY_INITIAL_MILLIS);+ long maxDelay = immediate ? 51 : Math.max(delay+1, Math.max(250, RECONNECT_DELAY_MAX_MILLIS));RetryPolicy<Object> retryPolicy = RetryPolicy.builder()- .withJitter(Duration.ofMillis(jitter))- .withDelay(Duration.ofMillis(delay))+ .withJitter(Duration.ofMillis(delay)).withBackoff(Duration.ofMillis(delay), Duration.ofMillis(maxDelay)).handle(RuntimeException.class).onRetryScheduled((execution) ->diff --git a/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.javaindex 5a0b4a008..34352401e 100644--- a/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java@@ -92,9 +92,9 @@ public abstract class AbstractVelbusProtocol<S extends AbstractVelbusProtocol<S,@Overrideprotected void doStop(Container container) throws Exception {if (network != null) {+ network.removeConnectionStatusConsumer(this::setConnectionStatus);network.disconnect();network.close();- network.removeConnectionStatusConsumer(this::setConnectionStatus);}}diff --git a/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusNetwork.java b/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusNetwork.javaindex e8345938f..9fb14024a 100644--- a/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusNetwork.java+++ b/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusNetwork.java@@ -72,8 +72,10 @@ public class VelbusNetwork {}public void sendPackets(VelbusPacket... packets) {- if (getConnectionStatus() != ConnectionStatus.CONNECTED) {- return;+ synchronized (this) {+ if (getConnectionStatus() != ConnectionStatus.CONNECTED) {+ return;+ }}synchronized (messageQueue) {diff --git a/test/src/testFixtures/java/org/openremote/test/TestFixture.java b/test/src/testFixtures/java/org/openremote/test/TestFixture.javaindex 474037888..9c530b28d 100644--- a/test/src/testFixtures/java/org/openremote/test/TestFixture.java+++ b/test/src/testFixtures/java/org/openremote/test/TestFixture.java@@ -51,7 +51,6 @@ public class TestFixture implements IGlobalExtension {public void start() {// Force RECONNECT times to be short to improve test run timesAbstractNettyIOClient.RECONNECT_DELAY_INITIAL_MILLIS = 50;- AbstractNettyIOClient.RECONNECT_DELAY_JITTER_MILLIS = 0;AbstractNettyIOClient.RECONNECT_DELAY_MAX_MILLIS = 50;}