Commit 37c0650f authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Updates for Multistats

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3950 b35dd754-fafc-0310-a699-88a17e54d16e
parent 758040ed
...@@ -72,6 +72,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -72,6 +72,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
private static final String usersStatKey = "muc_users"; private static final String usersStatKey = "muc_users";
private static final String incomingStatKey = "muc_incoming"; private static final String incomingStatKey = "muc_incoming";
private static final String outgoingStatKey = "muc_outgoing"; private static final String outgoingStatKey = "muc_outgoing";
private static final String trafficStatGroup = "muc_traffic";
/** /**
...@@ -1128,16 +1129,12 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -1128,16 +1129,12 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
private void addTotalRoomStats() { private void addTotalRoomStats() {
// Register a statistic. // Register a statistic.
Statistic statistic = new Statistic() { Statistic statistic = new Statistic() {
public String getKey() {
return roomsStatKey;
}
public String getName() { public String getName() {
return LocaleUtils.getLocalizedString("muc.room.summary.total_room"); return LocaleUtils.getLocalizedString("muc.room.summary.total_room");
} }
public Type getStatType() { public Type getStatType() {
return Type.COUNT; return Type.count;
} }
public String getDescription() { public String getDescription() {
...@@ -1152,22 +1149,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -1152,22 +1149,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return getNumberChatRooms(); return getNumberChatRooms();
} }
}; };
StatisticsManager.getInstance().addStatistic(statistic); StatisticsManager.getInstance().addStatistic(roomsStatKey, statistic);
} }
private void addTotalOccupantsStats() { private void addTotalOccupantsStats() {
// Register a statistic. // Register a statistic.
Statistic statistic = new Statistic() { Statistic statistic = new Statistic() {
public String getKey() {
return occupantsStatKey;
}
public String getName() { public String getName() {
return LocaleUtils.getLocalizedString("muc.stats.occupants.name"); return LocaleUtils.getLocalizedString("muc.stats.occupants.name");
} }
public Type getStatType() { public Type getStatType() {
return Type.COUNT; return Type.count;
} }
public String getDescription() { public String getDescription() {
...@@ -1182,22 +1175,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -1182,22 +1175,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return getNumberRoomOccupants(); return getNumberRoomOccupants();
} }
}; };
StatisticsManager.getInstance().addStatistic(statistic); StatisticsManager.getInstance().addStatistic(occupantsStatKey, statistic);
} }
private void addTotalConnectedUsers() { private void addTotalConnectedUsers() {
// Register a statistic. // Register a statistic.
Statistic statistic = new Statistic() { Statistic statistic = new Statistic() {
public String getKey() {
return usersStatKey;
}
public String getName() { public String getName() {
return LocaleUtils.getLocalizedString("muc.stats.users.name"); return LocaleUtils.getLocalizedString("muc.stats.users.name");
} }
public Type getStatType() { public Type getStatType() {
return Type.COUNT; return Type.count;
} }
public String getDescription() { public String getDescription() {
...@@ -1212,22 +1201,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -1212,22 +1201,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return getNumberConnectedUsers(); return getNumberConnectedUsers();
} }
}; };
StatisticsManager.getInstance().addStatistic(statistic); StatisticsManager.getInstance().addStatistic(usersStatKey, statistic);
} }
private void addNumberIncomingMessages() { private void addNumberIncomingMessages() {
// Register a statistic. // Register a statistic.
Statistic statistic = new Statistic() { Statistic statistic = new Statistic() {
public String getKey() {
return incomingStatKey;
}
public String getName() { public String getName() {
return LocaleUtils.getLocalizedString("muc.stats.incoming.name"); return LocaleUtils.getLocalizedString("muc.stats.incoming.name");
} }
public Type getStatType() { public Type getStatType() {
return Type.RATE; return Type.rate;
} }
public String getDescription() { public String getDescription() {
...@@ -1242,22 +1227,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -1242,22 +1227,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return inMessages.getAndSet(0); return inMessages.getAndSet(0);
} }
}; };
StatisticsManager.getInstance().addStatistic(statistic); StatisticsManager.getInstance().addMultiStatistic(incomingStatKey, trafficStatGroup, statistic);
} }
private void addNumberOutgoingMessages() { private void addNumberOutgoingMessages() {
// Register a statistic. // Register a statistic.
Statistic statistic = new Statistic() { Statistic statistic = new Statistic() {
public String getKey() {
return outgoingStatKey;
}
public String getName() { public String getName() {
return LocaleUtils.getLocalizedString("muc.stats.outgoing.name"); return LocaleUtils.getLocalizedString("muc.stats.outgoing.name");
} }
public Type getStatType() { public Type getStatType() {
return Type.RATE; return Type.rate;
} }
public String getDescription() { public String getDescription() {
...@@ -1272,6 +1253,6 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -1272,6 +1253,6 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return outMessages.getAndSet(0); return outMessages.getAndSet(0);
} }
}; };
StatisticsManager.getInstance().addStatistic(statistic); StatisticsManager.getInstance().addMultiStatistic(outgoingStatKey, trafficStatGroup, statistic);
} }
} }
\ No newline at end of file
...@@ -15,13 +15,6 @@ package org.jivesoftware.wildfire.stats; ...@@ -15,13 +15,6 @@ package org.jivesoftware.wildfire.stats;
*/ */
public interface Statistic { public interface Statistic {
/**
* The key uniquiely identifies a statistic in the system.
*
* @return Returns the key uniquiely identifies a statistic in the system.
*/
public String getKey();
/** /**
* Returns the name of a stat. * Returns the name of a stat.
* *
...@@ -61,11 +54,11 @@ public interface Statistic { ...@@ -61,11 +54,11 @@ public interface Statistic {
* Specifies a rate over time. * Specifies a rate over time.
* For example, the averave of kb/s in file transfers. * For example, the averave of kb/s in file transfers.
*/ */
RATE, rate,
/** /**
* Specifies a count at a specific time period. An example would be the * Specifies a count at a specific time period. An example would be the
* number of users in MultiUserChat at this second. * number of users in MultiUserChat at this second.
*/ */
COUNT count
} }
} }
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
*/ */
package org.jivesoftware.wildfire.stats; package org.jivesoftware.wildfire.stats;
import java.util.Collection; import java.util.*;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
...@@ -26,6 +25,10 @@ public class StatisticsManager { ...@@ -26,6 +25,10 @@ public class StatisticsManager {
private final Map<String, Statistic> statistics = new ConcurrentHashMap<String, Statistic>(); private final Map<String, Statistic> statistics = new ConcurrentHashMap<String, Statistic>();
private final Map<String, List<String>> multiStatGroups = new ConcurrentHashMap<String, List<String>>();
private final Map<String, String> keyToGroupMap = new ConcurrentHashMap<String, String>();
private StatisticsManager() {} private StatisticsManager() {}
/** /**
...@@ -33,8 +36,8 @@ public class StatisticsManager { ...@@ -33,8 +36,8 @@ public class StatisticsManager {
* *
* @param definition The statistic to be tracked. * @param definition The statistic to be tracked.
*/ */
public void addStatistic(Statistic definition) { public void addStatistic(String statKey, Statistic definition) {
statistics.put(definition.getKey(), definition); statistics.put(statKey, definition);
} }
/** /**
...@@ -47,12 +50,31 @@ public class StatisticsManager { ...@@ -47,12 +50,31 @@ public class StatisticsManager {
return statistics.get(statKey); return statistics.get(statKey);
} }
public void addMultiStatistic(String statKey, String groupName, Statistic statistic) {
addStatistic(statKey, statistic);
List<String> group = multiStatGroups.get(groupName);
if(group == null) {
group = new ArrayList<String>();
multiStatGroups.put(groupName, group);
}
group.add(statKey);
keyToGroupMap.put(statKey, groupName);
}
public List<String> getStatGroup(String statGroup) {
return multiStatGroups.get(statGroup);
}
public String getMultistatGroup(String statKey) {
return keyToGroupMap.get(statKey);
}
/** /**
* Returns all statistics that the StatManager is tracking. * Returns all statistics that the StatManager is tracking.
* @return Returns all statistics that the StatManager is tracking. * @return Returns all statistics that the StatManager is tracking.
*/ */
public Collection<Statistic> getAllStatistics() { public Set<Map.Entry<String, Statistic>> getAllStatistics() {
return statistics.values(); return statistics.entrySet();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment