Search in sources :

Example 1 with Interruptible

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;
}
Also used : Interruptible(org.apache.jmeter.samplers.Interruptible) TransactionSampler(org.apache.jmeter.control.TransactionSampler) Sampler(org.apache.jmeter.samplers.Sampler) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterStopTestNowException(org.apache.jorphan.util.JMeterStopTestNowException)

Example 2 with Interruptible

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));
    }
}
Also used : Interruptible(org.apache.jmeter.samplers.Interruptible)

Aggregations

Interruptible (org.apache.jmeter.samplers.Interruptible)2 TransactionSampler (org.apache.jmeter.control.TransactionSampler)1 Sampler (org.apache.jmeter.samplers.Sampler)1 JMeterStopTestException (org.apache.jorphan.util.JMeterStopTestException)1 JMeterStopTestNowException (org.apache.jorphan.util.JMeterStopTestNowException)1 JMeterStopThreadException (org.apache.jorphan.util.JMeterStopThreadException)1