예제 #1
0
 private void pause() {
   try {
     Thread.sleep(1000);
   } catch (InterruptedException e) {
     // Error handling goes here...
   }
 }
 @Override
 public void run() {
   try {
     while (true) {
       // Update the data for a while
       Thread.sleep(10000);
       if (!lastPushed.equals(lastMessage)) {
         access(
             () ->
                 chart
                     .getConfiguration()
                     .getSeries()
                     .forEach(
                         s -> {
                           Double newValue = Double.valueOf(lastMessage.split(":")[3]);
                           ((ListSeries) s).updatePoint(0, newValue);
                         }));
         System.out.println("pushed -> lastMessage = " + lastMessage);
         lastPushed = lastMessage;
       }
     }
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
 @Override
 public void run() {
   int connectionDuration = MQTTEventAdapterConstants.INITIAL_RECONNECTION_DURATION;
   while (!connectionSucceeded) {
     try {
       connectionDuration =
           connectionDuration * MQTTEventAdapterConstants.RECONNECTION_PROGRESS_FACTOR;
       Thread.sleep(connectionDuration);
       startListener();
       connectionSucceeded = true;
       log.info("MQTT Connection successful");
     } catch (InterruptedException e) {
       log.error("Interruption occurred while waiting for reconnection", e);
     } catch (MqttException e) {
       log.error("MQTT Exception occurred when starting listener", e);
     }
   }
 }