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
private static final String usersStatKey = "muc_users";
private static final String incomingStatKey = "muc_incoming";
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
private void addTotalRoomStats() {
// Register a statistic.
Statistic statistic = new Statistic() {
public String getKey() {
return roomsStatKey;
}
public String getName() {
return LocaleUtils.getLocalizedString("muc.room.summary.total_room");
}
public Type getStatType() {
return Type.COUNT;
return Type.count;
}
public String getDescription() {
......@@ -1152,22 +1149,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return getNumberChatRooms();
}
};
StatisticsManager.getInstance().addStatistic(statistic);
StatisticsManager.getInstance().addStatistic(roomsStatKey, statistic);
}
private void addTotalOccupantsStats() {
// Register a statistic.
Statistic statistic = new Statistic() {
public String getKey() {
return occupantsStatKey;
}
public String getName() {
return LocaleUtils.getLocalizedString("muc.stats.occupants.name");
}
public Type getStatType() {
return Type.COUNT;
return Type.count;
}
public String getDescription() {
......@@ -1182,22 +1175,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return getNumberRoomOccupants();
}
};
StatisticsManager.getInstance().addStatistic(statistic);
StatisticsManager.getInstance().addStatistic(occupantsStatKey, statistic);
}
private void addTotalConnectedUsers() {
// Register a statistic.
Statistic statistic = new Statistic() {
public String getKey() {
return usersStatKey;
}
public String getName() {
return LocaleUtils.getLocalizedString("muc.stats.users.name");
}
public Type getStatType() {
return Type.COUNT;
return Type.count;
}
public String getDescription() {
......@@ -1212,22 +1201,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return getNumberConnectedUsers();
}
};
StatisticsManager.getInstance().addStatistic(statistic);
StatisticsManager.getInstance().addStatistic(usersStatKey, statistic);
}
private void addNumberIncomingMessages() {
// Register a statistic.
Statistic statistic = new Statistic() {
public String getKey() {
return incomingStatKey;
}
public String getName() {
return LocaleUtils.getLocalizedString("muc.stats.incoming.name");
}
public Type getStatType() {
return Type.RATE;
return Type.rate;
}
public String getDescription() {
......@@ -1242,22 +1227,18 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return inMessages.getAndSet(0);
}
};
StatisticsManager.getInstance().addStatistic(statistic);
StatisticsManager.getInstance().addMultiStatistic(incomingStatKey, trafficStatGroup, statistic);
}
private void addNumberOutgoingMessages() {
// Register a statistic.
Statistic statistic = new Statistic() {
public String getKey() {
return outgoingStatKey;
}
public String getName() {
return LocaleUtils.getLocalizedString("muc.stats.outgoing.name");
}
public Type getStatType() {
return Type.RATE;
return Type.rate;
}
public String getDescription() {
......@@ -1272,6 +1253,6 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
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;
*/
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.
*
......@@ -61,11 +54,11 @@ public interface Statistic {
* Specifies a rate over time.
* 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
* number of users in MultiUserChat at this second.
*/
COUNT
count
}
}
......@@ -10,8 +10,7 @@
*/
package org.jivesoftware.wildfire.stats;
import java.util.Collection;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -26,6 +25,10 @@ public class StatisticsManager {
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() {}
/**
......@@ -33,8 +36,8 @@ public class StatisticsManager {
*
* @param definition The statistic to be tracked.
*/
public void addStatistic(Statistic definition) {
statistics.put(definition.getKey(), definition);
public void addStatistic(String statKey, Statistic definition) {
statistics.put(statKey, definition);
}
/**
......@@ -47,12 +50,31 @@ public class StatisticsManager {
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.
* @return Returns all statistics that the StatManager is tracking.
*/
public Collection<Statistic> getAllStatistics() {
return statistics.values();
public Set<Map.Entry<String, Statistic>> getAllStatistics() {
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