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=20e26f6508513a70c60694586e8351e9e84709bc;hp=bd6f6fa884fe0521bff93d8e0fc665e78c529dd7;hb=73e969cf365dd78772596c71e940ae44fe2f22d3;hpb=cf000a86e871a4acf98cf15ba31ce140e6c0f262 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 bd6f6fa884..20e26f6508 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 @@ -15,9 +15,9 @@ 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; @@ -45,9 +45,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 +97,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(); @@ -164,13 +188,13 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { } @Override - public void saveServiceReference(String serviceInterfaceName, String refName, ObjectName objectName) throws InstanceNotFoundException { - configTransactionControllerMXBeanProxy.saveServiceReference(serviceInterfaceName,refName,objectName); + public ObjectName saveServiceReference(String serviceInterfaceName, String refName, ObjectName moduleON) throws InstanceNotFoundException { + return configTransactionControllerMXBeanProxy.saveServiceReference(serviceInterfaceName,refName, moduleON); } @Override - public boolean removeServiceReference(String serviceInterfaceName, String refName) { - return configTransactionControllerMXBeanProxy.removeServiceReference(serviceInterfaceName, refName); + public void removeServiceReference(String serviceInterfaceName, String refName) throws InstanceNotFoundException{ + configTransactionControllerMXBeanProxy.removeServiceReference(serviceInterfaceName, refName); } @Override @@ -179,8 +203,8 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { } @Override - public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceName, String refName) { - return configTransactionControllerMXBeanProxy.lookupConfigBeanByServiceInterfaceName(serviceInterfaceName, refName); + public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceQName, String refName) { + return configTransactionControllerMXBeanProxy.lookupConfigBeanByServiceInterfaceName(serviceInterfaceQName, refName); } @Override @@ -189,8 +213,8 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { } @Override - public Map lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceName) { - return configTransactionControllerMXBeanProxy.lookupServiceReferencesByServiceInterfaceName(serviceInterfaceName); + public Map lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) { + return configTransactionControllerMXBeanProxy.lookupServiceReferencesByServiceInterfaceName(serviceInterfaceQName); } @Override @@ -208,23 +232,39 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { return configTransactionControllerMXBeanProxy.removeServiceReferences(objectName); } + @Override + public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException { + return configTransactionControllerMXBeanProxy.getServiceReference(serviceInterfaceQName, refName); + } + + @Override + public void checkServiceReferenceExists(ObjectName objectName) throws InstanceNotFoundException { + configTransactionControllerMXBeanProxy.checkServiceReferenceExists(objectName); + } + @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); @@ -233,4 +273,24 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient { + attrName + " for " + on, e); } } + + @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 Set getAvailableModuleFactoryQNames() { + return configTransactionControllerMXBeanProxy.getAvailableModuleFactoryQNames(); + } }