X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdynamicmbean%2FAbstractDynamicWrapper.java;h=25f7e2de9f425e4124e4ae0cd2a1233efbfca0cc;hp=d868f7c3321dd8ee9b0c28697d2c0c8b43c60fd5;hb=0e74e5866c506da072cae3a2897335df7170f958;hpb=597ffbbfe362fcea479b7fdb52f685289b7ea5fd diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java index d868f7c332..25f7e2de9f 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java @@ -7,8 +7,6 @@ */ package org.opendaylight.controller.config.manager.impl.dynamicmbean; -import static java.lang.String.format; - import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.ArrayList; @@ -49,8 +47,6 @@ import org.opendaylight.controller.config.spi.Module; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static java.lang.String.format; - /** * Contains common code for readable/rw dynamic mbean wrappers. Routes all * requests (getAttribute, setAttribute, invoke) into the actual instance, but @@ -61,14 +57,12 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { private static final class ModuleNotificationListener implements NotificationListener { private final ObjectName objectNameInternal; private final MBeanServer internalServer; - private final ObjectName thisWrapperObjectName; private final MBeanServer configMBeanServer; private ModuleNotificationListener(final ObjectName objectNameInternal, final MBeanServer internalServer, - final ObjectName thisWrapperObjectName, final MBeanServer configMBeanServer) { + final MBeanServer configMBeanServer) { this.objectNameInternal = objectNameInternal; this.internalServer = internalServer; - this.thisWrapperObjectName = thisWrapperObjectName; this.configMBeanServer = configMBeanServer; } @@ -76,25 +70,23 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { public void handleNotification(final Notification n, final Object handback) { if (n instanceof MBeanServerNotification && n.getType() - .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) { - if (((MBeanServerNotification) n).getMBeanName().equals( - thisWrapperObjectName)) { - try { - internalServer.unregisterMBean(objectNameInternal); - configMBeanServer.removeNotificationListener( - MBeanServerDelegate.DELEGATE_NAME, this); - } catch (MBeanRegistrationException - | ListenerNotFoundException - | InstanceNotFoundException e) { - throw new IllegalStateException(e); - } + .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION) + && ((MBeanServerNotification) n).getMBeanName().equals( + objectNameInternal)) { + try { + internalServer.unregisterMBean(objectNameInternal); + configMBeanServer.removeNotificationListener( + MBeanServerDelegate.DELEGATE_NAME, this); + } catch (MBeanRegistrationException + | ListenerNotFoundException + | InstanceNotFoundException e) { + throw new IllegalStateException(e); } } } } private static final Logger LOG = LoggerFactory.getLogger(AbstractDynamicWrapper.class); - protected final boolean writable; protected final Module module; private final MBeanInfo mbeanInfo; @@ -108,20 +100,17 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { final ObjectName thisWrapperObjectName, final MBeanOperationInfo[] dOperations, final MBeanServer internalServer, final MBeanServer configMBeanServer) { - this.writable = writable; this.module = module; this.moduleIdentifier = moduleIdentifier; this.internalServer = internalServer; this.objectNameInternal = thisWrapperObjectName; // register the actual instance into an mbean server. - registerActualModule(module, thisWrapperObjectName, objectNameInternal, - internalServer, configMBeanServer); + registerActualModule(objectNameInternal, configMBeanServer); Set> jmxInterfaces = InterfacesHelper.getMXInterfaces(module .getClass()); - this.attributeHolderMap = buildMBeanInfo(module, writable, - moduleIdentifier, jmxInterfaces, internalServer, - objectNameInternal); - this.mbeanInfo = generateMBeanInfo(module.getClass().getName(), module, + this.attributeHolderMap = buildMBeanInfo(writable, + moduleIdentifier, jmxInterfaces, objectNameInternal); + this.mbeanInfo = generateMBeanInfo(module, attributeHolderMap, dOperations, jmxInterfaces); } @@ -130,12 +119,8 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { * platform mbean server. Wait until this wrapper gets unregistered, in that * case unregister the module and remove listener. */ - private final NotificationListener registerActualModule(final Module module, - final ObjectName thisWrapperObjectName, - final ObjectName objectNameInternal, - final MBeanServer internalServer, + private final NotificationListener registerActualModule(final ObjectName objectNameInternal, final MBeanServer configMBeanServer) { - try { internalServer.registerMBean(module, objectNameInternal); } catch (InstanceAlreadyExistsException | MBeanRegistrationException @@ -144,7 +129,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { "Error occured during mbean registration with name " + objectNameInternal, e); } - NotificationListener listener = new ModuleNotificationListener(objectNameInternal, internalServer, thisWrapperObjectName, configMBeanServer); + NotificationListener listener = new ModuleNotificationListener(objectNameInternal, internalServer, configMBeanServer); try { configMBeanServer.addNotificationListener( MBeanServerDelegate.DELEGATE_NAME, listener, null, null); @@ -154,7 +139,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { return listener; } - private static MBeanInfo generateMBeanInfo(final String className, final Module module, + private static MBeanInfo generateMBeanInfo(final Module module, final Map attributeHolderMap, final MBeanOperationInfo[] dOperations, final Set> jmxInterfaces) { @@ -165,7 +150,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { for (AttributeHolder attributeHolder : attributeHolderMap.values()) { attributes.add(attributeHolder.toMBeanAttributeInfo()); } - return new MBeanInfo(className, dDescription, + return new MBeanInfo(module.getClass().getName(), dDescription, attributes.toArray(new MBeanAttributeInfo[0]), dConstructors, dOperations, new MBeanNotificationInfo[0]); } @@ -182,9 +167,8 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { // inspect all exported interfaces ending with MXBean, extract getters & // setters into attribute holder - private static Map buildMBeanInfo(final Module module, - final boolean writable, final ModuleIdentifier moduleIdentifier, - final Set> jmxInterfaces, final MBeanServer internalServer, + private Map buildMBeanInfo(final boolean writable, final ModuleIdentifier moduleIdentifier, + final Set> jmxInterfaces, final ObjectName internalObjectName) { // internal variables for describing MBean elements @@ -207,7 +191,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { for (MBeanAttributeInfo a : internalInfo.getAttributes()) { attributeMap.put(a.getName(), a); } - Map attributeHolderMap = new HashMap<>(); + Map attributeHolderMapLocal = new HashMap<>(); for (Method method : methods) { if (method.getParameterTypes().length == 1 @@ -231,10 +215,10 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { AttributeHolder attributeHolder = new AttributeHolder( attribName, module, attributeMap.get(attribName) .getType(), writable, ifc, description); - attributeHolderMap.put(attribName, attributeHolder); + attributeHolderMapLocal.put(attribName, attributeHolder); } } - return attributeHolderMap; + return attributeHolderMapLocal; } // DynamicMBean methods @@ -278,14 +262,14 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { } private Object fixDependencyListAttribute(final Object attribute) { - if (attribute.getClass().isArray() == false) { + if (!attribute.getClass().isArray()) { throw new IllegalArgumentException("Unexpected attribute type, should be an array, but was " + attribute.getClass()); } for (int i = 0; i < Array.getLength(attribute); i++) { Object on = Array.get(attribute, i); - if (on instanceof ObjectName == false) { + if (!(on instanceof ObjectName)) { throw new IllegalArgumentException("Unexpected attribute type, should be an ObjectName, but was " + on.getClass()); } on = fixObjectName((ObjectName) on); @@ -297,7 +281,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { } private boolean isDependencyListAttr(final String attributeName, final Object attribute) { - if (attributeHolderMap.containsKey(attributeName) == false) { + if (!attributeHolderMap.containsKey(attributeName)) { return false; } @@ -318,9 +302,9 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { String transactionName = ObjectNameUtil.getTransactionName(on); if (transactionName != null) { return ObjectNameUtil.withoutTransactionName(on); - } else { - return on; } + + return on; } @Override @@ -358,7 +342,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { } else { LOG.debug("Operation not found {} ", actionName); throw new UnsupportedOperationException( - format("Operation not found on %s. Method invoke is only supported for getInstance and getAttribute(s) " + String.format("Operation not found on %s. Method invoke is only supported for getInstance and getAttribute(s) " + "method, got actionName %s, params %s, signature %s ", moduleIdentifier, actionName, params, signature)); }