001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.threads;
020:
021: import org.apache.jmeter.samplers.SampleResult;
022: import org.apache.jmeter.samplers.Sampler;
023: import org.apache.jmeter.engine.StandardJMeterEngine;
024:
025: /**
026: * Holds context for a thread
027: */
028: public class JMeterContext {
029: JMeterVariables variables;
030:
031: SampleResult previousResult;
032:
033: Sampler currentSampler;
034:
035: Sampler previousSampler;
036:
037: boolean samplingStarted;
038:
039: private StandardJMeterEngine engine;
040:
041: private JMeterThread thread;
042:
043: private ThreadGroup threadGroup;
044:
045: private int threadNum;
046:
047: private byte[] readBuffer = null;
048:
049: JMeterContext() {
050: variables = null;
051: previousResult = null;
052: currentSampler = null;
053: samplingStarted = false;
054: }
055:
056: public void clear() {
057: variables = null;
058: previousResult = null;
059: currentSampler = null;
060: previousSampler = null;
061: samplingStarted = false;
062: threadNum = 0;
063: readBuffer = null;
064: }
065:
066: public JMeterVariables getVariables() {
067: return variables;
068: }
069:
070: public byte[] getReadBuffer() {
071: if (readBuffer == null) {
072: readBuffer = new byte[8192];
073: }
074: return readBuffer;
075: }
076:
077: public void setVariables(JMeterVariables vars) {
078: this .variables = vars;
079: }
080:
081: public SampleResult getPreviousResult() {
082: return previousResult;
083: }
084:
085: public void setPreviousResult(SampleResult result) {
086: this .previousResult = result;
087: }
088:
089: public Sampler getCurrentSampler() {
090: return currentSampler;
091: }
092:
093: public void setCurrentSampler(Sampler sampler) {
094: setPreviousSampler(currentSampler);
095: this .currentSampler = sampler;
096: }
097:
098: /**
099: * Returns the previousSampler.
100: *
101: * @return Sampler
102: */
103: public Sampler getPreviousSampler() {
104: return previousSampler;
105: }
106:
107: /**
108: * Sets the previousSampler.
109: *
110: * @param previousSampler
111: * the previousSampler to set
112: */
113: public void setPreviousSampler(Sampler previousSampler) {
114: this .previousSampler = previousSampler;
115: }
116:
117: /**
118: * Returns the threadNum.
119: *
120: * @return int
121: */
122: public int getThreadNum() {
123: return threadNum;
124: }
125:
126: /**
127: * Sets the threadNum.
128: *
129: * @param threadNum
130: * the threadNum to set
131: */
132: public void setThreadNum(int threadNum) {
133: this .threadNum = threadNum;
134: }
135:
136: public JMeterThread getThread() {
137: return this .thread;
138: }
139:
140: public void setThread(JMeterThread thread) {
141: this .thread = thread;
142: }
143:
144: public ThreadGroup getThreadGroup() {
145: return this .threadGroup;
146: }
147:
148: public void setThreadGroup(ThreadGroup threadgrp) {
149: this .threadGroup = threadgrp;
150: }
151:
152: public StandardJMeterEngine getEngine() {
153: return engine;
154: }
155:
156: public void setEngine(StandardJMeterEngine engine) {
157: this .engine = engine;
158: }
159:
160: public boolean isSamplingStarted() {
161: return samplingStarted;
162: }
163:
164: public void setSamplingStarted(boolean b) {
165: samplingStarted = b;
166: }
167: }
|