Package org.jgroups.protocols
Class BaseBundler
- java.lang.Object
-
- org.jgroups.protocols.BaseBundler
-
- All Implemented Interfaces:
Bundler
- Direct Known Subclasses:
BatchBundler,NoBundler,PerDestinationBundler,RemoveQueueBundler,RingBufferBundler,RingBufferBundlerLockless,RingBufferBundlerLockless2,SenderSendsBundler,TransferQueueBundler
public abstract class BaseBundler extends java.lang.Object implements Bundler
Implements storing of messages in a hashmap and sending of single messages and message batches. Most bundler implementations will want to extend this class- Since:
- 4.0
- Author:
- Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected AverageMinMaxavg_fill_countprotected AverageMinMaxavg_remove_queue_sizeprotected AverageMinMaxavg_send_timeprotected intcapacityprotected longcountprotected booleandrop_when_fullDeprecated, for removal: This API element is subject to removal in a future version.protected static java.lang.StringFMTprotected java.util.function.Function<Address,java.util.List<Message>>FUNCprotected java.util.concurrent.locks.ReentrantLocklockprotected Loglogprotected intmax_sizeMaximum number of bytes for messages to be queued until they are sent.protected MessageProcessingPolicymsg_processing_policyprotected MsgStatsmsg_statsprotected java.util.Map<Address,java.util.List<Message>>msgsKeys are destinations, values are lists of Messagesprotected java.util.concurrent.atomic.LongAddernum_batches_sentprotected java.util.concurrent.atomic.LongAddernum_drops_on_full_queueprotected java.util.concurrent.atomic.LongAddernum_sends_because_full_queueprotected java.util.concurrent.atomic.LongAddernum_sends_because_no_msgsprotected java.util.concurrent.atomic.LongAddernum_single_msgs_sentprotected ByteArrayDataOutputStreamoutputprotected intremove_queue_capacityprotected SuppressLog<Address>suppress_logprotected longsuppress_log_timeoutprotected java.util.concurrent.atomic.LongAddertotal_msgs_sentprotected TPtransportprotected booleanuse_ringbufferprotected booleanuse_single_sender_thread
-
Constructor Summary
Constructors Constructor Description BaseBundler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddMessage(Message msg, int size)doubleavgBatchSize()booleandropWhenFull()BundlerdropWhenFull(boolean ignored)intgetCapacity()If the bundler implementation supports a capacity (e.g.intgetMaxSize()Maximum number of bytes for messages to be queued until they are sentintgetQueueSize()If the bundler has a queue and it should be managed by a queuing discipline (like Random Early Detection), then return the number of elements in the queue, else -1.voidinit(TP transport)Called after creation of the bundlerprotected voidloopback(Address dest, Address sender, java.lang.Iterable<Message> list, int size)protected voidloopback(Address dest, Address sender, Message[] list, int len)protected voidloopbackUnlessDontLoopbackIsSet(Message msg)java.lang.StringprintBuffers()intremoveQueueCapacity()BundlerremoveQueueCapacity(int c)voidresetStats()voidsend(Message msg)protected voidsendBundledMessages()Sends all messages in the map.protected voidsendMessageList(Address dest, Address src, java.util.List<Message> list, ByteArrayDataOutputStream out)protected voidsendMessageListArray(Address dest, Address src, Message[] list, int len, ByteArrayDataOutputStream out)protected voidsendMultiple(Address dst, Address sender, java.util.List<Message> list, ByteArrayDataOutputStream out)protected voidsendMultiple(Address dst, Address sender, Message[] list, int len, ByteArrayDataOutputStream out)protected voidsendSingle(Address dst, Message msg, ByteArrayDataOutputStream out)protected voidsendSingleMessage(Address dest, Message msg, ByteArrayDataOutputStream out)BundlersetCapacity(int c)BundlersetMaxSize(int s)intsize()Returns the total number of messages in the hashmapvoidstart()Called afterBundler.init(TP)voidstop()booleanuseRingBuffer()BundleruseRingBuffer(boolean u)booleanuseSingleSenderThread()BundleruseSingleSenderThread(boolean u)voidviewChange(View view)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jgroups.protocols.Bundler
destroy, renameThread
-
-
-
-
Field Detail
-
msgs
protected final java.util.Map<Address,java.util.List<Message>> msgs
Keys are destinations, values are lists of Messages
-
transport
protected TP transport
-
msg_processing_policy
protected MessageProcessingPolicy msg_processing_policy
-
lock
protected final java.util.concurrent.locks.ReentrantLock lock
-
count
protected long count
-
output
protected ByteArrayDataOutputStream output
-
msg_stats
protected MsgStats msg_stats
-
log
protected Log log
-
suppress_log
protected SuppressLog<Address> suppress_log
-
FMT
protected static final java.lang.String FMT
- See Also:
- Constant Field Values
-
max_size
protected int max_size
Maximum number of bytes for messages to be queued until they are sent. This value needs to be smaller than the largest datagram packet size in case of UDP
-
capacity
protected int capacity
-
remove_queue_capacity
protected int remove_queue_capacity
-
use_ringbuffer
protected boolean use_ringbuffer
-
use_single_sender_thread
protected boolean use_single_sender_thread
-
drop_when_full
@Deprecated(since="5.5.0", forRemoval=true) protected boolean drop_when_fullDeprecated, for removal: This API element is subject to removal in a future version.
-
suppress_log_timeout
protected long suppress_log_timeout
-
avg_fill_count
protected final AverageMinMax avg_fill_count
-
avg_remove_queue_size
protected final AverageMinMax avg_remove_queue_size
-
avg_send_time
protected final AverageMinMax avg_send_time
-
total_msgs_sent
protected final java.util.concurrent.atomic.LongAdder total_msgs_sent
-
num_single_msgs_sent
protected final java.util.concurrent.atomic.LongAdder num_single_msgs_sent
-
num_batches_sent
protected final java.util.concurrent.atomic.LongAdder num_batches_sent
-
num_sends_because_full_queue
protected final java.util.concurrent.atomic.LongAdder num_sends_because_full_queue
-
num_sends_because_no_msgs
protected final java.util.concurrent.atomic.LongAdder num_sends_because_no_msgs
-
num_drops_on_full_queue
protected final java.util.concurrent.atomic.LongAdder num_drops_on_full_queue
-
-
Method Detail
-
printBuffers
public java.lang.String printBuffers()
-
getCapacity
public int getCapacity()
Description copied from interface:BundlerIf the bundler implementation supports a capacity (e.g.RingBufferBundler, then return it, else return -1- Specified by:
getCapacityin interfaceBundler
-
setCapacity
public Bundler setCapacity(int c)
-
removeQueueCapacity
public int removeQueueCapacity()
-
removeQueueCapacity
public Bundler removeQueueCapacity(int c)
-
getMaxSize
public int getMaxSize()
Description copied from interface:BundlerMaximum number of bytes for messages to be queued until they are sent- Specified by:
getMaxSizein interfaceBundler
-
setMaxSize
public Bundler setMaxSize(int s)
- Specified by:
setMaxSizein interfaceBundler
-
dropWhenFull
public boolean dropWhenFull()
-
dropWhenFull
public Bundler dropWhenFull(boolean ignored)
-
useSingleSenderThread
public boolean useSingleSenderThread()
-
useSingleSenderThread
public Bundler useSingleSenderThread(boolean u)
-
useRingBuffer
public boolean useRingBuffer()
-
useRingBuffer
public Bundler useRingBuffer(boolean u)
-
avgBatchSize
public double avgBatchSize()
-
init
public void init(TP transport)
Description copied from interface:BundlerCalled after creation of the bundler
-
resetStats
public void resetStats()
- Specified by:
resetStatsin interfaceBundler
-
start
public void start()
Description copied from interface:BundlerCalled afterBundler.init(TP)
-
send
public void send(Message msg) throws java.lang.Exception
-
viewChange
public void viewChange(View view)
- Specified by:
viewChangein interfaceBundler
-
size
public int size()
Returns the total number of messages in the hashmap
-
getQueueSize
public int getQueueSize()
Description copied from interface:BundlerIf the bundler has a queue and it should be managed by a queuing discipline (like Random Early Detection), then return the number of elements in the queue, else -1. In the latter case, the queue won't be managed.
This method needs to be fast as it might get called on every message to be sent.- Specified by:
getQueueSizein interfaceBundler
-
sendBundledMessages
protected void sendBundledMessages()
Sends all messages in the map. Messages for the same destination are bundled into a message list. The map will be cleared when done.
-
sendSingle
protected void sendSingle(Address dst, Message msg, ByteArrayDataOutputStream out) throws java.lang.Exception
- Throws:
java.lang.Exception
-
sendMultiple
protected void sendMultiple(Address dst, Address sender, java.util.List<Message> list, ByteArrayDataOutputStream out) throws java.lang.Exception
- Throws:
java.lang.Exception
-
sendMultiple
protected void sendMultiple(Address dst, Address sender, Message[] list, int len, ByteArrayDataOutputStream out)
-
loopbackUnlessDontLoopbackIsSet
protected void loopbackUnlessDontLoopbackIsSet(Message msg)
-
loopback
protected void loopback(Address dest, Address sender, java.lang.Iterable<Message> list, int size)
-
sendSingleMessage
protected void sendSingleMessage(Address dest, Message msg, ByteArrayDataOutputStream out) throws java.lang.Exception
- Throws:
java.lang.Exception
-
sendMessageList
protected void sendMessageList(Address dest, Address src, java.util.List<Message> list, ByteArrayDataOutputStream out) throws java.lang.Exception
- Throws:
java.lang.Exception
-
sendMessageListArray
protected void sendMessageListArray(Address dest, Address src, Message[] list, int len, ByteArrayDataOutputStream out)
-
addMessage
protected void addMessage(Message msg, int size)
-
-