public final class UtlGovernor extends Object
By default this class governs rates by busy spinning to keep cpu caches hot, unless
nv.conservecpu=false
in which case Thread.sleep will be use to
conserve cpu. If setWaitStrategy(WaitStrategy)
is explicitly set
by the creator of the governor then that policy will be used.
This class IS supported for use by end users.
Modifier and Type | Class and Description |
---|---|
static class |
UtlGovernor.WaitStrategy
Enumerates the set of wait strategies used by the
UtlGovernor in
#b |
Constructor and Description |
---|
UtlGovernor(int rate)
Creates a governer that will busy spin on calls to
blockToNext()
if the number of prior calls has exceeded the provided rate since the
creation of the UtlGoverner. |
Modifier and Type | Method and Description |
---|---|
void |
blockToNext()
Blocks until returning won't exceed this governer's target rate.
|
UtlGovernor.WaitStrategy |
getWaitStrategy()
Gets the
UtlGovernor.WaitStrategy used by the rate governor. |
static void |
run(int iterations,
int rate,
Runnable command)
Runs the provided
Runnable command for a given number of iterations, attempting
to operate at the overall given rate. |
void |
setWaitStrategy(UtlGovernor.WaitStrategy waitStrategy)
Sets the wait strategy used to wait for the next operation.
|
public UtlGovernor(int rate)
blockToNext()
if the number of prior calls has exceeded the provided rate since the
creation of the UtlGoverner.rate
- The target rate beyond which call to blockToNext()
will block.public final UtlGovernor.WaitStrategy getWaitStrategy()
UtlGovernor.WaitStrategy
used by the rate governor.public final void setWaitStrategy(UtlGovernor.WaitStrategy waitStrategy)
waitStrategy
- The wait strategy.public final void blockToNext()
public static final void run(int iterations, int rate, Runnable command)
Runnable
command for a given number of iterations, attempting
to operate at the overall given rate.iterations
- The number of interations to execute.rate
- The target rate at which to run the command.command
- The command to run on each iteration.Copyright © 2019 Neeve Research, LLC. All Rights Reserved.