KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > engine > ClientJMeterEngine


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java,v 1.14 2004/02/12 23:59:01 sebb Exp $
2
/*
3  * Copyright 2001-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 */

18
19 package org.apache.jmeter.engine;
20 import java.net.MalformedURLException JavaDoc;
21 import java.rmi.Naming JavaDoc;
22 import java.rmi.NotBoundException JavaDoc;
23 import java.rmi.RemoteException JavaDoc;
24
25 import org.apache.jmeter.testelement.TestListener;
26 import org.apache.jorphan.collections.HashTree;
27 import org.apache.jorphan.collections.SearchByClass;
28 import org.apache.jorphan.logging.LoggingManager;
29 import org.apache.log.Logger;
30
31
32 /**
33  * @author unattributed
34  * @version $Revision: 1.14 $ Updated on: $Date: 2004/02/12 23:59:01 $
35  */

36 public class ClientJMeterEngine implements JMeterEngine,Runnable JavaDoc
37 {
38     transient private static Logger log = LoggingManager.getLoggerForClass();
39     RemoteJMeterEngine remote;
40     HashTree test;
41     SearchByClass testListeners;
42     ConvertListeners sampleListeners;
43     private String JavaDoc host;
44
45     public ClientJMeterEngine(String JavaDoc host)
46         throws MalformedURLException JavaDoc, NotBoundException JavaDoc, RemoteException JavaDoc
47     {
48         this((RemoteJMeterEngine) Naming.lookup("//" + host + "/JMeterEngine"));
49         this.host = host;
50     }
51
52     public ClientJMeterEngine(RemoteJMeterEngine remote)
53     {
54         this.remote = remote;
55     }
56
57     protected HashTree getTestTree()
58     {
59         return test;
60     }
61
62     public void configure(HashTree testTree)
63     {
64         test = testTree;
65     }
66
67     public void setHost(String JavaDoc host)
68     {
69         this.host = host;
70     }
71
72     public void runTest()
73     {
74         log.info("about to run remote test");
75         new Thread JavaDoc(this).start();
76         log.info("done initiating run command");
77     }
78
79     public void stopTest()
80     {
81         try
82         {
83             remote.stopTest();
84         }
85         catch (Exception JavaDoc ex)
86         {
87             log.error("", ex);
88         }
89     }
90
91     public void reset()
92     {
93         try
94         {
95             remote.reset();
96         }
97         catch (Exception JavaDoc ex)
98         {
99             log.error("", ex);
100         }
101     }
102
103     /* (non-Javadoc)
104      * @see java.lang.Runnable#run()
105      */

106     public void run()
107     {
108         log.info("running clientengine run method");
109         testListeners = new SearchByClass(TestListener.class);
110         getTestTree().traverse(testListeners);
111         sampleListeners = new ConvertListeners();
112         
113         //TODO this is a temporary fix - see bug 23487
114
try {
115             getTestTree().traverse(sampleListeners);
116         }
117         catch(IndexOutOfBoundsException JavaDoc e)
118         {
119             log.warn("Error replacing sample listeners",e);
120         }
121         
122         try
123         {
124             remote.setHost(host);
125             log.info("sent host ="+host);
126             remote.configure(test);
127             log.info("sent test");
128             remote.runTest();
129             log.info("sent run command");
130         }
131         catch(Exception JavaDoc ex)
132         {
133             log.error("",ex);
134         }
135     }
136
137     /* (non-Javadoc)
138      * @see org.apache.jmeter.engine.JMeterEngine#exit()
139      */

140     public void exit()
141     {
142         try
143         {
144             remote.exit();
145         }
146         catch (RemoteException JavaDoc e)
147         {
148             log.warn("Could not perform remote exit: "+e.toString());
149         }
150     }
151 }
152
Popular Tags