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