[
https://issues.apache.org/jira/browse/SCB-985?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16664779#comment-16664779
]
ASF GitHub Bot commented on SCB-985:
------------------------------------
wujimin commented on a change in pull request #969: [SCB-985] Add
spring-boot2-starter-discovery
URL:
https://github.com/apache/incubator-servicecomb-java-chassis/pull/969#discussion_r228426288
##########
File path:
spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseDiscoveryClient.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.springboot2.starter.discovery;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.common.cache.VersionedCache;
+import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
+import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
+import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
+import org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext;
+import org.apache.servicecomb.serviceregistry.discovery.DiscoveryTree;
+import org.springframework.cloud.client.DefaultServiceInstance;
+import org.springframework.cloud.client.ServiceInstance;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
+
+public class CseDiscoveryClient implements DiscoveryClient {
+ private Map<String, DiscoveryTree> discoveryTrees = new
ConcurrentHashMapEx<>();
+
+ @Override
+ public String description() {
+ return "Spring Cloud CSE Discovery Client";
+ }
+
+ @Override
+ public List<ServiceInstance> getInstances(final String serviceId) {
+ DiscoveryContext context = new DiscoveryContext();
+ context.setInputParameters(serviceId);
+ DiscoveryTree discoveryTree = discoveryTrees.computeIfAbsent(serviceId,
key -> {
+ return new DiscoveryTree();
+ });
+ VersionedCache serversVersionedCache = discoveryTree.discovery(context,
+ RegistryUtils.getAppId(),
+ serviceId,
+ DefinitionConst.VERSION_RULE_ALL);
+ Map<String, MicroserviceInstance> servers = serversVersionedCache.data();
+ List<ServiceInstance> instances = new ArrayList<>(servers.size());
Review comment:
this convert result should be cached
please create a issue to trace the optimize
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Add springboot2-starter-discovery
> ---------------------------------
>
> Key: SCB-985
> URL: https://issues.apache.org/jira/browse/SCB-985
> Project: Apache ServiceComb
> Issue Type: Improvement
> Components: Java-Chassis
> Affects Versions: java-chassis-1.1.0
> Reporter: Yang Bo
> Assignee: Yang Bo
> Priority: Major
>
> Copied springboot-starter-discovery to spritnboot2. Removed test code and
> updated some spring-boot and spring-cloud versions.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)