org.jgroups.protocols.SenderSendsBundler Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including
all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and
JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
package org.jgroups.protocols;
import org.jgroups.Message;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author Bela Ban
* @since 4.0
*/
public class SenderSendsBundler extends BaseBundler {
protected final AtomicInteger num_senders=new AtomicInteger(0); // current senders adding msgs to the bundler
public void send(Message msg) throws Exception {
num_senders.incrementAndGet();
int size=msg.size();
lock.lock();
try {
if(count + size >= max_size)
sendBundledMessages();
addMessage(msg, size);
// at this point, we haven't sent our message yet !
if(num_senders.decrementAndGet() == 0) // no other sender threads present at this time
sendBundledMessages();
// else there are other sender threads waiting, so our message will be sent by a different thread
}
finally {
lock.unlock();
}
}
}