use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class FORK method getStateFromMainAndForkChannels.
protected void getStateFromMainAndForkChannels(Event evt) {
final OutputStream out = evt.getArg();
try (DataOutputStream dos = new DataOutputStream(out)) {
getStateFrom(null, up_prot, null, null, dos);
// now fetch state from all fork channels
for (Map.Entry<String, Protocol> entry : fork_stacks.entrySet()) {
String stack_name = entry.getKey();
Protocol prot = entry.getValue();
ForkProtocolStack fork_stack = getForkStack(prot);
for (Map.Entry<String, JChannel> en : fork_stack.getForkChannels().entrySet()) {
String fc_name = en.getKey();
JChannel fc = en.getValue();
getStateFrom(fc, null, stack_name, fc_name, dos);
}
}
} catch (Throwable ex) {
log.error("%s: failed fetching state from main channel", local_addr, ex);
}
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class FORK method up.
public void up(MessageBatch batch) {
// Sort fork messages by fork-stack-id
Map<String, List<Message>> map = new HashMap<>();
Iterator<Message> it = batch.iterator();
while (it.hasNext()) {
Message msg = it.next();
ForkHeader hdr = msg.getHeader(id);
if (hdr != null) {
it.remove();
List<Message> list = map.computeIfAbsent(hdr.fork_stack_id, k -> new ArrayList<>());
list.add(msg);
}
}
// Now pass fork messages up, batched by fork-stack-id
for (Map.Entry<String, List<Message>> entry : map.entrySet()) {
String fork_stack_id = entry.getKey();
List<Message> list = entry.getValue();
Protocol bottom_prot = get(fork_stack_id);
if (bottom_prot == null) {
for (Message m : list) unknownForkHandler.handleUnknownForkStack(m, fork_stack_id);
continue;
}
MessageBatch mb = new MessageBatch(batch.dest(), batch.sender(), batch.clusterName(), batch.multicast(), list);
try {
bottom_prot.up(mb);
} catch (Throwable t) {
log.error(Util.getMessage("FailedPassingUpBatch"), t);
}
}
if (!batch.isEmpty())
up_prot.up(batch);
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class SequencerMergeTest method getDigest.
protected static Digest getDigest(final View view, JChannel... channels) {
MutableDigest digest = new MutableDigest(view.getMembersRaw());
for (JChannel ch : channels) {
Protocol nak = ch.getProtocolStack().findProtocol(NAKACK2.class);
Digest tmp = (Digest) nak.down(new Event(Event.GET_DIGEST, ch.getAddress()));
if (tmp != null)
digest.set(tmp);
}
return digest;
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class SequencerMergeTest method injectViewAndDigest.
protected static void injectViewAndDigest(View view, Digest digest, JChannel... channels) {
for (JChannel ch : channels) {
GMS gms = ch.getProtocolStack().findProtocol(GMS.class);
gms.installView(view);
Protocol nak = ch.getProtocolStack().findProtocol(NAKACK2.class);
if (nak != null)
nak.down(new Event(Event.SET_DIGEST, digest));
}
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class OverlappingMergeTest method testSameCreatorDifferentIDs.
/**
* Tests a merge where all members have views whose ViewIds have the same creator, but different IDs, e.g.:
* A: A|5 {A}
* B: A|6 {A,B}
* C: A|7 {A,B,C}
*/
public void testSameCreatorDifferentIDs() throws Exception {
for (JChannel ch : new JChannel[] { a, b, c }) {
MERGE3 merge_prot = ch.getProtocolStack().findProtocol(MERGE3.class);
if (merge_prot == null) {
merge_prot = new MERGE3();
merge_prot.setMinInterval(500).setMaxInterval(1000).setCheckInterval(3000);
ch.getProtocolStack().insertProtocol(merge_prot, ProtocolStack.Position.ABOVE, Discovery.class);
merge_prot.init();
merge_prot.start();
for (Protocol p = merge_prot; p != null; p = p.getDownProtocol()) p.setAddress(ch.getAddress());
}
}
View view = View.create(a.getAddress(), 5, a.getAddress());
injectView(view, a);
view = View.create(a.getAddress(), 6, a.getAddress(), b.getAddress());
injectView(view, b);
view = View.create(a.getAddress(), 7, a.getAddress(), b.getAddress(), c.getAddress());
injectView(view, c);
System.out.println("\nA's view: " + a.getView());
System.out.println("B's view: " + b.getView());
System.out.println("C's view: " + c.getView());
Util.waitUntilAllChannelsHaveSameView(50000, 1000, a, b, c);
View va = a.getView(), vb = b.getView(), vc = c.getView();
System.out.println("\nA's view: " + va);
System.out.println("B's view: " + vb);
System.out.println("C's view: " + vc);
assert va.size() == 3;
assert vb.size() == 3;
assert vc.size() == 3;
}
Aggregations