@Test public void testPreferIncoming() throws Exception { InetAddress host = InetAddress.getByName(null); final TChannel server = new TChannel.Builder("server") .setServerHost(host) .build(); final SubChannel subServer = server.makeSubChannel("server", Connection.Direction.IN) .register("echo", new EchoHandler()); server.listen(); final int port = server.getListeningPort(); final TChannel client = new TChannel.Builder("client") .setServerHost(host) .build(); final SubChannel subClient = client.makeSubChannel("server", Connection.Direction.IN) .setPeers(ImmutableList.of(new InetSocketAddress(host, port))); client.listen(); RawRequest req = new RawRequest.Builder("server", "echo") .setHeader("title") .setBody("hello") .setId(1000) .setTimeout(2000) .build(); TFuture<RawResponse> future = subClient.send( req ); try (RawResponse res = future.get()) { assertEquals("title", res.getArg2().toString(CharsetUtil.UTF_8)); assertEquals("hello", res.getArg3().toString(CharsetUtil.UTF_8)); } assertStats("client", client, 0, 1); assertStats("server", server, 1, 0); client.shutdown(); server.shutdown(); assertStats("client", client, 0, 0); assertStats("server", server, 0, 0); }
public @Nullable Connection get(@NotNull Channel channel) { Peer peer = peers.get(channel.remoteAddress()); return peer == null ? null : peer.getConnection(channel.id()); }
PeerManager { public @Nullable Connection get(@NotNull Channel channel) { Peer peer = peers.get(channel.remoteAddress()); return peer == null ? null : peer.getConnection(channel.id()); } }
PeerManager { public @Nullable Connection get(@NotNull Channel channel) { Peer peer = peers.get(channel.remoteAddress()); return peer == null ? null : peer.getConnection(channel.id()); } PeerManager(Bootstrap clientBootstrap); }
PeerManager { public @Nullable Connection get(@NotNull Channel channel) { Peer peer = peers.get(channel.remoteAddress()); return peer == null ? null : peer.getConnection(channel.id()); } PeerManager(Bootstrap clientBootstrap); Connection findOrNew(@NotNull SocketAddress address); Peer findOrNewPeer(@NotNull SocketAddress address); @Nullable Peer getPeer(@NotNull SocketAddress address); @Nullable Peer getPeer(@NotNull Channel channel); Connection connectTo(@NotNull SocketAddress address); @Nullable Connection get(@NotNull Channel channel); void add(@NotNull ChannelHandlerContext ctx); @Nullable Connection remove(@NotNull Channel channel); void setIdentified(@NotNull Channel channel, @NotNull Map<String, String> headers); void handleConnectionErrors(@NotNull Channel channel, @NotNull Throwable cause); void close(); void setHostPort(String hostPort); String getHostPort(); @NotNull Map<String, Integer> getStats(); }
PeerManager { public @Nullable Connection get(@NotNull Channel channel) { Peer peer = peers.get(channel.remoteAddress()); return peer == null ? null : peer.getConnection(channel.id()); } PeerManager(Bootstrap clientBootstrap); Connection findOrNew(@NotNull SocketAddress address); Peer findOrNewPeer(@NotNull SocketAddress address); @Nullable Peer getPeer(@NotNull SocketAddress address); @Nullable Peer getPeer(@NotNull Channel channel); Connection connectTo(@NotNull SocketAddress address); @Nullable Connection get(@NotNull Channel channel); void add(@NotNull ChannelHandlerContext ctx); @Nullable Connection remove(@NotNull Channel channel); void setIdentified(@NotNull Channel channel, @NotNull Map<String, String> headers); void handleConnectionErrors(@NotNull Channel channel, @NotNull Throwable cause); void close(); void setHostPort(String hostPort); String getHostPort(); @NotNull Map<String, Integer> getStats();  }