liubao68 commented on a change in pull request #1400: [SCB-1407] Add gray 
release feature 
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1400#discussion_r348934877
 
 

 ##########
 File path: 
handlers/handler-router/src/main/java/org/apache/servicecomb/router/cache/RouterRuleCache.java
 ##########
 @@ -0,0 +1,115 @@
+/*
+ * 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.router.cache;
+
+import com.google.common.collect.Interner;
+import com.google.common.collect.Interners;
+import com.netflix.config.DynamicPropertyFactory;
+import com.netflix.config.DynamicStringProperty;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.servicecomb.router.model.PolicyRuleItem;
+import org.apache.servicecomb.router.model.ServiceInfoCache;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.util.CollectionUtils;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * @Author GuoYl123
+ * @Date 2019/10/17
+ **/
+public class RouterRuleCache {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(RouterRuleCache.class);
+
+  private static ConcurrentHashMap<String, ServiceInfoCache> 
serviceInfoCacheMap = new ConcurrentHashMap<>();
+
+  private static final String ROUTE_RULE = "servicecomb.routeRule.%s";
+
+  private static Interner<String> servicePool = Interners.newWeakInterner();
+
+  /**
+   * cache and register callback return false when: 1. parsing error 2. rule 
is null
+   *
+   * @param targetServiceName
+   * @return
+   */
+  public static boolean doInit(String targetServiceName) {
+    if (!serviceInfoCacheMap.containsKey(targetServiceName)) {
+      synchronized (servicePool.intern(targetServiceName)) {
+        if (serviceInfoCacheMap.containsKey(targetServiceName)) {
+          return true;
+        }
+        //Yaml not thread-safe
+        Yaml yaml = new Yaml();
+        DynamicStringProperty ruleStr = 
DynamicPropertyFactory.getInstance().getStringProperty(
+            String.format(ROUTE_RULE, targetServiceName), null, () -> {
+              Yaml temYaml = new Yaml();
 
 Review comment:
   ```
   Yaml temYaml = new Yaml();
   ```
   Can put to addAllRule method. 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to