Search in sources :

Example 71 with Protocol

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);
    }
}
Also used : JChannel(org.jgroups.JChannel) ForkProtocol(org.jgroups.fork.ForkProtocol) Protocol(org.jgroups.stack.Protocol) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ForkProtocolStack(org.jgroups.fork.ForkProtocolStack)

Example 72 with Protocol

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);
}
Also used : Message(org.jgroups.Message) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ForkProtocol(org.jgroups.fork.ForkProtocol) Protocol(org.jgroups.stack.Protocol) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 73 with Protocol

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;
}
Also used : MutableDigest(org.jgroups.util.MutableDigest) Digest(org.jgroups.util.Digest) MutableDigest(org.jgroups.util.MutableDigest) Protocol(org.jgroups.stack.Protocol)

Example 74 with Protocol

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));
    }
}
Also used : GMS(org.jgroups.protocols.pbcast.GMS) Protocol(org.jgroups.stack.Protocol)

Example 75 with Protocol

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;
}
Also used : Protocol(org.jgroups.stack.Protocol)

Aggregations

Protocol (org.jgroups.stack.Protocol)87 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)18 JChannel (org.jgroups.JChannel)17 GMS (org.jgroups.protocols.pbcast.GMS)17 STABLE (org.jgroups.protocols.pbcast.STABLE)13 ProtocolStack (org.jgroups.stack.ProtocolStack)12 ArrayList (java.util.ArrayList)9 Test (org.testng.annotations.Test)9 Property (org.jgroups.annotations.Property)6 HashMap (java.util.HashMap)5 ForkProtocol (org.jgroups.fork.ForkProtocol)5 ForkProtocolStack (org.jgroups.fork.ForkProtocolStack)5 InetAddress (java.net.InetAddress)4 ProtocolConfiguration (org.jgroups.conf.ProtocolConfiguration)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 Message (org.jgroups.Message)3 FORK (org.jgroups.protocols.FORK)3 UNICAST3 (org.jgroups.protocols.UNICAST3)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 Method (java.lang.reflect.Method)2