SampleResult previousResult,
Sampler currentSampler)
throws InvalidVariableException
{
JMeterVariables vars = getVariables();
if (values.length >= PARAM_NAME)
{
myName = ((CompoundVariable) values[PARAM_NAME-1]).execute();
}
myValue = ERR_IND;
/*
* To avoid re-opening the file repeatedly after an error,
* only try to open it in the first execute() call
* (It may be re=opened at EOF, but that will cause at most
* one failure.)
*/
if (firstTime) {
openFile();
firstTime=false;
}
if (null != myBread)
{ // Did we open the file?
try
{
String line = myBread.readLine();
if (line == null && reopenFile)
{ // EOF, re-open file
log.info("Reached EOF on " + fileName);//$NON-NLS-1$
closeFile();
openFile();
if (myBread != null) {
line = myBread.readLine();
} else {
line = ERR_IND;
}
}
myValue = line;
}
catch (Exception e)
{
String tn = Thread.currentThread().getName();
log.error(tn + " error reading file " + e.toString());//$NON-NLS-1$
}
} else { // File was not opened successfully
if (values.length >= PARAM_END){// Are we processing a file sequence?
log.info("Detected end of sequence.");
throw new RuntimeException("Stop Thread");//TODO there has to be a better way...
}
}
if (myName.length() > 0){
vars.put(myName, myValue);
}
if (log.isDebugEnabled()){
log.debug(this +"::StringFromFile.execute() name:" //$NON-NLS-1$
+ myName + " value:" + myValue);//$NON-NLS-1$