From 34b123ebb62f1661bcbe26dacaf1a5f5bb6a94a6 Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Tue, 1 Sep 2009 14:05:27 +0000 Subject: [PATCH] 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 --- .../apache/activemq/management/StatsImpl.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java b/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java index ebdd65c17d..32b19c6183 100755 --- a/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java +++ b/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java @@ -16,25 +16,28 @@ */ 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.Stats; - /** * Base class for a Stats implementation * * @version $Revision: 1.2 $ */ public class StatsImpl extends StatisticImpl implements Stats, Resettable { - private Map map; + //use a Set instead of a Map - to conserve Space + private Set set; public StatsImpl() { - this(new HashMap()); + this(new CopyOnWriteArraySet()); } - public StatsImpl(Map map) { + public StatsImpl(Set set) { super("stats", "many", "Used only as container, not Statistic"); - this.map = map; + this.set = set; } public void reset() { @@ -43,31 +46,38 @@ public class StatsImpl extends StatisticImpl implements Stats, Resettable { for (int i = 0; i < size; i++) { Statistic stat = stats[i]; if (stat instanceof Resettable) { - Resettable r = (Resettable)stat; + Resettable r = (Resettable) stat; r.reset(); } } } 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() { - Set keys = map.keySet(); - String[] answer = new String[keys.size()]; - keys.toArray(answer); + List names = new ArrayList(); + for (StatisticImpl stat : this.set) { + names.add(stat.getName()); + } + String[] answer = new String[names.size()]; + names.toArray(answer); return answer; } public Statistic[] getStatistics() { - Collection values = map.values(); - Statistic[] answer = new Statistic[values.size()]; - values.toArray(answer); + Statistic[] answer = new Statistic[this.set.size()]; + set.toArray(answer); return answer; } protected void addStatistic(String name, StatisticImpl statistic) { - map.put(name, statistic); + this.set.add(statistic); } }