1 17 package org.apache.jmeter.monitor.model; 18 19 20 import org.apache.jmeter.monitor.parser.Parser; 21 import org.apache.jmeter.monitor.parser.ParserImpl; 22 import org.apache.jmeter.samplers.SampleResult; 23 24 29 public class ObjectFactory 30 { 31 32 private static ObjectFactory FACTORY = null; 33 private static Parser PARSER = null; 34 35 38 protected ObjectFactory() 39 { 40 super(); 41 PARSER = new MonitorParser(this); 42 } 43 44 public static ObjectFactory getInstance(){ 45 if (FACTORY == null){ 46 FACTORY = new ObjectFactory(); 47 } 48 return FACTORY; 49 } 50 51 public synchronized Status parseBytes(byte[] bytes){ 52 return PARSER.parseBytes(bytes); 53 } 54 55 public Status parseString(String content){ 56 return PARSER.parseString(content); 57 } 58 59 public Status parseSampleResult(SampleResult result){ 60 return PARSER.parseSampleResult(result); 61 } 62 63 public Status createStatus(){ 64 return new StatusImpl(); 65 } 66 67 public Connector createConnector(){ 68 return new ConnectorImpl(); 69 } 70 71 public Jvm createJvm(){ 72 return new JvmImpl(); 73 } 74 75 public Memory createMemory(){ 76 return new MemoryImpl(); 77 } 78 79 public RequestInfo createRequestInfo(){ 80 return new RequestInfoImpl(); 81 } 82 83 public ThreadInfo createThreadInfo(){ 84 return new ThreadInfoImpl(); 85 } 86 87 public Worker createWorker(){ 88 return new WorkerImpl(); 89 } 90 91 public Workers createWorkers(){ 92 return new WorkersImpl(); 93 } 94 95 protected class MonitorParser extends ParserImpl { 96 public MonitorParser(ObjectFactory factory){ 97 super(factory); 98 } 99 } 100 101 105 public static void main(String [] args){ 106 if (args != null && args.length == 2){ 107 String file = null; 108 if (args[0] != null){ 110 file = args[0]; 111 } 112 if (args[1] != null){ 113 } 115 try { 116 ObjectFactory of = ObjectFactory.getInstance(); 117 java.io.File infile = new java.io.File (file); 118 java.io.FileInputStream fis = 119 new java.io.FileInputStream (infile); 120 java.io.InputStreamReader isr = 121 new java.io.InputStreamReader (fis); 122 StringBuffer buf = new StringBuffer (); 123 java.io.BufferedReader br = new java.io.BufferedReader (isr); 124 String line = null; 125 while ((line = br.readLine()) != null){ 126 buf.append(line); 127 } 128 System.out.println("contents: "); 129 System.out.println(buf.toString()); 130 System.out.println("----------------------"); 131 Status st = of.parseBytes(buf.toString().getBytes()); 132 if (st == null){ 133 System.out.println("parse failed"); 134 } else { 135 System.out.println("parse successful:"); 136 System.out.println(st.getJvm().getMemory().getFree()); 137 System.out.println(st.getJvm().getMemory().getTotal()); 138 System.out.println(st.getJvm().getMemory().getMax()); 139 System.out.println("connector size: " + 140 st.getConnector().size()); 141 Connector conn = (Connector)st.getConnector().get(0); 142 System.out.println("conn: " + 143 conn.getThreadInfo().getMaxThreads()); 144 } 145 } catch (java.io.FileNotFoundException e){ 146 e.printStackTrace(); 147 } catch (java.io.IOException e){ 148 e.printStackTrace(); 149 } 150 } else { 151 } 152 } 153 } 154 | Popular Tags |