1 22 package test.performance.modelmbean; 23 24 import junit.framework.TestCase; 25 import test.performance.PerformanceSUITE; 26 import test.performance.modelmbean.support.Resource; 27 28 import javax.management.*; 29 import javax.management.modelmbean.*; 30 31 public class ThroughputTEST extends TestCase 32 { 33 34 public ThroughputTEST(String s) 35 { 36 super(s); 37 } 38 39 public void testThroughput() throws Exception 40 { 41 MyThread myThread = new MyThread(); 42 Thread t = new Thread (myThread); 43 44 String method = "invokeMixedArgs"; 45 String [] signature = new String [] { 46 Integer .class.getName(), 47 String .class.getName(), 48 Object [][][].class.getName(), 49 Attribute.class.getName() 50 }; 51 52 Object [] args = new Object [] { 53 new Integer (1234), 54 "Hello", 55 new Object [][][] { 56 { 57 { "1x1x1", "1x1x2", "1x1x3" }, 58 { "1x2x1", "1x2x2", "1x2x3" }, 59 { "1x3x1", "1x3x2", "1x3x3" } 60 }, 61 62 { 63 { "2x1x1", "2x1x2", "2x1x3" }, 64 { "2x2x1", "2x2x2", "2x2x3" }, 65 { "2x3x1", "2x3x2", "2x3x3" } 66 }, 67 68 { 69 { "3x1x1", "3x1x2", "3x1x3" }, 70 { "3x2x1", "3x2x2", "3x2x3" }, 71 { "3x3x1", "3x3x2", "3x3x3" } 72 } 73 }, 74 new Attribute("attribute", "value") 75 }; 76 77 MBeanServer server = MBeanServerFactory.createMBeanServer(); 78 ObjectName name = new ObjectName("test:test=test"); 79 80 Resource res = new Resource(); 81 RequiredModelMBean rmm = new RequiredModelMBean(); 82 rmm.setModelMBeanInfo(getManagementInterface()); 83 rmm.setManagedResource(res, "ObjectReference"); 84 85 server.registerMBean(rmm, name); 86 87 t.start(); 88 while(myThread.isKeepRunning()) 89 { 90 server.invoke(name, method, args, signature); 91 } 92 93 System.out.println("\nModel MBean Throughput: " + 94 res.getCount() / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND) + 95 " invocations per second."); 96 System.out.println("(Total: " + res.getCount() + ")\n"); 97 } 98 99 class MyThread implements Runnable 100 { 101 102 private boolean keepRunning = true; 103 104 public void run() 105 { 106 try 107 { 108 Thread.sleep(PerformanceSUITE.THROUGHPUT_TIME); 109 } 110 catch (InterruptedException e) 111 { 112 113 } 114 115 keepRunning = false; 116 } 117 118 public boolean isKeepRunning() 119 { 120 return keepRunning; 121 } 122 } 123 124 private ModelMBeanInfo getManagementInterface() 125 { 126 final boolean READABLE = true; 127 final boolean WRITABLE = true; 128 final boolean BOOLEAN = true; 129 130 DescriptorSupport descMixedArgs = new DescriptorSupport(); 132 descMixedArgs.setField("name", "invokeMixedArgs"); 133 descMixedArgs.setField("descriptorType", "operation"); 134 descMixedArgs.setField("role", "operation"); 135 MBeanParameterInfo[] mixedArgsParms = 136 new MBeanParameterInfo[] 137 { 138 new MBeanParameterInfo 139 ( 140 "Arg1", 141 Integer .class.getName(), 142 "Desc" 143 ), 144 new MBeanParameterInfo 145 ( 146 "Arg2", 147 String .class.getName(), 148 "Desc" 149 ), 150 new MBeanParameterInfo 151 ( 152 "Arg3", 153 Object [][][].class.getName(), 154 "Desc" 155 ), 156 new MBeanParameterInfo 157 ( 158 "Arg3", 159 Attribute.class.getName(), 160 "Desc" 161 ) 162 }; 163 ModelMBeanOperationInfo invokeMixedArgs = 164 new ModelMBeanOperationInfo 165 ( 166 "invokeMixedArgs", 167 "Desc", 168 mixedArgsParms, 169 void.class.getName(), 170 ModelMBeanOperationInfo.ACTION_INFO, 171 descMixedArgs 172 ); 173 174 DescriptorSupport descMBean = new DescriptorSupport(); 176 descMBean.setField("name", RequiredModelMBean.class.getName()); 177 descMBean.setField("descriptorType", "MBean"); 178 ModelMBeanInfoSupport info = new ModelMBeanInfoSupport 179 ( 180 RequiredModelMBean.class.getName(), 181 "Resource", 182 new ModelMBeanAttributeInfo[0], 183 (ModelMBeanConstructorInfo[]) null, 184 new ModelMBeanOperationInfo[] 185 { 186 invokeMixedArgs 187 }, 188 (ModelMBeanNotificationInfo[]) null, 189 descMBean 190 ); 191 192 return info; 193 } 194 195 } 196 | Popular Tags |