private double doPing(int size) {
// let's get that speed
OutputParams op = new OutputParams(null);
op.log = true;
op.maxBufferSize = 1;
SystemUtils sysUtil = PMS.get().getRegistry();
final ProcessWrapperImpl pw = new ProcessWrapperImpl(sysUtil.getPingCommand(addr.getHostAddress(), 3, size), op, true, false);
Runnable r = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
}
pw.stopProcess();
}
};
Thread failsafe = new Thread(r, "SpeedStats Failsafe");
failsafe.start();
pw.runInSameThread();
List<String> ls = pw.getOtherResults();
double time = 0;
int c = 0;
String timeString;
for (String line : ls) {
timeString = sysUtil.parsePingLine(line);
if (timeString == null) {
continue;
}
try {
time += Double.parseDouble(timeString);