Search in sources :

Example 36 with MBeanOperationInfo

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);
}
Also used : Derived(com.acme.Derived) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo) Test(org.junit.Test)

Example 37 with MBeanOperationInfo

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;
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanInfo(javax.management.MBeanInfo)

Example 38 with MBeanOperationInfo

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();
    }
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanConstructorInfo(javax.management.MBeanConstructorInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo)

Example 39 with MBeanOperationInfo

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);
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ObjectName(javax.management.ObjectName) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 40 with MBeanOperationInfo

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);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) IOException(java.io.IOException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Aggregations

MBeanOperationInfo (javax.management.MBeanOperationInfo)68 MBeanInfo (javax.management.MBeanInfo)39 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)35 MBeanParameterInfo (javax.management.MBeanParameterInfo)25 ObjectName (javax.management.ObjectName)20 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)9 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)8 MBeanServer (javax.management.MBeanServer)8 Method (java.lang.reflect.Method)7 Descriptor (javax.management.Descriptor)7 Attribute (javax.management.Attribute)5 ReflectionException (javax.management.ReflectionException)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)4 AMX (com.sun.appserv.management.base.AMX)3 IOException (java.io.IOException)3 TreeMap (java.util.TreeMap)3 IntrospectionException (javax.management.IntrospectionException)3 MBeanServerConnection (javax.management.MBeanServerConnection)3