- private void updateModuleConfigMap(ModuleConfig moduleConfig) {
- HashMap<String, ModuleConfig> newModuleConfigMap = new HashMap<>(moduleConfigMap);
+ @Override
+ public ShardStrategy getStrategyForPrefix(@Nonnull final YangInstanceIdentifier prefix) {
+ Preconditions.checkNotNull(prefix, "Prefix cannot be null");
+ // FIXME using prefix tables like in mdsal will be better
+ Entry<YangInstanceIdentifier, PrefixShardConfiguration> bestMatchEntry =
+ new SimpleEntry<>(YangInstanceIdentifier.EMPTY, null);
+
+ for (Entry<YangInstanceIdentifier, PrefixShardConfiguration> entry : prefixConfigMap.entrySet()) {
+ if (entry.getKey().contains(prefix) && entry.getKey().getPathArguments().size()
+ > bestMatchEntry.getKey().getPathArguments().size()) {
+ bestMatchEntry = entry;
+ }
+ }
+
+ if (bestMatchEntry.getValue() == null) {
+ return null;
+ }
+ return new PrefixShardStrategy(
+ ClusterUtils.getCleanShardName(bestMatchEntry.getValue().getPrefix().getRootIdentifier()), this);
+ }
+
+ private void updateModuleConfigMap(final ModuleConfig moduleConfig) {
+ final Map<String, ModuleConfig> newModuleConfigMap = new HashMap<>(moduleConfigMap);