cshannon commented on code in PR #1329: URL: https://github.com/apache/activemq/pull/1329#discussion_r1888679702
########## activemq-client/src/main/java/org/apache/activemq/management/StatsImpl.java: ########## @@ -38,44 +35,35 @@ public StatsImpl(Set<StatisticImpl> set) { this.set = set; } - public void reset() { - Statistic[] stats = getStatistics(); - int size = stats.length; - for (int i = 0; i < size; i++) { - Statistic stat = stats[i]; - if (stat instanceof Resettable) { - Resettable r = (Resettable) stat; - r.reset(); - } - } + public synchronized void reset() { + this.set.stream() + .filter(Resettable.class::isInstance) + .map(Resettable.class::cast) + .forEach(resetStat -> resetStat.reset()); } - public Statistic getStatistic(String name) { - for (StatisticImpl stat : this.set) { - if (stat.getName() != null && stat.getName().equals(name)) { - return stat; - } - } - return null; + public synchronized Statistic getStatistic(String name) { + return this.set.stream().filter(s -> s.getName().equals(name)).findFirst().orElse(null); } - public String[] getStatisticNames() { - List<String> names = new ArrayList<String>(); - for (StatisticImpl stat : this.set) { - names.add(stat.getName()); - } - String[] answer = new String[names.size()]; - names.toArray(answer); - return answer; + public synchronized String[] getStatisticNames() { + return this.set.stream().map(StatisticImpl::getName).toArray(String[]::new); } - public Statistic[] getStatistics() { - Statistic[] answer = new Statistic[this.set.size()]; - set.toArray(answer); - return answer; + public synchronized Statistic[] getStatistics() { + return this.set.toArray(new Statistic[this.set.size()]); } - protected void addStatistic(String name, StatisticImpl statistic) { + @Deprecated(forRemoval = true, since = "6.2.0") + protected synchronized void addStatistic(String name, StatisticImpl statistic) { this.set.add(statistic); } + + protected synchronized void addStatistics(Collection<StatisticImpl> statistics) { Review Comment: This also doesn't make a lot of sense, you don't need to synchronize and also use a CopyOnWriteArrayList. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For additional commands, e-mail: gitbox-h...@activemq.apache.org For further information, visit: https://activemq.apache.org/contact