Bug 1446: Add JMX stats for in-memory data store
[controller.git] / opendaylight / md-sal / sal-common-util / src / main / java / org / opendaylight / controller / md / sal / common / util / jmx / QueuedNotificationManagerMXBeanImpl.java
diff --git a/opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/QueuedNotificationManagerMXBeanImpl.java b/opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/QueuedNotificationManagerMXBeanImpl.java
new file mode 100644 (file)
index 0000000..e6148fc
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.controller.md.sal.common.util.jmx;
+
+import java.util.List;
+
+import org.opendaylight.yangtools.util.concurrent.ListenerNotificationQueueStats;
+import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Implementation of the QueuedNotificationManagerMXBean interface.
+ *
+ * <p>
+ * This class is not intended for use outside of MD-SAL and its part of private
+ * implementation (still exported as public to be reused across MD-SAL implementation
+ * components) and may be removed in subsequent
+ * releases.
+ *
+ * @author Thomas Pantelis
+ */
+public class QueuedNotificationManagerMXBeanImpl extends AbstractMXBean
+                                                 implements QueuedNotificationManagerMXBean {
+
+    private final QueuedNotificationManager<?,?> manager;
+
+    public QueuedNotificationManagerMXBeanImpl( QueuedNotificationManager<?,?> manager,
+            String mBeanName, String mBeanType, String mBeanCategory ) {
+        super(mBeanName, mBeanType, mBeanCategory);
+        this.manager = Preconditions.checkNotNull( manager );
+    }
+
+    @Override
+    public List<ListenerNotificationQueueStats> getCurrentListenerQueueStats() {
+        return manager.getListenerNotificationQueueStats();
+    }
+
+    @Override
+    public int getMaxListenerQueueSize() {
+        return manager.getMaxQueueCapacity();
+    }
+
+    public QueuedNotificationManagerStats toQueuedNotificationManagerStats() {
+        return new QueuedNotificationManagerStats( getMaxListenerQueueSize(),
+                getCurrentListenerQueueStats() );
+    }
+}