1 4 package com.tctest.longrunning; 5 6 import EDU.oswego.cs.dl.util.concurrent.BrokenBarrierException; 7 import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier; 8 9 import com.tc.simulator.app.ApplicationConfig; 10 import com.tc.simulator.distrunner.ArgException; 11 import com.tc.simulator.distrunner.ArgParser; 12 import com.tc.simulator.distrunner.SpecFactoryImpl; 13 import com.tc.simulator.listener.ListenerProvider; 14 import com.tc.simulator.listener.OutputListener; 15 import com.tc.simulator.listener.ResultsListener; 16 import com.tc.simulator.listener.StatsListener; 17 import com.tcsimulator.ApplicationConfigImpl; 18 import com.tcsimulator.listener.OutputListenerObject; 19 20 import java.util.Iterator ; 21 import java.util.Map ; 22 import java.util.Properties ; 23 import java.util.Map.Entry; 24 25 public class LongrunningGCTestAppCLI { 26 private static final String PARTICIPANT_COUNT_ARG = "participantcount"; 27 private static int globalParticipantCount; 28 private static int intensity; 29 private static CyclicBarrier barrier; 30 31 public static void main(String [] args) throws ArgException, BrokenBarrierException, InterruptedException { 32 parseArgs(args); 33 barrier = new CyclicBarrier(globalParticipantCount); 34 ArgParser parser = new ArgParser(args, new SpecFactoryImpl(), false, false); 35 intensity = parser.getIntensity(); 36 37 String appId = "1"; 38 String applicatonClassname = LongrunningGCTestApp.class.getName(); 39 ApplicationConfig cfg = new ApplicationConfigImpl(applicatonClassname, intensity, globalParticipantCount); 40 ListenerProvider provider = new TestAppApplicationListenerProvider(new OutputListenerObject(), null); 41 LongrunningGCTestApp testApp = new LongrunningGCTestApp(appId, cfg, provider); 42 43 System.out.println("Waiting for other clients to start..."); 44 barrier.barrier(); 45 System.out.println("Done waiting for all clients to start."); 46 testApp.run(); 47 } 48 49 private static void parseArgs(String [] args) throws ArgException { 50 for (int i = 0; i < args.length; i++) { 51 if (args[i].startsWith(PARTICIPANT_COUNT_ARG)) { 52 String [] nvPair = args[i].split("="); 53 if (nvPair.length != 2) { throw new ArgException("Malformed argument: " + args[i]); } 54 globalParticipantCount = Integer.parseInt(nvPair[1]); 55 } 56 } 57 if (globalParticipantCount == 0) { throw new AssertionError ("Participant count must be specified."); } 58 } 59 60 61 62 private static class TestAppApplicationListenerProvider implements ListenerProvider { 63 private final OutputListener outputListener; 64 private final ResultsListener resultsListener; 65 66 public TestAppApplicationListenerProvider(OutputListener ol, ResultsListener rl) { 67 this.outputListener = ol; 68 this.resultsListener = rl; 69 } 70 71 public OutputListener getOutputListener() { 72 return outputListener; 73 } 74 75 public ResultsListener getResultsListener() { 76 return resultsListener; 77 } 78 79 public StatsListener newStatsListener(Properties properties) { 80 return new TestAppStatsListenerObject(properties); 81 } 82 83 } 84 85 86 87 private static class TestAppStatsListenerObject implements StatsListener { 88 private final String label; 89 private static final String TOKEN = "<app-perf>"; 90 91 public TestAppStatsListenerObject(Properties properties) { 92 StringBuffer buf = new StringBuffer (); 93 for (Iterator i = properties.entrySet().iterator(); i.hasNext();) { 94 Map.Entry entry = (Entry) i.next(); 95 buf.append(entry.getKey() + "=" + entry.getValue()); 96 if (i.hasNext()) { 97 buf.append(","); 98 } 99 } 100 this.label = buf.toString(); 101 } 102 103 public void sample(long sampleValue, String desc) { 104 System.out.println(TOKEN + label + ": " + sampleValue); 105 } 106 107 } 108 109 } 110 | Popular Tags |