FileDocCategorySizeDatePackage
MBeanInfo.javaAPI DocJava SE 6 API25346Tue Jun 10 00:26:12 BST 2008javax.management

MBeanInfo

public class MBeanInfo extends Object implements Serializable, DescriptorRead, Cloneable

Describes the management interface exposed by an MBean; that is, the set of attributes and operations which are available for management operations. Instances of this class are immutable. Subclasses may be mutable but this is not recommended.

The contents of the MBeanInfo for a Dynamic MBean are determined by its {@link DynamicMBean#getMBeanInfo getMBeanInfo()} method. This includes Open MBeans and Model MBeans, which are kinds of Dynamic MBeans.

The contents of the MBeanInfo for a Standard MBean are determined by the MBean server as follows:

  • {@link #getClassName()} returns the Java class name of the MBean object;
  • {@link #getConstructors()} returns the list of all public constructors in that object;
  • {@link #getAttributes()} returns the list of all attributes whose existence is deduced from the presence in the MBean interface of a getName, isName, or setName method that conforms to the conventions for Standard MBeans;
  • {@link #getOperations()} returns the list of all methods in the MBean interface that do not represent attributes;
  • {@link #getNotifications()} returns an empty array if the MBean does not implement the {@link NotificationBroadcaster} interface, otherwise the result of calling {@link NotificationBroadcaster#getNotificationInfo()} on it;
  • {@link #getDescriptor()} returns a descriptor containing the contents of any descriptor annotations in the MBean interface.

The description returned by {@link #getDescription()} and the descriptions of the contained attributes and operations are determined by the corresponding Description annotations if any; otherwise their contents are not specified.

The remaining details of the MBeanInfo for a Standard MBean are not specified. This includes the description of any contained constructors, and notifications; the names of parameters to constructors and operations; and the descriptions of constructor parameters.

since
1.5

Fields Summary
static final long
serialVersionUID
private transient Descriptor
descriptor
private final String
description
private final String
className
private final MBeanAttributeInfo[]
attributes
private final MBeanOperationInfo[]
operations
private final MBeanConstructorInfo[]
constructors
private final MBeanNotificationInfo[]
notifications
private transient int
hashCode
private final transient boolean
arrayGettersSafe

True if this class is known not to override the array-valued getters of MBeanInfo. Obviously true for MBeanInfo itself, and true for a subclass where we succeed in reflecting on the methods and discover they are not overridden.

The purpose of this variable is to avoid cloning the arrays when doing operations like {@link #equals} where we know they will not be changed. If a subclass overrides a getter, we cannot access the corresponding array directly.

private static final Map
arrayGettersSafeMap
Cached results of previous calls to arrayGettersSafe. This is a WeakHashMap so that we don't prevent a class from being garbage collected just because we know whether it's immutable.
Constructors Summary
public MBeanInfo(String className, String description, MBeanAttributeInfo[] attributes, MBeanConstructorInfo[] constructors, MBeanOperationInfo[] operations, MBeanNotificationInfo[] notifications)
Constructs an MBeanInfo.

param
className The name of the Java class of the MBean described by this MBeanInfo. This value may be any syntactically legal Java class name. It does not have to be a Java class known to the MBean server or to the MBean's ClassLoader. If it is a Java class known to the MBean's ClassLoader, it is recommended but not required that the class's public methods include those that would appear in a Standard MBean implementing the attributes and operations in this MBeanInfo.
param
description A human readable description of the MBean (optional).
param
attributes The list of exposed attributes of the MBean. This may be null with the same effect as a zero-length array.
param
constructors The list of public constructors of the MBean. This may be null with the same effect as a zero-length array.
param
operations The list of operations of the MBean. This may be null with the same effect as a zero-length array.
param
notifications The list of notifications emitted. This may be null with the same effect as a zero-length array.


                                                                                                                                                                                                   
      
		      
		      
		      
		      
		      
	      
        this(className, description, attributes, constructors, operations,
             notifications, null);
    
public MBeanInfo(String className, String description, MBeanAttributeInfo[] attributes, MBeanConstructorInfo[] constructors, MBeanOperationInfo[] operations, MBeanNotificationInfo[] notifications, Descriptor descriptor)
Constructs an MBeanInfo.

param
className The name of the Java class of the MBean described by this MBeanInfo. This value may be any syntactically legal Java class name. It does not have to be a Java class known to the MBean server or to the MBean's ClassLoader. If it is a Java class known to the MBean's ClassLoader, it is recommended but not required that the class's public methods include those that would appear in a Standard MBean implementing the attributes and operations in this MBeanInfo.
param
description A human readable description of the MBean (optional).
param
attributes The list of exposed attributes of the MBean. This may be null with the same effect as a zero-length array.
param
constructors The list of public constructors of the MBean. This may be null with the same effect as a zero-length array.
param
operations The list of operations of the MBean. This may be null with the same effect as a zero-length array.
param
notifications The list of notifications emitted. This may be null with the same effect as a zero-length array.
param
descriptor The descriptor for the MBean. This may be null which is equivalent to an empty descriptor.
since
1.6


        this.className = className;

	this.description = description;

	if (attributes == null)
	    attributes = MBeanAttributeInfo.NO_ATTRIBUTES;
	this.attributes = attributes;

	if (operations == null)
	    operations = MBeanOperationInfo.NO_OPERATIONS;
	this.operations = operations;

	if (constructors == null)
	    constructors = MBeanConstructorInfo.NO_CONSTRUCTORS;
	this.constructors = constructors;

	if (notifications == null)
	    notifications = MBeanNotificationInfo.NO_NOTIFICATIONS;
	this.notifications = notifications;
        
        if (descriptor == null)
            descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
        this.descriptor = descriptor;

	this.arrayGettersSafe =
                arrayGettersSafe(this.getClass(), MBeanInfo.class);
    
Methods Summary
static booleanarrayGettersSafe(java.lang.Class subclass, java.lang.Class immutableClass)
Return true if subclass is known to preserve the immutability of immutableClass. The class immutableClass is a reference class that is known to be immutable. The subclass subclass is considered immutable if it does not override any public method of immutableClass whose name begins with "get". This is obviously not an infallible test for immutability, but it works for the public interfaces of the MBean*Info classes.


                                                                            
          
	if (subclass == immutableClass)
	    return true;
	synchronized (arrayGettersSafeMap) {
	    Boolean safe = arrayGettersSafeMap.get(subclass);
	    if (safe == null) {
		try {
		    ArrayGettersSafeAction action =
			new ArrayGettersSafeAction(subclass, immutableClass);
		    safe = AccessController.doPrivileged(action);
		} catch (Exception e) { // e.g. SecurityException
		    /* We don't know, so we assume it isn't.  */
		    safe = false;
		}
		arrayGettersSafeMap.put(subclass, safe);
	    }
	    return safe;
	}
    
private static intarrayHashCode(java.lang.Object[] array)

	int hash = 0;
	for (int i = 0; i < array.length; i++)
	    hash ^= array[i].hashCode();
	return hash;
    
public java.lang.Objectclone()

Returns a shallow clone of this instance. The clone is obtained by simply calling super.clone(), thus calling the default native shallow cloning mechanism implemented by Object.clone(). No deeper cloning of any internal field is made.

Since this class is immutable, the clone method is chiefly of interest to subclasses.

	 try {
	     return super.clone() ;
	 } catch (CloneNotSupportedException e) {
	     // should not happen as this class is cloneable
	     return null;
	 }
     
public booleanequals(java.lang.Object o)

Compare this MBeanInfo to another. Two MBeanInfo objects are equal if and only if they return equal values for {@link #getClassName()}, for {@link #getDescription()}, and for {@link #getDescriptor()}, and the arrays returned by the two objects for {@link #getAttributes()}, {@link #getOperations()}, {@link #getConstructors()}, and {@link #getNotifications()} are pairwise equal. Here "equal" means {@link Object#equals(Object)}, not identity.

If two MBeanInfo objects return the same values in one of their arrays but in a different order then they are not equal.

param
o the object to compare to.
return
true if and only if o is an MBeanInfo that is equal to this one according to the rules above.

	if (o == this)
	    return true;
	if (!(o instanceof MBeanInfo))
	    return false;
	MBeanInfo p = (MBeanInfo) o;
        if (!isEqual(getClassName(),  p.getClassName()) ||
                !isEqual(getDescription(), p.getDescription()) ||
                !getDescriptor().equals(p.getDescriptor())) {
            return false;
        }

	return
	    (Arrays.equals(p.fastGetAttributes(), fastGetAttributes()) &&
	     Arrays.equals(p.fastGetOperations(), fastGetOperations()) &&
	     Arrays.equals(p.fastGetConstructors(), fastGetConstructors()) &&
	     Arrays.equals(p.fastGetNotifications(), fastGetNotifications()));
    
private javax.management.MBeanAttributeInfo[]fastGetAttributes()

	if (arrayGettersSafe)
	    return nonNullAttributes();
	else
	    return getAttributes();
    
private javax.management.MBeanConstructorInfo[]fastGetConstructors()

	if (arrayGettersSafe)
	    return nonNullConstructors();
	else
	    return getConstructors();
    
private javax.management.MBeanNotificationInfo[]fastGetNotifications()

	if (arrayGettersSafe)
	    return nonNullNotifications();
	else
	    return getNotifications();
    
private javax.management.MBeanOperationInfo[]fastGetOperations()

	if (arrayGettersSafe)
	    return nonNullOperations();
	else
	    return getOperations();
    
public javax.management.MBeanAttributeInfo[]getAttributes()
Returns the list of attributes exposed for management. Each attribute is described by an MBeanAttributeInfo object. The returned array is a shallow copy of the internal array, which means that it is a copy of the internal array of references to the MBeanAttributeInfo objects but that each referenced MBeanAttributeInfo object is not copied.

return
An array of MBeanAttributeInfo objects.

	MBeanAttributeInfo[] as = nonNullAttributes();
	if (as.length == 0)
	    return as;
	else
	    return (MBeanAttributeInfo[]) as.clone();
    
public java.lang.StringgetClassName()
Returns the name of the Java class of the MBean described by this MBeanInfo.

return
the class name.

	return className;
    
public javax.management.MBeanConstructorInfo[]getConstructors()

Returns the list of the public constructors of the MBean. Each constructor is described by an MBeanConstructorInfo object.

The returned array is a shallow copy of the internal array, which means that it is a copy of the internal array of references to the MBeanConstructorInfo objects but that each referenced MBeanConstructorInfo object is not copied.

The returned list is not necessarily exhaustive. That is, the MBean may have a public constructor that is not in the list. In this case, the MBean server can construct another instance of this MBean's class using that constructor, even though it is not listed here.

return
An array of MBeanConstructorInfo objects.

	MBeanConstructorInfo[] cs = nonNullConstructors();
	if (cs.length == 0)
	    return cs;
	else
	    return (MBeanConstructorInfo[]) cs.clone();
    
public java.lang.StringgetDescription()
Returns a human readable description of the MBean.

return
the description.

	return description;
    
public javax.management.DescriptorgetDescriptor()
Get the descriptor of this MBeanInfo. Changing the returned value will have no affect on the original descriptor.

return
a descriptor that is either immutable or a copy of the original.
since
1.6

        return (Descriptor) nonNullDescriptor(descriptor).clone();
    
public javax.management.MBeanNotificationInfo[]getNotifications()
Returns the list of the notifications emitted by the MBean. Each notification is described by an MBeanNotificationInfo object. The returned array is a shallow copy of the internal array, which means that it is a copy of the internal array of references to the MBeanNotificationInfo objects but that each referenced MBeanNotificationInfo object is not copied.

return
An array of MBeanNotificationInfo objects.

	MBeanNotificationInfo[] ns = nonNullNotifications();
	if (ns.length == 0)
	    return ns;
	else
	    return (MBeanNotificationInfo[]) ns.clone();
    
public javax.management.MBeanOperationInfo[]getOperations()
Returns the list of operations of the MBean. Each operation is described by an MBeanOperationInfo object. The returned array is a shallow copy of the internal array, which means that it is a copy of the internal array of references to the MBeanOperationInfo objects but that each referenced MBeanOperationInfo object is not copied.

return
An array of MBeanOperationInfo objects.

	MBeanOperationInfo[] os = nonNullOperations();
	if (os.length == 0)
	    return os;
	else
	    return (MBeanOperationInfo[]) os.clone();
    
public inthashCode()

	/* Since computing the hashCode is quite expensive, we cache it.
	   If by some terrible misfortune the computed value is 0, the
	   caching won't work and we will recompute it every time.

	   We don't bother synchronizing, because, at worst, n different
	   threads will compute the same hashCode at the same time.  */
	if (hashCode != 0)
	    return hashCode;

	hashCode =
	    getClassName().hashCode() ^
            getDescriptor().hashCode() ^
	    arrayHashCode(fastGetAttributes()) ^
	    arrayHashCode(fastGetOperations()) ^
	    arrayHashCode(fastGetConstructors()) ^
	    arrayHashCode(fastGetNotifications());

	return hashCode;
    
private static booleanisEqual(java.lang.String s1, java.lang.String s2)

	boolean ret;

	if (s1 == null) {
	    ret = (s2 == null);
	} else {
	    ret = s1.equals(s2);
	}

	return ret;
    
private javax.management.MBeanAttributeInfo[]nonNullAttributes()
Return the value of the attributes field, or an empty array if the field is null. This can't happen with a normally-constructed instance of this class, but can if the instance was deserialized from another implementation that allows the field to be null. It would be simpler if we enforced the class invariant that these fields cannot be null by writing a readObject() method, but that would require us to define the various array fields as non-final, which is annoying because conceptually they are indeed final.

	return (attributes == null) ?
	    MBeanAttributeInfo.NO_ATTRIBUTES : attributes;
    
private javax.management.MBeanConstructorInfo[]nonNullConstructors()

	return (constructors == null) ?
	    MBeanConstructorInfo.NO_CONSTRUCTORS : constructors;
    
private javax.management.MBeanNotificationInfo[]nonNullNotifications()

	return (notifications == null) ?
	    MBeanNotificationInfo.NO_NOTIFICATIONS : notifications;
    
private javax.management.MBeanOperationInfo[]nonNullOperations()

	return (operations == null) ?
	    MBeanOperationInfo.NO_OPERATIONS : operations;
    
private voidreadObject(java.io.ObjectInputStream in)
Deserializes an {@link MBeanInfo} from an {@link ObjectInputStream}.

serialData
For compatibility reasons, an object of this class is deserialized as follows.
    The method {@link ObjectInputStream#defaultReadObject defaultReadObject()} is called first to deserialize the object except the field {@code descriptor}, which is not serialized in the default way. Then the method {@link ObjectInputStream#read read()} is called to read a byte, the field {@code descriptor} is deserialized according to the value of the byte value:
    • 1. The method {@link ObjectInputStream#readObject readObject()} is called twice to obtain the field names (a {@code String[]}) and the field values (a {@code Object[]}) of the {@code descriptor}. The two obtained values then are used to construct an {@link ImmutableDescriptor} instance for the field {@code descriptor};
    • 0. The value for the field {@code descriptor} is obtained directly by calling the method {@link ObjectInputStream#readObject readObject()}. If the obtained value is null, the field {@code descriptor} is set to {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR};
    • -1. This means that there is no byte to read and that the object is from an earlier version of the JMX API. The field {@code descriptor} is set to {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR}.
    • Any other value. A {@link StreamCorruptedException} is thrown.
since
1.6

	
	in.defaultReadObject();

	switch (in.read()) {
	case 1:
	    final String[] names = (String[])in.readObject();

	    if (names.length == 0) {
		descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
	    } else {
		final Object[] values = (Object[])in.readObject();
		descriptor = new ImmutableDescriptor(names, values);
	    }

	    break;
	case 0:
	    descriptor = (Descriptor)in.readObject();

	    if (descriptor == null) {
		descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
	    }

	    break;
	case -1: // from an earlier version of the JMX API
	    descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;

	    break;
	default:
	    throw new StreamCorruptedException("Got unexpected byte.");
	}
    
public java.lang.StringtoString()

        return
            getClass().getName() + "[" +
            "description=" + getDescription() + ", " +
            "attributes=" + Arrays.asList(fastGetAttributes()) + ", " +
            "constructors=" + Arrays.asList(fastGetConstructors()) + ", " +
            "operations=" + Arrays.asList(fastGetOperations()) + ", " +
            "notifications=" + Arrays.asList(fastGetNotifications()) + ", " +
            "descriptor=" + getDescriptor() +
            "]";
    
private voidwriteObject(java.io.ObjectOutputStream out)
Serializes an {@link MBeanInfo} to an {@link ObjectOutputStream}.

serialData
For compatibility reasons, an object of this class is serialized as follows.
    The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()} is called first to serialize the object except the field {@code descriptor} which is declared as transient. The field {@code descriptor} is serialized as follows:
    • If {@code descriptor} is an instance of the class {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write write(int val)} is called to write a byte with the value {@code 1}, then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called twice to serialize the field names and the field values of the {@code descriptor}, respectively as a {@code String[]} and an {@code Object[]};
    • Otherwise, the method {@link ObjectOutputStream#write write(int val)} is called to write a byte with the value {@code 0}, then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called to serialize the field {@code descriptor} directly.
since
1.6

        out.defaultWriteObject();

	if (descriptor.getClass() == ImmutableDescriptor.class) {
	    out.write(1);

	    final String[] names = descriptor.getFieldNames();

	    out.writeObject(names);
	    out.writeObject(descriptor.getFieldValues(names));
	} else {
	    out.write(0);

	    out.writeObject(descriptor);
	}