X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Futil%2FConfigTransactionJMXClient.java;h=26ca1391ad4bf32eea9708e2db47f21cc33bdcfa;hp=e683d915baea604db86b891e81dc9192b203c4aa;hb=5c008222efa5c0af49cf8a52881a6299b1e249dc;hpb=81282cf3711693da7dde667c6bbf18cb40e81ad0 diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionJMXClient.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionJMXClient.java index e683d915ba..26ca1391ad 100644 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionJMXClient.java +++ b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionJMXClient.java @@ -9,16 +9,14 @@ package org.opendaylight.controller.config.util; import java.util.Map; import java.util.Set; - import javax.management.Attribute; import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceNotFoundException; import javax.management.JMException; import javax.management.JMX; +import javax.management.MBeanException; import javax.management.MBeanServer; import javax.management.ObjectName; -import javax.management.RuntimeMBeanException; - import org.opendaylight.controller.config.api.ConflictingVersionException; import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.api.jmx.CommitStatus; @@ -45,9 +43,22 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { } public T newMXBeanProxy(ObjectName on, Class clazz) { - return JMX.newMXBeanProxy(configMBeanServer, on, clazz); - } - + ObjectName onName = on; + // if on is without transaction, add it. Reason is that when using getters on MXBeans the transaction name is stripped + onName = ObjectNameUtil.withTransactionName(onName, getTransactionName()); + // if this is service reference and user requests for implementation, look it up + onName = ConfigRegistryJMXClient.translateServiceRefIfPossible(onName, clazz, configMBeanServer); + onName = ObjectNameUtil.withTransactionName(onName, getTransactionName()); + return JMX.newMXBeanProxy(configMBeanServer, onName, clazz); + } + + /** + * Usage of this method indicates error as config JMX uses solely MXBeans. + * Use {@link #newMXBeanProxy(javax.management.ObjectName, Class)} + * or {@link JMX#newMBeanProxy(javax.management.MBeanServerConnection, javax.management.ObjectName, Class)} + * This method will be removed soon. + */ + @Deprecated public T newMBeanProxy(ObjectName on, Class clazz) { return JMX.newMBeanProxy(configMBeanServer, on, clazz); } @@ -84,12 +95,23 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { } @Override + @Deprecated + /** + * {@inheritDoc} + */ public void destroyConfigBean(String moduleName, String instanceName) throws InstanceNotFoundException { destroyModule(ObjectNameUtil.createTransactionModuleON( getTransactionName(), moduleName, instanceName)); } + @Override + public void destroyModule(String moduleName, String instanceName) + throws InstanceNotFoundException { + destroyModule(ObjectNameUtil.createTransactionModuleON( + getTransactionName(), moduleName, instanceName)); + } + @Override public void abortConfig() { configTransactionControllerMXBeanProxy.abortConfig(); @@ -218,23 +240,49 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { configTransactionControllerMXBeanProxy.checkServiceReferenceExists(objectName); } + @Override + public Attribute getAttribute(ObjectName on, String attrName) { + if (ObjectNameUtil.getTransactionName(on) == null) { + throw new IllegalArgumentException("Not in transaction instance " + + on + ", no transaction name present"); + } + + try { + return new Attribute(attrName, configMBeanServer.getAttribute(on,attrName)); + } catch (JMException e) { + throw new IllegalStateException("Unable to get attribute " + + attrName + " for " + on, e); + } + } + + @Override + public Object getAttributeCurrentValue(ObjectName on, String attrName) { + return getAttribute(on, attrName).getValue(); + } + @Override public void validateBean(ObjectName configBeanON) throws ValidationException { try { configMBeanServer.invoke(configBeanON, "validate", null, null); + } catch (MBeanException e) { + Exception targetException = e.getTargetException(); + if (targetException instanceof ValidationException){ + throw (ValidationException) targetException; + } else { + throw new RuntimeException(e); + } } catch (JMException e) { throw new RuntimeException(e); - } catch (RuntimeMBeanException e) { - throw e.getTargetException(); } } @Override public void setAttribute(ObjectName on, String attrName, Attribute attribute) { - if (ObjectNameUtil.getTransactionName(on) == null) + if (ObjectNameUtil.getTransactionName(on) == null) { throw new IllegalArgumentException("Not in transaction instance " + on + ", no transaction name present"); + } try { configMBeanServer.setAttribute(on, attribute); @@ -248,4 +296,14 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { public Set getAvailableModuleFactoryQNames() { return configTransactionControllerMXBeanProxy.getAvailableModuleFactoryQNames(); } + + @Override + public Set lookupRuntimeBeans() { + return configTransactionControllerMXBeanProxy.lookupRuntimeBeans(); + } + + @Override + public Set lookupRuntimeBeans(final String moduleName, final String instanceName) { + return configTransactionControllerMXBeanProxy.lookupRuntimeBeans(moduleName, instanceName); + } }