@ConsoleCommand(description = "List all the active connections to the server", onlineHelp = "Console-Command-List-Connections")
public void listConnections() throws IOException {
checkForRemoteServer();
OrientDBRemote remote = (OrientDBRemote) OrientDBInternal.extract(orientDB);
final ODocument serverInfo = remote.getServerInfo(currentDatabaseUserName, currentDatabaseUserPassword);
final List<OIdentifiable> resultSet = new ArrayList<OIdentifiable>();
final List<Map<String, Object>> connections = serverInfo.field("connections");
for (Map<String, Object> conn : connections) {
final ODocument row = new ODocument();
String commandDetail = (String) conn.get("commandInfo");
if (commandDetail != null && ((String) conn.get("commandDetail")).length() > 1)
commandDetail += " (" + conn.get("commandDetail") + ")";
row.fields("ID", conn.get("connectionId"), "REMOTE_ADDRESS", conn.get("remoteAddress"), "PROTOC", conn.get("protocol"),
"LAST_OPERATION_ON", conn.get("lastCommandOn"), "DATABASE", conn.get("db"), "USER", conn.get("user"), "COMMAND",
commandDetail, "TOT_REQS", conn.get("totalRequests"));
resultSet.add(row);
}
Collections.sort(resultSet, new Comparator<OIdentifiable>() {
@Override
public int compare(final OIdentifiable o1, final OIdentifiable o2) {
final String o1s = ((ODocument) o1).field("LAST_OPERATION_ON");
final String o2s = ((ODocument) o2).field("LAST_OPERATION_ON");
return o2s.compareTo(o1s);
}
});
final OTableFormatter formatter = new OTableFormatter(this);
formatter.writeRecords(resultSet, -1);
out.println();
}