Example usage for io.netty.channel.socket InternetProtocolFamily IPv6

List of usage examples for io.netty.channel.socket InternetProtocolFamily IPv6

Introduction

In this page you can find the example usage for io.netty.channel.socket InternetProtocolFamily IPv6.

Prototype

InternetProtocolFamily IPv6

To view the source code for io.netty.channel.socket InternetProtocolFamily IPv6.

Click Source Link

Usage

From source file:io.advantageous.conekt.datagram.impl.DatagramSocketImpl.java

License:Open Source License

public DatagramSocketImpl(ConektInternal vertx, DatagramSocketOptions options) {
    super(vertx,/*from w w w  . ja  v a2 s . c o  m*/
            createChannel(
                    options.isIpV6() ? io.advantageous.conekt.datagram.impl.InternetProtocolFamily.IPv6
                            : io.advantageous.conekt.datagram.impl.InternetProtocolFamily.IPv4,
                    new DatagramSocketOptions(options)),
            vertx.getOrCreateContext(), options);
    ContextImpl creatingContext = vertx.getContext();
    if (creatingContext != null && creatingContext.isMultiThreadedWorkerContext()) {
        throw new IllegalStateException("Cannot use DatagramSocket in a multi-threaded worker verticle");
    }
    channel().config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true);
    context.nettyEventLoop().register(channel);
    channel.pipeline().addLast("handler", new DatagramServerHandler(this));
    channel().config().setMaxMessagesPerRead(1);
}

From source file:io.advantageous.conekt.datagram.impl.DatagramSocketImpl.java

License:Open Source License

private static NioDatagramChannel createChannel(
        io.advantageous.conekt.datagram.impl.InternetProtocolFamily family, DatagramSocketOptions options) {
    NioDatagramChannel channel;//from  w w  w  .j  a v  a 2 s .  c om
    if (family == null) {
        channel = new NioDatagramChannel();
    } else {
        switch (family) {
        case IPv4:
            channel = new NioDatagramChannel(InternetProtocolFamily.IPv4);
            break;
        case IPv6:
            channel = new NioDatagramChannel(InternetProtocolFamily.IPv6);
            break;
        default:
            channel = new NioDatagramChannel();
        }
    }
    if (options.getSendBufferSize() != -1) {
        channel.config().setSendBufferSize(options.getSendBufferSize());
    }
    if (options.getReceiveBufferSize() != -1) {
        channel.config().setReceiveBufferSize(options.getReceiveBufferSize());
        channel.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(options.getReceiveBufferSize()));
    }
    channel.config().setReuseAddress(options.isReuseAddress());
    if (options.getTrafficClass() != -1) {
        channel.config().setTrafficClass(options.getTrafficClass());
    }
    channel.config().setBroadcast(options.isBroadcast());
    channel.config().setLoopbackModeDisabled(options.isLoopbackModeDisabled());
    if (options.getMulticastTimeToLive() != -1) {
        channel.config().setTimeToLive(options.getMulticastTimeToLive());
    }
    if (options.getMulticastNetworkInterface() != null) {
        try {
            channel.config()
                    .setNetworkInterface(NetworkInterface.getByName(options.getMulticastNetworkInterface()));
        } catch (SocketException e) {
            throw new IllegalArgumentException(
                    "Could not find network interface with name " + options.getMulticastNetworkInterface());
        }
    }
    return channel;
}

From source file:io.hekate.cluster.seed.multicast.MulticastSeedNodeProvider.java

License:Apache License

/**
 * Constructs new instance./*from   www.  ja  va  2  s  .  c  om*/
 *
 * @param cfg Configuration.
 *
 * @throws UnknownHostException If failed to resolve multicast group address.
 */
public MulticastSeedNodeProvider(MulticastSeedNodeProviderConfig cfg) throws UnknownHostException {
    ConfigCheck check = ConfigCheck.get(getClass());

    check.notNull(cfg, "configuration");
    check.positive(cfg.getPort(), "port");
    check.nonNegative(cfg.getTtl(), "TTL");
    check.notEmpty(cfg.getGroup(), "multicast group");
    check.positive(cfg.getInterval(), "discovery interval");
    check.positive(cfg.getWaitTime(), "wait time");
    check.that(cfg.getInterval() < cfg.getWaitTime(), "discovery interval must be greater than wait time "
            + "[discovery-interval=" + cfg.getInterval() + ", wait-time=" + cfg.getWaitTime() + ']');

    InetAddress groupAddress = InetAddress.getByName(cfg.getGroup());

    check.isTrue(groupAddress.isMulticastAddress(),
            "address is not a multicast address [address=" + groupAddress + ']');

    group = new InetSocketAddress(groupAddress, cfg.getPort());
    ttl = cfg.getTtl();
    interval = cfg.getInterval();
    waitTime = cfg.getWaitTime();
    loopBackDisabled = cfg.isLoopBackDisabled();

    ipVer = group.getAddress() instanceof Inet6Address ? InternetProtocolFamily.IPv6
            : InternetProtocolFamily.IPv4;
}

From source file:io.jsync.datagram.impl.DefaultDatagramSocket.java

License:Open Source License

private static NioDatagramChannel createChannel(io.jsync.datagram.InternetProtocolFamily family) {
    if (family == null) {
        return new NioDatagramChannel();
    }//from   w  ww  .  jav a  2s . co  m
    switch (family) {
    case IPv4:
        return new NioDatagramChannel(InternetProtocolFamily.IPv4);
    case IPv6:
        return new NioDatagramChannel(InternetProtocolFamily.IPv6);
    default:
        return new NioDatagramChannel();
    }
}

From source file:io.vertx.core.datagram.impl.DatagramSocketImpl.java

License:Open Source License

public DatagramSocketImpl(VertxInternal vertx, DatagramSocketOptions options) {
    super(vertx,/* ww w. ja v a  2s .  co m*/
            createChannel(
                    options.isIpV6() ? io.vertx.core.datagram.impl.InternetProtocolFamily.IPv6
                            : io.vertx.core.datagram.impl.InternetProtocolFamily.IPv4,
                    new DatagramSocketOptions(options)),
            vertx.getOrCreateContext());
    ContextImpl creatingContext = vertx.getContext();
    if (creatingContext != null && creatingContext.isMultiThreadedWorkerContext()) {
        throw new IllegalStateException("Cannot use DatagramSocket in a multi-threaded worker verticle");
    }
    channel().config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true);
    context.nettyEventLoop().register(channel);
    if (options.getLogActivity()) {
        channel().pipeline().addLast("logging", new LoggingHandler());
    }
    channel.pipeline().addLast("handler", new DatagramServerHandler(this));
    channel().config().setMaxMessagesPerRead(1);
    channel().config().setAllocator(PartialPooledByteBufAllocator.INSTANCE);
    metrics = vertx.metricsSPI().createMetrics(this, (DatagramSocketOptions) options);
}

From source file:io.vertx.core.datagram.impl.DatagramSocketImpl.java

License:Open Source License

private static NioDatagramChannel createChannel(io.vertx.core.datagram.impl.InternetProtocolFamily family,
        DatagramSocketOptions options) {
    NioDatagramChannel channel;/*  ww w . java 2  s . c o m*/
    if (family == null) {
        channel = new NioDatagramChannel();
    } else {
        switch (family) {
        case IPv4:
            channel = new NioDatagramChannel(InternetProtocolFamily.IPv4);
            break;
        case IPv6:
            channel = new NioDatagramChannel(InternetProtocolFamily.IPv6);
            break;
        default:
            channel = new NioDatagramChannel();
        }
    }
    if (options.getSendBufferSize() != -1) {
        channel.config().setSendBufferSize(options.getSendBufferSize());
    }
    if (options.getReceiveBufferSize() != -1) {
        channel.config().setReceiveBufferSize(options.getReceiveBufferSize());
        channel.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(options.getReceiveBufferSize()));
    }
    channel.config().setReuseAddress(options.isReuseAddress());
    if (options.getTrafficClass() != -1) {
        channel.config().setTrafficClass(options.getTrafficClass());
    }
    channel.config().setBroadcast(options.isBroadcast());
    channel.config().setLoopbackModeDisabled(options.isLoopbackModeDisabled());
    if (options.getMulticastTimeToLive() != -1) {
        channel.config().setTimeToLive(options.getMulticastTimeToLive());
    }
    if (options.getMulticastNetworkInterface() != null) {
        try {
            channel.config()
                    .setNetworkInterface(NetworkInterface.getByName(options.getMulticastNetworkInterface()));
        } catch (SocketException e) {
            throw new IllegalArgumentException(
                    "Could not find network interface with name " + options.getMulticastNetworkInterface());
        }
    }
    return channel;
}

From source file:io.vertx.core.net.impl.transport.Transport.java

License:Open Source License

/**
 * @return a new datagram channel//from   ww w.j a  va  2  s. c  o m
 */
public DatagramChannel datagramChannel(InternetProtocolFamily family) {
    switch (family) {
    case IPv4:
        return new NioDatagramChannel(InternetProtocolFamily.IPv4);
    case IPv6:
        return new NioDatagramChannel(InternetProtocolFamily.IPv6);
    default:
        throw new UnsupportedOperationException();
    }
}

From source file:org.vertx.java.core.datagram.impl.DefaultDatagramSocket.java

License:Open Source License

private static NioDatagramChannel createChannel(org.vertx.java.core.datagram.InternetProtocolFamily family) {
    if (family == null) {
        return new NioDatagramChannel();
    }//from  ww  w. j av a2  s.c  om
    switch (family) {
    case IPv4:
        return new NioDatagramChannel(InternetProtocolFamily.IPv4);
    case IPv6:
        return new NioDatagramChannel(InternetProtocolFamily.IPv6);
    default:
        return new NioDatagramChannel();
    }
}

From source file:reactor.io.net.impl.netty.udp.NettyDatagramServer.java

License:Apache License

private InternetProtocolFamily toNettyFamily(ProtocolFamily family) {
    if (family == null) {
        return null;
    }//from ww  w  . java  2 s .  c  o  m
    switch (family.name()) {
    case "INET":
        return InternetProtocolFamily.IPv4;
    case "INET6":
        return InternetProtocolFamily.IPv6;
    default:
        throw new IllegalArgumentException("Unsupported protocolFamily: " + family.name());
    }
}