diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulator.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulator.java index 32b941a21c..ce2a914349 100644 --- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulator.java +++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulator.java @@ -20,18 +20,24 @@ import org.apache.streampipes.commons.exceptions.connect.AdapterException; import org.apache.streampipes.extensions.api.connect.IEventCollector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; public class MachineDataSimulator implements Runnable { - private IEventCollector collector; + private final IEventCollector collector; private final Integer waitTimeMs; private final String selectedSimulatorOption; private Boolean running; + private static final Logger LOG = LoggerFactory.getLogger(MachineDataSimulator.class); + public MachineDataSimulator(IEventCollector collector, Integer waitTimeMs, String selectedSimulatorOption) { @@ -44,10 +50,10 @@ public MachineDataSimulator(IEventCollector collector, @Override public void run() { this.running = true; - Map event = new HashMap<>(); long startTimeMs = System.currentTimeMillis(); while (running) { + Map event = new HashMap<>(); long currentTimeMs = System.currentTimeMillis(); long timeDeltaMs = currentTimeMs - startTimeMs; @@ -95,18 +101,18 @@ public void run() { try { throw new AdapterException("resource not found"); } catch (AdapterException e) { - e.printStackTrace(); + throw new RuntimeException(e); } } - if (event.keySet().size() > 0) { + if (!event.keySet().isEmpty()) { collector.collect(event); } try { - Thread.sleep(waitTimeMs); + TimeUnit.MILLISECONDS.sleep(waitTimeMs); } catch (InterruptedException e) { - e.printStackTrace(); + LOG.error("Machine simulator thread interrupted", e); } } }