Search in sources :

Example 21 with BytesMessage

use of org.jgroups.BytesMessage in project JGroups by belaban.

the class SequencerFailoverTestHelper method sendMessages.

// Do *NOT* make this method static, or else Byteman won't be able to find it!
public void sendMessages(final Protocol prot, final int start, final int end) {
    final Thread sender = new Thread(() -> {
        for (int i = start; i <= end; i++) {
            Message msg = new BytesMessage(null, i);
            System.out.println("[" + prot.getValue("local_addr") + "] --> sending message " + i);
            prot.down(msg);
        }
    });
    sender.setName("BytemanSenderThread");
    sender.start();
    try {
        sender.join(1000);
    } catch (InterruptedException e) {
    }
}
Also used : BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) BytesMessage(org.jgroups.BytesMessage)

Example 22 with BytesMessage

use of org.jgroups.BytesMessage in project JGroups by belaban.

the class SERIALIZE method down.

public Object down(Message msg) {
    if (msg.getSrc() == null)
        msg.setSrc(local_addr);
    ByteArray serialized_msg = null;
    try {
        serialized_msg = Util.messageToBuffer(msg);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // exclude existing headers, they will be seen again when we unmarshal the message at the receiver
    Message tmp = new BytesMessage(msg.dest(), serialized_msg).setFlag(msg.getFlags(), false);
    GMS.GmsHeader hdr = msg.getHeader(GMS_ID);
    if (hdr != null)
        tmp.putHeader(GMS_ID, hdr);
    return down_prot.down(tmp);
}
Also used : BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) ByteArray(org.jgroups.util.ByteArray) BytesMessage(org.jgroups.BytesMessage) GMS(org.jgroups.protocols.pbcast.GMS)

Example 23 with BytesMessage

use of org.jgroups.BytesMessage in project JGroups by belaban.

the class NonBlockingCreditMapTest method testDecrement.

public void testDecrement() {
    Message msg = new BytesMessage(null, new byte[8000]);
    // timeout will be ignored
    boolean rc = map.decrement(msg, msg.getLength(), 0);
    assert rc && map.getMinCredits() == 2000;
    assert !map.isQueuing();
    msg = new BytesMessage(null, new byte[2000]);
    rc = map.decrement(msg, msg.getLength(), 0);
    assert rc && !map.isQueuing();
    for (int i = 0; i < 5; i++) {
        msg = new BytesMessage(null, new byte[1000]);
        rc = map.decrement(msg, msg.getLength(), 0);
        assert !rc && map.isQueuing();
    }
    assert map.getQueuedMessages() == 5 && map.getQueuedMessageSize() == 5000;
    map.replenish(d, 4500);
    assert map.getMinCredits() == 0;
    assert map.isQueuing();
    for (Address member : Arrays.asList(a, b, c)) map.replenish(member, 4500);
    assert map.isQueuing() && map.getQueuedMessages() == 1;
}
Also used : BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) Address(org.jgroups.Address) BytesMessage(org.jgroups.BytesMessage)

Example 24 with BytesMessage

use of org.jgroups.BytesMessage in project JGroups by belaban.

the class NonBlockingCreditMapTest method testBlockingDecrement.

public void testBlockingDecrement() {
    map = new NonBlockingCreditMap(MAX_CREDITS, 2500, new ReentrantLock(true));
    addAll();
    Message msg = new BytesMessage(null, new byte[8000]);
    boolean rc = map.decrement(msg, msg.getLength(), 0);
    assert rc && !map.isQueuing();
    new Thread(() -> {
        Util.sleep(2000);
        System.out.println("\n-- replenishing 5000 credits");
        Stream.of(a, b, c, d).forEach(c -> map.replenish(c, 5000));
    }).start();
    for (int i = 1; i <= 5; i++) {
        msg = new BytesMessage(null, new byte[1000]);
        System.out.printf("-- adding msg %d: ", i);
        // message 5 should block, but replenish() should unblock it
        rc = map.decrement(msg, msg.getLength(), 0);
        System.out.printf("rc=%b\n", rc);
        assert rc == i < 3;
    }
    assert !map.isQueuing();
    assert map.getQueuedMessages() == 0;
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BytesMessage(org.jgroups.BytesMessage) Arrays(java.util.Arrays) Stream(java.util.stream.Stream) Message(org.jgroups.Message) Util(org.jgroups.util.Util) ReentrantLock(java.util.concurrent.locks.ReentrantLock) NonBlockingCreditMap(org.jgroups.util.NonBlockingCreditMap) BeforeMethod(org.testng.annotations.BeforeMethod) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test) Address(org.jgroups.Address) Collectors(java.util.stream.Collectors) BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) NonBlockingCreditMap(org.jgroups.util.NonBlockingCreditMap) BytesMessage(org.jgroups.BytesMessage)

Aggregations

BytesMessage (org.jgroups.BytesMessage)24 Message (org.jgroups.Message)19 RequestOptions (org.jgroups.blocks.RequestOptions)5 Address (org.jgroups.Address)3 MessageDispatcher (org.jgroups.blocks.MessageDispatcher)3 DataInput (java.io.DataInput)2 ByteBuffer (java.nio.ByteBuffer)2 MessageDigest (java.security.MessageDigest)2 Stream (java.util.stream.Stream)2 Rsp (org.jgroups.util.Rsp)2 Util (org.jgroups.util.Util)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Test (org.testng.annotations.Test)2 DatagramPacket (java.net.DatagramPacket)1 SocketException (java.net.SocketException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Collectors (java.util.stream.Collectors)1