2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.genius.itm.snd;
10 import java.lang.management.ManagementFactory;
11 import javax.management.InstanceAlreadyExistsException;
12 import javax.management.InstanceNotFoundException;
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 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class ITMStatusMonitor implements ITMStatusMonitorMBean {
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);
28 private ITMStatusMonitor() {
31 public void registerMbean() {
32 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
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);
48 public void unregisterMbean() {
49 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
51 ObjectName objName = new ObjectName(JMX_ITM_OBJ_NAME);
52 mbs.unregisterMBean(objName);
53 LOG.info("itm MXBean un-registration SUCCESSFUL!!! {}", JMX_ITM_OBJ_NAME);
54 } catch (MalformedObjectNameException e) {
55 LOG.error("itm MXBean un-registration FAILED with MalformedObjectNameException", e);
56 } catch (MBeanRegistrationException e) {
57 LOG.warn("itm MXBean un-registration FAILED with MBeanRegistrationException", e);
58 } catch (InstanceNotFoundException e) {
59 LOG.debug("itm MXBean un-registration FAILED with InstanceNotFoundException", e);
63 public static ITMStatusMonitor getInstance() {
64 return itmStatusMonitor;
68 public String acquireServiceStatus() {
72 public void reportStatus(@SuppressWarnings("hiding") String serviceStatus) {
73 this.serviceStatus = serviceStatus;