Java Reference
In-Depth Information
package jmxbook.ch11;
public interface PhoneCardMBean
{
public void disable();
}
Listing 11.1 shows the implementation of the PhoneCardMBean interface by the
PhoneCard class.
Listing 11.1
PhoneCard.java
package jmxbook.ch11;
public class PhoneCard implements PhoneCardMBean
{
private int cardNum=0;
public PhoneCard( int cardNum )
{
this.cardNum = cardNum;
}
public void disable()
{
System.out.println( "PhoneCardMBean::PhoneCard #" +
cardNum+" has been disabled" );
}
}
This MBean exposes one method and a constructor. The constructor takes an
int parameter that identifies the phone card slot this MBean represents. In the
constructor, you store a reference to this card's slot number so that you can use it
when the disable() method is called. The disable() method would typically exe-
cute some code that would disable the phone card. You do not have an actual
phone card, so you will just display a message indicating the card number that is
being disabled.
Writing the FaxCard MBean
Next, let's write the interface and implementation for the FaxCard MBean. The
interface for this class looks similar to the PhoneCardMBean interface:
package jmxbook.ch11;
public interface FaxCardMBean
{
public void disable();
}
Listing 11.2 shows the MBean class. It is also a simple class, like PhoneCard .
Search WWH ::




Custom Search