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_queue
protected static java.util.function.Consumer<Message>
NO_OP_SEND_FUNCTION
protected java.util.concurrent.atomic.LongAdder
num_queued
protected boolean
queuing
protected 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 boolean
addToQueue(Message msg, int length)
boolean
decrementIfEnoughCredits(Message msg, int credits, long timeout)
Decrements the sender's credits by the size of the message.int
getEnqueuedMessages()
int
getQueuedMessages()
int
getQueuedMessageSize()
void
increment(long credits, long max_credits)
boolean
isQueuing()
Credit
reset()
Sets this credit to be done and releases all blocked threads.void
resetStats()
java.lang.String
toString()
-
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:
resetStats
in classCredit
-
decrementIfEnoughCredits
public boolean decrementIfEnoughCredits(Message msg, int credits, long timeout)
Decrements the sender's credits by the size of the message.- Overrides:
decrementIfEnoughCredits
in 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:Credit
Sets 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)
-
-