@Test public void testListClient() throws Exception { ExchangeClient client1 = Exchangers.connect("dubbo: ExchangeClient client2 = Exchangers.connect("dubbo: Thread.sleep(5000); String result = port.telnet(null, "-l 20887"); String client1Addr = client1.getLocalAddress().toString(); String client2Addr = client2.getLocalAddress().toString(); System.out.printf("Result: %s %n", result); System.out.printf("Client 1 Address %s %n", client1Addr); System.out.printf("Client 2 Address %s %n", client2Addr); assertTrue(result.contains(client1Addr)); assertTrue(result.contains(client2Addr)); }
@SuppressWarnings("StringConcatenationInsideStringBufferAppend") public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (! StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); }
PortTelnetHandler implements TelnetHandler { @SuppressWarnings("StringConcatenationInsideStringBufferAppend") public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (! StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
PortTelnetHandler implements TelnetHandler { @SuppressWarnings("StringConcatenationInsideStringBufferAppend") public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (! StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); }  }
PortTelnetHandler implements TelnetHandler { @SuppressWarnings("StringConcatenationInsideStringBufferAppend") public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (! StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); }  @SuppressWarnings("StringConcatenationInsideStringBufferAppend") String telnet(Channel channel, String message); }
PortTelnetHandler implements TelnetHandler { @SuppressWarnings("StringConcatenationInsideStringBufferAppend") public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (! StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); }  @SuppressWarnings("StringConcatenationInsideStringBufferAppend") String telnet(Channel channel, String message);  }