1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
   |  public interface DataTypeMBean {
      int getCount();
      List<String> getNames();
      CompositeData getMyDataType() throws Exception;
      TabularData getMyDataTypeList() throws Exception; }
 
  public class DataType implements DataTypeMBean {
      @Override     public int getCount() {         return 2014;     }
      @Override     public List<String> getNames() {         return Arrays.asList("happy", "new", "year");     }
      @Override     public CompositeData getMyDataType() throws Exception {         String[] itemNames = { "name", "age" };         OpenType<?>[] openTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };         CompositeType compositeType = new CompositeType("MyDataType", "my dataType test", itemNames, itemNames,                                                         openTypes);         Object[] items = { "lucy", 10 };         CompositeData dataType = new CompositeDataSupport(compositeType, itemNames, items);                                    return dataType;     }
      @Override     public TabularData getMyDataTypeList() throws Exception{         String[] itemNames = { "name", "age" };         OpenType<?>[] openTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };         CompositeType compositeType = new CompositeType("MyDataType", "my dataType test", itemNames, itemNames,                                                         openTypes);         TabularType tabularType = new TabularType("MyDataListType", "my dataType List test", compositeType, itemNames);         TabularData tabularData = new TabularDataSupport(tabularType);         CompositeData lucy = new CompositeDataSupport(compositeType, itemNames, new Object[]{"lucy", 10});         CompositeData lily = new CompositeDataSupport(compositeType, itemNames, new Object[]{"lily", 11});         tabularData.put(lucy);         tabularData.put(lily);
 
 
 
 
 
          return tabularData;     }
      public static void main(String[] args) throws Exception {         MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();         ObjectName name = new ObjectName("name.chengchao:type=DataType");         DataType mbean = new DataType();         mBeanServer.registerMBean(mbean, name);         System.out.println("started...");         Thread.sleep(Long.MAX_VALUE);     } }
 
 
  |