KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > monitor > model > ObjectFactory


1 // $Header: /home/cvs/jakarta-jmeter/src/monitor/model/org/apache/jmeter/monitor/model/ObjectFactory.java,v 1.5.2.1 2004/06/12 20:27:39 sebb Exp $
2
/*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 /**
25  * ObjectFactory is a simple factory class which creates
26  * new instances of objects. It also provides convienant
27  * method to parse XML status results.
28  */

29 public class ObjectFactory
30 {
31
32     private static ObjectFactory FACTORY = null;
33     private static Parser PARSER = null;
34     
35     /**
36      *
37      */

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 JavaDoc 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     /**
102      * Basic method for testing the class
103      * @param args
104      */

105     public static void main(String JavaDoc[] args){
106         if (args != null && args.length == 2){
107             String JavaDoc file = null;
108             //int count = 1;
109
if (args[0] != null){
110                 file = args[0];
111             }
112             if (args[1] != null){
113                 //count = Integer.parseInt(args[1]);
114
}
115             try {
116                 ObjectFactory of = ObjectFactory.getInstance();
117                 java.io.File JavaDoc infile = new java.io.File JavaDoc(file);
118                 java.io.FileInputStream JavaDoc fis =
119                     new java.io.FileInputStream JavaDoc(infile);
120                 java.io.InputStreamReader JavaDoc isr =
121                     new java.io.InputStreamReader JavaDoc(fis);
122                 StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
123                 java.io.BufferedReader JavaDoc br = new java.io.BufferedReader JavaDoc(isr);
124                 String JavaDoc 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 JavaDoc e){
146                 e.printStackTrace();
147             } catch (java.io.IOException JavaDoc e){
148                 e.printStackTrace();
149             }
150         } else {
151         }
152     }
153 }
154
Popular Tags