Search in sources :

Example 11 with MBeanParameterInfo

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

the class InvokeDialog method createParameterGroup.

/**
     * Creates the parameter group.
     * 
     * @param parent The parent composite
     */
private void createParameterGroup(Composite parent) {
    if (info.getSignature().length == 0) {
        return;
    }
    Group group = new Group(parent, SWT.NONE);
    group.setText(Messages.parametersGroupLabel);
    GridLayout layout = new GridLayout(2, false);
    group.setLayout(layout);
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    for (MBeanParameterInfo signature : info.getSignature()) {
        Label label = new Label(group, SWT.NONE);
        String type = signature.getType();
        if (type.startsWith("[")) {
            //$NON-NLS-1$
            type = Signature.toString(type);
            label.setToolTipText(Messages.enterCommaSeparatedValuesToolTip);
        }
        int index = type.lastIndexOf('.');
        if (index > 0) {
            type = type.substring(index + 1);
        }
        //$NON-NLS-1$
        label.setText(type + ":");
        if (Boolean.class.getSimpleName().equalsIgnoreCase(type)) {
            Combo combo = new Combo(group, SWT.READ_ONLY);
            combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            combo.add(Boolean.TRUE.toString());
            combo.add(Boolean.FALSE.toString());
            combo.select(0);
            controls.put(signature, combo);
        } else {
            Text text = new Text(group, SWT.BORDER);
            text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            text.addModifyListener(new ModifyListener() {

                @Override
                public void modifyText(ModifyEvent e) {
                    validate();
                }
            });
            controls.put(signature, text);
        }
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 12 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo 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 13 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project deltaspike by apache.

the class SimpleRegistrationTest method checkMBean.

@Test
public void checkMBean() throws Exception {
    assertEquals(0, myMBean.getCounter());
    myMBean.resetTo(2);
    final ObjectName on = new ObjectName("org.apache.deltaspike:type=MBeans,name=" + MyMBean.class.getName());
    assertTrue(server.isRegistered(on));
    assertEquals(2, server.getAttribute(on, "counter"));
    assertEquals(6, server.invoke(on, "multiply", new Object[] { 3 }, new String[0]));
    myMBean.resetTo(5);
    assertEquals(5, server.getAttribute(on, "counter"));
    assertEquals(20, server.invoke(on, "multiply", new Object[] { 4 }, new String[0]));
    server.setAttribute(on, new Attribute("counter", 10));
    assertEquals(10, myMBean.getCounter());
    final Collection<Notification> notifications = new ArrayList<Notification>();
    server.addNotificationListener(on, new NotificationListener() {

        @Override
        public void handleNotification(final Notification notification, final Object handback) {
            notifications.add(notification);
        }
    }, null, null);
    myMBean.broadcast();
    assertEquals(1, notifications.size());
    assertEquals(10L, notifications.iterator().next().getSequenceNumber());
    MBeanInfo mBeanInfo = server.getMBeanInfo(on);
    Assert.assertNotNull(mBeanInfo);
    MBeanOperationInfo[] operations = mBeanInfo.getOperations();
    Assert.assertNotNull(operations);
    Assert.assertTrue(operations.length > 0);
    Assert.assertTrue("Empty Signature on operation: " + operations[1], operations[1].getSignature().length > 0);
    MBeanParameterInfo parameterInfo = operations[1].getSignature()[0];
    assertEquals("multiplier", parameterInfo.getName());
    assertEquals("the multiplier", parameterInfo.getDescription());
    {
        // table support - through map
        Object table = server.getAttribute(on, "table");
        assertTrue(TabularData.class.isInstance(table));
        final TabularData data = TabularData.class.cast(table);
        assertEquals(1, data.size());
        final CompositeData compositeData = CompositeData.class.cast(data.values().iterator().next());
        assertEquals(2, compositeData.values().size());
        assertEquals("value1", compositeData.get("key1"));
        assertEquals("value2", compositeData.get("key2"));
    }
    {
        // table support - through Table
        Object table = server.getAttribute(on, "table2");
        assertTrue(TabularData.class.isInstance(table));
        final TabularData data = TabularData.class.cast(table);
        assertEquals(2, data.size());
        final Iterator<?> iterator = data.values().iterator();
        {
            final CompositeData compositeData = CompositeData.class.cast(iterator.next());
            assertEquals(3, compositeData.values().size());
            assertEquals("1", compositeData.get("a"));
            assertEquals("2", compositeData.get("b"));
            assertEquals("3", compositeData.get("c"));
        }
        {
            final CompositeData compositeData = CompositeData.class.cast(iterator.next());
            assertEquals(3, compositeData.values().size());
            assertEquals("alpha", compositeData.get("a"));
            assertEquals("beta", compositeData.get("b"));
            assertEquals("gamma", compositeData.get("c"));
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Iterator(java.util.Iterator) NotificationListener(javax.management.NotificationListener) MBeanParameterInfo(javax.management.MBeanParameterInfo) Test(org.junit.Test)

Example 14 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project ignite by apache.

the class GridMBeanSelfTest method testCorrectMBeanInfo.

/**
     * Tests correct MBean interface.
     *
     * @throws Exception Thrown if test fails.
     */
public void testCorrectMBeanInfo() throws Exception {
    StandardMBean mbean = new IgniteStandardMXBean(new GridMBeanImplementation(), GridMBeanInterface.class);
    MBeanInfo info = mbean.getMBeanInfo();
    assert info.getDescription().equals("MBeanDescription.") == true;
    assert info.getOperations().length == 2;
    for (MBeanOperationInfo opInfo : info.getOperations()) {
        if (opInfo.getDescription().equals("MBeanOperation."))
            assert opInfo.getSignature().length == 2;
        else {
            assert opInfo.getDescription().equals("MBeanSuperOperation.") == true;
            assert opInfo.getSignature().length == 1;
        }
    }
    for (MBeanParameterInfo paramInfo : info.getOperations()[0].getSignature()) {
        if (paramInfo.getName().equals("ignored"))
            assert paramInfo.getDescription().equals("MBeanOperationParameter1.") == true;
        else {
            assert paramInfo.getName().equals("someData") == true;
            assert paramInfo.getDescription().equals("MBeanOperationParameter2.") == true;
        }
    }
    assert info.getAttributes().length == 4 : "Expected 4 attributes but got " + info.getAttributes().length;
    for (MBeanAttributeInfo attrInfo : info.getAttributes()) {
        if (attrInfo.isWritable() == false) {
            assert (attrInfo.getDescription().equals("MBeanReadonlyGetter.") == true || attrInfo.getDescription().equals("MBeanROGetter."));
        } else {
            assert (attrInfo.getDescription().equals("MBeanWritableGetter.") == true || attrInfo.getDescription().equals("MBeanWritableIsGetter."));
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) StandardMBean(javax.management.StandardMBean) IgniteStandardMXBean(org.apache.ignite.internal.mxbean.IgniteStandardMXBean) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 15 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project jackrabbit-oak by apache.

the class AnnotatedStandardMBeanTest method test.

@Test
public void test() throws Exception {
    MBeanInfo info = server.getMBeanInfo(objectName);
    assertEquals("MBean desc.", info.getDescription());
    MBeanAttributeInfo a0 = findAttribute(info, "Getter");
    assertEquals("getter", a0.getDescription());
    MBeanAttributeInfo a1 = findAttribute(info, "It");
    assertEquals("is", a1.getDescription());
    MBeanAttributeInfo a2 = findAttribute(info, "Setter");
    assertEquals("setter", a2.getDescription());
    MBeanOperationInfo op0 = info.getOperations()[0];
    assertEquals("run", op0.getDescription());
    assertEquals(MBeanOperationInfo.INFO, op0.getImpact());
    MBeanParameterInfo p0 = op0.getSignature()[0];
    assertEquals("timeout", p0.getName());
    assertEquals("how long?", p0.getDescription());
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo) Test(org.junit.Test)

Aggregations

MBeanParameterInfo (javax.management.MBeanParameterInfo)30 MBeanOperationInfo (javax.management.MBeanOperationInfo)17 MBeanInfo (javax.management.MBeanInfo)12 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)9 ObjectName (javax.management.ObjectName)6 ArrayList (java.util.ArrayList)5 Descriptor (javax.management.Descriptor)4 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)4 Test (org.junit.Test)4 TreeMap (java.util.TreeMap)3 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)3 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)3 Annotation (java.lang.annotation.Annotation)2 Method (java.lang.reflect.Method)2 ImmutableDescriptor (javax.management.ImmutableDescriptor)2 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)2 OpenMBeanOperationInfoSupport (javax.management.openmbean.OpenMBeanOperationInfoSupport)2 OpenMBeanParameterInfo (javax.management.openmbean.OpenMBeanParameterInfo)2 OpenMBeanParameterInfoSupport (javax.management.openmbean.OpenMBeanParameterInfoSupport)2 OpenType (javax.management.openmbean.OpenType)2