@Override
    public String telnet(Channel channel, String message) {
        String service = (String) channel.getAttribute(ChangeTelnetHandler.SERVICE_KEY);
        if ((StringUtils.isEmpty(service)) && (StringUtils.isEmpty(message))) {
            return "Please input service name, eg: \r\ntrace XxxService\r\ntrace XxxService xxxMethod\r\ntrace XxxService xxxMethod 10\r\nor \"cd XxxService\" firstly.";
        }
        String[] parts = message.split("\\s+");
        String method;
        String times;
        // message like : XxxService , XxxService 10 , XxxService xxxMethod , XxxService xxxMethod 10
        if (StringUtils.isEmpty(service)) {
            service = parts.length > 0 ? parts[0] : null;
            method = parts.length > 1 ? parts[1] : null;
            times = parts.length > 2 ? parts[2] : "1";
        } else { // message like : xxxMethod, xxxMethod 10
            method = parts.length > 0 ? parts[0] : null;
            times = parts.length > 1 ? parts[1] : "1";
        }
        if (StringUtils.isNumber(method)) {
            times = method;
            method = null;
        }
        if (!StringUtils.isNumber(times)) {
            return "Illegal times " + times + ", must be integer.";
        }
        Invoker<?> invoker = null;
        for (Exporter<?> exporter : DubboProtocol.getDubboProtocol().getExporters()) {
            if (service.equals(exporter.getInvoker().getInterface().getSimpleName())
                    || service.equals(exporter.getInvoker().getInterface().getName())
                    || service.equals(exporter.getInvoker().getUrl().getPath())) {
                invoker = exporter.getInvoker();
                break;
            }
        }
        if (invoker != null) {
            if (StringUtils.isNotEmpty(method)) {
                boolean found = false;
                for (Method m : invoker.getInterface().getMethods()) {
                    if (m.getName().equals(method)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    return "No such method " + method + " in class "
                            + invoker.getInterface().getName();
                }
            }
            TraceFilter.addTracer(invoker.getInterface(), method, channel, Integer.parseInt(times));
        } else {
            return "No such service " + service;
        }
        return null;
    }
@Test
    void testTraceTelnetAddTracer() throws Exception {
        String method = "sayHello";
        String message = "org.apache.dubbo.qos.legacy.service.DemoService sayHello 1";
        Class<?> type = DemoService.class;

        ExtensionLoader.getExtensionLoader(Protocol.class)
                .getExtension(DubboProtocol.NAME)
                .export(mockInvoker);
        handler.telnet(mockChannel, message);

        String key = type.getName() + "." + method;
        Field tracers = TraceFilter.class.getDeclaredField("TRACERS");
        tracers.setAccessible(true);
        ConcurrentHashMap<String, Set<Channel>> map =
                (ConcurrentHashMap<String, Set<Channel>>) tracers.get(new ConcurrentHashMap<String, Set<Channel>>());

        Set<Channel> channels = map.getOrDefault(key, null);
        Assertions.assertNotNull(channels);

        Assertions.assertTrue(channels.contains(mockChannel));
    }