Example usage for io.netty.channel ChannelConfig getOptions

List of usage examples for io.netty.channel ChannelConfig getOptions

Introduction

In this page you can find the example usage for io.netty.channel ChannelConfig getOptions.

Prototype

Map<ChannelOption<?>, Object> getOptions();

Source Link

Document

Return all set ChannelOption 's.

Usage

From source file:io.grpc.netty.Utils.java

License:Apache License

static InternalChannelz.SocketOptions getSocketOptions(Channel channel) {
    ChannelConfig config = channel.config();
    InternalChannelz.SocketOptions.Builder b = new InternalChannelz.SocketOptions.Builder();

    // The API allows returning null but not sure if it can happen in practice.
    // Let's be paranoid and do null checking just in case.
    Integer lingerSeconds = config.getOption(SO_LINGER);
    if (lingerSeconds != null) {
        b.setSocketOptionLingerSeconds(lingerSeconds);
    }/*from w  w w.  j  av a2 s. com*/

    Integer timeoutMillis = config.getOption(SO_TIMEOUT);
    if (timeoutMillis != null) {
        // in java, SO_TIMEOUT only applies to receiving
        b.setSocketOptionTimeoutMillis(timeoutMillis);
    }

    for (Entry<ChannelOption<?>, Object> opt : config.getOptions().entrySet()) {
        ChannelOption<?> key = opt.getKey();
        // Constants are pooled, so there should only be one instance of each constant
        if (key.equals(SO_LINGER) || key.equals(SO_TIMEOUT)) {
            continue;
        }
        Object value = opt.getValue();
        // zpencer: Can a netty option be null?
        b.addOption(key.name(), String.valueOf(value));
    }

    NativeSocketOptions nativeOptions = NettySocketSupport.getNativeSocketOptions(channel);
    if (nativeOptions != null) {
        b.setTcpInfo(nativeOptions.tcpInfo); // may be null
        for (Entry<String, String> entry : nativeOptions.otherInfo.entrySet()) {
            b.addOption(entry.getKey(), entry.getValue());
        }
    }
    return b.build();
}