jungan21 commented on a change in pull request #1804:
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1804#discussion_r433242948



##########
File path: 
service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/client/ZeroConfigClient.java
##########
@@ -0,0 +1,301 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.zeroconfig.client;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.commons.lang.StringUtils;
+import org.apache.servicecomb.registry.api.registry.FindInstancesResponse;
+import org.apache.servicecomb.registry.api.registry.Microservice;
+import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.registry.api.registry.MicroserviceInstances;
+import org.apache.servicecomb.registry.version.Version;
+import org.apache.servicecomb.registry.version.VersionRule;
+import org.apache.servicecomb.registry.version.VersionRuleUtils;
+import org.apache.servicecomb.registry.version.VersionUtils;
+import org.apache.servicecomb.zeroconfig.ZeroConfigRegistration;
+import org.apache.servicecomb.zeroconfig.server.ServerMicroserviceInstance;
+import org.apache.servicecomb.zeroconfig.server.ServerUtil;
+import org.apache.servicecomb.zeroconfig.server.ZeroConfigRegistryService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.client.RestTemplate;
+
+import static org.apache.servicecomb.zeroconfig.ZeroConfigRegistryConstants.*;
+
+public class ZeroConfigClient {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(ZeroConfigClient.class);
+
+  public static ZeroConfigClient INSTANCE = buildZeroConfigClient();
+
+  // Constructor Parameters
+  private ZeroConfigRegistryService zeroConfigRegistryService;
+  private RestTemplate restTemplate;
+  private MulticastSocket multicastSocket;
+
+  // Constructor
+
+  private ZeroConfigClient(ZeroConfigRegistryService zeroConfigRegistryService,
+      MulticastSocket multicastSocket, RestTemplate restTemplate) {
+    this.zeroConfigRegistryService = zeroConfigRegistryService;
+    this.restTemplate = restTemplate;
+    this.multicastSocket = multicastSocket;
+  }
+
+  @VisibleForTesting
+  public ZeroConfigClient initZeroConfigClientWithMocked(
+      ZeroConfigRegistryService zeroConfigRegistryService,
+      MulticastSocket multicastSocket, RestTemplate restTemplate) {
+    this.zeroConfigRegistryService = zeroConfigRegistryService;
+    this.multicastSocket = multicastSocket;
+    this.restTemplate = restTemplate;
+    return this;
+  }
+
+  // builder method
+  private static ZeroConfigClient buildZeroConfigClient() {
+    MulticastSocket multicastSocket = null;
+    try {
+      multicastSocket = new MulticastSocket();
+      multicastSocket.setLoopbackMode(false);
+    } catch (IOException e) {
+      // since we support multiple registries, not blocking other type of 
registries
+      LOGGER.error("Failed to create MulticastSocket object in Zero-Config 
mode", e);
+      //throw new ServiceCombException("Failed to create MulticastSocket 
object", e);
+    }
+    return new ZeroConfigClient(new ZeroConfigRegistryService(), 
multicastSocket,
+        new RestTemplate());

Review comment:
       will think about perfect soution in next PR




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to