The proxygen tool provided with the Java Dynamic Management Kit takes the class files of an MBean and its MBean interface, and generates the Java source code files of its corresponding proxy object and proxy MBean interface. You then need to compile the two proxy files with the javac command and include the resulting class files in your application's classpath.
The proxygen command is fully documented in the Java Dynamic Management Kit 4.2 Tools Reference guide, and in the Javadoc API for the ProxyGen class. Its command line options allow you to generate read-only proxies where all setter methods are suppressed and to define a package name for your proxies. For the purpose of the examples, we generate the default proxies without any of these options: see the section on "Running the Standard Proxy Example".
The following code sample shows part of the code generated for the SimpleStandard MBean used in the SimpleClients examples.
public java.lang.String getState() throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException { return ((java.lang.String)server.getAttribute( objectInstance.getObjectName(), "State")); } public void setState(java.lang.String value) throws InstanceNotFoundException, ReflectionException, AttributeNotFoundException,InvalidAttributeValueException, MBeanException { server.setAttribute(objectInstance.getObjectName(), new Attribute("State",value)); } public void reset() throws InstanceNotFoundException, ReflectionException, MBeanException { Object result; result= server.invoke(objectInstance.getObjectName(), "reset", null, null); } |
You are free to modify the generated code if you wish to customize the behavior of your proxies. However, customization is not recommended if your MBean interfaces are still evolving, because all modifications will need to be redone every time the proxies are generated.