From commits-return-11625-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Tue Sep 01 14:05:50 2009 Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 88162 invoked from network); 1 Sep 2009 14:05:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Sep 2009 14:05:49 -0000 Received: (qmail 88063 invoked by uid 500); 1 Sep 2009 14:05:49 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 88004 invoked by uid 500); 1 Sep 2009 14:05:49 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 87995 invoked by uid 99); 1 Sep 2009 14:05:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 14:05:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 14:05:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DB28B2388892; Tue, 1 Sep 2009 14:05:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r810062 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java Date: Tue, 01 Sep 2009 14:05:27 -0000 To: commits@activemq.apache.org From: rajdavies@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090901140527.DB28B2388892@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rajdavies Date: Tue Sep 1 14:05:27 2009 New Revision: 810062 URL: http://svn.apache.org/viewvc?rev=810062&view=rev Log: use a CopyOnWriteSet instead of a Map - to reduce memory footprint Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java?rev=810062&r1=810061&r2=810062&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java Tue Sep 1 14:05:27 2009 @@ -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 @@ 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); } }