Java Code Examples for javax.management.Descriptor#getFieldValue()
The following examples show how to use
javax.management.Descriptor#getFieldValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenMBeanParameterInfoSupport.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
private <T> OpenMBeanParameterInfoSupport(String name, String description, OpenType<T> openType, T defaultValue, T[] legalValues, Comparable<T> minValue, Comparable<T> maxValue) throws OpenDataException { super(name, (openType == null) ? null : openType.getClassName(), description, makeDescriptor(openType, defaultValue, legalValues, minValue, maxValue)); this.openType = openType; Descriptor d = getDescriptor(); this.defaultValue = defaultValue; this.minValue = minValue; this.maxValue = maxValue; // We already converted the array into an unmodifiable Set // in the descriptor. this.legalValues = (Set<?>) d.getFieldValue("legalValues"); check(this); }
Example 2
Source File: OpenMBeanParameterInfoSupport.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private <T> OpenMBeanParameterInfoSupport(String name, String description, OpenType<T> openType, T defaultValue, T[] legalValues, Comparable<T> minValue, Comparable<T> maxValue) throws OpenDataException { super(name, (openType == null) ? null : openType.getClassName(), description, makeDescriptor(openType, defaultValue, legalValues, minValue, maxValue)); this.openType = openType; Descriptor d = getDescriptor(); this.defaultValue = defaultValue; this.minValue = minValue; this.maxValue = maxValue; // We already converted the array into an unmodifiable Set // in the descriptor. this.legalValues = (Set<?>) d.getFieldValue("legalValues"); check(this); }
Example 3
Source File: MX4JModelMBean.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private Object resolveTargetObject(Descriptor descriptor) throws MBeanException { Logger logger = getLogger(); Object target = descriptor.getFieldValue("targetObject"); if (logger.isEnabledFor(Logger.TRACE)) logger.trace("targetObject is: " + target); if (target == null) { target = getManagedResource(); } else { String targetObjectType = (String)descriptor.getFieldValue("targetObjectType"); if (logger.isEnabledFor(Logger.TRACE)) logger.trace("targetObjectType is: " + targetObjectType); if (targetObjectType == null) { // Not defined, assume object reference targetObjectType = OBJECT_RESOURCE_TYPE; } if (!isResourceTypeSupported(targetObjectType)) throw new MBeanException(new InvalidTargetObjectTypeException(targetObjectType)); } return target; }
Example 4
Source File: ImmutableNotificationInfoTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private static boolean test(Object mbean, boolean expectImmutable) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("a:b=c"); mbs.registerMBean(mbean, on); MBeanInfo mbi = mbs.getMBeanInfo(on); Descriptor d = mbi.getDescriptor(); String immutableValue = (String) d.getFieldValue("immutableInfo"); boolean immutable = ("true".equals(immutableValue)); if (immutable != expectImmutable) { System.out.println("FAILED: " + mbean.getClass().getName() + " -> " + immutableValue); return false; } else { System.out.println("OK: " + mbean.getClass().getName()); return true; } }
Example 5
Source File: ImmutableNotificationInfoTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static boolean test(Object mbean, boolean expectImmutable) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("a:b=c"); mbs.registerMBean(mbean, on); MBeanInfo mbi = mbs.getMBeanInfo(on); Descriptor d = mbi.getDescriptor(); String immutableValue = (String) d.getFieldValue("immutableInfo"); boolean immutable = ("true".equals(immutableValue)); if (immutable != expectImmutable) { System.out.println("FAILED: " + mbean.getClass().getName() + " -> " + immutableValue); return false; } else { System.out.println("OK: " + mbean.getClass().getName()); return true; } }
Example 6
Source File: ImmutableNotificationInfoTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private static boolean test(Object mbean, boolean expectImmutable) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("a:b=c"); mbs.registerMBean(mbean, on); MBeanInfo mbi = mbs.getMBeanInfo(on); Descriptor d = mbi.getDescriptor(); String immutableValue = (String) d.getFieldValue("immutableInfo"); boolean immutable = ("true".equals(immutableValue)); if (immutable != expectImmutable) { System.out.println("FAILED: " + mbean.getClass().getName() + " -> " + immutableValue); return false; } else { System.out.println("OK: " + mbean.getClass().getName()); return true; } }
Example 7
Source File: DcmdMBeanTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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])); } } }
Example 8
Source File: OpenMBeanAttributeInfoSupport.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static <T> T valueFrom(Descriptor d, String name, OpenType<T> openType) { Object x = d.getFieldValue(name); if (x == null) return null; try { return convertFrom(x, openType); } catch (Exception e) { final String msg = "Cannot convert descriptor field " + name + " to " + openType.getTypeName(); throw EnvHelp.initCause(new IllegalArgumentException(msg), e); } }
Example 9
Source File: ImmutableDescriptorSerialTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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"); }
Example 10
Source File: OpenMBeanAttributeInfoSupport.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private <T> OpenMBeanAttributeInfoSupport(String name, String description, OpenType<T> openType, boolean isReadable, boolean isWritable, boolean isIs, T defaultValue, T[] legalValues, Comparable<T> minValue, Comparable<T> maxValue) throws OpenDataException { super(name, (openType==null) ? null : openType.getClassName(), description, isReadable, isWritable, isIs, makeDescriptor(openType, defaultValue, legalValues, minValue, maxValue)); this.openType = openType; Descriptor d = getDescriptor(); this.defaultValue = defaultValue; this.minValue = minValue; this.maxValue = maxValue; // We already converted the array into an unmodifiable Set // in the descriptor. this.legalValues = (Set<?>) d.getFieldValue("legalValues"); check(this); }
Example 11
Source File: OpenMBeanAttributeInfoSupport.java From JDKSourceCode1.8 with MIT License | 5 votes |
private <T> OpenMBeanAttributeInfoSupport(String name, String description, OpenType<T> openType, boolean isReadable, boolean isWritable, boolean isIs, T defaultValue, T[] legalValues, Comparable<T> minValue, Comparable<T> maxValue) throws OpenDataException { super(name, (openType==null) ? null : openType.getClassName(), description, isReadable, isWritable, isIs, makeDescriptor(openType, defaultValue, legalValues, minValue, maxValue)); this.openType = openType; Descriptor d = getDescriptor(); this.defaultValue = defaultValue; this.minValue = minValue; this.maxValue = maxValue; // We already converted the array into an unmodifiable Set // in the descriptor. this.legalValues = (Set<?>) d.getFieldValue("legalValues"); check(this); }
Example 12
Source File: DcmdMBeanTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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])); } } }
Example 13
Source File: OpenMBeanAttributeInfoSupport.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
static <T> T valueFrom(Descriptor d, String name, OpenType<T> openType) { Object x = d.getFieldValue(name); if (x == null) return null; try { return convertFrom(x, openType); } catch (Exception e) { final String msg = "Cannot convert descriptor field " + name + " to " + openType.getTypeName(); throw EnvHelp.initCause(new IllegalArgumentException(msg), e); } }
Example 14
Source File: ImmutableDescriptorSerialTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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"); }
Example 15
Source File: OpenMBeanAttributeInfoSupport.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
static <T> T valueFrom(Descriptor d, String name, OpenType<T> openType) { Object x = d.getFieldValue(name); if (x == null) return null; try { return convertFrom(x, openType); } catch (Exception e) { final String msg = "Cannot convert descriptor field " + name + " to " + openType.getTypeName(); throw EnvHelp.initCause(new IllegalArgumentException(msg), e); } }
Example 16
Source File: RequiredModelMBean.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void cacheResult(ModelMBeanOperationInfo opInfo, Descriptor opDescr, Object result) throws MBeanException { Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor(); Object objctl = opDescr.getFieldValue("currencyTimeLimit"); String ctl; if (objctl != null) { ctl = objctl.toString(); } else { ctl = null; } if ((ctl == null) && (mmbDesc != null)) { objctl = mmbDesc.getFieldValue("currencyTimeLimit"); if (objctl != null) { ctl = objctl.toString(); } else { ctl = null; } } if ((ctl != null) && !(ctl.equals("-1"))) { opDescr.setField("value", result); opDescr.setField("lastUpdatedTimeStamp", String.valueOf((new Date()).getTime())); modelMBeanInfo.setDescriptor(opDescr, "operation"); if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "invoke(String,Object[],Object[])", "new descriptor is " + opDescr); } } }
Example 17
Source File: OpenMBeanAttributeInfoSupport.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
private <T> OpenMBeanAttributeInfoSupport(String name, String description, OpenType<T> openType, boolean isReadable, boolean isWritable, boolean isIs, T defaultValue, T[] legalValues, Comparable<T> minValue, Comparable<T> maxValue) throws OpenDataException { super(name, (openType==null) ? null : openType.getClassName(), description, isReadable, isWritable, isIs, makeDescriptor(openType, defaultValue, legalValues, minValue, maxValue)); this.openType = openType; Descriptor d = getDescriptor(); this.defaultValue = defaultValue; this.minValue = minValue; this.maxValue = maxValue; // We already converted the array into an unmodifiable Set // in the descriptor. this.legalValues = (Set<?>) d.getFieldValue("legalValues"); check(this); }
Example 18
Source File: DescriptorSupportTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private static boolean caseTest(Descriptor d, String what) { boolean ok = true; System.out.println("..." + what); String[] names = d.getFieldNames(); if (names.length != 1 || !names[0].equals("NAME")) { ok = false; System.out.println("...getFieldNames() fails: " + Arrays.asList(names)); } String[] fields = d.getFields(); if (fields.length != 1 || !fields[0].equals("NAME=blah")) { ok = false; System.out.println("...getFields() fails: " + Arrays.asList(fields)); } Object value = d.getFieldValue("namE"); if (!"blah".equals(value)) { ok = false; System.out.println("...getFieldValue(\"namE\") fails: " + value); } Object[] values = d.getFieldValues(new String[] {"namE"}); if (values.length != 1 || !"blah".equals(values[0])) { ok = false; System.out.println("...getFieldValues({\"namE\"}) fails: " + Arrays.asList(values)); } d.setField("namE", "newblah"); Object newblah = d.getFieldValue("Name"); if (!"newblah".equals(newblah)) { ok = false; System.out.println("...setField value not returned: " + newblah); } d.setFields(new String[] {"NaMe"}, new Object[] {"newerblah"}); Object newerblah = d.getFieldValue("naMe"); if (!"newerblah".equals(newerblah)) { ok = false; System.out.println("...setFields value not returned: " + newerblah); } Descriptor d1 = (Descriptor) d.clone(); newerblah = d1.getFieldValue("NAMe"); if (!"newerblah".equals(newerblah)) { ok = false; System.out.println("...clone incorrect: " + newerblah); } d.removeField("NAme"); names = d.getFieldNames(); if (names.length != 0) { ok = false; System.out.println("...removeField failed: " + Arrays.asList(names)); } if (ok) System.out.println("...succeeded"); return ok; }
Example 19
Source File: RequiredModelMBean.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public void sendNotification(Notification ntfyObj) throws MBeanException, RuntimeOperationsException { if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "Entry"); } if (ntfyObj == null) throw new RuntimeOperationsException(new IllegalArgumentException("notification object must not be "+ "null"), "Exception occurred trying to send a notification from a "+ "RequiredModelMBean"); // log notification if specified in descriptor Descriptor ntfyDesc = modelMBeanInfo.getDescriptor(ntfyObj.getType(),"notification"); Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor(); if (ntfyDesc != null) { String logging = (String) ntfyDesc.getFieldValue("log"); if (logging == null) { if (mmbDesc != null) logging = (String) mmbDesc.getFieldValue("log"); } if ((logging != null) && (logging.equalsIgnoreCase("t") || logging.equalsIgnoreCase("true"))) { String logfile = (String) ntfyDesc.getFieldValue("logfile"); if (logfile == null) { if (mmbDesc != null) logfile = (String)mmbDesc.getFieldValue("logfile"); } if (logfile != null) { try { writeToLog(logfile,"LogMsg: " + ((new Date(ntfyObj.getTimeStamp())).toString())+ " " + ntfyObj.getType() + " " + ntfyObj.getMessage() + " Severity = " + (String)ntfyDesc.getFieldValue("severity")); } catch (Exception e) { if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) { MODELMBEAN_LOGGER.logp(Level.FINE, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "Failed to log " + ntfyObj.getType() + " notification: ", e); } } } } } if (generalBroadcaster != null) { generalBroadcaster.sendNotification(ntfyObj); } if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "sendNotification sent provided notification object"); MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)"," Exit"); } }
Example 20
Source File: RequiredModelMBean.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
public void sendNotification(Notification ntfyObj) throws MBeanException, RuntimeOperationsException { if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "Entry"); } if (ntfyObj == null) throw new RuntimeOperationsException(new IllegalArgumentException("notification object must not be "+ "null"), "Exception occurred trying to send a notification from a "+ "RequiredModelMBean"); // log notification if specified in descriptor Descriptor ntfyDesc = modelMBeanInfo.getDescriptor(ntfyObj.getType(),"notification"); Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor(); if (ntfyDesc != null) { String logging = (String) ntfyDesc.getFieldValue("log"); if (logging == null) { if (mmbDesc != null) logging = (String) mmbDesc.getFieldValue("log"); } if ((logging != null) && (logging.equalsIgnoreCase("t") || logging.equalsIgnoreCase("true"))) { String logfile = (String) ntfyDesc.getFieldValue("logfile"); if (logfile == null) { if (mmbDesc != null) logfile = (String)mmbDesc.getFieldValue("logfile"); } if (logfile != null) { try { writeToLog(logfile,"LogMsg: " + ((new Date(ntfyObj.getTimeStamp())).toString())+ " " + ntfyObj.getType() + " " + ntfyObj.getMessage() + " Severity = " + (String)ntfyDesc.getFieldValue("severity")); } catch (Exception e) { if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) { MODELMBEAN_LOGGER.logp(Level.FINE, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "Failed to log " + ntfyObj.getType() + " notification: ", e); } } } } } if (generalBroadcaster != null) { generalBroadcaster.sendNotification(ntfyObj); } if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "sendNotification sent provided notification object"); MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)"," Exit"); } }