From d95c284d3eec1075875d463c14757053c4e6da23 Mon Sep 17 00:00:00 2001 From: zzz Date: Tue, 13 Nov 2018 19:20:10 +0000 Subject: [PATCH] MLab/NDT: static instance, log fixes, cleanups --- .../src/com/vuze/plugins/mlab/MLabRunner.java | 14 ++++++-- .../src/edu/internet2/ndt/NDTConstants.java | 6 ++-- .../src/edu/internet2/ndt/OsfwWorker.java | 2 +- .../java/src/edu/internet2/ndt/Protocol.java | 2 +- .../java/src/edu/internet2/ndt/Tcpbw100.java | 33 +++++-------------- 5 files changed, 25 insertions(+), 32 deletions(-) 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 73d7e6f30..fab96920e 100644 --- a/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java +++ b/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java @@ -58,8 +58,17 @@ public class MLabRunner { // null for testing private final RouterContext _rcontext; private final Log _log; + private static MLabRunner _instance; - public MLabRunner(I2PAppContext ctx) { + public static MLabRunner getInstance(I2PAppContext ctx) { + synchronized(MLabRunner.class) { + if (_instance == null) + _instance = new MLabRunner(ctx); + return _instance; + } + } + + private MLabRunner(I2PAppContext ctx) { _context = ctx; _rcontext = ctx.isRouterContext() ? (RouterContext) ctx : null; _log = ctx.logManager().getLog(MLabRunner.class); @@ -338,9 +347,8 @@ public class MLabRunner { /** standalone test */ public static void main(String[] args) { I2PAppContext ctx = I2PAppContext.getGlobalContext(); - MLabRunner mlab = new MLabRunner(ctx); + MLabRunner mlab = MLabRunner.getInstance(ctx); ToolListener lsnr = new TestListener(); mlab.runNDT(lsnr); - try { Thread.sleep(120*1000); } catch(InterruptedException ie) {} } } diff --git a/apps/routerconsole/java/src/edu/internet2/ndt/NDTConstants.java b/apps/routerconsole/java/src/edu/internet2/ndt/NDTConstants.java index beda57c1c..69c70d25a 100644 --- a/apps/routerconsole/java/src/edu/internet2/ndt/NDTConstants.java +++ b/apps/routerconsole/java/src/edu/internet2/ndt/NDTConstants.java @@ -189,11 +189,11 @@ public class NDTConstants { try { _rscBundleMessages = ResourceBundle.getBundle(TCPBW100_MSGS, paramLocale); - System.out.println("Obtained messages "); + //System.out.println("Obtained messages "); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error while loading language files:\n" + e.getMessage()); - e.printStackTrace(); + //e.printStackTrace(); } } // end method @@ -214,7 +214,7 @@ public class NDTConstants { } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error while loading language files:\n" + e.getMessage()); - e.printStackTrace(); + //e.printStackTrace(); } }// end method initconstants diff --git a/apps/routerconsole/java/src/edu/internet2/ndt/OsfwWorker.java b/apps/routerconsole/java/src/edu/internet2/ndt/OsfwWorker.java index 32464281d..c9d1f11bf 100644 --- a/apps/routerconsole/java/src/edu/internet2/ndt/OsfwWorker.java +++ b/apps/routerconsole/java/src/edu/internet2/ndt/OsfwWorker.java @@ -93,7 +93,7 @@ public class OsfwWorker implements Runnable { // accept it socketObj = _srvSocket.accept(); } catch (Exception e) { - e.printStackTrace(); + //e.printStackTrace(); // The "accept" call has failed, and indicates a firewall // possibility diff --git a/apps/routerconsole/java/src/edu/internet2/ndt/Protocol.java b/apps/routerconsole/java/src/edu/internet2/ndt/Protocol.java index a15311b23..ffa45c057 100644 --- a/apps/routerconsole/java/src/edu/internet2/ndt/Protocol.java +++ b/apps/routerconsole/java/src/edu/internet2/ndt/Protocol.java @@ -183,7 +183,7 @@ public class Protocol { _ctlInStream.close(); _ctlOutStream.close(); } catch (IOException e) { - e.printStackTrace(); + //e.printStackTrace(); } } diff --git a/apps/routerconsole/java/src/edu/internet2/ndt/Tcpbw100.java b/apps/routerconsole/java/src/edu/internet2/ndt/Tcpbw100.java index fa295e7af..868e7e5e7 100644 --- a/apps/routerconsole/java/src/edu/internet2/ndt/Tcpbw100.java +++ b/apps/routerconsole/java/src/edu/internet2/ndt/Tcpbw100.java @@ -117,10 +117,6 @@ import javax.swing.SpinnerNumberModel; */ import com.vuze.plugins.mlab.tools.ndt.swingemu.*; -// Workaround for remote JavaScript start method -import java.security.AccessController; -import java.security.PrivilegedAction; - import net.i2p.util.Addresses; import net.i2p.util.Log; @@ -747,7 +743,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { } } } catch (Exception e) { - e.printStackTrace(); + _log.warn("?", e); String sMessage = NDTUtils.isEmpty(e.getMessage()) ? _resBundDisplayMsgs.getString("withoutMessage") @@ -788,18 +784,8 @@ public class Tcpbw100 extends JApplet implements ActionListener { * "Remote Control" function - invoke NDT' runtest() method from the API */ public void run_test() { - // The Java security model considers calling a method that opens a - // socket - // from JavaScript to be a privileged action. By using - // java.security.privilegedAction here, we can grant JavaScript the - // same expanded privileges as the signed applet to open a socket. - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { pub_errmsg = "Test in progress."; runtest(); - return null; - } - }); } /** @@ -829,7 +815,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error while loading language files:\n" + e.getMessage()); - e.printStackTrace(); + _log.warn("?", e); } // create main window @@ -1249,7 +1235,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { getAppletContext().showDocument(_targetURL); } catch (Exception e) { - e.printStackTrace(); + _log.warn("?", e); String sMessage = NDTUtils.isEmpty(e.getMessage()) ? _resBundDisplayMsgs.getString("withoutMessage") @@ -1641,15 +1627,14 @@ public class Tcpbw100 extends JApplet implements ActionListener { try { SecurityManager security = System.getSecurityManager(); if (security != null) { - System.out - .println("Asking security manager for listen permissions..."); + _log.warn("Asking security manager for listen permissions..."); security.checkListen(0); } // SOCKET_FREE_PORT_INDICATOR = 0 to use any free port srvSocket = new ServerSocket( NDTConstants.SOCKET_FREE_PORT_INDICATOR); } catch (Exception e) { - e.printStackTrace(); + _log.warn("?", e); _sErrMsg = _resBundDisplayMsgs.getString("sfwSocketFail") + "\n"; return true; @@ -1701,7 +1686,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { sfwCtl.send_json_msg(MessageType.TEST_MSG, new String( NDTConstants.SFW_PREDEFINED_TEST_MESSAGE).getBytes()); } catch (Exception e) { - e.printStackTrace(); + _log.warn("?", e); //Indication that there might be a firewall from C->S side. } @@ -2210,7 +2195,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { _iSsndqueue = Integer.parseInt(JSONUtils.getValueFromJsonObj(tmpstr3, "UnsentDataAmount")); _dSbytes = Double.parseDouble(JSONUtils.getValueFromJsonObj(tmpstr3, "TotalSentByte")); } catch (Exception e) { - e.printStackTrace(); + _log.warn("?", e); _sErrMsg = _resBundDisplayMsgs.getString("inboundWrongMessage") + "\n"; return true; @@ -2228,7 +2213,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { _dSbytes = Double.parseDouble(tmpstr3.substring(k1 + 1) .substring(k2 + 1)); } catch (Exception e) { - e.printStackTrace(); + _log.warn("?", e); _sErrMsg = _resBundDisplayMsgs.getString("inboundWrongMessage") + "\n"; return true; @@ -4479,7 +4464,7 @@ public class Tcpbw100 extends JApplet implements ActionListener { thread_group.destroy(); break; }catch( Throwable e ){ - e.printStackTrace(); + _log.warn("?", e); } }