org.jgroups.util

## Class CreditMap

- java.lang.Object
- - org.jgroups.util.CreditMap

    public class CreditMap
    extends java.lang.Object

Maintains credits for senders, when credits fall below 0, a sender blocks until new credits have been received.

Author:
  Bela Ban

### Field Summary

Fields
`protected long` `accumulated_credits`
`protected java.util.Map<Address,java.lang.Long>` `credits`
`protected java.util.concurrent.locks.Condition` `credits_available`
`protected java.util.concurrent.locks.Lock` `lock`
`protected long` `max_credits`
`protected long` `min_credits`
`protected int` `num_blockings`
`protected long` `total_block_time`

### Constructor Summary

Constructors
Constructor and Description
`CreditMap(long max_credits)`

### Method Summary

Methods
`void` `clear()`
`protected long` `computeLowestCredit()` Needs to be called with lock held
`long` `computeLowestCreditWithAccumulated()`
`protected boolean` `decrement(long credits)`
`boolean` `decrement(long credits, long timeout)` Decrements credits bytes from all.
`protected void` `decrementAndAdd(Address member, long new_credits)` Decrements credits bytes from all elements and add new_credits to member (if non null).
`protected void` `flushAccumulatedCredits()`
`java.lang.Long` `get(Address member)`
`long` `getAccumulatedCredits()`
`java.util.List<Tuple<Address,java.lang.Long>>` `getMembersWithCreditsLessThan(long min_credits)`
`java.util.List<Address>` `getMembersWithInsufficientCredits(long credit_needed)`
`long` `getMinCredits()`
`int` `getNumBlockings()`
`long` `getTotalBlockTime()`
`java.util.Set<Address>` `keys()`
`java.lang.Long` `putIfAbsent(Address key)`
`java.lang.Long` `remove(Address key)`
`void` `replenish(Address sender, long new_credits)`
`void` `replenishAll()`
`java.lang.String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### max_credits

    protected final long max_credits

#### credits

    protected final java.util.Map<Address,java.lang.Long> credits

#### min_credits

    protected long min_credits

#### accumulated_credits

    protected long accumulated_credits

#### lock

    protected final java.util.concurrent.locks.Lock lock

#### credits_available

    protected final java.util.concurrent.locks.Condition credits_available

#### num_blockings

    protected int num_blockings

#### total_block_time

    protected long total_block_time

### Constructor Detail

#### CreditMap

    public CreditMap(long max_credits)

### Method Detail

#### getAccumulatedCredits

    public long getAccumulatedCredits()

#### getMinCredits

    public long getMinCredits()

#### getNumBlockings

    public int getNumBlockings()

#### getTotalBlockTime

    public long getTotalBlockTime()

#### keys

    public java.util.Set<Address> keys()

#### get

    public java.lang.Long get(Address member)

#### remove

    public java.lang.Long remove(Address key)

#### putIfAbsent

    public java.lang.Long putIfAbsent(Address key)

#### getMembersWithInsufficientCredits

    public java.util.List<Address> getMembersWithInsufficientCredits(long credit_needed)

#### getMembersWithCreditsLessThan

    public java.util.List<Tuple<Address,java.lang.Long>> getMembersWithCreditsLessThan(long min_credits)

#### decrement

    public boolean decrement(long 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:
  `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()

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.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 add 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()