refactoring

This commit is contained in:
rusefi 2020-06-07 13:31:49 -04:00
parent 74d6791b31
commit 2310368be9
2 changed files with 16 additions and 19 deletions

View File

@ -1,31 +1,26 @@
package com.rusefi.io;
import com.rusefi.FileLog;
import com.rusefi.Timeouts;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* todo: open question if it's OK to use AWT timer in headless cases?
*/
public class ConnectionWatchdog {
private static final Timer reconnectTimer = new Timer(Timeouts.CONNECTION_RESTART_DELAY, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting");
LinkManager.restart();
onDataArrived();
}
});
private final Timer reconnectTimer;
private ConnectionWatchdog() {
public ConnectionWatchdog(int timeoutMs, Runnable action) {
reconnectTimer = new Timer(timeoutMs, e -> {
action.run();
onDataArrived();
});
}
public static void start() {
HeartBeatListeners.INSTANCE.addListener(ConnectionWatchdog::onDataArrived);
public void start() {
HeartBeatListeners.INSTANCE.addListener(this::onDataArrived);
onDataArrived();
}
private static void onDataArrived() {
private void onDataArrived() {
/**
* this timer will reconnect
*/

View File

@ -84,8 +84,10 @@ public class Launcher extends rusEFIVersion {
if (LinkManager.isLogViewerMode(port))
tabbedPane.addTab("Log Viewer", new LogViewer(engineSnifferPanel));
ConnectionWatchdog.start();
new ConnectionWatchdog(Timeouts.CONNECTION_RESTART_DELAY, () -> {
FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting");
LinkManager.restart();
}).start();
GaugesPanel.DetachedRepository.INSTANCE.init(getConfig().getRoot().getChild("detached"));
GaugesPanel.DetachedRepository.INSTANCE.load();