use of javax.management.MBeanOperationInfo in project jetty.project by eclipse.
the class ObjectMBeanTest method testDerivedOperations.
@Test
public void testDerivedOperations() throws Exception {
Derived derived = new Derived();
ObjectMBean mbean = (ObjectMBean) ObjectMBean.mbeanFor(derived);
mbean.setMBeanContainer(container);
container.beanAdded(null, derived);
MBeanInfo info = mbean.getMBeanInfo();
Assert.assertEquals("operation count does not match", 5, info.getOperations().length);
MBeanOperationInfo[] opinfos = info.getOperations();
boolean publish = false;
boolean doodle = false;
boolean good = false;
for (int i = 0; i < opinfos.length; ++i) {
MBeanOperationInfo opinfo = opinfos[i];
if ("publish".equals(opinfo.getName())) {
publish = true;
Assert.assertEquals("description doesn't match", "publish something", opinfo.getDescription());
}
if ("doodle".equals(opinfo.getName())) {
doodle = true;
Assert.assertEquals("description doesn't match", "Doodle something", opinfo.getDescription());
MBeanParameterInfo[] pinfos = opinfo.getSignature();
Assert.assertEquals("parameter description doesn't match", "A description of the argument", pinfos[0].getDescription());
Assert.assertEquals("parameter name doesn't match", "doodle", pinfos[0].getName());
}
// This is a proxied operation on the JMX wrapper
if ("good".equals(opinfo.getName())) {
good = true;
Assert.assertEquals("description does not match", "test of proxy operations", opinfo.getDescription());
Assert.assertEquals("execution contexts wrong", "not bad", mbean.invoke("good", new Object[] {}, new String[] {}));
}
}
Assert.assertTrue("publish operation was not not found", publish);
Assert.assertTrue("doodle operation was not not found", doodle);
Assert.assertTrue("good operation was not not found", good);
}
use of javax.management.MBeanOperationInfo in project hazelcast by hazelcast.
the class HazelcastMBean method operationInfos.
private MBeanOperationInfo[] operationInfos() {
MBeanOperationInfo[] array = new MBeanOperationInfo[operationMap.size()];
int i = 0;
for (BeanInfo beanInfo : operationMap.values()) {
array[i++] = beanInfo.getOperationInfo();
}
return array;
}
use of javax.management.MBeanOperationInfo in project tomcat by apache.
the class ManagedBean method getMBeanInfo.
/**
* Create and return a <code>ModelMBeanInfo</code> object that
* describes this entire managed bean.
* @return the MBean info
*/
MBeanInfo getMBeanInfo() {
// Return our cached information (if any)
mBeanInfoLock.readLock().lock();
try {
if (info != null) {
return info;
}
} finally {
mBeanInfoLock.readLock().unlock();
}
mBeanInfoLock.writeLock().lock();
try {
if (info == null) {
// Create subordinate information descriptors as required
AttributeInfo[] attrs = getAttributes();
MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[attrs.length];
for (int i = 0; i < attrs.length; i++) attributes[i] = attrs[i].createAttributeInfo();
OperationInfo[] opers = getOperations();
MBeanOperationInfo[] operations = new MBeanOperationInfo[opers.length];
for (int i = 0; i < opers.length; i++) operations[i] = opers[i].createOperationInfo();
NotificationInfo[] notifs = getNotifications();
MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[notifs.length];
for (int i = 0; i < notifs.length; i++) notifications[i] = notifs[i].createNotificationInfo();
// Construct and return a new ModelMBeanInfo object
info = new MBeanInfo(getClassName(), getDescription(), attributes, new MBeanConstructorInfo[] {}, operations, notifications);
}
return info;
} finally {
mBeanInfoLock.writeLock().unlock();
}
}
use of javax.management.MBeanOperationInfo in project tomcat by apache.
the class JMXProxyServlet method invokeOperationInternal.
/**
* Invokes an operation on an MBean.
*
* @param onameStr The name of the MBean.
* @param operation The name of the operation to invoke.
* @param parameters An array of Strings containing the parameters to the
* operation. They will be converted to the appropriate types to
* call the requested operation.
* @return The value returned by the requested operation.
*/
private Object invokeOperationInternal(String onameStr, String operation, String[] parameters) throws OperationsException, MBeanException, ReflectionException {
ObjectName oname = new ObjectName(onameStr);
MBeanOperationInfo methodInfo = registry.getMethodInfo(oname, operation);
MBeanParameterInfo[] signature = methodInfo.getSignature();
String[] signatureTypes = new String[signature.length];
Object[] values = new Object[signature.length];
for (int i = 0; i < signature.length; i++) {
MBeanParameterInfo pi = signature[i];
signatureTypes[i] = pi.getType();
values[i] = registry.convertValue(pi.getType(), parameters[i]);
}
return mBeanServer.invoke(oname, operation, values, signatureTypes);
}
use of javax.management.MBeanOperationInfo in project spring-framework by spring-projects.
the class MBeanClientInterceptor method retrieveMBeanInfo.
/**
* Loads the management interface info for the configured MBean into the caches.
* This information is used by the proxy when determining whether an invocation matches
* a valid operation or attribute on the management interface of the managed resource.
*/
private void retrieveMBeanInfo() throws MBeanInfoRetrievalException {
try {
MBeanInfo info = this.serverToUse.getMBeanInfo(this.objectName);
MBeanAttributeInfo[] attributeInfo = info.getAttributes();
this.allowedAttributes = new HashMap<>(attributeInfo.length);
for (MBeanAttributeInfo infoEle : attributeInfo) {
this.allowedAttributes.put(infoEle.getName(), infoEle);
}
MBeanOperationInfo[] operationInfo = info.getOperations();
this.allowedOperations = new HashMap<>(operationInfo.length);
for (MBeanOperationInfo infoEle : operationInfo) {
Class<?>[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader);
this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle);
}
} catch (ClassNotFoundException ex) {
throw new MBeanInfoRetrievalException("Unable to locate class specified in method signature", ex);
} catch (IntrospectionException ex) {
throw new MBeanInfoRetrievalException("Unable to obtain MBean info for bean [" + this.objectName + "]", ex);
} catch (InstanceNotFoundException ex) {
// if we are this far this shouldn't happen, but...
throw new MBeanInfoRetrievalException("Unable to obtain MBean info for bean [" + this.objectName + "]: it is likely that this bean was unregistered during the proxy creation process", ex);
} catch (ReflectionException ex) {
throw new MBeanInfoRetrievalException("Unable to read MBean info for bean [ " + this.objectName + "]", ex);
} catch (IOException ex) {
throw new MBeanInfoRetrievalException("An IOException occurred when communicating with the " + "MBeanServer. It is likely that you are communicating with a remote MBeanServer. " + "Check the inner exception for exact details.", ex);
}
}
Aggregations