mattrpav commented on code in PR #1329:
URL: https://github.com/apache/activemq/pull/1329#discussion_r1924507296


##########
activemq-client/src/main/java/org/apache/activemq/management/StatisticImpl.java:
##########
@@ -15,22 +15,19 @@
  * limitations under the License.
  */
 package org.apache.activemq.management;
-
 /**
- * Base class for a Statistic implementation
- * 
- * 
+ * A thread-safe class for a Statistic implementation
  */
 public class StatisticImpl implements Statistic, Resettable {
 
-    protected boolean enabled;
+    protected volatile boolean enabled;
 
-    private String name;
-    private String unit;
-    private String description;
-    private long startTime;
-    private long lastSampleTime;
-    private boolean doReset = true;
+    protected final String name;

Review Comment:
   Changes applied via commit c079d1bd03df5a2faf35f2ec9625e7e51b2a4973



##########
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:
   Changes applied via commit c079d1bd03df5a2faf35f2ec9625e7e51b2a4973



-- 
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


Reply via email to