@Override
    public void customize(ServiceInstance serviceInstance, ApplicationModel applicationModel) {
        MetadataInfo metadataInfo = serviceInstance.getServiceMetadata();
        if (metadataInfo == null || CollectionUtils.isEmptyMap(metadataInfo.getExportedServiceURLs())) {
            return;
        }

        Map<String, Integer> protocols = new HashMap<>();
        Set<URL> urls = metadataInfo.collectExportedURLSet();
        urls.forEach(url -> {
            // TODO, same protocol listen on different ports will override with each other.
            String protocol = url.getProtocol();
            Integer oldPort = protocols.get(protocol);
            int newPort = url.getPort();
            if (oldPort != null && oldPort != newPort) {
                LOGGER.warn(
                        LoggerCodeConstants.PROTOCOL_INCORRECT_PARAMETER_VALUES,
                        "the protocol is listening multiple ports",
                        "",
                        "Same protocol " + "[" + protocol + "]" + " listens on different ports " + "[" + oldPort + ","
                                + newPort + "]" + " will override with each other" + ". The port [" + oldPort
                                + "] is overridden with port [" + newPort + "].");
            }
            protocols.put(protocol, newPort);
        });

        if (protocols.size() > 0) { // set endpoints only for multi-protocol scenario
            setEndpoints(serviceInstance, protocols);
        }
    }
@Test
    void test() {
        ProtocolPortsMetadataCustomizer customizer = new ProtocolPortsMetadataCustomizer();
        customizer.customize(instance, ApplicationModel.defaultModel());
        String endpoints = instance.getMetadata().get(ENDPOINTS);
        assertNotNull(endpoints);
        List<DefaultServiceInstance.Endpoint> endpointList =
                JsonUtils.toJavaList(endpoints, DefaultServiceInstance.Endpoint.class);
        assertEquals(2, endpointList.size());
        MatcherAssert.assertThat(endpointList, hasItem(hasProperty("protocol", equalTo("dubbo"))));
        MatcherAssert.assertThat(endpointList, hasItem(hasProperty("port", equalTo(20880))));
        MatcherAssert.assertThat(endpointList, hasItem(hasProperty("protocol", equalTo("tri"))));
        MatcherAssert.assertThat(endpointList, hasItem(hasProperty("port", equalTo(50332))));
    }