Search in sources :

Example 6 with RuntimeOperationsException

use of javax.management.RuntimeOperationsException in project tomcat by apache.

the class ManagedBean method createMBean.

/**
     * Create and return a <code>ModelMBean</code> that has been
     * preconfigured with the <code>ModelMBeanInfo</code> information
     * for this managed bean, and is associated with the specified
     * managed object instance.  The returned <code>ModelMBean</code>
     * will <strong>NOT</strong> have been registered with our
     * <code>MBeanServer</code>.
     *
     * @param instance Instanced of the managed object, or <code>null</code>
     *  for no associated instance
     * @return the MBean
     * @exception InstanceNotFoundException if the managed resource
     *  object cannot be found
     * @exception MBeanException if a problem occurs instantiating the
     *  <code>ModelMBean</code> instance
     * @exception RuntimeOperationsException if a JMX runtime error occurs
     */
public DynamicMBean createMBean(Object instance) throws InstanceNotFoundException, MBeanException, RuntimeOperationsException {
    BaseModelMBean mbean = null;
    // Load the ModelMBean implementation class
    if (getClassName().equals(BASE_MBEAN)) {
        // Skip introspection
        mbean = new BaseModelMBean();
    } else {
        Class<?> clazz = null;
        Exception ex = null;
        try {
            clazz = Class.forName(getClassName());
        } catch (Exception e) {
        }
        if (clazz == null) {
            try {
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                if (cl != null)
                    clazz = cl.loadClass(getClassName());
            } catch (Exception e) {
                ex = e;
            }
        }
        if (clazz == null) {
            throw new MBeanException(ex, "Cannot load ModelMBean class " + getClassName());
        }
        try {
            // Stupid - this will set the default minfo first....
            mbean = (BaseModelMBean) clazz.newInstance();
        } catch (RuntimeOperationsException e) {
            throw e;
        } catch (Exception e) {
            throw new MBeanException(e, "Cannot instantiate ModelMBean of class " + getClassName());
        }
    }
    mbean.setManagedBean(this);
    // Set the managed resource (if any)
    try {
        if (instance != null)
            mbean.setManagedResource(instance, "ObjectReference");
    } catch (InstanceNotFoundException e) {
        throw e;
    }
    return mbean;
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) AttributeNotFoundException(javax.management.AttributeNotFoundException) ServiceNotFoundException(javax.management.ServiceNotFoundException) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 7 with RuntimeOperationsException

use of javax.management.RuntimeOperationsException in project tomcat by apache.

the class SlowQueryReportJmx method notifyJmx.

protected void notifyJmx(String query, String type) {
    try {
        long sequence = notifySequence.incrementAndGet();
        if (isNotifyPool()) {
            if (this.pool != null && this.pool.getJmxPool() != null) {
                this.pool.getJmxPool().notify(type, query);
            }
        } else {
            if (notifier != null) {
                Notification notification = new Notification(type, this, sequence, System.currentTimeMillis(), query);
                notifier.sendNotification(notification);
            }
        }
    } catch (RuntimeOperationsException e) {
        if (log.isDebugEnabled()) {
            log.debug("Unable to send failed query notification.", e);
        }
    }
}
Also used : Notification(javax.management.Notification) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 8 with RuntimeOperationsException

use of javax.management.RuntimeOperationsException 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)

Example 9 with RuntimeOperationsException

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

the class DescriptorSupportXMLTest method main.

public static void main(String[] args) throws Exception {
    System.out.println("Testing that DescriptorSupport.toXMLString() " + "can be used to reconstruct an equivalent " + "DescriptorSupport");
    int failed = 0;
    final Object[] testValues = { // Values that should be encodable.
    "", "ok", "null", "(open", "close)", "(parens)", "quote\"quote", "a description with several words", "magic&\"\\<> \r\t\n\f;&;magic", "&lt;descriptor&gt;&&&&lt;/descriptor&gt;", "&lt;descriptor&gt;&&&&lt;/blahblahblah&gt;", null, new Integer(10), Boolean.TRUE, new Float(1.0f), // because they don't have a (String) constructor.
    new Character('!'), new java.util.HashMap() };
    for (int i = 0; i < testValues.length; i++) {
        final Object v = testValues[i];
        final String what = (v == null) ? "null" : (v.getClass().getName() + "{" + v + "}");
        final DescriptorSupport in = new DescriptorSupport(new String[] { "bloo" }, new Object[] { v });
        final String xml;
        try {
            xml = in.toXMLString();
        } catch (RuntimeOperationsException e) {
            final Throwable cause = e.getCause();
            if (cause instanceof IllegalArgumentException) {
                System.out.println("OK: " + what + ": got a " + "RuntimeOperationsException wrapping " + "an IllegalArgumentException: " + cause.getMessage());
            } else {
                final String causeString = (cause == null) ? "null" : cause.getClass().getName();
                System.out.println("FAILED: " + what + ": got a " + "RuntimeOperationException wrapping " + causeString);
                failed++;
            }
            continue;
        }
        System.out.println("Encoded " + what + " as " + xml);
        final DescriptorSupport out;
        try {
            out = new DescriptorSupport(xml);
        } catch (Exception e) {
            System.out.println("FAILED: " + what + ": got an exception:");
            e.printStackTrace(System.out);
            failed++;
            continue;
        }
        final String[] names = out.getFieldNames();
        if (names.length != 1 || !"bloo".equals(names[0])) {
            System.out.println("FAILED: decoded names wrong: " + Arrays.asList(names));
            failed++;
            continue;
        }
        final Object[] values = out.getFieldValues(names);
        if (values.length != 1) {
            System.out.println("FAILED: wrong number of values: " + Arrays.asList(values));
            failed++;
            continue;
        }
        final Object outValue = values[0];
        if (v == null) {
            if (outValue == null)
                System.out.println("OK: decoded null value");
            else {
                System.out.println("FAILED: decoded null value as " + outValue.getClass().getName() + "{" + outValue + "}");
                failed++;
            }
            continue;
        }
        if (outValue == null) {
            System.out.println("FAILED: decoded non-null value as null");
            failed++;
            continue;
        }
        if (v.getClass() != outValue.getClass()) {
            System.out.println("FAILED: decoded value has class " + outValue.getClass().getName() + "{" + outValue + "}");
            failed++;
            continue;
        }
        if (v.equals(outValue))
            System.out.println("OK: decoded value is equal to original");
        else {
            System.out.println("FAILED: decoded value is different: {" + outValue + "}");
            failed++;
        }
    }
    if (failed == 0)
        System.out.println("OK: all tests passed");
    else {
        System.out.println("TEST FAILED: fail count: " + failed);
        System.exit(1);
    }
}
Also used : DescriptorSupport(javax.management.modelmbean.DescriptorSupport) RuntimeOperationsException(javax.management.RuntimeOperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 10 with RuntimeOperationsException

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

the class ImmutableDescriptorSetFieldsTest method main.

public static void main(String[] args) throws Exception {
    boolean ok = true;
    ImmutableDescriptor d = new ImmutableDescriptor("k=v");
    try {
        System.out.println("Call ImmutableDescriptor.setFields(fieldNames,fieldValues) " + "with empty name in field names array");
        String[] fieldNames = { "a", "", "c" };
        Object[] fieldValues = { 1, 2, 3 };
        d.setFields(fieldNames, fieldValues);
        System.out.println("Didn't get expected exception");
        ok = false;
    } catch (RuntimeOperationsException e) {
        if (e.getCause() instanceof IllegalArgumentException) {
            System.out.println("Got expected exception:");
            ok = true;
        } else {
            System.out.println("Got unexpected exception:");
            ok = false;
        }
        e.printStackTrace(System.out);
    } catch (Exception e) {
        System.out.println("Got unexpected exception:");
        ok = false;
        e.printStackTrace(System.out);
    }
    try {
        System.out.println("Call ImmutableDescriptor.setFields(fieldNames,fieldValues) " + "with null name in field names array");
        String[] fieldNames = { "a", null, "c" };
        Object[] fieldValues = { 1, 2, 3 };
        d.setFields(fieldNames, fieldValues);
        System.out.println("Didn't get expected exception");
        ok = false;
    } catch (RuntimeOperationsException e) {
        if (e.getCause() instanceof IllegalArgumentException) {
            System.out.println("Got expected exception:");
            ok = true;
        } else {
            System.out.println("Got unexpected exception:");
            ok = false;
        }
        e.printStackTrace(System.out);
    } catch (Exception e) {
        System.out.println("Got unexpected exception:");
        ok = false;
        e.printStackTrace(System.out);
    }
    if (ok) {
        System.out.println("TEST PASSED");
    } else {
        System.out.println("TEST FAILED");
        throw new Exception("Got unexpected exceptions");
    }
}
Also used : ImmutableDescriptor(javax.management.ImmutableDescriptor) RuntimeOperationsException(javax.management.RuntimeOperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

RuntimeOperationsException (javax.management.RuntimeOperationsException)67 AttributeNotFoundException (javax.management.AttributeNotFoundException)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)20 ReflectionException (javax.management.ReflectionException)20 MBeanException (javax.management.MBeanException)18 Descriptor (javax.management.Descriptor)17 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)16 ListenerNotFoundException (javax.management.ListenerNotFoundException)16 RuntimeErrorException (javax.management.RuntimeErrorException)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 ServiceNotFoundException (javax.management.ServiceNotFoundException)13 DynamicMBean (javax.management.DynamicMBean)10 FileLogger (mx4j.log.FileLogger)10 Logger (mx4j.log.Logger)10 MBeanLogger (mx4j.log.MBeanLogger)10 MBeanRegistrationException (javax.management.MBeanRegistrationException)9 JMRuntimeException (javax.management.JMRuntimeException)8 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)8 Attribute (javax.management.Attribute)7 Date (java.util.Date)6