Search in sources :

Example 36 with View

use of org.jgroups.View in project JGroups by belaban.

the class FILE_PING method down.

public Object down(Event evt) {
    switch(evt.getType()) {
        case Event.VIEW_CHANGE:
            View old_view = view;
            boolean previous_coord = is_coord;
            Object retval = super.down(evt);
            View new_view = evt.getArg();
            handleView(new_view, old_view, previous_coord != is_coord);
            return retval;
    }
    return super.down(evt);
}
Also used : View(org.jgroups.View)

Example 37 with View

use of org.jgroups.View in project JGroups by belaban.

the class ConnectStressTest method testConcurrentJoining.

public void testConcurrentJoining() throws Exception {
    for (int i = 0; i < NUM; i++) {
        threads[i] = new MyThread(channels[i], i + 1, barrier);
        threads[i].start();
    }
    // causes all threads to call Channel.connect()
    barrier.await();
    System.out.println("*** Starting the connect phase ***");
    long target_time = System.currentTimeMillis() + 60000L;
    while (System.currentTimeMillis() < target_time) {
        View view = channels[0].getView();
        if (view != null) {
            int size = view.size();
            System.out.println("channel[0].view has " + size + " members (expected: " + NUM + ")");
            if (size >= NUM)
                break;
        }
        Util.sleep(1000L);
    }
    for (JChannel ch : channels) {
        View view = ch.getView();
        if (view != null)
            System.out.println(ch.getName() + ": size=" + view.size() + ", view-id: " + view.getViewId());
    }
    for (JChannel ch : channels) {
        View view = ch.getView();
        int size = view != null ? view.size() : 0;
        assert view != null && size == NUM : "view doesn't have size of " + NUM + " (has " + size + "): " + view;
    }
}
Also used : JChannel(org.jgroups.JChannel) View(org.jgroups.View)

Example 38 with View

use of org.jgroups.View in project JGroups by belaban.

the class MergeTest5 method testSplitWithNoCoordinator.

/**
 * Tests https://issues.jboss.org/browse/JGRP-2092:
 *     <pre>
 *     Host A view: B,A,C (where B should be coordinator)
 *     Host B view: C,A,B (where C should be coordinator)
 *     Host C view: A,B,C (where A should be coordinator)
 *     </pre>
 */
public void testSplitWithNoCoordinator() throws Exception {
    System.out.printf("Initial views:\n%s\n", printViews(a, b, c));
    View v1 = createView(5, b, a, c);
    View v2 = createView(5, c, a, b);
    System.out.printf("Injecting view %s into %s and %s into %s\n", v1, a.getName(), v2, b.getName());
    injectView(v1, a);
    injectView(v2, b);
    System.out.printf("\nViews after injection:\n%s\n", printViews(a, b, c));
    for (int x = 0; x < 20; x++) {
        View first = a.getView();
        if (first.equals(b.getView()) && first.equals(c.getView()))
            break;
        for (JChannel ch : Arrays.asList(a, b, c)) {
            MERGE3 merge = ch.getProtocolStack().findProtocol(MERGE3.class);
            // multicasts an INFO msg to everybody else
            merge.sendInfo();
        }
        Util.sleep(1000);
    }
    System.out.printf("\nFinal views:\n%s\n", printViews(a, b, c));
    Util.assertAllChannelsHaveSameView(a, b, c);
}
Also used : JChannel(org.jgroups.JChannel) MERGE3(org.jgroups.protocols.MERGE3) View(org.jgroups.View)

Example 39 with View

use of org.jgroups.View in project JGroups by belaban.

the class Topology method start.

public void start() throws Exception {
    channel = new JChannel(props).name(name);
    channel.setReceiver(new Receiver() {

        public void viewAccepted(View view) {
            setInternalState(view.getMembers());
        }

        public void setInternalState(java.util.List<Address> mbrs) {
            members.clear();
            for (Address mbr : mbrs) addNode(mbr);
            coordinator = mbrs.size() <= 1 || (mbrs.size() > 1 && mbrs.iterator().next().equals(my_addr));
            repaint();
        }
    });
    channel.connect(channel_name);
    my_addr = channel.getAddress();
    if (my_addr != null)
        setTitle(my_addr.toString());
    pack();
    setVisible(true);
}
Also used : JChannel(org.jgroups.JChannel) Address(org.jgroups.Address) Receiver(org.jgroups.Receiver) View(org.jgroups.View)

Example 40 with View

use of org.jgroups.View in project JGroups by belaban.

the class CounterServiceDemo method start.

public void start(JChannel ch) throws Exception {
    this.ch = ch;
    ch.setReceiver(new Receiver() {

        public void viewAccepted(View view) {
            System.out.println("-- view: " + view);
        }
    });
    loop();
}
Also used : Receiver(org.jgroups.Receiver) View(org.jgroups.View)

Aggregations

View (org.jgroups.View)51 Address (org.jgroups.Address)24 JChannel (org.jgroups.JChannel)14 GMS (org.jgroups.protocols.pbcast.GMS)6 Event (org.jgroups.Event)5 Receiver (org.jgroups.Receiver)5 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ViewId (org.jgroups.ViewId)3 IOException (java.io.IOException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 NetView (org.apache.geode.distributed.internal.membership.NetView)2 IpAddress (org.jgroups.stack.IpAddress)2 UUID (org.jgroups.util.UUID)2 java.io (java.io)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1