From 082f5e042cba52a4b9e752c8faf33f4563912c11 Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Sun, 11 Jun 2023 10:07:08 -0700 Subject: [PATCH] Fixes #6140 - JMX total number of keys in SelectorManager Added a new JMX property in SelectorManager that reports total number of keys from all ManagedSelectors Co-authored-by: Simone Bordet --- .../org/eclipse/jetty/io/SelectorManager.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java index 2b89d7befa0..ad35aa2f388 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java @@ -139,6 +139,23 @@ public abstract class SelectorManager extends ContainerLifeCycle implements Dump executor.execute(task); } + /** + * Get total number of keys from each selector. + * + * @return total number of selector keys + */ + @ManagedAttribute(value = "Total number of keys in all selectors", readonly = true) + public int getTotalKeys() + { + int keys = 0; + for (final ManagedSelector selector : _selectors) + { + keys += selector.getTotalKeys(); + } + return keys; + } + + /** * @return the number of selectors in use */ @@ -506,4 +523,10 @@ public abstract class SelectorManager extends ContainerLifeCycle implements Dump { } } + + @Override + public String toString() + { + return String.format("%s@%x[keys=%d]", getClass().getSimpleName(), hashCode(), getTotalKeys()); + } }