2 * Copyright (c) 2020 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
9 package org.opendaylight.openflowplugin.applications.frm;
11 import java.lang.management.ManagementFactory;
12 import javax.inject.Inject;
13 import javax.management.InstanceAlreadyExistsException;
14 import javax.management.MBeanRegistrationException;
15 import javax.management.MBeanServer;
16 import javax.management.MalformedObjectNameException;
17 import javax.management.NotCompliantMBeanException;
18 import javax.management.ObjectName;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public final class ReconciliationJMXAgent {
23 private static final Logger LOG = LoggerFactory.getLogger(ReconciliationJMXAgent.class);
24 private static final String OF_RECONC_BEANNAME
25 = "org.opendaylight.openflowplugin.frm:type=ReconciliationState";
26 private MBeanServer mbs = null;
27 private ObjectName objectName = null;
30 public ReconciliationJMXAgent(final ReconciliationJMXService reconciliationJMXService) {
31 mbs = ManagementFactory.getPlatformMBeanServer();
33 objectName = new ObjectName(OF_RECONC_BEANNAME);
34 registerReconciliationMbean(reconciliationJMXService);
35 } catch (MalformedObjectNameException e) {
36 LOG.error("ObjectName instance creation failed for Mbean {} : ", OF_RECONC_BEANNAME, e);
40 public void registerReconciliationMbean(ReconciliationJMXService reconciliationJMXService) {
42 // Uniquely identify the MBeans and register them with the platform MBeanServer
43 if (!mbs.isRegistered(objectName)) {
44 mbs.registerMBean(reconciliationJMXService, objectName);
45 LOG.debug("Registered Mbean {} successfully", OF_RECONC_BEANNAME);
47 } catch (MBeanRegistrationException | InstanceAlreadyExistsException | NotCompliantMBeanException e) {
48 LOG.error("Registeration failed for Mbean {} : ", OF_RECONC_BEANNAME , e);