diff --git a/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java b/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java index 9c5d4f37ed..ba640194f3 100644 --- a/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java +++ b/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java @@ -171,12 +171,16 @@ public class MLabRunner { String[] args = useSSL ? new String[] { "-s", server_host } : new String[] { server_host }; long start = System.currentTimeMillis(); final Tcpbw100 test = Tcpbw100.mainSupport(args); + final AtomicBoolean cancelled = new AtomicBoolean(); run.addListener( new ToolRunListener() { public void cancelled() { + cancelled.set(true); + _log.warn("TRL cancelling test"); test.killIt(); + _log.warn("TRL cancelled test"); } public String getStatus() { @@ -188,7 +192,7 @@ public class MLabRunner { try { Thread.sleep(2000); } catch (InterruptedException ie) { return; } for (int i = 0; i < 180; i++) { - if (!test.isTestInProgress()) + if (cancelled.get() || !test.isTestInProgress()) break; try { Thread.sleep(1000); } catch (InterruptedException ie) { break; } } @@ -206,7 +210,9 @@ public class MLabRunner { } catch(Throwable e) {} String result_str; - if (up_bps == 0 || down_bps == 0) { + if (cancelled.get()) { + result_str = "Test cancelled"; + } else if (up_bps == 0 || down_bps == 0) { result_str = "No results were received. Either the test server is unavailable or network problems are preventing the test from running correctly. Please try again."; } else { result_str = diff --git a/apps/routerconsole/java/src/edu/internet2/ndt/StatusPanel.java b/apps/routerconsole/java/src/edu/internet2/ndt/StatusPanel.java index a9f9b63256..77add0d8b0 100644 --- a/apps/routerconsole/java/src/edu/internet2/ndt/StatusPanel.java +++ b/apps/routerconsole/java/src/edu/internet2/ndt/StatusPanel.java @@ -96,19 +96,16 @@ public class StatusPanel extends JPanel { * * @return boolean indicating intention to stop or not * */ - public boolean wantToStop() { + public synchronized boolean wantToStop() { return _bStop; } /** * End the currently running test + * Cannot be restarted. * */ - public void endTest() { -/**** - _progressBarObj.setValue(_iTestsCompleted); - _iTestsCompleted++; - setTestNoLabelText(); -****/ + public synchronized void endTest() { + _bStop = true; } /** diff --git a/apps/routerconsole/java/src/edu/internet2/ndt/Tcpbw100.java b/apps/routerconsole/java/src/edu/internet2/ndt/Tcpbw100.java index bda625305c..6812fa6e2c 100644 --- a/apps/routerconsole/java/src/edu/internet2/ndt/Tcpbw100.java +++ b/apps/routerconsole/java/src/edu/internet2/ndt/Tcpbw100.java @@ -301,6 +301,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { private final Log _log = _context.logManager().getLog(Tcpbw100.class); private final boolean _useSSL; private final I2PSSLSocketFactory _sslFactory; + private StatusPanel _sPanel; public Tcpbw100(boolean useSSL) { super(); @@ -652,6 +653,9 @@ public class Tcpbw100 extends JApplet implements ActionListener { // number of tests StatusPanel sPanel = new StatusPanel(testsNum, sTempEnable); + synchronized (Tcpbw100.this) { + _sPanel = sPanel; + } getContentPane().add(BorderLayout.NORTH, sPanel); getContentPane().validate(); getContentPane().repaint(); @@ -659,6 +663,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { try { while (true) { if (sPanel.wantToStop()) { + _log.warn("cancelled"); break; } if (testsNum == 0) { @@ -681,6 +686,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { } // If user stops the test, quit if (sPanel.wantToStop()) { + _log.warn("cancelled"); break; } sPanel.setText(""); @@ -2846,6 +2852,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { _sErrMsg = "\n" + _resBundDisplayMsgs.getString("stopped") + "\n"; _bFailed = true; + _log.warn(_sErrMsg); return; } int testId = Integer.parseInt(tokenizer.nextToken()); @@ -2915,6 +2922,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { ctlSocket.close(); _sErrMsg = _resBundDisplayMsgs.getString("stopped") + "\n"; _bFailed = true; + _log.warn(_sErrMsg); return; } @@ -4505,24 +4513,60 @@ public class Tcpbw100 extends JApplet implements ActionListener { } /** bigly */ - private ThreadGroup thread_group; + private ThreadGroup _thread_group; - /** bigly */ + /** + * bigly -- must have been started with main() or runIt() + */ + @SuppressWarnings("deprecation") public void killIt() { - while( !thread_group.isDestroyed()){ + final ThreadGroup thread_group; + synchronized(this) { + thread_group = _thread_group; + if (thread_group == null) { + _log.warn("No thread group to kill"); + return; + } + // so wantToStop() returns true + if (_sPanel != null) + _sPanel.endTest(); + } + _log.warn("killIt()"); + boolean destroyed = false; + for (int j = 0; j < 10 && !thread_group.isDestroyed(); j++) { Thread[] threads = new Thread[thread_group.activeCount()]; thread_group.enumerate( threads ); int done = 0; for ( int i=0;i<%=intl._t("Test server location")%><%=wizhelper.getServerLocation()%> <%=intl._t("Completion status")%><%=wizhelper.getCompletionStatus()%> <%=intl._t("Details")%><%=wizhelper.getDetailStatus()%> +<% + if (wizhelper.isNDTSuccessful()) { + // don't display this if test failed +%> <%=intl._t("Downstream Bandwidth")%><%=net.i2p.data.DataHelper.formatSize2Decimal(wizhelper.getDownBandwidth())%>Bps <%=intl._t("Upstream Bandwidth")%><%=net.i2p.data.DataHelper.formatSize2Decimal(wizhelper.getUpBandwidth())%>Bps <%=intl._t("Share of Bandwidth for I2P")%><%=Math.round(net.i2p.router.web.helpers.WizardHelper.BW_SCALE * 100)%>% +<% + } // sucessful +%> <% } // skipbw