March 3, 2021
Hot Topics:

Standard MBeans

  • By O'Reilly & Associates
  • Send Email »
  • More Articles »

Standard MBean Inheritance Patterns

As you are probably aware, inheritance in Java is achieved through the use of the extends keyword. When it comes to exposing a management interface, the MBean server's introspection enforces certain rules. There are some fundamental differences between Java inheritance and management interface inheritance. This section will spell out those differences.

With respect to inheritance, certain patterns are enforced by the MBean server at introspection time. If you are to successfully expose the intended management interface on your MBeans, it is important that you understand these patterns. While an MBean may inherit the public (and protected) attributes and operations of its parent class, it will not necessarily inherit its management interface.

There are five basic patterns of MBean inheritance. We will discuss each of them in this section. We will also introduce and explain the application MBean interfaces in this section, starting with the top of the inheritance hierarchy, BasicMBean. We will use UML diagrams to reduce ambiguity.

BasicMBean is the management interface that all MBeans in the inheritance graph will expose and in this section we will see exactly how to go about doing that. Along the way, I'll point out some areas to watch out for and offer some tips for avoiding potential mistakes. Example 2-2 shows the source listing for BasicMBean.

Example 2-2. The BasicMBean interface

package sample.standard;

public interface BasicMBean {
  public boolean isTraceOn();
  public boolean isDebugOn();
  public int getNumberOfResets();
  public void enableTracing();
  public void disableTracing();
  public void enableDebugging();
  public void disableDebugging();
  public void reset();

Pattern #1: Basic inheritance

In the basic inheritance pattern, a class implements an MBean interface. This pattern is shown in UML notation in Figure 2-1.

Figure 2-1. UML notation for pattern #1

In source code, this pattern is implemented using the implements keyword:

public class Basic implements BasicMBean {
//implementation of BasicMBean and other stuff. . .

Use of the implements keyword was explained in the previous section.

Pattern #2: Simple inheritance

With simple inheritance, one class extends another class that implements an MBean interface. This relationship is shown in Figure 2-2.

Figure 2-2. UML notation for pattern #2

In source code, this pattern is implemented using the extends keyword:

public class Worker extends Basic {
//implementation of Worker here. . .

In this pattern, the management interface exposed by Worker is BasicMBean. To a management application, Worker will appear to be a BasicMBean, complete with all of its attributes and operations. In other words, the management interface of Worker is the same as that of .

Pattern #3: Simple inheritance with child class implementing an MBean interface

Of course, Worker could implement its own MBean interface and still extend Basic. The WorkerMBean interface is shown in Example 2-3.

Example 2-3. WorkerMBean management interface definition

package sample.standard;

public interface WorkerMBean {
  public String getWorkerName();
  public void setWorkerName(String name);
  public int getWorkFactor();
  public long getNumberOfUnitsProcessed();
  public float getAverageUnitProcessingTime();
  public boolean isSuspended();
  public void stop();
  public void suspend();
  public void resume();

According to this pattern, Worker would continue to extend Basic but would now explicitly expose its own MBean interface:

public class Worker extends Basic implements WorkerMBean {
//implementation of WorkerMBean. . .

This pattern is shown in UML notation in Figure 2-3.

Figure 2-3. UML notation for pattern #3

Page 3 of 7

This article was originally published on May 23, 2003

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date