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;
}
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);
}
}
}
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);
}
}
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", "<descriptor>&&&</descriptor>", "<descriptor>&&&</blahblahblah>", 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);
}
}
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");
}
}
Aggregations