Class CreditMap

java.lang.Object
org.jgroups.util.CreditMap
Direct Known Subclasses:
NonBlockingCreditMap

public class CreditMap extends Object
Maintains credits for senders, when credits fall below 0, a sender blocks until new credits have been received.
  • Field Details

    • max_credits

      protected final long max_credits
    • credits

      protected final Map<Address,Long> credits
    • min_credits

      protected long min_credits
    • accumulated_credits

      protected long accumulated_credits
    • lock

      protected final Lock lock
    • credits_available

      protected final Condition credits_available
    • num_blockings

      protected int num_blockings
    • avg_block_time

      protected final Average avg_block_time
    • done

      protected boolean done
  • Constructor Details

    • CreditMap

      public CreditMap(long max_credits)
    • CreditMap

      public CreditMap(long max_credits, Lock lock)
  • Method Details

    • getAccumulatedCredits

      public long getAccumulatedCredits()
    • getMinCredits

      public long getMinCredits()
    • getNumBlockings

      public int getNumBlockings()
    • getAverageBlockTime

      public double getAverageBlockTime()
    • keys

      public Set<Address> keys()
    • get

      public Long get(Address member)
    • remove

      public Long remove(Address key)
    • putIfAbsent

      public Long putIfAbsent(Address key)
    • getMembersWithInsufficientCredits

      public List<Address> getMembersWithInsufficientCredits(long credit_needed)
    • getMembersWithCreditsLessThan

      public List<Tuple<Address,Long>> getMembersWithCreditsLessThan(long min_credits)
    • decrement

      public boolean decrement(Message msg, int credits, long timeout)
      Decrements credits bytes from all. Returns true if successful, or false if not. Blocks for timeout ms (if greater than 0).
      Parameters:
      msg - The message to be sent
      credits - Number of bytes to decrement from all members
      timeout - Number of milliseconds to wait until more credits have been received
      Returns:
      True if decrementing credits bytes succeeded, false otherwise
    • replenish

      public void replenish(Address sender, long new_credits)
    • replenishAll

      public void replenishAll()
    • clear

      public void clear()
    • reset

      public CreditMap reset()
      Sets this credit to be done and releases all blocked threads. This is not revertable; a new credit has to be created
    • resetStats

      public void resetStats()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • decrement

      protected boolean decrement(long credits)
    • computeLowestCredit

      protected long computeLowestCredit()
      Needs to be called with lock held
    • computeLowestCreditWithAccumulated

      public long computeLowestCreditWithAccumulated()
    • decrementAndAdd

      protected void decrementAndAdd(Address member, long new_credits)
      Decrements credits bytes from all elements and adds new_credits to member (if non null). The lowest credit needs to be greater than min_credits. Needs to be called with lock held
      Parameters:
      member - The member to which new_credits are added. NOP if null
      new_credits - Number of bytes to add to member. NOP if 0.
    • flushAccumulatedCredits

      protected void flushAccumulatedCredits()