Search in sources :

Example 71 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project spf4j by zolyfarkas.

the class ExportedValuesMBean method setAttribute.

/**
 * {@inheritDoc}
 */
@Override
public void setAttribute(final Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    String name = attribute.getName();
    ExportedValue<Object> result = (ExportedValue<Object>) exportedValues.get(name);
    if (result == null) {
        throw new AttributeNotFoundException(name);
    }
    try {
        result.set(attribute.getValue());
    } catch (SecurityException ex) {
        throw ex;
    } catch (InvalidObjectException | RuntimeException ex) {
        Logger.getLogger(ExportedValuesMBean.class.getName()).log(Level.SEVERE, "Exception while setting attr: " + attribute, ex);
        InvalidAttributeValueException jx = new InvalidAttributeValueException("Invalid value " + attribute);
        jx.addSuppressed(ex);
        throw jx;
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) JMRuntimeException(javax.management.JMRuntimeException) InvalidObjectException(java.io.InvalidObjectException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Example 72 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project openj9 by eclipse.

the class TestLoggingMXBean method testSetAttribute.

@Test
public final void testSetAttribute() {
    // The only attribute for this type is not a writable one.
    Attribute attr = new Attribute("LoggerLevel", "Boris");
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (AttributeNotFoundException | ReflectionException e) {
    // One of these exceptions is expected.
    } catch (Exception e) {
        Assert.fail("Unexpected exception: " + e.getMessage());
    }
    attr = new Attribute("LoggerNames", new String[] { "Strummer", "Jones" });
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (AttributeNotFoundException | ReflectionException e) {
    // One of these exceptions is expected.
    } catch (Exception e) {
        Assert.fail("Unexpected exception: " + e.getMessage());
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) MBeanException(javax.management.MBeanException) Test(org.testng.annotations.Test)

Example 73 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project openj9 by eclipse.

the class MyTestListener method testSetAttribute.

@Test
public final void testSetAttribute() {
    // The only writable attribute of this type of bean
    Attribute attr = null;
    try {
        attr = new Attribute("Verbose", Boolean.valueOf(true));
        mbs.setAttribute(objName, attr);
    } catch (AttributeNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected AttributeNotFoundException " + e.getMessage());
    } catch (InvalidAttributeValueException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InvalidAttributeValueException occurred (Verbose): " + e.getMessage());
    } catch (MBeanException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected MBeanException occurred (Verbose): " + e.getCause().getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (Verbose): " + e.getCause().getMessage());
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (Verbose): " + e.getMessage());
    }
    // Now check that the other, readonly attributes can't be set.
    MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
    CompositeData cd = MemoryUsageUtil.toCompositeData(mu);
    attr = new Attribute("HeapMemoryUsage", cd);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (HeapMemoryUsage): " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (HeapMemoryUsage): " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    attr = new Attribute("NonHeapMemoryUsage", cd);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (NonHeapMemoryUsage): " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (NonHeapMemoryUsage): " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    attr = new Attribute("ObjectPendingFinalizationCount", Long.valueOf(38));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (ObjectPendingFinalizationCount): " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (ObjectPendingFinalizationCount): " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    // Try and set the Verbose attribute with an incorrect type.
    attr = new Attribute("Verbose", Long.valueOf(42));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (Verbose): " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (Verbose): " + e.getMessage());
    } catch (Exception e2) {
        AssertJUnit.assertTrue(e2 instanceof javax.management.InvalidAttributeValueException);
        logger.debug("Exception occurred, as expected: " + e2.getMessage());
    }
    // set Verbose back to false
    try {
        attr = new Attribute("Verbose", Boolean.valueOf(false));
        mbs.setAttribute(objName, attr);
    } catch (AttributeNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected AttributeNotFoundException " + e.getMessage());
    } catch (InvalidAttributeValueException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InvalidAttributeValueException occurred (Verbose): " + e.getMessage());
    } catch (MBeanException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected MBeanException occurred (Verbose): " + e.getCause().getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (Verbose): " + e.getCause().getMessage());
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (Verbose): " + e.getMessage());
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) CompositeData(javax.management.openmbean.CompositeData) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MemoryUsage(java.lang.management.MemoryUsage) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) Test(org.testng.annotations.Test)

Example 74 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project openj9 by eclipse.

the class TestCompilationMXBean method testSetAttribute.

/* Test the setAttribute() API. */
@Test
public final void testSetAttribute() {
    // Nothing is writable for this type. Try setting values into those readonly attributes ...
    Attribute attr = new Attribute("Name", "Boris");
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + "attempting to set a read-only attribute.");
    }
    attr = new Attribute("TotalCompilationTime", Long.valueOf(65533));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + "attempting to set a read-only attribute.");
    }
    attr = new Attribute("CompilationTimeMonitoringSupported", Boolean.valueOf(true));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + "attempting to set a read-only attribute.");
    }
    // Try and set the Name attribute with an incorrect type.
    attr = new Attribute("Name", Long.valueOf(42));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception");
    } catch (InstanceNotFoundException e) {
        Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
    } catch (Exception e2) {
        AssertJUnit.assertTrue(e2 instanceof javax.management.AttributeNotFoundException);
        logger.debug("AttributeNotFoundException Exception occurred, as expected: " + e2.getMessage());
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) MBeanException(javax.management.MBeanException) Test(org.testng.annotations.Test)

Example 75 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project openj9 by eclipse.

the class AttributeData method testSetAttribute.

@Test
public final void testSetAttribute() {
    Attribute attr = null;
    try {
        // The one writable attribute of ClassLoadingMXBean...
        Boolean before = (Boolean) mbs.getAttribute(objName, "Verbose");
        // Toggle the boolean state of "isVerbose"
        boolean newVal = !before;
        attr = new Attribute("Verbose", Boolean.valueOf(newVal));
        mbs.setAttribute(objName, attr);
        Boolean after = (Boolean) mbs.getAttribute(objName, "Verbose");
        assert (newVal == after);
    } catch (AttributeNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected AttributeNotFoundException " + e.getMessage());
    } catch (InvalidAttributeValueException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InvalidAttributeValueException " + e.getMessage());
    } catch (MBeanException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected MBeanException " + e.getCause().getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException " + e.getCause().getMessage());
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
    }
    // Let's try and set some non-writable attributes.
    attr = new Attribute("LoadedClassCount", Integer.valueOf(25));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    attr = new Attribute("TotalLoadedClassCount", Long.valueOf(3300));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    attr = new Attribute("UnloadedClassCount", Long.valueOf(38));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    // Try and set the Verbose attribute with an incorrect type.
    attr = new Attribute("Verbose", Long.valueOf(42));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
    } catch (Exception e2) {
        AssertJUnit.assertTrue(e2 instanceof javax.management.InvalidAttributeValueException);
        logger.debug("Exception occurred, as expected: " + e2.getMessage());
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) Test(org.testng.annotations.Test)

Aggregations

AttributeNotFoundException (javax.management.AttributeNotFoundException)77 ReflectionException (javax.management.ReflectionException)57 MBeanException (javax.management.MBeanException)54 InstanceNotFoundException (javax.management.InstanceNotFoundException)40 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)30 Attribute (javax.management.Attribute)26 ObjectName (javax.management.ObjectName)24 RuntimeOperationsException (javax.management.RuntimeOperationsException)16 IntrospectionException (javax.management.IntrospectionException)13 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)13 AttributeList (javax.management.AttributeList)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Method (java.lang.reflect.Method)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 Test (org.testng.annotations.Test)9 MBeanInfo (javax.management.MBeanInfo)8 ListenerNotFoundException (javax.management.ListenerNotFoundException)7 RuntimeErrorException (javax.management.RuntimeErrorException)7 RuntimeMBeanException (javax.management.RuntimeMBeanException)7 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)7