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]));
}
}
}
java类javax.management.Descriptor的实例源码
DcmdMBeanTest.java 文件源码
项目:openjdk-jdk10
阅读 17
收藏 0
点赞 0
评论 0
OpenMBeanAttributeInfoSupport.java 文件源码
项目:openjdk-jdk10
阅读 27
收藏 0
点赞 0
评论 0
static <T> Comparable<?> comparableValueFrom(Descriptor d, String name,
OpenType<T> openType) {
T t = valueFrom(d, name, openType);
if (t == null || t instanceof Comparable<?>)
return (Comparable<?>) t;
final String msg =
"Descriptor field " + name + " with value " + t +
" is not Comparable";
throw new IllegalArgumentException(msg);
}
ModelMBeanInfoSupport.java 文件源码
项目:OpenJSharp
阅读 22
收藏 0
点赞 0
评论 0
/**
* Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
if (compat) {
// Read an object serialized in the old serial form
//
ObjectInputStream.GetField fields = in.readFields();
modelMBeanDescriptor =
(Descriptor) fields.get("modelMBeanDescriptor", null);
if (fields.defaulted("modelMBeanDescriptor")) {
throw new NullPointerException("modelMBeanDescriptor");
}
modelMBeanAttributes =
(MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
if (fields.defaulted("mmbAttributes")) {
throw new NullPointerException("mmbAttributes");
}
modelMBeanConstructors =
(MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
if (fields.defaulted("mmbConstructors")) {
throw new NullPointerException("mmbConstructors");
}
modelMBeanNotifications =
(MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
if (fields.defaulted("mmbNotifications")) {
throw new NullPointerException("mmbNotifications");
}
modelMBeanOperations =
(MBeanOperationInfo[]) fields.get("mmbOperations", null);
if (fields.defaulted("mmbOperations")) {
throw new NullPointerException("mmbOperations");
}
} else {
// Read an object serialized in the new serial form
//
in.defaultReadObject();
}
}
RequiredModelMBean.java 文件源码
项目:OpenJSharp
阅读 20
收藏 0
点赞 0
评论 0
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);
}
}
}
MXBeanIntrospector.java 文件源码
项目:jdk8u-jdk
阅读 27
收藏 0
点赞 0
评论 0
@Override
Descriptor getMBeanDescriptor(Class<?> resourceClass) {
/* We already have immutableInfo=true in the Descriptor
* included in the MBeanInfo for the MXBean interface. This
* method is being called for the MXBean *class* to add any
* new items beyond those in the interface Descriptor, which
* currently it does not.
*/
return ImmutableDescriptor.EMPTY_DESCRIPTOR;
}
MBeanIntrospector.java 文件源码
项目:jdk8u-jdk
阅读 19
收藏 0
点赞 0
评论 0
/** Make an MBeanInfo based on the attributes and operations
* found in the interface. */
MBeanInfo makeMBeanInfo(Class<?> mbeanInterface,
String description) {
final MBeanAttributeInfo[] attrArray =
attrs.toArray(new MBeanAttributeInfo[0]);
final MBeanOperationInfo[] opArray =
ops.toArray(new MBeanOperationInfo[0]);
final String interfaceClassName =
"interfaceClassName=" + mbeanInterface.getName();
final Descriptor classNameDescriptor =
new ImmutableDescriptor(interfaceClassName);
final Descriptor mbeanDescriptor = getBasicMBeanDescriptor();
final Descriptor annotatedDescriptor =
Introspector.descriptorForElement(mbeanInterface);
final Descriptor descriptor =
DescriptorCache.getInstance().union(
classNameDescriptor,
mbeanDescriptor,
annotatedDescriptor);
return new MBeanInfo(mbeanInterface.getName(),
description,
attrArray,
null,
opArray,
null,
descriptor);
}
OpenMBeanParameterInfoSupport.java 文件源码
项目:OpenJSharp
阅读 20
收藏 0
点赞 0
评论 0
/**
* Constructs an {@code OpenMBeanParameterInfoSupport} instance,
* which describes the parameter used in one or more operations or
* constructors of a class of open MBeans, with the specified
* {@code name}, {@code openType}, {@code description},
* and {@code descriptor}.
*
* <p>The {@code descriptor} can contain entries that will define
* the values returned by certain methods of this class, as
* explained in the <a href="package-summary.html#constraints">
* package description</a>.
*
* @param name cannot be a null or empty string.
*
* @param description cannot be a null or empty string.
*
* @param openType cannot be null.
*
* @param descriptor The descriptor for the parameter. This may be null
* which is equivalent to an empty descriptor.
*
* @throws IllegalArgumentException if {@code name} or {@code
* description} are null or empty string, or {@code openType} is
* null, or the descriptor entries are invalid as described in the
* <a href="package-summary.html#constraints">package
* description</a>.
*
* @since 1.6
*/
public OpenMBeanParameterInfoSupport(String name,
String description,
OpenType<?> openType,
Descriptor descriptor) {
// Construct parent's state
//
super(name,
(openType==null) ? null : openType.getClassName(),
description,
ImmutableDescriptor.union(descriptor,(openType==null)?null:
openType.getDescriptor()));
// Initialize this instance's specific state
//
this.openType = openType;
descriptor = getDescriptor(); // replace null by empty
this.defaultValue = valueFrom(descriptor, "defaultValue", openType);
this.legalValues = valuesFrom(descriptor, "legalValues", openType);
this.minValue = comparableValueFrom(descriptor, "minValue", openType);
this.maxValue = comparableValueFrom(descriptor, "maxValue", openType);
try {
check(this);
} catch (OpenDataException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
OpenMBeanAttributeInfoSupport.java 文件源码
项目:openjdk-jdk10
阅读 26
收藏 0
点赞 0
评论 0
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);
}
}
ModelMBeanInfoSupport.java 文件源码
项目:jdk8u-jdk
阅读 20
收藏 0
点赞 0
评论 0
/**
* Creates a ModelMBeanInfoSupport with the provided information
* and the descriptor given in parameter.
*
* @param className classname of the MBean
* @param description human readable description of the
* ModelMBean
* @param attributes array of ModelMBeanAttributeInfo objects
* which have descriptors
* @param constructors array of ModelMBeanConstructorInfo
* objects which have descriptor
* @param operations array of ModelMBeanOperationInfo objects
* which have descriptor
* @param notifications array of ModelMBeanNotificationInfo
* objects which have descriptor
* @param mbeandescriptor descriptor to be used as the
* MBeanDescriptor containing MBean wide policy. If the
* descriptor is null, a default descriptor will be constructed.
* The default descriptor is:
* name=className, descriptorType="mbean", displayName=className,
* persistPolicy="never", log="F", visibility="1". If the descriptor
* does not contain all of these fields, the missing ones are
* added with these default values.
*
* @exception RuntimeOperationsException Wraps an
* IllegalArgumentException for invalid descriptor passed in
* parameter. (see {@link #getMBeanDescriptor
* getMBeanDescriptor} for the definition of a valid MBean
* descriptor.)
*/
public ModelMBeanInfoSupport(String className,
String description,
ModelMBeanAttributeInfo[] attributes,
ModelMBeanConstructorInfo[] constructors,
ModelMBeanOperationInfo[] operations,
ModelMBeanNotificationInfo[] notifications,
Descriptor mbeandescriptor) {
super(className,
description,
(attributes != null) ? attributes : NO_ATTRIBUTES,
(constructors != null) ? constructors : NO_CONSTRUCTORS,
(operations != null) ? operations : NO_OPERATIONS,
(notifications != null) ? notifications : NO_NOTIFICATIONS);
/* The values saved here are possibly null, but we
check this everywhere they are referenced. If at
some stage we replace null with an empty array
here, as we do in the superclass constructor
parameters, then we must also do this in
readObject(). */
modelMBeanAttributes = attributes;
modelMBeanConstructors = constructors;
modelMBeanOperations = operations;
modelMBeanNotifications = notifications;
modelMBeanDescriptor = validDescriptor(mbeandescriptor);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanInfoSupport.class.getName(),
"ModelMBeanInfoSupport(String,String,ModelMBeanAttributeInfo[]," +
"ModelMBeanConstructorInfo[],ModelMBeanOperationInfo[]," +
"ModelMBeanNotificationInfo[],Descriptor)",
"Exit");
}
}
ModelMBeanInfoSupport.java 文件源码
项目:jdk8u-jdk
阅读 20
收藏 0
点赞 0
评论 0
/**
* Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
if (compat) {
// Read an object serialized in the old serial form
//
ObjectInputStream.GetField fields = in.readFields();
modelMBeanDescriptor =
(Descriptor) fields.get("modelMBeanDescriptor", null);
if (fields.defaulted("modelMBeanDescriptor")) {
throw new NullPointerException("modelMBeanDescriptor");
}
modelMBeanAttributes =
(MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
if (fields.defaulted("mmbAttributes")) {
throw new NullPointerException("mmbAttributes");
}
modelMBeanConstructors =
(MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
if (fields.defaulted("mmbConstructors")) {
throw new NullPointerException("mmbConstructors");
}
modelMBeanNotifications =
(MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
if (fields.defaulted("mmbNotifications")) {
throw new NullPointerException("mmbNotifications");
}
modelMBeanOperations =
(MBeanOperationInfo[]) fields.get("mmbOperations", null);
if (fields.defaulted("mmbOperations")) {
throw new NullPointerException("mmbOperations");
}
} else {
// Read an object serialized in the new serial form
//
in.defaultReadObject();
}
}