Search in sources :

Example 1 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project tdi-studio-se by Talend.

the class InvokeAction method selectionChanged.

/*
     * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent)
     */
@Override
public void selectionChanged(SelectionChangedEvent event) {
    info = null;
    ISelection selection = event.getSelection();
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof MBeanOperationInfo) {
            info = (MBeanOperationInfo) element;
        }
    }
    setEnabled(info != null);
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project tdi-studio-se by Talend.

the class OperationsTab method getValidOperations.

/**
     * Gets the valid MBean operations.
     * 
     * @param operations
     * @return The valid MBean operations
     */
static MBeanOperationInfo[] getValidOperations(MBeanOperationInfo[] operations) {
    List<MBeanOperationInfo> validOperations = new ArrayList<MBeanOperationInfo>();
    for (MBeanOperationInfo operation : operations) {
        boolean invalid = false;
        MBeanParameterInfo[] signature = operation.getSignature();
        for (int i = 0; i < signature.length; i++) {
            String name = signature[i].getName();
            String type = signature[i].getType();
            String description = signature[i].getDescription();
            if (name == null || type == null || description == null) {
                invalid = true;
                signature[i] = new MBeanParameterInfo(getNonNull(name), getNonNull(type), getNonNull(description), signature[i].getDescriptor());
            }
        }
        if (invalid) {
            operation = new MBeanOperationInfo(operation.getName(), operation.getDescription(), signature, operation.getReturnType(), operation.getImpact(), operation.getDescriptor());
        }
        validOperations.add(operation);
    }
    return validOperations.toArray(new MBeanOperationInfo[validOperations.size()]);
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 3 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project Activiti by Activiti.

the class JobExecutorMBeanTest method testAnnotations.

@Test
public void testAnnotations() throws MalformedObjectNameException, JMException {
    ModelMBean modelBean = assembler.assemble(jobExecutorMbean, new ObjectName("domain", "key", "value"));
    assertNotNull(modelBean);
    MBeanInfo beanInfo = modelBean.getMBeanInfo();
    assertNotNull(beanInfo);
    assertNotNull(beanInfo.getOperations());
    assertEquals(2, beanInfo.getOperations().length);
    int counter = 0;
    for (MBeanOperationInfo op : beanInfo.getOperations()) {
        if (op.getName().equals("setJobExecutorActivate")) {
            counter++;
            assertEquals("set job executor activate", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.Boolean", op.getSignature()[0].getType());
        }
    }
    assertEquals(1, counter);
    // check attributes
    assertNotNull(beanInfo.getAttributes());
    assertEquals(1, beanInfo.getAttributes().length);
    counter = 0;
    for (MBeanAttributeInfo attr : beanInfo.getAttributes()) {
        if (attr.getName().equals("JobExecutorActivated")) {
            counter++;
            assertEquals("check if the job executor is activated", attr.getDescription());
            assertEquals("boolean", attr.getType());
        }
    }
    assertEquals(1, counter);
}
Also used : ModelMBean(javax.management.modelmbean.ModelMBean) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 4 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project Activiti by Activiti.

the class ProcessDefinitionsTest method testAnnotations.

@Test
public void testAnnotations() throws MalformedObjectNameException, JMException {
    ModelMBean modelBean = assembler.assemble(processDefinitionsMBean, new ObjectName("domain", "key", "value"));
    assertNotNull(modelBean);
    MBeanInfo beanInfo = modelBean.getMBeanInfo();
    assertNotNull(beanInfo);
    assertNotNull(beanInfo.getOperations());
    assertEquals(9, beanInfo.getOperations().length);
    int counter = 0;
    for (MBeanOperationInfo op : beanInfo.getOperations()) {
        if (op.getName().equals("deleteDeployment")) {
            counter++;
            assertEquals("delete deployment", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
        } else if (op.getName().equals("suspendProcessDefinitionById")) {
            counter++;
            assertEquals("Suspend given process ID", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
        } else if (op.getName().equals("activatedProcessDefinitionById")) {
            counter++;
            assertEquals("Activate given process ID", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
        } else if (op.getName().equals("suspendProcessDefinitionByKey")) {
            counter++;
            assertEquals("Suspend given process ID", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
        } else if (op.getName().equals("activatedProcessDefinitionByKey")) {
            counter++;
            assertEquals("Activate given process ID", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
        } else if (op.getName().equals("deployProcessDefinition")) {
            counter++;
            assertEquals("Deploy Process Definition", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(2, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
            assertEquals("java.lang.String", op.getSignature()[1].getType());
        }
    }
    assertEquals(6, counter);
    // check attributes
    assertNotNull(beanInfo.getAttributes());
    assertEquals(2, beanInfo.getAttributes().length);
    counter = 0;
    for (MBeanAttributeInfo attr : beanInfo.getAttributes()) {
        if (attr.getName().equals("ProcessDefinitions")) {
            counter++;
            assertEquals("List of Process definitions", attr.getDescription());
            assertEquals("java.util.List", attr.getType());
        } else if (attr.getName().equals("Deployments")) {
            counter++;
            assertEquals("List of deployed Processes", attr.getDescription());
            assertEquals("java.util.List", attr.getType());
        }
    }
    assertEquals(2, counter);
}
Also used : ModelMBean(javax.management.modelmbean.ModelMBean) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 5 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project jdk8u_jdk by JetBrains.

the class FeatureOrderTest method main.

public static void main(String[] args) throws Exception {
    // Build the lists of attributes and operations that we would expect
    // if they are derived by reflection and preserve the reflection order
    List<String> expectedAttributeNames = new ArrayList<String>();
    List<String> expectedOperationNames = new ArrayList<String>();
    for (Method m : OrderMXBean.class.getMethods()) {
        String name = m.getName();
        String attrName = null;
        if (name.startsWith("get") && !name.equals("get") && m.getParameterTypes().length == 0 && m.getReturnType() != void.class)
            attrName = name.substring(3);
        else if (name.startsWith("is") && !name.equals("is") && m.getParameterTypes().length == 0 && m.getReturnType() == boolean.class)
            attrName = name.substring(2);
        else if (name.startsWith("set") && !name.equals("set") && m.getReturnType() == void.class && m.getParameterTypes().length == 1)
            attrName = name.substring(3);
        if (attrName != null) {
            if (!expectedAttributeNames.contains(attrName))
                expectedAttributeNames.add(attrName);
        } else
            expectedOperationNames.add(name);
    }
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    for (boolean mxbean : booleans) {
        for (boolean withStandardMBean : booleans) {
            String testName = "MXBean: " + mxbean + "; " + "using javax.management.StandardMBean: " + withStandardMBean;
            System.out.println("Test case: " + testName);
            Object mbean;
            if (mxbean) {
                if (withStandardMBean) {
                    mbean = new StandardMBean(new OrderImpl(), OrderMXBean.class, true);
                } else
                    mbean = new OrderImpl();
            } else {
                if (withStandardMBean)
                    mbean = new StandardMBean(new Order(), OrderMBean.class);
                else
                    mbean = new Order();
            }
            ObjectName name = new ObjectName(":mxbean=" + mxbean + "," + "withStandardMBean=" + withStandardMBean);
            mbs.registerMBean(mbean, name);
            /* Make sure we are testing what we think. */
            MBeanInfo mbi = mbs.getMBeanInfo(name);
            boolean isWithStandardMBean = mbs.isInstanceOf(name, StandardMBean.class.getName());
            System.out.println("classname " + mbi.getClassName());
            String mxbeanField = (String) mbi.getDescriptor().getFieldValue("mxbean");
            boolean isMXBean = "true".equalsIgnoreCase(mxbeanField);
            if (mxbean != isMXBean)
                throw new Exception("Test error: MXBean mismatch");
            if (withStandardMBean != isWithStandardMBean)
                throw new Exception("Test error: StandardMBean mismatch");
            // Check that order of attributes and operations matches
            MBeanAttributeInfo[] mbais = mbi.getAttributes();
            checkEqual(expectedAttributeNames.size(), mbais.length, "number of attributes");
            List<String> attributeNames = new ArrayList<String>();
            for (MBeanAttributeInfo mbai : mbais) attributeNames.add(mbai.getName());
            checkEqual(expectedAttributeNames, attributeNames, "order of attributes");
            MBeanOperationInfo[] mbois = mbi.getOperations();
            checkEqual(expectedOperationNames.size(), mbois.length, "number of operations");
            List<String> operationNames = new ArrayList<String>();
            for (MBeanOperationInfo mboi : mbois) operationNames.add(mboi.getName());
            checkEqual(expectedOperationNames, operationNames, "order of operations");
            System.out.println();
        }
    }
    if (failed)
        throw new Exception("TEST FAILED");
    System.out.println("TEST PASSED");
}
Also used : MBeanInfo(javax.management.MBeanInfo) StandardMBean(javax.management.StandardMBean) MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Aggregations

MBeanOperationInfo (javax.management.MBeanOperationInfo)111 MBeanInfo (javax.management.MBeanInfo)72 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)55 MBeanParameterInfo (javax.management.MBeanParameterInfo)36 ObjectName (javax.management.ObjectName)32 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)23 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)20 InstanceNotFoundException (javax.management.InstanceNotFoundException)19 ArrayList (java.util.ArrayList)18 ReflectionException (javax.management.ReflectionException)16 Test (org.junit.Test)15 IntrospectionException (javax.management.IntrospectionException)13 MBeanServer (javax.management.MBeanServer)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 Test (org.testng.annotations.Test)9 Method (java.lang.reflect.Method)8 Attribute (javax.management.Attribute)7 Descriptor (javax.management.Descriptor)7 IOException (java.io.IOException)6 MBeanServerConnection (javax.management.MBeanServerConnection)5