package org.openkilda.floodlight.kafka;

import org.openkilda.messaging.Topic;

import java.util.Timer;
import java.util.TimerTask;

public class HeartBeat {
    private static final String topic = Topic.TOPO_DISCO;

    private final Producer producer;
    private final long interval;

    private final Timer timer;
    private TimerTask task;

    public HeartBeat(Producer producer, long interval) {
        this.producer = producer;
        this.interval = interval;

        task = new HeartBeatAction(producer, topic);
        timer = new Timer("kafka.HeartBeat",true);
        timer.scheduleAtFixedRate(task, interval, interval);
    }

    public void reschedule() {
        TimerTask replace = new HeartBeatAction(producer, topic);
        timer.scheduleAtFixedRate(replace, interval, interval);

        task.cancel();
        task = replace;
    }
}

@@ -801,16 +801,50 @@
 rval);%0A%0A
+        synchronized (this) %7B%0A    
         
@@ -862,24 +862,28 @@
 ();%0A        
+  
+  
 task = repla
@@ -886,16 +886,26 @@
 eplace;%0A
+        %7D%0A
     %7D%0A%7D%0A

Fix HeartBeat scheduling