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_r392524940
##########
File path:
helix-core/src/main/java/org/apache/helix/spectator/RoutingTableProvider.java
##########
@@ -106,61 +120,113 @@ 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 sourceDataTypeMap
+ * @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>> sourceDataTypeMap, boolean
isPeriodicRefreshEnabled,
+ long periodRefreshInterval) throws HelixException {
+
+ validateSourceDataTypeMap(sourceDataTypeMap);
+
+ _routingTableRefMap = new HashMap<>();
_helixManager = helixManager;
- _sourceDataType = sourceDataType;
+ _sourceDataTypeMap = sourceDataTypeMap;
_routingTableChangeListenerMap = new ConcurrentHashMap<>();
String clusterName = _helixManager != null ?
_helixManager.getClusterName() : null;
+ _routerUpdater = new RouterUpdater(clusterName, sourceDataTypeMap);
+ _routerUpdater.start();
+ _monitorMap = 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 : _sourceDataTypeMap.keySet()) {
+ _monitorMap.put(propertyType, new
RoutingTableProviderMonitor(propertyType, clusterName));
+ try {
+ _monitorMap.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 : _sourceDataTypeMap.keySet()) {
+ if (_sourceDataTypeMap.get(propertyType).size() == 0) {
+ // Empty CustomizedStateType
+ String customizedStateType = DEFAULT_TYPE;
+ String key = propertyType.name() + "_" + customizedStateType;
+ if (_routingTableRefMap.get(key) == null) {
+ _routingTableRefMap.put(key, new AtomicReference<>(new
RoutingTable(propertyType)));
}
-
- try {
- _helixManager.addTargetExternalViewChangeListener(this);
- } catch (Exception e) {
- shutdown();
- logger.error("Failed to attach TargetExternalView Listener to
HelixManager!");
- throw new HelixException("Failed to attach TargetExternalView
Listener to HelixManager!",
- e);
+ } else {
+ for (String customizedStateType :
_sourceDataTypeMap.get(propertyType)) {
+ String key = propertyType.name() + "_" + customizedStateType;
Review comment:
nit, Some common logic could be merged. We can set the local vars and finish
the _routingTableRefMap set up after the condition check.
----------------------------------------------------------------
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]