*/
package org.opendaylight.controller.config.util;
-import org.opendaylight.controller.config.api.ConflictingVersionException;
-import org.opendaylight.controller.config.api.ValidationException;
-import org.opendaylight.controller.config.api.jmx.CommitStatus;
-import org.opendaylight.controller.config.api.jmx.ConfigRegistryMXBean;
-import org.opendaylight.controller.config.api.jmx.ConfigTransactionControllerMXBean;
-import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
-
+import java.util.Map;
+import java.util.Set;
import javax.management.Attribute;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
-import java.util.Map;
-import java.util.Set;
+import org.opendaylight.controller.config.api.ConflictingVersionException;
+import org.opendaylight.controller.config.api.ValidationException;
+import org.opendaylight.controller.config.api.jmx.CommitStatus;
+import org.opendaylight.controller.config.api.jmx.ConfigRegistryMXBean;
+import org.opendaylight.controller.config.api.jmx.ConfigTransactionControllerMXBean;
+import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
public class ConfigTransactionJMXClient implements ConfigTransactionClient {
private final ConfigRegistryMXBean configRegistryMXBeanProxy;
}
public <T> T newMXBeanProxy(ObjectName on, Class<T> 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> T newMBeanProxy(ObjectName on, Class<T> clazz) {
return JMX.newMBeanProxy(configMBeanServer, on, clazz);
}
return configTransactionControllerMXBeanProxy.createModule(moduleName, instanceName);
}
+ @Override
+ public void reCreateModule(ObjectName objectName) throws InstanceNotFoundException {
+ configTransactionControllerMXBeanProxy.reCreateModule(objectName);
+ }
+
@Override
public void destroyModule(ObjectName objectName)
throws InstanceNotFoundException {
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 {
@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);
public Set<String> getAvailableModuleFactoryQNames() {
return configTransactionControllerMXBeanProxy.getAvailableModuleFactoryQNames();
}
+
+ @Override
+ public Set<ObjectName> lookupRuntimeBeans() {
+ return configTransactionControllerMXBeanProxy.lookupRuntimeBeans();
+ }
+
+ @Override
+ public Set<ObjectName> lookupRuntimeBeans(final String moduleName, final String instanceName) {
+ return configTransactionControllerMXBeanProxy.lookupRuntimeBeans(moduleName, instanceName);
+ }
}