1 package mbeanTest; 2 3 import javax.management.Notification; 4 import javax.management.NotificationBroadcasterSupport; 5 6 public class HelloWorld extends NotificationBroadcasterSupport implements 7 HelloWorldMBean 8 { 9 10 public String hello; 11 12 private long seq = 0l; 13 14 public HelloWorld() 15 { 16 this.hello = "Hello World! I am a Standard MBean"; 17 } 18 19 public HelloWorld(String hello) 20 { 21 this.hello = hello; 22 } 23 24 public String getHello() 25 { 26 return hello+": 调用方法getHello()"; 27 } 28 29 @Override 30 public Object getInstance() 31 { 32 return new Object(); 33 } 34 35 /* 36 * 当执行message的时候,发送一个消息(事件) 37 * 38 * @see test.jmx.HelloWorldMBean#message(java.lang.String) 39 */ 40 @Override 41 public String message(String ms) 42 { 43 Notification notice = new Notification("type1", this, seq++, 44 " the message metheod is invoked,the argument ms: " + ms); 45 sendNotification(notice); 46 return " the message : "; 47 } 48 49 @Override 50 public void setHello(String hello) 51 { 52 this.hello = hello; 53 } 54 }