Now that we have implemented both types of MBeans we can compare how they are managed. We purposely created a dynamic MBean and a standard MBean with the same management interface so that we can do exactly the same operations on them. On the Solaris platform, we can compare the relevant code of the two agent applications with the diff utility (your output may vary):
$ cd examplesDir $ diff ./StandardMBean/StandardAgent.java ./DynamicMBean/DynamicAgent.java [...] 41c40 < public class StandardAgent { --- > public class DynamicAgent { 49c48 < public StandardAgent() { --- > public DynamicAgent() { 77c76 < StandardAgent agent = new StandardAgent(); --- > DynamicAgent agent = new DynamicAgent(); 88c87 < echo("\n>>> END of the SimpleStandard example:\n"); --- > echo("\n>>> END of the SimpleDynamic example:\n"); 113c112 < String mbeanName = "SimpleStandard"; --- > String mbeanName = "SimpleDynamic"; |
If the two agent classes had the same name, we see that the only programmatic difference would be the following:
113c112 < String mbeanName = "SimpleStandard"; --- > String mbeanName = "SimpleDynamic"; |
We can see that there is only one difference between the two example agents handling different types of MBeans: the name of the MBean class that is instantiated! In other words, standard and dynamic MBeans are indistinguishable from the agent's point of view. This is the power of the JMX architecture: managers interact with the attributes and operations of a manageable resource, and the specification of the agent hides any implementation differences between MBeans.
Since we know that the two MBeans are being managed identically, we can also compare their runtime behavior. In doing so, we can draw two conclusions:
The dynamic MBean was programmed to have the same behavior as the standard MBean; the example output shows that this is indeed the case: despite the different implementations, the functionality of the resource is strictly the same
The only functional difference between the two is that the agent can obtain the self-description strings encoded in the dynamic MBean: attributes and operations are associated with the explanation that the programmer provides for them
There is no mechanism which allows a standard MBean to provide a self-description. The MBean server provides a default description string for each feature in a standard MBean, and these descriptions are identical for all standard MBeans.