use of javax.management.AttributeNotFoundException in project camel by apache.
the class RestSwaggerSupport method findCamelContexts.
public List<String> findCamelContexts() throws Exception {
List<String> answer = new ArrayList<>();
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> names = server.queryNames(new ObjectName("*:type=context,*"), null);
for (ObjectName on : names) {
String id = on.getKeyProperty("name");
if (id.startsWith("\"") && id.endsWith("\"")) {
id = id.substring(1, id.length() - 1);
}
// filter out older Camel versions as this requires Camel 2.15 or better (rest-dsl)
try {
String version = (String) server.getAttribute(on, "CamelVersion");
if (CamelVersionHelper.isGE("2.15.0", version)) {
answer.add(id);
}
} catch (AttributeNotFoundException ex) {
// ignore
}
}
return answer;
}
use of javax.management.AttributeNotFoundException in project felix by apache.
the class DynamicMBeanImpl method setAttribute.
/**
* Changes specified attribute value.
*
* @param attribute the attribute with new value to be changed
* @throws AttributeNotFoundException if the required attribute was not found
* @throws InvalidAttributeValueException if the value is inccorrect type
* @throws MBeanException if something bad occures
* @throws ReflectionException if something bad occures
*/
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
// Check attribute is not null to avoid NullPointerException later on
if (attribute == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Cannot invoke a setter of " + m_className + " with null attribute");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot invoke the setter of " + m_className + " with null attribute name");
}
// Check for a recognized attribute name and call the corresponding
// setter
//
PropertyField propertyField = (PropertyField) m_configMap.getPropertyFromName(name);
if (propertyField == null) {
// unrecognized attribute name:
throw new AttributeNotFoundException("Attribute " + name + " not found in " + m_className);
}
if (!propertyField.isWritable()) {
throw new InvalidAttributeValueException("Attribute " + name + " can not be set");
}
if (value == null) {
try {
m_instanceManager.onSet(null, propertyField.getField(), null);
} catch (Exception e) {
throw new InvalidAttributeValueException("Cannot set attribute " + name + " to null");
}
} else {
// if non null value, make sure it is assignable to the
// attribute
// if (true /* TODO type.class.isAssignableFrom(value.getClass()) */) {
// propertyField.setValue(value);
// setValue(attributeField.getField(),null);
m_instanceManager.onSet(null, propertyField.getField(), value);
// } else {
// throw new InvalidAttributeValueException(
// "Cannot set attribute " + name + " to a "
// + value.getClass().getName()
// + " object, String expected");
// }
}
}
use of javax.management.AttributeNotFoundException in project felix by apache.
the class NodePanel method startMBeanTabBundles.
private void startMBeanTabBundles(String connString, MBeanServerConnection mbsc) {
try {
this.clean();
// ioe
Set set_on = mbsc.queryNames(null, null);
Object[] ons = set_on.toArray();
int oldUnstartedBundleNbr = 0;
do {
Vector v_unstartedBundle = new Vector();
oldUnstartedBundleNbr = ons.length;
for (int i = 0; i < ons.length; i++) {
ObjectName name = (ObjectName) ons[i];
if ("TabUI".equals(name.getDomain())) {
/* Get the plugin implementation via a bundle */
try {
// mbe, anfe, be, infe, re
String tabBundle = (String) mbsc.getAttribute(name, "BundleName");
if (tabBundle != null) {
Plugin p = (Plugin) this.pluginList.get(tabBundle);
if (p == null) {
// be
Bundle b = m_context.installBundle(tabBundle);
try {
// be2
b.start();
System.out.println(" - Bundle started: \"" + name.toString() + "\" - " + tabBundle);
} catch (BundleException be2) {
// be2
System.out.println(" - Unable to start: \"" + name.toString() + "\" - " + tabBundle);
be2.printStackTrace();
v_unstartedBundle.add(name);
}
} else {
System.out.println(" - Register service plugin: " + p);
p.registerServicePlugin();
}
/* ServiceReference[] sr = b.getRegisteredServices();
* System.out.println(sr);
* Plugin p;
* for (int j=0 ; j < sr.length ; j++) {
* p=(Plugin)m_context.getService(sr[j]);
* this.add(p.getName(), p.getGUI());
* this.a.addPropertyChangeListener(p);
* }
*
* System.out.println("Delegation for this");
* printcl = this.getClass().getClassLoader();
* while (printcl != null) {
* System.out.println(printcl);
* printcl = printcl.getParent();
* }
* System.out.println("{bootstrap loader}");
* System.out.println("");
*
* // Get the tab object
* Object tabObj = mbsc.getAttribute(name, "Tab");
*
* System.out.println("Delegation for tabObj: " + tabObj);
* printcl = tabObj.getClass().getClassLoader();
* while (printcl != null) {
* System.out.println(printcl);
* printcl = printcl.getParent();
* }
* System.out.println("{bootstrap loader}");
* System.out.println("");
*
* System.out.println("tabObj.getName(): " + ((fr.inria.ares.managedelements.testprobe.tab.TestProbeTabUI) tabObj).getName());
*
* // Cast the tab
* Plugin tab = (Plugin)tabObj;
* // register the tab on the JTabbedPane
* this.add(tab.getName(), tab.getGUI());
*/
} else {
System.out.println(" - No bundleName attribute defined for \"" + name.toString() + "\". I cannot install tab");
}
} catch (MBeanException mbe) {
// mbe
mbe.printStackTrace();
} catch (AttributeNotFoundException anfe) {
// anfe
anfe.printStackTrace();
} catch (BundleException be) {
// be
be.printStackTrace();
} catch (InstanceNotFoundException infe) {
// infe
infe.printStackTrace();
} catch (ReflectionException re) {
// re
re.printStackTrace();
}
}
}
ons = v_unstartedBundle.toArray();
} while (oldUnstartedBundleNbr != ons.length);
} catch (IOException ioe) {
// ioe
ioe.printStackTrace();
}
a.firePropertyChangedEvent(Plugin.NEW_NODE_READY, connString, mbsc);
a.firePropertyChangedEvent(Plugin.PLUGIN_ACTIVATED, null, this.getComponentAt(0).getName());
}
use of javax.management.AttributeNotFoundException in project felix by apache.
the class AbstractDynamicMBean method setAttribute.
/**
* Sets the value of the manageable attribute, as specified by the DynamicMBean interface.
* @see #createMBeanAttributeInfo
*/
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
if (attribute == null)
throw new AttributeNotFoundException("Attribute " + attribute + " not found");
Object resource = null;
MBeanInfo info = null;
synchronized (this) {
resource = getResourceOrThis();
info = getMBeanInfo();
}
MBeanAttributeInfo[] attrs = info.getAttributes();
if (attrs == null || attrs.length == 0)
throw new AttributeNotFoundException("No attributes defined for this MBean");
for (int i = 0; i < attrs.length; ++i) {
MBeanAttributeInfo attr = attrs[i];
if (attr == null)
continue;
if (attribute.getName().equals(attr.getName())) {
if (!attr.isWritable())
throw new ReflectionException(new NoSuchMethodException("No setter defined for attribute: " + attribute));
try {
String signature = attr.getType();
Class cls = Utils.loadClass(resource.getClass().getClassLoader(), signature);
invoke(resource, "set" + attr.getName(), new Class[] { cls }, new Object[] { attribute.getValue() });
return;
} catch (ClassNotFoundException x) {
throw new ReflectionException(x);
}
}
}
throw new AttributeNotFoundException("Attribute " + attribute + " not found");
}
use of javax.management.AttributeNotFoundException in project felix by apache.
the class ReflectedMBeanInvoker method setAttribute.
public void setAttribute(MBeanMetaData metadata, Attribute attribute) throws MBeanException, AttributeNotFoundException, InvalidAttributeValueException, ReflectionException {
String name = attribute.getName();
MBeanAttributeInfo attr = getStandardAttributeInfo(metadata, name, true);
if (attr != null) {
String attributeName = getAttributeName(attr, false);
try {
invokeImpl(metadata, attributeName, new String[] { attr.getType() }, new Object[] { attribute.getValue() });
} catch (IllegalArgumentException x) {
throw new InvalidAttributeValueException("Invalid value for attribute " + name + ": " + attribute.getValue());
}
} else {
throw new AttributeNotFoundException(name);
}
}
Aggregations