@Override public String localStatus(DeviceId deviceId) { LocalStatus ls = deviceLocalStatus.get(deviceId); if (ls == null) { return "No Record"; } String timeAgo = Tools.timeAgo(ls.dateTime.toEpochMilli()); return (ls.connected) ? "connected " + timeAgo : "disconnected " + timeAgo; }
@Override protected void execute() { FpmInfoService fpmInfo = get(FpmInfoService.class); fpmInfo.peers().forEach((socketAddress, timestamp) -> { if (socketAddress instanceof InetSocketAddress) { InetSocketAddress inet = (InetSocketAddress) socketAddress; print(FORMAT, inet.getHostString(), inet.getPort(), Tools.timeAgo(timestamp)); } else { print("Unknown data format"); } }); } }
private void displayCandidates(Map<String, Leadership> leaderBoard) { print("--------------------------------------------------------------------------------------------"); print(FMT_C, "Topic", "Leader", "Term", "Elected", "Candidates"); print("--------------------------------------------------------------------------------------------"); leaderBoard.entrySet() .stream() .filter(es -> allTopics || pattern.matcher(es.getKey()).matches()) .sorted((a, b) -> leadershipComparator.compare(a.getValue(), b.getValue())) .forEach(es -> { Leadership l = es.getValue(); List<NodeId> candidateList = l.candidates(); if (candidateList == null || candidateList.isEmpty()) { return; } print(FMT_C, es.getKey(), String.valueOf(l.leaderNodeId()), l.leader().term(), Tools.timeAgo(l.leader().termStartTime()), // formatting hacks to get it into a table candidateList.get(0).toString()); candidateList.subList(1, candidateList.size()) .forEach(n -> print(FMT_C, " ", " ", " ", " ", n)); print(FMT_C, " ", " ", " ", " ", " "); }); print("--------------------------------------------------------------------------------------------"); }
/** * Displays text representing the leaders. * * @param leaderBoard map of leaders */ private void displayLeaders(Map<String, Leadership> leaderBoard) { print("------------------------------------------------------------------------"); print(FMT, "Topic", "Leader", "Term", "Elected"); print("------------------------------------------------------------------------"); leaderBoard.values() .stream() .filter(l -> allTopics || pattern.matcher(l.topic()).matches()) .filter(l -> l.leader() != null) .sorted(leadershipComparator) .forEach(l -> print(FMT, l.topic(), l.leaderNodeId(), l.leader().term(), Tools.timeAgo(l.leader().termStartTime()))); print("------------------------------------------------------------------------"); }