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..9ff31ae5e40 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 @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.activemq.broker.region; import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.StatsImpl; +import java.util.Set; + /** * The J2EE Statistics for the Connection. * @@ -35,8 +36,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..1176e91a37a 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 @@ -14,13 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.activemq.broker.region; import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.PollCountStatisticImpl; import org.apache.activemq.management.StatsImpl; +import java.util.Set; + /** * The J2EE Statistics for the a Destination. * @@ -42,11 +43,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..db61e34a0ae 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 @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.activemq.broker.region; import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.StatsImpl; +import java.util.Set; + /** * The J2EE Statistics for the Connection. * @@ -41,10 +42,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..449ed997da1 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 @@ -14,13 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.activemq.broker.region; import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.SizeStatisticImpl; import org.apache.activemq.management.StatsImpl; +import java.util.Set; + /** * The J2EE Statistics for a Subsription. */ @@ -32,7 +33,6 @@ public class SubscriptionStatistics extends StatsImpl { protected CountStatisticImpl dispatched; protected SizeStatisticImpl inflightMessageSize; - public SubscriptionStatistics() { this(true); } @@ -45,12 +45,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..a9157dcbd1a 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 @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.activemq.network; import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.StatsImpl; +import java.util.Set; + /** * The Statistics for a NetworkBridge. */ @@ -34,9 +35,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..08913eb8b88 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 @@ -21,13 +21,14 @@ import org.apache.activemq.management.SizeStatisticImpl; import org.apache.activemq.management.StatsImpl; +import java.util.Set; + public abstract class AbstractMessageStoreStatistics extends StatsImpl { protected final CountStatisticImpl messageCount; protected final SizeStatisticImpl messageSize; - protected AbstractMessageStoreStatistics(String countDescription, String sizeDescription) { this(true, countDescription, sizeDescription); } @@ -37,9 +38,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..881625b499e 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 @@ -14,13 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.activemq.store; import org.apache.activemq.management.CountStatisticImpl; import org.apache.activemq.management.SizeStatisticImpl; import org.apache.activemq.management.StatsImpl; +import java.util.Set; + /** * The J2EE Statistics for a Message Sore */ @@ -39,9 +40,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..8a5e1bb6f81 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,7 @@ */ package org.apache.activemq.store; +import java.util.Set; import org.apache.activemq.management.StatsImpl; import org.apache.activemq.management.TimeStatisticImpl; @@ -31,14 +32,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); - + 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(slowCleanupTime, slowWriteTime, slowReadTime, writeTime, readTime)); } public void addSlowCleanupTime(final long time) { diff --git a/activemq-client/src/main/java/org/apache/activemq/management/StatsImpl.java b/activemq-client/src/main/java/org/apache/activemq/management/StatsImpl.java index 46d24a685f2..05f1d2ad8f8 100644 --- a/activemq-client/src/main/java/org/apache/activemq/management/StatsImpl.java +++ b/activemq-client/src/main/java/org/apache/activemq/management/StatsImpl.java @@ -59,11 +59,11 @@ protected synchronized void addStatistic(String name, StatisticImpl statistic) { this.set.add(statistic); } - protected void addStatistics(Collection statistics) { + protected void addStatistics(final Collection statistics) { this.set.addAll(statistics); } - protected void removeStatistics(Collection statistics) { + protected void removeStatistics(final Collection statistics) { this.set.removeAll(statistics); } }