use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class BATCH method up.
public void up(MessageBatch batch) {
int len = 0;
for (Message msg : batch) if (msg instanceof BatchMessage)
len += ((BatchMessage) msg).getNumberOfMessages();
if (len > 0) {
// remove BatchMessages and add their contents to a new batch
MessageBatch mb = new MessageBatch(len + 1).setDest(batch.dest()).setSender(batch.getSender());
for (Iterator<Message> it = batch.iterator(); it.hasNext(); ) {
Message m = it.next();
if (m instanceof BatchMessage) {
BatchMessage ebm = (BatchMessage) m;
it.remove();
mb.add(ebm.getMessages(), ebm.getNumberOfMessages());
}
}
if (!mb.isEmpty())
up_prot.up(mb);
}
if (!batch.isEmpty())
up_prot.up(batch);
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class BATCH method up.
public Object up(Message msg) {
if (msg.getHeader(getId()) == null)
return up_prot.up(msg);
BatchMessage comp = (BatchMessage) msg;
for (Message bundledMsg : comp) {
bundledMsg.setDest(comp.getDest());
if (bundledMsg.getSrc() == null)
bundledMsg.setSrc(comp.getSrc());
}
MessageBatch batch = new MessageBatch();
batch.set(comp.getDest(), comp.getSrc(), comp.getMessages());
if (!batch.isEmpty())
up_prot.up(batch);
return null;
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testTransfer3.
public void testTransfer3() {
MessageBatch other = new MessageBatch(30);
MessageBatch batch = new MessageBatch(10);
int num = batch.transferFrom(other, true);
assert num == 0;
assert batch.capacity() == 10;
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testIsEmpty.
public void testIsEmpty() {
MessageBatch batch = new MessageBatch(3).add(new Message()).add(new Message()).add(new Message());
assert !batch.isEmpty();
for (Iterator<Message> it = batch.iterator(); it.hasNext(); ) {
it.next();
it.remove();
}
set(batch, 2, new Message());
assert !batch.isEmpty();
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testIterator6.
public void testIterator6() {
List<Message> msgs = createMessages();
MessageBatch batch = new MessageBatch(msgs);
remove(batch, 1, 2, 3, 10, msgs.size() - 1);
System.out.println("batch = " + batch);
int count = 0;
for (Message ignored : batch) count++;
assert count == msgs.size() - 5;
count = 0;
batch.add(new Message()).add(new Message());
System.out.println("batch = " + batch);
for (Message ignored : batch) count++;
assert count == msgs.size() - 5 + 2;
}
Aggregations