OpenMBeanInfoSupportpublic class OpenMBeanInfoSupport extends MBeanInfo implements Serializable, OpenMBeanInfoThe OpenMBeanInfoSupport class describes the management information of an open MBean:
it is a subclass of {@link javax.management.MBeanInfo}, and it implements the {@link OpenMBeanInfo} interface.
Note that an open MBean is recognized as such if its getMBeanInfo() method returns an instance of a class
which implements the OpenMBeanInfo interface, typically OpenMBeanInfoSupport. |
Fields Summary |
---|
static final long | serialVersionUID | private transient Integer | myHashCode | private transient String | myToString |
Constructors Summary |
---|
public OpenMBeanInfoSupport(String className, String description, OpenMBeanAttributeInfo[] openAttributes, OpenMBeanConstructorInfo[] openConstructors, OpenMBeanOperationInfo[] openOperations, MBeanNotificationInfo[] notifications)Constructs an OpenMBeanInfoSupport instance,
which describes a class of open MBeans with the specified
className, description, openAttributes,
openConstructors , openOperations and notifications.
The openAttributes, openConstructors,
openOperations and notifications
array parameters are internally copied, so that subsequent changes
to the arrays referenced by these parameters have no effect on this instance.
// need only be calculated once.
super(className,
description,
( openAttributes == null ? null : attributesArrayCopyCast(openAttributes) ), // may throw an ArrayStoreException
( openConstructors == null ? null : constructorsArrayCopyCast(openConstructors) ), // may throw an ArrayStoreException
( openOperations == null ? null : operationsArrayCopyCast(openOperations) ), // may throw an ArrayStoreException
( notifications == null ? null : notificationsArrayCopy(notifications) ));
|
Methods Summary |
---|
private static javax.management.MBeanAttributeInfo[] | attributesArrayCopyCast(javax.management.openmbean.OpenMBeanAttributeInfo[] src)
MBeanAttributeInfo[] dst = new MBeanAttributeInfo[src.length];
System.arraycopy(src, 0, dst, 0, src.length); // may throw an ArrayStoreException
return dst;
| private static javax.management.MBeanConstructorInfo[] | constructorsArrayCopyCast(javax.management.openmbean.OpenMBeanConstructorInfo[] src)
MBeanConstructorInfo[] dst = new MBeanConstructorInfo[src.length];
System.arraycopy(src, 0, dst, 0, src.length); // may throw an ArrayStoreException
return dst;
| public boolean | equals(java.lang.Object obj)Compares the specified obj parameter with this OpenMBeanInfoSupport instance for equality.
Returns true if and only if all of the following statements are true:
- obj is non null,
- obj also implements the
OpenMBeanInfo interface,
- their class names are equal
- their infos on attributes, constructors, operations and notifications are equal
This ensures that this equals method works properly for obj parameters which are
different implementations of the OpenMBeanInfo interface.
// if obj is null, return false
//
if (obj == null) {
return false;
}
// if obj is not a OpenMBeanInfo, return false
//
OpenMBeanInfo other;
try {
other = (OpenMBeanInfo) obj;
} catch (ClassCastException e) {
return false;
}
// Now, really test for equality between this OpenMBeanInfo implementation and the other:
//
// their MBean className should be equal
if ( ! this.getClassName().equals(other.getClassName()) ) {
return false;
}
// their infos on attributes should be equal (order not significant => equality between sets, not arrays or lists)
if ( ! new HashSet(Arrays.asList(this.getAttributes())).equals(new HashSet(Arrays.asList(other.getAttributes()))) ) {
return false;
}
// their infos on constructors should be equal (order not significant => equality between sets, not arrays or lists)
if ( ! new HashSet(Arrays.asList(this.getConstructors())).equals(new HashSet(Arrays.asList(other.getConstructors()))) ) {
return false;
}
// their infos on operations should be equal (order not significant => equality between sets, not arrays or lists)
if ( ! new HashSet(Arrays.asList(this.getOperations())).equals(new HashSet(Arrays.asList(other.getOperations()))) ) {
return false;
}
// their infos on notifications should be equal (order not significant => equality between sets, not arrays or lists)
if ( ! new HashSet(Arrays.asList(this.getNotifications())).equals(new HashSet(Arrays.asList(other.getNotifications()))) ) {
return false;
}
// All tests for equality were successfull
//
return true;
| public int | hashCode()Returns the hash code value for this OpenMBeanInfoSupport instance.
The hash code of an OpenMBeanInfoSupport instance is the sum of the hash codes
of all elements of information used in equals comparisons
(ie: its class name, and its infos on attributes, constructors, operations and notifications,
where the hashCode of each of these arrays is calculated by a call to
new java.util.HashSet(java.util.Arrays.asList(this.getSignature)).hashCode()).
This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode()
for any two OpenMBeanInfoSupport instances t1 and t2 ,
as required by the general contract of the method
{@link Object#hashCode() Object.hashCode()}.
However, note that another instance of a class implementing the OpenMBeanInfo interface
may be equal to this OpenMBeanInfoSupport instance as defined by {@link #equals(java.lang.Object)},
but may have a different hash code if it is calculated differently.
As OpenMBeanInfoSupport instances are immutable, the hash code for this instance is calculated once,
on the first call to hashCode , and then the same value is returned for subsequent calls.
// Calculate the hash code value if it has not yet been done (ie 1st call to hashCode())
//
if (myHashCode == null) {
int value = 0;
value += this.getClassName().hashCode();
value += new HashSet(Arrays.asList(this.getAttributes())).hashCode();
value += new HashSet(Arrays.asList(this.getConstructors())).hashCode();
value += new HashSet(Arrays.asList(this.getOperations())).hashCode();
value += new HashSet(Arrays.asList(this.getNotifications())).hashCode();
myHashCode = new Integer(value);
}
// return always the same hash code for this instance (immutable)
//
return myHashCode.intValue();
| private static javax.management.MBeanNotificationInfo[] | notificationsArrayCopy(javax.management.MBeanNotificationInfo[] src)
MBeanNotificationInfo[] dst = new MBeanNotificationInfo[src.length];
System.arraycopy(src, 0, dst, 0, src.length);
return dst;
| private static javax.management.MBeanOperationInfo[] | operationsArrayCopyCast(javax.management.openmbean.OpenMBeanOperationInfo[] src)
MBeanOperationInfo[] dst = new MBeanOperationInfo[src.length];
System.arraycopy(src, 0, dst, 0, src.length); // may throw an ArrayStoreException
return dst;
| public java.lang.String | toString()Returns a string representation of this OpenMBeanInfoSupport instance.
The string representation consists of the name of this class (ie javax.management.openmbean.OpenMBeanInfoSupport ),
the MBean class name,
and the string representation of infos on attributes, constructors, operations and notifications of the described MBean.
As OpenMBeanInfoSupport instances are immutable,
the string representation for this instance is calculated once,
on the first call to toString , and then the same value is returned for subsequent calls.
// Calculate the hash code value if it has not yet been done (ie 1st call to toString())
//
if (myToString == null) {
myToString = new StringBuffer()
.append(this.getClass().getName())
.append("(mbean_class_name=")
.append(this.getClassName())
.append(",attributes=")
.append(Arrays.asList(this.getAttributes()).toString())
.append(",constructors=")
.append(Arrays.asList(this.getConstructors()).toString())
.append(",operations=")
.append(Arrays.asList(this.getOperations()).toString())
.append(",notifications=")
.append(Arrays.asList(this.getNotifications()).toString())
.append(")")
.toString();
}
// return always the same string representation for this instance (immutable)
//
return myToString;
|
|