use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class JmxConfigurator method unregisterChannel.
public static void unregisterChannel(JChannel c, MBeanServer server, String domain, String clusterName) throws Exception {
if (clusterName != null)
clusterName = ObjectName.quote(clusterName);
ProtocolStack stack = c.getProtocolStack();
List<Protocol> protocols = stack.getProtocols();
for (Protocol p : protocols) {
if (p.getClass().isAnnotationPresent(MBean.class)) {
try {
String obj_name = getProtocolRegistrationName(clusterName, domain, p);
unregister(p, server, obj_name);
} catch (MBeanRegistrationException e) {
log.warn("MBean unregistration failed: " + e.getCause());
}
}
}
unregister(c, server, getChannelRegistrationName(domain, clusterName));
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class GMS_MergeTest 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 NAKACK_Delivery_Test method setUp.
@BeforeMethod
protected void setUp() throws Exception {
a = Util.createRandomAddress("A");
b = Util.createRandomAddress("B");
nak = new NAKACK2();
TP transport = new TP() {
public boolean supportsMulticasting() {
return false;
}
public void sendUnicast(PhysicalAddress dest, byte[] data, int offset, int length) throws Exception {
}
public String getInfo() {
return null;
}
public Object down(Event evt) {
return null;
}
public Object down(Message msg) {
return null;
}
protected PhysicalAddress getPhysicalAddress() {
return null;
}
public TimeScheduler getTimer() {
return new TimeScheduler3();
}
};
transport.setId((short) 100);
nak.setDownProtocol(transport);
receiver.init(a, b);
nak.setUpProtocol(receiver);
nak.start();
List<Address> members = new ArrayList<>(2);
members.add(a);
members.add(b);
View view = new View(a, 1, members);
// set the local address
for (Protocol p = nak; p != null; p = p.getDownProtocol()) p.setAddress(a);
// set a dummy digest
View tmp_view = View.create(a, 1, a, b);
MutableDigest digest = new MutableDigest(tmp_view.getMembersRaw());
digest.set(a, 0, 0);
digest.set(b, 0, 0);
nak.down(new Event(Event.SET_DIGEST, digest));
// set dummy view
nak.down(new Event(Event.VIEW_CHANGE, view));
nak.down(new Event(Event.BECOME_SERVER));
pool = new ThreadPoolExecutor(1, 100, 1000, TimeUnit.MILLISECONDS, new SynchronousQueue<>());
// pool=new DirectExecutor();
// if(pool instanceof ThreadPoolExecutor)
((ThreadPoolExecutor) pool).setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class UNICAST_OOB_Test method sendMessages.
/**
* Check that 4 is received before 3
*/
private void sendMessages(boolean oob) throws Exception {
DISCARD_PAYLOAD discard = new DISCARD_PAYLOAD();
MyReceiver receiver = new MyReceiver();
b.setReceiver(receiver);
// the first channel will discard the unicast messages with seqno #3 two times, the let them pass down
ProtocolStack stack = a.getProtocolStack();
Protocol neighbor = stack.findProtocol(Util.getUnicastProtocols());
System.out.println("Found unicast protocol " + neighbor.getClass().getSimpleName());
stack.insertProtocolInStack(discard, neighbor, ProtocolStack.Position.BELOW);
Util.waitUntilAllChannelsHaveSameView(10000, 1000, a, b);
Address dest = b.getAddress();
for (int i = 1; i <= 5; i++) {
Message msg = new ObjectMessage(dest, (long) i);
if (i == 4 && oob)
msg.setFlag(Message.Flag.OOB);
System.out.println("-- sending message #" + i);
a.send(msg);
Util.sleep(100);
}
// wait until retransmission of seqno #3 happens, so that 4 and 5 are received as well
long target_time = System.currentTimeMillis() + 30000;
do {
if (receiver.size() >= 5)
break;
Util.sleep(500);
} while (target_time > System.currentTimeMillis());
List<Long> seqnos = receiver.getSeqnos();
System.out.println("-- sequence numbers: " + seqnos);
assert seqnos.size() == 5;
if (!oob) {
for (int i = 0; i < 5; i++) assert seqnos.get(i) == i + 1 : " seqno is " + seqnos.get(i) + ", but expected " + i + 1;
} else {
// 4 needs to be received before 3. Reason: 4 is sent OOB, does *not* wait until 3 has been retransmitted !
int index_3 = -1, index_4 = -1;
for (int i = 0; i < 5; i++) {
if (seqnos.get(i) == 3)
index_3 = i;
if (seqnos.get(i) == 4)
index_4 = i;
}
assert index_4 < index_3 : "4 must come before 3 in list " + seqnos;
}
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class UNICAST_ConnectionTests method testMessageToNonExistingMember.
@Test(dataProvider = "configProvider")
public void testMessageToNonExistingMember(Class<? extends UNICAST3> unicast) throws Exception {
setup(unicast);
Stream.of(a, b).forEach(ch -> ((UNICAST3) ch.getProtocolStack().findProtocol(unicast)).setMaxRetransmitTime(5000));
Address target = Util.createRandomAddress("FakeAddress");
a.send(target, "hello");
Protocol prot = a.getProtocolStack().findProtocol(unicast);
Method hasSendConnectionTo = unicast.getMethod("hasSendConnectionTo", Address.class);
for (int i = 0; i < 10; i++) {
boolean result = (Boolean) hasSendConnectionTo.invoke(prot, target);
if (!result)
break;
Util.sleep(1000);
}
assert !(Boolean) hasSendConnectionTo.invoke(prot, target);
}
Aggregations