Search in sources :

Example 16 with View

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

the class ServerGmsImpl method handleViewChange.

/**
 * Called by the GMS when a VIEW is received.
 * @param view The view to be installed
 * @param digest   If view is a MergeView, the digest contains the seqnos of all members and has to be set by GMS
 */
public void handleViewChange(View view, Digest digest) {
    if (gms.isLeaving() && !view.containsMember(gms.getAddress()))
        return;
    View prev_view = gms.view();
    gms.installView(view, digest);
    Address prev_coord = prev_view != null ? prev_view.getCoord() : null, curr_coord = view.getCoord();
    if (!Objects.equals(curr_coord, prev_coord))
        coordChanged(prev_coord, curr_coord);
}
Also used : Address(org.jgroups.Address) View(org.jgroups.View)

Example 17 with View

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

the class TCPGOSSIP_Test method testDisconnectConnectTwo.

/**
 * Tests connect-disconnect-connect sequence for a group with two members (using the default configuration).
 */
public void testDisconnectConnectTwo() throws Exception {
    coordinator = createTcpgossipChannel("A");
    channel = createTcpgossipChannel("B");
    coordinator.connect(GROUP);
    channel.connect("DisconnectTest.testgroup-1");
    channel.disconnect();
    channel.connect(GROUP);
    View view = channel.getView();
    assert view.size() == 2;
    assert view.containsMember(channel.getAddress());
    assert view.containsMember(coordinator.getAddress());
}
Also used : View(org.jgroups.View)

Example 18 with View

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

the class TCPGOSSIP_Test method testConnectThreeChannelsWithGRAlreadyDown.

public void testConnectThreeChannelsWithGRAlreadyDown() throws Exception {
    JChannel third = null;
    try {
        coordinator = createTcpgossipChannel("A");
        channel = createTcpgossipChannel("B");
        // kill router
        gossipRouter.stop();
        // cannot discover others since GR is down
        coordinator.connect("testConnectThreeChannelsWithGRAlreadyDown");
        channel.connect("testConnectThreeChannelsWithGRAlreadyDown");
        third = createTcpgossipChannel("C");
        third.connect("testConnectThreeChannelsWithGRAlreadyDown");
        // restart and....
        gossipRouter.start();
        Util.waitUntilAllChannelsHaveSameView(60000, 1000, coordinator, channel, third);
        // confirm they found each other
        View view = channel.getView();
        assert channel.getView().size() == 3;
        assert third.getView().size() == 3;
        assert view.containsMember(channel.getAddress());
        assert view.containsMember(coordinator.getAddress());
    } finally {
        Util.close(third);
    }
}
Also used : JChannel(org.jgroups.JChannel) View(org.jgroups.View)

Example 19 with View

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

the class InfinispanStackMerge3Test method main.

public static void main(String[] args) throws Exception {
    Map<String, List<Long>> results = new HashMap<>();
    for (Supplier<TP> transport : TRANSPORTS) {
        results.put(transport.get().getClass().getSimpleName(), new LinkedList<>());
        for (int run = 0; run < RUNS; run++) {
            JChannel[] channels = new JChannel[MEMBERS];
            // Setup
            for (int member = 0; member < MEMBERS; member++) channels[member] = createChannel(transport.get(), String.valueOf(member + 1));
            Util.waitUntilAllChannelsHaveSameView(10_000, 500, channels);
            System.out.printf("-- run #%d: cluster formed:\n%s\n", run + 1, printViews(channels));
            // Partition
            Stream.of(channels).forEach(channel -> {
                GMS gms = channel.getProtocolStack().findProtocol(GMS.class);
                View view = View.create(channel.getAddress(), gms.getViewId().getId() + 1, channel.getAddress());
                gms.installView(view);
            });
            System.out.printf("-- injected partition (waiting for merge):\n%s\n", printViews(channels));
            // Merge
            long timeBeforeMerge = System.currentTimeMillis();
            Util.waitUntilAllChannelsHaveSameView(360_000, 100, channels);
            long timeAfterMerge = System.currentTimeMillis();
            System.out.printf("-- run #%d: %s cluster merged in %d ms:\n%s\n", run + 1, transport.get().getClass().getSimpleName(), timeAfterMerge - timeBeforeMerge, printViews(channels));
            // Cleanup
            Stream.of(channels).forEach(JChannel::close);
            results.get(transport.get().getClass().getSimpleName()).add(timeAfterMerge - timeBeforeMerge);
        }
    }
    printStats(results);
}
Also used : JChannel(org.jgroups.JChannel) GMS(org.jgroups.protocols.pbcast.GMS) View(org.jgroups.View)

Example 20 with View

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

the class ViewTest method testDiff3.

public void testDiff3() {
    View one = View.create(a, 1, a, b, c, d, e);
    View two = View.create(a, 2, a, b, c);
    Address[][] diff = View.diff(one, two);
    System.out.println("diffs: " + printDiff(diff));
    Address[] joined = diff[0], left = diff[1];
    assert joined.length == 0;
    assert left.length == 2;
    assert left[0].equals(d) && left[1].equals(e);
}
Also used : Address(org.jgroups.Address) 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