@SuppressWarnings("unchecked") public synchronized DatagramSocket pause() { if (demand > 0L) { demand = 0L; channel.config().setAutoRead(false); } return this; }
@SuppressWarnings("unchecked") public synchronized DatagramSocket resume() { if (demand == 0L) { demand = Long.MAX_VALUE; channel.config().setAutoRead(true); } return this; }
@Override public synchronized DatagramSocket fetch(long amount) { if (amount < 0L) { throw new IllegalArgumentException("Illegal fetch " + amount); } if (amount > 0L) { if (demand == 0L) { channel.config().setAutoRead(true); } demand += amount; if (demand < 0L) { demand = Long.MAX_VALUE; } } return this; }
@Override public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setOption(KQueueChannelOption.SO_REUSEPORT, options.isReusePort()); super.configure(channel, options); } }
@Override public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setOption(EpollChannelOption.SO_REUSEPORT, options.isReusePort()); super.configure(channel, options); }
public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setAllocator(PartialPooledByteBufAllocator.INSTANCE); 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().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()); } } } }
actualCtx = vertx.getOrCreateContext(); channel = transport.datagramChannel(this.dnsServer.getAddress() instanceof Inet4Address ? InternetProtocolFamily.IPv4 : InternetProtocolFamily.IPv6); channel.config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true); MaxMessagesRecvByteBufAllocator bufAllocator = channel.config().getRecvByteBufAllocator(); bufAllocator.maxMessagesPerRead(1); channel.config().setAllocator(PartialPooledByteBufAllocator.INSTANCE); actualCtx.nettyEventLoop().register(channel); if (options.getLogActivity()) {
private DatagramSocketImpl(VertxInternal vertx, DatagramSocketOptions options) { Transport transport = vertx.transport(); DatagramChannel channel = transport.datagramChannel(options.isIpV6() ? InternetProtocolFamily.IPv6 : InternetProtocolFamily.IPv4); transport.configure(channel, new DatagramSocketOptions(options)); ContextInternal context = vertx.getOrCreateContext(); channel.config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true); MaxMessagesRecvByteBufAllocator bufAllocator = channel.config().getRecvByteBufAllocator(); bufAllocator.maxMessagesPerRead(1); context.nettyEventLoop().register(channel); if (options.getLogActivity()) { channel.pipeline().addLast("logging", new LoggingHandler()); } VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createDatagramSocketMetrics(options) : null; this.channel = channel; this.context = context; this.demand = Long.MAX_VALUE; }
ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(maxPayloadSize));
@SuppressWarnings("unchecked") public synchronized DatagramSocket pause() { if (demand > 0L) { demand = 0L; channel.config().setAutoRead(false); } return this; }
@SuppressWarnings("unchecked") public synchronized DatagramSocket resume() { if (demand == 0L) { demand = Long.MAX_VALUE; channel.config().setAutoRead(true); } return this; }
@Override public synchronized DatagramSocket fetch(long amount) { if (amount < 0L) { throw new IllegalArgumentException("Illegal fetch " + amount); } if (amount > 0L) { if (demand == 0L) { channel.config().setAutoRead(true); } demand += amount; if (demand < 0L) { demand = Long.MAX_VALUE; } } return this; }
@Override public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setOption(EpollChannelOption.SO_REUSEPORT, options.isReusePort()); super.configure(channel, options); }
@Override public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setOption(KQueueChannelOption.SO_REUSEPORT, options.isReusePort()); super.configure(channel, options); } }
public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setAllocator(PartialPooledByteBufAllocator.INSTANCE); 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().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()); } } } }
actualCtx = vertx.getOrCreateContext(); channel = transport.datagramChannel(this.dnsServer.getAddress() instanceof Inet4Address ? InternetProtocolFamily.IPv4 : InternetProtocolFamily.IPv6); channel.config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true); MaxMessagesRecvByteBufAllocator bufAllocator = channel.config().getRecvByteBufAllocator(); bufAllocator.maxMessagesPerRead(1); channel.config().setAllocator(PartialPooledByteBufAllocator.INSTANCE); actualCtx.nettyEventLoop().register(channel); if (options.getLogActivity()) {
private DatagramSocketImpl(VertxInternal vertx, DatagramSocketOptions options) { Transport transport = vertx.transport(); DatagramChannel channel = transport.datagramChannel(options.isIpV6() ? InternetProtocolFamily.IPv6 : InternetProtocolFamily.IPv4); transport.configure(channel, new DatagramSocketOptions(options)); ContextInternal context = vertx.getOrCreateContext(); if (context.isMultiThreadedWorkerContext()) { throw new IllegalStateException("Cannot use DatagramSocket in a multi-threaded worker verticle"); } channel.config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true); MaxMessagesRecvByteBufAllocator bufAllocator = channel.config().getRecvByteBufAllocator(); bufAllocator.maxMessagesPerRead(1); context.nettyEventLoop().register(channel); if (options.getLogActivity()) { channel.pipeline().addLast("logging", new LoggingHandler()); } VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createDatagramSocketMetrics(options) : null; this.channel = channel; this.context = context; this.demand = Long.MAX_VALUE; }
/** * Leave a multicast group. * * @param multicastAddress multicast address of the group to leave * * @return a {@link Publisher} that will be complete when the group has been left */ @Override public Mono<Void> leave(final InetAddress multicastAddress, NetworkInterface iface) { if (null == iface && null != datagramChannel.config().getNetworkInterface()) { iface = datagramChannel.config().getNetworkInterface(); } final ChannelFuture future; if (null != iface) { future = datagramChannel.leaveGroup(new InetSocketAddress(multicastAddress, datagramChannel.localAddress() .getPort()), iface); } else { future = datagramChannel.leaveGroup(multicastAddress); } return FutureMono.from(future) .doOnSuccess(v -> log.info(format(future.channel(), "JOIN {}"), multicastAddress)); }
/** * Join a multicast group. * * @param multicastAddress multicast address of the group to join * * @return a {@link Publisher} that will be complete when the group has been joined */ @Override public Mono<Void> join(final InetAddress multicastAddress, NetworkInterface iface) { if (null == iface && null != datagramChannel.config().getNetworkInterface()) { iface = datagramChannel.config().getNetworkInterface(); } final ChannelFuture future; if (null != iface) { future = datagramChannel.joinGroup(new InetSocketAddress(multicastAddress, datagramChannel.localAddress() .getPort()), iface); } else { future = datagramChannel.joinGroup(multicastAddress); } return FutureMono.from(future) .doOnSuccess(v -> log.info("JOIN {}", multicastAddress)); }
/** * Leave a multicast group. * * @param multicastAddress multicast address of the group to leave * * @return a {@link Publisher} that will be complete when the group has been left */ @Override public Mono<Void> leave(final InetAddress multicastAddress, NetworkInterface iface) { if (null == iface && null != datagramChannel.config().getNetworkInterface()) { iface = datagramChannel.config().getNetworkInterface(); } final ChannelFuture future; if (null != iface) { future = datagramChannel.leaveGroup(new InetSocketAddress(multicastAddress, datagramChannel.localAddress() .getPort()), iface); } else { future = datagramChannel.leaveGroup(multicastAddress); } return FutureMono.from(future) .doOnSuccess(v -> log.info(format(future.channel(), "JOIN {}"), multicastAddress)); }