Java Dynamic Management Kit 5.0 Tutorial

Generating Proxies for Standard MBeans

The proxygen tool provided with the Java DMK 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 compiler is fully documented in the Java Dynamic Management Kit 5.0 Tools Reference and in the Javadoc API for the ProxyGen class. Its command—line options enable 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.

Example 11–1 shows part of the code generated for the SimpleStandard MBean used in the SimpleClients examples.

Example 11–1 Code Generated for the SimpleStandardProxy Class

  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,
    MBeanException {

                          new Attribute("State",value));

  public void reset()
    throws InstanceNotFoundException, ReflectionException,
    MBeanException {

    Object result;
    result= server.invoke(objectInstance.getObjectName(), "reset",
                          null, null);

You can modify the generated code if you want 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.