MLab/NDT: static instance, log fixes, cleanups

This commit is contained in:
zzz
2018-11-13 19:20:10 +00:00
parent 84c0aa4072
commit d95c284d3e
5 changed files with 25 additions and 32 deletions

View File

@@ -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) {}
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -183,7 +183,7 @@ public class Protocol {
_ctlInStream.close();
_ctlOutStream.close();
} catch (IOException e) {
e.printStackTrace();
//e.printStackTrace();
}
}

View File

@@ -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);
}
}