Java Reference
In-Depth Information
4.4.1
Making applications easily configurable
In chapter 1, you read that one of the benefits of using JMX in your applications
is that it can make them more configurable. With JMX , you can expose API s from
your application for management. By exposing certain operations, you can use
MBeans to expose the behavior of your application at runtime. In other words,
you can use MBeans to expose an API that configures your application. The con-
figuration ability will give your applications more flexibility and can possibly save
you downtime. The next section describes using MBeans to encapsulate your
application properties.
Managing application properties
Many applications are configured by loading a set of properties from the file
system. Unless the application chooses to monitor and reload the properties
file, it can only be refreshed by being restarted. For many applications, it's not
feasible to stop and start just for a minor reconfiguration. Applications that
have the ability to be reconfigured during runtime are more flexible, powerful,
and long lasting.
The PropertyManager Standard MBean example manages a set of properties.
An application can acquire its configuration by using this MBean, and users can
update the configuration by connecting to the embedded JMX agent. The first
step in creating this MBean is to define its MBean interface:
package jmxbook.ch4;
import java.util.*;
public interface PropertyManagerMBean
{
public String getProperty( String key );
public void setProperty( String key, String value );
public Enumeration keys();
public void setSource( String path );
}
Now that you know how an MBean interface describes a Standard MBean's man-
agement interface, look at the PropertyManagerMBean interface to determine the
management interface it describes. Judging by the fact that there is a getProp-
erty() method and a setProperty() method, you might think the interface
exposes a readable and writable attribute. However, the get method in this case is
an operation, not an exposed readable attribute; a getter method cannot accept
arguments. Likewise, the setProperty() method is not really a setter method—set-
ter methods can take only a single argument. Therefore, although acceptable, this
Search WWH ::




Custom Search