Expose QueuedNotificationManager statistics 09/81309/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 29 Mar 2019 09:51:31 +0000 (10:51 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 29 Mar 2019 10:31:02 +0000 (11:31 +0100)
This backports the MXBean defined in the controller project and makes
an implementation of it available through getMXBean().

JIRA: CONTROLLER-653
BUGZILLA: BUG-1446
Change-Id: Ica8dff7aef8989f2b23b1fc8c100a535998273b1
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ListenerNotificationQueueStats.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManagerMXBean.java [new file with mode: 0644]
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManagerMXBeanImpl.java [new file with mode: 0644]

index 50f2ca45a09e1d5fc7a3aaaf7fb613b6921c2d81..17b08a29e46e53d137822700f1764d7a87f5b905 100644 (file)
@@ -5,10 +5,12 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.yangtools.util.concurrent;
 
+import static java.util.Objects.requireNonNull;
+
 import java.beans.ConstructorProperties;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
  * Class used by the {@link QueuedNotificationManager} that contains a snapshot of notification
@@ -17,14 +19,14 @@ import java.beans.ConstructorProperties;
  * @author Thomas Pantelis
  * @see QueuedNotificationManager
  */
+@NonNullByDefault
 public class ListenerNotificationQueueStats {
-
     private final String listenerClassName;
     private final int currentQueueSize;
 
-    @ConstructorProperties({ "listenerClassName","currentQueueSize" })
+    @ConstructorProperties({ "listenerClassName", "currentQueueSize" })
     public ListenerNotificationQueueStats(final String listenerClassName, final int currentQueueSize) {
-        this.listenerClassName = listenerClassName;
+        this.listenerClassName = requireNonNull(listenerClassName);
         this.currentQueueSize = currentQueueSize;
     }
 
index 35ef8bce75861f7a52a8cdb5408cfb23bf5b7333..68055fda957b3c2f7bde722765c2a119a475c86e 100644 (file)
@@ -69,6 +69,7 @@ public final class QueuedNotificationManager<L, N> implements NotificationManage
     private static final long TASK_WAIT_NANOS = TimeUnit.MILLISECONDS.toNanos(10);
 
     private final ConcurrentMap<ListenerKey<L>, NotificationTask> listenerCache = new ConcurrentHashMap<>();
+    private final @NonNull QueuedNotificationManagerMXBean mxBean = new QueuedNotificationManagerMXBeanImpl(this);
     private final @NonNull BatchedInvoker<L, N> listenerInvoker;
     private final @NonNull Executor executor;
     private final @NonNull String name;
@@ -105,6 +106,15 @@ public final class QueuedNotificationManager<L, N> implements NotificationManage
         return maxQueueCapacity;
     }
 
+    /**
+     * Return an {@link QueuedNotificationManagerMXBean} tied to this instance.
+     *
+     * @return An QueuedNotificationManagerMXBean object.
+     */
+    public @NonNull QueuedNotificationManagerMXBean getMXBean() {
+        return mxBean;
+    }
+
     /**
      * Returns the {@link Executor} to used for notification tasks.
      */
diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManagerMXBean.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManagerMXBean.java
new file mode 100644 (file)
index 0000000..41baf5c
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util.concurrent;
+
+import java.util.List;
+
+/**
+ * MXBean interface for {@link QueuedNotificationManager} statistic metrics.
+ *
+ * @author Thomas Pantelis
+ */
+public interface QueuedNotificationManagerMXBean {
+    /**
+     * Returns a list of stat instances for each current listener notification task in progress.
+     */
+    List<ListenerNotificationQueueStats> getCurrentListenerQueueStats();
+
+    /**
+     * Returns the configured maximum listener queue size.
+     */
+    int getMaxListenerQueueSize();
+}
diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManagerMXBeanImpl.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManagerMXBeanImpl.java
new file mode 100644 (file)
index 0000000..c9a2c2d
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util.concurrent;
+
+import static java.util.Objects.requireNonNull;
+
+import java.util.List;
+
+final class QueuedNotificationManagerMXBeanImpl implements QueuedNotificationManagerMXBean {
+    private final QueuedNotificationManager<?, ?> manager;
+
+    QueuedNotificationManagerMXBeanImpl(final QueuedNotificationManager<?, ?> manager) {
+        this.manager = requireNonNull(manager);
+    }
+
+    /**
+     * Returns a list of stat instances for each current listener notification task in progress.
+     */
+    @Override
+    public List<ListenerNotificationQueueStats> getCurrentListenerQueueStats() {
+        return manager.getListenerNotificationQueueStats();
+    }
+
+    /**
+     * Returns the configured maximum listener queue size.
+     */
+    @Override
+    public int getMaxListenerQueueSize() {
+        return manager.getMaxQueueCapacity();
+    }
+}