Search |
||
MBeanInfo.equals: who's asking?Posted by emcmanus on November 13, 2006 at 9:40 AM PST
Defining an equals(Object) method in a public class is not always straightforward. One reason it might not be is that the answer to the question "are these objects equal?" might be "who's asking?". In a very interesting comment on my previous blog entry, rullrich suggests that the real problem is with MBeanInfo.equals. I'm inclined to disagree, but the issue is a subtle one. One frequent difficulty with implementing an
But the question at hand is whether two I can see at least two use cases for callers of
The snapshot shows the JConsole GUI for the MemoryMXBean. If
the order of the attributes changed, and assuming we think it is
useful to preserve the order from the MBeanInfo, then we would
want to change the order in the GUI too. You could imagine
JConsole calling
In this second use case, MBeanInfo.equals should return false if the order of the attributes has changed, or if any other detail has changed, such as the description of an attribute. But in the first use case, MBeanInfo.equals should ignore these details because they don't change the set of valid client operations. Obviously we can't make MBeanInfo.equals conform to both use cases so we must pick one. We chose the second use case because it is precise. Two MBeanInfo objects are different if they differ in any detail, including the order of attributes. The first use case is much less precise:
A secondary reason for preferring the definition where order is
significant is that it makes for a faster A summary of the choice we made, then, is that it allows me to answer the question: Is this MBeanInfo object the same as one I got earlier for the same MBean? If the answer is yes, then the MBean interface definitely hasn't changed. If the answer is no, then the MBean interface might or might not have changed, but I must assume it has. The choice does not in general allow you to use MBeanInfo.equals to answer the incompatible question: Is this MBeanInfo object the same as the one I expected? So the moral is that when you define an But what about the order of methods in a Standard MBean interface?rullrich also makes some other interesting points.
First, in principle calling Second, I am also inclined to think we should preserve the order returned by Class.getMethods(). The implication for the regression test is that it should use reflection to determine what it thinks the order of attributes and operations in the MBeanInfo should be, and compare this with the order that is actually in the MBeanInfo returned by the JMX API. That test is then imposing a stronger restriction on the JDK's implementation of the API than is required by the spec, but that's all right. The bug in the test that I actually coded is that it hardwired this expected order instead of getting it from Class.getMethods(). »
Related Topics >>
Open JDK Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|