Stop some of the threads on frame destroy

Kill the main frame on plugin exit
This commit is contained in:
zzz
2022-01-12 07:25:07 -05:00
parent e62edc04ad
commit c3ad937523
10 changed files with 92 additions and 9 deletions

View File

@ -46,6 +46,7 @@ public class OverviewTab extends TabLogoPanel {
private final MultiLineLabel lblNetworkStatusSpecified; private final MultiLineLabel lblNetworkStatusSpecified;
private final BandwidthChart bwChart; private final BandwidthChart bwChart;
private final ParticipatingTunnelsChart partTunnelChart; private final ParticipatingTunnelsChart partTunnelChart;
private volatile boolean running;
public OverviewTab(String imageName, ConfigurationManager conf) { public OverviewTab(String imageName, ConfigurationManager conf) {
super(imageName); super(imageName);
@ -134,19 +135,33 @@ public class OverviewTab extends TabLogoPanel {
final int updateInterval = _conf.getConf("overview.info.updateinterval", DEFAULT_INFO_UPDATE_INTERVAL); final int updateInterval = _conf.getConf("overview.info.updateinterval", DEFAULT_INFO_UPDATE_INTERVAL);
(new Thread(){ (new Thread("IToopie-OT"){
@Override @Override
public void run() { public void run() {
while (true) { running = true;
while (running) {
populateInfo(); populateInfo();
try { try {
Thread.sleep(updateInterval); Thread.sleep(updateInterval);
} catch (Exception e){} // Never stop. } catch (InterruptedException e) {
break;
}
} }
} }
}).start(); }).start();
} }
/**
* @since 0.0.4
*/
@Override
public void removeNotify() {
running = false;
bwChart.destroy();
partTunnelChart.destroy();
super.removeNotify();
}
/** /**
* @since 0.0.4 * @since 0.0.4
*/ */

View File

@ -35,6 +35,7 @@ public class TrayManager {
protected TrayIcon trayIcon; protected TrayIcon trayIcon;
private final net.i2p.itoopie.Main main; private final net.i2p.itoopie.Main main;
private final ConfigurationManager _conf; private final ConfigurationManager _conf;
private WindowHandler _wh;
/** /**
* Instantiate tray manager. * Instantiate tray manager.
@ -49,6 +50,7 @@ public class TrayManager {
*/ */
public synchronized void startManager() { public synchronized void startManager() {
final WindowHandler windowHandler = new WindowHandler(_conf); final WindowHandler windowHandler = new WindowHandler(_conf);
_wh = windowHandler;
windowHandler.toggleFrames(); windowHandler.toggleFrames();
// so the tray icon works right on Gnome // so the tray icon works right on Gnome
try { Thread.sleep(500); } catch (InterruptedException ie) {} try { Thread.sleep(500); } catch (InterruptedException ie) {}
@ -85,6 +87,8 @@ public class TrayManager {
trayIcon = null; trayIcon = null;
} }
} catch (Exception e) {} } catch (Exception e) {}
if (_wh != null)
_wh.destroyMain();
} }
protected void languageChanged() { protected void languageChanged() {

View File

@ -25,6 +25,14 @@ public class WindowHandler {
mainFrame = frame; mainFrame = frame;
} }
public void destroyMain() {
if (mainFrame != null) {
mainFrame.dispose();
_frames.remove(mainFrame);
mainFrame = null;
}
}
public void deRegister(JFrame frame){ public void deRegister(JFrame frame){
// don't remove the main frame when // don't remove the main frame when
// the user clicks on the X, so we have the updated // the user clicks on the X, so we have the updated

View File

@ -89,6 +89,15 @@ public class BandwidthChart extends Chart2D{
bwInAdapter = new ObjRecorder2Trace2DAdapter(dataBWIn, bwInTracker, "m_value", updateInterval/2); bwInAdapter = new ObjRecorder2Trace2DAdapter(dataBWIn, bwInTracker, "m_value", updateInterval/2);
bwOutAdapter = new ObjRecorder2Trace2DAdapter(dataBWOut, bwOutTracker, "m_value", updateInterval/2); bwOutAdapter = new ObjRecorder2Trace2DAdapter(dataBWOut, bwOutTracker, "m_value", updateInterval/2);
} }
@Override
public void destroy() {
bwInTracker.kill();
bwOutTracker.kill();
bwInAdapter.kill();
bwOutAdapter.kill();
super.destroy();
}
/* /*
public static void main(final String[] args) { public static void main(final String[] args) {

View File

@ -75,7 +75,14 @@ public class ParticipatingTunnelsChart extends Chart2D {
partTunnelTracker = new ParticipatingTunnelsTracker(updateInterval); partTunnelTracker = new ParticipatingTunnelsTracker(updateInterval);
partTunnelAdapter = new ObjRecorder2Trace2DAdapter(dataPartTunnels, partTunnelTracker, "m_value", updateInterval/2); partTunnelAdapter = new ObjRecorder2Trace2DAdapter(dataPartTunnels, partTunnelTracker, "m_value", updateInterval/2);
} }
@Override
public void destroy() {
partTunnelTracker.kill();
partTunnelAdapter.kill();
super.destroy();
}
/* /*
public static void main(final String[] args) { public static void main(final String[] args) {
JFrame frame = new JFrame(); JFrame frame = new JFrame();

View File

@ -16,6 +16,7 @@ public class InboundBandwidthTracker extends Thread implements Tracker {
/** Last read bw */ /** Last read bw */
private double m_value = 0; private double m_value = 0;
private final int updateInterval; private final int updateInterval;
private volatile boolean running;
/** /**
* Start daemon that checks to current inbound bandwidth of the router. * Start daemon that checks to current inbound bandwidth of the router.
@ -33,7 +34,8 @@ public class InboundBandwidthTracker extends Thread implements Tracker {
@Override @Override
public void run() { public void run() {
while (true) { running = true;
while (running) {
runOnce(); runOnce();
try { try {
@ -57,6 +59,14 @@ public class InboundBandwidthTracker extends Thread implements Tracker {
} }
} }
/**
* @since 0.0.4
*/
public void kill() {
running = false;
interrupt();
}
/** /**
* @since 0.0.4 * @since 0.0.4
*/ */

View File

@ -159,4 +159,8 @@ public class ObjRecorder2Trace2DAdapter implements ChangeListener {
this.m_view.addPoint(tmpx, tmpy); this.m_view.addPoint(tmpx, tmpy);
} }
} }
public void kill() {
m_inspector.kill();
}
} }

View File

@ -142,6 +142,7 @@ public class ObjectRecorder extends Thread {
/** The instance to inspect. */ /** The instance to inspect. */
protected Tracker m_toinspect; protected Tracker m_toinspect;
private volatile boolean running;
/** /**
* Creates an instance that will inspect the given Object in the given time * Creates an instance that will inspect the given Object in the given time
@ -353,7 +354,8 @@ public class ObjectRecorder extends Thread {
*/ */
@Override @Override
public void run() { public void run() {
while (true) { running = true;
while (running) {
try { try {
Thread.sleep(this.m_interval); Thread.sleep(this.m_interval);
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
@ -363,6 +365,11 @@ public class ObjectRecorder extends Thread {
} }
} }
public void kill() {
running = false;
interrupt();
}
/** /**
* Define the amount of recorded states of the Object to inspect that remain * Define the amount of recorded states of the Object to inspect that remain
* in memory. * in memory.

View File

@ -16,6 +16,7 @@ public class OutboundBandwidthTracker extends Thread implements Tracker {
/** Last read bw */ /** Last read bw */
private double m_value = 0; private double m_value = 0;
private final int updateInterval; private final int updateInterval;
private volatile boolean running;
/** /**
* Start daemon that checks to current inbound bandwidth of the router. * Start daemon that checks to current inbound bandwidth of the router.
@ -32,8 +33,8 @@ public class OutboundBandwidthTracker extends Thread implements Tracker {
*/ */
@Override @Override
public void run() { public void run() {
running = true;
while (true) { while (running) {
runOnce(); runOnce();
try { try {
@ -57,6 +58,14 @@ public class OutboundBandwidthTracker extends Thread implements Tracker {
} }
} }
/**
* @since 0.0.4
*/
public void kill() {
running = false;
interrupt();
}
/** /**
* @since 0.0.4 * @since 0.0.4
*/ */

View File

@ -17,6 +17,7 @@ public class ParticipatingTunnelsTracker extends Thread implements Tracker {
/** Last read bw */ /** Last read bw */
private double m_value = 0; private double m_value = 0;
private final int updateInterval; private final int updateInterval;
private volatile boolean running;
/** /**
* Start daemon that checks to current inbound bandwidth of the router. * Start daemon that checks to current inbound bandwidth of the router.
@ -33,7 +34,8 @@ public class ParticipatingTunnelsTracker extends Thread implements Tracker {
*/ */
@Override @Override
public void run() { public void run() {
while (true) { running = true;
while (running) {
runOnce(); runOnce();
try { try {
@ -57,6 +59,14 @@ public class ParticipatingTunnelsTracker extends Thread implements Tracker {
} }
} }
/**
* @since 0.0.4
*/
public void kill() {
running = false;
interrupt();
}
/** /**
* @since 0.0.4 * @since 0.0.4
*/ */