Package org.jgroups.util
Class NonBlockingCredit
- java.lang.Object
-
- org.jgroups.util.Credit
-
- org.jgroups.util.NonBlockingCredit
-
public class NonBlockingCredit extends Credit
Non-blocking credit for a unicast destination.
Instead of blocking when insufficient credits are available for sending a message, this class queues the message and sends it at a later time when enough credits have been received to send it.
JIRA: https://issues.jboss.org/browse/JGRP-2172- Since:
- 4.0.4
- Author:
- Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected SizeBoundedQueue<Message>msg_queueprotected static java.util.function.Consumer<Message>NO_OP_SEND_FUNCTIONprotected java.util.concurrent.atomic.LongAddernum_queuedprotected booleanqueuingprotected java.util.function.Consumer<Message>send_function-
Fields inherited from class org.jgroups.util.Credit
avg_blockings, credits_available, credits_left, done, last_credit_request, lock, num_blockings
-
-
Constructor Summary
Constructors Constructor Description NonBlockingCredit(long credits, int max_size, java.util.concurrent.locks.Lock lock)NonBlockingCredit(long credits, int max_size, java.util.concurrent.locks.Lock lock, java.util.function.Consumer<Message> send_function)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanaddToQueue(Message msg, int length)booleandecrementIfEnoughCredits(Message msg, int credits, long timeout)Decrements the sender's credits by the size of the message.intgetEnqueuedMessages()intgetQueuedMessages()intgetQueuedMessageSize()voidincrement(long credits, long max_credits)booleanisQueuing()Creditreset()Sets this credit to be done and releases all blocked threads.voidresetStats()java.lang.StringtoString()-
Methods inherited from class org.jgroups.util.Credit
decrement, decrementAndGet, get, getAverageBlockTime, getNumBlockings, needToSendCreditRequest
-
-
-
-
Field Detail
-
msg_queue
protected final SizeBoundedQueue<Message> msg_queue
-
queuing
protected boolean queuing
-
send_function
protected final java.util.function.Consumer<Message> send_function
-
NO_OP_SEND_FUNCTION
protected static final java.util.function.Consumer<Message> NO_OP_SEND_FUNCTION
-
num_queued
protected final java.util.concurrent.atomic.LongAdder num_queued
-
-
Constructor Detail
-
NonBlockingCredit
public NonBlockingCredit(long credits, int max_size, java.util.concurrent.locks.Lock lock)
-
NonBlockingCredit
public NonBlockingCredit(long credits, int max_size, java.util.concurrent.locks.Lock lock, java.util.function.Consumer<Message> send_function)
-
-
Method Detail
-
isQueuing
public boolean isQueuing()
-
getQueuedMessages
public int getQueuedMessages()
-
getQueuedMessageSize
public int getQueuedMessageSize()
-
getEnqueuedMessages
public int getEnqueuedMessages()
-
resetStats
public void resetStats()
- Overrides:
resetStatsin classCredit
-
decrementIfEnoughCredits
public boolean decrementIfEnoughCredits(Message msg, int credits, long timeout)
Decrements the sender's credits by the size of the message.- Overrides:
decrementIfEnoughCreditsin classCredit- Parameters:
msg- The messagecredits- The number of bytes to decrement the credits. IsMessage.length().timeout- Ignored- Returns:
- True if the message was sent, false if it was queued
-
increment
public void increment(long credits, long max_credits)
-
reset
public Credit reset()
Description copied from class:CreditSets this credit to be done and releases all blocked threads. This is not revertable; a new credit has to be created
-
addToQueue
protected boolean addToQueue(Message msg, int length)
-
-