List of usage examples for io.netty.channel.socket DatagramChannel config
@Override DatagramChannelConfig config();
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 2s . c o m*/ * @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:io.vertx.core.net.impl.transport.EpollTransport.java
License:Open Source License
@Override public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setOption(EpollChannelOption.SO_REUSEPORT, options.isReusePort()); super.configure(channel, options); }
From source file:io.vertx.core.net.impl.transport.KQueueTransport.java
License:Open Source License
@Override public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setOption(KQueueChannelOption.SO_REUSEPORT, options.isReusePort()); super.configure(channel, options); }
From source file:io.vertx.core.net.impl.transport.Transport.java
License:Open Source License
public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setAllocator(PartialPooledByteBufAllocator.INSTANCE); if (options.getSendBufferSize() != -1) { channel.config().setSendBufferSize(options.getSendBufferSize()); }//from w w w . j a va2 s . c om if (options.getReceiveBufferSize() != -1) { channel.config().setReceiveBufferSize(options.getReceiveBufferSize()); channel.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } channel.config().setOption(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); if (options.getTrafficClass() != -1) { channel.config().setTrafficClass(options.getTrafficClass()); } channel.config().setBroadcast(options.isBroadcast()); if (this == Transport.JDK) { 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()); } } } }