Class DataPool<T>

java.lang.Object
com.xceptance.xlt.api.data.DataPool<T>

public class DataPool<T> extends Object
This is a utility class that stores a limited amount of data objects and provides a way to reuse it later.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
    DataPool(int max, int expirationRate)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(T element)
    Store an element with a random expiration number between 0 and 99, that will be compared to the set expiration number.
    boolean
    add(T element, int rate)
    Stores a data element if the max size of the pool is not yet reached.
    void
    Clear the content
    Get a data row exclusively, return null otherwise.
    int
     
    int
    Returns the current maximum permitted pool size.
    int
    Returns the current size of the data pool.
    void
    setExpireRate(int rate)
    Set a new expiration rate.
    void
    setMax(int max)
    Sets the new max, will shrink the data pool if needed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DataPool

      public DataPool(int max, int expirationRate)
      Constructor
      Parameters:
      max - amount of data to store, will be set to 1 if argument is equal to or less than zero
      expirationRate - 0 means nothing will expire, 100 means all will expire, rest is a rate in percent
    • DataPool

      public DataPool()
      Constructor.
  • Method Details

    • getDataElement

      public T getDataElement()

      Get a data row exclusively, return null otherwise. The element will be removed from the data storage and cannot be accessed by others. To reuse, it has to be added again.

      The first element of the data pool will be returned.

      Returns:
      a data row or null, if none available
    • add

      public boolean add(T element, int rate)

      Stores a data element if the max size of the pool is not yet reached. If the max size is reached, an expiration limit determines, whether or not the data is kept or added.

      If the pool expiration rate is 100, elements will never be added. If the pool expiration rate is 0, elements will always be added. If the provided expiration rate is bigger than the expiration rate of the pool, the element will be added, otherwise it will not.

      So if the set expiration rate of the pool is 60 (like 60%) and the provided rate is 61, the data will be added, if the rate is 60 or below that, the data will not be added.

      If the data pool is full, the first element is removed before new data is added.

      Parameters:
      element - the data to store
      rate - the rate to use (will be compared to the set expiration rate)
      Returns:
      true if data was stored, false otherwise
    • add

      public boolean add(T element)
      Store an element with a random expiration number between 0 and 99, that will be compared to the set expiration number.
      Parameters:
      element - a data element to store
      Returns:
      true if element was stored, false otherwise
    • getExpireRate

      public int getExpireRate()
      Returns:
      Returns the expireRate.
    • setExpireRate

      public void setExpireRate(int rate)
      Set a new expiration rate. The current content is not affected.
      Parameters:
      rate - the new rate to use
    • getMax

      public int getMax()
      Returns the current maximum permitted pool size.
      Returns:
      the max number of elements to be stored.
    • getSize

      public int getSize()
      Returns the current size of the data pool.
      Returns:
      the current size of the data pool
    • setMax

      public void setMax(int max)
      Sets the new max, will shrink the data pool if needed. The elements will be removed according to FIFO.
      Parameters:
      max - the new maximum size of the pool, will be set to 1 if argument is equal to or less than zero
    • clear

      public void clear()
      Clear the content