Search in sources :

Example 11 with BytesMessage

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

the class MessageDispatcherUnitTest method sendMessage.

private void sendMessage(int size) throws Exception {
    long start, stop;
    MyHandler handler = new MyHandler(new byte[size]);
    da.setRequestHandler(handler);
    Message msg = new BytesMessage(null, buf);
    RequestOptions opts = new RequestOptions(ResponseMode.GET_ALL, 0);
    start = System.currentTimeMillis();
    RspList<byte[]> rsps = da.castMessage(null, msg, opts);
    stop = System.currentTimeMillis();
    System.out.println("rsps:\n" + rsps);
    System.out.println("call took " + (stop - start) + " ms");
    assert rsps != null;
    Assert.assertEquals(1, rsps.size());
    byte[] tmp = rsps.getFirst();
    assert tmp != null;
    Assert.assertEquals(size, tmp.length);
}
Also used : BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) RequestOptions(org.jgroups.blocks.RequestOptions) BytesMessage(org.jgroups.BytesMessage)

Example 12 with BytesMessage

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

the class MessageDispatcherUnitTest method testNullMessageToSelf.

public void testNullMessageToSelf() throws Exception {
    MyHandler handler = new MyHandler(null);
    da.setRequestHandler(handler);
    RspList<byte[]> rsps = da.castMessage(null, new BytesMessage(null, buf), new RequestOptions(ResponseMode.GET_ALL, 0));
    System.out.println("rsps:\n" + rsps);
    assert rsps != null;
    assert 1 == rsps.size();
    Object obj = rsps.getFirst();
    assert obj == null;
}
Also used : RequestOptions(org.jgroups.blocks.RequestOptions) BytesMessage(org.jgroups.BytesMessage)

Example 13 with BytesMessage

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

the class UnicastTestTcpSlow method readMessage.

protected static Message readMessage(byte[] buf, int offset, int length) throws Exception {
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(buf, offset, length);
    short ver = in.readShort();
    byte flags = in.readByte();
    // final boolean multicast=(flags & (byte)2) == (byte)2;
    // don't create headers, readFrom() will do this
    Message msg = new BytesMessage();
    msg.readFrom(in);
    return msg;
}
Also used : BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) BytesMessage(org.jgroups.BytesMessage)

Example 14 with BytesMessage

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

the class UnicastTestTcpSlow method sendMessages.

void sendMessages() throws Exception {
    if (num_threads > 1 && num_msgs % num_threads != 0) {
        System.err.println("num_msgs (" + num_msgs + " ) has to be divisible by num_threads (" + num_threads + ")");
        return;
    }
    System.out.println("sending " + num_msgs + " messages (" + Util.printBytes(msg_size) + ") to " + remote + ": oob=" + oob + ", " + num_threads + " sender thread(s)");
    ByteBuffer buf = ByteBuffer.allocate(Global.BYTE_SIZE + Global.LONG_SIZE).put(START).putLong(num_msgs);
    Message msg = new BytesMessage(null, buf.array());
    // msg.writeTo(output);
    ByteArrayDataOutputStream dos = new ByteArrayDataOutputStream(msg.size());
    byte flags = 0;
    // write the version
    dos.writeShort(Version.version);
    if (msg.getDest() == null)
        flags += (byte) 2;
    dos.writeByte(flags);
    msg.writeTo(dos);
    ByteArray buffer = dos.getBuffer();
    // need to sync if we have more than 1 sender
    output_lock.lock();
    try {
        // msg.writeTo(output);
        output.writeInt(buffer.getLength());
        output.write(buffer.getArray(), buffer.getOffset(), buffer.getLength());
    } finally {
        output_lock.unlock();
    }
    int msgs_per_sender = num_msgs / num_threads;
    Sender[] senders = new Sender[num_threads];
    for (int i = 0; i < senders.length; i++) senders[i] = new Sender(msgs_per_sender, msg_size, num_msgs / 10);
    for (Sender sender : senders) sender.start();
    for (Sender sender : senders) sender.join();
    output.flush();
    System.out.println("done sending " + num_msgs + " to " + remote);
}
Also used : BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) BytesMessage(org.jgroups.BytesMessage) ByteBuffer(java.nio.ByteBuffer)

Example 15 with BytesMessage

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

the class TableTest method _testSeqnoOverflow.

protected static void _testSeqnoOverflow(long seqno, final int delta) {
    long orig_seqno = seqno;
    Table<Message> win = new Table<>(3, 10, seqno);
    for (int i = 1; i <= delta; i++) {
        Message msg = new BytesMessage(null, "hello");
        win.add(++seqno, msg);
    }
    System.out.println("win = " + win);
    assert win.size() == delta;
    assertIndices(win, orig_seqno, orig_seqno, seqno);
    List<Message> msgs = win.removeMany(true, 200, null);
    System.out.printf("removed %d msgs\n", msgs.size());
    assert win.isEmpty();
    assertIndices(win, seqno, seqno, seqno);
}
Also used : BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) EmptyMessage(org.jgroups.EmptyMessage) 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