01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.functions;
20:
21: import java.io.Serializable;
22: import java.util.Collection;
23: import java.util.LinkedList;
24: import java.util.List;
25:
26: import org.apache.jmeter.samplers.SampleResult;
27: import org.apache.jmeter.samplers.Sampler;
28:
29: /**
30: * TODO: should this extend AbstractFunction?
31: */
32: public class ThreadNumber implements Function, Serializable {
33:
34: private static final String KEY = "__threadNum"; //$NON-NLS-1$
35:
36: private static final List desc = new LinkedList();
37:
38: /*
39: * (non-Javadoc)
40: *
41: * @see org.apache.jmeter.functions.Function#execute(SampleResult, Sampler)
42: */
43: public String execute(SampleResult previousResult,
44: Sampler currentSampler) throws InvalidVariableException {
45: return Thread.currentThread().getName().substring(
46: Thread.currentThread().getName().lastIndexOf("-") + 1); //$NON-NLS-1$
47: }
48:
49: /*
50: * (non-Javadoc)
51: *
52: * @see org.apache.jmeter.functions.Function#setParameters(Collection)
53: */
54: public void setParameters(Collection parameters)
55: throws InvalidVariableException {
56: }
57:
58: /*
59: * (non-Javadoc)
60: *
61: * @see org.apache.jmeter.functions.Function#getReferenceKey()
62: */
63: public String getReferenceKey() {
64: return KEY;
65: }
66:
67: /*
68: * (non-Javadoc)
69: *
70: * @see org.apache.jmeter.functions.Function#getArgumentDesc()
71: */
72: public List getArgumentDesc() {
73: return desc;
74: }
75: }
|