You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by ne...@apache.org on 2002/01/19 04:59:47 UTC
cvs commit: jakarta-jmeter/src/org/apache/jmeter/ejb/jndi/sampler JNDISampler.java
neth 02/01/18 19:59:47
Modified: src/org/apache/jmeter/ejb/jndi/sampler JNDISampler.java
Log:
Modified to handle reflection of Home Interface
Revision Changes Path
1.3 +167 -24 jakarta-jmeter/src/org/apache/jmeter/ejb/jndi/sampler/JNDISampler.java
Index: JNDISampler.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/ejb/jndi/sampler/JNDISampler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JNDISampler.java 24 Dec 2001 02:54:46 -0000 1.2
+++ JNDISampler.java 19 Jan 2002 03:59:47 -0000 1.3
@@ -54,6 +54,8 @@
*/
package org.apache.jmeter.ejb.jndi.sampler;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
@@ -64,6 +66,9 @@
import org.apache.jmeter.ejb.jndi.config.JndiConfig;
import org.apache.jmeter.ejb.jndi.config.LookupConfig;
+import org.apache.jmeter.ejb.jndi.config.MethodConfig;
+import org.apache.jmeter.ejb.jndi.config.MethodConfigUserObjectException;
+import org.apache.jmeter.ejb.jndi.config.gui.MethodConfigGui;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.samplers.SampleResult;
@@ -101,13 +106,13 @@
long end = (long)0;
long ctxTime = (long)0;
long lookupTime = (long)0;
- long methodTime = (long)0;
+ long homeMethodTime = (long)0;
SampleResult res = new SampleResult();
SampleResult contextLookupRes = new SampleResult();
contextLookupRes.putValue(SampleResult.DISPLAY_NAME, "Context Lookup");
SampleResult lookupRes = new SampleResult();
- SampleResult methodRes = new SampleResult();
+ SampleResult homeMethodRes = null;
Hashtable ht = new Hashtable();
JndiConfig jndiConfig = null;
InitialContext ctx = null;
@@ -145,44 +150,182 @@
contextLookupRes.setTime(ctxTime);
// look up the name
+ Object ref = null;
LookupConfig lookupConfig =
(LookupConfig)e.getConfigElement(LookupConfig.class);
- String lookupName = lookupConfig.getLookupName();
+ String lookupName = null;
+ if(lookupConfig != null)
+ {
+ lookupName = lookupConfig.getLookupName();
+ if(catClass.isDebugEnabled())
+ {
+ catClass.debug("sample1 : LookupName - " + lookupName);
+ }
+ start = System.currentTimeMillis();
+ ref = ctx.lookup(lookupName);
+ end = System.currentTimeMillis();
+ lookupTime = end - start;
+ catClass.info("Got remote interface");
+ lookupRes.setTime(lookupTime);
+ lookupRes.putValue(SampleResult.DISPLAY_NAME,
+ "Remote Interface Lookup - " + lookupName);
+ }
+ Class lookupNameClass = ref.getClass();
+
+ // lookup method name
+ MethodConfig methodConfig =
+ (MethodConfig)e.getConfigElement(MethodConfig.class);
+ // store all reflections result in the model of the gui and not the
+ // MethodConfig obtained from getConfigElement() 'cos that's the clone.
+ // To get the model of the MethodConfigGui, get the MethodConfigGui
+ // from the MethodConfig clone first. All MethodConfig clones cloned
+ // from the same MethodConfig shares the same MethodConfigGui.
+ MethodConfigGui methodConfigGui = methodConfig.getGui();
+ MethodConfig model = methodConfigGui.getModel();
+ // Make all changes on the model of the gui and not the MethodConfig
+ // obtained from getConfigElement() because that is the clone.
+ int state = model.getState();
+ String[] strings = null;
if(catClass.isDebugEnabled())
{
- catClass.debug("sample1 : Got LookupConfig - " + lookupConfig);
- catClass.debug("sample1 : LookupName - " + lookupName);
+ catClass.debug("sample1 : state - " + state);
+ }
+ if(state == MethodConfig.METHOD_GET_HOME_NAMES)
+ {
+ // for this state, get the list of all methods in the remote
+ // interface
+ Method[] methods = lookupNameClass.getMethods();
+ Class[] parameterTypes = null;
+ StringBuffer strbuff = new StringBuffer();
+ strings = new String[methods.length];
+ for(int i = 0; i < methods.length; i++)
+ {
+ // create method name which includes method signatures
+ parameterTypes = methods[i].getParameterTypes();
+ strbuff.delete(0, strbuff.length());
+ strbuff.append(methods[i].getName());
+ strbuff.append("(");
+ if(parameterTypes.length > 0)
+ {
+ for(int j = 0; j < (parameterTypes.length - 1); j++)
+ {
+ strbuff.append(parameterTypes[j].toString());
+ strbuff.append(", ");
+ }
+ strbuff.append(parameterTypes[parameterTypes.length - 1]);
+ }
+ strbuff.append(")");
+ strings[i] = strbuff.toString();
+ }
+ model.setMethodHomeList(strings);
+ model.setState(MethodConfig.METHOD_GET_HOME_PARMS);
+ }
+ else if(state == MethodConfig.METHOD_GET_HOME_PARMS)
+ {
+ // for this state, get all the required parms for the selected
+ // method
+ String methodHomeName = methodConfig.getMethodHomeName();
+ if(catClass.isDebugEnabled())
+ {
+ catClass.debug("sample1 : selected methodHomeName - " +
+ methodHomeName);
+ }
+ Method method = null;
+ Method[] methods = lookupNameClass.getMethods();
+ Class[] parameterTypes = null;
+ Class[] methodParmTypes = null;
+ StringBuffer strbuff = new StringBuffer();
+ for(int i = 0; i < methods.length; i++)
+ {
+ // create method name which includes method signatures
+ parameterTypes = methods[i].getParameterTypes();
+ strbuff.delete(0, strbuff.length());
+ strbuff.append(methods[i].getName());
+ strbuff.append("(");
+ if(parameterTypes.length > 0)
+ {
+ for(int j = 0; j < (parameterTypes.length - 1); j++)
+ {
+ strbuff.append(parameterTypes[j].toString());
+ strbuff.append(", ");
+ }
+ strbuff.append(parameterTypes[parameterTypes.length - 1]);
+ }
+ strbuff.append(")");
+ String name = strbuff.toString();
+ if(catClass.isDebugEnabled())
+ {
+ catClass.debug("sample1 : current method to be compared - " + name);
+ }
+ if(name.equals(methodHomeName))
+ {
+ method = methods[i];
+ methodParmTypes = parameterTypes;
+ break;
+ }
+ }
+ // once the method is obtained store the parms
+ model.setMethodHomeParms(methodParmTypes);
+ model.setMethod(method);
+ model.setState(MethodConfig.METHOD_INVOKE_HOME);
+ }
+ else if(state == MethodConfig.METHOD_INVOKE_HOME)
+ {
+ Method method = model.getMethod();
+ // only initialize homeMethodRes if method execution is to be measured
+ homeMethodRes = new SampleResult();
+ // invoke the method
+ start = System.currentTimeMillis();
+ // gather all parms from MethodConfigGui
+ Object[] parmsArray = null;
+ try
+ {
+ parmsArray = methodConfigGui.getMethodParmsValues();
+ Object returnVal = method.invoke(ref, parmsArray);
+System.out.println("return - " + returnVal);
+ }
+ catch(IllegalAccessException err)
+ {
+ catClass.error(err);
+ System.out.println(err);
+ }
+ catch(InvocationTargetException err)
+ {
+ catClass.error(err);
+ System.out.println(err);
+ }
+ catch(MethodConfigUserObjectException err)
+ {
+ catClass.error(err);
+ System.out.println(err);
+ }
+ end = System.currentTimeMillis();
+ homeMethodTime = end - start;
+ homeMethodRes.setTime(homeMethodTime);
+ homeMethodRes.putValue(SampleResult.DISPLAY_NAME, "Home Method Execution - "
+ + method.getName());
}
- start = System.currentTimeMillis();
- Object ref = ctx.lookup(lookupName);
- end = System.currentTimeMillis();
- lookupTime = end - start;
- catClass.info("Got remote interface");
- lookupRes.setTime(lookupTime);
- lookupRes.putValue(SampleResult.DISPLAY_NAME,
- "Remote Interface Lookup - " + lookupName);
- // invoke the method
- start = System.currentTimeMillis();
- end = System.currentTimeMillis();
- String methodName = "hello";
- methodTime = end - start;
- methodRes.setTime(methodTime);
- methodRes.putValue(SampleResult.DISPLAY_NAME, "Method Execution - "
- + methodName);
- long totalTime = ctxTime + lookupTime + methodTime;
+ long totalTime = ctxTime + lookupTime + homeMethodTime;
res.setTime(0);
res.putValue(SampleResult.DISPLAY_NAME, lookupName);
ArrayList resultList = new ArrayList();
+ // don't need to test for null in contextLookupRes and lookupRes
+ // because both cannot be null otherwise error will be thrown
resultList.add(contextLookupRes);
resultList.add(lookupRes);
- resultList.add(methodRes);
+ // test for null in methodRes 'cos a null means that user just want
+ // to get a list of all methods of the remote interfaces
+ if(homeMethodRes != null)
+ {
+ resultList.add(homeMethodRes);
+ }
res.putValue(SampleResult.RESULT_LIST, resultList);
res.putValue(SampleResult.TOTAL_TIME, new Long(totalTime));
System.out.println("!!!!! ctxTime : " + ctxTime);
System.out.println("!!!!! lookupTime : " + lookupTime);
- System.out.println("!!!!! methodTime : " + methodTime);
+ System.out.println("!!!!! homeMethodTime : " + homeMethodTime);
}
catch(NamingException err)
{
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>