ConnectionStatData data = new ConnectionStatData(path);
logger.l5("get ConnectionStatData " + data);
List<ConnectionStatData.ConnectionStatDataElement> elements = reset ? data.loadAndDrop() : data.load();
logger.l5(MessageFormat.format("has {0} elements", elements != null ? elements.size() : 0));
ReportBuilder builder = new ReportBuilder();
builder.setColumns(Arrays.asList("Link", "I_OK", "I_FA", "O_OK", "O_FA", "BR", "BS"));
builder.setColLength(Arrays.asList(19, 5, 5, 5, 5, 9, 9));
Collections.sort(elements, new Comparator<ConnectionStatData.ConnectionStatDataElement>() {
@Override
public int compare(ConnectionStatData.ConnectionStatDataElement arg0,
ConnectionStatData.ConnectionStatDataElement arg1) {
FtnAddress a1 = arg0.linkStr != null ? new FtnAddress(arg0.linkStr) : null;
FtnAddress a2 = arg1.linkStr != null ? new FtnAddress(arg1.linkStr) : null;
if (a1 == null && a2 != null) {
return 1;
} else if (a2 == null && a1 != null) {
return -1;
} else if (a1 == null && a2 == null) {
return 0;
} else {
return new FtnTools.Ftn4DComparator().compare(a1, a2);
}
}
});
int iOkT = 0;
int iFaT = 0;
int oOkT = 0;
int oFaT = 0;
int bsT = 0;
int brT = 0;
for (ConnectionStatData.ConnectionStatDataElement element : elements) {
FtnAddress link = element.linkStr != null ? new FtnAddress(element.linkStr) : null;
String linkName = (link != null) ? link.toString()
: "Unknown";
iOkT += element.incomingOk;
iFaT += element.incomingFailed;
oOkT += element.outgoingOk;
oFaT += element.outgoingFailed;
bsT += element.bytesSended;
brT += element.bytesReceived;
builder.printLine(
linkName,
String.valueOf(element.incomingOk),
String.valueOf(element.incomingFailed),
String.valueOf(element.outgoingOk),
String.valueOf(element.outgoingFailed),
b2s(element.bytesReceived),
b2s(element.bytesSended)
);
}
if (elements.size() > 0){
builder.printHorLine();
}
builder.printLine(
"Summary",
String.valueOf(iOkT),
String.valueOf(iFaT),
String.valueOf(oOkT),
String.valueOf(oFaT),
b2s(brT),
b2s(bsT)
);
return builder.getText().toString();
}