From d1192dc5bd25d09e2597d4152f48b9868252b102 Mon Sep 17 00:00:00 2001 From: Trevor Dyck Date: Sat, 30 May 2026 23:22:55 -0700 Subject: [PATCH] Replace deprecated StatsImpl.addStatistic with addStatistics(Set.of(..)) StatsImpl.addStatistic(String, StatisticImpl) is marked @Deprecated(forRemoval = true, since = "6.2.0") and its String name argument is unused. Replace the remaining call sites in the broker statistics classes with the batched addStatistics(Collection) API, following the pattern already adopted in the activemq-client management classes (e.g. JMSSessionStatsImpl). Pure mechanical refactor: each constructor now registers its statistics in a single addStatistics(Set.of(...)) call. No behavioral change -- the statistics are stored in the same backing set; only the redundant, ignored name argument and the deprecated call are removed. Fixes #1984 --- .../activemq/broker/region/ConnectionStatistics.java | 5 +++-- .../activemq/broker/region/ConnectorStatistics.java | 8 +++----- .../activemq/broker/region/RegionStatistics.java | 6 +++--- .../broker/region/SubscriptionStatistics.java | 8 +++----- .../activemq/network/NetworkBridgeStatistics.java | 6 +++--- .../store/AbstractMessageStoreStatistics.java | 5 +++-- .../apache/activemq/store/MessageStoreStatistics.java | 5 +++-- .../activemq/store/PersistenceAdapterStatistics.java | 11 +++++------ 8 files changed, 26 insertions(+), 28 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/ConnectionStatistics.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/ConnectionStatistics.java index 38eddb96dd4..b7cc8ac3ac1 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/ConnectionStatistics.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/ConnectionStatistics.java @@ -17,6 +17,8 @@ package org.apache.activemq.broker.region; +import java.util.Set; + import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.StatsImpl; @@ -35,8 +37,7 @@ public ConnectionStatistics() { enqueues = new CountStatisticImpl("enqueues", "The number of messages that have been sent to the connection"); dequeues = new CountStatisticImpl("dequeues", "The number of messages that have been dispatched from the connection"); - addStatistic("enqueues", enqueues); - addStatistic("dequeues", dequeues); + addStatistics(Set.of(enqueues, dequeues)); } public CountStatisticImpl getEnqueues() { diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/ConnectorStatistics.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/ConnectorStatistics.java index 11a15358bdf..874bd4a8f8c 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/ConnectorStatistics.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/ConnectorStatistics.java @@ -17,6 +17,8 @@ package org.apache.activemq.broker.region; +import java.util.Set; + import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.PollCountStatisticImpl; import org.apache.activemq.management.StatsImpl; @@ -42,11 +44,7 @@ public ConnectorStatistics() { messages = new CountStatisticImpl("messages", "The number of messages that that are being held by the destination"); messagesCached = new PollCountStatisticImpl("messagesCached", "The number of messages that are held in the destination's memory cache"); - addStatistic("enqueues", enqueues); - addStatistic("dequeues", dequeues); - addStatistic("consumers", consumers); - addStatistic("messages", messages); - addStatistic("messagesCached", messagesCached); + addStatistics(Set.of(enqueues, dequeues, consumers, messages, messagesCached)); } public CountStatisticImpl getEnqueues() { diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/RegionStatistics.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/RegionStatistics.java index d39a4f12142..7d88fed60c0 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/RegionStatistics.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/RegionStatistics.java @@ -17,6 +17,8 @@ package org.apache.activemq.broker.region; +import java.util.Set; + import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.StatsImpl; @@ -41,9 +43,7 @@ public RegionStatistics(boolean enabled) { destinations = new CountStatisticImpl("destinations", "The number of regular (non-adivsory) destinations in the region"); allDestinations = new CountStatisticImpl("allDestinations", "The total number of destinations, including advisory destinations, in the region"); - addStatistic("advisoryDestinations", advisoryDestinations); - addStatistic("destinations", destinations); - addStatistic("allDestinations", allDestinations); + addStatistics(Set.of(advisoryDestinations, destinations, allDestinations)); this.setEnabled(enabled); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/SubscriptionStatistics.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/SubscriptionStatistics.java index d6a276e5d18..fc9c18da9e2 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/SubscriptionStatistics.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/SubscriptionStatistics.java @@ -17,6 +17,8 @@ package org.apache.activemq.broker.region; +import java.util.Set; + import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.SizeStatisticImpl; import org.apache.activemq.management.StatsImpl; @@ -45,11 +47,7 @@ public SubscriptionStatistics(boolean enabled) { dequeues = new CountStatisticImpl("dequeues", "The number of messages that have been acknowledged from the subscription"); inflightMessageSize = new SizeStatisticImpl("inflightMessageSize", "The size in bytes of messages dispatched but awaiting acknowledgement"); - addStatistic("consumedCount", consumedCount); - addStatistic("enqueues", enqueues); - addStatistic("dispatched", dispatched); - addStatistic("dequeues", dequeues); - addStatistic("inflightMessageSize", inflightMessageSize); + addStatistics(Set.of(consumedCount, enqueues, dispatched, dequeues, inflightMessageSize)); this.setEnabled(enabled); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/network/NetworkBridgeStatistics.java b/activemq-broker/src/main/java/org/apache/activemq/network/NetworkBridgeStatistics.java index 50c39512798..7271750de75 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/network/NetworkBridgeStatistics.java +++ b/activemq-broker/src/main/java/org/apache/activemq/network/NetworkBridgeStatistics.java @@ -17,6 +17,8 @@ package org.apache.activemq.network; +import java.util.Set; + import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.StatsImpl; @@ -34,9 +36,7 @@ public NetworkBridgeStatistics() { dequeues = new CountStatisticImpl("dequeues", "The current number of dequeues this bridge has, which is the number of messages received by the remote broker."); receivedCount = new CountStatisticImpl("receivedCount", "The number of messages that have been received by the NetworkBridge from the remote broker. Only applies for Duplex bridges."); - addStatistic("enqueues", enqueues); - addStatistic("dequeues", dequeues); - addStatistic("receivedCount", receivedCount); + addStatistics(Set.of(enqueues, dequeues, receivedCount)); } /** diff --git a/activemq-broker/src/main/java/org/apache/activemq/store/AbstractMessageStoreStatistics.java b/activemq-broker/src/main/java/org/apache/activemq/store/AbstractMessageStoreStatistics.java index 249b767285a..38d803f0903 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/store/AbstractMessageStoreStatistics.java +++ b/activemq-broker/src/main/java/org/apache/activemq/store/AbstractMessageStoreStatistics.java @@ -17,6 +17,8 @@ package org.apache.activemq.store; +import java.util.Set; + import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.SizeStatisticImpl; import org.apache.activemq.management.StatsImpl; @@ -37,8 +39,7 @@ protected AbstractMessageStoreStatistics(boolean enabled, String countDescriptio messageCount = new CountStatisticImpl("messageCount", countDescription); messageSize = new SizeStatisticImpl("messageSize", sizeDescription); - addStatistic("messageCount", messageCount); - addStatistic("messageSize", messageSize); + addStatistics(Set.of(messageCount, messageSize)); this.setEnabled(enabled); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/store/MessageStoreStatistics.java b/activemq-broker/src/main/java/org/apache/activemq/store/MessageStoreStatistics.java index 0a2b0216100..a06a60e65fc 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/store/MessageStoreStatistics.java +++ b/activemq-broker/src/main/java/org/apache/activemq/store/MessageStoreStatistics.java @@ -17,6 +17,8 @@ package org.apache.activemq.store; +import java.util.Set; + import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.SizeStatisticImpl; import org.apache.activemq.management.StatsImpl; @@ -39,8 +41,7 @@ public MessageStoreStatistics(boolean enabled) { messageCount = new CountStatisticImpl("messageCount", "The number of messages in the store passing through the destination"); messageSize = new SizeStatisticImpl("messageSize","Size of messages in the store passing through the destination"); - addStatistic("messageCount", messageCount); - addStatistic("messageSize", messageSize); + addStatistics(Set.of(messageCount, messageSize)); this.setEnabled(enabled); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/store/PersistenceAdapterStatistics.java b/activemq-broker/src/main/java/org/apache/activemq/store/PersistenceAdapterStatistics.java index 23a112cacf4..59284929c9c 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/store/PersistenceAdapterStatistics.java +++ b/activemq-broker/src/main/java/org/apache/activemq/store/PersistenceAdapterStatistics.java @@ -16,6 +16,8 @@ */ package org.apache.activemq.store; +import java.util.Set; + import org.apache.activemq.management.StatsImpl; import org.apache.activemq.management.TimeStatisticImpl; @@ -31,14 +33,11 @@ public PersistenceAdapterStatistics() { slowCleanupTime = new TimeStatisticImpl("slowCleanupTime", "Slow time to cleanup data in the PersistentAdapter."); slowWriteTime = new TimeStatisticImpl("slowWriteTime", "Slow time to write data to the PersistentAdapter."); slowReadTime = new TimeStatisticImpl("slowReadTime", "Slow time to read data from the PersistentAdapter."); - addStatistic("slowCleanupTime", slowCleanupTime); - addStatistic("slowWriteTime", slowWriteTime); - addStatistic("slowReadTime", slowReadTime); - + addStatistics(Set.of(slowCleanupTime, slowWriteTime, slowReadTime)); + writeTime = new TimeStatisticImpl("writeTime", "Time to write data to the PersistentAdapter."); readTime = new TimeStatisticImpl("readTime", "Time to read data from the PersistentAdapter."); - addStatistic("writeTime", writeTime); - addStatistic("readTime", readTime); + addStatistics(Set.of(writeTime, readTime)); } public void addSlowCleanupTime(final long time) {