use of javax.management.MBeanOperationInfo in project tomee by apache.
the class ManagedMBean method getMBeanInfo.
public MBeanInfo getMBeanInfo() {
final List<MBeanAttributeInfo> attributes = new ArrayList<>(this.attributes);
final List<MBeanOperationInfo> operations = new ArrayList<>(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();
}
}
operations.sort(MBeanFeatureInfoComparator.INSTANCE);
attributes.sort(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.MBeanOperationInfo in project tomee by apache.
the class LocalJMXCommand method invoke.
private void invoke(final String value) {
if (!value.contains("(") || !value.contains(")")) {
streamManager.writeErr("method should follow the format: <methoName>(<arg1>,<arg2>,...)");
return;
}
int open = value.indexOf("(");
int close = value.lastIndexOf(")");
final String name = value.substring(0, open).trim();
final String rawArgs = value.substring(open + 1, close).trim();
final ObjectName on;
try {
on = new ObjectName(value.substring(close + 1).trim());
} catch (MalformedObjectNameException e) {
streamManager.writeErr(e);
return;
}
final MBeanServer server = LocalMBeanServer.get();
final String[] args;
if (rawArgs == null || rawArgs.isEmpty()) {
args = new String[0];
} else {
args = rawArgs.split(",");
}
try {
final MBeanInfo minfo = server.getMBeanInfo(on);
final MBeanOperationInfo[] methods = minfo.getOperations();
MBeanOperationInfo operation = null;
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals(name)) {
operation = methods[i];
break;
}
}
if (operation == null) {
streamManager.writeErr("can't find operation '" + name + "'");
return;
}
final Object[] passedArgs = new Object[args.length];
final String[] passedArgTypes = new String[args.length];
for (int i = 0; i < passedArgs.length; i++) {
final String expected = operation.getSignature()[i].getType();
if (!String.class.getName().equals(expected)) {
passedArgs[i] = propertyEditorRegistry.getValue(expected, args[i], Thread.currentThread().getContextClassLoader());
} else {
passedArgs[i] = args[i];
}
passedArgTypes[i] = expected;
}
streamManager.writeOut(stringify(server.invoke(on, name, passedArgs, passedArgTypes)));
} catch (Exception e) {
streamManager.writeErr(e);
return;
}
}
use of javax.management.MBeanOperationInfo in project spring-boot by spring-projects.
the class MBeanInfoFactoryTests method getMBeanInfoShouldUseJmxOperationResponseMapper.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
void getMBeanInfoShouldUseJmxOperationResponseMapper() {
JmxOperationResponseMapper mapper = mock(JmxOperationResponseMapper.class);
given(mapper.mapResponseType(String.class)).willReturn((Class) Integer.class);
MBeanInfoFactory factory = new MBeanInfoFactory(mapper);
MBeanInfo info = factory.getMBeanInfo(new TestExposableJmxEndpoint(new TestJmxOperation()));
MBeanOperationInfo operationInfo = info.getOperations()[0];
assertThat(operationInfo.getReturnType()).isEqualTo(Integer.class.getName());
}
use of javax.management.MBeanOperationInfo in project Payara by payara.
the class ConfigBeanJMXSupport method duckTypedToMBeanOperationInfo.
/**
* DuckTyped methods are <em>always</em> exposed as operations, never as Attributes.
*/
public MBeanOperationInfo duckTypedToMBeanOperationInfo(final DuckTypedInfo info) {
final Descriptor descriptor = descriptor(info.duckTyped());
final String name = info.name();
final Class<?> type = remoteType(info.returnType());
final String description = "@DuckTyped " + name + " of " + mIntf.getName();
// how to tell?
final int impact = MBeanOperationInfo.UNKNOWN;
final List<MBeanParameterInfo> paramInfos = new ArrayList<MBeanParameterInfo>();
int i = 0;
for (final Class<?> paramClass : info.signature()) {
final String paramName = "p" + i;
final String paramType = remoteType(paramClass).getName();
final String paramDescription = "parameter " + i;
final MBeanParameterInfo paramInfo = new MBeanParameterInfo(paramName, paramType, paramDescription, null);
paramInfos.add(paramInfo);
++i;
}
final MBeanParameterInfo[] paramInfosArray = CollectionUtil.toArray(paramInfos, MBeanParameterInfo.class);
return new MBeanOperationInfo(name, description, paramInfosArray, type.getName(), impact, descriptor);
}
use of javax.management.MBeanOperationInfo in project Payara by payara.
the class MBeanInterfaceGenerator method generateOperations.
protected String generateOperations(MBeanOperationInfo[] infos) {
final StringBuilder buf = new StringBuilder();
for (int i = 0; i < infos.length; ++i) {
final MBeanOperationInfo info = infos[i];
final String name = info.getName();
final String returnType = info.getReturnType();
final MBeanParameterInfo[] paramInfos = info.getSignature();
final String[] paramTypes = new String[paramInfos.length];
for (int p = 0; p < paramInfos.length; ++p) {
paramTypes[p] = paramInfos[p].getType();
}
final String[] paramNames = getParamNames(info);
if (mEmitComments) {
final String comment = getOperationComment(info, paramNames);
if (comment.length() != 0) {
buf.append(NEWLINE).append(indent(comment)).append(NEWLINE);
}
}
final String method = formMethod(returnType, name, paramTypes, paramNames);
buf.append(indent(method)).append(NEWLINE);
}
return (buf.toString());
}
Aggregations