Search in sources :

Example 1 with SuppressJava6Requirement

use of io.netty.util.internal.SuppressJava6Requirement in project netty by netty.

the class NioDatagramChannel method leaveGroup.

@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@Override
public ChannelFuture leaveGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source, ChannelPromise promise) {
    checkJavaVersion();
    ObjectUtil.checkNotNull(multicastAddress, "multicastAddress");
    ObjectUtil.checkNotNull(networkInterface, "networkInterface");
    synchronized (this) {
        if (memberships != null) {
            List<MembershipKey> keys = memberships.get(multicastAddress);
            if (keys != null) {
                Iterator<MembershipKey> keyIt = keys.iterator();
                while (keyIt.hasNext()) {
                    MembershipKey key = keyIt.next();
                    if (networkInterface.equals(key.networkInterface())) {
                        if (source == null && key.sourceAddress() == null || source != null && source.equals(key.sourceAddress())) {
                            key.drop();
                            keyIt.remove();
                        }
                    }
                }
                if (keys.isEmpty()) {
                    memberships.remove(multicastAddress);
                }
            }
        }
    }
    promise.setSuccess();
    return promise;
}
Also used : MembershipKey(java.nio.channels.MembershipKey) SuppressJava6Requirement(io.netty.util.internal.SuppressJava6Requirement)

Example 2 with SuppressJava6Requirement

use of io.netty.util.internal.SuppressJava6Requirement in project netty by netty.

the class NioDatagramChannel method block.

/**
 * Block the given sourceToBlock address for the given multicastAddress on the given networkInterface
 */
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@Override
public ChannelFuture block(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock, ChannelPromise promise) {
    checkJavaVersion();
    ObjectUtil.checkNotNull(multicastAddress, "multicastAddress");
    ObjectUtil.checkNotNull(sourceToBlock, "sourceToBlock");
    ObjectUtil.checkNotNull(networkInterface, "networkInterface");
    synchronized (this) {
        if (memberships != null) {
            List<MembershipKey> keys = memberships.get(multicastAddress);
            for (MembershipKey key : keys) {
                if (networkInterface.equals(key.networkInterface())) {
                    try {
                        key.block(sourceToBlock);
                    } catch (IOException e) {
                        promise.setFailure(e);
                    }
                }
            }
        }
    }
    promise.setSuccess();
    return promise;
}
Also used : MembershipKey(java.nio.channels.MembershipKey) IOException(java.io.IOException) SuppressJava6Requirement(io.netty.util.internal.SuppressJava6Requirement)

Example 3 with SuppressJava6Requirement

use of io.netty.util.internal.SuppressJava6Requirement in project netty by netty.

the class ReferenceCountedOpenSslEngine method getSSLParameters.

@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@Override
public final synchronized SSLParameters getSSLParameters() {
    SSLParameters sslParameters = super.getSSLParameters();
    int version = PlatformDependent.javaVersion();
    if (version >= 7) {
        sslParameters.setEndpointIdentificationAlgorithm(endPointIdentificationAlgorithm);
        Java7SslParametersUtils.setAlgorithmConstraints(sslParameters, algorithmConstraints);
        if (version >= 8) {
            if (sniHostNames != null) {
                Java8SslUtils.setSniHostNames(sslParameters, sniHostNames);
            }
            if (!isDestroyed()) {
                Java8SslUtils.setUseCipherSuitesOrder(sslParameters, (SSL.getOptions(ssl) & SSL.SSL_OP_CIPHER_SERVER_PREFERENCE) != 0);
            }
            Java8SslUtils.setSNIMatchers(sslParameters, matchers);
        }
    }
    return sslParameters;
}
Also used : SSLParameters(javax.net.ssl.SSLParameters) SuppressJava6Requirement(io.netty.util.internal.SuppressJava6Requirement)

Example 4 with SuppressJava6Requirement

use of io.netty.util.internal.SuppressJava6Requirement in project netty by netty.

the class DatagramUnicastIPv6Test method assumeIpv6Supported.

@SuppressJava6Requirement(reason = "Guarded by java version check")
@BeforeAll
public static void assumeIpv6Supported() {
    try {
        if (PlatformDependent.javaVersion() < 7) {
            throw new UnsupportedOperationException();
        }
        Channel channel = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET6);
        channel.close();
    } catch (UnsupportedOperationException e) {
        throw new AssumptionViolatedException("IPv6 not supported", e);
    } catch (IOException ignore) {
    // Ignore
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) Channel(java.nio.channels.Channel) IOException(java.io.IOException) BeforeAll(org.junit.jupiter.api.BeforeAll) SuppressJava6Requirement(io.netty.util.internal.SuppressJava6Requirement)

Example 5 with SuppressJava6Requirement

use of io.netty.util.internal.SuppressJava6Requirement in project netty by netty.

the class ByteBufIndexOfBenchmark method init.

@Setup(Level.Trial)
@SuppressJava6Requirement(reason = "using SplittableRandom to reliably produce data")
public void init() {
    System.setProperty("io.netty.noUnsafe", Boolean.valueOf(noUnsafe).toString());
    SplittableRandom random = new SplittableRandom(seed);
    permutations = 1 << logPermutations;
    this.data = new ByteBuf[permutations];
    final ByteBufAllocator allocator = pooled ? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT;
    for (int i = 0; i < permutations; ++i) {
        data[i] = direct ? allocator.directBuffer(size, size) : allocator.heapBuffer(size, size);
        for (int j = 0; j < size; j++) {
            int value = random.nextInt(Byte.MIN_VALUE, Byte.MAX_VALUE + 1);
            // turn any found value into something different
            if (value == needleByte) {
                if (needleByte != 1) {
                    value = 1;
                } else {
                    value = 0;
                }
            }
            data[i].setByte(j, value);
        }
        final int foundIndex = random.nextInt(Math.max(0, size - 8), size);
        data[i].setByte(foundIndex, needleByte);
    }
}
Also used : UnpooledByteBufAllocator(io.netty.buffer.UnpooledByteBufAllocator) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) SplittableRandom(java.util.SplittableRandom) SuppressJava6Requirement(io.netty.util.internal.SuppressJava6Requirement) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

SuppressJava6Requirement (io.netty.util.internal.SuppressJava6Requirement)8 MembershipKey (java.nio.channels.MembershipKey)3 IOException (java.io.IOException)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 UnpooledByteBufAllocator (io.netty.buffer.UnpooledByteBufAllocator)1 BigInteger (java.math.BigInteger)1 InetAddress (java.net.InetAddress)1 Channel (java.nio.channels.Channel)1 PrivateKey (java.security.PrivateKey)1 CertificateException (java.security.cert.CertificateException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SplittableRandom (java.util.SplittableRandom)1 SSLParameters (javax.net.ssl.SSLParameters)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Setup (org.openjdk.jmh.annotations.Setup)1 CertificateAlgorithmId (sun.security.x509.CertificateAlgorithmId)1