Class DataPool<T>
- java.lang.Object
-
- com.xceptance.xlt.api.data.DataPool<T>
-
public class DataPool<T> extends java.lang.Object
This is a utility class that stores a limited amount of data objects and provides a way to reuse it later.
-
-
Method Summary
All Methods Instance Methods Concrete Methods 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()
Clear the contentT
getDataElement()
Get a data row exclusively, return null otherwise.int
getExpireRate()
int
getMax()
Returns the current maximum permitted pool size.int
getSize()
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.
-
-
-
Constructor Detail
-
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 zeroexpirationRate
- 0 means nothing will expire, 100 means all will expire, rest is a rate in percent
-
DataPool
public DataPool()
Constructor.
-
-
Method Detail
-
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 storerate
- 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
-
-