org.jgroups.stack.LargestWinningPolicy Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including
all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and
JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
package org.jgroups.stack;
import org.jgroups.Address;
import org.jgroups.Membership;
import org.jgroups.protocols.pbcast.GMS;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Policy which picks the new coordinator in a merge from the largest subview.
* JIRA: https://issues.redhat.com/browse/JGRP-1976
* @author Osamu Nagano
* @since 3.6.7
*/
public class LargestWinningPolicy extends GMS.DefaultMembershipPolicy {
/**
* Called when a merge happened. The largest subview wins.
*/
public List getNewMembership(final Collection> subviews) {
ArrayList> aSubviews=new ArrayList<>(subviews);
int sLargest = 0;
int iLargest = 0;
for (int i = 0; i < aSubviews.size(); i++) {
int size = aSubviews.get(i).size();
if (size > sLargest) {
sLargest = size;
iLargest = i;
}
}
Membership mbrs = new Membership(aSubviews.get(iLargest));
for (int i = 0; i < aSubviews.size(); i++)
if (i != iLargest)
mbrs.add(aSubviews.get(i));
return mbrs.getMembers();
}
}