Search in sources :

Example 6 with Buffer

use of org.jgroups.util.Buffer in project JGroups by belaban.

the class MessageSizeTest method testMulticast.

/**
 * Tests size of a multicast message.
 * Current record: 84 bytes (March 2010)
 * Prev: 166, 109, 103, 84
 * @throws Exception
 */
public static void testMulticast() throws Exception {
    Address src = Util.createRandomAddress();
    Message msg = createMessage(null, src);
    Buffer buf = marshal(msg);
    System.out.println("buf = " + buf);
    int len = buf.getLength();
    System.out.println("len = " + len);
    assert len <= MCAST_MAX_SIZE;
    if (len < MCAST_MAX_SIZE) {
        double percentage = compute(len, MCAST_MAX_SIZE);
        System.out.printf("multicast message (%d bytes) is %.2f %% smaller than previous max size (%d bytes)\n", len, percentage, MCAST_MAX_SIZE);
    }
}
Also used : Buffer(org.jgroups.util.Buffer) Address(org.jgroups.Address) Message(org.jgroups.Message)

Example 7 with Buffer

use of org.jgroups.util.Buffer in project JGroups by belaban.

the class MessageSizeTest method testUnicast.

/**
 * Tests size of a unicast message.
 * Current record: 102 (March 2010)
 * Prev: 161, 127, 121, 102
 * @throws Exception
 */
public static void testUnicast() throws Exception {
    Address dest = Util.createRandomAddress();
    Address src = Util.createRandomAddress();
    Message msg = createMessage(dest, src);
    Buffer buf = marshal(msg);
    System.out.println("buf = " + buf);
    int len = buf.getLength();
    System.out.println("len = " + len);
    assert len <= UNICAST_MAX_SIZE;
    if (len < UNICAST_MAX_SIZE) {
        double percentage = compute(len, UNICAST_MAX_SIZE);
        System.out.printf("unicast message (%d bytes) is %.2f %% smaller than previous max size (%d bytes)\n", len, percentage, MCAST_MAX_SIZE);
    }
}
Also used : Buffer(org.jgroups.util.Buffer) Address(org.jgroups.Address) Message(org.jgroups.Message)

Example 8 with Buffer

use of org.jgroups.util.Buffer in project wildfly by wildfly.

the class CommandResponseMarshaller method objectToBuffer.

@Override
public Buffer objectToBuffer(Object object) throws Exception {
    int version = this.context.getCurrentVersion();
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    try (DataOutputStream output = new DataOutputStream(bytes)) {
        IndexExternalizer.VARIABLE.writeData(output, version);
        try (Marshaller marshaller = this.context.createMarshaller(version)) {
            marshaller.start(Marshalling.createByteOutput(output));
            marshaller.writeObject(object);
            marshaller.flush();
        }
    }
    return new Buffer(bytes.toByteArray());
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(org.jgroups.util.Buffer) Marshaller(org.jboss.marshalling.Marshaller) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 9 with Buffer

use of org.jgroups.util.Buffer in project JGroups by belaban.

the class DynamicDiscardTest method testLeaveDuringSend.

public void testLeaveDuringSend() throws Exception {
    final JChannel[] channels = new JChannel[NUM];
    final MessageDispatcher[] dispatchers = new MessageDispatcher[NUM];
    for (int i = 0; i < NUM; i++) {
        channels[i] = new JChannel(new SHARED_LOOPBACK(), new SHARED_LOOPBACK_PING(), new MERGE3(), new FD().setValue("timeout", 1000).setValue("max_tries", 1), new NAKACK2(), new UNICAST3(), new STABLE(), new GMS(), new RSVP().setValue("ack_on_delivery", false).setValue("throw_exception_on_timeout", false));
        channels[i].setName(Character.toString((char) ('A' + i)));
        channels[i].setDiscardOwnMessages(true);
        dispatchers[i] = new MessageDispatcher(channels[i], new MyRequestHandler());
        dispatchers[i].setMembershipListener(new MyMembershipListener(channels[i]));
        channels[i].connect("DynamicDiscardTest");
        System.out.print(i + 1 + " ");
    }
    Util.waitUntilAllChannelsHaveSameView(10000, 1000, channels);
    // discard all messages (except those to self)
    DISCARD discard = new DISCARD().setDiscardAll(true);
    channels[0].getProtocolStack().insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class);
    // send a RSVP message
    byte[] data = "message2".getBytes();
    Buffer buf = new Buffer(data, 0, data.length);
    RspList<Object> rsps = dispatchers[0].castMessage(null, buf, RequestOptions.SYNC().timeout(5000).flags(Message.Flag.RSVP, Message.Flag.OOB));
    Rsp<Object> objectRsp = rsps.get(channels[1].getAddress());
    assertFalse(objectRsp.wasReceived());
    assertTrue(objectRsp.wasSuspected());
}
Also used : Buffer(org.jgroups.util.Buffer) GMS(org.jgroups.protocols.pbcast.GMS) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) MessageDispatcher(org.jgroups.blocks.MessageDispatcher) STABLE(org.jgroups.protocols.pbcast.STABLE)

Example 10 with Buffer

use of org.jgroups.util.Buffer in project JGroups by belaban.

the class GroupRequestTest method _testMessageReceptionWithViewChange.

private void _testMessageReceptionWithViewChange(boolean async) throws Exception {
    List<Address> new_dests = new ArrayList<>();
    new_dests.add(a);
    new_dests.add(b);
    new_dests.add(a);
    Object[] responses = { new Message(null, (long) 1).src(a), new View(Util.createRandomAddress(), 322649, new_dests), new Message(null, (long) 2).src(b) };
    MyCorrelator corr = new MyCorrelator(async, responses, 0);
    GroupRequest<Long> req = new GroupRequest<>(corr, dests, new RequestOptions(ResponseMode.GET_ALL, 0));
    corr.setGroupRequest(req);
    RspList<Long> results = req.execute(new Buffer(buf, 0, buf.length), true);
    System.out.println("group request is " + req);
    assert req.isDone();
    Assert.assertEquals(2, results.size());
}
Also used : Buffer(org.jgroups.util.Buffer) ArrayList(java.util.ArrayList)

Aggregations

Buffer (org.jgroups.util.Buffer)14 Address (org.jgroups.Address)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 Message (org.jgroups.Message)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 UnknownHostException (java.net.UnknownHostException)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 CompletionStage (java.util.concurrent.CompletionStage)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Marshaller (org.jboss.marshalling.Marshaller)1 org.jgroups (org.jgroups)1 MessageDispatcher (org.jgroups.blocks.MessageDispatcher)1 RequestOptions (org.jgroups.blocks.RequestOptions)1 GMS (org.jgroups.protocols.pbcast.GMS)1 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)1 STABLE (org.jgroups.protocols.pbcast.STABLE)1