Search in sources :

Example 16 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method check_joinAnySource_multiple_joins.

private void check_joinAnySource_multiple_joins(InetAddress group, NetworkInterface networkInterface) throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey1 = dc.join(group, networkInterface);
    MembershipKey membershipKey2 = dc.join(group, loopbackInterface);
    assertFalse(membershipKey1.equals(membershipKey2));
    MembershipKey membershipKey1_2 = dc.join(group, networkInterface);
    assertEquals(membershipKey1, membershipKey1_2);
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 17 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method test_unblock_mixedAddressTypes_IPv4.

public void test_unblock_mixedAddressTypes_IPv4() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey = dc.join(GOOD_MULTICAST_IPv4, ipv4NetworkInterface);
    try {
        membershipKey.unblock(UNICAST_IPv6_1);
        fail();
    } catch (IllegalStateException expected) {
    // Either of these exceptions are fine
    } catch (IllegalArgumentException expected) {
    // Either of these exceptions are fine
    }
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 18 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method test_unblock_multipleUnblocksFail.

public void test_unblock_multipleUnblocksFail() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey = dc.join(GOOD_MULTICAST_IPv4, ipv4NetworkInterface);
    try {
        membershipKey.unblock(UNICAST_IPv4_1);
        fail();
    } catch (IllegalStateException expected) {
    }
    assertTrue(membershipKey.isValid());
    membershipKey.block(UNICAST_IPv4_1);
    membershipKey.unblock(UNICAST_IPv4_1);
    try {
        membershipKey.unblock(UNICAST_IPv4_1);
        fail();
    } catch (IllegalStateException expected) {
    }
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 19 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method check_dropSourceSpecific_sourceKeysAreIndependent.

private void check_dropSourceSpecific_sourceKeysAreIndependent(InetAddress groupAddress, InetAddress sourceAddress1, InetAddress sourceAddress2, NetworkInterface networkInterface) throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey1 = dc.join(groupAddress, networkInterface, sourceAddress1);
    MembershipKey membershipKey2 = dc.join(groupAddress, networkInterface, sourceAddress2);
    assertFalse(membershipKey1.equals(membershipKey2));
    assertTrue(membershipKey1.isValid());
    assertTrue(membershipKey2.isValid());
    membershipKey1.drop();
    assertFalse(membershipKey1.isValid());
    assertTrue(membershipKey2.isValid());
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 20 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method test_drop_keyBehaviorAfterDrop.

public void test_drop_keyBehaviorAfterDrop() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey = dc.join(GOOD_MULTICAST_IPv4, ipv4NetworkInterface, UNICAST_IPv4_1);
    membershipKey.drop();
    assertFalse(membershipKey.isValid());
    try {
        membershipKey.block(UNICAST_IPv4_1);
        fail();
    } catch (IllegalStateException expected) {
    }
    try {
        membershipKey.unblock(UNICAST_IPv4_1);
        fail();
    } catch (IllegalStateException expected) {
    }
    assertSame(dc, membershipKey.channel());
    assertSame(GOOD_MULTICAST_IPv4, membershipKey.group());
    assertSame(UNICAST_IPv4_1, membershipKey.sourceAddress());
    assertSame(ipv4NetworkInterface, membershipKey.networkInterface());
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Aggregations

MembershipKey (java.nio.channels.MembershipKey)25 DatagramChannel (java.nio.channels.DatagramChannel)22 SuppressJava6Requirement (io.netty.util.internal.SuppressJava6Requirement)3 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 ByteBuffer (java.nio.ByteBuffer)2 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1