Example usage for io.netty.channel ChannelOption DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION

List of usage examples for io.netty.channel ChannelOption DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION

Introduction

In this page you can find the example usage for io.netty.channel ChannelOption DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION.

Prototype

ChannelOption DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION

To view the source code for io.netty.channel ChannelOption DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION.

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,/*www . j a  v a 2s .co 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.jsync.datagram.impl.DefaultDatagramSocket.java

License:Open Source License

@SuppressWarnings("deprecation")
public DefaultDatagramSocket(AsyncInternal async, io.jsync.datagram.InternetProtocolFamily family) {
    super(async, createChannel(family), async.getOrCreateContext());
    // Note: Look into why this has been deprecated...
    channel().config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true);
    context.getEventLoop().register(channel);
    channel.pipeline().addLast("handler", new DatagramServerHandler(this.async, this));
    channel().config().setMaxMessagesPerRead(1);
}

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

License:Open Source License

public DatagramSocketImpl(VertxInternal vertx, DatagramSocketOptions options) {
    super(vertx,// ww w.  j a  v  a 2  s.  c o 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.dns.impl.fix.DnsNameResolver.java

License:Apache License

/**
 * Creates a new DNS-based name resolver that communicates with the specified list of DNS servers.
 *
 * @param eventLoop the {@link EventLoop} which will perform the communication with the DNS servers
 * @param channelFactory the {@link ChannelFactory} that will create a {@link DatagramChannel}
 * @param nameServerAddresses the addresses of the DNS server. For each DNS query, a new stream is created from
 *                            this to determine which DNS server should be contacted for the next retry in case
 *                            of failure.
 * @param resolveCache the DNS resolved entries cache
 * @param queryTimeoutMillis timeout of each DNS query in millis
 * @param resolvedAddressTypes list of the protocol families
 * @param recursionDesired if recursion desired flag must be set
 * @param maxQueriesPerResolve the maximum allowed number of DNS queries for a given name resolution
 * @param traceEnabled if trace is enabled
 * @param maxPayloadSize the capacity of the datagram packet buffer
 * @param optResourceEnabled if automatic inclusion of a optional records is enabled
 * @param hostsFileEntriesResolver the {@link HostsFileEntriesResolver} used to check for local aliases
 * @param searchDomains TODO/*from w  w w.  j av  a 2 s.c om*/
 * @param ndots TODO
 */
public DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory,
        DnsServerAddresses nameServerAddresses, DnsCache resolveCache, long queryTimeoutMillis,
        InternetProtocolFamily[] resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve,
        boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled,
        HostsFileEntriesResolver hostsFileEntriesResolver, List<String> searchDomains, int ndots) {

    super(eventLoop);
    checkNotNull(channelFactory, "channelFactory");
    this.nameServerAddresses = checkNotNull(nameServerAddresses, "nameServerAddresses");
    this.queryTimeoutMillis = checkPositive(queryTimeoutMillis, "queryTimeoutMillis");
    this.resolvedAddressTypes = checkNonEmpty(resolvedAddressTypes, "resolvedAddressTypes");
    this.recursionDesired = recursionDesired;
    this.maxQueriesPerResolve = checkPositive(maxQueriesPerResolve, "maxQueriesPerResolve");
    this.traceEnabled = traceEnabled;
    this.maxPayloadSize = checkPositive(maxPayloadSize, "maxPayloadSize");
    this.optResourceEnabled = optResourceEnabled;
    this.hostsFileEntriesResolver = checkNotNull(hostsFileEntriesResolver, "hostsFileEntriesResolver");
    this.resolveCache = resolveCache;
    this.searchDomains = checkNotNull(searchDomains, "searchDomains");
    this.ndots = checkPositive(ndots, "ndots");

    Bootstrap b = new Bootstrap();
    b.group(executor());
    b.channelFactory(channelFactory);
    b.option(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true);
    final DnsResponseHandler responseHandler = new DnsResponseHandler(executor().<Channel>newPromise());
    b.handler(new ChannelInitializer<DatagramChannel>() {
        @Override
        protected void initChannel(DatagramChannel ch) throws Exception {
            ch.pipeline().addLast(DECODER, ENCODER, responseHandler);
        }
    });

    channelFuture = responseHandler.channelActivePromise;
    ch = (DatagramChannel) b.register().channel();
    ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(maxPayloadSize));

    ch.closeFuture().addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            resolveCache.clear();
        }
    });
}

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

License:Open Source License

public DefaultDatagramSocket(VertxInternal vertx, org.vertx.java.core.datagram.InternetProtocolFamily family) {
    super(vertx, createChannel(family), vertx.getOrCreateContext());
    channel().config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true);
    context.getEventLoop().register(channel);
    channel.pipeline().addLast("handler", new DatagramServerHandler(this.vertx, this));
    channel().config().setMaxMessagesPerRead(1);
}