Search in sources :

Example 26 with View

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

the class ViewTest method testDiff4.

public void testDiff4() {
    View one = View.create(a, 1, a, b, c, d, e, f, g);
    View two = View.create(b, 2, b, c, d, g, h, i);
    Address[][] diff = View.diff(one, two);
    System.out.println("diffs: " + printDiff(diff));
    Address[] joined = diff[0], left = diff[1];
    assert joined.length == 2;
    assert joined[0].equals(h) && joined[1].equals(i);
    assert left.length == 3;
    assert left[0].equals(a) && left[1].equals(e) && left[2].equals(f);
}
Also used : Address(org.jgroups.Address) View(org.jgroups.View)

Example 27 with View

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

the class ReplCacheDemo method start.

private void start(String props, String cluster_name, long rpc_timeout, long caching_time, boolean migrate_data, boolean use_l1_cache, int l1_max_entries, long l1_reaping_interval, int l2_max_entries, long l2_reaping_interval) throws Exception {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    cache = new ReplCache<>(props, cluster_name);
    cache.setCallTimeout(rpc_timeout);
    cache.setCachingTime(caching_time);
    cache.setMigrateData(migrate_data);
    JmxConfigurator.register(cache, server, BASENAME + ":name=cache");
    JmxConfigurator.register(cache.getL2Cache(), server, BASENAME + ":name=l2-cache");
    if (use_l1_cache) {
        Cache<String, String> l1_cache = new Cache<>();
        cache.setL1Cache(l1_cache);
        if (l1_reaping_interval > 0)
            l1_cache.enableReaping(l1_reaping_interval);
        if (l1_max_entries > 0)
            l1_cache.setMaxNumberOfEntries(l1_max_entries);
        JmxConfigurator.register(cache.getL1Cache(), server, BASENAME + ":name=l1-cache");
    }
    if (l2_max_entries > 0 || l2_reaping_interval > 0) {
        Cache<String, ReplCache.Value<String>> l2_cache = cache.getL2Cache();
        if (l2_max_entries > 0)
            l2_cache.setMaxNumberOfEntries(l2_max_entries);
        if (l2_reaping_interval > 0)
            l2_cache.enableReaping(l2_reaping_interval);
    }
    Runtime.getRuntime().addShutdownHook(new Thread(() -> cache.stop()));
    cache.start();
    model = new MyTableModel<String, String>();
    model.setMap(cache.getL2Cache().getInternalMap());
    cache.addChangeListener(model);
    frame = new JFrame("ReplCacheDemo");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    table = new MyTable(model);
    table.setPreferredScrollableViewportSize(new Dimension(500, 200));
    // table.setFillsViewportHeight(true); // JDK 6 specific
    table.setShowGrid(false);
    table.setFont(table.getFont().deriveFont(Font.BOLD));
    add(new JScrollPane(table));
    JPanel key = new JPanel(new FlowLayout(FlowLayout.LEFT));
    key.add(new JLabel("Key  "));
    key.add(key_field);
    add(key);
    JPanel value = new JPanel(new FlowLayout(FlowLayout.LEFT));
    value.add(new JLabel("Value"));
    value.add(value_field);
    add(value);
    JPanel repl_count = new JPanel(new FlowLayout(FlowLayout.LEFT));
    repl_count.add(new JLabel("Replication count"));
    repl_count.add(repl_count_field);
    add(repl_count);
    JPanel timeout = new JPanel(new FlowLayout(FlowLayout.LEFT));
    timeout.add(new JLabel("Timeout"));
    timeout.add(timeout_field);
    add(timeout);
    JPanel buttons = new JPanel();
    JButton put_button = createButton("Put");
    buttons.add(createButton("Put"));
    buttons.add(createButton("Remove"));
    buttons.add(createButton("Clear"));
    buttons.add(createButton("Rebalance"));
    buttons.add(createButton("Exit"));
    buttons.add(num_elements);
    add(buttons);
    setOpaque(true);
    root_pane.addTab("Data", this);
    JPanel perf_panel = new JPanel();
    perf_panel.setLayout(new BoxLayout(perf_panel, BoxLayout.Y_AXIS));
    perf_panel.setOpaque(true);
    root_pane.addTab("Perf test", perf_panel);
    perf_panel.add(status);
    status.setForeground(Color.BLUE);
    JPanel prefix = new JPanel(new FlowLayout(FlowLayout.LEFT));
    prefix.add(new JLabel("Key prefix"));
    prefix.add(perf_key_prefix);
    perf_panel.add(prefix);
    JPanel keys = new JPanel(new FlowLayout(FlowLayout.LEFT));
    keys.add(new JLabel("Number of keys to insert"));
    keys.add(perf_num_keys);
    perf_panel.add(keys);
    JPanel size = new JPanel(new FlowLayout(FlowLayout.LEFT));
    size.add(new JLabel("Size of each key (bytes)"));
    size.add(perf_size);
    size.add(new JLabel("    (ignored for now)"));
    perf_panel.add(size);
    JPanel perf_repl_count = new JPanel(new FlowLayout(FlowLayout.LEFT));
    perf_repl_count.add(new JLabel("Replication count"));
    perf_repl_count.add(perf_repl_count_field);
    perf_panel.add(perf_repl_count);
    JPanel perf_timeout = new JPanel(new FlowLayout(FlowLayout.LEFT));
    perf_timeout.add(new JLabel("Timeout"));
    perf_timeout.add(perf_timeout_field);
    perf_panel.add(perf_timeout);
    JPanel perf_buttons = new JPanel(new FlowLayout(FlowLayout.LEFT));
    perf_buttons.add(createButton("Start"));
    perf_buttons.add(createButton("Stop"));
    perf_buttons.add(createButton("Reset"));
    perf_buttons.add(createButton("Exit"));
    perf_panel.add(perf_buttons);
    frame.setContentPane(root_pane);
    frame.pack();
    frame.getRootPane().setDefaultButton(put_button);
    frame.setVisible(true);
    setTitle("ReplCacheDemo");
    cache.addReceiver(new Receiver() {

        public void viewAccepted(View new_view) {
            setTitle("ReplCacheDemo");
        }
    });
}
Also used : Receiver(org.jgroups.Receiver) View(org.jgroups.View) MBeanServer(javax.management.MBeanServer) ReplCache(org.jgroups.blocks.ReplCache) Cache(org.jgroups.blocks.Cache)

Example 28 with View

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

the class CounterServiceDemo method start.

void start(String props, String channel_name) throws Exception {
    ch = new JChannel(props);
    ch.setName(channel_name);
    ch.setReceiver(new Receiver() {

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

Example 29 with View

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

the class INJECT_VIEWTest method testInjectView.

public static void testInjectView() throws Exception {
    JChannel[] channels = null;
    try {
        channels = create(false, true, "testInjectView", "A", "B", "C");
        print(channels);
        View view = channels[channels.length - 1].getView();
        assert view.size() == channels.length : "view is " + view;
        String injectionViewString = "A=A/B;B=B/C;C=C";
        System.out.println("\ninjecting views: " + injectionViewString);
        for (JChannel channel : channels) {
            channel.getProtocolStack().addProtocol(new INJECT_VIEW());
        }
        for (JChannel channel : channels) {
            INJECT_VIEW iv = channel.getProtocolStack().findProtocol(INJECT_VIEW.class);
            iv.injectView(injectionViewString);
        }
        System.out.println("\nInjected views: " + injectionViewString);
        print(channels);
        System.out.println("\nchecking views: ");
        checkViews(channels, "A", "A", "B");
        System.out.println("\nA is OK");
        checkViews(channels, "B", "B", "C");
        System.out.println("\nB is OK");
        checkViews(channels, "C", "C");
        System.out.println("\nC is OK");
        System.out.println("\ndigests:");
        printDigests(channels);
        Address leader = determineLeader(channels, "A", "B", "C");
        long end_time = System.currentTimeMillis() + 30000;
        do {
            System.out.println("\n==== injecting merge events into " + leader + " ====");
            injectMergeEvent(channels, leader, "A", "B", "C");
            Util.sleep(1000);
            if (allChannelsHaveViewOf(channels, channels.length))
                break;
        } while (end_time > System.currentTimeMillis());
        System.out.println("\n");
        print(channels);
        assertAllChannelsHaveViewOf(channels, channels.length);
        System.out.println("\ndigests:");
        printDigests(channels);
    } finally {
        System.out.println("closing channels");
        close(channels);
        System.out.println("done");
    }
}
Also used : JChannel(org.jgroups.JChannel) Address(org.jgroups.Address) View(org.jgroups.View)

Example 30 with View

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

the class DeliveryManagerImpl method handleView.

/**
 * Updates the current view in use and returns a {@link Collection} with the members that left the cluster.
 */
public final Collection<Address> handleView(View newView) {
    View oldView;
    synchronized (deliverySet) {
        oldView = getAndSetView(newView);
        deliverySet.removeIf(this::removeMessage);
        notifyIfNeeded();
    }
    return View.leftMembers(oldView, newView);
}
Also used : 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