HwVTEP support for interfacemanager
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / statusanddiag / InterfaceStatusMonitor.java
diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/statusanddiag/InterfaceStatusMonitor.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/statusanddiag/InterfaceStatusMonitor.java
new file mode 100644 (file)
index 0000000..b1bd942
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.vpnservice.interfacemgr.statusanddiag;
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InterfaceStatusMonitor implements InterfaceStatusMonitorMBean{
+
+    private String serviceStatus;
+    private static InterfaceStatusMonitor interfaceStatusMonitor = new InterfaceStatusMonitor();
+    private static final String JMX_INTERFACE_OBJ_NAME = "com.ericsson.sdncp.services.status:type=SvcInterfaceService";
+    private static final Logger log = LoggerFactory.getLogger(InterfaceStatusMonitor.class);
+
+    private InterfaceStatusMonitor () {
+    }
+
+    public void registerMbean() {
+        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        try {
+            ObjectName objName = new ObjectName(JMX_INTERFACE_OBJ_NAME);
+            log.debug("MXBean Object-Name framed");
+            mbs.registerMBean(interfaceStatusMonitor, objName);
+            log.info("MXBean registration SUCCESSFUL!!! {}", JMX_INTERFACE_OBJ_NAME);
+        } catch (InstanceAlreadyExistsException iaeEx) {
+            log.error("MXBean registration FAILED with InstanceAlreadyExistsException", iaeEx);
+        } catch (MBeanRegistrationException mbrEx) {
+            log.error("MXBean registration FAILED with MBeanRegistrationException", mbrEx);
+        } catch (NotCompliantMBeanException ncmbEx) {
+            log.error("MXBean registration FAILED with NotCompliantMBeanException", ncmbEx);
+        } catch (MalformedObjectNameException monEx) {
+            log.error("MXBean registration failed with MalformedObjectNameException", monEx);
+        }
+    }
+
+    public static InterfaceStatusMonitor getInstance() {
+        return interfaceStatusMonitor;
+    }
+
+    @Override
+    public String acquireServiceStatus() {
+        return serviceStatus;
+    }
+
+    public void reportStatus (String serviceStatus) {
+        this.serviceStatus = serviceStatus;
+    }
+}