@Test public void toAddress_other() throws Exception { final String name = "my name"; SocketAddress other = new SocketAddress() { @Override public String toString() { return name; } }; assertEquals( Address.newBuilder().setOtherAddress( OtherAddress .newBuilder() .setName(name)) .build(), ChannelzProtoUtil.toAddress(other)); }
static Address toAddress(SocketAddress address) { Preconditions.checkNotNull(address); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetSocketAddress inetAddress = (InetSocketAddress) address; builder.setTcpipAddress( TcpIpAddress .newBuilder() .setIpAddress( ByteString.copyFrom(inetAddress.getAddress().getAddress())) .setPort(inetAddress.getPort()) .build()); } else if (address.getClass().getName().endsWith("io.netty.channel.unix.DomainSocketAddress")) { builder.setUdsAddress( UdsAddress .newBuilder() .setFilename(address.toString()) .build()); } else { builder.setOtherAddress(OtherAddress.newBuilder().setName(address.toString()).build()); } return builder.build(); }
ChannelzProtoUtil { static Address toAddress(SocketAddress address) { Preconditions.checkNotNull(address); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetSocketAddress inetAddress = (InetSocketAddress) address; builder.setTcpipAddress( TcpIpAddress .newBuilder() .setIpAddress( ByteString.copyFrom(inetAddress.getAddress().getAddress())) .setPort(inetAddress.getPort()) .build()); } else if (address.getClass().getName().endsWith("io.netty.channel.unix.DomainSocketAddress")) { builder.setUdsAddress( UdsAddress .newBuilder() .setFilename(address.toString()) .build()); } else { builder.setOtherAddress(OtherAddress.newBuilder().setName(address.toString()).build()); } return builder.build(); } }
ChannelzProtoUtil { static Address toAddress(SocketAddress address) { Preconditions.checkNotNull(address); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetSocketAddress inetAddress = (InetSocketAddress) address; builder.setTcpipAddress( TcpIpAddress .newBuilder() .setIpAddress( ByteString.copyFrom(inetAddress.getAddress().getAddress())) .setPort(inetAddress.getPort()) .build()); } else if (address.getClass().getName().endsWith("io.netty.channel.unix.DomainSocketAddress")) { builder.setUdsAddress( UdsAddress .newBuilder() .setFilename(address.toString()) .build()); } else { builder.setOtherAddress(OtherAddress.newBuilder().setName(address.toString()).build()); } return builder.build(); } private  ChannelzProtoUtil(); }
ChannelzProtoUtil { static Address toAddress(SocketAddress address) { Preconditions.checkNotNull(address); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetSocketAddress inetAddress = (InetSocketAddress) address; builder.setTcpipAddress( TcpIpAddress .newBuilder() .setIpAddress( ByteString.copyFrom(inetAddress.getAddress().getAddress())) .setPort(inetAddress.getPort()) .build()); } else if (address.getClass().getName().endsWith("io.netty.channel.unix.DomainSocketAddress")) { builder.setUdsAddress( UdsAddress .newBuilder() .setFilename(address.toString()) .build()); } else { builder.setOtherAddress(OtherAddress.newBuilder().setName(address.toString()).build()); } return builder.build(); } private  ChannelzProtoUtil();  }
ChannelzProtoUtil { static Address toAddress(SocketAddress address) { Preconditions.checkNotNull(address); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetSocketAddress inetAddress = (InetSocketAddress) address; builder.setTcpipAddress( TcpIpAddress .newBuilder() .setIpAddress( ByteString.copyFrom(inetAddress.getAddress().getAddress())) .setPort(inetAddress.getPort()) .build()); } else if (address.getClass().getName().endsWith("io.netty.channel.unix.DomainSocketAddress")) { builder.setUdsAddress( UdsAddress .newBuilder() .setFilename(address.toString()) .build()); } else { builder.setOtherAddress(OtherAddress.newBuilder().setName(address.toString()).build()); } return builder.build(); } private  ChannelzProtoUtil();  static final String SO_LINGER; static final String SO_TIMEOUT; static final String TCP_INFO; }