Class ThroughputControl

java.lang.Object
org.jpos.util.ThroughputControl

public class ThroughputControl extends Object
ThroughputControl limits the throughput of a process to a maximum number of transactions in a given period of time. As an example, the following code will cap the transaction count at 15 every second (a.k.a. 15 TPS).

 ThroughputControl throughput = new ThroughputControl(15, 1000);

 while (isConditionTrue()) {
     throughput.control();
     // Do stuff.
 }

  • Constructor Details

    • ThroughputControl

      public ThroughputControl(int maxTransactions, int periodInMillis)
      Parameters:
      maxTransactions - Transaction count threshold.
      periodInMillis - Time window, expressed in milliseconds.
    • ThroughputControl

      public ThroughputControl(int[] maxTransactions, int[] periodInMillis)
      Parameters:
      maxTransactions - An array with transaction count thresholds.
      periodInMillis - An array of time windows, expressed in milliseconds.
  • Method Details

    • control

      public long control()
      This method should be called on every transaction. It will pause the thread for a while when the threshold is reached in order to control the process throughput.
      Returns:
      Returns sleep time in milliseconds when threshold is reached. Otherwise, zero.
    • toString

      public String toString()
      Overrides:
      toString in class Object