use of javax.management.MBeanInfo in project tomee by apache.
the class LocalJMXCommand method set.
private void set(final String cmd) {
final String[] split = cmd.split(" ");
if (split.length < 2) {
streamManager.writeErr("you need to specify an attribute, an objectname and a value");
return;
}
final MBeanServer mBeanServer = LocalMBeanServer.get();
final String newValue = cmd.substring(split[0].length() + split[1].length() + 1).trim();
try {
final ObjectName oname = new ObjectName(split[1]);
final MBeanInfo minfo = mBeanServer.getMBeanInfo(oname);
final MBeanAttributeInfo[] attrs = minfo.getAttributes();
String type = String.class.getName();
for (int i = 0; i < attrs.length; i++) {
if (attrs[i].getName().equals(split[0])) {
type = attrs[i].getType();
break;
}
}
final Object valueObj = PropertyEditors.getValue(type, newValue, Thread.currentThread().getContextClassLoader());
mBeanServer.setAttribute(oname, new Attribute(split[0], valueObj));
streamManager.writeOut("done");
} catch (Exception ex) {
streamManager.writeOut("Error - " + ex.toString());
}
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class MBeanIntrospector method getClassMBeanInfo.
/**
* Return the basic MBeanInfo for resources of the given class and
* per-interface data. This MBeanInfo might not be the final MBeanInfo
* for instances of the class, because if the class is a
* NotificationBroadcaster then each instance gets to decide what
* MBeanNotificationInfo[] to put in its own MBeanInfo.
*/
final MBeanInfo getClassMBeanInfo(Class<?> resourceClass, PerInterface<M> perInterface) {
MBeanInfoMap map = getMBeanInfoMap();
synchronized (map) {
WeakHashMap<Class<?>, MBeanInfo> intfMap = map.get(resourceClass);
if (intfMap == null) {
intfMap = new WeakHashMap<Class<?>, MBeanInfo>();
map.put(resourceClass, intfMap);
}
Class<?> intfClass = perInterface.getMBeanInterface();
MBeanInfo mbi = intfMap.get(intfClass);
if (mbi == null) {
MBeanInfo imbi = perInterface.getMBeanInfo();
Descriptor descriptor = ImmutableDescriptor.union(imbi.getDescriptor(), getMBeanDescriptor(resourceClass));
mbi = new MBeanInfo(resourceClass.getName(), imbi.getDescription(), imbi.getAttributes(), findConstructors(resourceClass), imbi.getOperations(), (MBeanNotificationInfo[]) null, descriptor);
intfMap.put(intfClass, mbi);
}
return mbi;
}
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class MBeanIntrospector method getPerInterface.
final PerInterface<M> getPerInterface(Class<?> mbeanInterface) throws NotCompliantMBeanException {
PerInterfaceMap<M> map = getPerInterfaceMap();
synchronized (map) {
WeakReference<PerInterface<M>> wr = map.get(mbeanInterface);
PerInterface<M> pi = (wr == null) ? null : wr.get();
if (pi == null) {
try {
MBeanAnalyzer<M> analyzer = getAnalyzer(mbeanInterface);
MBeanInfo mbeanInfo = makeInterfaceMBeanInfo(mbeanInterface, analyzer);
pi = new PerInterface<M>(mbeanInterface, this, analyzer, mbeanInfo);
wr = new WeakReference<PerInterface<M>>(pi);
map.put(mbeanInterface, wr);
} catch (Exception x) {
throw Introspector.throwException(mbeanInterface, x);
}
}
return pi;
}
}
use of javax.management.MBeanInfo in project tomee by apache.
the class ManagedMBean method getMBeanInfo.
public MBeanInfo getMBeanInfo() {
final List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>(this.attributes);
final List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>(this.operations);
for (final Member member : dynamic) {
try {
final ManagedCollection managedCollection = member.getAnnotation(ManagedCollection.class);
final Collection collection = (Collection) member.get();
for (final Object o : collection) {
try {
final Field field = o.getClass().getDeclaredField(managedCollection.key());
field.setAccessible(true);
final Object key = field.get(o);
final ManagedMBean bean = new ManagedMBean(o, key.toString());
Collections.addAll(attributes, bean.getMBeanInfo().getAttributes());
Collections.addAll(operations, bean.getMBeanInfo().getOperations());
attributesMap.putAll(bean.attributesMap);
operationsMap.putAll(bean.operationsMap);
} catch (final Exception e) {
e.printStackTrace();
}
}
} catch (final Exception e) {
e.printStackTrace();
}
}
sort(operations, MBeanFeatureInfoComparator.INSTANCE);
sort(attributes, MBeanFeatureInfoComparator.INSTANCE);
if (filterAttributes) {
final Iterator<MBeanAttributeInfo> iterator = attributes.iterator();
while (iterator.hasNext()) {
final MBeanAttributeInfo info = iterator.next();
if (includes.matcher(info.getName()).matches()) {
continue;
}
if (excludes.matcher(info.getName()).matches()) {
iterator.remove();
}
}
}
return new MBeanInfo(this.getClass().getName(), "", attributes.toArray(new MBeanAttributeInfo[attributes.size()]), new MBeanConstructorInfo[0], operations.toArray(new MBeanOperationInfo[operations.size()]), EMPTY_NOTIFICATIONS);
}
use of javax.management.MBeanInfo in project jmxtrans by jmxtrans.
the class TreeWalker2 method walkTree.
public void walkTree(MBeanServerConnection connection, Server server) throws Exception {
// key here is null, null returns everything!
Set<ObjectName> mbeans = connection.queryNames(null, null);
for (ObjectName name : mbeans) {
MBeanInfo info = connection.getMBeanInfo(name);
MBeanAttributeInfo[] attrs = info.getAttributes();
Query.Builder queryBuilder = Query.builder().setObj(name.getCanonicalName()).addOutputWriterFactory(new StdOutWriter(ImmutableList.<String>of(), false, false, Collections.<String, Object>emptyMap()));
for (MBeanAttributeInfo attrInfo : attrs) {
queryBuilder.addAttr(attrInfo.getName());
}
Query query = queryBuilder.build();
try {
Iterable<Result> results = server.execute(query);
query.runOutputWritersForQuery(server, results);
} catch (AttributeNotFoundException anfe) {
log.error("Error", anfe);
}
}
}
Aggregations