jiajunwang commented on a change in pull request #834: Complete the Routing 
Table Provider for CustomizedView
URL: https://github.com/apache/helix/pull/834#discussion_r390011682
 
 

 ##########
 File path: 
helix-core/src/main/java/org/apache/helix/spectator/RoutingTableProvider.java
 ##########
 @@ -106,61 +115,131 @@ public RoutingTableProvider(HelixManager helixManager, 
PropertyType sourceDataTy
    */
   public RoutingTableProvider(HelixManager helixManager, PropertyType 
sourceDataType,
       boolean isPeriodicRefreshEnabled, long periodRefreshInterval) throws 
HelixException {
-    _routingTableRef = new AtomicReference<>(new RoutingTable());
+    this(helixManager, ImmutableMap.of(sourceDataType, 
Collections.emptyList()),
+        isPeriodicRefreshEnabled, periodRefreshInterval);
+  }
+
+  /**
+   * Initialize an instance of RoutingTableProvider
+   * @param helixManager
+   * @param sourceDataTypes
+   * @param isPeriodicRefreshEnabled true if periodic refresh is enabled, 
false otherwise
+   * @param periodRefreshInterval only effective if isPeriodRefreshEnabled is 
true
+   * @throws HelixException
+   */
+  public RoutingTableProvider(HelixManager helixManager,
+      Map<PropertyType, List<String>> sourceDataTypes, boolean 
isPeriodicRefreshEnabled,
+      long periodRefreshInterval) throws HelixException {
+
+    // Check and validate the input of the sourceDataTypes parameter
+    for (PropertyType propertyType : sourceDataTypes.keySet()) {
+      if (propertyType.equals(PropertyType.CUSTOMIZEDVIEW)
+          && sourceDataTypes.get(propertyType).size() == 0) {
+        logger.error("CustomizedView has been used without any aggregation 
type!");
+        throw new HelixException("CustomizedView has been used without any 
aggregation type!");
+      }
+      if (!propertyType.equals(PropertyType.CUSTOMIZEDVIEW)
+          && sourceDataTypes.get(propertyType).size() != 0) {
+        logger.error("Type has been used in addition to the property type {} 
!",
+            propertyType.name());
+        throw new HelixException(String.format(
+            "Type has been used in addition to the property type %s !", 
propertyType.name()));
+      }
+    }
+
+    _routingTableRef = new HashMap<>();
     _helixManager = helixManager;
-    _sourceDataType = sourceDataType;
+    _routerUpdater = new HashMap<>();
+    _sourceDataTypes = sourceDataTypes;
     _routingTableChangeListenerMap = new ConcurrentHashMap<>();
     String clusterName = _helixManager != null ? 
_helixManager.getClusterName() : null;
+    _monitor = new HashMap<>();
 
-    _monitor = new RoutingTableProviderMonitor(_sourceDataType, clusterName);
-    try {
-      _monitor.register();
-    } catch (JMException e) {
-      logger.error("Failed to register RoutingTableProvider monitor MBean.", 
e);
+    for (PropertyType propertyType : _sourceDataTypes.keySet()) {
+      _monitor.put(propertyType, new RoutingTableProviderMonitor(propertyType, 
clusterName));
+      try {
+        _monitor.get(propertyType).register();
+      } catch (JMException e) {
+        logger.error("Failed to register RoutingTableProvider monitor MBean.", 
e);
+      }
     }
     _reportExecutor = Executors.newSingleThreadExecutor();
 
-    _routerUpdater = new RouterUpdater(clusterName, _sourceDataType);
-    _routerUpdater.start();
-
-    if (_helixManager != null) {
-      switch (_sourceDataType) {
-      case EXTERNALVIEW:
-        try {
-          _helixManager.addExternalViewChangeListener(this);
-        } catch (Exception e) {
-          shutdown();
-          logger.error("Failed to attach ExternalView Listener to 
HelixManager!");
-          throw new HelixException("Failed to attach ExternalView Listener to 
HelixManager!", e);
-        }
-        break;
-
-      case TARGETEXTERNALVIEW:
-        // Check whether target external has been enabled or not
-        if (!_helixManager.getHelixDataAccessor().getBaseDataAccessor().exists(
-            
_helixManager.getHelixDataAccessor().keyBuilder().targetExternalViews().getPath(),
 0)) {
-          shutdown();
-          throw new HelixException("Target External View is not enabled!");
+    for (PropertyType propertyType : _sourceDataTypes.keySet()) {
+      if (_sourceDataTypes.get(propertyType).size() == 0) {
+        // Empty aggregationType
+        String aggregationType = "";
 
 Review comment:
   This should be default string as well.

----------------------------------------------------------------
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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to