Java Reference
In-Depth Information
e.printStackTrace();
con = null;
return null;
}
}
public boolean getAutoCommit( )
{
return commit;
}
public void setAutoCommit( boolean commit )
{
this.commit = commit;
}
}
B
The getConnection() method is unique because the implementation class does
not contain a Connection attribute. In fact, it really returns a connection from the
DataSource object. The getConnection() method is more like an operation than
an exposed attribute. This situation illustrates again the importance of carefully
naming methods for an MBean interface—for example, perhaps you should
name this method acquireConnection() . By naming methods thoughtfully, you
can avoid misunderstandings.
Testing the PropertyManager MBean
Before moving to the next section, let's run one of these MBeans in the JMXBook-
Agent agent from chapter 3. (As we've mentioned, you will use this agent class at
various times in the topic.)
You can register an MBean into your agent two ways: you can use either the
HTML adapter or the Remote Method Invocation ( RMI ) connector. You have
already seen how to use the HTML adapter, so let's take this chance to use the
RMI connector to register an MBean in the agent. To do so, you need to write a
simple setup class that contacts an instance of the JMXBookAgent and registers an
MBean. Listing 4.3 shows a setup class to create the PropertyManager MBean.
Listing 4.3
PropertyManagerSetup.java
package jmxbook.ch4;
import javax.management.*;
import com.sun.jdmk.comm.*;
import jmxbook.ch3.*;
public class PropertyManagerSetup
Search WWH ::




Custom Search