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);
}
}
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);
}
}
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());
}
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());
}
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());
}
Aggregations