Package com.unboundid.util
Class RateAdjustor
java.lang.Object
java.lang.Thread
com.unboundid.util.RateAdjustor
- All Implemented Interfaces:
Runnable
This class allows a FixedRateBarrier to change dynamically. The rate changes
are governed by lines read from a
The following simple example will run at a target rate of 1000 per second for one minute, and then 10000 per second for 10 seconds.
The following example has a default duration of one minute, and will repeat the two intervals until this RateAdjustor is shut down. The first interval is run for the default of 1 minute at two and half times the base rate, and then run for 10 seconds at 10000 per second.
The header can contain the following options:
Reader (typically backed by a
file). The input starts with a header that provides some global options and
then has a list of lines, where each line contains a single rate per second,
a comma, and a duration to maintain that rate. Rates are specified as an
absolute rate per second or as a rate relative to the base rate per second.
The duration is an integer followed by a time unit (ms=milliseconds,
s=seconds, m=minutes, h=hours, and d=days).
The following simple example will run at a target rate of 1000 per second for one minute, and then 10000 per second for 10 seconds.
# format=rate-duration 1000,1m 10000,10s
The following example has a default duration of one minute, and will repeat the two intervals until this RateAdjustor is shut down. The first interval is run for the default of 1 minute at two and half times the base rate, and then run for 10 seconds at 10000 per second.
# format=rate-duration # default-duration=1m # repeat=true 2.5X 10000,10sA
RateAdjustor is a daemon thread. It is necessary to call the
start() method to start the thread and begin the rate changes.
Once this finished processing the rates, the thread will complete.
It can be stopped prematurely by calling shutDown().
The header can contain the following options:
format(required): This must currently have the valuerate-duration.default-duration(optional): This can specify a default duration for intervals that do not include a duration. The format is an integer followed by a time unit as described above.repeat(optional): If this has a value oftrue, then the rates in the input will be repeated untilshutDown()is called.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charThis starts a comment in the input.static final StringThe header key that represents the default duration.static final StringThe text that must appear on a line by itself in order to denote that the end of the file header has been reached.static final StringThe header key that represents the format of the file.static final StringThe value of the format key that represents a list of rates and durations within the input file.A list of all formats that we support.A list of all header keys that we support.static final StringThe header key that represents whether the input should be repeated.Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionRateAdjustor(FixedRateBarrier barrier, long baseRatePerSecond, Reader rates) Constructs a new RateAdjustor with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetGenerateSampleVariableRateFileDescription(String dataFileArgName) Retrieves a string that may be used as the description of the argument that generates a sample variable rate data file that serves as documentation of the variable rate data format.static StringgetVariableRateDataArgumentDescription(String genArgName) Retrieves a string that may be used as the description of the argument that specifies the path to a variable rate data file for use in conjunction with this rate adjustor.static RateAdjustornewInstance(FixedRateBarrier barrier, Integer baseRatePerSecond, File rates) Returns a new RateAdjustor with the specified parameters.voidrun()Adjusts the rate in FixedRateBarrier as described in the rates.voidshutDown()Signals this to shut down.voidstart()Starts this thread and waits for the initial rate to be set.static voidWrites a sample variable write data file to the specified location.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
COMMENT_START
This starts a comment in the input.- See Also:
-
END_HEADER_TEXT
The text that must appear on a line by itself in order to denote that the end of the file header has been reached.- See Also:
-
DEFAULT_DURATION_KEY
The header key that represents the default duration.- See Also:
-
FORMAT_KEY
The header key that represents the format of the file.- See Also:
-
FORMAT_VALUE_RATE_DURATION
The value of the format key that represents a list of rates and durations within the input file.- See Also:
-
FORMATS
A list of all formats that we support. -
REPEAT_KEY
The header key that represents whether the input should be repeated.- See Also:
-
KEYS
A list of all header keys that we support.
-
-
Constructor Details
-
RateAdjustor
public RateAdjustor(@NotNull FixedRateBarrier barrier, long baseRatePerSecond, @NotNull Reader rates) throws IOException, IllegalArgumentException Constructs a new RateAdjustor with the specified parameters. See the class-level javadoc for more information.- Parameters:
barrier- The barrier to update based on the specified rates.baseRatePerSecond- The baseline rate per second, or 0 if none was specified.rates- A list of rates and durations as described in the class-level javadoc. The reader will always be closed before this method returns.- Throws:
IOException- If there is a problem reading from the rates Reader.IllegalArgumentException- If there is a problem with the rates input.
-
-
Method Details
-
newInstance
@NotNull public static RateAdjustor newInstance(@NotNull FixedRateBarrier barrier, @Nullable Integer baseRatePerSecond, @NotNull File rates) throws IOException, IllegalArgumentException Returns a new RateAdjustor with the specified parameters. See the class-level javadoc for more information.- Parameters:
barrier- The barrier to update based on the specified rates.baseRatePerSecond- The baseline rate per second, ornullif none was specified.rates- A file containing a list of rates and durations as described in the class-level javadoc.- Returns:
- A new RateAdjustor constructed from the specified parameters.
- Throws:
IOException- If there is a problem reading from the rates Reader.IllegalArgumentException- If there is a problem with the rates input.
-
getVariableRateDataArgumentDescription
Retrieves a string that may be used as the description of the argument that specifies the path to a variable rate data file for use in conjunction with this rate adjustor.- Parameters:
genArgName- The name of the argument that may be used to generate a sample variable rate data file.- Returns:
- A string that may be used as the description of the argument that specifies the path to a variable rate data file for use in conjunction with this rate adjustor.
-
getGenerateSampleVariableRateFileDescription
@Nullable public static String getGenerateSampleVariableRateFileDescription(@NotNull String dataFileArgName) Retrieves a string that may be used as the description of the argument that generates a sample variable rate data file that serves as documentation of the variable rate data format.- Parameters:
dataFileArgName- The name of the argument that specifies the path to a file- Returns:
- A string that may be used as the description of the argument that generates a sample variable rate data file that serves as documentation of the variable rate data format.
-
writeSampleVariableRateFile
Writes a sample variable write data file to the specified location.- Parameters:
f- The path to the file to be written.- Throws:
IOException- If a problem is encountered while writing to the specified file.
-
start
Starts this thread and waits for the initial rate to be set. -
run
Adjusts the rate in FixedRateBarrier as described in the rates. -
shutDown
Signals this to shut down.
-