Example usage for java.nio.channels DatagramChannel getOption

List of usage examples for java.nio.channels DatagramChannel getOption

Introduction

In this page you can find the example usage for java.nio.channels DatagramChannel getOption.

Prototype

<T> T getOption(SocketOption<T> name) throws IOException;

Source Link

Document

Returns the value of a socket option.

Usage

From source file:org.apache.nifi.io.nio.ChannelListener.java

private DatagramChannel createAndBindDatagramChannel(final InetAddress nicIPAddress, final int port,
        final int receiveBufferSize) throws IOException {
    final DatagramChannel dChannel = DatagramChannel.open();
    dChannel.configureBlocking(false);/*from  w w w .  ja v a 2  s .c  o m*/
    if (receiveBufferSize > 0) {
        dChannel.setOption(StandardSocketOptions.SO_RCVBUF, receiveBufferSize);
        final int actualReceiveBufSize = dChannel.getOption(StandardSocketOptions.SO_RCVBUF);
        if (actualReceiveBufSize < receiveBufferSize) {
            LOGGER.warn(this + " attempted to set UDP Receive Buffer Size to " + receiveBufferSize
                    + " bytes but could only set to " + actualReceiveBufSize
                    + "bytes. You may want to consider changing the Operating System's "
                    + "maximum receive buffer");
        }
    }
    dChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    dChannel.bind(new InetSocketAddress(nicIPAddress, port));
    return dChannel;
}