本文整理了Java中org.apache.jmeter.threads.JMeterContext.getThread()
方法的一些代码示例,展示了JMeterContext.getThread()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMeterContext.getThread()
方法的具体详情如下:
包路径:org.apache.jmeter.threads.JMeterContext
类名称:JMeterContext
方法名:getThread
[英]Returns the threadNum.
[中]返回threadNum。
代码示例来源:origin: Blazemeter/jmeter-bzm-plugins
public JMeterThreadParallel(HashTree test, JMeterThreadMonitor monitor, ListenerNotifier notifier, boolean generateParent) {
super(test, monitor, notifier);
this.generateParent = generateParent;
parentThread = JMeterContextService.getContext().getThread();
if (parentThread == null) {
throw new NullPointerException();
}
try {
copyCompilerFromParent();
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: undera/jmeter-plugins
/**
* Update the worker thread jmeter context with the main thread one
* @param isInit if true the context a full copy is done, if false only update is done
*/
private void syncContext(boolean isInit)
{
// jmeter context synchronisation
JMeterContext current = JMeterContextService.getContext();
JMeterContext ctx = this.getThreadContext();
if (isInit)
{
current.setCurrentSampler(ctx.getCurrentSampler());
current.setEngine(ctx.getEngine());
current.setRestartNextLoop(ctx.isRestartNextLoop());
current.setSamplingStarted(ctx.isSamplingStarted());
current.setThread(ctx.getThread());
current.setThreadGroup(ctx.getThreadGroup());
current.setThreadNum(ctx.getThreadNum());
}
current.setVariables(ctx.getVariables());
current.setPreviousResult(ctx.getPreviousResult());
//current.getSamplerContext().putAll(ctx.getSamplerContext());
}
代码示例来源:origin: Blazemeter/jmeter-bzm-plugins
private HashTree getSubTree(TestElement te) {
try {
Field field = JMeterThread.class.getDeclaredField("testTree");
field.setAccessible(true);
JMeterThread parentThread = JMeterContextService.getContext().getThread();
if (parentThread == null) {
log.error("Current thread is null.");
throw new NullPointerException();
}
HashTree testTree = (HashTree) field.get(parentThread);
SearchByClass<?> searcher = new SearchByClass<>(te.getClass());
testTree.traverse(searcher);
return searcher.getSubTree(te);
} catch (ReflectiveOperationException ex) {
log.warn("Can not get sub tree for Test element " + te.getName(), ex);
return null;
}
}
代码示例来源:origin: undera/jmeter-plugins
/**
* Update the worker thread jmeter context with the main thread one
* @param isInit if true the context a full copy is done, if false only update is done
*/
private void syncContext(boolean isInit)
{
// jmeter context synchronisation
JMeterContext current = JMeterContextService.getContext();
JMeterContext ctx = this.getThreadContext();
if (isInit)
{
current.setCurrentSampler(ctx.getCurrentSampler());
current.setEngine(ctx.getEngine());
current.setRestartNextLoop(ctx.isRestartNextLoop());
current.setSamplingStarted(ctx.isSamplingStarted());
current.setThread(ctx.getThread());
current.setThreadGroup(ctx.getThreadGroup());
current.setThreadNum(ctx.getThreadNum());
}
current.setVariables(ctx.getVariables());
current.setPreviousResult(ctx.getPreviousResult());
//current.getSamplerContext().putAll(ctx.getSamplerContext());
}
@Override
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_components
@Override
public long delay() {
double nextEvent;
EventProducer events = getEventProducer();
synchronized (events) {
nextEvent = events.next();
}
long delay = (long) (nextEvent * TimeUnit.SECONDS.toMillis(1) + testStarted - System.currentTimeMillis());
if (log.isDebugEnabled()) {
log.debug("Calculated delay is {}", delay);
}
delay = Math.max(0, delay);
long endTime = getThreadContext().getThread().getEndTime();
if (endTime > 0 && System.currentTimeMillis() + delay > endTime) {
throw new JMeterStopThreadException("The thread is scheduled to stop in " +
(System.currentTimeMillis() - endTime) + " ms" +
" and the throughput timer generates a delay of " + delay + "." +
" JMeter (as of 4.0) does not support interrupting of sleeping threads, thus terminating the thread manually."
);
}
return delay;
}
代码示例来源:origin: kg.apc/jmeter-plugins-cmn-jmeter
/**
* Update the worker thread jmeter context with the main thread one
* @param isInit if true the context a full copy is done, if false only update is done
*/
private void syncContext(boolean isInit)
{
// jmeter context synchronisation
JMeterContext current = JMeterContextService.getContext();
JMeterContext ctx = this.getThreadContext();
if (isInit)
{
current.setCurrentSampler(ctx.getCurrentSampler());
current.setEngine(ctx.getEngine());
current.setRestartNextLoop(ctx.isRestartNextLoop());
current.setSamplingStarted(ctx.isSamplingStarted());
current.setThread(ctx.getThread());
current.setThreadGroup(ctx.getThreadGroup());
current.setThreadNum(ctx.getThreadNum());
}
current.setVariables(ctx.getVariables());
current.setPreviousResult(ctx.getPreviousResult());
//current.getSamplerContext().putAll(ctx.getSamplerContext());
}
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_core
/**
* Adjust delay so that initialDelay does not exceed end of test
* @param initialDelay initial delay in millis
* @return initialDelay or adjusted delay
*/
public long adjustDelay(final long initialDelay) {
JMeterThread thread = JMeterContextService.getContext().getThread();
long endTime = thread != null ? thread.getEndTime() : 0;
return adjustDelay(initialDelay, endTime);
}
代码示例来源:origin: kg.apc/jmeter-plugins-standard
public void startNextLoop() {
JMeterThread thread = JMeterContextService.getContext().getThread();
if (owner instanceof ArrivalsThreadGroup) {
getOwnerAsArrivals().abandonFact(thread, iterationNo);
}
if (!moveToPool(thread)) {
setDone(true);
}
}
代码示例来源:origin: undera/jmeter-plugins
public void startNextLoop() {
JMeterThread thread = JMeterContextService.getContext().getThread();
if (owner instanceof ArrivalsThreadGroup) {
getOwnerAsArrivals().abandonFact(thread, iterationNo);
if (!moveToPool(thread)) {
setDone(true);
}
} else {
reInitialize();
}
}
代码示例来源:origin: kg.apc/jmeter-plugins-standard
@Override
public Sampler next() {
if (!owner.isRunning()) {
setDone(true);
} else if (!hasArrived) {
if (owner.isLimitReached()) {
throw new IllegalStateException("Should not have more iterations");
}
hasArrived = true;
iterationNo++;
if (owner instanceof ArrivalsThreadGroup) {
getOwnerAsArrivals().arrivalFact(JMeterContextService.getContext().getThread(), iterationNo);
}
}
return super.next();
}
代码示例来源:origin: undera/jmeter-plugins
@Override
public Sampler next() {
if (owner.isLimitReached()) {
setDone(true);
} else if (!hasArrived) {
if (owner.isLimitReached()) {
throw new IllegalStateException("Should not have more iterations");
}
hasArrived = true;
iterationNo++;
if (owner instanceof ArrivalsThreadGroup) {
getOwnerAsArrivals().arrivalFact(JMeterContextService.getContext().getThread(), iterationNo);
}
}
return super.next();
}
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_components
log.info(MSG_STOP_CURRENT_THREAD, getName());
context.getThread().stop();
} else if (target == TEST) {
if (action == STOP_NOW) {
log.info(MSG_STOP_CURRENT_THREAD, getName());
context.getThread().stop();
if(log.isInfoEnabled()) {
log.info("Stopping all threads now from element {}", getName());
log.info(MSG_STOP_CURRENT_THREAD, getName());
context.getThread().stop();
if(log.isInfoEnabled()) {
log.info("Stopping all threads from element {}", getName());
代码示例来源:origin: kg.apc/jmeter-plugins-casutg
@Override
public Sampler next() {
if (owner.isLimitReached()) {
setDone(true);
} else if (!hasArrived) {
if (owner.isLimitReached()) {
throw new IllegalStateException("Should not have more iterations");
}
hasArrived = true;
iterationNo++;
if (owner instanceof ArrivalsThreadGroup) {
getOwnerAsArrivals().arrivalFact(JMeterContextService.getContext().getThread(), iterationNo);
}
}
return super.next();
}
代码示例来源:origin: kg.apc/jmeter-plugins-casutg
public void startNextLoop() {
JMeterThread thread = JMeterContextService.getContext().getThread();
if (owner instanceof ArrivalsThreadGroup) {
getOwnerAsArrivals().abandonFact(thread, iterationNo);
if (!moveToPool(thread)) {
setDone(true);
}
} else {
reInitialize();
}
}
代码示例来源:origin: kawasima/jmeter-websocket
public void initialize() throws Exception {
URI uri = getUri();
WebSocketClient webSocketClient = webSocketClientFactory.newWebSocketClient();
final WebSocketSampler parent = this;
final String threadName = JMeterContextService.getContext().getThread().getThreadName();
final Pattern regex = (getRecvMessage() != null) ? Pattern.compile(getRecvMessage()) : null;
Future<WebSocket.Connection> futureConnection = webSocketClient.open(uri, new WebSocket.OnTextMessage() {
@Override
public void onMessage(String s) {
synchronized (parent) {
if (regex == null || regex.matcher(s).find()) {
responseMessage = s;
parent.notify();
}
}
}
@Override
public void onOpen(Connection connection) {
log.debug("Connect " + threadName);
}
@Override
public void onClose(int i, String s) {
log.debug("Disconnect " + threadName);
}
});
connection = futureConnection.get();
samplerConnections.add(connection);
initialized = true;
}
@Override
代码示例来源:origin: kg.apc/jmeter-plugins-extras
} else {
log.info("End of file reached: " + getFileName());
if (JMeterContextService.getContext().getThread() != null) {
JMeterContextService.getContext().getThread().stop();
代码示例来源:origin: undera/jmeter-plugins
} else {
log.info("End of file reached: " + getFileName());
if (JMeterContextService.getContext().getThread() != null) {
JMeterContextService.getContext().getThread().stop();
代码示例来源:origin: kg.apc/jmeter-plugins-standard
@Override
protected Sampler nextIsNull() throws NextIsNullException {
JMeterThread thread = JMeterContextService.getContext().getThread();
if (owner instanceof ArrivalsThreadGroup) {
getOwnerAsArrivals().completionFact(thread, iterationNo);
}
long iLimit = owner.getIterationsLimitAsLong();
if (owner.isLimitReached()) {
log.info("Test limit reached, thread is done: " + thread.getThreadName());
setDone(true);
return null;
} else if (iLimit > 0 && iterationNo >= iLimit) {
log.info("Iteration limit reached, thread is done: " + thread.getThreadName());
setDone(true);
return null;
} else if (owner instanceof ConcurrencyThreadGroup && ((ConcurrencyThreadGroup) owner).tooMuchConcurrency()) {
log.info("Need to decrease concurrency, thread is done: " + thread.getThreadName());
setDone(true);
return null;
} else if (owner instanceof ArrivalsThreadGroup) {
moveToPool(thread);
return super.nextIsNull();
} else {
reInitialize();
return next();
}
}
代码示例来源:origin: undera/jmeter-plugins
@Override
protected Sampler nextIsNull() throws NextIsNullException {
JMeterThread thread = JMeterContextService.getContext().getThread();
if (owner instanceof ArrivalsThreadGroup) {
getOwnerAsArrivals().completionFact(thread, iterationNo);
}
long iLimit = owner.getIterationsLimitAsLong();
if (owner.isLimitReached()) {
log.info("Test limit reached, thread is done: " + thread.getThreadName());
setDone(true);
return null;
} else if (iLimit > 0 && iterationNo >= iLimit) {
log.info("Iteration limit reached, thread is done: " + thread.getThreadName());
setDone(true);
return null;
} else if (owner instanceof ConcurrencyThreadGroup && ((ConcurrencyThreadGroup) owner).tooMuchConcurrency()) {
log.info("Need to decrease concurrency, thread is done: " + thread.getThreadName());
setDone(true);
return null;
} else if (owner instanceof ArrivalsThreadGroup) {
moveToPool(thread);
return super.nextIsNull();
} else {
reInitialize();
return next();
}
}
代码示例来源:origin: kg.apc/jmeter-plugins-casutg
@Override
protected Sampler nextIsNull() throws NextIsNullException {
JMeterThread thread = JMeterContextService.getContext().getThread();
if (owner instanceof ArrivalsThreadGroup) {
getOwnerAsArrivals().completionFact(thread, iterationNo);
}
long iLimit = owner.getIterationsLimitAsLong();
if (owner.isLimitReached()) {
log.info("Test limit reached, thread is done: " + thread.getThreadName());
setDone(true);
return null;
} else if (iLimit > 0 && iterationNo >= iLimit) {
log.info("Iteration limit reached, thread is done: " + thread.getThreadName());
setDone(true);
return null;
} else if (owner instanceof ConcurrencyThreadGroup && ((ConcurrencyThreadGroup) owner).tooMuchConcurrency()) {
log.info("Need to decrease concurrency, thread is done: " + thread.getThreadName());
setDone(true);
return null;
} else if (owner instanceof ArrivalsThreadGroup) {
moveToPool(thread);
return super.nextIsNull();
} else {
reInitialize();
return next();
}
}
内容来源于网络,如有侵权,请联系作者删除!