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 2001/12/23 05:49:10 UTC
cvs commit: jakarta-jmeter/src/org/apache/jmeter/ejb/jndi/sampler JNDISampler.java
neth 01/12/22 20:49:10
Added: src/org/apache/jmeter/ejb/jndi/sampler JNDISampler.java
Log:
Samples the JNDI lookups based on the Entries generated by JndiTestSample from all JNDI configurations
Revision Changes Path
1.1 jakarta-jmeter/src/org/apache/jmeter/ejb/jndi/sampler/JNDISampler.java
Index: JNDISampler.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.ejb.jndi.sampler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.jmeter.ejb.jndi.config.JndiConfig;
import org.apache.jmeter.ejb.jndi.config.LookupConfig;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.JndiSampleResult;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.log4j.Category;
/**
* Samples the JNDI performance and records them
*
* @author Khor Soon Hin
* @created 2001 Dec 18
* @modified 2001 Dec 22
*/
public class JNDISampler implements Sampler
{
private static Category catClass = Category.getInstance(
JNDISampler.class.getName());
public static final String QUERY = "JNDISampler.query";
protected static Map keyMap = new HashMap();
public JNDISampler()
{
}
/**
* The main method which samples and records the JNDI performance
*
* @param e the JNDI sampling configuration
* @return the measurements captured
*/
public SampleResult sample(Entry e)
{
catClass.info("Start : sample1");
long start = (long)0;
long end = (long)0;
long ctxTime = (long)0;
long lookupTime = (long)0;
long methodTime = (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();
Hashtable ht = new Hashtable();
JndiConfig jndiConfig = null;
InitialContext ctx = null;
try
{
jndiConfig = (JndiConfig)e.getConfigElement(JndiConfig.class);
// check if InitialContext is already obtained previously
ctx = jndiConfig.getInitialContext();
if(ctx == null)
{
// setup the hashtable
for(int i = 0 ; i < JndiConfig.JNDI_PROPS.length; i++)
{
String value = jndiConfig.getValue(i);
if(value != null)
{
if(catClass.isDebugEnabled())
{
catClass.debug("sample1 : JNDI env - " +
JndiConfig.JNDI_PROPS[i] + " = " + value);
}
ht.put(JndiConfig.JNDI_PROPS[i], value);
}
}
// initialize initial context
start = System.currentTimeMillis();
ctx = new InitialContext(ht);
end = System.currentTimeMillis();
catClass.info("sample1 : Got initial context");
// store the initial context for reuse
jndiConfig.setInitialContext(ctx);
}
// set the initial context lookup time
ctxTime = end - start;
contextLookupRes.setTime(ctxTime);
// look up the name
LookupConfig lookupConfig =
(LookupConfig)e.getConfigElement(LookupConfig.class);
String lookupName = lookupConfig.getLookupName();
if(catClass.isDebugEnabled())
{
catClass.debug("sample1 : Got LookupConfig - " + lookupConfig);
catClass.debug("sample1 : LookupName - " + lookupName);
}
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;
res.setTime(0);
res.putValue(SampleResult.DISPLAY_NAME, lookupName);
ArrayList resultList = new ArrayList();
resultList.add(contextLookupRes);
resultList.add(lookupRes);
resultList.add(methodRes);
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);
}
catch(NamingException err)
{
catClass.error(err);
System.err.println(err);
}
catClass.info("End : sample1");
return res;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>