Java Reference
In-Depth Information
{
public PropertyManagerSetup()
{
try
{
RmiConnectorClient client = RMIClientFactory.getClient();
ObjectName propertyName = new
ObjectName( "JMXBookAgent:name=property");
client.createMBean( "jmxbook.ch4.PropertyManager",
propertyName );
}
catch( Exception e )
{
ExceptionUtil.printException( e );
}
}
public static void main( String args[] )
{
PropertyManagerSetup setup = new PropertyManagerSetup();
}
}
The setup class uses the
RMIClientFactory
class to acquire an
RMI
client with
which to contact your agent. Using the client, it invokes the
createMBean()
method of the
MBeanServer
. When you used the
HTML
adapter in chapter 2, you
caused the same thing to happen by using the browser.
Before you run the setup class, make sure you have an instance of the
JMX-
BookAgent
running—use the following command to do so:
javac jmxbook.ch4.JMXBookAgent
After the agent successfully starts, execute the
PropertyManagerSetup
class to cre-
ate your
PropertyManager
MBean. Open your web browser to the address of the
agent's
HTML
adapter, and you will see the new MBean registered in the agent.
The
PropertyManager
and
DBSource
MBeans are both good examples of using
MBeans to make an application more configurable. The next section deals with
making an application componentized.
4.4.2
Breaking applications into components
Chapter 1 explains that it is possible to use
JMX
to break applications into man-
ageable components.
Componentization
is a development method that defines
interfaces between components of an application, allowing their implementa-
tions to be changed or even replaced. With Standard MBeans, you can define