public class MBeanServerRunner {
public static void main(String[] args) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("twitter4j.mbean:type=APIStatistics");
ObjectName name2 = new ObjectName("twitter4j.mbean:type=APIStatisticsOpenMBean");
APIStatistics statsMBean = new APIStatistics(100);
mbs.registerMBean(statsMBean, name);
APIStatisticsOpenMBean openMBean = new APIStatisticsOpenMBean(statsMBean);
mbs.registerMBean(openMBean, name2);
for (int i = 0; i < 10; i++) {
statsMBean.methodCalled("foo", 5, true);
statsMBean.methodCalled("bar", 2, true);
statsMBean.methodCalled("baz", 10, true);
statsMBean.methodCalled("foo", 2, false);
}
Thread.sleep(1000 * 60 * 60);
}