refactoring
This commit is contained in:
parent
74d6791b31
commit
2310368be9
|
@ -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();
|
||||
private final Timer reconnectTimer;
|
||||
|
||||
public ConnectionWatchdog(int timeoutMs, Runnable action) {
|
||||
reconnectTimer = new Timer(timeoutMs, e -> {
|
||||
action.run();
|
||||
onDataArrived();
|
||||
}
|
||||
});
|
||||
|
||||
private ConnectionWatchdog() {
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue