+ public static class Builder {
+ private String name;
+ private String nameSpace;
+ private ShardStrategy shardStrategy;
+ private final Map<String, ShardConfig> shardConfigs = new HashMap<>();
+
+ private Builder(String name) {
+ this.name = name;
+ }
+
+ private Builder(ModuleConfig moduleConfig) {
+ this.name = moduleConfig.getName();
+ this.nameSpace = moduleConfig.getNameSpace();
+ this.shardStrategy = moduleConfig.getShardStrategy();
+ for (ShardConfig shardConfig : moduleConfig.getShardConfigs()) {
+ shardConfigs.put(shardConfig.getName(), shardConfig);
+ }
+ }
+
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder nameSpace(String nameSpace) {
+ this.nameSpace = nameSpace;
+ return this;
+ }
+
+ public Builder shardStrategy(ShardStrategy shardStrategy) {
+ this.shardStrategy = shardStrategy;
+ return this;
+ }
+
+ public Builder shardConfig(String name, Collection<String> replicas) {
+ shardConfigs.put(name, new ShardConfig(name, replicas));
+ return this;
+ }
+
+ public ModuleConfig build() {
+ return new ModuleConfig(Preconditions.checkNotNull(name), nameSpace, shardStrategy,
+ ImmutableMap.copyOf(shardConfigs));
+ }