use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class NAKACK_RetransmitTest method setLevel.
protected static void setLevel(String level, JChannel... channels) {
for (JChannel ch : channels) {
Protocol prot = ch.getProtocolStack().findProtocol(NAKACK2.class);
prot.level(level);
}
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class NAKACK_StressTest method start.
private static void start(final int num_threads, final int num_msgs, boolean oob) {
final NAKACK2 nak = new NAKACK2();
final AtomicInteger counter = new AtomicInteger(num_msgs);
final AtomicLong seqno = new AtomicLong(1);
final AtomicInteger delivered_msgs = new AtomicInteger(0);
final Lock lock = new ReentrantLock();
final Condition all_msgs_delivered = lock.newCondition();
final ConcurrentLinkedQueue<Long> delivered_msg_list = new ConcurrentLinkedQueue<>();
final Address local_addr = Util.createRandomAddress("A");
final Address sender = Util.createRandomAddress("B");
nak.setDownProtocol(new Protocol() {
public Object down(Event evt) {
return null;
}
});
nak.setUpProtocol(new Protocol() {
public Object up(Message msg) {
delivered_msgs.incrementAndGet();
NakAckHeader2 hdr = msg.getHeader(NAKACK_ID);
if (hdr != null)
delivered_msg_list.add(hdr.getSeqno());
if (delivered_msgs.get() >= num_msgs) {
lock.lock();
try {
all_msgs_delivered.signalAll();
} finally {
lock.unlock();
}
}
return null;
}
public void up(MessageBatch batch) {
for (Message msg : batch) {
delivered_msgs.incrementAndGet();
NakAckHeader2 hdr = msg.getHeader(NAKACK_ID);
if (hdr != null)
delivered_msg_list.add(hdr.getSeqno());
if (delivered_msgs.get() >= num_msgs) {
lock.lock();
try {
all_msgs_delivered.signalAll();
} finally {
lock.unlock();
}
}
}
}
});
nak.setDiscardDeliveredMsgs(true);
for (Protocol p = nak; p != null; p = p.getDownProtocol()) p.setAddress(local_addr);
nak.down(new Event(Event.BECOME_SERVER));
View view = View.create(local_addr, 1, local_addr, sender);
nak.down(new Event(Event.VIEW_CHANGE, view));
MutableDigest digest = new MutableDigest(view.getMembersRaw());
digest.set(local_addr, 0, 0);
digest.set(sender, 0, 0);
nak.down(new Event(Event.SET_DIGEST, digest));
final CountDownLatch latch = new CountDownLatch(1);
Sender[] adders = new Sender[num_threads];
for (int i = 0; i < adders.length; i++) {
adders[i] = new Sender(nak, latch, counter, seqno, oob, sender);
adders[i].start();
}
long start = System.currentTimeMillis();
// starts all adders
latch.countDown();
int max_tries = 30;
lock.lock();
try {
while (delivered_msgs.get() < num_msgs && max_tries-- > 0) {
try {
all_msgs_delivered.await(1000, TimeUnit.MILLISECONDS);
System.out.println("received " + delivered_msgs.get() + " msgs");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} finally {
lock.unlock();
}
long time = System.currentTimeMillis() - start;
double requests_sec = num_msgs / (time / 1000.0);
System.out.printf("\nTime: %d ms, %.2f requests / sec\n", time, requests_sec);
System.out.println("Delivered messages: " + delivered_msg_list.size());
if (delivered_msg_list.size() < 100)
System.out.println("Elements: " + delivered_msg_list);
nak.stop();
List<Long> results = new ArrayList<>(delivered_msg_list);
if (oob)
Collections.sort(results);
assert results.size() == num_msgs : "expected " + num_msgs + ", but got " + results.size();
System.out.println("Checking results consistency");
int i = 1;
for (Long num : results) {
if (num != i) {
assert i == num : "expected " + i + " but got " + num;
return;
}
i++;
}
System.out.println("OK");
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class FlowControlUnitTest method replaceUFC.
protected static void replaceUFC(int max_queue_size, JChannel... channels) throws Exception {
for (JChannel ch : channels) {
ProtocolStack stack = ch.getProtocolStack();
UFC_NB ufc_nb = new UFC_NB().setMaxCredits(MAX_CREDITS).setMinThreshold(0.2);
ufc_nb.setMaxQueueSize(max_queue_size);
ufc_nb.frag_size = 1500;
View view = ch.getView();
// needs to setup received and sent hashmaps
ufc_nb.handleViewChange(view.getMembers());
stack.replaceProtocol(stack.findProtocol(UFC.class), ufc_nb);
for (Protocol p = ufc_nb; p != null; p = p.getDownProtocol()) p.setAddress(ch.getAddress());
ufc_nb.start();
}
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class INJECT_VIEWTest method modify.
protected static Protocol[] modify(Protocol[] retval) {
for (Protocol prot : retval) {
if (prot instanceof GMS)
((GMS) prot).setJoinTimeout(1000);
if (prot instanceof NAKACK2) {
((NAKACK2) prot).logDiscardMessages(false);
((NAKACK2) prot).logNotFoundMessages(false);
}
}
return retval;
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class ProgrammaticUPerf method init.
public void init(String name, AddressGenerator generator, String bind_addr, int bind_port, boolean udp, String mcast_addr, int mcast_port, String initial_hosts) throws Throwable {
InetAddress bind_address = bind_addr != null ? Util.getAddress(bind_addr, Util.getIpStackType()) : Util.getLoopback();
Protocol[] prot_stack = { // transport
null, // discovery protocol
null, new MERGE3(), new FD_SOCK(), new FD_ALL3(), new VERIFY_SUSPECT(), new NAKACK2(), new UNICAST3(), new STABLE(), new GMS().setJoinTimeout(1000), new UFC(), new MFC(), new FRAG4() };
if (udp) {
UDP u = new UDP().setMulticastAddress(InetAddress.getByName(mcast_addr)).setMulticastPort(mcast_port);
u.getDiagnosticsHandler().setMcastAddress(InetAddress.getByName("224.0.75.75")).enableUdp(true);
prot_stack[0] = u;
prot_stack[1] = new PING();
} else {
if (initial_hosts == null) {
InetAddress host = bind_addr == null ? InetAddress.getLocalHost() : Util.getAddress(bind_addr, Util.getIpStackType());
initial_hosts = String.format("%s[%d]", host.getHostAddress(), bind_port);
}
TCP tcp = new TCP();
tcp.getDiagnosticsHandler().enableUdp(false).enableTcp(true);
prot_stack[0] = tcp;
prot_stack[1] = new TCPPING().setInitialHosts2(Util.parseCommaDelimitedHosts(initial_hosts, 2));
}
((TP) prot_stack[0]).setBindAddress(bind_address).setBindPort(bind_port);
channel = new JChannel(prot_stack).addAddressGenerator(generator).setName(name);
TP transport = channel.getProtocolStack().getTransport();
// todo: remove default ProbeHandler for "jmx" and "op"
NonReflectiveProbeHandler h = new NonReflectiveProbeHandler(channel);
transport.registerProbeHandler(h);
h.initialize(channel.getProtocolStack().getProtocols());
// System.out.printf("contents:\n%s\n", h.dump());
disp = new RpcDispatcher(channel, this).setReceiver(this).setMethodInvoker(this);
channel.connect(groupname);
local_addr = channel.getAddress();
if (members.size() < 2)
return;
Address coord = members.get(0);
Config config = disp.callRemoteMethod(coord, new CustomCall(GET_CONFIG), new RequestOptions(ResponseMode.GET_ALL, 5000));
if (config != null) {
applyConfig(config);
System.out.println("Fetched config from " + coord + ": " + config + "\n");
} else
System.err.println("failed to fetch config from " + coord);
}
Aggregations