use of org.jgroups.protocols.pbcast.NAKACK2 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.protocols.pbcast.NAKACK2 in project geode by apache.
the class JGroupsMessenger method getMessageState.
@Override
public void getMessageState(InternalDistributedMember target, Map state, boolean includeMulticast) {
if (includeMulticast) {
NAKACK2 nakack = (NAKACK2) myChannel.getProtocolStack().findProtocol("NAKACK2");
if (nakack != null) {
long seqno = nakack.getCurrentSeqno();
state.put("JGroups.mcastState", Long.valueOf(seqno));
}
}
}
use of org.jgroups.protocols.pbcast.NAKACK2 in project geode by apache.
the class JGroupsMessengerJUnitTest method testGetMessageState.
@Test
public void testGetMessageState() throws Exception {
initMocks(true);
// do some multicast messaging
messenger.testMulticast(50);
NAKACK2 nakack = (NAKACK2) messenger.myChannel.getProtocolStack().findProtocol("NAKACK2");
assertNotNull(nakack);
long seqno = nakack.getCurrentSeqno();
Map state = new HashMap();
messenger.getMessageState(null, state, true);
assertEquals(1, state.size());
Long stateLong = (Long) state.values().iterator().next();
assertTrue("expected multicast state to be at least " + seqno + " but it was " + stateLong.longValue(), stateLong.longValue() >= seqno);
}
use of org.jgroups.protocols.pbcast.NAKACK2 in project geode by apache.
the class JGroupsMessengerJUnitTest method testWaitForMessageStateThrowsExceptionIfMessagesMissing.
@Test
public void testWaitForMessageStateThrowsExceptionIfMessagesMissing() throws Exception {
initMocks(true);
NAKACK2 nakack = mock(NAKACK2.class);
Digest digest = mock(Digest.class);
when(nakack.getDigest(any(Address.class))).thenReturn(digest);
when(digest.get(any(Address.class))).thenReturn(new long[] { 0, 0 }, new long[] { 2, 50 }, new long[] { 49, 50 });
try {
// message 50 will never arrive
Map state = new HashMap();
state.put("JGroups.mcastState", Long.valueOf(50));
InternalDistributedMember mbr = createAddress(1234);
messenger.scheduledMcastSeqnos.put(mbr, new JGroupsMessenger.MessageTracker(30));
messenger.waitForMessageState(mbr, state);
fail("expected a GemFireIOException to be thrown");
} catch (GemFireIOException e) {
// pass
}
}
Aggregations