make ConnectionInfo comparable and sort list of connections in Connections_p

ConnectionInfo compare by initTime
Connections_p implement wish to sort connections, descending

Signed-off-by: Marek Otahal <markotahal@gmail.com>
pull/1/head
Marek Otahal 13 years ago committed by Michael Peter Christen
parent c1973c78a3
commit 1dc5d9f0f3

@ -43,6 +43,9 @@ import de.anomic.server.serverCore;
import de.anomic.server.serverCore.Session;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public final class Connections_p {
@ -141,11 +144,14 @@ public final class Connections_p {
// client sessions
final Set<ConnectionInfo> allConnections = ConnectionInfo.getAllConnections();
// TODO sorting
// Arrays.sort(a, httpc.connectionTimeComparatorInstance);
// sorting: sort by initTime, decending
List<ConnectionInfo> allConnectionsSorted = new LinkedList<ConnectionInfo>(allConnections);
Collections.sort(allConnectionsSorted);
Collections.reverse(allConnectionsSorted); // toggle ascending/descending
int c = 0;
synchronized (allConnections) {
for (final ConnectionInfo conInfo: allConnections) {
synchronized (allConnectionsSorted) {
for (final ConnectionInfo conInfo: allConnectionsSorted) {
prop.put("clientList_" + c + "_clientProtocol", conInfo.getProtocol());
prop.putNum("clientList_" + c + "_clientLifetime", conInfo.getLifetime());
prop.putNum("clientList_" + c + "_clientUpbytes", conInfo.getUpbytes());

@ -36,7 +36,7 @@ import java.util.Set;
* @author daniel
* @author sixcooler
*/
public class ConnectionInfo {
public class ConnectionInfo implements Comparable<ConnectionInfo> {
/**
* a list of all current connections to be shown in Connections_p
*/
@ -270,4 +270,11 @@ public class ConnectionInfo {
final ConnectionInfo other = (ConnectionInfo) obj;
return this.id == other.id;
}
public int compareTo(ConnectionInfo o) {
if(o==null) throw new NullPointerException("ConnectionInfo: compare() : passed argument is null \n");
if(this.initTime>o.initTime) return 1;
else if(this.initTime<o.initTime) return -1;
else return 0;
}
}

Loading…
Cancel
Save