mirror of https://github.com/apache/activemq.git
use a CopyOnWriteSet instead of a Map - to reduce memory footprint
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@810062 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5221cd349d
commit
34b123ebb6
|
@ -16,25 +16,28 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.management;
|
package org.apache.activemq.management;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import javax.management.j2ee.statistics.Statistic;
|
import javax.management.j2ee.statistics.Statistic;
|
||||||
import javax.management.j2ee.statistics.Stats;
|
import javax.management.j2ee.statistics.Stats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for a Stats implementation
|
* Base class for a Stats implementation
|
||||||
*
|
*
|
||||||
* @version $Revision: 1.2 $
|
* @version $Revision: 1.2 $
|
||||||
*/
|
*/
|
||||||
public class StatsImpl extends StatisticImpl implements Stats, Resettable {
|
public class StatsImpl extends StatisticImpl implements Stats, Resettable {
|
||||||
private Map<String, StatisticImpl> map;
|
//use a Set instead of a Map - to conserve Space
|
||||||
|
private Set<StatisticImpl> set;
|
||||||
|
|
||||||
public StatsImpl() {
|
public StatsImpl() {
|
||||||
this(new HashMap<String, StatisticImpl>());
|
this(new CopyOnWriteArraySet<StatisticImpl>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public StatsImpl(Map<String, StatisticImpl> map) {
|
public StatsImpl(Set<StatisticImpl> set) {
|
||||||
super("stats", "many", "Used only as container, not Statistic");
|
super("stats", "many", "Used only as container, not Statistic");
|
||||||
this.map = map;
|
this.set = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
|
@ -43,31 +46,38 @@ public class StatsImpl extends StatisticImpl implements Stats, Resettable {
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
Statistic stat = stats[i];
|
Statistic stat = stats[i];
|
||||||
if (stat instanceof Resettable) {
|
if (stat instanceof Resettable) {
|
||||||
Resettable r = (Resettable)stat;
|
Resettable r = (Resettable) stat;
|
||||||
r.reset();
|
r.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Statistic getStatistic(String name) {
|
public Statistic getStatistic(String name) {
|
||||||
return map.get(name);
|
for (StatisticImpl stat : this.set) {
|
||||||
|
if (stat.getName() != null && stat.getName().equals(name)) {
|
||||||
|
return stat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getStatisticNames() {
|
public String[] getStatisticNames() {
|
||||||
Set<String> keys = map.keySet();
|
List<String> names = new ArrayList<String>();
|
||||||
String[] answer = new String[keys.size()];
|
for (StatisticImpl stat : this.set) {
|
||||||
keys.toArray(answer);
|
names.add(stat.getName());
|
||||||
|
}
|
||||||
|
String[] answer = new String[names.size()];
|
||||||
|
names.toArray(answer);
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Statistic[] getStatistics() {
|
public Statistic[] getStatistics() {
|
||||||
Collection<StatisticImpl> values = map.values();
|
Statistic[] answer = new Statistic[this.set.size()];
|
||||||
Statistic[] answer = new Statistic[values.size()];
|
set.toArray(answer);
|
||||||
values.toArray(answer);
|
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addStatistic(String name, StatisticImpl statistic) {
|
protected void addStatistic(String name, StatisticImpl statistic) {
|
||||||
map.put(name, statistic);
|
this.set.add(statistic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue