Java Reference
In-Depth Information
support class is that you do not have to write code for the broadcaster interface.
If your MBean does not need to extend a class, then have it extend the Notifica-
tionBroadcasterSupport class and reuse that implementation. The HelloWorld
class does not need any special super class, so you are free to extend the broad-
caster support class, NotificationBroadcasterSupport , as shown in listing 2.3.
Listing 2.3
HelloWorld.java
package jmxbook.ch2;
import javax.management.*;
public class HelloWorld extends NotificationBroadcasterSupport
implements HelloWorldMBean
{
B
Extend NotificationBroadcasterSupport class
C
Define two public
constructors
public HelloWorld()
{
this.greeting = "Hello World! I am a Standard MBean";
}
C
Define two public
constructors
public HelloWorld( String greeting )
{
this.greeting = greeting;
}
public void setGreeting( String greeting )
{
this.greeting = greeting;
Notification notification = new Notification(
"jmxbook.ch2.helloWorld.test", this, -1,
System.currentTimeMillis(), greeting );
D
Create
javax.management.Notification
object
sendNotification( notification );
}
Send notification
public String getGreeting()
{
return greeting;
}
public void printGreeting()
{
System.out.println( greeting );
}
private String greeting;
}//class
Search WWH ::




Custom Search