Search in sources :

Example 1 with NativeSocketOptions

use of io.grpc.netty.NettySocketSupport.NativeSocketOptions in project grpc-java by grpc.

the class Utils method getSocketOptions.

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);
    }
    Integer timeoutMillis = config.getOption(SO_TIMEOUT);
    if (timeoutMillis != null) {
        // in java, SO_TIMEOUT only applies to receiving
        b.setSocketOptionTimeoutMillis(timeoutMillis);
    }
    for (Map.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) {
        // may be null
        b.setTcpInfo(nativeOptions.tcpInfo);
        for (Map.Entry<String, String> entry : nativeOptions.otherInfo.entrySet()) {
            b.addOption(entry.getKey(), entry.getValue());
        }
    }
    return b.build();
}
Also used : ChannelOption(io.netty.channel.ChannelOption) NativeSocketOptions(io.grpc.netty.NettySocketSupport.NativeSocketOptions) AsciiString(io.netty.util.AsciiString) ChannelConfig(io.netty.channel.ChannelConfig) InternalChannelz(io.grpc.InternalChannelz) NativeSocketOptions(io.grpc.netty.NettySocketSupport.NativeSocketOptions) Map(java.util.Map)

Aggregations

InternalChannelz (io.grpc.InternalChannelz)1 NativeSocketOptions (io.grpc.netty.NettySocketSupport.NativeSocketOptions)1 ChannelConfig (io.netty.channel.ChannelConfig)1 ChannelOption (io.netty.channel.ChannelOption)1 AsciiString (io.netty.util.AsciiString)1 Map (java.util.Map)1