refactoring
This commit is contained in:
parent
74d6791b31
commit
2310368be9
|
@ -1,31 +1,26 @@
|
||||||
package com.rusefi.io;
|
package com.rusefi.io;
|
||||||
|
|
||||||
import com.rusefi.FileLog;
|
|
||||||
import com.rusefi.Timeouts;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
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 {
|
public class ConnectionWatchdog {
|
||||||
private static final Timer reconnectTimer = new Timer(Timeouts.CONNECTION_RESTART_DELAY, new ActionListener() {
|
private final Timer reconnectTimer;
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting");
|
|
||||||
LinkManager.restart();
|
|
||||||
onDataArrived();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
private ConnectionWatchdog() {
|
public ConnectionWatchdog(int timeoutMs, Runnable action) {
|
||||||
|
reconnectTimer = new Timer(timeoutMs, e -> {
|
||||||
|
action.run();
|
||||||
|
onDataArrived();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void start() {
|
public void start() {
|
||||||
HeartBeatListeners.INSTANCE.addListener(ConnectionWatchdog::onDataArrived);
|
HeartBeatListeners.INSTANCE.addListener(this::onDataArrived);
|
||||||
onDataArrived();
|
onDataArrived();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onDataArrived() {
|
private void onDataArrived() {
|
||||||
/**
|
/**
|
||||||
* this timer will reconnect
|
* this timer will reconnect
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -84,8 +84,10 @@ public class Launcher extends rusEFIVersion {
|
||||||
if (LinkManager.isLogViewerMode(port))
|
if (LinkManager.isLogViewerMode(port))
|
||||||
tabbedPane.addTab("Log Viewer", new LogViewer(engineSnifferPanel));
|
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.init(getConfig().getRoot().getChild("detached"));
|
||||||
GaugesPanel.DetachedRepository.INSTANCE.load();
|
GaugesPanel.DetachedRepository.INSTANCE.load();
|
||||||
|
|
Loading…
Reference in New Issue