Save This Page
Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.functions » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *   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.util.Collection;
   22   import java.util.LinkedList;
   23   import java.util.List;
   24   
   25   import org.apache.jmeter.engine.util.CompoundVariable;
   26   import org.apache.jmeter.samplers.SampleResult;
   27   import org.apache.jmeter.samplers.Sampler;
   28   import org.apache.jmeter.threads.JMeterVariables;
   29   import org.apache.jmeter.util.JMeterUtils;
   30   
   31   public class MachineName extends AbstractFunction {
   32   
   33       private static final List desc = new LinkedList();
   34   
   35       private static final String KEY = "__machineName"; //$NON-NLS-1$
   36   
   37       static {
   38           // desc.add("Use fully qualified host name: TRUE/FALSE (Default FALSE)");
   39           desc.add(JMeterUtils.getResString("function_name_paropt")); //$NON-NLS-1$
   40       }
   41   
   42       private Object[] values;
   43   
   44       public MachineName() {
   45       }
   46   
   47       public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
   48               throws InvalidVariableException {
   49   
   50           /*
   51            * boolean fullHostName = false; if (((CompoundFunction) values[0])
   52            * .execute() .toLowerCase() .equals("true")) { fullHostName = true; }
   53            */
   54   
   55           String machineName = JMeterUtils.getLocalHostName();
   56           
   57           if (values.length >= 1){// we have a variable name
   58               JMeterVariables vars = getVariables();
   59               if (vars != null) {// May be null if function is used on TestPlan
   60                   String varName = ((CompoundVariable) values[0]).execute().trim();
   61                   if (varName.length() > 0) {
   62                       vars.put(varName, machineName);
   63                   }
   64               }
   65           }
   66           return machineName;
   67   
   68       }
   69   
   70       public synchronized void setParameters(Collection parameters) throws InvalidVariableException {
   71           checkParameterCount(parameters, 0, 1);
   72           values = parameters.toArray();
   73       }
   74   
   75       public String getReferenceKey() {
   76           return KEY;
   77       }
   78   
   79       public List getArgumentDesc() {
   80           return desc;
   81       }
   82   }

Save This Page
Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.functions » [javadoc | source]