com.neeve.util
Class UtlGovernor

java.lang.Object
  extended by com.neeve.util.UtlGovernor

public final class UtlGovernor
extends Object

A convenience class for executing a number of operations at a maximum target rate.

This class IS supported for use by end users.


Constructor Summary
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.
 
Method Summary
 void blockToNext()
          Blocks until returning won't exceed this governer's target rate.
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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtlGovernor

public 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.

Parameters:
rate - The target rate beyond which call to blockToNext() will block.
Method Detail

blockToNext

public final void blockToNext()
Blocks until returning won't exceed this governer's target rate.


run

public static final 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.

Parameters:
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 © 2016 Neeve Research, LLC. All Rights Reserved.