You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/04/15 08:49:10 UTC

[GitHub] [servicecomb-java-chassis] wujimin commented on a change in pull request #1180: [SCB-1251] Reduce archaius callback

wujimin commented on a change in pull request #1180: [SCB-1251] Reduce archaius callback
URL: https://github.com/apache/servicecomb-java-chassis/pull/1180#discussion_r275260767
 
 

 ##########
 File path: foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java
 ##########
 @@ -0,0 +1,136 @@
+/*
+ * 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.config.priority;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.configuration.event.ConfigurationEvent;
+import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.servicecomb.config.inject.ConfigObjectFactory;
+import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
+
+import com.netflix.config.ConfigurationManager;
+import com.netflix.config.DynamicPropertyFactory;
+
+public class PriorityPropertyManager {
+  private ConfigurationListener configurationListener = this::configurationListener;
+
+  private Map<PriorityProperty<?>, PriorityProperty<?>> priorityPropertyMap = new ConcurrentHashMapEx<>();
+
+  private Map<Object, List<PriorityProperty<?>>> configObjectMap = new ConcurrentHashMapEx<>();
+
+  // will be reset to null after register or unregister
+  // and build when configuration changed
+  private Map<String, List<PriorityProperty<?>>> keyCache;
+
+  public PriorityPropertyManager() {
+    // make sure create a DynamicPropertyFactory instance
+    // otherwise will cause wrong order of configurationListeners
+    DynamicPropertyFactory.getInstance();
+
+    ConfigurationManager.getConfigInstance().addConfigurationListener(configurationListener);
+  }
+
+  public void close() {
+    ConfigurationManager.getConfigInstance().removeConfigurationListener(configurationListener);
+  }
+
+  public synchronized void configurationListener(ConfigurationEvent event) {
+    if (event.isBeforeUpdate()) {
+      return;
+    }
+
+    if (keyCache == null) {
+      keyCache = new ConcurrentHashMapEx<>();
+      updateCache(priorityPropertyMap.values());
+      configObjectMap.values().stream().forEach(this::updateCache);
+    }
+
+    keyCache.getOrDefault(event.getPropertyName(), Collections.emptyList()).stream()
 
 Review comment:
   done

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services