use of org.apache.jmeter.samplers.Interruptible in project jmeter by apache.
the class JMeterThread method interrupt.
/** {@inheritDoc} */
@Override
public boolean interrupt() {
try {
interruptLock.lock();
// fetch once; must be done under lock
Sampler samp = currentSampler;
if (samp instanceof Interruptible) {
// (also protects against null)
if (log.isWarnEnabled()) {
log.warn("Interrupting: {} sampler: {}", threadName, samp.getName());
}
try {
boolean found = ((Interruptible) samp).interrupt();
if (!found) {
log.warn("No operation pending");
}
return found;
} catch (Exception e) {
// NOSONAR
if (log.isWarnEnabled()) {
log.warn("Caught Exception interrupting sampler: {}", e.toString());
}
}
} else if (samp != null) {
if (log.isWarnEnabled()) {
log.warn("Sampler is not Interruptible: {}", samp.getName());
}
}
} finally {
interruptLock.unlock();
}
return false;
}
use of org.apache.jmeter.samplers.Interruptible in project jmeter by apache.
the class SampleTimeout method createTask.
private void createTask(final Sampler samp) {
// refetch each time so it can be a variable
long timeout = getPropertyAsLong(TIMEOUT);
if (timeout <= 0) {
return;
}
if (!(samp instanceof Interruptible)) {
// Cannot time out in this case
return;
}
final Interruptible sampler = (Interruptible) samp;
Callable<Object> call = () -> {
long start = System.nanoTime();
boolean interrupted = sampler.interrupt();
String elapsed = Double.toString((double) (System.nanoTime() - start) / 1000000000) + " secs";
if (interrupted) {
if (log.isWarnEnabled()) {
log.warn("Call Done interrupting {} took {}", getInfo(samp), elapsed);
}
} else {
if (log.isDebugEnabled()) {
log.debug("Call Didn't interrupt: {} took {}", getInfo(samp), elapsed);
}
}
return null;
};
// schedule the interrupt to occur and save for possible cancellation
future = execService.schedule(call, timeout, TimeUnit.MILLISECONDS);
if (log.isDebugEnabled()) {
log.debug("Scheduled timer: @{} {}", System.identityHashCode(future), getInfo(samp));
}
}
Aggregations