org.apache.jmeter.functions

## Class AbstractFunction

- java.lang.Object
- - org.apache.jmeter.functions.AbstractFunction

- All Implemented Interfaces:
    Function
  Direct Known Subclasses:
    BeanShell, ChangeCase, CharFunction, CSVRead, DateTimeConvertFunction, DigestEncodeFunction, EscapeHtml, EscapeOroRegexpChars, EscapeXml, EvalFunction, EvalVarFunction, FileToString, Groovy, IntSum, IsPropDefined, IsVarDefined, IterationCounter, JavaScript, Jexl2Function, Jexl3Function, LogFunction, LogFunction2, LongSum, MachineIP, MachineName, Property, Property2, Random, RandomDate, RandomFromMultipleVars, RandomString, RegexFunction, SamplerName, SetProperty, SplitFunction, StringFromFile, TestPlanName, ThreadGroupName, ThreadNumber, TimeFunction, TimeShift, UnEscape, UnEscapeHtml, UrlDecode, UrlEncode, Uuid, Variable, XPath

      public abstract class AbstractFunction
      extends java.lang.Object
      implements Function

  Provides common methods for all functions

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractFunction()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addVariableValue(java.lang.String value, CompoundVariable[] values, int index)` Utility method to store value in a variable
    `protected void` | `checkMinParameterCount(java.util.Collection<CompoundVariable> parameters, int minimum)` Utility method to check parameter counts.
    `protected void` | `checkParameterCount(java.util.Collection<CompoundVariable> parameters, int count)` Utility method to check parameter counts.
    `protected void` | `checkParameterCount(java.util.Collection<CompoundVariable> parameters, int min, int max)` Utility method to check parameter counts.
    `java.lang.String` | `execute()`
    `abstract java.lang.String` | `execute(SampleResult previousResult, Sampler currentSampler)` N.B. execute() should be synchronized if function is operating with non-thread-safe objects (e.g. operates with files).
    `abstract java.lang.String` | `getReferenceKey()` Return the name of your function.
    `protected JMeterVariables` | `getVariables()` Gives access to the JMeter variables for the current thread.
    `abstract void` | `setParameters(java.util.Collection<CompoundVariable> parameters)` Note: This is always called even if no parameters are provided (versions of JMeter after 2.3.1)

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.jmeter.functions.Function

      `getArgumentDesc`

- - ### Constructor Detail

    - #### AbstractFunction

          public AbstractFunction()

  - ### Method Detail

    - #### execute

          public abstract java.lang.String execute(SampleResult previousResult,
                                                   Sampler currentSampler)
                                            throws InvalidVariableException

      N.B. execute() should be synchronized if function is operating with non-thread-safe objects (e.g. operates with files).

      JMeter ensures setParameters() happens-before execute(): setParameters is executed in main thread, and worker threads are started after that.
      Specified by:
        `execute` in interface `Function`
      Parameters:
        `previousResult` - The previous `SampleResult`
        `currentSampler` - The current `Sampler`
      Returns:
        The replacement value, which was generated by the function
      Throws:
        `InvalidVariableException` - - when the variables for the function call can't be evaluated
      See Also:
        `Function.execute(SampleResult, Sampler)`

    - #### execute

          public java.lang.String execute()
                                   throws InvalidVariableException

      Throws:
        `InvalidVariableException`

    - #### setParameters

          public abstract void setParameters(java.util.Collection<CompoundVariable> parameters)
                                      throws InvalidVariableException

      Note: This is always called even if no parameters are provided (versions of JMeter after 2.3.1)
      Specified by:
        `setParameters` in interface `Function`
      Parameters:
        `parameters` - The parameters for the function call
      Throws:
        `InvalidVariableException` - - when the variables for the function call can't be evaluated
      See Also:
        `Function.setParameters(Collection)`

    - #### getReferenceKey

          public abstract java.lang.String getReferenceKey()

      Description copied from interface: `Function`
      Return the name of your function. Convention is to prepend "__" to the name (ie "__regexFunction")
      Specified by:
        `getReferenceKey` in interface `Function`
      Returns:
        The name of the function
      See Also:
        `Function.getReferenceKey()`

    - #### getVariables

          protected JMeterVariables getVariables()

      Gives access to the JMeter variables for the current thread.
      Returns:
        a pointer to the JMeter variables.

    - #### checkParameterCount

          protected void checkParameterCount(java.util.Collection<CompoundVariable> parameters,
                                             int min,
                                             int max)
                                      throws InvalidVariableException

      Utility method to check parameter counts.
      Parameters:
        `parameters` - collection of parameters
        `min` - minimum number of parameters allowed
        `max` - maximum number of parameters allowed
      Throws:
        `InvalidVariableException` - if the number of parameters is incorrect

    - #### checkParameterCount

          protected void checkParameterCount(java.util.Collection<CompoundVariable> parameters,
                                             int count)
                                      throws InvalidVariableException

      Utility method to check parameter counts.
      Parameters:
        `parameters` - collection of parameters
        `count` - number of parameters expected
      Throws:
        `InvalidVariableException` - if the number of parameters is incorrect

    - #### checkMinParameterCount

          protected void checkMinParameterCount(java.util.Collection<CompoundVariable> parameters,
                                                int minimum)
                                         throws InvalidVariableException

      Utility method to check parameter counts.
      Parameters:
        `parameters` - collection of parameters
        `minimum` - number of parameters expected
      Throws:
        `InvalidVariableException` - if the number of parameters is incorrect

    - #### addVariableValue

          protected final void addVariableValue(java.lang.String value,
                                                CompoundVariable[] values,
                                                int index)

      Utility method to store value in a variable
      Parameters:
        `value` - value of variable to update
        `values` - array of `CompoundVariable` from which variable name will be extracted
        `index` - index of variable in values array

Copyright © 1998-2019 Apache Software Foundation. All Rights Reserved.