This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 6d8db7b [CAMEL-11947] Possible race condition in iec60870 producer (#3503) 6d8db7b is described below commit 6d8db7b502391085cbdac2973981a21648f9ec38 Author: Thomas Diesler <tdies...@redhat.com> AuthorDate: Tue Jan 21 13:31:28 2020 +0100 [CAMEL-11947] Possible race condition in iec60870 producer (#3503) --- .../iec60870/client/ClientConnection.java | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/client/ClientConnection.java b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/client/ClientConnection.java index ffee89c..a50a679 100644 --- a/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/client/ClientConnection.java +++ b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/client/ClientConnection.java @@ -19,6 +19,8 @@ package org.apache.camel.component.iec60870.client; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import io.netty.channel.ChannelHandlerContext; import org.apache.camel.component.iec60870.DiscardAckModule; @@ -43,13 +45,6 @@ public class ClientConnection { void update(ObjectAddress address, Value<?> value); } - private final StateListener stateListener = new StateListener() { - - @Override - public void stateChanged(final State state, final Throwable e) { - } - }; - private final DataHandler dataHandler = new AbstractDataProcessor() { /** @@ -99,7 +94,19 @@ public class ClientConnection { public void start() { final DataModule dataModule = new DataModule(this.dataHandler, this.options.getDataModuleOptions()); final ModulesFactory factory = () -> Arrays.asList(dataModule, new DiscardAckModule()); - this.client = new AutoConnectClient(this.host, this.port, this.options.getProtocolOptions(), factory, this.stateListener); + final CountDownLatch latch = new CountDownLatch(1); + this.client = new AutoConnectClient(this.host, this.port, this.options.getProtocolOptions(), factory, new StateListener() { + @Override + public void stateChanged(final State state, final Throwable e) { + if (state == State.CONNECTED) + latch.countDown(); + } + }); + try { + latch.await(2000, TimeUnit.MILLISECONDS); + } catch (InterruptedException ex) { + // ignore + } } public void stop() throws Exception {