1 package org.sapia.soto.jmx.config; 2 3 import org.sapia.soto.jmx.MBeanDescriptor; 4 5 import javax.management.MBeanAttributeInfo ; 6 import javax.management.MBeanOperationInfo ; 7 import javax.management.MBeanParameterInfo ; 8 9 10 17 public class SomeBean { 18 private String _name; 19 20 public void setName(String name) { 21 _name = name; 22 } 23 24 public String getName() { 25 return _name; 26 } 27 28 public void performOperationOne(String param1, int param2) { 29 } 30 31 public void performOperationTwo(String param1, int param2) { 32 } 33 34 public static void main(String [] args) { 35 try { 36 SomeBean bean = new SomeBean(); 37 MBeanDescriptor mbean = MBeanDescriptor.newInstanceFor(bean); 38 Attributes attrs = new Attributes(); 39 Attribute a = attrs.createInclude(); 40 a.setDescription("The Name"); 41 a.setName("name"); 42 a.setWritable(false); 43 attrs.init(mbean); 44 45 Operations ops = new Operations(); 46 Operation include = ops.createInclude(); 47 include.setName("performOperationOne"); 48 include.setDescription("Some operation"); 49 50 Operation exclude = ops.createExclude(); 51 exclude.setName("performOperationTwo"); 52 exclude.setDescription("Some operation"); 53 ops.init(mbean); 54 55 mbean.init(); 56 57 MBeanAttributeInfo [] info = mbean.getMBeanInfo().getAttributes(); 58 System.out.println("Operations:"); 59 60 for (int i = 0; i < info.length; i++) { 61 System.out.println("=============================="); 62 System.out.println(info[i].getName()); 63 System.out.println(info[i].getDescription()); 64 System.out.println("readable: " + info[i].isReadable() + 65 ", writable: " + info[i].isWritable()); 66 } 67 68 MBeanOperationInfo [] opInfo = mbean.getMBeanInfo().getOperations(); 69 70 for (int i = 0; i < opInfo.length; i++) { 71 System.out.println("=============================="); 72 System.out.println(opInfo[i].getName()); 73 System.out.println(opInfo[i].getDescription()); 74 75 MBeanParameterInfo [] params = opInfo[i].getSignature(); 76 77 for (int j = 0; j < params.length; j++) { 78 System.out.println(params[j].getName() + ", " + 79 params[j].getDescription()); 80 } 81 } 82 } catch (Throwable t) { 83 t.printStackTrace(); 84 } 85 } 86 } 87 | Popular Tags |