Merge "L2 Gw create changes related to ITM Tunnels creation in neutronvpn module"
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / statusanddiag / InterfaceStatusMonitor.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.vpnservice.interfacemgr.statusanddiag;
9
10 import java.lang.management.ManagementFactory;
11
12 import javax.management.InstanceAlreadyExistsException;
13 import javax.management.MBeanRegistrationException;
14 import javax.management.MBeanServer;
15 import javax.management.MalformedObjectNameException;
16 import javax.management.NotCompliantMBeanException;
17 import javax.management.ObjectName;
18
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class InterfaceStatusMonitor implements InterfaceStatusMonitorMBean{
23
24     private String serviceStatus;
25     private static InterfaceStatusMonitor interfaceStatusMonitor = new InterfaceStatusMonitor();
26     private static final String JMX_INTERFACE_OBJ_NAME = "com.ericsson.sdncp.services.status:type=SvcInterfaceService";
27     private static final Logger log = LoggerFactory.getLogger(InterfaceStatusMonitor.class);
28
29     private InterfaceStatusMonitor () {
30     }
31
32     public void registerMbean() {
33         MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
34         try {
35             ObjectName objName = new ObjectName(JMX_INTERFACE_OBJ_NAME);
36             log.debug("MXBean Object-Name framed");
37             mbs.registerMBean(interfaceStatusMonitor, objName);
38             log.info("MXBean registration SUCCESSFUL!!! {}", JMX_INTERFACE_OBJ_NAME);
39         } catch (InstanceAlreadyExistsException iaeEx) {
40             log.error("MXBean registration FAILED with InstanceAlreadyExistsException", iaeEx);
41         } catch (MBeanRegistrationException mbrEx) {
42             log.error("MXBean registration FAILED with MBeanRegistrationException", mbrEx);
43         } catch (NotCompliantMBeanException ncmbEx) {
44             log.error("MXBean registration FAILED with NotCompliantMBeanException", ncmbEx);
45         } catch (MalformedObjectNameException monEx) {
46             log.error("MXBean registration failed with MalformedObjectNameException", monEx);
47         }
48     }
49
50     public static InterfaceStatusMonitor getInstance() {
51         return interfaceStatusMonitor;
52     }
53
54     @Override
55     public String acquireServiceStatus() {
56         return serviceStatus;
57     }
58
59     public void reportStatus (String serviceStatus) {
60         this.serviceStatus = serviceStatus;
61     }
62 }