Package org.jgroups.protocols
Class BaseBundler
- java.lang.Object
-
- org.jgroups.protocols.BaseBundler
-
- All Implemented Interfaces:
Bundler
- Direct Known Subclasses:
BatchBundler
,NoBundler
,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 AverageMinMax
avg_send_time
protected int
capacity
protected long
count
protected java.util.function.Function<Address,java.util.List<Message>>
FUNC
protected java.util.concurrent.locks.ReentrantLock
lock
protected Log
log
protected int
max_size
Maximum number of bytes for messages to be queued until they are sent.protected MessageProcessingPolicy
msg_processing_policy
protected MsgStats
msg_stats
protected java.util.Map<Address,java.util.List<Message>>
msgs
Keys are destinations, values are lists of Messagesprotected ByteArrayDataOutputStream
output
protected TP
transport
-
Constructor Summary
Constructors Constructor Description BaseBundler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addMessage(Message msg, int size)
int
getCapacity()
If the bundler implementation supports a capacity (e.g.int
getMaxSize()
Maximum number of bytes for messages to be queued until they are sentint
getQueueSize()
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.void
init(TP transport)
Called after creation of the bundlerprotected void
loopback(Address dest, Address sender, java.lang.Iterable<Message> list, int size)
protected void
loopback(Address dest, Address sender, Message[] list, int len)
protected void
loopbackUnlessDontLoopbackIsSet(Message msg)
java.lang.String
printBuffers()
void
resetStats()
void
send(Message msg)
protected void
sendBundledMessages()
Sends all messages in the map.protected void
sendMessageList(Address dest, Address src, java.util.List<Message> list, ByteArrayDataOutputStream out)
protected void
sendMessageList(Address dest, Address src, Message[] list, int len, ByteArrayDataOutputStream out)
protected void
sendMultiple(Address dst, Address sender, java.util.List<Message> list, ByteArrayDataOutputStream out)
protected void
sendMultiple(Address dst, Address sender, Message[] list, int len, ByteArrayDataOutputStream out)
protected void
sendSingle(Address dst, Message msg, ByteArrayDataOutputStream out)
protected void
sendSingleMessage(Message msg, ByteArrayDataOutputStream out)
Bundler
setCapacity(int c)
Bundler
setMaxSize(int s)
int
size()
Returns the total number of messages in the hashmapvoid
start()
Called afterBundler.init(TP)
void
stop()
void
viewChange(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
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
-
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
-
avg_send_time
protected final AverageMinMax avg_send_time
-
-
Method Detail
-
printBuffers
public java.lang.String printBuffers()
-
getCapacity
public int getCapacity()
Description copied from interface:Bundler
If the bundler implementation supports a capacity (e.g.RingBufferBundler
, then return it, else return -1- Specified by:
getCapacity
in interfaceBundler
-
setCapacity
public Bundler setCapacity(int c)
-
getMaxSize
public int getMaxSize()
Description copied from interface:Bundler
Maximum number of bytes for messages to be queued until they are sent- Specified by:
getMaxSize
in interfaceBundler
-
setMaxSize
public Bundler setMaxSize(int s)
- Specified by:
setMaxSize
in interfaceBundler
-
init
public void init(TP transport)
Description copied from interface:Bundler
Called after creation of the bundler
-
resetStats
public void resetStats()
- Specified by:
resetStats
in interfaceBundler
-
start
public void start()
Description copied from interface:Bundler
Called afterBundler.init(TP)
-
send
public void send(Message msg) throws java.lang.Exception
-
viewChange
public void viewChange(View view)
- Specified by:
viewChange
in interfaceBundler
-
size
public int size()
Returns the total number of messages in the hashmap
-
getQueueSize
public int getQueueSize()
Description copied from interface:Bundler
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. 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:
getQueueSize
in 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)
-
sendMultiple
protected void sendMultiple(Address dst, Address sender, java.util.List<Message> list, ByteArrayDataOutputStream out)
-
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(Message msg, ByteArrayDataOutputStream out)
-
sendMessageList
protected void sendMessageList(Address dest, Address src, java.util.List<Message> list, ByteArrayDataOutputStream out)
-
sendMessageList
protected void sendMessageList(Address dest, Address src, Message[] list, int len, ByteArrayDataOutputStream out)
-
addMessage
protected void addMessage(Message msg, int size)
-
-