Bump versions by 0.1.0 for next dev cycle
[vpnservice.git] / itm / itm-impl / src / main / java / org / opendaylight / vpnservice / itm / snd / ITMStatusMonitor.java
1 /*
2  * Copyright (c) 2015 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.itm.snd;
9
10 import java.lang.management.ManagementFactory;
11 import javax.management.InstanceAlreadyExistsException;
12 import javax.management.MBeanRegistrationException;
13 import javax.management.MBeanServer;
14 import javax.management.MalformedObjectNameException;
15 import javax.management.NotCompliantMBeanException;
16 import javax.management.ObjectName;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class ITMStatusMonitor implements ITMStatusMonitorMBean {
21
22
23     private String serviceStatus;
24     private static ITMStatusMonitor itmStatusMonitor = new ITMStatusMonitor();
25     private static final String JMX_ITM_OBJ_NAME = "com.ericsson.sdncp.services.status:type=SvcItmService";
26     private static final Logger log = LoggerFactory.getLogger(ITMStatusMonitor.class);
27
28     private ITMStatusMonitor () {
29     }
30
31     public void registerMbean() {
32         MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
33         try {
34             ObjectName objName = new ObjectName(JMX_ITM_OBJ_NAME);
35             mbs.registerMBean(itmStatusMonitor, objName);
36             log.info("itm MXBean registration SUCCESSFUL!!! {}", JMX_ITM_OBJ_NAME);
37         } catch (InstanceAlreadyExistsException iaeEx) {
38             log.error("itm MXBean registration FAILED with InstanceAlreadyExistsException", iaeEx);
39         } catch (MBeanRegistrationException mbrEx) {
40             log.error("itm MXBean registration FAILED with MBeanRegistrationException", mbrEx);
41         } catch (NotCompliantMBeanException ncmbEx) {
42             log.error("itm MXBean registration FAILED with NotCompliantMBeanException", ncmbEx);
43         } catch (MalformedObjectNameException monEx) {
44             log.error("itm MXBean registration failed with MalformedObjectNameException", monEx);
45         }
46     }
47
48     public static ITMStatusMonitor getInstance() {
49         return itmStatusMonitor;
50     }
51
52     @Override
53     public String acquireServiceStatus() {
54         return serviceStatus;
55     }
56
57     public void reportStatus (String serviceStatus) {
58         this.serviceStatus = serviceStatus;
59     }
60
61
62 }