分类: Java
2005-10-09 14:16:06
jboss-4.0.1sp1serverdefaultdeploy
----jmxtest.sar
----com.example.mbeans.* //all classes file
----META-INF
----jboss-service.xml
HelloMBean.java
package com.example.mbeans;
public interface HelloMBean {
public void sayHello();
public int add(int x, int y);
public String getName();
public int getCacheSize();
public void setCacheSize(int size);
public void start() throws Exception;
public void stop() throws Exception;
}
Hello.java
package com.example.mbeans;
import javax.management.*;
public class Hello
extends NotificationBroadcasterSupport implements HelloMBean {
public void start() throws Exception{
System.out.println("-------------------------------------start()");
}
public void stop() throws Exception{
System.out.println("-------------------------------------stop()");
}
public void sayHello() {
System.out.println("hello, world");
}
public int add(int x, int y) {
return x + y;
}
public String getName() {
return this.name;
}
public int getCacheSize() {
return this.cacheSize;
}
public synchronized void setCacheSize(int size) {
// int oldSize = this.cacheSize;
this.cacheSize = size;
System.out.println("Cache size now " + this.cacheSize);
// Notification n =
// new AttributeChangeNotification(this,
// sequenceNumber++,
// System.currentTimeMillis(),
// "CacheSize changed",
// "CacheSize",
// "int",
// oldSize,
// this.cacheSize);
//
// sendNotification(n);
}
public MBeanNotificationInfo[] getNotificationInfo() {
String[] types = new String[] {
AttributeChangeNotification.ATTRIBUTE_CHANGE
};
String name = AttributeChangeNotification.class.getName();
String description = "An attribute of this MBean has changed";
MBeanNotificationInfo info =
new MBeanNotificationInfo(types, name, description);
return new MBeanNotificationInfo[] {info};
}
private final String name = "Reginald";
private int cacheSize = DEFAULT_CACHE_SIZE;
private static final int DEFAULT_CACHE_SIZE = 200;
// private long sequenceNumber = 1;
}
jboss-service.xml