Stop some of the threads on frame destroy
Kill the main frame on plugin exit
This commit is contained in:
@ -46,6 +46,7 @@ public class OverviewTab extends TabLogoPanel {
|
||||
private final MultiLineLabel lblNetworkStatusSpecified;
|
||||
private final BandwidthChart bwChart;
|
||||
private final ParticipatingTunnelsChart partTunnelChart;
|
||||
private volatile boolean running;
|
||||
|
||||
public OverviewTab(String imageName, ConfigurationManager conf) {
|
||||
super(imageName);
|
||||
@ -134,19 +135,33 @@ public class OverviewTab extends TabLogoPanel {
|
||||
|
||||
final int updateInterval = _conf.getConf("overview.info.updateinterval", DEFAULT_INFO_UPDATE_INTERVAL);
|
||||
|
||||
(new Thread(){
|
||||
(new Thread("IToopie-OT"){
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
running = true;
|
||||
while (running) {
|
||||
populateInfo();
|
||||
try {
|
||||
Thread.sleep(updateInterval);
|
||||
} catch (Exception e){} // Never stop.
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.0.4
|
||||
*/
|
||||
@Override
|
||||
public void removeNotify() {
|
||||
running = false;
|
||||
bwChart.destroy();
|
||||
partTunnelChart.destroy();
|
||||
super.removeNotify();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.0.4
|
||||
*/
|
||||
|
@ -35,6 +35,7 @@ public class TrayManager {
|
||||
protected TrayIcon trayIcon;
|
||||
private final net.i2p.itoopie.Main main;
|
||||
private final ConfigurationManager _conf;
|
||||
private WindowHandler _wh;
|
||||
|
||||
/**
|
||||
* Instantiate tray manager.
|
||||
@ -49,6 +50,7 @@ public class TrayManager {
|
||||
*/
|
||||
public synchronized void startManager() {
|
||||
final WindowHandler windowHandler = new WindowHandler(_conf);
|
||||
_wh = windowHandler;
|
||||
windowHandler.toggleFrames();
|
||||
// so the tray icon works right on Gnome
|
||||
try { Thread.sleep(500); } catch (InterruptedException ie) {}
|
||||
@ -85,6 +87,8 @@ public class TrayManager {
|
||||
trayIcon = null;
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
if (_wh != null)
|
||||
_wh.destroyMain();
|
||||
}
|
||||
|
||||
protected void languageChanged() {
|
||||
|
@ -25,6 +25,14 @@ public class WindowHandler {
|
||||
mainFrame = frame;
|
||||
}
|
||||
|
||||
public void destroyMain() {
|
||||
if (mainFrame != null) {
|
||||
mainFrame.dispose();
|
||||
_frames.remove(mainFrame);
|
||||
mainFrame = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void deRegister(JFrame frame){
|
||||
// don't remove the main frame when
|
||||
// the user clicks on the X, so we have the updated
|
||||
|
@ -90,6 +90,15 @@ public class BandwidthChart extends Chart2D{
|
||||
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) {
|
||||
JFrame frame = new JFrame();
|
||||
|
@ -76,6 +76,13 @@ public class ParticipatingTunnelsChart extends Chart2D {
|
||||
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) {
|
||||
JFrame frame = new JFrame();
|
||||
|
@ -16,6 +16,7 @@ public class InboundBandwidthTracker extends Thread implements Tracker {
|
||||
/** Last read bw */
|
||||
private double m_value = 0;
|
||||
private final int updateInterval;
|
||||
private volatile boolean running;
|
||||
|
||||
/**
|
||||
* Start daemon that checks to current inbound bandwidth of the router.
|
||||
@ -33,7 +34,8 @@ public class InboundBandwidthTracker extends Thread implements Tracker {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
running = true;
|
||||
while (running) {
|
||||
|
||||
runOnce();
|
||||
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
|
||||
*/
|
||||
|
@ -159,4 +159,8 @@ public class ObjRecorder2Trace2DAdapter implements ChangeListener {
|
||||
this.m_view.addPoint(tmpx, tmpy);
|
||||
}
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
m_inspector.kill();
|
||||
}
|
||||
}
|
||||
|
@ -142,6 +142,7 @@ public class ObjectRecorder extends Thread {
|
||||
|
||||
/** The instance to inspect. */
|
||||
protected Tracker m_toinspect;
|
||||
private volatile boolean running;
|
||||
|
||||
/**
|
||||
* Creates an instance that will inspect the given Object in the given time
|
||||
@ -353,7 +354,8 @@ public class ObjectRecorder extends Thread {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
running = true;
|
||||
while (running) {
|
||||
try {
|
||||
Thread.sleep(this.m_interval);
|
||||
} 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
|
||||
* in memory.
|
||||
|
@ -16,6 +16,7 @@ public class OutboundBandwidthTracker extends Thread implements Tracker {
|
||||
/** Last read bw */
|
||||
private double m_value = 0;
|
||||
private final int updateInterval;
|
||||
private volatile boolean running;
|
||||
|
||||
/**
|
||||
* Start daemon that checks to current inbound bandwidth of the router.
|
||||
@ -32,8 +33,8 @@ public class OutboundBandwidthTracker extends Thread implements Tracker {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
running = true;
|
||||
while (running) {
|
||||
|
||||
runOnce();
|
||||
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
|
||||
*/
|
||||
|
@ -17,6 +17,7 @@ public class ParticipatingTunnelsTracker extends Thread implements Tracker {
|
||||
/** Last read bw */
|
||||
private double m_value = 0;
|
||||
private final int updateInterval;
|
||||
private volatile boolean running;
|
||||
|
||||
/**
|
||||
* Start daemon that checks to current inbound bandwidth of the router.
|
||||
@ -33,7 +34,8 @@ public class ParticipatingTunnelsTracker extends Thread implements Tracker {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
running = true;
|
||||
while (running) {
|
||||
|
||||
runOnce();
|
||||
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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user