use of org.jgroups.ViewId in project geode by apache.
the class JGroupsMessenger method start.
@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void start() {
// create the configuration XML string for JGroups
String properties = this.jgStackConfig;
long start = System.currentTimeMillis();
// start the jgroups channel and establish the membership ID
boolean reconnecting = false;
try {
Object oldChannel = services.getConfig().getTransport().getOldDSMembershipInfo();
if (oldChannel != null) {
logger.debug("Reusing JGroups channel from previous system", properties);
myChannel = (JChannel) oldChannel;
// scrub the old channel
ViewId vid = new ViewId(new JGAddress(), 0);
View jgv = new View(vid, new ArrayList<>());
this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
UUID logicalAddress = (UUID) myChannel.getAddress();
if (logicalAddress instanceof JGAddress) {
((JGAddress) logicalAddress).setVmViewId(-1);
}
reconnecting = true;
} else {
logger.debug("JGroups configuration: {}", properties);
checkForIPv6();
InputStream is = new ByteArrayInputStream(properties.getBytes("UTF-8"));
myChannel = new JChannel(is);
}
} catch (Exception e) {
throw new GemFireConfigException("unable to create jgroups channel", e);
}
// give the stats to the jchannel statistics recorder
StatRecorder sr = (StatRecorder) myChannel.getProtocolStack().findProtocol(StatRecorder.class);
if (sr != null) {
sr.setServices(services);
}
Transport transport = (Transport) myChannel.getProtocolStack().getTransport();
transport.setMessenger(this);
nackack2HeaderId = ClassConfigurator.getProtocolId(NAKACK2.class);
try {
myChannel.setReceiver(null);
myChannel.setReceiver(new JGroupsReceiver());
if (!reconnecting) {
// apache g***** (whatever we end up calling it)
myChannel.connect("AG");
}
} catch (Exception e) {
myChannel.close();
throw new SystemConnectException("unable to create jgroups channel", e);
}
if (JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK) {
JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK = false;
throw new SystemConnectException("failing for test");
}
establishLocalAddress();
logger.info("JGroups channel {} (took {}ms)", (reconnecting ? "reinitialized" : "created"), System.currentTimeMillis() - start);
}
use of org.jgroups.ViewId in project geode by apache.
the class JGroupsMessenger method installView.
@Override
public void installView(NetView v) {
this.view = v;
if (this.jgAddress.getVmViewId() < 0) {
this.jgAddress.setVmViewId(this.localAddress.getVmViewId());
}
List<JGAddress> mbrs = new ArrayList<>(v.size());
mbrs.addAll(v.getMembers().stream().map(JGAddress::new).collect(Collectors.toList()));
ViewId vid = new ViewId(new JGAddress(v.getCoordinator()), v.getViewId());
View jgv = new View(vid, new ArrayList<>(mbrs));
logger.trace("installing JGroups view: {}", jgv);
this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
addressesWithIoExceptionsProcessed.clear();
if (encrypt != null) {
encrypt.installView(v);
}
synchronized (scheduledMcastSeqnos) {
for (DistributedMember mbr : v.getCrashedMembers()) {
scheduledMcastSeqnos.remove(mbr);
}
for (DistributedMember mbr : v.getShutdownMembers()) {
scheduledMcastSeqnos.remove(mbr);
}
}
}
use of org.jgroups.ViewId in project JGroups by belaban.
the class ViewTest method testEquals2.
public void testEquals2() {
View v1 = new View(new ViewId(a, 12345), new ArrayList<>(members));
View v2 = new View(a, 12345, new ArrayList<>(members));
assert v1.equals(v2);
View v3 = new View(a, 12543, new ArrayList<>(members));
assert !v1.equals(v3);
}
use of org.jgroups.ViewId in project JGroups by belaban.
the class ViewIdTest method setUp.
@BeforeClass
void setUp() throws UnknownHostException {
v1 = new ViewId(Util.createRandomAddress("A"), 22);
v2 = new ViewId(Util.createRandomAddress("B"), 21);
v3 = v1.copy();
v4 = new ViewId(Util.createRandomAddress("C"), 22);
}
use of org.jgroups.ViewId in project JGroups by belaban.
the class LargeMergeTest method testClusterFormationAfterMerge.
public void testClusterFormationAfterMerge() {
System.out.println("\nEnabling message traffic between members to start the merge");
for (JChannel ch : channels) {
DISCARD discard = ch.getProtocolStack().findProtocol(DISCARD.class);
discard.discardAll(false);
}
boolean merge_completed = true;
for (int i = 0; i < NUM; i++) {
merge_completed = true;
System.out.println();
Map<ViewId, Integer> views = new HashMap<>();
for (JChannel ch : channels) {
ViewId view_id = ch.getView().getViewId();
Integer val = views.get(view_id);
views.put(view_id, val == null ? 1 : val + 1);
int size = ch.getView().size();
if (size != NUM)
merge_completed = false;
}
if (i++ > 0) {
int num_singleton_views = 0;
for (Map.Entry<ViewId, Integer> entry : views.entrySet()) {
if (entry.getValue() == 1)
num_singleton_views++;
else {
System.out.println("==> " + entry.getKey() + ": " + entry.getValue() + " members");
}
}
if (num_singleton_views > 0)
System.out.println("==> " + num_singleton_views + " singleton views");
System.out.println("------------------\n" + getStats());
}
if (merge_completed)
break;
Util.sleep(5000);
}
if (!merge_completed) {
System.out.println("\nFinal cluster:");
for (JChannel ch : channels) {
int size = ch.getView().size();
System.out.println(ch.getAddress() + ": " + size + " members - " + (size == NUM ? "OK" : "FAIL"));
}
}
for (JChannel ch : channels) {
int size = ch.getView().size();
assert size == NUM : "Channel has " + size + " members, but should have " + NUM;
}
}
Aggregations