Search in sources :

Example 21 with MessageBatch

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);
}
Also used : MessageBatch(org.jgroups.util.MessageBatch)

Example 22 with MessageBatch

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;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch)

Example 23 with MessageBatch

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;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch)

Example 24 with MessageBatch

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();
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 25 with MessageBatch

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;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Aggregations

MessageBatch (org.jgroups.util.MessageBatch)46 Message (org.jgroups.Message)37 Util (org.jgroups.util.Util)6 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)5 ClassConfigurator (org.jgroups.conf.ClassConfigurator)5 Test (org.testng.annotations.Test)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 java.util (java.util)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 BiFunction (java.util.function.BiFunction)4 Predicate (java.util.function.Predicate)4 Collectors (java.util.stream.Collectors)4 Address (org.jgroups.Address)4 Global (org.jgroups.Global)4 org.jgroups.protocols (org.jgroups.protocols)4 Collection (java.util.Collection)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2