Search in sources :

Example 1 with NAKACK2

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);
}
Also used : JChannel(org.jgroups.JChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) NetView(org.apache.geode.distributed.internal.membership.NetView) View(org.jgroups.View) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) ByteArrayInputStream(java.io.ByteArrayInputStream) GemFireConfigException(org.apache.geode.GemFireConfigException) ViewId(org.jgroups.ViewId) Event(org.jgroups.Event) UUID(org.jgroups.util.UUID) SystemConnectException(org.apache.geode.SystemConnectException)

Example 2 with NAKACK2

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));
        }
    }
}
Also used : NAKACK2(org.jgroups.protocols.pbcast.NAKACK2)

Example 3 with NAKACK2

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);
}
Also used : NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with NAKACK2

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
    }
}
Also used : NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) Address(org.jgroups.Address) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Digest(org.jgroups.util.Digest) HashMap(java.util.HashMap) GemFireIOException(org.apache.geode.GemFireIOException) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GemFireIOException (org.apache.geode.GemFireIOException)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnknownHostException (java.net.UnknownHostException)1 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)1 GemFireConfigException (org.apache.geode.GemFireConfigException)1 SystemConnectException (org.apache.geode.SystemConnectException)1 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 NetView (org.apache.geode.distributed.internal.membership.NetView)1 VersionedDataInputStream (org.apache.geode.internal.VersionedDataInputStream)1