use of javax.management.ImmutableDescriptor 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");
}
}
use of javax.management.ImmutableDescriptor in project jdk8u_jdk by JetBrains.
the class ImmutableDescriptorSerialTest method main.
public static void main(String[] args) throws Exception {
System.out.println("Test that ImmutableDescriptor.EMPTY_DESCRIPTOR " + "deserializes identically");
if (serialize(ImmutableDescriptor.EMPTY_DESCRIPTOR) != ImmutableDescriptor.EMPTY_DESCRIPTOR) {
throw new Exception("ImmutableDescriptor.EMPTY_DESCRIPTOR did not " + "deserialize identically");
}
System.out.println("...OK");
System.out.println("Test that serialization preserves case and " + "that deserialized object is case-insensitive");
Descriptor d = new ImmutableDescriptor("a=aval", "B=Bval", "cC=cCval");
Descriptor d1 = serialize(d);
Set<String> keys = new HashSet(Arrays.asList(d1.getFieldNames()));
if (keys.size() != 3 || !keys.containsAll(Arrays.asList("a", "B", "cC"))) {
throw new Exception("Keys don't match: " + keys);
}
for (String key : keys) {
String value = (String) d.getFieldValue(key);
for (String t : Arrays.asList(key, key.toLowerCase(), key.toUpperCase())) {
String tvalue = (String) d1.getFieldValue(t);
if (!tvalue.equals(value)) {
throw new Exception("Value of " + key + " for " + "deserialized object does not match: " + tvalue + " should be " + value);
}
}
}
System.out.println("...OK");
}
use of javax.management.ImmutableDescriptor in project jdk8u_jdk by JetBrains.
the class DescriptorCache method get.
public ImmutableDescriptor get(ImmutableDescriptor descriptor) {
WeakReference<ImmutableDescriptor> wr = map.get(descriptor);
ImmutableDescriptor got = (wr == null) ? null : wr.get();
if (got != null)
return got;
map.put(descriptor, new WeakReference<ImmutableDescriptor>(descriptor));
return descriptor;
}
use of javax.management.ImmutableDescriptor in project jdk8u_jdk by JetBrains.
the class Introspector method descriptorForAnnotations.
public static Descriptor descriptorForAnnotations(Annotation[] annots) {
if (annots.length == 0)
return ImmutableDescriptor.EMPTY_DESCRIPTOR;
Map<String, Object> descriptorMap = new HashMap<String, Object>();
for (Annotation a : annots) {
Class<? extends Annotation> c = a.annotationType();
Method[] elements = c.getMethods();
boolean packageAccess = false;
for (Method element : elements) {
DescriptorKey key = element.getAnnotation(DescriptorKey.class);
if (key != null) {
String name = key.value();
Object value;
try {
// Avoid checking access more than once per annotation
if (!packageAccess) {
ReflectUtil.checkPackageAccess(c);
packageAccess = true;
}
value = MethodUtil.invoke(element, a, null);
} catch (RuntimeException e) {
//
throw e;
} catch (Exception e) {
// we don't expect this
throw new UndeclaredThrowableException(e);
}
value = annotationToField(value);
Object oldValue = descriptorMap.put(name, value);
if (oldValue != null && !equals(oldValue, value)) {
final String msg = "Inconsistent values for descriptor field " + name + " from annotations: " + value + " :: " + oldValue;
throw new IllegalArgumentException(msg);
}
}
}
}
if (descriptorMap.isEmpty())
return ImmutableDescriptor.EMPTY_DESCRIPTOR;
else
return new ImmutableDescriptor(descriptorMap);
}
use of javax.management.ImmutableDescriptor in project jdk8u_jdk by JetBrains.
the class Basic method setNotifDescriptorAsMapAtt.
/**
* Set the Descriptor used to build the NotificationInfo
* of emitted notifications.
* <br>A Map<String, Object> would better fit Descriptor needs but then
* it is not convertible according the MXBean specification so the MBean
* registration fails.
* As we plan to test our custom Descriptor finds its way into
* the metadata of emitted notifications, String is good enough.
*/
public void setNotifDescriptorAsMapAtt(Map<String, String> value) {
notifDescriptorAsMapAtt = new HashMap<String, String>(value);
notifDescriptorAtt = new ImmutableDescriptor(value);
}
Aggregations