You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ji...@apache.org on 2020/04/07 18:04:48 UTC

[helix] branch customizeView updated: fix customized state provider (#928)

This is an automated email from the ASF dual-hosted git repository.

jiajunwang pushed a commit to branch customizeView
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/customizeView by this push:
     new 3a3c3a9  fix customized state provider (#928)
3a3c3a9 is described below

commit 3a3c3a9eee1da569a47ad5c8da385a409229b8da
Author: meng <mn...@linkedin.com>
AuthorDate: Tue Apr 7 11:04:40 2020 -0700

    fix customized state provider (#928)
    
    Modify customized state provider factory. The new factory can build a customized state provider with either Helix own manager or a customer input manager.
---
 .../CustomizedStateProviderFactory.java            | 43 +++++++++-------------
 1 file changed, 17 insertions(+), 26 deletions(-)

diff --git a/helix-core/src/main/java/org/apache/helix/customizedstate/CustomizedStateProviderFactory.java b/helix-core/src/main/java/org/apache/helix/customizedstate/CustomizedStateProviderFactory.java
index 3e60522..5190a82 100644
--- a/helix-core/src/main/java/org/apache/helix/customizedstate/CustomizedStateProviderFactory.java
+++ b/helix-core/src/main/java/org/apache/helix/customizedstate/CustomizedStateProviderFactory.java
@@ -19,9 +19,9 @@ package org.apache.helix.customizedstate;
  * under the License.
  */
 
-import java.util.HashMap;
-import org.apache.helix.HelixException;
 import org.apache.helix.HelixManager;
+import org.apache.helix.HelixManagerFactory;
+import org.apache.helix.InstanceType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -30,9 +30,6 @@ import org.slf4j.LoggerFactory;
  */
 public class CustomizedStateProviderFactory {
   private static Logger LOG = LoggerFactory.getLogger(CustomizedStateProvider.class);
-  private final HashMap<String, CustomizedStateProvider> _customizedStateProviderMap =
-      new HashMap<>();
-  private HelixManager _helixManager;
 
   protected CustomizedStateProviderFactory() {
   }
@@ -46,34 +43,28 @@ public class CustomizedStateProviderFactory {
     return SingletonHelper.INSTANCE;
   }
 
-  public CustomizedStateProvider buildCustomizedStateProvider(String instanceName) {
-    if (_helixManager == null) {
-      throw new HelixException("Helix Manager has not been set yet.");
-    }
-    return buildCustomizedStateProvider(_helixManager, instanceName);
+  /**
+   * Build a customized state provider based on user input.
+   * @param instanceName The name of the instance
+   * @param clusterName The name of the cluster that has the instance
+   * @param zkAddress The zookeeper address of the cluster
+   * @return CustomizedStateProvider
+   */
+  public CustomizedStateProvider buildCustomizedStateProvider(String instanceName,
+      String clusterName, String zkAddress) {
+    HelixManager helixManager = HelixManagerFactory
+        .getZKHelixManager(clusterName, instanceName, InstanceType.ADMINISTRATOR, zkAddress);
+    return new CustomizedStateProvider(helixManager, instanceName);
   }
 
   /**
-   * Build a customized state provider based on the specified input. If the instance already has a
-   * provider, return it. Otherwise, build a new one and put it in the map.
-   * @param helixManager The helix manager that belongs to the instance
+   * Build a customized state provider based on user input.
    * @param instanceName The name of the instance
+   * @param helixManager Helix manager provided by user
    * @return CustomizedStateProvider
    */
   public CustomizedStateProvider buildCustomizedStateProvider(HelixManager helixManager,
       String instanceName) {
-    synchronized (_customizedStateProviderMap) {
-      if (_customizedStateProviderMap.get(instanceName) != null) {
-        return _customizedStateProviderMap.get(instanceName);
-      }
-      CustomizedStateProvider customizedStateProvider =
-          new CustomizedStateProvider(helixManager, instanceName);
-      _customizedStateProviderMap.put(instanceName, customizedStateProvider);
-      return customizedStateProvider;
-    }
-  }
-
-  public void setHelixManager(HelixManager helixManager) {
-    _helixManager = helixManager;
+    return new CustomizedStateProvider(helixManager, instanceName);
   }
 }