Java Reference
In-Depth Information
public RoutingTable(){}
public void removePhoneRoute(Integer cardNum)
{
System.out.println( "RoutingTableMBean::PhoneCard" +
cardNum.intValue() + " removed from "
+ " routing table");
}
public void removeFaxRoute()
{
System.out.println( "RoutingTableMBean::FaxCard removed "
+ " from routing table");
}
}
This MBean manages a routing table that has both fax and phone board refer-
ences, so it includes two user methods. The first method removes a phone card
from the routing table and takes an integer as a parameter; this integer describes
the slot of a phone card. The second method removes the fax card from the rout-
ing table; it requires no parameter, because there can be only one fax card per sys-
tem. For this example, both methods will print a message to the screen, because
you do not really have a routing table implemented for the phone and fax cards.
Registering the MBeans in the agent
Now that you have created the MBeans, you need to write code that will add them
to the agent. The remaining code in this chapter comes from a main class built to
create and register MBeans in the agent. The methods being described will form
a class called RelationMain . This class will be similar to the setup classes you have
written in previous chapters. However, in addition to registering your MBeans,
this class will eventually contain the code that creates your relation. The method
in listing 11.4 is extracted from the RelationMain class. You can find the complete
source listing for this class on the topic's web site at http://www.manning.com/.
Listing 11.4
The createMBeans() method from RelationMain.java
public void createMBeans()
{
try
{
//register the first PhoneCard
Object[] params = new Object[1];
params[0] = new Integer(1);
String[] sig = new String[1];
sig[0] = "int";
 
Search WWH ::




Custom Search