Search in sources :

Example 6 with Descriptor

use of javax.management.Descriptor in project spring-framework by spring-projects.

the class AbstractMetadataAssemblerTests method testMetricDescriptor.

@Test
public void testMetricDescriptor() throws Exception {
    ModelMBeanInfo info = getMBeanInfoFromAssembler();
    Descriptor desc = info.getAttribute(QUEUE_SIZE_METRIC).getDescriptor();
    assertEquals("Currency Time Limit should be 20", "20", desc.getFieldValue("currencyTimeLimit"));
    assertEquals("Persist Policy should be OnUpdate", "OnUpdate", desc.getFieldValue("persistPolicy"));
    assertEquals("Persist Period should be 300", "300", desc.getFieldValue("persistPeriod"));
    assertEquals("Unit should be messages", "messages", desc.getFieldValue("units"));
    assertEquals("Display Name should be Queue Size", "Queue Size", desc.getFieldValue("displayName"));
    assertEquals("Metric Type should be COUNTER", "COUNTER", desc.getFieldValue("metricType"));
    assertEquals("Metric Category should be utilization", "utilization", desc.getFieldValue("metricCategory"));
}
Also used : Descriptor(javax.management.Descriptor) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Example 7 with Descriptor

use of javax.management.Descriptor in project spring-framework by spring-projects.

the class AbstractMetadataAssemblerTests method testManagedResourceDescriptor.

@Test
public void testManagedResourceDescriptor() throws Exception {
    ModelMBeanInfo info = getMBeanInfoFromAssembler();
    Descriptor desc = info.getMBeanDescriptor();
    assertEquals("Logging should be set to true", "true", desc.getFieldValue("log"));
    assertEquals("Log file should be jmx.log", "jmx.log", desc.getFieldValue("logFile"));
    assertEquals("Currency Time Limit should be 15", "15", desc.getFieldValue("currencyTimeLimit"));
    assertEquals("Persist Policy should be OnUpdate", "OnUpdate", desc.getFieldValue("persistPolicy"));
    assertEquals("Persist Period should be 200", "200", desc.getFieldValue("persistPeriod"));
    assertEquals("Persist Location should be foo", "./foo", desc.getFieldValue("persistLocation"));
    assertEquals("Persist Name should be bar", "bar.jmx", desc.getFieldValue("persistName"));
}
Also used : Descriptor(javax.management.Descriptor) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Example 8 with Descriptor

use of javax.management.Descriptor in project spring-framework by spring-projects.

the class AbstractMetadataAssemblerTests method testAttributeDescriptor.

@Test
public void testAttributeDescriptor() throws Exception {
    ModelMBeanInfo info = getMBeanInfoFromAssembler();
    Descriptor desc = info.getAttribute(NAME_ATTRIBUTE).getDescriptor();
    assertEquals("Default value should be foo", "foo", desc.getFieldValue("default"));
    assertEquals("Currency Time Limit should be 20", "20", desc.getFieldValue("currencyTimeLimit"));
    assertEquals("Persist Policy should be OnUpdate", "OnUpdate", desc.getFieldValue("persistPolicy"));
    assertEquals("Persist Period should be 300", "300", desc.getFieldValue("persistPeriod"));
}
Also used : Descriptor(javax.management.Descriptor) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Example 9 with Descriptor

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

the class DcmdMBeanTest method printOperation.

static void printOperation(MBeanOperationInfo info) {
    System.out.println("Name: " + info.getName());
    System.out.println("Description: " + info.getDescription());
    System.out.println("Return Type: " + info.getReturnType());
    System.out.println("Impact: " + info.getImpact());
    Descriptor desc = info.getDescriptor();
    System.out.println("Descriptor");
    for (int i = 0; i < desc.getFieldNames().length; i++) {
        if (desc.getFieldNames()[i].compareTo("dcmd.arguments") == 0) {
            System.out.println("\t" + desc.getFieldNames()[i] + ":");
            Descriptor desc2 = (Descriptor) desc.getFieldValue(desc.getFieldNames()[i]);
            for (int j = 0; j < desc2.getFieldNames().length; j++) {
                System.out.println("\t\t" + desc2.getFieldNames()[j] + "=");
                Descriptor desc3 = (Descriptor) desc2.getFieldValue(desc2.getFieldNames()[j]);
                for (int k = 0; k < desc3.getFieldNames().length; k++) {
                    System.out.println("\t\t\t" + desc3.getFieldNames()[k] + "=" + desc3.getFieldValue(desc3.getFieldNames()[k]));
                }
            }
        } else {
            System.out.println("\t" + desc.getFieldNames()[i] + "=" + desc.getFieldValue(desc.getFieldNames()[i]));
        }
    }
}
Also used : Descriptor(javax.management.Descriptor)

Example 10 with Descriptor

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

the class DescriptorSupportTest method main.

public static void main(String[] args) throws Exception {
    boolean ok = true;
    System.out.println("Checking that name and descriptorType are " + "mandatory");
    // Try omitting name and/or descriptorType
    for (int i = 0; i < 3; i++) {
        final boolean addName = ((i & 1) != 0);
        final boolean addDescriptorType = ((i & 2) != 0);
        final List fields = new ArrayList();
        if (addName)
            fields.add("name=something");
        if (addDescriptorType)
            fields.add("descriptorType=something-else");
        final String[] fs = (String[]) fields.toArray(new String[0]);
        final String what = "DescriptorSupport with " + (addName ? "" : "no ") + "name and " + (addDescriptorType ? "" : "no ") + "descriptorType";
        DescriptorSupport ds = new DescriptorSupport(fs);
        if (ds.isValid()) {
            System.out.println("INCORRECTLY ACCEPTED: " + what);
            ok = false;
        } else
            System.out.println("OK: rejected " + what);
    }
    for (int pass = 0; pass < 2; pass++) {
        boolean shouldAccept = (pass == 0);
        System.out.println("Trying out " + (shouldAccept ? "correct" : "bogus") + " DescriptorSupport fields");
        Object[] fields = shouldAccept ? goodFields : badFields;
        for (int i = 0; i < fields.length; i += 2) {
            String[] names = { "name", "descriptorType" };
            String[] values = { "some-name", "some-type" };
            DescriptorSupport d = new DescriptorSupport(names, values);
            final String name = (String) fields[i];
            final Object value = fields[i + 1];
            final String valueS = (value instanceof String) ? ("\"" + value + "\"") : (value == null) ? "null" : value.toString();
            final String what = "DescriptorSupport with " + name + " = " + valueS;
            try {
                d.setField(name, value);
                if (shouldAccept)
                    System.out.println("OK: accepted " + what);
                else {
                    System.out.println("INCORRECTLY ACCEPTED: " + what);
                    ok = false;
                }
            } catch (RuntimeOperationsException e) {
                if (shouldAccept) {
                    System.out.println("INCORRECTLY REJECTED: " + what + ": " + e);
                    ok = false;
                } else {
                    System.out.println("OK: rejected " + what);
                // OK: this is what should happen
                }
            } catch (Exception e) {
                System.out.println("WRONG EXCEPTION: " + what + ": " + e);
                ok = false;
            }
        }
    }
    // 4894856: ModelMBeanInfoSupport.setDescriptor(d, "mbean") fails
    System.out.println("Checking that setDescriptor(d, \"mbean\") works");
    ModelMBeanInfo mmbi = new ModelMBeanInfoSupport("x", "descr", null, null, null, null);
    Descriptor d = mmbi.getDescriptor("x", "mbean");
    try {
        mmbi.setDescriptor(d, "mbean");
    } catch (Exception e) {
        System.out.println("Unexpected exception:");
        e.printStackTrace(System.out);
        ok = false;
    }
    // 5016685: DescriptorSupport forces field names to lower case
    System.out.println("Checking that field name case is ignored " + "but preserved");
    ok &= caseTest(new DescriptorSupport(new String[] { "NAME=blah" }), "DescriptorSupport(String[])");
    ok &= caseTest(new DescriptorSupport(new String[] { "NAME" }, new String[] { "blah" }), "DescriptorSupport(String[], Object[])");
    DescriptorSupport d1 = new DescriptorSupport();
    d1.setField("NAME", "blah");
    ok &= caseTest(d1, "DescriptorSupport.setField");
    d1 = new DescriptorSupport(new String[] { "NAME=blah" });
    ok &= caseTest(new DescriptorSupport(d1), "DescriptorSupport(Descriptor)");
    d1 = new DescriptorSupport(new String[] { "NAME=blah" });
    ok &= caseTest(new DescriptorSupport(d1.toXMLString()), "DescriptorSupport(String)");
    d1 = new DescriptorSupport(new String[] { "NAME=blah" });
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(d1);
    oos.close();
    bos.close();
    ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bis);
    d1 = (DescriptorSupport) ois.readObject();
    ok &= caseTest(d1, "serialized DescriptorSupport");
    if (ok)
        System.out.println("Test passed");
    else {
        System.out.println("TEST FAILED");
        System.exit(1);
    }
}
Also used : ArrayList(java.util.ArrayList) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) RuntimeOperationsException(javax.management.RuntimeOperationsException) ByteArrayInputStream(java.io.ByteArrayInputStream) Descriptor(javax.management.Descriptor) List(java.util.List) ArrayList(java.util.ArrayList) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport) RuntimeOperationsException(javax.management.RuntimeOperationsException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Descriptor (javax.management.Descriptor)60 RuntimeOperationsException (javax.management.RuntimeOperationsException)18 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)16 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)15 ImmutableDescriptor (javax.management.ImmutableDescriptor)9 MBeanException (javax.management.MBeanException)9 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)8 MBeanServer (javax.management.MBeanServer)8 ObjectName (javax.management.ObjectName)8 ServiceNotFoundException (javax.management.ServiceNotFoundException)8 Method (java.lang.reflect.Method)7 InstanceNotFoundException (javax.management.InstanceNotFoundException)7 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 FileLogger (mx4j.log.FileLogger)7 Logger (mx4j.log.Logger)7 MBeanLogger (mx4j.log.MBeanLogger)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 Date (java.util.Date)6 ListenerNotFoundException (javax.management.ListenerNotFoundException)6