+
+ @Override
+ public boolean isShardConfigured(String shardName) {
+ Preconditions.checkNotNull(shardName, "shardName should not be null");
+ return allShardNames.contains(shardName);
+ }
+
+ @Override
+ public void addMemberReplicaForShard(String shardName, MemberName newMemberName) {
+ Preconditions.checkNotNull(shardName, "shardName should not be null");
+ Preconditions.checkNotNull(newMemberName, "MemberName should not be null");
+
+ for (ModuleConfig moduleConfig: moduleConfigMap.values()) {
+ ShardConfig shardConfig = moduleConfig.getShardConfig(shardName);
+ if (shardConfig != null) {
+ Set<MemberName> replicas = new HashSet<>(shardConfig.getReplicas());
+ replicas.add(newMemberName);
+ updateModuleConfigMap(ModuleConfig.builder(moduleConfig).shardConfig(shardName, replicas).build());
+ return;
+ }
+ }
+ }
+
+ @Override
+ public void removeMemberReplicaForShard(String shardName, MemberName newMemberName) {
+ Preconditions.checkNotNull(shardName, "shardName should not be null");
+ Preconditions.checkNotNull(newMemberName, "MemberName should not be null");
+
+ for (ModuleConfig moduleConfig: moduleConfigMap.values()) {
+ ShardConfig shardConfig = moduleConfig.getShardConfig(shardName);
+ if (shardConfig != null) {
+ Set<MemberName> replicas = new HashSet<>(shardConfig.getReplicas());
+ replicas.remove(newMemberName);
+ updateModuleConfigMap(ModuleConfig.builder(moduleConfig).shardConfig(shardName, replicas).build());
+ return;
+ }
+ }
+ }
+
+ private void updateModuleConfigMap(ModuleConfig moduleConfig) {
+ Map<String, ModuleConfig> newModuleConfigMap = new HashMap<>(moduleConfigMap);
+ newModuleConfigMap.put(moduleConfig.getName(), moduleConfig);
+ moduleConfigMap = ImmutableMap.copyOf(newModuleConfigMap);
+ }